JAXB是否使用字节码检测? [英] Does JAXB use bytecode instrumentation?
问题描述
我工作的人注意到(在堆栈跟踪中)当使用-javaagent:spring-instrumentation.jar运行jvm时,我的JAXB注释类中有一些我们没有编写的奇怪的新方法:例如SomeJaxbAnnotatedClass $ JaxbAccessorM_getFields_setFields_java_util_Set.get
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
这是否意味着jaxb在可用时使用字节码检测?我在哪里可以阅读有关此功能的更多信息?
Does this mean that jaxb uses bytecode instrumentation when it is available? Where can i read more about this functionality?
谢谢,
Yuval
Thanks, Yuval
推荐答案
只是对skaffman帖子的补充:
Just an addition to skaffman's post:
你看到的内容(SomeJaxbAnnotatedClass $ JaxbAccessor ...)是一个内部类,它由动态生成JAXB参考实现。为了防止运行时的反射开销,生成类 com.sun.xml.bind.v2.runtime.reflect.Accessor
的具体实现的字节码并注入当前classloader通过调用ClassLoader.defineClass(String,byte [],int,int),在使用反射来绕过defineClass方法的受保护访问修饰符之后。
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.
所以, JAXB参考实现并不是在修改现有类,而是为了优化运行时性能而生成新类。
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.
这篇关于JAXB是否使用字节码检测?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!