# HG changeset patch # User Josef Eisl # Date 1454493835 -3600 # Node ID 0fdbe9bbb647551ab648376bd003c9c41c9a8ace # Parent fe8c901fe8ff8f281b6bec78e319e5b4b9018031 GraalCompiler: add BailoutAndRestartBackendException and update OutOfRegistersException. diff -r fe8c901fe8ff -r 0fdbe9bbb647 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java Wed Jan 27 10:08:22 2016 +0100 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java Wed Feb 03 11:03:55 2016 +0100 @@ -23,9 +23,7 @@ package com.oracle.graal.compiler; import static com.oracle.graal.compiler.GraalCompilerOptions.EmitLIRRepeatCount; -import static com.oracle.graal.compiler.common.GraalOptions.RegisterPressure; import static com.oracle.graal.compiler.common.GraalOptions.UseGraalInstrumentation; -import static com.oracle.graal.compiler.common.alloc.RegisterAllocationConfig.ALL_REGISTERS; import static com.oracle.graal.phases.common.DeadCodeEliminationPhase.Optionality.Optional; import java.util.List; @@ -52,8 +50,8 @@ import com.oracle.graal.debug.DebugCloseable; import com.oracle.graal.debug.DebugMetric; import com.oracle.graal.debug.DebugTimer; +import com.oracle.graal.lir.BailoutAndRestartBackendException; import com.oracle.graal.lir.LIR; -import com.oracle.graal.lir.alloc.lsra.OutOfRegistersException; import com.oracle.graal.lir.asm.CompilationResultBuilder; import com.oracle.graal.lir.asm.CompilationResultBuilderFactory; import com.oracle.graal.lir.framemap.FrameMap; @@ -68,7 +66,6 @@ import com.oracle.graal.nodes.StructuredGraph.ScheduleResult; import com.oracle.graal.nodes.cfg.Block; import com.oracle.graal.nodes.spi.NodeLIRBuilderTool; -import com.oracle.graal.options.OptionValue; import com.oracle.graal.options.OptionValue.OverrideScope; import com.oracle.graal.phases.OptimisticOptimizations; import com.oracle.graal.phases.PhaseSuite; @@ -241,15 +238,16 @@ public static LIRGenerationResult emitLIR(Backend backend, StructuredGraph graph, Object stub, RegisterConfig registerConfig, LIRSuites lirSuites) { try { return emitLIR0(backend, graph, stub, registerConfig, lirSuites); - } catch (OutOfRegistersException e) { - if (RegisterPressure.getValue() != null && !RegisterPressure.getValue().equals(ALL_REGISTERS)) { - try (OverrideScope s = OptionValue.override(RegisterPressure, ALL_REGISTERS)) { - // retry with default register set - return emitLIR0(backend, graph, stub, registerConfig, lirSuites); + } catch (BailoutAndRestartBackendException e) { + if (BailoutAndRestartBackendException.Options.LIRUnlockBackendRestart.getValue() && e.shouldRestart()) { + try (OverrideScope scope = e.getOverrideScope()) { + LIRSuites lirSuites0 = e.updateLIRSuites(lirSuites); + if (lirSuites0 != null) { + return emitLIR0(backend, graph, stub, registerConfig, lirSuites0); + } } - } else { - throw e; } + throw e; } } diff -r fe8c901fe8ff -r 0fdbe9bbb647 graal/com.oracle.graal.lir/src/com/oracle/graal/lir/BailoutAndRestartBackendException.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/BailoutAndRestartBackendException.java Wed Feb 03 11:03:55 2016 +0100 @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2016, 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.graal.lir; + +import jdk.vm.ci.code.BailoutException; + +import com.oracle.graal.lir.phases.LIRSuites; +import com.oracle.graal.options.Option; +import com.oracle.graal.options.OptionType; +import com.oracle.graal.options.OptionValue; +import com.oracle.graal.options.OptionValue.OverrideScope; +import com.oracle.graal.options.StableOptionValue; + +/** + * Restarts the {@link LIR low-level} compilation with a modified configuration. + * {@link BailoutAndRestartBackendException.Options#LIRUnlockBackendRestart LIRUnlockBackendRestart} + * needs to be enabled. Use only for debugging purposes only. + */ +public abstract class BailoutAndRestartBackendException extends BailoutException { + + public static class Options { + // @formatter:off + @Option(help = "Unlock backend restart feature.", type = OptionType.Debug) + public static final StableOptionValue LIRUnlockBackendRestart = new StableOptionValue<>(false); + // @formatter:on + } + + private static final long serialVersionUID = 792969002851591180L; + + public BailoutAndRestartBackendException(String msg) { + super(msg); + } + + public BailoutAndRestartBackendException(Throwable cause, String msg) { + super(cause, msg); + } + + public BailoutAndRestartBackendException(boolean permanent, String msg) { + super(permanent, msg); + } + + /** Returns {@code true} if the low-level compilation should be restarted. */ + public abstract boolean shouldRestart(); + + /** + * Returns an {@link OverrideScope} to change {@link OptionValue OptionValues} or {@code null} + * if no changes are required. + */ + public abstract OverrideScope getOverrideScope(); + + /** + * Updates the {@link LIRSuites} used by the low-level compiler. Note that {@link LIRSuites} are + * usually shared, so a modified input parameter will affect other compilations. In case only + * the current compilation should be altered, create a copy using {@link LIRSuites#copy()}. + */ + public abstract LIRSuites updateLIRSuites(LIRSuites lirSuites); + +} diff -r fe8c901fe8ff -r 0fdbe9bbb647 graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/OutOfRegistersException.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/OutOfRegistersException.java Wed Jan 27 10:08:22 2016 +0100 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/OutOfRegistersException.java Wed Feb 03 11:03:55 2016 +0100 @@ -22,9 +22,15 @@ */ package com.oracle.graal.lir.alloc.lsra; -import jdk.vm.ci.code.BailoutException; +import static com.oracle.graal.compiler.common.GraalOptions.RegisterPressure; +import static com.oracle.graal.compiler.common.alloc.RegisterAllocationConfig.ALL_REGISTERS; -public class OutOfRegistersException extends BailoutException { +import com.oracle.graal.lir.BailoutAndRestartBackendException; +import com.oracle.graal.lir.phases.LIRSuites; +import com.oracle.graal.options.OptionValue; +import com.oracle.graal.options.OptionValue.OverrideScope; + +public class OutOfRegistersException extends BailoutAndRestartBackendException { private static final long serialVersionUID = -3479786650143432195L; @@ -63,4 +69,19 @@ public String getDescription() { return description; } + + @Override + public boolean shouldRestart() { + return RegisterPressure.getValue() != null && !RegisterPressure.getValue().equals(ALL_REGISTERS); + } + + @Override + public OverrideScope getOverrideScope() { + return OptionValue.override(RegisterPressure, ALL_REGISTERS); + } + + @Override + public LIRSuites updateLIRSuites(LIRSuites lirSuites) { + return lirSuites; + } }