Mercurial > hg > graal-compiler
comparison graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java @ 2741:a3cd5eb68837
more GraphBuilder cleanup, moved mergeOrClone to GraphBuilder
author | Lukas Stadler <lukas.stadler@jku.at> |
---|---|
date | Fri, 20 May 2011 11:11:33 +0200 |
parents | d913f3049cee |
children | 05c92e53a50d 0fe79e7435c3 |
comparison
equal
deleted
inserted
replaced
2736:03b80fb10ae9 | 2741:a3cd5eb68837 |
---|---|
102 private int flags; | 102 private int flags; |
103 | 103 |
104 // Exception handler list | 104 // Exception handler list |
105 private List<ExceptionHandler> exceptionHandlers; | 105 private List<ExceptionHandler> exceptionHandlers; |
106 | 106 |
107 private Block curBlock; // the current block | |
108 private final FrameStateBuilder frameState; // the current execution state | 107 private final FrameStateBuilder frameState; // the current execution state |
109 private Instruction lastInstr; // the last instruction added | 108 private Instruction lastInstr; // the last instruction added |
110 private Instruction placeholder; | 109 private Instruction placeholder; |
111 | 110 |
112 | 111 |
180 Block startBlock = nextBlock(Instruction.SYNCHRONIZATION_ENTRY_BCI); | 179 Block startBlock = nextBlock(Instruction.SYNCHRONIZATION_ENTRY_BCI); |
181 BlockBegin startBlockBegin = new BlockBegin(0, startBlock.blockID, graph); | 180 BlockBegin startBlockBegin = new BlockBegin(0, startBlock.blockID, graph); |
182 startBlock.firstInstruction = startBlockBegin; | 181 startBlock.firstInstruction = startBlockBegin; |
183 | 182 |
184 graph.root().setStart(startBlockBegin); | 183 graph.root().setStart(startBlockBegin); |
185 curBlock = startBlock; | |
186 | 184 |
187 RiExceptionHandler[] handlers = rootMethod.exceptionHandlers(); | 185 RiExceptionHandler[] handlers = rootMethod.exceptionHandlers(); |
188 if (handlers != null && handlers.length > 0) { | 186 if (handlers != null && handlers.length > 0) { |
189 exceptionHandlers = new ArrayList<ExceptionHandler>(handlers.length); | 187 exceptionHandlers = new ArrayList<ExceptionHandler>(handlers.length); |
190 for (RiExceptionHandler ch : handlers) { | 188 for (RiExceptionHandler ch : handlers) { |
198 } | 196 } |
199 flags |= Flag.HasHandler.mask; | 197 flags |= Flag.HasHandler.mask; |
200 } | 198 } |
201 | 199 |
202 assert !loopHeaders.contains(startBlock); | 200 assert !loopHeaders.contains(startBlock); |
203 startBlockBegin.mergeOrClone(frameState, rootMethod, false); | 201 mergeOrClone(startBlockBegin, frameState, false); |
204 | 202 |
205 // 3. setup internal state for appending instructions | 203 // 3. setup internal state for appending instructions |
206 curBlock = startBlock; | |
207 lastInstr = startBlockBegin; | 204 lastInstr = startBlockBegin; |
208 lastInstr.appendNext(null); | 205 lastInstr.appendNext(null); |
209 | 206 |
210 Instruction entryBlock = blockAt(0); | 207 Instruction entryBlock = blockAt(0); |
211 BlockBegin syncHandler = null; | 208 BlockBegin syncHandler = null; |
271 return blocksVisited.contains(block); | 268 return blocksVisited.contains(block); |
272 } | 269 } |
273 | 270 |
274 private void finishStartBlock(BlockBegin startBlock, Instruction stdEntry) { | 271 private void finishStartBlock(BlockBegin startBlock, Instruction stdEntry) { |
275 assert bci() == 0; | 272 assert bci() == 0; |
276 assert curBlock.firstInstruction == startBlock; | |
277 FrameState stateAfter = frameState.create(bci()); | 273 FrameState stateAfter = frameState.create(bci()); |
278 Goto base = new Goto((BlockBegin) stdEntry, stateAfter, graph); | 274 Goto base = new Goto((BlockBegin) stdEntry, stateAfter, graph); |
279 appendWithBCI(base); | 275 appendWithBCI(base); |
280 startBlock.setEnd(base); | 276 startBlock.setEnd(base); |
281 // assert stdEntry instanceof Placeholder; | 277 // assert stdEntry instanceof Placeholder; |
282 assert ((BlockBegin) stdEntry).stateBefore() == null; | 278 assert ((BlockBegin) stdEntry).stateBefore() == null; |
283 prepareTarget(0); | 279 prepareTarget(0); |
284 mergeOrClone(stdEntry, stateAfter, method(), loopHeaders.contains(stdEntry)); | 280 mergeOrClone(stdEntry, stateAfter, loopHeaders.contains(stdEntry)); |
285 } | 281 } |
286 | 282 |
287 private void prepareTarget(int bci) { | 283 private void prepareTarget(int bci) { |
288 } | 284 } |
289 | 285 |
290 private void mergeOrClone(Instruction block, FrameState stateAfter, RiMethod method, boolean loopHeader) { | 286 |
291 ((BlockBegin) block).mergeOrClone(stateAfter, method, loopHeader); | 287 public void mergeOrClone(Block target, FrameStateAccess newState) { |
288 if (target.isLoopHeader) { | |
289 assert target.firstInstruction instanceof BlockBegin; | |
290 mergeOrClone(target.firstInstruction, newState, true); | |
291 | |
292 | |
293 } | |
294 } | |
295 | |
296 | |
297 private void mergeOrClone(Instruction first, FrameStateAccess stateAfter, boolean loopHeader) { | |
298 if (first instanceof BlockBegin) { | |
299 BlockBegin block = (BlockBegin) first; | |
300 FrameState existingState = block.stateBefore(); | |
301 | |
302 if (existingState == null) { | |
303 // copy state because it is modified | |
304 FrameState duplicate = stateAfter.duplicate(block.bci()); | |
305 | |
306 // if the block is a loop header, insert all necessary phis | |
307 if (loopHeader) { | |
308 insertLoopPhis(block, duplicate); | |
309 } | |
310 | |
311 block.setStateBefore(duplicate); | |
312 } else { | |
313 if (!C1XOptions.AssumeVerifiedBytecode && !existingState.isCompatibleWith(stateAfter)) { | |
314 // stacks or locks do not match--bytecodes would not verify | |
315 throw new CiBailout("stack or locks do not match"); | |
316 } | |
317 | |
318 assert existingState.localsSize() == stateAfter.localsSize(); | |
319 assert existingState.stackSize() == stateAfter.stackSize(); | |
320 | |
321 existingState.merge(block, stateAfter); | |
322 } | |
323 } else { | |
324 assert false; | |
325 } | |
326 } | |
327 | |
328 private void insertLoopPhis(BlockBegin merge, FrameState newState) { | |
329 int stackSize = newState.stackSize(); | |
330 for (int i = 0; i < stackSize; i++) { | |
331 // always insert phis for the stack | |
332 newState.setupPhiForStack(merge, i); | |
333 } | |
334 int localsSize = newState.localsSize(); | |
335 for (int i = 0; i < localsSize; i++) { | |
336 Value x = newState.localAt(i); | |
337 if (x != null) { | |
338 newState.setupPhiForLocal(merge, i); | |
339 } | |
340 } | |
292 } | 341 } |
293 | 342 |
294 public RiMethod method() { | 343 public RiMethod method() { |
295 return compilation.method; | 344 return compilation.method; |
296 } | 345 } |
299 return stream; | 348 return stream; |
300 } | 349 } |
301 | 350 |
302 public int bci() { | 351 public int bci() { |
303 return stream.currentBCI(); | 352 return stream.currentBCI(); |
304 } | |
305 | |
306 public int nextBCI() { | |
307 return stream.nextBCI(); | |
308 } | 353 } |
309 | 354 |
310 private void loadLocal(int index, CiKind kind) { | 355 private void loadLocal(int index, CiKind kind) { |
311 frameState.push(kind, frameState.loadLocal(index)); | 356 frameState.push(kind, frameState.loadLocal(index)); |
312 } | 357 } |
419 private void updateDispatchChain(BlockBegin dispatchEntry, FrameStateAccess state, int bci) { | 464 private void updateDispatchChain(BlockBegin dispatchEntry, FrameStateAccess state, int bci) { |
420 FrameState oldState = dispatchEntry.stateBefore(); | 465 FrameState oldState = dispatchEntry.stateBefore(); |
421 if (oldState != null && dispatchEntry.predecessors().size() == 1) { | 466 if (oldState != null && dispatchEntry.predecessors().size() == 1) { |
422 dispatchEntry.setStateBefore(null); | 467 dispatchEntry.setStateBefore(null); |
423 } | 468 } |
424 dispatchEntry.mergeOrClone(state, null, false); | 469 mergeOrClone(dispatchEntry, state, false); |
425 FrameState mergedState = dispatchEntry.stateBefore(); | 470 FrameState mergedState = dispatchEntry.stateBefore(); |
426 | 471 |
427 if (dispatchEntry.next() instanceof ExceptionDispatch) { | 472 if (dispatchEntry.next() instanceof ExceptionDispatch) { |
428 // ordinary dispatch handler | 473 // ordinary dispatch handler |
429 ExceptionDispatch dispatch = (ExceptionDispatch) dispatchEntry.next(); | 474 ExceptionDispatch dispatch = (ExceptionDispatch) dispatchEntry.next(); |
642 Value y = append(Constant.forInt(delta, graph)); | 687 Value y = append(Constant.forInt(delta, graph)); |
643 frameState.storeLocal(index, append(new ArithmeticOp(IADD, CiKind.Int, x, y, isStrict(method().accessFlags()), false, graph))); | 688 frameState.storeLocal(index, append(new ArithmeticOp(IADD, CiKind.Int, x, y, isStrict(method().accessFlags()), false, graph))); |
644 } | 689 } |
645 | 690 |
646 private void genGoto(int fromBCI, int toBCI) { | 691 private void genGoto(int fromBCI, int toBCI) { |
647 append(new Goto((BlockBegin) blockAt(toBCI), null, graph)); | 692 append(new Goto((BlockBegin) createTargetAt(toBCI, frameState), null, graph)); |
648 } | 693 } |
649 | 694 |
650 private void ifNode(Value x, Condition cond, Value y, FrameState stateBefore) { | 695 private void ifNode(Value x, Condition cond, Value y) { |
651 Instruction tsucc = blockAt(stream().readBranchDest()); | 696 Instruction tsucc = createTargetAt(stream().readBranchDest(), frameState); |
652 Instruction fsucc = blockAt(stream().nextBCI()); | 697 Instruction fsucc = createTargetAt(stream().nextBCI(), frameState); |
653 append(new If(x, cond, y, (BlockBegin) tsucc, (BlockBegin) fsucc, null, graph)); | 698 append(new If(x, cond, y, (BlockBegin) tsucc, (BlockBegin) fsucc, null, graph)); |
654 stateBefore.delete(); | |
655 } | 699 } |
656 | 700 |
657 private void genIfZero(Condition cond) { | 701 private void genIfZero(Condition cond) { |
658 Value y = appendConstant(CiConstant.INT_0); | 702 Value y = appendConstant(CiConstant.INT_0); |
659 FrameState stateBefore = frameState.create(bci()); | |
660 Value x = frameState.ipop(); | 703 Value x = frameState.ipop(); |
661 ifNode(x, cond, y, stateBefore); | 704 ifNode(x, cond, y); |
662 } | 705 } |
663 | 706 |
664 private void genIfNull(Condition cond) { | 707 private void genIfNull(Condition cond) { |
665 FrameState stateBefore = frameState.create(bci()); | |
666 Value y = appendConstant(CiConstant.NULL_OBJECT); | 708 Value y = appendConstant(CiConstant.NULL_OBJECT); |
667 Value x = frameState.apop(); | 709 Value x = frameState.apop(); |
668 ifNode(x, cond, y, stateBefore); | 710 ifNode(x, cond, y); |
669 } | 711 } |
670 | 712 |
671 private void genIfSame(CiKind kind, Condition cond) { | 713 private void genIfSame(CiKind kind, Condition cond) { |
672 FrameState stateBefore = frameState.create(bci()); | |
673 Value y = frameState.pop(kind); | 714 Value y = frameState.pop(kind); |
674 Value x = frameState.pop(kind); | 715 Value x = frameState.pop(kind); |
675 ifNode(x, cond, y, stateBefore); | 716 ifNode(x, cond, y); |
676 } | 717 } |
677 | 718 |
678 private void genThrow(int bci) { | 719 private void genThrow(int bci) { |
679 FrameState stateBefore = frameState.create(bci); | 720 FrameState stateBefore = frameState.create(bci); |
680 Throw t = new Throw(frameState.apop(), graph); | 721 Throw t = new Throw(frameState.apop(), graph); |
1023 List<Instruction> list = new ArrayList<Instruction>(max + 1); | 1064 List<Instruction> list = new ArrayList<Instruction>(max + 1); |
1024 boolean isBackwards = false; | 1065 boolean isBackwards = false; |
1025 for (int i = 0; i < max; i++) { | 1066 for (int i = 0; i < max; i++) { |
1026 // add all successors to the successor list | 1067 // add all successors to the successor list |
1027 int offset = ts.offsetAt(i); | 1068 int offset = ts.offsetAt(i); |
1028 list.add(blockAt(bci + offset)); | 1069 list.add(createTargetAt(bci + offset, frameState)); |
1029 isBackwards |= offset < 0; // track if any of the successors are backwards | 1070 isBackwards |= offset < 0; // track if any of the successors are backwards |
1030 } | 1071 } |
1031 int offset = ts.defaultOffset(); | 1072 int offset = ts.defaultOffset(); |
1032 isBackwards |= offset < 0; // if the default successor is backwards | 1073 isBackwards |= offset < 0; // if the default successor is backwards |
1033 list.add(blockAt(bci + offset)); | 1074 list.add(createTargetAt(bci + offset, frameState)); |
1034 boolean isSafepoint = isBackwards && !noSafepoints(); | 1075 boolean isSafepoint = isBackwards && !noSafepoints(); |
1035 FrameState stateBefore = isSafepoint ? frameState.create(bci()) : null; | 1076 FrameState stateAfter = isSafepoint ? frameState.create(bci()) : null; |
1036 append(new TableSwitch(frameState.ipop(), (List) list, ts.lowKey(), stateBefore, graph)); | 1077 append(new TableSwitch(frameState.ipop(), (List) list, ts.lowKey(), stateAfter, graph)); |
1078 } | |
1079 | |
1080 private Instruction createTargetAt(int bci, FrameStateAccess stateAfter) { | |
1081 return createTarget(blockList[bci], stateAfter); | |
1082 } | |
1083 | |
1084 private Instruction createTarget(Block block, FrameStateAccess stateAfter) { | |
1085 return block.firstInstruction; | |
1037 } | 1086 } |
1038 | 1087 |
1039 private void genLookupswitch() { | 1088 private void genLookupswitch() { |
1040 int bci = bci(); | 1089 int bci = bci(); |
1041 BytecodeLookupSwitch ls = new BytecodeLookupSwitch(stream(), bci); | 1090 BytecodeLookupSwitch ls = new BytecodeLookupSwitch(stream(), bci); |
1044 int[] keys = new int[max]; | 1093 int[] keys = new int[max]; |
1045 boolean isBackwards = false; | 1094 boolean isBackwards = false; |
1046 for (int i = 0; i < max; i++) { | 1095 for (int i = 0; i < max; i++) { |
1047 // add all successors to the successor list | 1096 // add all successors to the successor list |
1048 int offset = ls.offsetAt(i); | 1097 int offset = ls.offsetAt(i); |
1049 list.add(blockAt(bci + offset)); | 1098 list.add(createTargetAt(bci + offset, frameState)); |
1050 keys[i] = ls.keyAt(i); | 1099 keys[i] = ls.keyAt(i); |
1051 isBackwards |= offset < 0; // track if any of the successors are backwards | 1100 isBackwards |= offset < 0; // track if any of the successors are backwards |
1052 } | 1101 } |
1053 int offset = ls.defaultOffset(); | 1102 int offset = ls.defaultOffset(); |
1054 isBackwards |= offset < 0; // if the default successor is backwards | 1103 isBackwards |= offset < 0; // if the default successor is backwards |
1055 list.add(blockAt(bci + offset)); | 1104 list.add(createTargetAt(bci + offset, frameState)); |
1056 boolean isSafepoint = isBackwards && !noSafepoints(); | 1105 boolean isSafepoint = isBackwards && !noSafepoints(); |
1057 FrameState stateBefore = isSafepoint ? frameState.create(bci()) : null; | 1106 FrameState stateAfter = isSafepoint ? frameState.create(bci()) : null; |
1058 append(new LookupSwitch(frameState.ipop(), (List) list, keys, stateBefore, graph)); | 1107 append(new LookupSwitch(frameState.ipop(), (List) list, keys, stateAfter, graph)); |
1059 } | 1108 } |
1060 | 1109 |
1061 private Value appendConstant(CiConstant constant) { | 1110 private Value appendConstant(CiConstant constant) { |
1062 return appendWithBCI(new Constant(constant, graph)); | 1111 return appendWithBCI(new Constant(constant, graph)); |
1063 } | 1112 } |
1106 return state.localAt(0); | 1155 return state.localAt(0); |
1107 } | 1156 } |
1108 } | 1157 } |
1109 | 1158 |
1110 private void fillSyncHandler(Value lock, Block syncHandler) { | 1159 private void fillSyncHandler(Value lock, Block syncHandler) { |
1111 Block origBlock = curBlock; | |
1112 FrameState origState = frameState.create(-1); | 1160 FrameState origState = frameState.create(-1); |
1113 Instruction origLast = lastInstr; | 1161 Instruction origLast = lastInstr; |
1114 | 1162 |
1115 lastInstr = syncHandler.firstInstruction; | 1163 lastInstr = syncHandler.firstInstruction; |
1116 curBlock = syncHandler; | |
1117 while (lastInstr.next() != null) { | 1164 while (lastInstr.next() != null) { |
1118 // go forward to the end of the block | 1165 // go forward to the end of the block |
1119 lastInstr = lastInstr.next(); | 1166 lastInstr = lastInstr.next(); |
1120 } | 1167 } |
1121 frameState.initializeFrom(((BlockBegin) syncHandler.firstInstruction).stateBefore()); | 1168 frameState.initializeFrom(((BlockBegin) syncHandler.firstInstruction).stateBefore()); |
1133 // exit the monitor | 1180 // exit the monitor |
1134 genMonitorExit(lock, Instruction.SYNCHRONIZATION_ENTRY_BCI); | 1181 genMonitorExit(lock, Instruction.SYNCHRONIZATION_ENTRY_BCI); |
1135 | 1182 |
1136 genThrow(bci); | 1183 genThrow(bci); |
1137 BlockEnd end = (BlockEnd) lastInstr; | 1184 BlockEnd end = (BlockEnd) lastInstr; |
1138 ((BlockBegin) curBlock.firstInstruction).setEnd(end); | 1185 ((BlockBegin) syncHandler.firstInstruction).setEnd(end); |
1139 end.setStateAfter(frameState.create(bci())); | 1186 end.setStateAfter(frameState.create(bci())); |
1140 | 1187 |
1141 curBlock = origBlock; | |
1142 frameState.initializeFrom(origState); | 1188 frameState.initializeFrom(origState); |
1143 origState.delete(); | 1189 origState.delete(); |
1144 lastInstr = origLast; | 1190 lastInstr = origLast; |
1145 } | 1191 } |
1146 | 1192 |
1155 } | 1201 } |
1156 | 1202 |
1157 if (!isVisited(block)) { | 1203 if (!isVisited(block)) { |
1158 markVisited(block); | 1204 markVisited(block); |
1159 // now parse the block | 1205 // now parse the block |
1160 curBlock = block; | |
1161 if (block.firstInstruction instanceof Placeholder) { | 1206 if (block.firstInstruction instanceof Placeholder) { |
1162 assert false; | 1207 assert false; |
1163 placeholder = block.firstInstruction; | 1208 placeholder = block.firstInstruction; |
1164 frameState.initializeFrom(((Placeholder) placeholder).stateBefore()); | 1209 frameState.initializeFrom(((Placeholder) placeholder).stateBefore()); |
1165 lastInstr = null; | 1210 lastInstr = null; |
1169 frameState.initializeFrom(((BlockBegin) block.firstInstruction).stateBefore()); | 1214 frameState.initializeFrom(((BlockBegin) block.firstInstruction).stateBefore()); |
1170 lastInstr = block.firstInstruction; | 1215 lastInstr = block.firstInstruction; |
1171 } | 1216 } |
1172 assert block.firstInstruction.next() == null; | 1217 assert block.firstInstruction.next() == null; |
1173 | 1218 |
1174 iterateBytecodesForBlock(block.startBci); | 1219 iterateBytecodesForBlock(block); |
1175 } | 1220 } |
1176 } | 1221 } |
1177 } | 1222 } |
1178 | 1223 |
1179 private BlockEnd iterateBytecodesForBlock(int bci) { | 1224 private BlockEnd iterateBytecodesForBlock(Block block) { |
1180 assert frameState != null; | 1225 assert frameState != null; |
1181 stream.setBCI(bci); | 1226 |
1182 | 1227 stream.setBCI(block.startBci); |
1183 BlockBegin block = (BlockBegin) curBlock.firstInstruction; | 1228 |
1184 BlockEnd end = null; | 1229 BlockEnd end = null; |
1185 int endBCI = stream.endBCI(); | 1230 int endBCI = stream.endBCI(); |
1186 boolean blockStart = true; | 1231 boolean blockStart = true; |
1187 | 1232 |
1233 int bci = block.startBci; | |
1188 while (bci < endBCI) { | 1234 while (bci < endBCI) { |
1189 Instruction nextBlock = blockAtOrNull(bci); | 1235 Block nextBlock = blockList[bci]; |
1190 if (nextBlock != null && nextBlock != block) { | 1236 if (nextBlock != null && nextBlock != block) { |
1191 // we fell through to the next block, add a goto and break | 1237 // we fell through to the next block, add a goto and break |
1192 end = new Goto((BlockBegin) nextBlock, null, graph); | 1238 end = new Goto((BlockBegin) nextBlock.firstInstruction, null, graph); |
1193 lastInstr = lastInstr.appendNext(end); | 1239 lastInstr = lastInstr.appendNext(end); |
1194 break; | 1240 break; |
1195 } | 1241 } |
1196 // read the opcode | 1242 // read the opcode |
1197 int opcode = stream.currentBC(); | 1243 int opcode = stream.currentBC(); |
1198 | 1244 |
1199 traceState(); | 1245 traceState(); |
1200 traceInstruction(bci, stream, opcode, blockStart); | 1246 traceInstruction(bci, opcode, blockStart); |
1201 processBytecode(bci, stream, opcode); | 1247 processBytecode(bci, opcode); |
1202 | 1248 |
1203 if (lastInstr instanceof BlockEnd) { | 1249 if (lastInstr instanceof BlockEnd) { |
1204 end = (BlockEnd) lastInstr; | 1250 end = (BlockEnd) lastInstr; |
1205 break; | 1251 break; |
1206 } | 1252 } |
1223 // connect to begin and set state | 1269 // connect to begin and set state |
1224 // NOTE that inlining may have changed the block we are parsing | 1270 // NOTE that inlining may have changed the block we are parsing |
1225 assert end != null : "end should exist after iterating over bytecodes"; | 1271 assert end != null : "end should exist after iterating over bytecodes"; |
1226 FrameState stateAtEnd = frameState.create(bci()); | 1272 FrameState stateAtEnd = frameState.create(bci()); |
1227 end.setStateAfter(stateAtEnd); | 1273 end.setStateAfter(stateAtEnd); |
1228 block.setEnd(end); | 1274 if (block.firstInstruction instanceof BlockBegin) { |
1275 ((BlockBegin) block.firstInstruction).setEnd(end); | |
1276 } | |
1229 | 1277 |
1230 // propagate the state | 1278 // propagate the state |
1231 for (BlockBegin succ : end.blockSuccessors()) { | 1279 for (BlockBegin succ : end.blockSuccessors()) { |
1232 assert succ.blockPredecessors().contains(block.end()); | 1280 assert succ.blockPredecessors().contains(end); |
1233 succ.mergeOrClone(stateAtEnd, method(), loopHeaders.contains(succ)); | 1281 mergeOrClone(succ, stateAtEnd, loopHeaders.contains(succ)); |
1234 addToWorkList(blockList[succ.bci()]); | 1282 addToWorkList(blockList[succ.bci()]); |
1235 } | 1283 } |
1236 return end; | 1284 return end; |
1237 } | 1285 } |
1238 | 1286 |
1252 log.println(String.format("| lock[%d] = %-8s : %s", i, value == null ? "bogus" : value.kind.javaName, value)); | 1300 log.println(String.format("| lock[%d] = %-8s : %s", i, value == null ? "bogus" : value.kind.javaName, value)); |
1253 } | 1301 } |
1254 } | 1302 } |
1255 } | 1303 } |
1256 | 1304 |
1257 private void processBytecode(int bci, BytecodeStream s, int opcode) { | 1305 private void processBytecode(int bci, int opcode) { |
1258 int cpi; | 1306 int cpi; |
1259 | 1307 |
1260 // Checkstyle: stop | 1308 // Checkstyle: stop |
1261 switch (opcode) { | 1309 switch (opcode) { |
1262 case NOP : /* nothing to do */ break; | 1310 case NOP : /* nothing to do */ break; |
1273 case FCONST_0 : frameState.fpush(appendConstant(CiConstant.FLOAT_0)); break; | 1321 case FCONST_0 : frameState.fpush(appendConstant(CiConstant.FLOAT_0)); break; |
1274 case FCONST_1 : frameState.fpush(appendConstant(CiConstant.FLOAT_1)); break; | 1322 case FCONST_1 : frameState.fpush(appendConstant(CiConstant.FLOAT_1)); break; |
1275 case FCONST_2 : frameState.fpush(appendConstant(CiConstant.FLOAT_2)); break; | 1323 case FCONST_2 : frameState.fpush(appendConstant(CiConstant.FLOAT_2)); break; |
1276 case DCONST_0 : frameState.dpush(appendConstant(CiConstant.DOUBLE_0)); break; | 1324 case DCONST_0 : frameState.dpush(appendConstant(CiConstant.DOUBLE_0)); break; |
1277 case DCONST_1 : frameState.dpush(appendConstant(CiConstant.DOUBLE_1)); break; | 1325 case DCONST_1 : frameState.dpush(appendConstant(CiConstant.DOUBLE_1)); break; |
1278 case BIPUSH : frameState.ipush(appendConstant(CiConstant.forInt(s.readByte()))); break; | 1326 case BIPUSH : frameState.ipush(appendConstant(CiConstant.forInt(stream.readByte()))); break; |
1279 case SIPUSH : frameState.ipush(appendConstant(CiConstant.forInt(s.readShort()))); break; | 1327 case SIPUSH : frameState.ipush(appendConstant(CiConstant.forInt(stream.readShort()))); break; |
1280 case LDC : // fall through | 1328 case LDC : // fall through |
1281 case LDC_W : // fall through | 1329 case LDC_W : // fall through |
1282 case LDC2_W : genLoadConstant(s.readCPI()); break; | 1330 case LDC2_W : genLoadConstant(stream.readCPI()); break; |
1283 case ILOAD : loadLocal(s.readLocalIndex(), CiKind.Int); break; | 1331 case ILOAD : loadLocal(stream.readLocalIndex(), CiKind.Int); break; |
1284 case LLOAD : loadLocal(s.readLocalIndex(), CiKind.Long); break; | 1332 case LLOAD : loadLocal(stream.readLocalIndex(), CiKind.Long); break; |
1285 case FLOAD : loadLocal(s.readLocalIndex(), CiKind.Float); break; | 1333 case FLOAD : loadLocal(stream.readLocalIndex(), CiKind.Float); break; |
1286 case DLOAD : loadLocal(s.readLocalIndex(), CiKind.Double); break; | 1334 case DLOAD : loadLocal(stream.readLocalIndex(), CiKind.Double); break; |
1287 case ALOAD : loadLocal(s.readLocalIndex(), CiKind.Object); break; | 1335 case ALOAD : loadLocal(stream.readLocalIndex(), CiKind.Object); break; |
1288 case ILOAD_0 : // fall through | 1336 case ILOAD_0 : // fall through |
1289 case ILOAD_1 : // fall through | 1337 case ILOAD_1 : // fall through |
1290 case ILOAD_2 : // fall through | 1338 case ILOAD_2 : // fall through |
1291 case ILOAD_3 : loadLocal(opcode - ILOAD_0, CiKind.Int); break; | 1339 case ILOAD_3 : loadLocal(opcode - ILOAD_0, CiKind.Int); break; |
1292 case LLOAD_0 : // fall through | 1340 case LLOAD_0 : // fall through |
1311 case DALOAD : genLoadIndexed(CiKind.Double); break; | 1359 case DALOAD : genLoadIndexed(CiKind.Double); break; |
1312 case AALOAD : genLoadIndexed(CiKind.Object); break; | 1360 case AALOAD : genLoadIndexed(CiKind.Object); break; |
1313 case BALOAD : genLoadIndexed(CiKind.Byte ); break; | 1361 case BALOAD : genLoadIndexed(CiKind.Byte ); break; |
1314 case CALOAD : genLoadIndexed(CiKind.Char ); break; | 1362 case CALOAD : genLoadIndexed(CiKind.Char ); break; |
1315 case SALOAD : genLoadIndexed(CiKind.Short ); break; | 1363 case SALOAD : genLoadIndexed(CiKind.Short ); break; |
1316 case ISTORE : storeLocal(CiKind.Int, s.readLocalIndex()); break; | 1364 case ISTORE : storeLocal(CiKind.Int, stream.readLocalIndex()); break; |
1317 case LSTORE : storeLocal(CiKind.Long, s.readLocalIndex()); break; | 1365 case LSTORE : storeLocal(CiKind.Long, stream.readLocalIndex()); break; |
1318 case FSTORE : storeLocal(CiKind.Float, s.readLocalIndex()); break; | 1366 case FSTORE : storeLocal(CiKind.Float, stream.readLocalIndex()); break; |
1319 case DSTORE : storeLocal(CiKind.Double, s.readLocalIndex()); break; | 1367 case DSTORE : storeLocal(CiKind.Double, stream.readLocalIndex()); break; |
1320 case ASTORE : storeLocal(CiKind.Object, s.readLocalIndex()); break; | 1368 case ASTORE : storeLocal(CiKind.Object, stream.readLocalIndex()); break; |
1321 case ISTORE_0 : // fall through | 1369 case ISTORE_0 : // fall through |
1322 case ISTORE_1 : // fall through | 1370 case ISTORE_1 : // fall through |
1323 case ISTORE_2 : // fall through | 1371 case ISTORE_2 : // fall through |
1324 case ISTORE_3 : storeLocal(CiKind.Int, opcode - ISTORE_0); break; | 1372 case ISTORE_3 : storeLocal(CiKind.Int, opcode - ISTORE_0); break; |
1325 case LSTORE_0 : // fall through | 1373 case LSTORE_0 : // fall through |
1424 case IF_ICMPGE : genIfSame(CiKind.Int, Condition.GE); break; | 1472 case IF_ICMPGE : genIfSame(CiKind.Int, Condition.GE); break; |
1425 case IF_ICMPGT : genIfSame(CiKind.Int, Condition.GT); break; | 1473 case IF_ICMPGT : genIfSame(CiKind.Int, Condition.GT); break; |
1426 case IF_ICMPLE : genIfSame(CiKind.Int, Condition.LE); break; | 1474 case IF_ICMPLE : genIfSame(CiKind.Int, Condition.LE); break; |
1427 case IF_ACMPEQ : genIfSame(frameState.peekKind(), Condition.EQ); break; | 1475 case IF_ACMPEQ : genIfSame(frameState.peekKind(), Condition.EQ); break; |
1428 case IF_ACMPNE : genIfSame(frameState.peekKind(), Condition.NE); break; | 1476 case IF_ACMPNE : genIfSame(frameState.peekKind(), Condition.NE); break; |
1429 case GOTO : genGoto(s.currentBCI(), s.readBranchDest()); break; | 1477 case GOTO : genGoto(stream.currentBCI(), stream.readBranchDest()); break; |
1430 case JSR : genJsr(s.readBranchDest()); break; | 1478 case JSR : genJsr(stream.readBranchDest()); break; |
1431 case RET : genRet(s.readLocalIndex()); break; | 1479 case RET : genRet(stream.readLocalIndex()); break; |
1432 case TABLESWITCH : genTableswitch(); break; | 1480 case TABLESWITCH : genTableswitch(); break; |
1433 case LOOKUPSWITCH : genLookupswitch(); break; | 1481 case LOOKUPSWITCH : genLookupswitch(); break; |
1434 case IRETURN : genReturn(frameState.ipop()); break; | 1482 case IRETURN : genReturn(frameState.ipop()); break; |
1435 case LRETURN : genReturn(frameState.lpop()); break; | 1483 case LRETURN : genReturn(frameState.lpop()); break; |
1436 case FRETURN : genReturn(frameState.fpop()); break; | 1484 case FRETURN : genReturn(frameState.fpop()); break; |
1437 case DRETURN : genReturn(frameState.dpop()); break; | 1485 case DRETURN : genReturn(frameState.dpop()); break; |
1438 case ARETURN : genReturn(frameState.apop()); break; | 1486 case ARETURN : genReturn(frameState.apop()); break; |
1439 case RETURN : genReturn(null ); break; | 1487 case RETURN : genReturn(null ); break; |
1440 case GETSTATIC : cpi = s.readCPI(); genGetStatic(cpi, constantPool().lookupField(cpi, opcode)); break; | 1488 case GETSTATIC : cpi = stream.readCPI(); genGetStatic(cpi, constantPool().lookupField(cpi, opcode)); break; |
1441 case PUTSTATIC : cpi = s.readCPI(); genPutStatic(cpi, constantPool().lookupField(cpi, opcode)); break; | 1489 case PUTSTATIC : cpi = stream.readCPI(); genPutStatic(cpi, constantPool().lookupField(cpi, opcode)); break; |
1442 case GETFIELD : cpi = s.readCPI(); genGetField(cpi, constantPool().lookupField(cpi, opcode)); break; | 1490 case GETFIELD : cpi = stream.readCPI(); genGetField(cpi, constantPool().lookupField(cpi, opcode)); break; |
1443 case PUTFIELD : cpi = s.readCPI(); genPutField(cpi, constantPool().lookupField(cpi, opcode)); break; | 1491 case PUTFIELD : cpi = stream.readCPI(); genPutField(cpi, constantPool().lookupField(cpi, opcode)); break; |
1444 case INVOKEVIRTUAL : cpi = s.readCPI(); genInvokeVirtual(constantPool().lookupMethod(cpi, opcode), cpi, constantPool()); break; | 1492 case INVOKEVIRTUAL : cpi = stream.readCPI(); genInvokeVirtual(constantPool().lookupMethod(cpi, opcode), cpi, constantPool()); break; |
1445 case INVOKESPECIAL : cpi = s.readCPI(); genInvokeSpecial(constantPool().lookupMethod(cpi, opcode), null, cpi, constantPool()); break; | 1493 case INVOKESPECIAL : cpi = stream.readCPI(); genInvokeSpecial(constantPool().lookupMethod(cpi, opcode), null, cpi, constantPool()); break; |
1446 case INVOKESTATIC : cpi = s.readCPI(); genInvokeStatic(constantPool().lookupMethod(cpi, opcode), cpi, constantPool()); break; | 1494 case INVOKESTATIC : cpi = stream.readCPI(); genInvokeStatic(constantPool().lookupMethod(cpi, opcode), cpi, constantPool()); break; |
1447 case INVOKEINTERFACE: cpi = s.readCPI(); genInvokeInterface(constantPool().lookupMethod(cpi, opcode), cpi, constantPool()); break; | 1495 case INVOKEINTERFACE: cpi = stream.readCPI(); genInvokeInterface(constantPool().lookupMethod(cpi, opcode), cpi, constantPool()); break; |
1448 case NEW : genNewInstance(s.readCPI()); break; | 1496 case NEW : genNewInstance(stream.readCPI()); break; |
1449 case NEWARRAY : genNewTypeArray(s.readLocalIndex()); break; | 1497 case NEWARRAY : genNewTypeArray(stream.readLocalIndex()); break; |
1450 case ANEWARRAY : genNewObjectArray(s.readCPI()); break; | 1498 case ANEWARRAY : genNewObjectArray(stream.readCPI()); break; |
1451 case ARRAYLENGTH : genArrayLength(); break; | 1499 case ARRAYLENGTH : genArrayLength(); break; |
1452 case ATHROW : genThrow(s.currentBCI()); break; | 1500 case ATHROW : genThrow(stream.currentBCI()); break; |
1453 case CHECKCAST : genCheckCast(); break; | 1501 case CHECKCAST : genCheckCast(); break; |
1454 case INSTANCEOF : genInstanceOf(); break; | 1502 case INSTANCEOF : genInstanceOf(); break; |
1455 case MONITORENTER : genMonitorEnter(frameState.apop(), s.currentBCI()); break; | 1503 case MONITORENTER : genMonitorEnter(frameState.apop(), stream.currentBCI()); break; |
1456 case MONITOREXIT : genMonitorExit(frameState.apop(), s.currentBCI()); break; | 1504 case MONITOREXIT : genMonitorExit(frameState.apop(), stream.currentBCI()); break; |
1457 case MULTIANEWARRAY : genNewMultiArray(s.readCPI()); break; | 1505 case MULTIANEWARRAY : genNewMultiArray(stream.readCPI()); break; |
1458 case IFNULL : genIfNull(Condition.EQ); break; | 1506 case IFNULL : genIfNull(Condition.EQ); break; |
1459 case IFNONNULL : genIfNull(Condition.NE); break; | 1507 case IFNONNULL : genIfNull(Condition.NE); break; |
1460 case GOTO_W : genGoto(s.currentBCI(), s.readFarBranchDest()); break; | 1508 case GOTO_W : genGoto(stream.currentBCI(), stream.readFarBranchDest()); break; |
1461 case JSR_W : genJsr(s.readFarBranchDest()); break; | 1509 case JSR_W : genJsr(stream.readFarBranchDest()); break; |
1462 case BREAKPOINT: | 1510 case BREAKPOINT: |
1463 throw new CiBailout("concurrent setting of breakpoint"); | 1511 throw new CiBailout("concurrent setting of breakpoint"); |
1464 default: | 1512 default: |
1465 throw new CiBailout("Unsupported opcode " + opcode + " (" + nameOf(opcode) + ") [bci=" + bci + "]"); | 1513 throw new CiBailout("Unsupported opcode " + opcode + " (" + nameOf(opcode) + ") [bci=" + bci + "]"); |
1466 } | 1514 } |
1467 // Checkstyle: resume | 1515 // Checkstyle: resume |
1468 } | 1516 } |
1469 | 1517 |
1470 private void traceInstruction(int bci, BytecodeStream s, int opcode, boolean blockStart) { | 1518 private void traceInstruction(int bci, int opcode, boolean blockStart) { |
1471 if (C1XOptions.TraceBytecodeParserLevel >= TRACELEVEL_INSTRUCTIONS && !TTY.isSuppressed()) { | 1519 if (C1XOptions.TraceBytecodeParserLevel >= TRACELEVEL_INSTRUCTIONS && !TTY.isSuppressed()) { |
1472 StringBuilder sb = new StringBuilder(40); | 1520 StringBuilder sb = new StringBuilder(40); |
1473 sb.append(blockStart ? '+' : '|'); | 1521 sb.append(blockStart ? '+' : '|'); |
1474 if (bci < 10) { | 1522 if (bci < 10) { |
1475 sb.append(" "); | 1523 sb.append(" "); |
1476 } else if (bci < 100) { | 1524 } else if (bci < 100) { |
1477 sb.append(' '); | 1525 sb.append(' '); |
1478 } | 1526 } |
1479 sb.append(bci).append(": ").append(Bytecodes.nameOf(opcode)); | 1527 sb.append(bci).append(": ").append(Bytecodes.nameOf(opcode)); |
1480 for (int i = bci + 1; i < s.nextBCI(); ++i) { | 1528 for (int i = bci + 1; i < stream.nextBCI(); ++i) { |
1481 sb.append(' ').append(s.readUByte(i)); | 1529 sb.append(' ').append(stream.readUByte(i)); |
1482 } | 1530 } |
1483 log.println(sb.toString()); | 1531 log.println(sb.toString()); |
1484 } | 1532 } |
1485 } | 1533 } |
1486 | 1534 |