changeset 3159:7f2bf8fe6804

Removed ExceptionDispatch node (replaced with normal InstanceOf).
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Wed, 06 Jul 2011 13:28:51 +0200
parents eb120717a534
children 8044bdfaab06
files graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/ExceptionDispatch.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/ValueVisitor.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/GraphBuilderPhase.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64LIRGenerator.java
diffstat 4 files changed, 16 insertions(+), 170 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/ExceptionDispatch.java	Wed Jul 06 13:18:34 2011 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,133 +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.oracle.max.graal.compiler.ir;
-
-import com.oracle.max.graal.compiler.debug.*;
-import com.oracle.max.graal.graph.*;
-import com.sun.cri.ci.*;
-import com.sun.cri.ri.*;
-
-/**
- * This instruction takes an exception object and has two successors:
- * The catchSuccessor is called whenever the exception matches the given type, otherwise otherSuccessor is called.
- */
-public final class ExceptionDispatch extends ControlSplit {
-
-    private static final int INPUT_COUNT = 1;
-    private static final int INPUT_EXCEPTION = 0;
-
-    private static final int SUCCESSOR_COUNT = 0;
-
-    @Override
-    protected int inputCount() {
-        return super.inputCount() + INPUT_COUNT;
-    }
-
-    @Override
-    protected int successorCount() {
-        return super.successorCount() + SUCCESSOR_COUNT;
-    }
-
-    /**
-     * The instruction producing the exception object.
-     */
-     public Value exception() {
-        return (Value) inputs().get(super.inputCount() + INPUT_EXCEPTION);
-    }
-
-    public Value setException(Value n) {
-        return (Value) inputs().set(super.inputCount() + INPUT_EXCEPTION, n);
-    }
-
-    private final RiType catchType;
-
-    /**
-     * Constructs a new ExceptionDispatch instruction.
-     */
-    public ExceptionDispatch(Value exception, FixedNode catchSuccessor, FixedNode otherSuccessor, RiType catchType, Graph graph) {
-        super(CiKind.Int, 2, INPUT_COUNT, SUCCESSOR_COUNT, graph);
-        setException(exception);
-        setBlockSuccessor(0, otherSuccessor);
-        setBlockSuccessor(1, catchSuccessor);
-        this.catchType = catchType;
-    }
-
-    public RiType catchType() {
-        return catchType;
-    }
-
-    /**
-     * Gets the block corresponding to the catch block.
-     * @return the true successor
-     */
-    public FixedNode catchSuccessor() {
-        return blockSuccessor(1);
-    }
-
-    /**
-     * Gets the block corresponding to the rest of the dispatch chain.
-     * @return the false successor
-     */
-    public FixedNode otherSuccessor() {
-        return blockSuccessor(0);
-    }
-
-    /**
-     * Gets the block corresponding to the specified outcome of the branch.
-     * @param istrue {@code true} if the true successor is requested, {@code false} otherwise
-     * @return the corresponding successor
-     */
-    public FixedNode successor(boolean istrue) {
-        return blockSuccessor(istrue ? 1 : 0);
-    }
-
-    @Override
-    public void accept(ValueVisitor v) {
-        v.visitExceptionDispatch(this);
-    }
-
-    @Override
-    public void print(LogStream out) {
-        out.print("exception_dispatch ").
-        print(exception()).
-        print(' ').
-        print("instanceof").
-        print(' ').
-        print(catchType().name()).
-        print(" then ").
-        print(catchSuccessor().toString()).
-        print(" else B").
-        print(otherSuccessor().toString());
-    }
-
-    @Override
-    public String shortName() {
-        return "Dispatch " + catchType().name();
-    }
-
-    @Override
-    public Node copy(Graph into) {
-        ExceptionDispatch x = new ExceptionDispatch(null, null, null, catchType, into);
-        return x;
-    }
-}
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/ValueVisitor.java	Wed Jul 06 13:18:34 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/ValueVisitor.java	Wed Jul 06 13:28:51 2011 +0200
@@ -69,7 +69,6 @@
     public abstract void visitStoreIndexed(StoreIndexed i);
     public abstract void visitTableSwitch(TableSwitch i);
     public abstract void visitDeoptimize(Deoptimize deoptimize);
