Mercurial > hg > graal-jvmci-8
comparison graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java @ 2716:c1a9bf38da28
Removed bci from the Instruction class.
author | Thomas Wuerthinger <thomas@wuerthinger.net> |
---|---|
date | Thu, 19 May 2011 13:59:55 +0200 |
parents | 3ac3dd97d8df |
children | c1ce2a53d6c3 |
comparison
equal
deleted
inserted
replaced
2715:3ac3dd97d8df | 2716:c1a9bf38da28 |
---|---|
187 BlockBegin syncHandler = null; | 187 BlockBegin syncHandler = null; |
188 | 188 |
189 // 3. setup internal state for appending instructions | 189 // 3. setup internal state for appending instructions |
190 curBlock = startBlock; | 190 curBlock = startBlock; |
191 lastInstr = startBlock; | 191 lastInstr = startBlock; |
192 lastInstr.appendNext(null, -1); | 192 lastInstr.appendNext(null); |
193 | 193 |
194 BlockBegin entryBlock = blockList[0]; | 194 BlockBegin entryBlock = blockList[0]; |
195 if (isSynchronized(rootMethod.accessFlags())) { | 195 if (isSynchronized(rootMethod.accessFlags())) { |
196 // 4A.1 add a monitor enter to the start block | 196 // 4A.1 add a monitor enter to the start block |
197 rootMethodSynchronizedObject = synchronizedObject(frameState, compilation.method); | 197 rootMethodSynchronizedObject = synchronizedObject(frameState, compilation.method); |
245 | 245 |
246 private void finishStartBlock(BlockBegin startBlock, BlockBegin stdEntry) { | 246 private void finishStartBlock(BlockBegin startBlock, BlockBegin stdEntry) { |
247 assert curBlock == startBlock; | 247 assert curBlock == startBlock; |
248 FrameState stateAfter = frameState.create(bci()); | 248 FrameState stateAfter = frameState.create(bci()); |
249 Goto base = new Goto(stdEntry, stateAfter, graph); | 249 Goto base = new Goto(stdEntry, stateAfter, graph); |
250 appendWithoutOptimization(base, 0); | 250 appendWithBCI(base); |
251 startBlock.setEnd(base); | 251 startBlock.setEnd(base); |
252 assert stdEntry.stateBefore() == null; | 252 assert stdEntry.stateBefore() == null; |
253 stdEntry.mergeOrClone(stateAfter, method()); | 253 stdEntry.mergeOrClone(stateAfter, method()); |
254 } | 254 } |
255 | 255 |
313 current--; | 313 current--; |
314 } else { | 314 } else { |
315 if (unwindBlock == null) { | 315 if (unwindBlock == null) { |
316 unwindBlock = new BlockBegin(bci, ir.nextBlockNumber(), graph); | 316 unwindBlock = new BlockBegin(bci, ir.nextBlockNumber(), graph); |
317 Unwind unwind = new Unwind(null, graph); | 317 Unwind unwind = new Unwind(null, graph); |
318 unwindBlock.appendNext(unwind, bci); | 318 unwindBlock.appendNext(unwind); |
319 unwindBlock.setEnd(unwind); | 319 unwindBlock.setEnd(unwind); |
320 } | 320 } |
321 successor = unwindBlock; | 321 successor = unwindBlock; |
322 } | 322 } |
323 | 323 |
339 } else { | 339 } else { |
340 BlockBegin dispatchEntry = new BlockBegin(handler.handlerBCI(), ir.nextBlockNumber(), graph); | 340 BlockBegin dispatchEntry = new BlockBegin(handler.handlerBCI(), ir.nextBlockNumber(), graph); |
341 if (handler.handler.catchType().isResolved()) { | 341 if (handler.handler.catchType().isResolved()) { |
342 ExceptionDispatch end = new ExceptionDispatch(null, handler.entryBlock(), null, handler, null, graph); | 342 ExceptionDispatch end = new ExceptionDispatch(null, handler.entryBlock(), null, handler, null, graph); |
343 end.setBlockSuccessor(0, successor); | 343 end.setBlockSuccessor(0, successor); |
344 dispatchEntry.appendNext(end, handler.handlerBCI()); | 344 dispatchEntry.appendNext(end); |
345 dispatchEntry.setEnd(end); | 345 dispatchEntry.setEnd(end); |
346 } else { | 346 } else { |
347 Deoptimize deopt = new Deoptimize(graph); | 347 Deoptimize deopt = new Deoptimize(graph); |
348 dispatchEntry.appendNext(deopt, bci); | 348 dispatchEntry.appendNext(deopt); |
349 Goto end = new Goto(successor, null, graph); | 349 Goto end = new Goto(successor, null, graph); |
350 deopt.appendNext(end, bci); | 350 deopt.appendNext(end); |
351 dispatchEntry.setEnd(end); | 351 dispatchEntry.setEnd(end); |
352 } | 352 } |
353 newBlocks.add(dispatchEntry); | 353 newBlocks.add(dispatchEntry); |
354 successor = dispatchEntry; | 354 successor = dispatchEntry; |
355 } | 355 } |
358 FrameState entryState = frameState.duplicateWithEmptyStack(bci); | 358 FrameState entryState = frameState.duplicateWithEmptyStack(bci); |
359 | 359 |
360 BlockBegin entry = new BlockBegin(bci, ir.nextBlockNumber(), graph); | 360 BlockBegin entry = new BlockBegin(bci, ir.nextBlockNumber(), graph); |
361 entry.setStateBefore(entryState); | 361 entry.setStateBefore(entryState); |
362 ExceptionObject exception = new ExceptionObject(graph); | 362 ExceptionObject exception = new ExceptionObject(graph); |
363 entry.appendNext(exception, bci); | 363 entry.appendNext(exception); |
364 FrameState stateWithException = entryState.duplicateModified(bci, CiKind.Void, exception); | 364 FrameState stateWithException = entryState.duplicateModified(bci, CiKind.Void, exception); |
365 BlockEnd end = new Goto(successor, stateWithException, graph); | 365 BlockEnd end = new Goto(successor, stateWithException, graph); |
366 exception.appendNext(end, bci); | 366 exception.appendNext(end); |
367 entry.setEnd(end); | 367 entry.setEnd(end); |
368 | 368 |
369 if (x instanceof Invoke) { | 369 if (x instanceof Invoke) { |
370 ((Invoke) x).setExceptionEdge(entry); | 370 ((Invoke) x).setExceptionEdge(entry); |
371 } else { | 371 } else { |
609 } | 609 } |
610 | 610 |
611 private void ifNode(Value x, Condition cond, Value y, FrameState stateBefore) { | 611 private void ifNode(Value x, Condition cond, Value y, FrameState stateBefore) { |
612 BlockBegin tsucc = blockAt(stream().readBranchDest()); | 612 BlockBegin tsucc = blockAt(stream().readBranchDest()); |
613 BlockBegin fsucc = blockAt(stream().nextBCI()); | 613 BlockBegin fsucc = blockAt(stream().nextBCI()); |
614 int bci = stream().currentBCI(); | 614 append(new If(x, cond, y, tsucc, fsucc, null, graph)); |
615 boolean isSafepoint = !noSafepoints() && (tsucc.bci() <= bci || fsucc.bci() <= bci); | 615 stateBefore.delete(); |
616 if (isSafepoint) { | |
617 append(new If(x, cond, y, tsucc, fsucc, stateBefore, graph)); | |
618 } else { | |
619 append(new If(x, cond, y, tsucc, fsucc, null, graph)); | |
620 stateBefore.delete(); | |
621 } | |
622 } | 616 } |
623 | 617 |
624 private void genIfZero(Condition cond) { | 618 private void genIfZero(Condition cond) { |
625 Value y = appendConstant(CiConstant.INT_0); | 619 Value y = appendConstant(CiConstant.INT_0); |
626 FrameState stateBefore = frameState.create(bci()); | 620 FrameState stateBefore = frameState.create(bci()); |
644 | 638 |
645 private void genThrow(int bci) { | 639 private void genThrow(int bci) { |
646 FrameState stateBefore = frameState.create(bci); | 640 FrameState stateBefore = frameState.create(bci); |
647 Throw t = new Throw(frameState.apop(), graph); | 641 Throw t = new Throw(frameState.apop(), graph); |
648 t.setStateBefore(stateBefore); | 642 t.setStateBefore(stateBefore); |
649 appendWithoutOptimization(t, bci); | 643 appendWithBCI(t); |
644 handleException(t, bci); | |
650 } | 645 } |
651 | 646 |
652 private void genCheckCast() { | 647 private void genCheckCast() { |
653 int cpi = stream().readCPI(); | 648 int cpi = stream().readCPI(); |
654 RiType type = constantPool().lookupType(cpi, CHECKCAST); | 649 RiType type = constantPool().lookupType(cpi, CHECKCAST); |
861 appendInvoke(INVOKESPECIAL, target, args, cpi, constantPool); | 856 appendInvoke(INVOKESPECIAL, target, args, cpi, constantPool); |
862 } | 857 } |
863 | 858 |
864 private void appendInvoke(int opcode, RiMethod target, Value[] args, int cpi, RiConstantPool constantPool) { | 859 private void appendInvoke(int opcode, RiMethod target, Value[] args, int cpi, RiConstantPool constantPool) { |
865 CiKind resultType = returnKind(target); | 860 CiKind resultType = returnKind(target); |
866 Value result = append(new Invoke(opcode, resultType.stackKind(), args, target, target.signature().returnType(compilation.method.holder()), graph)); | 861 Invoke invoke = new Invoke(opcode, resultType.stackKind(), args, target, target.signature().returnType(compilation.method.holder()), graph); |
862 Value result = appendWithBCI(invoke); | |
863 handleException(invoke, bci()); | |
867 frameState.pushReturn(resultType, result); | 864 frameState.pushReturn(resultType, result); |
868 } | 865 } |
869 | 866 |
870 private RiType getExactType(RiType staticType, Value receiver) { | 867 private RiType getExactType(RiType staticType, Value receiver) { |
871 RiType exact = staticType.exactType(); | 868 RiType exact = staticType.exactType(); |
966 if (compilation.runtime.sizeOfBasicObjectLock() != 0) { | 963 if (compilation.runtime.sizeOfBasicObjectLock() != 0) { |
967 lockAddress = new MonitorAddress(lockNumber, graph); | 964 lockAddress = new MonitorAddress(lockNumber, graph); |
968 append(lockAddress); | 965 append(lockAddress); |
969 } | 966 } |
970 MonitorEnter monitorEnter = new MonitorEnter(x, lockAddress, lockNumber, graph); | 967 MonitorEnter monitorEnter = new MonitorEnter(x, lockAddress, lockNumber, graph); |
971 appendWithoutOptimization(monitorEnter, bci); | 968 appendWithBCI(monitorEnter); |
972 frameState.lock(ir, x, lockNumber + 1); | 969 frameState.lock(ir, x, lockNumber + 1); |
973 if (bci == Instruction.SYNCHRONIZATION_ENTRY_BCI) { | 970 if (bci == Instruction.SYNCHRONIZATION_ENTRY_BCI) { |
974 monitorEnter.setStateAfter(frameState.create(0)); | 971 monitorEnter.setStateAfter(frameState.create(0)); |
975 } | 972 } |
976 } | 973 } |
983 MonitorAddress lockAddress = null; | 980 MonitorAddress lockAddress = null; |
984 if (compilation.runtime.sizeOfBasicObjectLock() != 0) { | 981 if (compilation.runtime.sizeOfBasicObjectLock() != 0) { |
985 lockAddress = new MonitorAddress(lockNumber, graph); | 982 lockAddress = new MonitorAddress(lockNumber, graph); |
986 append(lockAddress); | 983 append(lockAddress); |
987 } | 984 } |
988 appendWithoutOptimization(new MonitorExit(x, lockAddress, lockNumber, graph), bci); | 985 appendWithBCI(new MonitorExit(x, lockAddress, lockNumber, graph)); |
989 frameState.unlock(); | 986 frameState.unlock(); |
990 } | 987 } |
991 | 988 |
992 private void genJsr(int dest) { | 989 private void genJsr(int dest) { |
993 throw new CiBailout("jsr/ret not supported"); | 990 throw new CiBailout("jsr/ret not supported"); |
1038 FrameState stateBefore = isSafepoint ? frameState.create(bci()) : null; | 1035 FrameState stateBefore = isSafepoint ? frameState.create(bci()) : null; |
1039 append(new LookupSwitch(frameState.ipop(), list, keys, stateBefore, graph)); | 1036 append(new LookupSwitch(frameState.ipop(), list, keys, stateBefore, graph)); |
1040 } | 1037 } |
1041 | 1038 |
1042 private Value appendConstant(CiConstant constant) { | 1039 private Value appendConstant(CiConstant constant) { |
1043 return appendWithBCI(new Constant(constant, graph), bci()); | 1040 return appendWithBCI(new Constant(constant, graph)); |
1044 } | 1041 } |
1045 | 1042 |
1046 private Value append(Instruction x) { | 1043 private Value append(Instruction x) { |
1047 return appendWithBCI(x, bci()); | 1044 return appendWithBCI(x); |
1048 } | 1045 } |
1049 | 1046 |
1050 private Value appendWithoutOptimization(Instruction x, int bci) { | 1047 private Value appendWithBCI(Instruction x) { |
1051 return appendWithBCI(x, bci); | |
1052 } | |
1053 | |
1054 private Value appendWithBCI(Instruction x, int bci) { | |
1055 if (x.isAppended()) { | 1048 if (x.isAppended()) { |
1056 // the instruction has already been added | 1049 // the instruction has already been added |
1057 return x; | 1050 return x; |
1058 } | 1051 } |
1059 | 1052 |
1060 assert x.next() == null : "instruction should not have been appended yet"; | 1053 assert x.next() == null : "instruction should not have been appended yet"; |
1061 assert lastInstr.next() == null : "cannot append instruction to instruction which isn't end (" + lastInstr + "->" + lastInstr.next() + ")"; | 1054 assert lastInstr.next() == null : "cannot append instruction to instruction which isn't end (" + lastInstr + "->" + lastInstr.next() + ")"; |
1062 | 1055 |
1063 lastInstr = lastInstr.appendNext(x, bci); | 1056 lastInstr = lastInstr.appendNext(x); |
1064 if (++stats.nodeCount >= C1XOptions.MaximumInstructionCount) { | 1057 if (++stats.nodeCount >= C1XOptions.MaximumInstructionCount) { |
1065 // bailout if we've exceeded the maximum inlining size | 1058 // bailout if we've exceeded the maximum inlining size |
1066 throw new CiBailout("Method and/or inlining is too large"); | 1059 throw new CiBailout("Method and/or inlining is too large"); |
1067 } | |
1068 | |
1069 if (x instanceof ExceptionEdgeInstruction) { | |
1070 // connect the instruction to any exception handlers | |
1071 handleException(x, bci); | |
1072 } | 1060 } |
1073 | 1061 |
1074 return x; | 1062 return x; |
1075 } | 1063 } |
1076 | 1064 |
1085 } | 1073 } |
1086 | 1074 |
1087 private Value synchronizedObject(FrameStateAccess state, RiMethod target) { | 1075 private Value synchronizedObject(FrameStateAccess state, RiMethod target) { |
1088 if (isStatic(target.accessFlags())) { | 1076 if (isStatic(target.accessFlags())) { |
1089 Constant classConstant = new Constant(target.holder().getEncoding(Representation.JavaClass), graph); | 1077 Constant classConstant = new Constant(target.holder().getEncoding(Representation.JavaClass), graph); |
1090 return appendWithoutOptimization(classConstant, Instruction.SYNCHRONIZATION_ENTRY_BCI); | 1078 return appendWithBCI(classConstant); |
1091 } else { | 1079 } else { |
1092 return state.localAt(0); | 1080 return state.localAt(0); |
1093 } | 1081 } |
1094 } | 1082 } |
1095 | 1083 |
1110 assert lock != null; | 1098 assert lock != null; |
1111 assert frameState.locksSize() > 0 && frameState.lockAt(frameState.locksSize() - 1) == lock; | 1099 assert frameState.locksSize() > 0 && frameState.lockAt(frameState.locksSize() - 1) == lock; |
1112 if (lock instanceof Instruction) { | 1100 if (lock instanceof Instruction) { |
1113 Instruction l = (Instruction) lock; | 1101 Instruction l = (Instruction) lock; |
1114 if (!l.isAppended()) { | 1102 if (!l.isAppended()) { |
1115 lock = appendWithoutOptimization(l, Instruction.SYNCHRONIZATION_ENTRY_BCI); | 1103 lock = appendWithBCI(l); |
1116 } | 1104 } |
1117 } | 1105 } |
1118 // exit the monitor | 1106 // exit the monitor |
1119 genMonitorExit(lock, Instruction.SYNCHRONIZATION_ENTRY_BCI); | 1107 genMonitorExit(lock, Instruction.SYNCHRONIZATION_ENTRY_BCI); |
1120 | 1108 |
1143 markVisited(b); | 1131 markVisited(b); |
1144 // now parse the block | 1132 // now parse the block |
1145 curBlock = b; | 1133 curBlock = b; |
1146 frameState.initializeFrom(b.stateBefore()); | 1134 frameState.initializeFrom(b.stateBefore()); |
1147 lastInstr = b; | 1135 lastInstr = b; |
1148 b.appendNext(null, -1); | 1136 b.appendNext(null); |
1149 | 1137 |
1150 iterateBytecodesForBlock(b.bci()); | 1138 iterateBytecodesForBlock(b.bci()); |
1151 } | 1139 } |
1152 } | 1140 } |
1153 } | 1141 } |
1156 assert frameState != null; | 1144 assert frameState != null; |
1157 stream.setBCI(bci); | 1145 stream.setBCI(bci); |
1158 | 1146 |
1159 BlockBegin block = curBlock; | 1147 BlockBegin block = curBlock; |
1160 BlockEnd end = null; | 1148 BlockEnd end = null; |
1161 int prevBCI = bci; | |
1162 int endBCI = stream.endBCI(); | 1149 int endBCI = stream.endBCI(); |
1163 boolean blockStart = true; | 1150 boolean blockStart = true; |
1164 | 1151 |
1165 while (bci < endBCI) { | 1152 while (bci < endBCI) { |
1166 BlockBegin nextBlock = blockAtOrNull(bci); | 1153 BlockBegin nextBlock = blockAtOrNull(bci); |
1167 if (nextBlock != null && nextBlock != block) { | 1154 if (nextBlock != null && nextBlock != block) { |
1168 // we fell through to the next block, add a goto and break | 1155 // we fell through to the next block, add a goto and break |
1169 end = new Goto(nextBlock, null, graph); | 1156 end = new Goto(nextBlock, null, graph); |
1170 lastInstr = lastInstr.appendNext(end, prevBCI); | 1157 lastInstr = lastInstr.appendNext(end); |
1171 break; | 1158 break; |
1172 } | 1159 } |
1173 // read the opcode | 1160 // read the opcode |
1174 int opcode = stream.currentBC(); | 1161 int opcode = stream.currentBC(); |
1175 | 1162 |
1176 traceState(); | 1163 traceState(); |
1177 traceInstruction(bci, stream, opcode, blockStart); | 1164 traceInstruction(bci, stream, opcode, blockStart); |
1178 processBytecode(bci, stream, opcode); | 1165 processBytecode(bci, stream, opcode); |
1179 | |
1180 prevBCI = bci; | |
1181 | 1166 |
1182 if (lastInstr instanceof BlockEnd) { | 1167 if (lastInstr instanceof BlockEnd) { |
1183 end = (BlockEnd) lastInstr; | 1168 end = (BlockEnd) lastInstr; |
1184 break; | 1169 break; |
1185 } | 1170 } |