# HG changeset patch # User Thomas Wuerthinger # Date 1328819186 -3600 # Node ID f55914bc1d6724dc7a4ec05c4c0aa9e4e9f76834 # Parent a3cdfa2be94e70fa3de90a0b792b1245a6b514df Added experimental ConvertDeoptimizeToGuardPhase. diff -r a3cdfa2be94e -r f55914bc1d67 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/ConvertDeoptimizeToGuardPhase.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/ConvertDeoptimizeToGuardPhase.java Thu Feb 09 21:26:26 2012 +0100 @@ -0,0 +1,73 @@ +/* + * Copyright (c) 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.phases; + +import java.util.*; + +import com.oracle.max.graal.graph.*; +import com.oracle.max.graal.nodes.*; + +public class ConvertDeoptimizeToGuardPhase extends Phase { + + private static BeginNode findBeginNode(Node startNode) { + Node n = startNode; + while (true) { + if (n instanceof BeginNode) { + return (BeginNode) n; + } else { + n = n.predecessor(); + } + } + } + + @Override + protected void run(final StructuredGraph graph) { + List nodes = graph.getNodes(DeoptimizeNode.class).snapshot(); + if (nodes.size() == 0) { + return; + } + + for (DeoptimizeNode d : nodes) { + BeginNode myBeginNode = findBeginNode(d); + Node controlSplit = myBeginNode.predecessor(); + + if (controlSplit instanceof IfNode) { + IfNode ifNode = (IfNode) controlSplit; + BeginNode otherBegin = ifNode.trueSuccessor(); + BooleanNode conditionNode = ifNode.compare(); + if (myBeginNode == ifNode.trueSuccessor()) { + conditionNode = conditionNode.negate(); + otherBegin = ifNode.falseSuccessor(); + } + BeginNode ifBlockBegin = findBeginNode(ifNode); + graph.unique(new GuardNode(conditionNode, ifBlockBegin)); + otherBegin.replaceAtUsages(ifBlockBegin); + FixedNode next = otherBegin.next(); + otherBegin.setNext(null); + ifNode.replaceAtPredecessors(next); + } + } + + new DeadCodeEliminationPhase().apply(graph); + } +} diff -r a3cdfa2be94e -r f55914bc1d67 graal/com.oracle.max.graal.java/src/com/oracle/max/graal/java/GraphBuilderConfiguration.java --- a/graal/com.oracle.max.graal.java/src/com/oracle/max/graal/java/GraphBuilderConfiguration.java Thu Feb 09 20:05:59 2012 +0100 +++ b/graal/com.oracle.max.graal.java/src/com/oracle/max/graal/java/GraphBuilderConfiguration.java Thu Feb 09 21:26:26 2012 +0100 @@ -22,6 +22,7 @@ */ package com.oracle.max.graal.java; +import com.oracle.max.cri.ri.*; import com.oracle.max.graal.compiler.*; import com.oracle.max.graal.compiler.phases.*; @@ -34,6 +35,7 @@ private final boolean useBranchPrediction; private final ResolvePolicy resolving; private final PhasePlan plan; + private RiResolvedType[] skippedExceptionTypes; public GraphBuilderConfiguration(boolean useBranchPrediction, ResolvePolicy resolving, PhasePlan plan) { this.useBranchPrediction = useBranchPrediction; @@ -45,6 +47,15 @@ return useBranchPrediction; } + + public void setSkippedExceptionTypes(RiResolvedType[] skippedExceptionTypes) { + this.skippedExceptionTypes = skippedExceptionTypes; + } + + public RiResolvedType[] getSkippedExceptionTypes() { + return skippedExceptionTypes; + } + public boolean eagerResolvingForSnippets() { return (resolving == ResolvePolicy.EagerForSnippets || resolving == ResolvePolicy.Eager); } diff -r a3cdfa2be94e -r f55914bc1d67 graal/com.oracle.max.graal.java/src/com/oracle/max/graal/java/GraphBuilderPhase.java --- a/graal/com.oracle.max.graal.java/src/com/oracle/max/graal/java/GraphBuilderPhase.java Thu Feb 09 20:05:59 2012 +0100 +++ b/graal/com.oracle.max.graal.java/src/com/oracle/max/graal/java/GraphBuilderPhase.java Thu Feb 09 21:26:26 2012 +0100 @@ -1446,7 +1446,18 @@ if (config.eagerResolving()) { catchType = lookupType(block.handler.catchTypeCPI(), INSTANCEOF); } - ConstantNode typeInstruction = genTypeOrDeopt(RiType.Representation.ObjectHub, catchType, (catchType instanceof RiResolvedType) && ((RiResolvedType) catchType).isInitialized()); + boolean initialized = (catchType instanceof RiResolvedType) && ((RiResolvedType) catchType).isInitialized(); + if (initialized && config.getSkippedExceptionTypes() != null) { + RiResolvedType resolvedCatchType = (RiResolvedType) catchType; + for (RiResolvedType skippedType : config.getSkippedExceptionTypes()) { + initialized &= !resolvedCatchType.isSubtypeOf(skippedType); + if (!initialized) { + break; + } + } + } + + ConstantNode typeInstruction = genTypeOrDeopt(RiType.Representation.ObjectHub, catchType, initialized); if (typeInstruction != null) { Block nextBlock = block.successors.size() == 1 ? unwindBlock(block.deoptBci) : block.successors.get(1); FixedNode catchSuccessor = createTarget(block.successors.get(0), frameState); diff -r a3cdfa2be94e -r f55914bc1d67 graal/com.oracle.max.graal.lir/src/com/oracle/max/graal/lir/cfg/Block.java --- a/graal/com.oracle.max.graal.lir/src/com/oracle/max/graal/lir/cfg/Block.java Thu Feb 09 20:05:59 2012 +0100 +++ b/graal/com.oracle.max.graal.lir/src/com/oracle/max/graal/lir/cfg/Block.java Thu Feb 09 21:26:26 2012 +0100 @@ -98,6 +98,19 @@ return dominator; } + public Block getEarliestPostDominated() { + Block b = this; + while (true) { + Block dom = b.getDominator(); + if (dom != null && dom.getPostdominator() == b) { + b = dom; + } else { + break; + } + } + return b; + } + public List getDominated() { if (dominated == null) { return Collections.emptyList();