RE: ASM-based class transformation affect class loading?
"Tim Eck" <[email protected]>
| Newsgroups | gmane.comp.java.objectweb.asm |
|---|---|
| Message-ID | <00b201cb3330$b7515a80$25f40f80$@com> |
I'm not entirely sure if this is your problem or not, but one lesser known things about ClassFileTransformer agents is that they are not reentrant. If the course of instrumenting a class (ie. within your transform() method) you cause another class load then the transformer will be skipped. If your transform loads other types (for verification or other purposes) then you might miss types. For the classes that are missing you might want to set a breakpoint on your c lassloader to see if it is being loaded in the context of transforming some other type. Once you know the call stack causing it you can work on trying to fix it :-) From: Sai Zhang [mailto:[email protected]] Sent: Tuesday, August 03, 2010 8:49 AM To: asm Subject: [asm] ASM-based class transformation affect class loading? Hi all: I met a strange problem when using ASM to transform my client code at load time (excluding all JDK code already). It seems that my transformer is highly likely to affect the class loading process. Please refer to the simple code below for illustration: Here is my simple ClassFileTransformer for load time class transformation, all transformation operations are in the treeAPITransform(byte[]) method. It is actually a fairly simple intra-method transformation based on the "tree api" of ASM (just adding tracing method at the begin/end of each method call) @Override public byte[] transform(ClassLoader loader, String className, Class<?> clazz, ProtectionDomain domain, byte[] bytes) { //code omitted here, for excluding all JDK classes /*I print each loaded class for debugging */ (1) System.err.println("---- load class: " + className); try { (2) return this.treeAPITransform(bytes); //my simple transformation implementation } catch (Exception e) { e.printStackTrace(); return null; } } The weird thing is that statement (1) does not print out some obviously loaded classes (which has definitely been initialized and executed). If I remove statement (2), or change that to "return null", every thing OK. all classes loaded are printed out at statement (1). I feel very confused on this point. I am wondering will ASM-based intra-method transformation affect the class loading? or did I instrument some extra classes by accident? or I should not use the tree api? or there is any tricks on this point? P.S. I use the ClassCheckerAdapter in ASM to check the validity of transformed bytecode after transformation. and no error messages are issued. thanks. Any comments are highly appreciated!!! -Sai
message-footer.txt
(text/plain, 238 B)
-- You receive this message as a subscriber of the [email protected] mailing list. To unsubscribe: mailto:[email protected] For general help: mailto:[email protected]?subject=help OW2 mailing lists service home page: http://www.ow2.org/wws