equal
deleted
inserted
replaced
1218 } |
1218 } |
1219 l = l.tail; |
1219 l = l.tail; |
1220 } |
1220 } |
1221 |
1221 |
1222 // Determine whether to issue a tableswitch or a lookupswitch |
1222 // Determine whether to issue a tableswitch or a lookupswitch |
1223 // instruction. |
1223 // instruction. The difference in computation cost is |
1224 long table_space_cost = 4 + ((long) hi - lo + 1); // words |
1224 // proportional to log(#cases), which is negligable, so we only |
1225 long table_time_cost = 3; // comparisons |
1225 // consider the size of the bytecode. |
1226 long lookup_space_cost = 3 + 2 * (long) nlabels; |
1226 // A discussion of the metric can be found here: |
1227 long lookup_time_cost = nlabels; |
1227 // http://mail.openjdk.java.net/pipermail/compiler-dev/2014-September/008987.html |
1228 int opcode = |
1228 int table_cost = 4 + (hi - lo + 1); // words |
1229 nlabels > 0 && |
1229 int lookup_cost = 3 + 2 * nlabels; |
1230 table_space_cost + 3 * table_time_cost <= |
1230 int opcode = table_cost <= lookup_cost ? tableswitch : lookupswitch; |
1231 lookup_space_cost + 3 * lookup_time_cost |
|
1232 ? |
|
1233 tableswitch : lookupswitch; |
|
1234 |
1231 |
1235 int startpc = code.curCP(); // the position of the selector operation |
1232 int startpc = code.curCP(); // the position of the selector operation |
1236 code.emitop0(opcode); |
1233 code.emitop0(opcode); |
1237 code.align(4); |
1234 code.align(4); |
1238 int tableBase = code.curCP(); // the start of the jump table |
1235 int tableBase = code.curCP(); // the start of the jump table |