comparison graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java @ 2516:a384fac3fd34

Removed anything OSR-related.
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Wed, 27 Apr 2011 15:49:27 +0200
parents 4fdef1464592
children f6125fb5bfbc
comparison
equal deleted inserted replaced
2515:4fdef1464592 2516:a384fac3fd34
117 // 1. create the start block 117 // 1. create the start block
118 ir.startBlock = new BlockBegin(0, ir.nextBlockNumber()); 118 ir.startBlock = new BlockBegin(0, ir.nextBlockNumber());
119 BlockBegin startBlock = ir.startBlock; 119 BlockBegin startBlock = ir.startBlock;
120 120
121 // 2. compute the block map and get the entrypoint(s) 121 // 2. compute the block map and get the entrypoint(s)
122 BlockMap blockMap = compilation.getBlockMap(scope.method, compilation.osrBCI); 122 BlockMap blockMap = compilation.getBlockMap(scope.method);
123 BlockBegin stdEntry = blockMap.get(0); 123 BlockBegin stdEntry = blockMap.get(0);
124 BlockBegin osrEntry = compilation.osrBCI < 0 ? null : blockMap.get(compilation.osrBCI);
125 pushRootScope(scope, blockMap, startBlock); 124 pushRootScope(scope, blockMap, startBlock);
126 MutableFrameState initialState = stateAtEntry(rootMethod); 125 MutableFrameState initialState = stateAtEntry(rootMethod);
127 startBlock.mergeOrClone(initialState); 126 startBlock.mergeOrClone(initialState);
128 BlockBegin syncHandler = null; 127 BlockBegin syncHandler = null;
129 128
136 if (isSynchronized(rootMethod.accessFlags())) { 135 if (isSynchronized(rootMethod.accessFlags())) {
137 // 4A.1 add a monitor enter to the start block 136 // 4A.1 add a monitor enter to the start block
138 rootMethodSynchronizedObject = synchronizedObject(initialState, compilation.method); 137 rootMethodSynchronizedObject = synchronizedObject(initialState, compilation.method);
139 genMonitorEnter(rootMethodSynchronizedObject, Instruction.SYNCHRONIZATION_ENTRY_BCI); 138 genMonitorEnter(rootMethodSynchronizedObject, Instruction.SYNCHRONIZATION_ENTRY_BCI);
140 // 4A.2 finish the start block 139 // 4A.2 finish the start block
141 finishStartBlock(startBlock, stdEntry, osrEntry); 140 finishStartBlock(startBlock, stdEntry);
142 141
143 // 4A.3 setup an exception handler to unlock the root method synchronized object 142 // 4A.3 setup an exception handler to unlock the root method synchronized object
144 syncHandler = new BlockBegin(Instruction.SYNCHRONIZATION_ENTRY_BCI, ir.nextBlockNumber()); 143 syncHandler = new BlockBegin(Instruction.SYNCHRONIZATION_ENTRY_BCI, ir.nextBlockNumber());
145 syncHandler.setExceptionEntry(); 144 syncHandler.setExceptionEntry();
146 syncHandler.setBlockFlag(BlockBegin.BlockFlag.IsOnWorkList); 145 syncHandler.setBlockFlag(BlockBegin.BlockFlag.IsOnWorkList);
149 ExceptionHandler h = new ExceptionHandler(new CiExceptionHandler(0, rootMethod.code().length, -1, 0, null)); 148 ExceptionHandler h = new ExceptionHandler(new CiExceptionHandler(0, rootMethod.code().length, -1, 0, null));
150 h.setEntryBlock(syncHandler); 149 h.setEntryBlock(syncHandler);
151 scopeData.addExceptionHandler(h); 150 scopeData.addExceptionHandler(h);
152 } else { 151 } else {
153 // 4B.1 simply finish the start block 152 // 4B.1 simply finish the start block
154 finishStartBlock(startBlock, stdEntry, osrEntry); 153 finishStartBlock(startBlock, stdEntry);
155 } 154 }
156 155
157 // 5. 156 // 5.
158 C1XIntrinsic intrinsic = C1XOptions.OptIntrinsify ? C1XIntrinsic.getIntrinsic(rootMethod) : null; 157 C1XIntrinsic intrinsic = C1XOptions.OptIntrinsify ? C1XIntrinsic.getIntrinsic(rootMethod) : null;
159 if (intrinsic != null) { 158 if (intrinsic != null) {
160 lastInstr = stdEntry; 159 lastInstr = stdEntry;
161 // 6A.1 the root method is an intrinsic; load the parameters onto the stack and try to inline it 160 // 6A.1 the root method is an intrinsic; load the parameters onto the stack and try to inline it
162 if (C1XOptions.OptIntrinsify && osrEntry == null) { 161 if (C1XOptions.OptIntrinsify) {
163 // try to inline an Intrinsic node 162 // try to inline an Intrinsic node
164 boolean isStatic = Modifier.isStatic(rootMethod.accessFlags()); 163 boolean isStatic = Modifier.isStatic(rootMethod.accessFlags());
165 int argsSize = rootMethod.signature().argumentSlots(!isStatic); 164 int argsSize = rootMethod.signature().argumentSlots(!isStatic);
166 Value[] args = new Value[argsSize]; 165 Value[] args = new Value[argsSize];
167 for (int i = 0; i < args.length; i++) { 166 for (int i = 0; i < args.length; i++) {
196 195
197 if (syncHandler != null && syncHandler.stateBefore() != null) { 196 if (syncHandler != null && syncHandler.stateBefore() != null) {
198 // generate unlocking code if the exception handler is reachable 197 // generate unlocking code if the exception handler is reachable
199 fillSyncHandler(rootMethodSynchronizedObject, syncHandler, false); 198 fillSyncHandler(rootMethodSynchronizedObject, syncHandler, false);
200 } 199 }
201 200 }
202 if (compilation.osrBCI >= 0) { 201
203 BlockBegin osrBlock = blockMap.get(compilation.osrBCI); 202 private void finishStartBlock(BlockBegin startBlock, BlockBegin stdEntry) {
204 assert osrBlock.wasVisited();
205 if (!osrBlock.stateBefore().stackEmpty()) {
206 throw new CiBailout("cannot OSR with non-empty stack");
207 }
208 }
209 }
210
211 private void finishStartBlock(BlockBegin startBlock, BlockBegin stdEntry, BlockBegin osrEntry) {
212 assert curBlock == startBlock; 203 assert curBlock == startBlock;
213 Base base = new Base(stdEntry, osrEntry); 204 Base base = new Base(stdEntry);
214 appendWithoutOptimization(base, 0); 205 appendWithoutOptimization(base, 0);
215 FrameState stateAfter = curState.immutableCopy(bci()); 206 FrameState stateAfter = curState.immutableCopy(bci());
216 base.setStateAfter(stateAfter); 207 base.setStateAfter(stateAfter);
217 startBlock.setEnd(base); 208 startBlock.setEnd(base);
218 assert stdEntry.stateBefore() == null; 209 assert stdEntry.stateBefore() == null;
1433 } 1424 }
1434 1425
1435 void pushScope(RiMethod target, BlockBegin continuation) { 1426 void pushScope(RiMethod target, BlockBegin continuation) {
1436 // prepare callee scope 1427 // prepare callee scope
1437 IRScope calleeScope = new IRScope(scope(), curState.immutableCopy(bci()), target, -1); 1428 IRScope calleeScope = new IRScope(scope(), curState.immutableCopy(bci()), target, -1);
1438 BlockMap blockMap = compilation.getBlockMap(calleeScope.method, -1); 1429 BlockMap blockMap = compilation.getBlockMap(calleeScope.method);
1439 calleeScope.setStoresInLoops(blockMap.getStoresInLoops()); 1430 calleeScope.setStoresInLoops(blockMap.getStoresInLoops());
1440 // prepare callee state 1431 // prepare callee state
1441 curState = curState.pushScope(calleeScope); 1432 curState = curState.pushScope(calleeScope);
1442 BytecodeStream stream = new BytecodeStream(target.code()); 1433 BytecodeStream stream = new BytecodeStream(target.code());
1443 RiConstantPool constantPool = compilation.runtime.getConstantPool(target); 1434 RiConstantPool constantPool = compilation.runtime.getConstantPool(target);
1939 1930
1940 private void iterateAllBlocks() { 1931 private void iterateAllBlocks() {
1941 BlockBegin b; 1932 BlockBegin b;
1942 while ((b = scopeData.removeFromWorkList()) != null) { 1933 while ((b = scopeData.removeFromWorkList()) != null) {
1943 if (!b.wasVisited()) { 1934 if (!b.wasVisited()) {
1944 if (b.isOsrEntry()) {
1945 // this is the OSR entry block, set up edges accordingly
1946 setupOsrEntryBlock();
1947 // this is no longer the OSR entry block
1948 b.setOsrEntry(false);
1949 }
1950 b.setWasVisited(true); 1935 b.setWasVisited(true);
1951 // now parse the block 1936 // now parse the block
1952 killMemoryMap(); 1937 killMemoryMap();
1953 curBlock = b; 1938 curBlock = b;
1954 curState = b.stateBefore().copy(); 1939 curState = b.stateBefore().copy();
1966 scope().updateMaxLocks(maxLocks); 1951 scope().updateMaxLocks(maxLocks);
1967 } 1952 }
1968 1953
1969 private void popScopeForJsr() { 1954 private void popScopeForJsr() {
1970 scopeData = scopeData.parent; 1955 scopeData = scopeData.parent;
1971 }
1972
1973 private void setupOsrEntryBlock() {
1974 assert compilation.isOsrCompilation();
1975
1976 int osrBCI = compilation.osrBCI;
1977 BytecodeStream s = scopeData.stream;
1978 RiOsrFrame frame = compilation.getOsrFrame();
1979 s.setBCI(osrBCI);
1980 s.next(); // XXX: why go to next bytecode?
1981
1982 // create a new block to contain the OSR setup code
1983 ir.osrEntryBlock = new BlockBegin(osrBCI, ir.nextBlockNumber());
1984 ir.osrEntryBlock.setOsrEntry(true);
1985 ir.osrEntryBlock.setDepthFirstNumber(0);
1986
1987 // get the target block of the OSR
1988 BlockBegin target = scopeData.blockAt(osrBCI);
1989 assert target != null && target.isOsrEntry();
1990
1991 MutableFrameState state = target.stateBefore().copy();
1992 ir.osrEntryBlock.setStateBefore(state);
1993
1994 killMemoryMap();
1995 curBlock = ir.osrEntryBlock;
1996 curState = state.copy();
1997 lastInstr = ir.osrEntryBlock;
1998
1999 // create the entry instruction which represents the OSR state buffer
2000 // input from interpreter / JIT
2001 Instruction e = new OsrEntry();
2002 e.setFlag(Value.Flag.NonNull, true);
2003
2004 for (int i = 0; i < state.localsSize(); i++) {
2005 Value local = state.localAt(i);
2006 Value get;
2007 int offset = frame.getLocalOffset(i);
2008 if (local != null) {
2009 // this is a live local according to compiler
2010 if (local.kind.isObject() && !frame.isLiveObject(i)) {
2011 // the compiler thinks this is live, but not the interpreter
2012 // pretend that it passed null
2013 get = appendConstant(CiConstant.NULL_OBJECT);
2014 } else {
2015 Value oc = appendConstant(CiConstant.forInt(offset));
2016 get = append(new UnsafeGetRaw(local.kind, e, oc, 0, true));
2017 }
2018 state.storeLocal(i, get);
2019 }
2020 }
2021
2022 assert state.callerState() == null;
2023 state.clearLocals();
2024 // ATTN: assumption: state is not used further below, else add .immutableCopy()
2025 Goto g = new Goto(target, state, false);
2026 append(g);
2027 ir.osrEntryBlock.setEnd(g);
2028 target.mergeOrClone(ir.osrEntryBlock.end().stateAfter());
2029 } 1956 }
2030 1957
2031 private BlockEnd iterateBytecodesForBlock(int bci, boolean inliningIntoCurrentBlock) { 1958 private BlockEnd iterateBytecodesForBlock(int bci, boolean inliningIntoCurrentBlock) {
2032 skipBlock = false; 1959 skipBlock = false;
2033 assert curState != null; 1960 assert curState != null;
2057 lastInstr = lastInstr.setNext(end, prevBCI); 1984 lastInstr = lastInstr.setNext(end, prevBCI);
2058 break; 1985 break;
2059 } 1986 }
2060 // read the opcode 1987 // read the opcode
2061 int opcode = s.currentBC(); 1988 int opcode = s.currentBC();
2062
2063 // check for active JSR during OSR compilation
2064 if (compilation.isOsrCompilation() && scope().isTopScope() && scopeData.parsingJsr() && s.currentBCI() == compilation.osrBCI) {
2065 throw new CiBailout("OSR not supported while a JSR is active");
2066 }
2067 1989
2068 // push an exception object onto the stack if we are parsing an exception handler 1990 // push an exception object onto the stack if we are parsing an exception handler
2069 if (pushException) { 1991 if (pushException) {
2070 FrameState stateBefore = curState.immutableCopy(bci()); 1992 FrameState stateBefore = curState.immutableCopy(bci());
2071 apush(append(new ExceptionObject(stateBefore))); 1993 apush(append(new ExceptionObject(stateBefore)));