java code : ,
byte a_b = 12;
short c_d = 14
replaces in bytecodes with
bipush 12 // expands byte1 (a byte type) to an int and pushes it onto the stack
sipush 14 // expands byte1, byte2 (a short type) to an int and pushes it onto the stack
Why jvm does that expansion, and not use byte & short ?
Also when i open bytecode of my file
EDIT : short var = 14 is replaced by bipush 14 rather than sipush 14
Is my understanding is not clear or is there a bug ?
I am using following version
java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java HotSpot(TM) Client VM (build 20.1-b02, mixed mode, sharing)
Because (conceptually) the smallest unit of data on the JVM stack is 32 bits. So there is no way to increase the size of the stack with just 8 bits.
http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-2.html#jvms-2.6.2
At any point in time, an operand stack has an associated depth, where a value of type long or double contributes two units to the depth and a value of any other type contributes one unit.