Click here to Skip to main content
14,265,950 members
Rate this:
Please Sign up or sign in to vote.
See more:
I am trying to implement the invokevirtual instruction in c and even though I have read how theoretically this works, I have trouble to understand what happens when reading an actual ijvm file. In particular, let the following ijvm file:

1d ea df ad 00 01 00 00 00 00 00 04 00 00 00 10
00 00 00 00 00 00 00 1a 10 00 10 00 10 00 10 02
10 03 b6 00 00 10 02 ff 00 03 00 00 15 01 15 02
60 ac

I understand that after 5 bipush instructions (10 00 10 00 10 00 10 02 10 03), the invokevirtual instruction is called (b6 00 00) with an offset of 16 bytes (0x10 read from the cPool) for the method. Once the IRETURN is called (ac), the program should continue from where it was before the method was called for the remaing file (10 02 ff). I also understand that the first 4 bytes of the method (00 03 00 00), provide some information about the number of the parameters (00 03) and the size of the local variable area (00 00).

What is unclear to me is how to read the rest of the method. What I understand is that I should push into the stack an OBJREF and then the method's parameters into the stack, which in this this case are given to be 3, so 4 including the OBJREF in total. But which are specifically these 3 parameters to push in this file? Are the results from the subsequent ILOAD and IADD operations?

What I have tried:

<pre>Could someone please explain me how the stack should look like right before the INVOKEVIRTUAL instruction is called and how after each new instruction from the method ? I would appreciate if you could reference me also to some link with an actual example similar to this. Thank you very much for your time.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100