-    public abstract void visitExceptionDispatch(ExceptionDispatch exceptionDispatch);
     public abstract void visitUnwind(Unwind unwind);
     public abstract void visitLoopBegin(LoopBegin loopBegin);
     public abstract void visitLoopEnd(LoopEnd loopEnd);
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/GraphBuilderPhase.java	Wed Jul 06 13:18:34 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/GraphBuilderPhase.java	Wed Jul 06 13:28:51 2011 +0200
@@ -730,8 +730,7 @@
     private void genCheckCast() {
         int cpi = stream().readCPI();
         RiType type = constantPool.lookupType(cpi, CHECKCAST);
-        boolean isInitialized = type.isResolved();
-        Constant typeInstruction = genTypeOrDeopt(RiType.Representation.ObjectHub, type, isInitialized, cpi);
+        Constant typeInstruction = genTypeOrDeopt(RiType.Representation.ObjectHub, type, type.isResolved());
         Value object = frameState.apop();
         if (typeInstruction != null) {
 //            InstanceOf instanceOf = new InstanceOf(typeInstruction, object, true, graph);
@@ -749,8 +748,7 @@
     private void genInstanceOf() {
         int cpi = stream().readCPI();
         RiType type = constantPool.lookupType(cpi, INSTANCEOF);
-        boolean isInitialized = type.isResolved();
-        Constant typeInstruction = genTypeOrDeopt(RiType.Representation.ObjectHub, type, isInitialized, cpi);
+        Constant typeInstruction = genTypeOrDeopt(RiType.Representation.ObjectHub, type, type.isResolved());
         Value object = frameState.apop();
         if (typeInstruction != null) {
             frameState.ipush(append(new MaterializeNode(new InstanceOf(typeInstruction, object, false, graph), graph)));
@@ -844,7 +842,7 @@
         if (constantValue != null) {
             frameState.push(constantValue.kind.stackKind(), appendConstant(constantValue));
         } else {
-            Value container = genTypeOrDeopt(RiType.Representation.StaticFields, holder, isInitialized, cpi);
+            Value container = genTypeOrDeopt(RiType.Representation.StaticFields, holder, isInitialized);
             CiKind kind = field.kind();
             if (container != null) {
                 LoadField load = new LoadField(container, field, graph);
@@ -858,7 +856,7 @@
 
     private void genPutStatic(int cpi, RiField field) {
         RiType holder = field.holder();
-        Value container = genTypeOrDeopt(RiType.Representation.StaticFields, holder, field.isResolved() && field.holder().isInitialized(), cpi);
+        Value container = genTypeOrDeopt(RiType.Representation.StaticFields, holder, field.isResolved() && field.holder().isInitialized());
         Value value = frameState.pop(field.kind().stackKind());
         if (container != null) {
             StoreField store = new StoreField(container, field, value, graph);
@@ -868,7 +866,7 @@
         }
     }
 
-    private Constant genTypeOrDeopt(RiType.Representation representation, RiType holder, boolean initialized, int cpi) {
+    private Constant genTypeOrDeopt(RiType.Representation representation, RiType holder, boolean initialized) {
         if (initialized) {
             return appendConstant(holder.getEncoding(representation));
         } else {
@@ -895,7 +893,7 @@
             // Re-use the same resolution code as for accessing a static field. Even though
             // the result of resolution is not used by the invocation (only the side effect
             // of initialization is required), it can be commoned with static field accesses.
-            genTypeOrDeopt(RiType.Representation.StaticFields, holder, isInitialized, cpi);
+            genTypeOrDeopt(RiType.Representation.StaticFields, holder, isInitialized);
         }
         Value[] args = frameState.popArguments(target.signature().argumentSlots(false));
         appendInvoke(INVOKESTATIC, target, args, cpi, constantPool);
@@ -1330,14 +1328,18 @@
             assert frameState.stackSize() == 1 : frameState;
 
             Block nextBlock = block.next == null ? unwindBlock(block.deoptBci) : block.next;
-            if (block.handler.catchType().isResolved()) {
+
+
+            RiType catchType = block.handler.catchType();
+            Constant typeInstruction = genTypeOrDeopt(RiType.Representation.ObjectHub, catchType, catchType.isResolved());
+            if (typeInstruction != null) {
                 FixedNode catchSuccessor = createTarget(blockFromBci[block.handler.handlerBCI()], frameState);
                 FixedNode nextDispatch = createTarget(nextBlock, frameState);
-                append(new ExceptionDispatch(frameState.stackAt(0), catchSuccessor, nextDispatch, block.handler.catchType(), graph));
-            } else {
-                Deoptimize deopt = new Deoptimize(DeoptAction.InvalidateRecompile, graph);
-                deopt.setMessage("unresolved " + block.handler.catchType().name());
-                append(deopt);
+                Value exception = frameState.stackAt(0);
+                If ifNode = new If(new InstanceOf(typeInstruction, exception, false, graph), graph);
+                append(ifNode);
+                ifNode.setTrueSuccessor(catchSuccessor);
+                ifNode.setFalseSuccessor(nextDispatch);
             }
         }
     }
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64LIRGenerator.java	Wed Jul 06 13:18:34 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64LIRGenerator.java	Wed Jul 06 13:28:51 2011 +0200
@@ -33,9 +33,6 @@
 import com.oracle.max.graal.compiler.util.*;
 import com.sun.cri.bytecode.*;
 import com.sun.cri.ci.*;
-import com.sun.cri.ri.*;
-import com.sun.cri.ri.RiType.*;
-import com.sun.cri.xir.*;
 
 /**
  * This class implements the X86-specific portion of the LIR generator.
@@ -466,30 +463,11 @@
     }
 
     @Override
-    public void visitExceptionDispatch(ExceptionDispatch x) {
-        // TODO ls: this needs some more work...
-
-        RiType riType = x.catchType();
-        assert riType.isResolved();
-
-        XirArgument obj = toXirArgument(x.exception());
-        XirArgument clazz = toXirArgument(riType.getEncoding(Representation.ObjectHub));
-        XirSnippet snippet = xir.genInstanceOf(site(x), obj, clazz, riType);
-        emitXir(snippet, x, stateFor(x), null, false);
-
-        LIRXirInstruction instr = (LIRXirInstruction) lir.instructionsList().get(lir.instructionsList().size() - 1);
-        instr.setTrueSuccessor(getLIRBlock(x.catchSuccessor()));
-        lir.jump(getLIRBlock(x.otherSuccessor()));
-    }
-
-    @Override
     public void visitLoopBegin(LoopBegin x) {
-
     }
 
     @Override
     public void visitValueAnchor(ValueAnchor valueAnchor) {
         // nothing to do for ValueAnchors
     }
-
 }