The format of class data loaded in method area of jvm by the class loader? - jvm

What is the format of the class related information loaded in method area by the class loader of jvm? Does the class information loaded in method area by class loader is present in machine language(native instructions set)?
Actually as the JVM's execution engine converts the bytecode into native instructions set. So I wanted to know does the class related information loaded by classloaders in method area of jvm is already present in native instructions set or present in any other format and later gets converted to native instructions set by JVM's execution engine.

Related

ByteBuddy: Workaround for modifying schema of loaded class

The issue: We generate classes using ByteBuddy, load them and at one point will need to add/remove fields without re-starting the application.
If I understand correctly, in Java it is not possible to modify the schema (add fields/methods) of a class already loaded into a class loader.
My question: As a workaround, would it be a possible/reasonable to create a new class loader when a such a conflict occurs - load all generated classes into the new class loader and close the old class loader?
Thank you.
There is a VM version of OpenJDK that supports such transformations, the Dynamic Code Evolution VM.
For a regular VM, you can load a class in a new class loader. However, in this case no previous instance will be an instance of this altered class. You would need to recreate all instances. If this is feasible for you, this is an option.

Byte Buddy LocationStrategy types

I saw that the default LocationStrategy is STRONG, which keeps a strong reference to the class loader when creating a ClassFileLocator. Does this mean Byte Buddy can prevent a class loader from being garbage collected (eg when undeploying a webapp from a servlet container) or is there another mechanism to evacuate those?
Also in this regard- the documentation about the WEAK strategy says a ClassFileLocator will "stop working" after the corresponding class loader is garbage collected. What are the implications? How would a locator for a garbage-collected class loader be used?
You are right about your assertion. With a strong type locator, all TypeDescriptions will reference the class loader as dependent types are resolved lazily. This means for example that if you look up a type's field type, that type will only be loaded if you are using it for the first time what might never happen.
Typically, those type descriptions are not stored over the life time of a class being loaded. Since the class loader will never be garbage collected during a loading of one of its classes, referencing the class loader strongly does not render any issue. However, once you want to cache type descriptions in between multiple class loadings (what can make a lot of sence since some applications load thousands of classes using the same class loader), this might become a problem if a class loader would be garbage collected while the cache is still referencing the type description with the underlying class loader.
In this case, reusing the type descriptions will be problematic since no lazily referenced classes can be resolved after the class loader was garbage collected. Note that a type description might be resolved using a specific class loader while the class is defined by a parent of that class loader which is why this might be a problem.
Typically, if you maintain a cache of type descriptions per class loader, this should however not be a problem.

JVM crashes/OutOfMemory when Java Instrumentation retransform a class many times

I wrote a Java agent, with a instance that implements ClassFileTransformer's below method:
class MyTransformer {
public byte[] transform(ClassLoader loader, String classNameWithSlash,
Class classBeingRedefined, ProtectionDomain protectionDomain,
byte[] classfileBuffer) throws IllegalClassFormatException {
return null;
}
}
In order to be able to retransform a loaded class, I used below method to add the above transformer:
inst.addTransformer(new MyTransformer(), true);
It functionally works, however, there is a problem:
When testing using Oracle JDK1.8.0_102 (on Linux 64bit), and enable tracing of class loading and unloading by adding below arguments to JVM startup arguments
-XX:+TraceClassLoading -XX:+TraceClassUnloading. I can see trace logs for class loading when a inst.retransform(aClass) is invoked, e.g.
[Loaded myapp.MyClass from __VM_RedefineClasses__]
This is fine for class loading, but when I retransform the same class again, I can see this 'loading' trace log again but can't see any trace related to 'unloading'.
So the problem is, if I call inst.retransform() to a certain number of times, the JVM crashes! When I increase the setting for -XX:MetaspaceSize, the number of calls I can make increases before the JVM crashes. These two numbers are highly correlated, .
So, the questions: Is this a JVM bug, or it is the agent developer's job to unload a class being transformed?
Note: The JVM crashes (or complains about out of memory in meta space) even if my transformer does not do any transformation by returning null.
Classes loaded are default behavior when functionality of the classes are used but unloading cannot be performed similar way. Classes unloading are done by GC. GC performs some heuristics checks before unloading classes. This is not a bug. JVM is working as designed.

What's the package of a Java array class?

This question is for JVM specification advocates. According to the JVMS, Java SE 7 edition, section 5.3.3, last paragraph:
If the component type is a reference type, the accessibility of the array class is determined by the accessibility of its component type. Otherwise, the accessibility of the array class is public.
Thus an array class can have package visibility. Logically I would expect that, if foo.baz.MyClass has package visibility, then an array of MyClass is visible only to package foo.baz. But I can't find anything in the specification supporting this view. Section 5.3 says that the run-time package, that should be used to determine visibility constraints, is built of the binary name of the package plus the defining classloader. But the binary name comes from the classfile, and array classes do not have classfiles. Similar issue for the primitive classes (e.g., Boolean.TYPE), which apparently have public visibility, but I cannot find information about them anywhere.
Can you spot a point in the JVMS where the package of array/primitive classes is clearly defined (or a reason why there is none)?
Isn't that exactly what the quote from the specification is saying?
If the component type is a reference type, the accessibility of the array class is determined by the accessibility of its component type.
If you have a class some.pkg.SomeClass and want to use it as some.pkg.SomeClass[] the accessibility is determined by the accessibility of its component type. In this case the component type is some.pkg.SomeClass.
The other case is for native types, and you can't add more native types to Java.

Codeigniter Image Manipulation Class process overhead

in Codeigniter's Image Manipulation Class there's a preference called 'library_path' where you have to mention the path to the binary. this means its executing the binary. Does this take more ram than using the apache extension ?
is there a less process intensive class or a method that can be used with CI?