Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does JAXB use bytecode instrumentation?

Someone where i work noticed (in stacktrace) that when running the jvm with -javaagent:spring-instrumentation.jar my JAXB annotated classes have strange new methods in them which we didn't write: e.g. SomeJaxbAnnotatedClass$JaxbAccessorM_getFields_setFields_java_util_Set.get

Does this mean that jaxb uses bytecode instrumentation when it is available? Where can i read more about this functionality?

Thanks, Yuval

like image 719
Yuval Rimar Avatar asked Jan 25 '10 16:01

Yuval Rimar


1 Answers

Just an addition to skaffman's post:

What you see (SomeJaxbAnnotatedClass$JaxbAccessor...) is an inner class, which is generated dynamically by the JAXB reference implementation. To prevent reflection overhead at runtime, bytecode for the concrete implementations of the class com.sun.xml.bind.v2.runtime.reflect.Accessor are generated and injected into the current classloader by invoking ClassLoader.defineClass(String, byte[], int, int), after using reflection to circumvent the protected access modifier of the defineClass method.

So, the JAXB reference implementation is not instrumenting bytecode in the sense that it's modifying existing classes, but generates new classes for optimized runtime performance.

like image 136
jarnbjo Avatar answered Oct 04 '22 13:10

jarnbjo