# HG changeset patch # User Thomas Wuerthinger # Date 1306832484 -7200 # Node ID 706047ee5f2e8529e45929281bf407c7794285e5 # Parent 27c00b180416c678927c6d0ec5f04b2dea257736 Removed ExceptionHandler class because of clean up. diff -r 27c00b180416 -r 706047ee5f2e graal/GraalCompiler/src/com/sun/c1x/alloc/LinearScan.java --- a/graal/GraalCompiler/src/com/sun/c1x/alloc/LinearScan.java Tue May 31 09:51:59 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/alloc/LinearScan.java Tue May 31 11:01:24 2011 +0200 @@ -1181,14 +1181,6 @@ final int blockFrom = block.firstLirInstructionId(); int blockTo = block.lastLirInstructionId(); - // (tw) Destroy all registers on exception handler entry. - if (block.isExceptionEntry()) { - for (CiRegister r : callerSaveRegs) { - if (attributes(r).isAllocatable) { - addTemp(r.asValue(), block.firstLirInstructionId(), RegisterPriority.None, CiKind.Illegal); - } - } - } assert blockFrom == instructions.get(0).id; assert blockTo == instructions.get(instructions.size() - 1).id; diff -r 27c00b180416 -r 706047ee5f2e graal/GraalCompiler/src/com/sun/c1x/graph/BlockMap.java --- a/graal/GraalCompiler/src/com/sun/c1x/graph/BlockMap.java Tue May 31 09:51:59 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/graph/BlockMap.java Tue May 31 11:01:24 2011 +0200 @@ -131,7 +131,6 @@ public static class ExceptionBlock extends Block { public RiExceptionHandler handler; public Block next; - public Block handlerBlock; } private static final Block[] NO_SUCCESSORS = new Block[0]; @@ -423,7 +422,6 @@ block.endBci = -1; block.handler = handler; block.successors.add(blockMap[handler.handlerBCI()]); - block.handlerBlock = blockMap[handler.handlerBCI()]; Block next; if (index < handlers.size() - 1) { next = makeExceptionDispatch(handlers, index + 1); diff -r 27c00b180416 -r 706047ee5f2e graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java --- a/graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java Tue May 31 09:51:59 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java Tue May 31 11:01:24 2011 +0200 @@ -69,6 +69,9 @@ private Block[] blockFromBci; private ArrayList blockList; + private Block syncBlock; + private CiExceptionHandler syncHandler; + // the constant pool private final RiConstantPool constantPool; @@ -79,9 +82,6 @@ } }); - // Exception handler list - private List exceptionHandlers; - private FrameStateBuilder frameState; // the current execution state private Instruction lastInstr; // the last instruction added @@ -133,21 +133,6 @@ if (block.startBci >= 0) { blockFromBci[block.startBci] = block; } -// System.out.println("block " + blockID + " @ " + block.startBci); - } - - RiExceptionHandler[] handlers = rootMethod.exceptionHandlers(); - if (handlers != null && handlers.length > 0) { - exceptionHandlers = new ArrayList(handlers.length); - for (RiExceptionHandler ch : handlers) { - Block entry = blockFromBci[ch.handlerBCI()]; - // entry == null means that the exception handler is unreachable according to the BlockMap conservative analysis - if (entry != null) { - ExceptionHandler h = new ExceptionHandler(ch); - h.setEntryBlock(entry); - exceptionHandlers.add(h); - } - } } // 1. create the start block @@ -156,7 +141,6 @@ lastInstr = createTarget(startBlock, frameState); graph.start().setStart(lastInstr); - Block syncBlock = null; if (isSynchronized(rootMethod.accessFlags())) { // 4A.1 add a monitor enter to the start block rootMethodSynchronizedObject = synchronizedObject(frameState, compilation.method); @@ -168,9 +152,7 @@ syncBlock = nextBlock(Instruction.SYNCHRONIZATION_ENTRY_BCI); markOnWorkList(syncBlock); - ExceptionHandler h = new ExceptionHandler(new CiExceptionHandler(0, rootMethod.code().length, -1, 0, null)); - h.setEntryBlock(syncBlock); - addExceptionHandler(h); + syncHandler = new CiExceptionHandler(0, rootMethod.code().length, Instruction.SYNCHRONIZATION_ENTRY_BCI, 0, null); } else { // 4B.1 simply finish the start block finishStartBlock(startBlock); @@ -347,6 +329,14 @@ frameState.storeLocal(index, frameState.pop(kind)); } + public boolean covers(RiExceptionHandler handler, int bci) { + return handler.startBCI() <= bci && bci < handler.endBCI(); + } + + public boolean isCatchAll(RiExceptionHandler handler) { + return handler.catchTypeCPI() == 0; + } + private void handleException(Instruction x, int bci) { if (!hasHandler()) { return; @@ -354,18 +344,23 @@ assert bci == Instruction.SYNCHRONIZATION_ENTRY_BCI || bci == bci() : "invalid bci"; - ExceptionHandler firstHandler = null; + RiExceptionHandler firstHandler = null; + RiExceptionHandler[] exceptionHandlers = compilation.method.exceptionHandlers(); // join with all potential exception handlers - if (this.exceptionHandlers != null) { - for (ExceptionHandler handler : this.exceptionHandlers) { + if (exceptionHandlers != null) { + for (RiExceptionHandler handler : exceptionHandlers) { // if the handler covers this bytecode index, add it to the list - if (handler.covers(bci)) { - firstHandler = new ExceptionHandler(handler); + if (covers(handler, bci)) { + firstHandler = handler; break; } } } + if (firstHandler == null) { + firstHandler = syncHandler; + } + if (firstHandler != null) { compilation.setHasExceptionHandlers(); @@ -373,7 +368,7 @@ for (Block block : blockList) { if (block instanceof ExceptionBlock) { ExceptionBlock excBlock = (ExceptionBlock) block; - if (excBlock.handler == firstHandler.handler) { + if (excBlock.handler == firstHandler) { dispatchBlock = block; break; } @@ -381,8 +376,13 @@ } // if there's no dispatch block then the catch block needs to be a catch all if (dispatchBlock == null) { - assert firstHandler.isCatchAll(); - dispatchBlock = firstHandler.entryBlock(); + assert isCatchAll(firstHandler); + int handlerBCI = firstHandler.handlerBCI(); + if (handlerBCI == Instruction.SYNCHRONIZATION_ENTRY_BCI) { + dispatchBlock = syncBlock; + } else { + dispatchBlock = blockFromBci[handlerBCI]; + } } FrameState entryState = frameState.duplicateWithEmptyStack(bci); @@ -1153,7 +1153,7 @@ assert frameState.stackSize() == 1; if (block.handler.catchType().isResolved()) { - Instruction catchSuccessor = createTarget(block.handlerBlock, frameState); + Instruction catchSuccessor = createTarget(blockFromBci[block.handler.handlerBCI()], frameState); Instruction nextDispatch = createTarget(block.next, frameState); append(new ExceptionDispatch(frameState.stackAt(0), catchSuccessor, nextDispatch, block.handler.catchType(), graph)); } else { @@ -1468,17 +1468,6 @@ } /** - * Adds an exception handler. - * @param handler the handler to add - */ - private void addExceptionHandler(ExceptionHandler handler) { - if (exceptionHandlers == null) { - exceptionHandlers = new ArrayList(); - } - exceptionHandlers.add(handler); - } - - /** * Adds a block to the worklist, if it is not already in the worklist. * This method will keep the worklist topologically stored (i.e. the lower * DFNs are earlier in the list). diff -r 27c00b180416 -r 706047ee5f2e graal/GraalCompiler/src/com/sun/c1x/ir/ExceptionHandler.java --- a/graal/GraalCompiler/src/com/sun/c1x/ir/ExceptionHandler.java Tue May 31 09:51:59 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,189 +0,0 @@ -/* - * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.sun.c1x.ir; - -import java.util.*; - -import com.sun.c1x.graph.*; -import com.sun.c1x.lir.*; -import com.sun.cri.ri.*; - -/** - * The {@code ExceptionHandler} class represents an exception handler for a Java bytecode method. - * There is exactly one instance of this class for every exception handler without any specific - * reference to an exception-throwing instruction covered by the handler. Then there is one - * instance per exception-throwing instruction that is used to record the frame state before - * execution of the instruction. The latter is used to generate exception adapter blocks - * (see section 3.4 of the paper - * Optimized Interval Splitting in a Linear Scan Register Allocator) where necessary. - */ -public final class ExceptionHandler { - - public static final List ZERO_HANDLERS = Collections.emptyList(); - - public final RiExceptionHandler handler; - private BlockMap.Block entryBlock; - private LIRList entryCode; - private int entryCodeOffset; - private int phiOperand; - private int lirOpId; - - public ExceptionHandler(RiExceptionHandler handler) { - this.handler = handler; - this.entryCodeOffset = -1; - this.phiOperand = -1; - this.lirOpId = -1; - } - - public ExceptionHandler(ExceptionHandler other) { - this.handler = other.handler; - this.entryBlock = other.entryBlock; - this.entryCode = other.entryCode; - this.entryCodeOffset = other.entryCodeOffset; - this.phiOperand = other.phiOperand; - this.lirOpId = other.lirOpId; - } - - @Override - public String toString() { - return "XHandler(Block=" + entryBlock.blockID + ") " + handler; - } - - /** - * Gets the compiler interface object that describes this exception handler, - * including the bytecode ranges. - * @return the compiler interface exception handler - */ - public RiExceptionHandler handler() { - return handler; - } - - /** - * Gets the bytecode index of the handler (catch block). - * @return the bytecode index of the handler - */ - public int handlerBCI() { - return handler.handlerBCI(); - } - - /** - * Utility method to check if this exception handler covers the specified bytecode index. - * @param bci the bytecode index to check - * @return {@code true} if this exception handler covers the specified bytecode - */ - public boolean covers(int bci) { - return handler.startBCI() <= bci && bci < handler.endBCI(); - } - - /** - * Gets the entry block for this exception handler. - * @return the entry block - */ - public BlockMap.Block entryBlock() { - return entryBlock; - } - - /** - * Gets the PC offset of the handler entrypoint, which is used by - * the runtime to forward exception points to their catch sites. - * @return the pc offset of the handler entrypoint - */ - public int entryCodeOffset() { - return entryCodeOffset; - } - - public int phiOperand() { - return phiOperand; - } - - public void setEntryBlock(BlockMap.Block entry) { - entryBlock = entry; - } - - public void setEntryCodeOffset(int pco) { - entryCodeOffset = pco; - } - - public void setPhiOperand(int phi) { - phiOperand = phi; - } - - public boolean isCatchAll() { - return handler.catchTypeCPI() == 0; - } - - public static boolean couldCatch(List exceptionHandlers, RiType klass, boolean typeIsExact) { - // the type is unknown so be conservative - if (!klass.isResolved()) { - return true; - } - - for (int i = 0; i < exceptionHandlers.size(); i++) { - ExceptionHandler handler = exceptionHandlers.get(i); - if (handler.isCatchAll()) { - // catch of ANY - return true; - } - RiType handlerKlass = handler.handler.catchType(); - // if it's unknown it might be catchable - if (!handlerKlass.isResolved()) { - return true; - } - // if the throw type is definitely a subtype of the catch type - // then it can be caught. - if (klass.isSubtypeOf(handlerKlass)) { - return true; - } - if (!typeIsExact) { - // If the type isn't exactly known then it can also be caught by - // catch statements where the inexact type is a subtype of the - // catch type. - // given: foo extends bar extends Exception - // throw bar can be caught by catch foo, catch bar, and catch - // Exception, however it can't be caught by any handlers without - // bar in its type hierarchy. - if (handlerKlass.isSubtypeOf(klass)) { - return true; - } - } - } - return false; - } - - public int lirOpId() { - return lirOpId; - } - - public LIRList entryCode() { - return entryCode; - } - - public void setLirOpId(int throwingOpId) { - lirOpId = throwingOpId; - } - - public void setEntryCode(LIRList entryCode) { - this.entryCode = entryCode; - - } -}