8058243: Reduce size of bytecode for large switch statements
Reviewed-by: jjg, vromero
This commit is contained in:
parent
a7b8ca6209
commit
f3201874bc
@ -1220,17 +1220,14 @@ public class Gen extends JCTree.Visitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Determine whether to issue a tableswitch or a lookupswitch
|
// Determine whether to issue a tableswitch or a lookupswitch
|
||||||
// instruction.
|
// instruction. The difference in computation cost is
|
||||||
long table_space_cost = 4 + ((long) hi - lo + 1); // words
|
// proportional to log(#cases), which is negligable, so we only
|
||||||
long table_time_cost = 3; // comparisons
|
// consider the size of the bytecode.
|
||||||
long lookup_space_cost = 3 + 2 * (long) nlabels;
|
// A discussion of the metric can be found here:
|
||||||
long lookup_time_cost = nlabels;
|
// http://mail.openjdk.java.net/pipermail/compiler-dev/2014-September/008987.html
|
||||||
int opcode =
|
int table_cost = 4 + (hi - lo + 1); // words
|
||||||
nlabels > 0 &&
|
int lookup_cost = 3 + 2 * nlabels;
|
||||||
table_space_cost + 3 * table_time_cost <=
|
int opcode = table_cost <= lookup_cost ? tableswitch : lookupswitch;
|
||||||
lookup_space_cost + 3 * lookup_time_cost
|
|
||||||
?
|
|
||||||
tableswitch : lookupswitch;
|
|
||||||
|
|
||||||
int startpc = code.curCP(); // the position of the selector operation
|
int startpc = code.curCP(); // the position of the selector operation
|
||||||
code.emitop0(opcode);
|
code.emitop0(opcode);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user