mnemonics<->opcodes map and format of output of the javap utility

A

Albretch

which official documentation I can't find posted by Sun anywhere:

Say you have this (real) output from a class

. . .
0: aload_0
1: arraylength
2: iconst_1
3: if_icmpge 18
6: getstatic #2; //Field java/lang/System.out:Ljava/io/PrintStream;
9: ldc #3; //String input file missing!
. . .

This is how I think things work:

1._ the first number is the offset in the operand stack
2._ then comes the opcode's mnemonic
3._ then depending on the instruction comes a reference, which
3.1_ when prefixed by '#' represents the line number in the methods code section
3.2_ otherwise the valid offset of the operand stack processing should continue


Also I found what apparently looks like new mnemonics/opcodes, e.g.; "invokespecial"

I knew of the following

{"invokevirtual","182"},
{"invokenonvirtual","183"},
{"invokestatic","184"},
{"invokeinterface","185"},

what is the opcode for "invokespecial"?

Where can you find 'the' table mapping opcode's - mnemonic?
 
A

Albretch

OK, I see Sun has been fooling around renaming the mnemonics.

I had always understood the mnemonics<->opcodes mapping to be a 1 to
1 one.

I had first gone and checked the link you provided me with, but could
not find a single reference to the 'depreceated' mnemonic
'invokenonvirtual'

I wonder which other ones might be renamed now or in the future

Also, does anyone know about the format of the javap output (better
than what you get by trying its command line switches)?
 
M

Martin Schoeberl

{"invokevirtual","182"},
{"invokenonvirtual","183"},
{"invokestatic","184"},
{"invokeinterface","185"},

what is the opcode for "invokespecial"?

'invokespecial' is 183, there is no 'invokenonvirtual' in the JVM
specification.

Martin
 
L

Larry Barowski

Albretch said:
OK, I see Sun has been fooling around renaming the mnemonics.

I had always understood the mnemonics<->opcodes mapping to be a 1 to
1 one.

I had first gone and checked the link you provided me with, but could
not find a single reference to the 'depreceated' mnemonic
'invokenonvirtual'

It is not deprecated - it has become 'invokespecial'. If the ACC_SUPER
flag is not set for the class, this instruction behaves in the old way, as
a non-virtual invoke. This was changed because implementing a super
call with a non-virtual invoke can fail or behave incorrectly at runtime
if the parent/ancestor classes are not the same as they were at compile
time (since the nearest ancestor class for which the method exists may
change - which should be allowed). So with ACC_SUPER set,
invokespecial can only be used for super, private, and init method
invocations - but it now does the "right" thing for super calls.
 

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,754
Messages
2,569,525
Members
44,997
Latest member
mileyka

Latest Threads

Top