# 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.

## 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" ...

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

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!

1. 1
2. 2
Rutin
21
3. 3
4. 4
frob
18
5. 5

• 33
• 13
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
632562
• Total Posts
3007095

×