Clement Escoffier | 2 Feb 09:26
Picon
Gravatar

Re: Frames computation with ClassWriter.getCommonSuperClass()

Hi,

On 30.01.2012, at 22:01, Eugene Kuleshov wrote:

> Clement,
> 
>  In your case, because you are introducing new variables and new
> values on the stack, the visitFrame call will have to take into
> account the current state of locals and stack. Normally you need to
> pass EXPAND_FRAMES to the  ClassReader.accept() call and then keep the
> current state of locals and stack based on visitFrame() events
> received by your own visitor and then merge it with your own added
> locals and stack.
> 

It's what I'm doing.

>  Naturally, when using any subclass of the LocalVariableSorter, you
> should be calling super.visitXXX() method instead of mv.visitXXX().
> 

I'm using a GeneratorAdapter directly. So, no inheritance.

>  To get some more details about bytecode validity you can use
> CheckClassAdapter, though it is not taking frames into the account,
> but you can compare its output with your own expectations for those
> frames.

I'm using it (actually, the CheckClassAdapter is enabled automatically when running my tests (just to
check). But as you said, it does not check the frames, so I always run into this Verifier error at runtime
(Continue reading)

Eugene Kuleshov | 2 Feb 14:37
Picon
Gravatar

Re: Frames computation with ClassWriter.getCommonSuperClass()

On Thu, Feb 2, 2012 at 3:26 AM, Clement Escoffier
<clement.escoffier <at> gmail.com> wrote:

>>  Naturally, when using any subclass of the LocalVariableSorter, you
>> should be calling super.visitXXX() method instead of mv.visitXXX().
> I'm using a GeneratorAdapter directly. So, no inheritance.

  GeneratorAdapter is a subclass of the LocalVariableSorter.

>>  To get some more details about bytecode validity you can use
>> CheckClassAdapter, though it is not taking frames into the account,
>> but you can compare its output with your own expectations for those
>> frames.
>
> I'm using it (actually, the CheckClassAdapter is enabled automatically when running my tests (just to
check). But as you said, it does not check the frames, so I always run into this Verifier error at runtime
without any details making clear from where it comes.

  It does not verify STACK_MAP info, but it can print out the frames.
http://asm.ow2.org/asm40/javadoc/user/org/objectweb/asm/util/CheckClassAdapter.html

  regards,
  Eugene

--

-- 
You receive this message as a subscriber of the asm <at> ow2.org mailing list.
To unsubscribe: mailto:asm-unsubscribe <at> ow2.org
For general help: mailto:sympa <at> ow2.org?subject=help
(Continue reading)

theUser BL | 8 Feb 00:46
Picon
Favicon

Problem with visitLineNumber()


Hi!

This is my test-program:
------------------------------------
public class TestProgram {

  int GlobalVaribale1 = 5;
  double GlobalVariable2 = 14.3;

  public static void rectangle(int left, int right, int width, int height) {

    // calculate something

    int result = 5;
    int tmp;

    result=left+width;
    tmp=width+height;

    result *= tmp;

    System.out.println("The result is: " + result); 

  }

}
-------------------------------------
compiled with ASM and decompiled with ASMifier and added some debug-information myself, it looks like

(Continue reading)

Eliot Moss | 8 Feb 02:33
Picon
Favicon

Re: Problem with visitLineNumber()

On 2/7/2012 6:46 PM, theUser BL wrote:

> compiled with ASM and decompiled with ASMifier and added some debug-information myself, it looks like

ASM is not a compiler, it is a bytecode transforming tool.
It must have been working on a .class file compiled by
javac (or some other Java compiler) from the source you
showed us.

If you just want to see bytecode in a (more or less)
human readable form, the javap program, which comes
with the Oracle(/Sun) JDK (though not, I think, the
JRE) can do that.

Just below shows where your code visited the static initializer.
The compiler synthesized it from the various initializations you
provide, and I guess does not supply line numbers for those.

> mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
> mv.visitCode();
> mv.visitVarInsn(ALOAD, 0);
> mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
> mv.visitVarInsn(ALOAD, 0);
> mv.visitInsn(ICONST_5);
> mv.visitFieldInsn(PUTFIELD, "TestProgram", "GlobalVaribale1", "I");
> mv.visitVarInsn(ALOAD, 0);
> mv.visitLdcInsn(new Double("14.3"));
> mv.visitFieldInsn(PUTFIELD, "TestProgram", "GlobalVariable2", "D");
> mv.visitInsn(RETURN);
> mv.visitMaxs(3, 1);
(Continue reading)

theUser BL | 8 Feb 08:14
Picon
Favicon

RE: Problem with visitLineNumber()


> > compiled with ASM and decompiled with ASMifier and added some debug-information myself, it looks like
>
> ASM is not a compiler, it is a bytecode transforming tool.

I know. But I don't know how to better describe the ASMifier functioality. So have have written here, that I
have "decompiled" the code with ASMifier.

> It must have been working on a .class file compiled by
> javac (or some other Java compiler) from the source you
> showed us.

