ASM method attribute and code order

M

MarlonBrando

the asm-guider.pdf said: [This means that annotations and attributes,
if any, must be visited first, followed
by the method’s bytecode]

but when i use it, for example

MethodVisitor mv = new CheckMethodAdapter(cw.visitMethod(
ACC_PUBLIC, "get" + Helper.capitalize(property),
"()Ljava/lang/String;", null, null));
mv.visitAttribute(new MethodAttribute(cw));
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, Type.getType(clazz)
.getInternalName(), property, Type
.getDescriptor(AtomicLong.class));
// mv.visitInsn(LCONST_0);
mv.visitMethodInsn(INVOKEVIRTUAL, Type.getType
(AtomicLong.class)
.getInternalName(), "get", "()J");
mv.visitMethodInsn(INVOKESTATIC, Type.getType(Long.class)
.getInternalName(), "valueOf", "(J)Ljava/lang/
Long;");
mv.visitMethodInsn(INVOKESTATIC, Type.getType
(MonitorUtil.class)
.getInternalName(), "getFormatedMonitor",
"(Ljava/lang/Long;)Ljava/lang/String;");
mv.visitInsn(ARETURN);
mv.visitMaxs(2, 1);
mv.visitEnd();

i found the code order and the attribute order are reverse, using the
bytecode tool [jclasslib]
just looked like this:

...............Methods
+ [o] <init>
- [1] getState
- [0]
org.aspectj.weaver.MethodDeclarationLineNumber
- [1] code

however, it should be :

- [1] getState
- [0] code
- [1]
org.aspectj.weaver.MethodDeclarationLineNumber

plz help me..
 
M

Marcin Rze¼nicki

the asm-guider.pdf said: [This means that annotations and attributes,
if any, must be visited first, followed
by the method’s bytecode]
plz help me..

I am not sure whether I understand fully your problem, but the way I
see it the order of attributes is not important.
 
M

Marcin Rze¼nicki

the asm-guider.pdf said: [This means that annotations and attributes,
if any, must be visited first, followed
by the method’s bytecode]
plz help me..

Google ate my reply. :)
I am not sure if I understand fully your problem, but the way I see it
the order of attributes is not important.
 
M

MarlonBrando

the asm-guider.pdf said: [This means that annotations and attributes,
if any, must be visited first, followed
by the method's bytecode]

but when i use it, for example

MethodVisitor mv = new CheckMethodAdapter(cw.visitMethod(
ACC_PUBLIC, "get" + Helper.capitalize(property),
"()Ljava/lang/String;", null, null));
mv.visitAttribute(new MethodAttribute(cw));
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, Type.getType(clazz)
.getInternalName(), property, Type
.getDescriptor(AtomicLong.class));
// mv.visitInsn(LCONST_0);
mv.visitMethodInsn(INVOKEVIRTUAL, Type.getType
(AtomicLong.class)
.getInternalName(), "get", "()J");
mv.visitMethodInsn(INVOKESTATIC, Type.getType(Long.class)
.getInternalName(), "valueOf", "(J)Ljava/lang/
Long;");
mv.visitMethodInsn(INVOKESTATIC, Type.getType
(MonitorUtil.class)
.getInternalName(), "getFormatedMonitor",
"(Ljava/lang/Long;)Ljava/lang/String;");
mv.visitInsn(ARETURN);
mv.visitMaxs(2, 1);
mv.visitEnd();

i found the code order and the attribute order are reverse, using the
bytecode tool [jclasslib]
just looked like this:

..............Methods
+ [o] <init>
- [1] getState
- [0]
org.aspectj.weaver.MethodDeclarationLineNumber
- [1] code

however, it should be :

- [1] getState
- [0] code
- [1]
org.aspectj.weaver.MethodDeclarationLineNumber

plz help me..

order is not problem.

i wrote a interface in bytecode. oops
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top