Skip to content

Commit

Permalink
[GR-7464] Avoid reusing exception dispatch blocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
mur47x111 committed Dec 14, 2017
1 parent b29a94a commit afd24f2
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -748,15 +748,6 @@ private void createJsrAlternatives(BciBlock[] blockMap, BciBlock block) {
}
}

private EconomicMap<ExceptionHandler, ExceptionDispatchBlock> initialExceptionDispatch;

private EconomicMap<ExceptionHandler, ExceptionDispatchBlock> getInitialExceptionDispatch() {
if (initialExceptionDispatch == null) {
initialExceptionDispatch = EconomicMap.create(Equivalence.DEFAULT);
}
return initialExceptionDispatch;
}

private ExceptionDispatchBlock handleExceptions(BciBlock[] blockMap, int bci) {
ExceptionDispatchBlock lastHandler = null;

Expand All @@ -769,20 +760,17 @@ private ExceptionDispatchBlock handleExceptions(BciBlock[] blockMap, int bci) {
lastHandler = null;
}

EconomicMap<ExceptionHandler, ExceptionDispatchBlock> exceptionDispatch = lastHandler != null ? lastHandler.exceptionDispatch : getInitialExceptionDispatch();
ExceptionDispatchBlock curHandler = exceptionDispatch.get(h);
if (curHandler == null) {
curHandler = new ExceptionDispatchBlock();
blocksNotYetAssignedId++;
curHandler.startBci = -1;
curHandler.endBci = -1;
curHandler.deoptBci = bci;
curHandler.handler = h;
curHandler.addSuccessor(blockMap[h.getHandlerBCI()]);
if (lastHandler != null) {
curHandler.addSuccessor(lastHandler);
}
exceptionDispatch.put(h, curHandler);
// We do not reuse exception dispatch blocks, because nested exception handler might
// have problem reasoning the correct frame state.
ExceptionDispatchBlock curHandler = new ExceptionDispatchBlock();
blocksNotYetAssignedId++;
curHandler.startBci = -1;
curHandler.endBci = -1;
curHandler.deoptBci = bci;
curHandler.handler = h;
curHandler.addSuccessor(blockMap[h.getHandlerBCI()]);
if (lastHandler != null) {
curHandler.addSuccessor(lastHandler);
}
lastHandler = curHandler;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2788,6 +2788,10 @@ protected void processBlock(BciBlock block) {
setCurrentFrameState(frameState);
currentBlock = block;

if (block != blockMap.getUnwindBlock() && !(block instanceof ExceptionDispatchBlock)) {
frameState.setRethrowException(false);
}

if (firstInstruction instanceof AbstractMergeNode) {
setMergeStateAfter(block, firstInstruction);
}
Expand All @@ -2797,7 +2801,6 @@ protected void processBlock(BciBlock block) {
} else if (block instanceof ExceptionDispatchBlock) {
createExceptionDispatch((ExceptionDispatchBlock) block);
} else {
frameState.setRethrowException(false);
iterateBytecodesForBlock(block);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (c) 2017, 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 org.graalvm.compiler.replacements.test;

import org.graalvm.compiler.api.directives.GraalDirectives;
import org.graalvm.compiler.core.phases.HighTier;
import org.graalvm.compiler.core.test.GraalCompilerTest;
import org.graalvm.compiler.options.OptionValues;
import org.junit.Test;

public class NestedExceptionHandlerTest extends GraalCompilerTest {

@BytecodeParserNeverInline(invokeWithException = true)
public static void foo() {
}

@BytecodeParserNeverInline(invokeWithException = true)
public static void bar() {
throw new NegativeArraySizeException();
}

public static int nestedExceptionHandler() {
int flag = 0;
try {
try {
try {
foo();
} catch (NegativeArraySizeException e) {
flag = -1;
}
bar();
} catch (NullPointerException e) {
flag = -2;
}
} catch (Throwable e) {
GraalDirectives.deoptimize();
}
return flag;
}

@Test
public void testNestedExceptionHandler() {
test(new OptionValues(getInitialOptions(), HighTier.Options.Inline, false), "nestedExceptionHandler");
}

}

0 comments on commit afd24f2

Please sign in to comment.