Difference between JVM's LookupSwitch and TableSwitch?

前端 未结 4 815
花落未央
花落未央 2020-11-27 11:05

I have some difficulty to understand LookUpSwitch and TableSwitch in Java bytecode.

If I understand well, both LookUpSwitch and TableSwitch correspond to the s

4条回答
  •  一整个雨季
    2020-11-27 12:08

    I suspect it is mostly historical, due to some specific binding of Java bytecode to underlying machine code (e.g. Sun's own CPU).

    The tableswitch is essentially a computed jump, where destination is taken from a lookup table. By contrast, lookupswitch requires comparison of each value, basically an iteration trough table elements until matching value is found.

    Obviously those opcodes are interchangeable, but based on values, one or the other could be faster or more compact (e.g. compare set of keys with large gaps in between and a sequential set of keys).

提交回复
热议问题