Re: Show stack objects/instructions

Rémi Forax <[email protected]>
Newsgroups gmane.comp.java.objectweb.asm
Message-ID <[email protected]>
On 03/27/2011 11:57 PM, [email protected] wrote:
> hi,
>
> is there any posibility to generate/display stack or instructions which added
> elements to stack from actual instruction?
>
> regards

PrintWriter pw = new PrintWriter(System.out);
CheckClassAdapter.verify(new ClassReader(byteArray), true, pw);

with byteArray containing the actual bytecode.

You will get something like the code below:
main([Ljava/lang/String;)V
00000 String . .  :  :     NEW java/lang/Object
00001 String . .  : Object  :     ASTORE 1
00002 String Object .  :  :     ALOAD 1
00003 String Object .  : Object  :     INVOKESPECIAL 
java/lang/Object.<init> ()V
00004 String Object .  :  :     ALOAD 1
00005 String Object .  : Object  :     IFNONNULL L0
00006 String Object .  :  :     GETSTATIC java/lang/System.out : 
Ljava/io/PrintStream;
00007 String Object .  : PrintStream  :     ASTORE 1
00008 String PrintStream .  :  :     LDC "null !"
00009 String PrintStream .  : String  :     ASTORE 2
00010 String PrintStream String  :  :     ALOAD 1
00011 String PrintStream String  : PrintStream  :     ALOAD 2
00012 String PrintStream String  : PrintStream String  :     
INVOKEVIRTUAL java/io/PrintStream.println (Ljava/lang/String;)V
00013 String PrintStream String  :  :    L1
00014 String PrintStream String  :  :     RETURN
00015 String Object .  :  :    L0
00016 String Object .  :  :     GETSTATIC java/lang/System.out : 
Ljava/io/PrintStream;
00017 String Object .  : PrintStream  :     ASTORE 1
00018 String PrintStream .  :  :     LDC "not null !"
00019 String PrintStream .  : String  :     ASTORE 2
00020 String PrintStream String  :  :     ALOAD 1
00021 String PrintStream String  : PrintStream  :     ALOAD 2
00022 String PrintStream String  : PrintStream String  :     
INVOKEVIRTUAL java/io/PrintStream.println (Ljava/lang/String;)V
00023 String PrintStream String  :  :     GOTO L1

To decode it:
   String . . : : NEW java/lang/Object
means:
   String . . : we have 3 locals, the first one contains a String the 
others are uninitialized
   :               empty stack

Rémi
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.