Mercurial > hg > graal-jvmci-8
comparison graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java @ 2830:706047ee5f2e
Removed ExceptionHandler class because of clean up.
author | Thomas Wuerthinger <thomas@wuerthinger.net> |
---|---|
date | Tue, 31 May 2011 11:01:24 +0200 |
parents | 27c00b180416 |
children | 1cd59ca9ac86 caf55daa41dc |
comparison
equal
deleted
inserted
replaced
2829:27c00b180416 | 2830:706047ee5f2e |
---|---|
67 private final BytecodeStream stream; // the bytecode stream | 67 private final BytecodeStream stream; // the bytecode stream |
68 // bci-to-block mapping | 68 // bci-to-block mapping |
69 private Block[] blockFromBci; | 69 private Block[] blockFromBci; |
70 private ArrayList<Block> blockList; | 70 private ArrayList<Block> blockList; |
71 | 71 |
72 private Block syncBlock; | |
73 private CiExceptionHandler syncHandler; | |
74 | |
72 // the constant pool | 75 // the constant pool |
73 private final RiConstantPool constantPool; | 76 private final RiConstantPool constantPool; |
74 | 77 |
75 // the worklist of blocks, sorted by depth first number | 78 // the worklist of blocks, sorted by depth first number |
76 private final PriorityQueue<Block> workList = new PriorityQueue<Block>(10, new Comparator<Block>() { | 79 private final PriorityQueue<Block> workList = new PriorityQueue<Block>(10, new Comparator<Block>() { |
77 public int compare(Block o1, Block o2) { | 80 public int compare(Block o1, Block o2) { |
78 return o1.blockID - o2.blockID; | 81 return o1.blockID - o2.blockID; |
79 } | 82 } |
80 }); | 83 }); |
81 | |
82 // Exception handler list | |
83 private List<ExceptionHandler> exceptionHandlers; | |
84 | 84 |
85 private FrameStateBuilder frameState; // the current execution state | 85 private FrameStateBuilder frameState; // the current execution state |
86 private Instruction lastInstr; // the last instruction added | 86 private Instruction lastInstr; // the last instruction added |
87 | 87 |
88 private final LogStream log; | 88 private final LogStream log; |
131 assert blockID == i; | 131 assert blockID == i; |
132 Block block = blockList.get(i); | 132 Block block = blockList.get(i); |
133 if (block.startBci >= 0) { | 133 if (block.startBci >= 0) { |
134 blockFromBci[block.startBci] = block; | 134 blockFromBci[block.startBci] = block; |
135 } | 135 } |
136 // System.out.println("block " + blockID + " @ " + block.startBci); | |
137 } | |
138 | |
139 RiExceptionHandler[] handlers = rootMethod.exceptionHandlers(); | |
140 if (handlers != null && handlers.length > 0) { | |
141 exceptionHandlers = new ArrayList<ExceptionHandler>(handlers.length); | |
142 for (RiExceptionHandler ch : handlers) { | |
143 Block entry = blockFromBci[ch.handlerBCI()]; | |
144 // entry == null means that the exception handler is unreachable according to the BlockMap conservative analysis | |
145 if (entry != null) { | |
146 ExceptionHandler h = new ExceptionHandler(ch); | |
147 h.setEntryBlock(entry); | |
148 exceptionHandlers.add(h); | |
149 } | |
150 } | |
151 } | 136 } |
152 | 137 |
153 // 1. create the start block | 138 // 1. create the start block |
154 Block startBlock = nextBlock(Instruction.SYNCHRONIZATION_ENTRY_BCI); | 139 Block startBlock = nextBlock(Instruction.SYNCHRONIZATION_ENTRY_BCI); |
155 markOnWorkList(startBlock); | 140 markOnWorkList(startBlock); |
156 lastInstr = createTarget(startBlock, frameState); | 141 lastInstr = createTarget(startBlock, frameState); |
157 graph.start().setStart(lastInstr); | 142 graph.start().setStart(lastInstr); |
158 | 143 |
159 Block syncBlock = null; | |
160 if (isSynchronized(rootMethod.accessFlags())) { | 144 if (isSynchronized(rootMethod.accessFlags())) { |
161 // 4A.1 add a monitor enter to the start block | 145 // 4A.1 add a monitor enter to the start block |
162 rootMethodSynchronizedObject = synchronizedObject(frameState, compilation.method); | 146 rootMethodSynchronizedObject = synchronizedObject(frameState, compilation.method); |
163 genMonitorEnter(rootMethodSynchronizedObject, Instruction.SYNCHRONIZATION_ENTRY_BCI); | 147 genMonitorEnter(rootMethodSynchronizedObject, Instruction.SYNCHRONIZATION_ENTRY_BCI); |
164 // 4A.2 finish the start block | 148 // 4A.2 finish the start block |
166 | 150 |
167 // 4A.3 setup an exception handler to unlock the root method synchronized object | 151 // 4A.3 setup an exception handler to unlock the root method synchronized object |
168 syncBlock = nextBlock(Instruction.SYNCHRONIZATION_ENTRY_BCI); | 152 syncBlock = nextBlock(Instruction.SYNCHRONIZATION_ENTRY_BCI); |
169 markOnWorkList(syncBlock); | 153 markOnWorkList(syncBlock); |
170 | 154 |
171 ExceptionHandler h = new ExceptionHandler(new CiExceptionHandler(0, rootMethod.code().length, -1, 0, null)); | 155 syncHandler = new CiExceptionHandler(0, rootMethod.code().length, Instruction.SYNCHRONIZATION_ENTRY_BCI, 0, null); |
172 h.setEntryBlock(syncBlock); | |
173 addExceptionHandler(h); | |
174 } else { | 156 } else { |
175 // 4B.1 simply finish the start block | 157 // 4B.1 simply finish the start block |
176 finishStartBlock(startBlock); | 158 finishStartBlock(startBlock); |
177 } | 159 } |
178 | 160 |
345 | 327 |
346 private void storeLocal(CiKind kind, int index) { | 328 private void storeLocal(CiKind kind, int index) { |
347 frameState.storeLocal(index, frameState.pop(kind)); | 329 frameState.storeLocal(index, frameState.pop(kind)); |
348 } | 330 } |
349 | 331 |
332 public boolean covers(RiExceptionHandler handler, int bci) { | |
333 return handler.startBCI() <= bci && bci < handler.endBCI(); | |
334 } | |
335 | |
336 public boolean isCatchAll(RiExceptionHandler handler) { | |
337 return handler.catchTypeCPI() == 0; | |
338 } | |
339 | |
350 private void handleException(Instruction x, int bci) { | 340 private void handleException(Instruction x, int bci) { |
351 if (!hasHandler()) { | 341 if (!hasHandler()) { |
352 return; | 342 return; |
353 } | 343 } |
354 | 344 |
355 assert bci == Instruction.SYNCHRONIZATION_ENTRY_BCI || bci == bci() : "invalid bci"; | 345 assert bci == Instruction.SYNCHRONIZATION_ENTRY_BCI || bci == bci() : "invalid bci"; |
356 | 346 |
357 ExceptionHandler firstHandler = null; | 347 RiExceptionHandler firstHandler = null; |
348 RiExceptionHandler[] exceptionHandlers = compilation.method.exceptionHandlers(); | |
358 // join with all potential exception handlers | 349 // join with all potential exception handlers |
359 if (this.exceptionHandlers != null) { | 350 if (exceptionHandlers != null) { |
360 for (ExceptionHandler handler : this.exceptionHandlers) { | 351 for (RiExceptionHandler handler : exceptionHandlers) { |
361 // if the handler covers this bytecode index, add it to the list | 352 // if the handler covers this bytecode index, add it to the list |
362 if (handler.covers(bci)) { | 353 if (covers(handler, bci)) { |
363 firstHandler = new ExceptionHandler(handler); | 354 firstHandler = handler; |
364 break; | 355 break; |
365 } | 356 } |
366 } | 357 } |
358 } | |
359 | |
360 if (firstHandler == null) { | |
361 firstHandler = syncHandler; | |
367 } | 362 } |
368 | 363 |
369 if (firstHandler != null) { | 364 if (firstHandler != null) { |
370 compilation.setHasExceptionHandlers(); | 365 compilation.setHasExceptionHandlers(); |
371 | 366 |
372 Block dispatchBlock = null; | 367 Block dispatchBlock = null; |
373 for (Block block : blockList) { | 368 for (Block block : blockList) { |
374 if (block instanceof ExceptionBlock) { | 369 if (block instanceof ExceptionBlock) { |
375 ExceptionBlock excBlock = (ExceptionBlock) block; | 370 ExceptionBlock excBlock = (ExceptionBlock) block; |
376 if (excBlock.handler == firstHandler.handler) { | 371 if (excBlock.handler == firstHandler) { |
377 dispatchBlock = block; | 372 dispatchBlock = block; |
378 break; | 373 break; |
379 } | 374 } |
380 } | 375 } |
381 } | 376 } |
382 // if there's no dispatch block then the catch block needs to be a catch all | 377 // if there's no dispatch block then the catch block needs to be a catch all |
383 if (dispatchBlock == null) { | 378 if (dispatchBlock == null) { |
384 assert firstHandler.isCatchAll(); | 379 assert isCatchAll(firstHandler); |
385 dispatchBlock = firstHandler.entryBlock(); | 380 int handlerBCI = firstHandler.handlerBCI(); |
381 if (handlerBCI == Instruction.SYNCHRONIZATION_ENTRY_BCI) { | |
382 dispatchBlock = syncBlock; | |
383 } else { | |
384 dispatchBlock = blockFromBci[handlerBCI]; | |
385 } | |
386 } | 386 } |
387 FrameState entryState = frameState.duplicateWithEmptyStack(bci); | 387 FrameState entryState = frameState.duplicateWithEmptyStack(bci); |
388 | 388 |
389 StateSplit entry = new Placeholder(graph); | 389 StateSplit entry = new Placeholder(graph); |
390 entry.setStateBefore(entryState); | 390 entry.setStateBefore(entryState); |
1151 append(new Unwind(frameState.apop(), graph)); | 1151 append(new Unwind(frameState.apop(), graph)); |
1152 } else { | 1152 } else { |
1153 assert frameState.stackSize() == 1; | 1153 assert frameState.stackSize() == 1; |
1154 | 1154 |
1155 if (block.handler.catchType().isResolved()) { | 1155 if (block.handler.catchType().isResolved()) { |
1156 Instruction catchSuccessor = createTarget(block.handlerBlock, frameState); | 1156 Instruction catchSuccessor = createTarget(blockFromBci[block.handler.handlerBCI()], frameState); |
1157 Instruction nextDispatch = createTarget(block.next, frameState); | 1157 Instruction nextDispatch = createTarget(block.next, frameState); |
1158 append(new ExceptionDispatch(frameState.stackAt(0), catchSuccessor, nextDispatch, block.handler.catchType(), graph)); | 1158 append(new ExceptionDispatch(frameState.stackAt(0), catchSuccessor, nextDispatch, block.handler.catchType(), graph)); |
1159 } else { | 1159 } else { |
1160 Deoptimize deopt = new Deoptimize(graph); | 1160 Deoptimize deopt = new Deoptimize(graph); |
1161 deopt.setMessage("unresolved " + block.handler.catchType().name()); | 1161 deopt.setMessage("unresolved " + block.handler.catchType().name()); |
1466 private RiConstantPool constantPool() { | 1466 private RiConstantPool constantPool() { |
1467 return constantPool; | 1467 return constantPool; |
1468 } | 1468 } |
1469 | 1469 |
1470 /** | 1470 /** |
1471 * Adds an exception handler. | |
1472 * @param handler the handler to add | |
1473 */ | |
1474 private void addExceptionHandler(ExceptionHandler handler) { | |
1475 if (exceptionHandlers == null) { | |
1476 exceptionHandlers = new ArrayList<ExceptionHandler>(); | |
1477 } | |
1478 exceptionHandlers.add(handler); | |
1479 } | |
1480 | |
1481 /** | |
1482 * Adds a block to the worklist, if it is not already in the worklist. | 1471 * Adds a block to the worklist, if it is not already in the worklist. |
1483 * This method will keep the worklist topologically stored (i.e. the lower | 1472 * This method will keep the worklist topologically stored (i.e. the lower |
1484 * DFNs are earlier in the list). | 1473 * DFNs are earlier in the list). |
1485 * @param block the block to add to the work list | 1474 * @param block the block to add to the work list |
1486 */ | 1475 */ |