Jump to content
  • Advertisement
Sign in to follow this  
Harry Hunt

Typed load/store instructions for local variables

This topic is 4141 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! I have noticed something about Java bytecode that really confuses me. There are a series of instructions in Java bytecode for loading specific constants onto the operand stack, something along the lines of
iconst_1 // Loads integer "1" onto the stack
fconst_1 // Loads float "1" ...
dconst_1 // Loads double "1"
As you can see, all of these instructions are "typed" which makes sense since an integer "1" doesn't have the same representation as a floating point "1" and also because int/float and long/double are of different sizes. Java bytecode also has a couple of instructions that load constants from a so called constant pool (aka symbol table) onto the stack. The instructions are
ldc // Load 32 bit constant
ldc_w // Load 64 bit constant
As you can see, a distinction is made between 32 bit and 64 bit constants, but not between the various types. Again, that makes sense because loading a constant from the constant pool is merely a memory copy operation. So far so good. What confuses me though is, that the instructions for loading local variables unlinke the const-loading instructions are fully typed again:
iload_1 // Load int local variable at offset 1
dload_2 // Load double local variable at offset 2
As far as I understand it, having two different instructions for loading 32 bit and 64 bit values onto the stack should be sufficient. Especially since all arithmetic instructions are also typed. So now I'm wondering, what the point of this is. My guess is, they use the type information in the JIT-compiler to rebuild the AST and so they can perform better optimization. But of course that's just a guess. Anyone got a better explanation? Thanks a lot in advance!

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!