ASM itselof can create *.class files at its own. And that is what I'm doing. I use it do write a compiler.
Only ASMifier nedded an existing class file. And the sourcecode of that file, I have shown you at the
beginning of my last mail.

> If you just want to see bytecode in a (more or less)
> human readable form, the javap program, which comes
> with the Oracle(/Sun) JDK (though not, I think, the
> JRE) can do that.

I know.

> Just below shows where your code visited the static initializer.
> The compiler synthesized it from the various initializations you
> provide, and I guess does not supply line numbers for those.

I know.

> Just below is where your code visited your rectangle method,
(Continue reading)

theUser BL | 8 Feb 11:15
Picon
Favicon

RE: RE: Problem with visitLineNumber() [solved]


Ok, my fault.
I have forgotten to call visitLabel.

So with an

> Label line010 = new Label();
> my. visitLabel(line10);
> mv.visitLineNumber(10, line010);
> mv.visitInsn(ICONST_5);
> mv.visitVarInsn(ISTORE, 4);
> mv.visitVarInsn(ILOAD, 0);
> mv.visitVarInsn(ILOAD, 2);

It works.

Greatings
theuserbl
 		 	   		  

--

-- 
You receive this message as a subscriber of the asm <at> ow2.org mailing list.
To unsubscribe: mailto:asm-unsubscribe <at> ow2.org
For general help: mailto:sympa <at> ow2.org?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
Eliot Moss | 8 Feb 12:57
Picon
Favicon

Re: Problem with visitLineNumber()

On 2/8/2012 2:14 AM, theUser BL wrote:

I think I am understanding better your intent:
You are using ASM in the back-end of a compiler,
to create a properly-formed class file for the
compiler's output.

>>> Label line010 = new Label();
>>> mv.visitLineNumber(10, line010);
>>> mv.visitInsn(ICONST_5);
>>> mv.visitVarInsn(ISTORE, 4);
>>> mv.visitVarInsn(ILOAD, 0);
>>> mv.visitVarInsn(ILOAD, 2);

You create a Label, and mention it in visitLineNumber,
but you never visit the Label itself, which is what
would place it in the code stream.

Regards -- Eliot Moss

--

-- 
You receive this message as a subscriber of the asm <at> ow2.org mailing list.
To unsubscribe: mailto:asm-unsubscribe <at> ow2.org
For general help: mailto:sympa <at> ow2.org?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
Eliot Moss | 8 Feb 13:06
Picon
Favicon

Re: RE: RE: Problem with visitLineNumber() [solved]

On 2/8/2012 5:15 AM, theUser BL wrote:
>
> Ok, my fault.
> I have forgotten to call visitLabel.

Our messages crossed; good job figuring it out!   EM

--

-- 
You receive this message as a subscriber of the asm <at> ow2.org mailing list.
To unsubscribe: mailto:asm-unsubscribe <at> ow2.org
For general help: mailto:sympa <at> ow2.org?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
Jochen Theodorou | 10 Feb 16:52
Picon
Gravatar

some strange bytecode in asm 4.0

Hi all,

I noticed I have suddenly in my bytecode things like this appearing:

>    L5
>    FRAME FULL [] [java/lang/Throwable]
>     NOP
>     NOP
>     ATHROW

This looks a bit like an exception handler, only the exception table has 
no entry for this. There is no usage of that label and I am pretty sure, 
that my code does not generate this. I checked my code that still uses 
the 3.x asm and it does not appear there. The big difference between the 
older version and this version is only that I now use stack frames.

I use the ClassWriter with automatic computing of stack frames and maxs, 
the only change I made here is that I use a custom getCommonSuperClass

Now... is that code part somehow related to computing frames? Is it 
something else? Is it even needed (looks like dead code to me)? Or is it 
a bug?

bye Jochen

--

-- 
Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
blog: http://blackdragsview.blogspot.com/
german groovy discussion newsgroup: de.comp.lang.misc
For Groovy programming sources visit http://groovy-lang.org
(Continue reading)

Rémi Forax | 10 Feb 17:45
Picon

Re: some strange bytecode in asm 4.0

On 02/10/2012 04:52 PM, Jochen Theodorou wrote:
> Hi all,

Hi Jochen,

>
>
> I noticed I have suddenly in my bytecode things like this appearing:
>
>>    L5
>>    FRAME FULL [] [java/lang/Throwable]
>>     NOP
>>     NOP
>>     ATHROW
>
> This looks a bit like an exception handler, only the exception table 
> has no entry for this. There is no usage of that label and I am pretty 
> sure, that my code does not generate this. I checked my code that 
> still uses the 3.x asm and it does not appear there. The big 
> difference between the older version and this version is only that I 
> now use stack frames.
>
> I use the ClassWriter with automatic computing of stack frames and 
> maxs, the only change I made here is that I use a custom 
> getCommonSuperClass
>
> Now... is that code part somehow related to computing frames?

yes.
It's the famous nop, nop, athrow, see section 3.5.4 (Dead code)
(Continue reading)


Gmane