# HG changeset patch # User Gilles Duboscq # Date 1398347512 -7200 # Node ID 2682747f71082ae187342eb9e26944b7bcc2729c # Parent 64afa46e6aed6850c3d19c24ded4e540fd679290 Refactoring in InliningUtil.processFrameStates, add some bci/monitor related asserts Fix a typo in InliningUtil.handleMissingAfterExceptionFrameState diff -r 64afa46e6aed -r 2682747f7108 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/DebugInfoBuilder.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/DebugInfoBuilder.java Thu Apr 24 12:17:29 2014 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/DebugInfoBuilder.java Thu Apr 24 15:51:52 2014 +0200 @@ -117,6 +117,15 @@ protected BytecodeFrame computeFrameForState(FrameState state) { try { + assert state.bci != BytecodeFrame.INVALID_FRAMESTATE_BCI; + assert state.bci != BytecodeFrame.UNKNOWN_BCI; + assert state.bci != BytecodeFrame.BEFORE_BCI || state.locksSize() == 0; + assert state.bci != BytecodeFrame.AFTER_BCI || state.locksSize() == 0; + assert state.bci != BytecodeFrame.AFTER_EXCEPTION_BCI || state.locksSize() == 0; + assert !(state.method().isSynchronized() && state.bci != BytecodeFrame.BEFORE_BCI && state.bci != BytecodeFrame.AFTER_BCI && state.bci != BytecodeFrame.AFTER_EXCEPTION_BCI) || + state.locksSize() > 0; + assert state.verify(); + int numLocals = state.localsSize(); int numStack = state.stackSize(); int numLocks = state.locksSize(); diff -r 64afa46e6aed -r 2682747f7108 graal/com.oracle.graal.java/src/com/oracle/graal/java/HIRFrameStateBuilder.java --- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/HIRFrameStateBuilder.java Thu Apr 24 12:17:29 2014 +0200 +++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/HIRFrameStateBuilder.java Thu Apr 24 15:51:52 2014 +0200 @@ -326,6 +326,7 @@ } finally { lockedObjects = lockedObjects.length == 1 ? EMPTY_ARRAY : Arrays.copyOf(lockedObjects, lockedObjects.length - 1); monitorIds = monitorIds.length == 1 ? EMPTY_MONITOR_ARRAY : Arrays.copyOf(monitorIds, monitorIds.length - 1); + assert lockedObjects.length == monitorIds.length; } } diff -r 64afa46e6aed -r 2682747f7108 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/FrameState.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/FrameState.java Thu Apr 24 12:17:29 2014 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/FrameState.java Thu Apr 24 15:51:52 2014 +0200 @@ -95,8 +95,8 @@ this.virtualObjectMappings = new NodeInputList<>(this, virtualObjectMappings); this.rethrowException = rethrowException; this.duringCall = duringCall; - assert !rethrowException || stackSize == 1 : "must have exception on top of the stack"; - assert values.size() - localsSize - stackSize == monitorIds.size(); + assert !this.rethrowException || this.stackSize == 1 : "must have exception on top of the stack"; + assert this.locksSize() == this.monitorIds.size(); } /** @@ -399,7 +399,7 @@ @Override public boolean verify() { - assertTrue(values.size() - localsSize - stackSize == monitorIds.size(), "mismatch in number of locks"); + assertTrue(locksSize() == monitorIds.size(), "mismatch in number of locks"); for (ValueNode value : values) { assertTrue(value == null || !value.isDeleted(), "frame state must not contain deleted nodes"); assertTrue(value == null || value instanceof VirtualObjectNode || (value.getKind() != Kind.Void), "unexpected value: %s", value); diff -r 64afa46e6aed -r 2682747f7108 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/InliningUtil.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/InliningUtil.java Thu Apr 24 12:17:29 2014 +0200 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/InliningUtil.java Thu Apr 24 15:51:52 2014 +0200 @@ -1439,47 +1439,43 @@ } protected static void processFrameStates(Invoke invoke, StructuredGraph inlineGraph, Map duplicates, FrameState stateAtExceptionEdge) { - FrameState stateAfter = invoke.stateAfter(); + FrameState stateAtReturn = invoke.stateAfter(); FrameState outerFrameState = null; Kind invokeReturnKind = invoke.asNode().getKind(); for (FrameState original : inlineGraph.getNodes(FrameState.class)) { FrameState frameState = (FrameState) duplicates.get(original); if (frameState != null && frameState.isAlive()) { - assert frameState.bci != BytecodeFrame.BEFORE_BCI : frameState; if (frameState.bci == BytecodeFrame.AFTER_BCI) { /* * pop return kind from invoke's stateAfter and replace with this frameState's * return value (top of stack) */ - Node otherFrameState = stateAfter; - if (invokeReturnKind != Kind.Void && frameState.stackSize() > 0) { - otherFrameState = stateAfter.duplicateModified(invokeReturnKind, frameState.stackAt(0)); + FrameState stateAfterReturn = stateAtReturn; + if (invokeReturnKind != Kind.Void && frameState.stackSize() > 0 && stateAfterReturn.stackAt(0) != frameState.stackAt(0)) { + stateAfterReturn = stateAtReturn.duplicateModified(invokeReturnKind, frameState.stackAt(0)); } - frameState.replaceAndDelete(otherFrameState); - } else if (frameState.bci == BytecodeFrame.AFTER_EXCEPTION_BCI || (frameState.bci == BytecodeFrame.UNWIND_BCI && !frameState.method().isSynchronized())) { - if (stateAtExceptionEdge != null) { - /* - * pop exception object from invoke's stateAfter and replace with this - * frameState's exception object (top of stack) - */ - Node newFrameState = stateAtExceptionEdge; - if (frameState.stackSize() > 0 && stateAtExceptionEdge.stackAt(0) != frameState.stackAt(0)) { - newFrameState = stateAtExceptionEdge.duplicateModified(Kind.Object, frameState.stackAt(0)); - } - frameState.replaceAndDelete(newFrameState); - } else { - handleMissingAfterExceptionFrameState(frameState); + frameState.replaceAndDelete(stateAfterReturn); + } else if (stateAtExceptionEdge != null && isStateAfterException(frameState)) { + /* + * pop exception object from invoke's stateAfter and replace with this + * frameState's exception object (top of stack) + */ + FrameState stateAfterException = stateAtExceptionEdge; + if (frameState.stackSize() > 0 && stateAtExceptionEdge.stackAt(0) != frameState.stackAt(0)) { + stateAfterException = stateAtExceptionEdge.duplicateModified(Kind.Object, frameState.stackAt(0)); } - } else if (frameState.bci == BytecodeFrame.UNWIND_BCI) { + frameState.replaceAndDelete(stateAfterException); + } else if (frameState.bci == BytecodeFrame.UNWIND_BCI || frameState.bci == BytecodeFrame.AFTER_EXCEPTION_BCI) { handleMissingAfterExceptionFrameState(frameState); } else { // only handle the outermost frame states if (frameState.outerFrameState() == null) { + assert frameState.bci != BytecodeFrame.BEFORE_BCI : frameState; assert frameState.bci == BytecodeFrame.INVALID_FRAMESTATE_BCI || frameState.method().equals(inlineGraph.method()); assert frameState.bci != BytecodeFrame.AFTER_EXCEPTION_BCI && frameState.bci != BytecodeFrame.BEFORE_BCI && frameState.bci != BytecodeFrame.AFTER_EXCEPTION_BCI && frameState.bci != BytecodeFrame.UNWIND_BCI : frameState.bci; if (outerFrameState == null) { - outerFrameState = stateAfter.duplicateModified(invoke.bci(), stateAfter.rethrowException(), invoke.asNode().getKind()); + outerFrameState = stateAtReturn.duplicateModified(invoke.bci(), stateAtReturn.rethrowException(), invokeReturnKind); outerFrameState.setDuringCall(true); } frameState.setOuterFrameState(outerFrameState); @@ -1489,10 +1485,14 @@ } } - protected static void handleMissingAfterExceptionFrameState(FrameState nonReplacableFrameState) { - Graph graph = nonReplacableFrameState.graph(); + private static boolean isStateAfterException(FrameState frameState) { + return frameState.bci == BytecodeFrame.AFTER_EXCEPTION_BCI || (frameState.bci == BytecodeFrame.UNWIND_BCI && !frameState.method().isSynchronized()); + } + + protected static void handleMissingAfterExceptionFrameState(FrameState nonReplaceableFrameState) { + Graph graph = nonReplaceableFrameState.graph(); NodeWorkList workList = graph.createNodeWorkList(); - workList.add(nonReplacableFrameState); + workList.add(nonReplaceableFrameState); for (Node node : workList) { FrameState fs = (FrameState) node; for (Node usage : fs.usages().snapshot()) {