Re: Re: Re: Unexpected InternalName format on Enum classes
Freddy Mallet <[email protected]>
| Newsgroups | gmane.comp.java.objectweb.asm |
|---|---|
| Message-ID | <[email protected]> |
Thanks a lot for your help Eugene and Rémi, I've now a clear understanding of what happens ! ---------------------------------------- Freddy Mallet www.SonarSource.org www.SonarSource.com http://twitter.com/FreddyMallet ---------------------------------------- On Thu, Jul 22, 2010 at 9:26 PM, Rémi Forax <[email protected]> wrote: > Le 22/07/2010 15:36, Eugene Kuleshov a écrit : > > I wonder how did you got such bytecode for values() method... When > compiled with Java 1.6 it doesn't have clone() and there is an array > copy is used. > > > > Eclipse ecj uses arraycopy and javac uses clone. > Eclipse compiler does that because instrinsics for clone was > added recently see http://bugs.sun.com/view_bug.do?bug_id=6428387 > Before this fix clone was slower than arraycopy. > > Calling clone() on an array is legal, as far as I remember > the support of array.clone was added during one update of 1.4 > because jikes (remember, the java compiler written in C++) > was the first to generate this kind of code > (legal from the JVMS point of view). > > > Anyways, your test can be shortened to something like this: > > public final class TestClass { > public class MyEnum { > MyEnum[] values; > public MyEnum[] values() { > return values.clone(); > } > } > } > > The corresponding ASM code for this method look like this: > > mv = cw.visitMethod(ACC_PUBLIC, "values", > "()[Ltest/TestClass$MyEnum;", null, null); > mv.visitCode(); > mv.visitVarInsn(ALOAD, 0); > mv.visitFieldInsn(GETFIELD, "test/TestClass$MyEnum", "values", > "[Ltest/TestClass$MyEnum;"); > mv.visitMethodInsn(INVOKEVIRTUAL, "[Ltest/TestClass$MyEnum;", "clone", > "()Ljava/lang/Object;"); > mv.visitTypeInsn(CHECKCAST, "[Ltest/TestClass$MyEnum;"); > mv.visitInsn(ARETURN); > mv.visitMaxs(1, 1); > mv.visitEnd(); > > The owner in INVOKEVIRTUAL is not test/TestClass$MyEnum, but an > array of test/TestClass$MyEnum, so when trying to get this class you > need to check if argument is an array and use Type.getElementType() to > extract the actual array element type. Try something like > > Type t = Type.getType("[[Ltest/TestClass$ > if(t.getSort()==Type.ARRAY) { > System.err.println(t.getElementType().getInternalName()); > } > > regards, > Eugene > > > On Thu, Jul 22, 2010 at 8:14 AM, Freddy Mallet <[email protected]> <[email protected]> wrote: > > > Hi all, > I'm one of the developers of the open source Sonar quality platform > (www.sonarsource.org) and we use ASM to generate some O.O. metrics and > understand the global architecture of a project. > I'm currently facing a little issue when analyzing java enumerations (seehttp://jira.codehaus.org/browse/SONAR-1638). Indeed, the bytecode contains > some use of INVOKEVIRTUAL instruction with an unexpected format (at least > for me) : > > INVOKEVIRTUAL [LspecialCases/ClassWithEnum$MyEnum;.clone > ()Ljava/lang/Object; > > In that case, I expect to get : > > INVOKEVIRTUAL specialCases/ClassWithEnum$MyEnum.clone ()Ljava/lang/Object > > Indeed, when my implementation of the VisitMethod interface is called back > on the method visitMethodInsn(int opcode, String owner, String name, String > desc); > and in that case the argument "owner" equals to > "[LspecialCases/ClassWithEnum$MyEnum;" where I expect to get the internal > name "specialCases/ClassWithEnum$MyEnum" > Does it means that I need to always check the format of the "owner" argument > before doing anything ? > Thanks for your help, > Freddy > > > > Rémi > > > -- > 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 > >
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