Pier-Alexandre Bouchard
Pier-Alexandre Bouchard

Reputation: 5235

ByteCode Instructions: Do I understand well

I am learning about Java Bytecodes. I would like to know if I am understand correctly this bytecode process

I did not finished, but It is just to begin on the good way..

00000000    aload_0 
// load param1 (String)
// Stack is [StringParam]
00000001    invokevirtual       char[] java.lang.String.toCharArray() 
// split variable in an array of char
// Stack is [ReferenceToCharArray] ?
00000004    dup 
// duplicate the top of operand stack and put it back at the end
// Stack is now [ReferenceToCharArray ReferenceToCharArray]
00000005    arraylength 
// Return array's length
// Stack is now [ReferenceToCharArray ArrayLength]
00000006    iconst_2 
// push 2 in stack
// Stack is now [ReferenceToCharArray ArrayLength 2]
00000007    if_icmpge           pos.00000013
// If the Array length is greater or equals to 2
// Stack is now [ReferenceToCharArray]
00000013    areturn
// Return the array
// Stack is empty

Upvotes: 0

Views: 184

Answers (1)

antlersoft
antlersoft

Reputation: 14786

Your stack is wrong after the invoke virtual, param1 is no longer top of stack. And I don't think 3 ever gets put on the stack.

What the if_icmpge is really doing is comparing the length of the char array returned by the invokevirtual to 2

Upvotes: 1

Related Questions