J2SE 5.0 specification for method ClassFileTransformer.transform(ClassLoader classLoader, String className, Class classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) tells:
transformer will be called for every new class definition and every
class redefinition. The request for a new class definition is made
with ClassLoader.defineClass. The request for a class redefinition is
made with Instrumentation.redefineClasses or its native equivalents.
The transformer is called during the processing of the request, before
the class file bytes have been verified or applied.
Using this information I can’t say if it’s possible for method ClassFileTransformer.transform to be called concurrently for the same runtime class (classLoader&className). I understand that method Instrumentation.redefineClasses can be called concurrently for the same class, but this doesn’t mean that such invocation can lead to concurrent invocation of ClassFileTransformer.transform for the same class. Is there some way to clarify my incomprehension?
It’s important in my case, because I use Javassist for transformation and the same instance of CtClass can be used from concurrently running methods ClassFileTransformer.transform. Currently I do all work with CtClass instance within synchronized(ctClass) block, just in case.
I just tried to invoke method
Instrumentation.redefineClassesconcurrently for the same class and checked if my class file transformertransformmethod was invoked concurrently. And the answer is yes,ClassFileTransformer.transformmethods can be invoked by JVM for the same class concurrently.