# HG changeset patch # User Christian Wimmer # Date 1443735159 25200 # Node ID dfb01e333fc58f117afd169935f555838dc780d2 # Parent a19722cd3dd2c0bf37c038e33a0ef731e06ec957# Parent e55ba9746e5e2a7924486bf615a042e9572fdf05 Merge diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.asm.test/src/com/oracle/graal/asm/test/AssemblerTest.java --- a/graal/com.oracle.graal.asm.test/src/com/oracle/graal/asm/test/AssemblerTest.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.asm.test/src/com/oracle/graal/asm/test/AssemblerTest.java Thu Oct 01 14:32:39 2015 -0700 @@ -76,7 +76,7 @@ compResult.setTargetCode(targetCode, targetCode.length); compResult.setTotalFrameSize(0); - InstalledCode code = codeCache.addMethod(method, compResult, null, null); + InstalledCode code = codeCache.addCode(method, compResult, null, null); for (DisassemblerProvider dis : Services.load(DisassemblerProvider.class)) { String disasm1 = dis.disassembleCompiledCode(codeCache, compResult); diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.code/src/com/oracle/graal/code/DisassemblerProvider.java --- a/graal/com.oracle.graal.code/src/com/oracle/graal/code/DisassemblerProvider.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.code/src/com/oracle/graal/code/DisassemblerProvider.java Thu Oct 01 14:32:39 2015 -0700 @@ -34,8 +34,7 @@ /** * Gets a textual disassembly of a given compilation result. * - * @param codeCache the object used for code {@link CodeCacheProvider#addMethod code - * installation} + * @param codeCache the object used for code {@link CodeCacheProvider#addCode code installation} * @param compResult a compilation result * @return a non-zero length string containing a disassembly of {@code compResult} or null it * could not be disassembled @@ -47,8 +46,7 @@ /** * Gets a textual disassembly of a given installed code. * - * @param codeCache the object used for code {@link CodeCacheProvider#addMethod code - * installation} + * @param codeCache the object used for code {@link CodeCacheProvider#addCode code installation} * @param compResult a compiled code that was installed to produce {@code installedCode}. This * will be null if not available. * @param installedCode diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/BackendOptions.java --- a/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/BackendOptions.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/BackendOptions.java Thu Oct 01 14:32:39 2015 -0700 @@ -22,7 +22,6 @@ */ package com.oracle.graal.compiler.common; -import static com.oracle.graal.compiler.common.BackendOptions.UserOptions.LIREagerSSADestruction; import jdk.internal.jvmci.options.DerivedOptionValue; import jdk.internal.jvmci.options.DerivedOptionValue.OptionSupplier; import jdk.internal.jvmci.options.Option; @@ -79,7 +78,7 @@ if (UserOptions.LIROptSSILinearScan.getValue()) { return LSRAVariant.SSI_LSRA; } - if (GraalOptions.SSA_LIR.getValue() && !LIREagerSSADestruction.getValue()) { + if (GraalOptions.SSA_LIR.getValue() && !UserOptions.LIREagerSSADestruction.getValue()) { return LSRAVariant.SSA_LSRA; } return LSRAVariant.NONSSA_LSAR; diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/GraalOptions.java --- a/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/GraalOptions.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/GraalOptions.java Thu Oct 01 14:32:39 2015 -0700 @@ -311,4 +311,8 @@ return enabled; } }; + + @Option(help = "Enable compiler decision queries") + public static final OptionValue UseGraalQueries = new OptionValue<>(false); + } diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/spi/ForeignCallLinkage.java --- a/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/spi/ForeignCallLinkage.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/spi/ForeignCallLinkage.java Thu Oct 01 14:32:39 2015 -0700 @@ -44,8 +44,8 @@ CallingConvention getIncomingCallingConvention(); /** - * Returns the maximum absolute offset of PC relative call to this stub from any position in the - * code cache or -1 when not applicable. Intended for determining the required size of + * Returns the maximum absolute offset of a PC relative call to this stub from any position in + * the code cache or -1 when not applicable. Intended for determining the required size of * address/offset fields. */ long getMaxCallTargetOffset(); diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCLIRGenerator.java --- a/graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCLIRGenerator.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCLIRGenerator.java Thu Oct 01 14:32:39 2015 -0700 @@ -146,7 +146,6 @@ */ public abstract class SPARCLIRGenerator extends LIRGenerator { - private StackSlotValue tmpStackSlot; private SPARCSpillMoveFactory moveFactory; private Variable constantTableBase; private SPARCLoadConstantTableBaseOp loadConstantTableBaseOp; @@ -1053,10 +1052,7 @@ } protected StackSlotValue getTempSlot(LIRKind kind) { - if (tmpStackSlot == null) { - tmpStackSlot = getResult().getFrameMapBuilder().allocateSpillSlot(kind); - } - return tmpStackSlot; + return getResult().getFrameMapBuilder().allocateSpillSlot(kind); } protected SPARC getArchitecture() { diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerAssumptionsTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerAssumptionsTest.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerAssumptionsTest.java Thu Oct 01 14:32:39 2015 -0700 @@ -65,7 +65,7 @@ checkGraph(expectedAssumption, graph); CompilationResult compilationResult = compile(javaMethod, graph); - final InstalledCode installedCode = getProviders().getCodeCache().setDefaultMethod(javaMethod, compilationResult); + final InstalledCode installedCode = getProviders().getCodeCache().setDefaultCode(javaMethod, compilationResult); assertTrue(installedCode.isValid()); if (classToLoad != null) { String fullName = getClass().getName() + "$" + classToLoad; diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java Thu Oct 01 14:32:39 2015 -0700 @@ -779,7 +779,7 @@ } protected InstalledCode addMethod(final ResolvedJavaMethod method, final CompilationResult compResult) { - return getCodeCache().addMethod(method, compResult, null, null); + return getCodeCache().addCode(method, compResult, null, null); } private final Map methodMap = new HashMap<>(); diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/InstalledCodeInvalidationTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/InstalledCodeInvalidationTest.java Thu Oct 01 14:32:39 2015 -0700 @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2015, 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.compiler.test; + +import jdk.internal.jvmci.code.InstalledCode; +import jdk.internal.jvmci.code.InvalidInstalledCodeException; + +import org.junit.Test; + +import com.oracle.graal.api.directives.GraalDirectives; + +public class InstalledCodeInvalidationTest extends GraalCompilerTest { + + public void recurse(InstalledCode code, int depth) throws InvalidInstalledCodeException { + if (depth > 1) { + /* + * Recurse a few times to ensure there are multiple activations. + */ + code.executeVarargs(this, code, depth - 1); + } else { + /* + * Deoptimize this activation and make the compiled code no longer usable. + */ + + GraalDirectives.deoptimizeAndInvalidate(); + assert code.isAlive() && !code.isValid(); + code.invalidate(); + assert !code.isAlive(); + } + if (GraalDirectives.inCompiledCode()) { + /* + * If this still in compiled code then the deoptimizeAndInvalidate call above didn't + * remove all existing activations. + */ + throw new InternalError(); + } + } + + /** + * Test that after uncommon trapping in an installed code it's still possible to invalidate all + * existing activations of that installed code. + * + * @throws InvalidInstalledCodeException + */ + @Test + public void testInstalledCodeInvalidation() throws InvalidInstalledCodeException { + InstalledCode code = getCode(getMetaAccess().lookupJavaMethod(getMethod("recurse"))); + code.executeVarargs(this, code, 3); + } +} diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/deopt/MonitorDeoptTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/deopt/MonitorDeoptTest.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/deopt/MonitorDeoptTest.java Thu Oct 01 14:32:39 2015 -0700 @@ -147,7 +147,7 @@ removeLoopSafepoint(graph); CompilationResult compilationResult = compile(javaMethod, graph); - final InstalledCode installedCode = getProviders().getCodeCache().setDefaultMethod(javaMethod, compilationResult); + final InstalledCode installedCode = getProviders().getCodeCache().setDefaultCode(javaMethod, compilationResult); final Monitor monitor = new Monitor(); diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/tutorial/InvokeGraal.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/tutorial/InvokeGraal.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/tutorial/InvokeGraal.java Thu Oct 01 14:32:39 2015 -0700 @@ -138,7 +138,7 @@ * Install the compilation result into the VM, i.e., copy the byte[] array that contains * the machine code into an actual executable memory location. */ - InstalledCode installedCode = codeCache.addMethod(method, compilationResult, null, null); + InstalledCode installedCode = codeCache.addCode(method, compilationResult, null, null); return installedCode; } catch (Throwable ex) { diff -r a19722cd3dd2 -r dfb01e333fc5 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 Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java Thu Oct 01 14:32:39 2015 -0700 @@ -24,6 +24,7 @@ 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.UseGraalQueries; import static com.oracle.graal.compiler.common.alloc.RegisterAllocationConfig.ALL_REGISTERS; import static com.oracle.graal.phases.common.DeadCodeEliminationPhase.Optionality.Optional; @@ -75,6 +76,7 @@ import com.oracle.graal.phases.OptimisticOptimizations; import com.oracle.graal.phases.PhaseSuite; import com.oracle.graal.phases.common.DeadCodeEliminationPhase; +import com.oracle.graal.phases.common.query.ExtractICGPhase; import com.oracle.graal.phases.schedule.SchedulePhase; import com.oracle.graal.phases.tiers.HighTierContext; import com.oracle.graal.phases.tiers.LowTierContext; @@ -201,6 +203,9 @@ HighTierContext highTierContext = new HighTierContext(providers, graphBuilderSuite, optimisticOpts); if (graph.start().next() == null) { graphBuilderSuite.apply(graph, highTierContext); + if (UseGraalQueries.getValue()) { + new ExtractICGPhase().apply(graph, highTierContext); + } new DeadCodeEliminationPhase(Optional).apply(graph); } else { Debug.dump(graph, "initial state"); diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/HighTier.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/HighTier.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/HighTier.java Thu Oct 01 14:32:39 2015 -0700 @@ -31,7 +31,7 @@ import static com.oracle.graal.compiler.common.GraalOptions.OptConvertDeoptsToGuards; import static com.oracle.graal.compiler.common.GraalOptions.OptLoopTransform; import static com.oracle.graal.compiler.common.GraalOptions.PartialEscapeAnalysis; -import static com.oracle.graal.compiler.phases.HighTier.Options.Inline; +import static com.oracle.graal.compiler.common.GraalOptions.UseGraalQueries; import static com.oracle.graal.phases.common.DeadCodeEliminationPhase.Optionality.Optional; import jdk.internal.jvmci.options.Option; import jdk.internal.jvmci.options.OptionType; @@ -49,6 +49,7 @@ import com.oracle.graal.phases.common.LoweringPhase; import com.oracle.graal.phases.common.RemoveValueProxyPhase; import com.oracle.graal.phases.common.inlining.InliningPhase; +import com.oracle.graal.phases.common.query.HighTierReconcileICGPhase; import com.oracle.graal.phases.tiers.HighTierContext; import com.oracle.graal.virtual.phases.ea.PartialEscapePhase; @@ -72,7 +73,7 @@ appendPhase(canonicalizer); } - if (Inline.getValue()) { + if (Options.Inline.getValue()) { appendPhase(new InliningPhase(canonicalizer)); appendPhase(new DeadCodeEliminationPhase(Optional)); @@ -109,5 +110,8 @@ appendPhase(new RemoveValueProxyPhase()); appendPhase(new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER)); + if (UseGraalQueries.getValue()) { + appendPhase(new HighTierReconcileICGPhase()); + } } } diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/LowTier.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/LowTier.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/LowTier.java Thu Oct 01 14:32:39 2015 -0700 @@ -25,6 +25,7 @@ import static com.oracle.graal.compiler.common.GraalOptions.ConditionalElimination; import static com.oracle.graal.compiler.common.GraalOptions.ImmutableCode; import static com.oracle.graal.compiler.common.GraalOptions.OptCanonicalizer; +import static com.oracle.graal.compiler.common.GraalOptions.UseGraalQueries; import static com.oracle.graal.phases.common.DeadCodeEliminationPhase.Optionality.Required; import jdk.internal.jvmci.options.Option; import jdk.internal.jvmci.options.OptionType; @@ -40,6 +41,7 @@ import com.oracle.graal.phases.common.ProfileCompiledMethodsPhase; import com.oracle.graal.phases.common.RemoveValueProxyPhase; import com.oracle.graal.phases.common.UseTrappingNullChecksPhase; +import com.oracle.graal.phases.common.query.InlineICGPhase; import com.oracle.graal.phases.tiers.LowTierContext; public class LowTier extends PhaseSuite { @@ -64,6 +66,9 @@ } appendPhase(new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.LOW_TIER)); + if (UseGraalQueries.getValue()) { + appendPhase(new InlineICGPhase()); + } appendPhase(new RemoveValueProxyPhase()); diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/MidTier.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/MidTier.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/MidTier.java Thu Oct 01 14:32:39 2015 -0700 @@ -31,6 +31,7 @@ import static com.oracle.graal.compiler.common.GraalOptions.OptPushThroughPi; import static com.oracle.graal.compiler.common.GraalOptions.OptReadElimination; import static com.oracle.graal.compiler.common.GraalOptions.ReassociateInvariants; +import static com.oracle.graal.compiler.common.GraalOptions.UseGraalQueries; import static com.oracle.graal.compiler.common.GraalOptions.VerifyHeapAtReturn; import com.oracle.graal.loop.phases.LoopSafepointEliminationPhase; @@ -52,6 +53,7 @@ import com.oracle.graal.phases.common.RemoveValueProxyPhase; import com.oracle.graal.phases.common.ValueAnchorCleanupPhase; import com.oracle.graal.phases.common.VerifyHeapAtReturnPhase; +import com.oracle.graal.phases.common.query.MidTierReconcileICGPhase; import com.oracle.graal.phases.tiers.MidTierContext; import com.oracle.graal.virtual.phases.ea.EarlyReadEliminationPhase; @@ -113,6 +115,9 @@ } appendPhase(new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.MID_TIER)); + if (UseGraalQueries.getValue()) { + appendPhase(new MidTierReconcileICGPhase()); + } appendPhase(new FrameStateAssignmentPhase()); diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/target/Backend.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/target/Backend.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/target/Backend.java Thu Oct 01 14:32:39 2015 -0700 @@ -27,7 +27,6 @@ import jdk.internal.jvmci.code.CompilationResult; import jdk.internal.jvmci.code.RegisterConfig; import jdk.internal.jvmci.code.TargetDescription; -import jdk.internal.jvmci.code.stack.StackIntrospection; import jdk.internal.jvmci.common.JVMCIError; import jdk.internal.jvmci.meta.ConstantReflectionProvider; import jdk.internal.jvmci.meta.MetaAccessProvider; @@ -132,8 +131,6 @@ public abstract CompilationResultBuilder newCompilationResultBuilder(LIRGenerationResult lirGenResult, FrameMap frameMap, CompilationResult compilationResult, CompilationResultBuilderFactory factory); - public abstract StackIntrospection getStackIntrospection(); - /** * Emits the code for a given graph. * diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/query/DelimitationAPI.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/query/DelimitationAPI.java Thu Oct 01 14:32:39 2015 -0700 @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2015, 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.debug.query; + +public class DelimitationAPI { + + /** + * Marks the beginning of the instrumentation boundary. - The target parameter indicates whether + * to associate the instrumentation with the preceding or the following base program IR node. + * Supported values are -1 (predecessor), 1 (successor)}. + */ + public static void instrumentationBegin(@SuppressWarnings("unused") int offset) { + } + + public static void instrumentationBegin(@SuppressWarnings("unused") int offset, @SuppressWarnings("unused") int type) { + } + + /** + * Marks the end of the instrumentation boundary. + */ + public static void instrumentationEnd() { + } + +} diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/query/GraalQueryAPI.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/query/GraalQueryAPI.java Thu Oct 01 14:32:39 2015 -0700 @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2015, 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.debug.query; + +/** + * NOTE that these queries return fixed constants in the interpreter mode. The Graal option + * RemoveNeverExecutedCode is switched off to prevent de-optimization. + */ +public final class GraalQueryAPI { + + // Static query intrinsics + + /** + * @return true if the enclosing method has been compiled by the dynamic compiler. + */ + public static boolean isMethodCompiled() { + return false; + } + + /** + * @return true if the enclosing method is inlined. + */ + public static boolean isMethodInlined() { + return false; + } + + /** + * @return the name of the root method for the current compilation task. If the enclosing method + * is inlined, this query returns the name of the method into which it is inlined. + */ + public static String getRootName() { + return "unknown"; + } + + // Dynamic query intrinsics + + public static final int ERROR = -1; + + /** + * @return the kind of heap allocation for a directly preceding allocation site. The possible + * return values are {ERROR(-1), TLAB(0), HEAP(1)}. While ERROR denotes either the + * utility is not supported, e.g. in interpreter, or if the allocation site was + * eliminated, the other two represent a TLAB allocation (fast path) or a direct heap + * allocation (slow path). + */ + public static int getAllocationType() { + return ERROR; + } + + /** + * @return the runtime lock type for a directly preceding lock site. The possible return values + * are {ERROR(-1), bias:existing(0), bias:acquired(1), bias:transfer(2), + * stub:revoke_or_stub:epoch-expired(3), stub:failed-cas(4), recursive(5), cas(6)}. + */ + public static int getLockType() { + return ERROR; + } + +} diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/query/SpecialIntrinsicGuard.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/query/SpecialIntrinsicGuard.java Thu Oct 01 14:32:39 2015 -0700 @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2015, 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.debug.query; + +import jdk.internal.jvmci.meta.ResolvedJavaMethod; + +public class SpecialIntrinsicGuard { + + public static final String CN_DELIMITATIONAPI = DelimitationAPI.class.getName(); + public static final String CN_GRAALQUERYAPI = GraalQueryAPI.class.getName(); + + public static boolean isQueryIntrinsic(ResolvedJavaMethod method) { + String klass = method.getDeclaringClass().toJavaName(); + return CN_DELIMITATIONAPI.equals(klass) || CN_GRAALQUERYAPI.equals(klass); + } + +} diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackendFactory.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackendFactory.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackendFactory.java Thu Oct 01 14:32:39 2015 -0700 @@ -40,6 +40,7 @@ import jdk.internal.jvmci.hotspot.HotSpotMetaAccessProvider; import jdk.internal.jvmci.hotspot.HotSpotVMConfig; import jdk.internal.jvmci.inittimer.InitTimer; +import jdk.internal.jvmci.meta.ConstantReflectionProvider; import jdk.internal.jvmci.meta.Value; import jdk.internal.jvmci.runtime.JVMCIBackend; import jdk.internal.jvmci.service.ServiceProvider; @@ -108,13 +109,13 @@ foreignCalls = createForeignCalls(jvmciRuntime, graalRuntime, metaAccess, codeCache, nativeABICallerSaveRegisters); } try (InitTimer rt = timer("create Lowerer provider")) { - lowerer = createLowerer(graalRuntime, metaAccess, foreignCalls, registers, target); + lowerer = createLowerer(graalRuntime, metaAccess, foreignCalls, registers, constantReflection, target); } HotSpotStampProvider stampProvider = new HotSpotStampProvider(); Providers p = new Providers(metaAccess, codeCache, constantReflection, foreignCalls, lowerer, null, stampProvider); try (InitTimer rt = timer("create SnippetReflection provider")) { - snippetReflection = createSnippetReflection(graalRuntime); + snippetReflection = createSnippetReflection(graalRuntime, constantReflection); } try (InitTimer rt = timer("create Replacements provider")) { replacements = createReplacements(config, p, snippetReflection); @@ -167,13 +168,13 @@ registers.getHeapBaseRegister())); } - protected HotSpotSnippetReflectionProvider createSnippetReflection(HotSpotGraalRuntimeProvider runtime) { - return new HotSpotSnippetReflectionProvider(runtime); + protected HotSpotSnippetReflectionProvider createSnippetReflection(HotSpotGraalRuntimeProvider runtime, ConstantReflectionProvider constantReflection) { + return new HotSpotSnippetReflectionProvider(runtime, constantReflection); } protected HotSpotLoweringProvider createLowerer(HotSpotGraalRuntimeProvider runtime, HotSpotMetaAccessProvider metaAccess, HotSpotForeignCallsProvider foreignCalls, - HotSpotRegistersProvider registers, TargetDescription target) { - return new AMD64HotSpotLoweringProvider(runtime, metaAccess, foreignCalls, registers, target); + HotSpotRegistersProvider registers, ConstantReflectionProvider constantReflection, TargetDescription target) { + return new AMD64HotSpotLoweringProvider(runtime, metaAccess, foreignCalls, registers, constantReflection, target); } protected Value[] createNativeABICallerSaveRegisters(HotSpotVMConfig config, RegisterConfig regConfig) { diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotForeignCallsProvider.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotForeignCallsProvider.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotForeignCallsProvider.java Thu Oct 01 14:32:39 2015 -0700 @@ -41,7 +41,6 @@ import jdk.internal.jvmci.code.CodeCacheProvider; import jdk.internal.jvmci.code.RegisterValue; import jdk.internal.jvmci.code.TargetDescription; -import jdk.internal.jvmci.hotspot.CompilerToVM; import jdk.internal.jvmci.hotspot.HotSpotJVMCIRuntimeProvider; import jdk.internal.jvmci.hotspot.HotSpotVMConfig; import jdk.internal.jvmci.meta.LIRKind; @@ -76,9 +75,8 @@ RegisterValue exception = rax.asValue(LIRKind.reference(word)); RegisterValue exceptionPc = rdx.asValue(LIRKind.value(word)); CallingConvention exceptionCc = new CallingConvention(0, ILLEGAL, exception, exceptionPc); - CompilerToVM vm = jvmciRuntime.getCompilerToVM(); - register(new HotSpotForeignCallLinkageImpl(vm, EXCEPTION_HANDLER, 0L, PRESERVES_REGISTERS, LEAF_NOFP, null, exceptionCc, NOT_REEXECUTABLE, any())); - register(new HotSpotForeignCallLinkageImpl(vm, EXCEPTION_HANDLER_IN_CALLER, JUMP_ADDRESS, PRESERVES_REGISTERS, LEAF_NOFP, exceptionCc, null, NOT_REEXECUTABLE, any())); + register(new HotSpotForeignCallLinkageImpl(EXCEPTION_HANDLER, 0L, PRESERVES_REGISTERS, LEAF_NOFP, null, exceptionCc, NOT_REEXECUTABLE, any())); + register(new HotSpotForeignCallLinkageImpl(EXCEPTION_HANDLER_IN_CALLER, JUMP_ADDRESS, PRESERVES_REGISTERS, LEAF_NOFP, exceptionCc, null, NOT_REEXECUTABLE, any())); if (PreferGraalStubs.getValue()) { link(new AMD64DeoptimizationStub(providers, target, config, registerStubCall(DEOPTIMIZATION_HANDLER, REEXECUTABLE, LEAF, NO_LOCATIONS))); diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLIRGenerator.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLIRGenerator.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLIRGenerator.java Thu Oct 01 14:32:39 2015 -0700 @@ -30,7 +30,6 @@ import static com.oracle.graal.hotspot.HotSpotBackend.UNCOMMON_TRAP; import static com.oracle.graal.lir.LIRValueUtil.asConstant; import static com.oracle.graal.lir.LIRValueUtil.isConstantValue; -import static jdk.internal.jvmci.amd64.AMD64.cpuxmmRegisters; import static jdk.internal.jvmci.amd64.AMD64.rbp; import java.util.ArrayList; @@ -358,7 +357,7 @@ public SaveRegistersOp emitSaveAllRegisters() { // We are saving all registers. // TODO Save upper half of YMM registers. - return emitSaveAllRegisters(cpuxmmRegisters, false); + return emitSaveAllRegisters(target().arch.getAvailableValueRegisters(), false); } protected void emitRestoreRegisters(AMD64SaveRegistersOp save) { diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLoweringProvider.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLoweringProvider.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLoweringProvider.java Thu Oct 01 14:32:39 2015 -0700 @@ -24,6 +24,7 @@ import jdk.internal.jvmci.code.TargetDescription; import jdk.internal.jvmci.hotspot.HotSpotVMConfig; +import jdk.internal.jvmci.meta.ConstantReflectionProvider; import jdk.internal.jvmci.meta.MetaAccessProvider; import com.oracle.graal.compiler.common.spi.ForeignCallsProvider; @@ -41,8 +42,8 @@ private AMD64ConvertSnippets.Templates convertSnippets; public AMD64HotSpotLoweringProvider(HotSpotGraalRuntimeProvider runtime, MetaAccessProvider metaAccess, ForeignCallsProvider foreignCalls, HotSpotRegistersProvider registers, - TargetDescription target) { - super(runtime, metaAccess, foreignCalls, registers, target); + ConstantReflectionProvider constantReflection, TargetDescription target) { + super(runtime, metaAccess, foreignCalls, registers, constantReflection, target); } @Override diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotRegisterAllocationConfig.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotRegisterAllocationConfig.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotRegisterAllocationConfig.java Thu Oct 01 14:32:39 2015 -0700 @@ -53,6 +53,7 @@ import static jdk.internal.jvmci.amd64.AMD64.xmm8; import static jdk.internal.jvmci.amd64.AMD64.xmm9; +import java.util.ArrayList; import java.util.BitSet; import jdk.internal.jvmci.code.Register; @@ -90,16 +91,14 @@ regMap.set(reg.number); } - Register[] allocatableRegisters = new Register[registers.length]; - int i = 0; + ArrayList allocatableRegisters = new ArrayList<>(registers.length); for (Register reg : registerAllocationOrder) { if (regMap.get(reg.number)) { - allocatableRegisters[i++] = reg; + allocatableRegisters.add(reg); } } - assert i == allocatableRegisters.length; - return super.initAllocatable(allocatableRegisters); + return super.initAllocatable(allocatableRegisters.toArray(new Register[allocatableRegisters.size()])); } @Override diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotBackendFactory.java --- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotBackendFactory.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotBackendFactory.java Thu Oct 01 14:32:39 2015 -0700 @@ -36,6 +36,7 @@ import jdk.internal.jvmci.hotspot.HotSpotJVMCIRuntimeProvider; import jdk.internal.jvmci.hotspot.HotSpotMetaAccessProvider; import jdk.internal.jvmci.hotspot.HotSpotVMConfig; +import jdk.internal.jvmci.meta.ConstantReflectionProvider; import jdk.internal.jvmci.meta.Value; import jdk.internal.jvmci.runtime.JVMCIBackend; import jdk.internal.jvmci.service.ServiceProvider; @@ -86,10 +87,10 @@ HotSpotConstantReflectionProvider constantReflection = new HotSpotGraalConstantReflectionProvider(jvmciRuntime); Value[] nativeABICallerSaveRegisters = createNativeABICallerSaveRegisters(config, codeCache.getRegisterConfig()); HotSpotForeignCallsProvider foreignCalls = new SPARCHotSpotForeignCallsProvider(jvmciRuntime, runtime, metaAccess, codeCache, nativeABICallerSaveRegisters); - LoweringProvider lowerer = createLowerer(runtime, metaAccess, foreignCalls, registers, target); + LoweringProvider lowerer = createLowerer(runtime, metaAccess, foreignCalls, registers, constantReflection, target); HotSpotStampProvider stampProvider = new HotSpotStampProvider(); Providers p = new Providers(metaAccess, codeCache, constantReflection, foreignCalls, lowerer, null, stampProvider); - HotSpotSnippetReflectionProvider snippetReflection = new HotSpotSnippetReflectionProvider(runtime); + HotSpotSnippetReflectionProvider snippetReflection = new HotSpotSnippetReflectionProvider(runtime, constantReflection); HotSpotReplacementsImpl replacements = new HotSpotReplacementsImpl(p, snippetReflection, config, target); HotSpotWordTypes wordTypes = new HotSpotWordTypes(metaAccess, target.wordJavaKind); Plugins plugins = createGraphBuilderPlugins(config, metaAccess, constantReflection, foreignCalls, stampProvider, snippetReflection, replacements, wordTypes); @@ -117,8 +118,8 @@ } protected HotSpotLoweringProvider createLowerer(HotSpotGraalRuntimeProvider runtime, HotSpotMetaAccessProvider metaAccess, HotSpotForeignCallsProvider foreignCalls, - HotSpotRegistersProvider registers, TargetDescription target) { - return new SPARCHotSpotLoweringProvider(runtime, metaAccess, foreignCalls, registers, target); + HotSpotRegistersProvider registers, ConstantReflectionProvider constantReflection, TargetDescription target) { + return new SPARCHotSpotLoweringProvider(runtime, metaAccess, foreignCalls, registers, constantReflection, target); } protected HotSpotRegistersProvider createRegisters() { diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotForeignCallsProvider.java --- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotForeignCallsProvider.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotForeignCallsProvider.java Thu Oct 01 14:32:39 2015 -0700 @@ -41,7 +41,6 @@ import jdk.internal.jvmci.code.CodeCacheProvider; import jdk.internal.jvmci.code.RegisterValue; import jdk.internal.jvmci.code.TargetDescription; -import jdk.internal.jvmci.hotspot.CompilerToVM; import jdk.internal.jvmci.hotspot.HotSpotJVMCIRuntimeProvider; import jdk.internal.jvmci.meta.JavaKind; import jdk.internal.jvmci.meta.LIRKind; @@ -78,9 +77,8 @@ RegisterValue incomingExceptionPc = i1.asValue(LIRKind.value(word)); CallingConvention outgoingExceptionCc = new CallingConvention(0, ILLEGAL, outgoingException, outgoingExceptionPc); CallingConvention incomingExceptionCc = new CallingConvention(0, ILLEGAL, incomingException, incomingExceptionPc); - CompilerToVM vm = jvmciRuntime.getCompilerToVM(); - register(new HotSpotForeignCallLinkageImpl(vm, EXCEPTION_HANDLER, 0L, PRESERVES_REGISTERS, LEAF_NOFP, outgoingExceptionCc, incomingExceptionCc, NOT_REEXECUTABLE, any())); - register(new HotSpotForeignCallLinkageImpl(vm, EXCEPTION_HANDLER_IN_CALLER, JUMP_ADDRESS, PRESERVES_REGISTERS, LEAF_NOFP, outgoingExceptionCc, incomingExceptionCc, NOT_REEXECUTABLE, any())); + register(new HotSpotForeignCallLinkageImpl(EXCEPTION_HANDLER, 0L, PRESERVES_REGISTERS, LEAF_NOFP, outgoingExceptionCc, incomingExceptionCc, NOT_REEXECUTABLE, any())); + register(new HotSpotForeignCallLinkageImpl(EXCEPTION_HANDLER_IN_CALLER, JUMP_ADDRESS, PRESERVES_REGISTERS, LEAF_NOFP, outgoingExceptionCc, incomingExceptionCc, NOT_REEXECUTABLE, any())); if (PreferGraalStubs.getValue()) { link(new SPARCDeoptimizationStub(providers, target, registerStubCall(DEOPTIMIZATION_HANDLER, REEXECUTABLE, LEAF, NO_LOCATIONS))); diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotLoweringProvider.java --- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotLoweringProvider.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotLoweringProvider.java Thu Oct 01 14:32:39 2015 -0700 @@ -23,6 +23,7 @@ package com.oracle.graal.hotspot.sparc; import jdk.internal.jvmci.code.TargetDescription; +import jdk.internal.jvmci.meta.ConstantReflectionProvider; import jdk.internal.jvmci.meta.MetaAccessProvider; import com.oracle.graal.compiler.common.spi.ForeignCallsProvider; @@ -36,8 +37,8 @@ public class SPARCHotSpotLoweringProvider extends DefaultHotSpotLoweringProvider { public SPARCHotSpotLoweringProvider(HotSpotGraalRuntimeProvider runtime, MetaAccessProvider metaAccess, ForeignCallsProvider foreignCalls, HotSpotRegistersProvider registers, - TargetDescription target) { - super(runtime, metaAccess, foreignCalls, registers, target); + ConstantReflectionProvider constantReflection, TargetDescription target) { + super(runtime, metaAccess, foreignCalls, registers, constantReflection, target); } @Override diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/AheadOfTimeCompilationTest.java --- a/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/AheadOfTimeCompilationTest.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/AheadOfTimeCompilationTest.java Thu Oct 01 14:32:39 2015 -0700 @@ -30,8 +30,8 @@ import jdk.internal.jvmci.code.CallingConvention; import jdk.internal.jvmci.code.CallingConvention.Type; import jdk.internal.jvmci.code.CompilationResult; -import jdk.internal.jvmci.hotspot.HotSpotObjectConstantImpl; import jdk.internal.jvmci.hotspot.HotSpotResolvedObjectType; +import jdk.internal.jvmci.meta.JavaConstant; import jdk.internal.jvmci.meta.JavaKind; import jdk.internal.jvmci.meta.ResolvedJavaMethod; import jdk.internal.jvmci.options.OptionValue; @@ -119,9 +119,8 @@ NodeIterable filter = getConstantNodes(result); assertDeepEquals(1, filter.count()); - HotSpotObjectConstantImpl c = (HotSpotObjectConstantImpl) filter.first().asConstant(); - Assert.assertEquals(Class.class, c.getObjectClass()); - Assert.assertTrue(c.isEqualTo(AheadOfTimeCompilationTest.class)); + JavaConstant c = filter.first().asJavaConstant(); + Assert.assertEquals(getSnippetReflection().asObject(Class.class, c), AheadOfTimeCompilationTest.class); assertDeepEquals(0, result.getNodes().filter(FloatingReadNode.class).count()); assertDeepEquals(0, result.getNodes().filter(ReadNode.class).count()); @@ -148,9 +147,8 @@ StructuredGraph result = compile("getPrimitiveClassObject", false); NodeIterable filter = getConstantNodes(result); assertDeepEquals(1, filter.count()); - HotSpotObjectConstantImpl c = (HotSpotObjectConstantImpl) filter.first().asConstant(); - Assert.assertEquals(Class.class, c.getObjectClass()); - Assert.assertTrue(c.isEqualTo(Integer.TYPE)); + JavaConstant c = filter.first().asJavaConstant(); + Assert.assertEquals(getSnippetReflection().asObject(Class.class, c), Integer.TYPE); assertDeepEquals(0, result.getNodes().filter(FloatingReadNode.class).count()); assertDeepEquals(0, result.getNodes().filter(ReadNode.class).count()); @@ -176,9 +174,8 @@ NodeIterable filter = getConstantNodes(result); assertDeepEquals(1, filter.count()); - HotSpotObjectConstantImpl c = (HotSpotObjectConstantImpl) filter.first().asConstant(); - Assert.assertEquals(String.class, c.getObjectClass()); - Assert.assertTrue(c.isEqualTo("test string")); + JavaConstant c = filter.first().asJavaConstant(); + Assert.assertEquals(getSnippetReflection().asObject(String.class, c), "test string"); assertDeepEquals(0, result.getNodes().filter(FloatingReadNode.class).count()); assertDeepEquals(0, result.getNodes().filter(ReadNode.class).count()); @@ -210,8 +207,8 @@ ConstantNode constant = getConstantNodes(result).first(); assertDeepEquals(JavaKind.Object, constant.getStackKind()); - HotSpotObjectConstantImpl c = (HotSpotObjectConstantImpl) constant.asConstant(); - Assert.assertTrue(c.isEqualTo(Boolean.TRUE)); + JavaConstant c = constant.asJavaConstant(); + Assert.assertEquals(getSnippetReflection().asObject(Boolean.class, c), Boolean.TRUE); } @SuppressWarnings("try") diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/HotSpotCryptoSubstitutionTest.java --- a/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/HotSpotCryptoSubstitutionTest.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/HotSpotCryptoSubstitutionTest.java Thu Oct 01 14:32:39 2015 -0700 @@ -23,7 +23,6 @@ package com.oracle.graal.hotspot.test; import static com.oracle.graal.graphbuilderconf.IntrinsicContext.CompilationContext.ROOT_COMPILATION; -import static jdk.internal.jvmci.hotspot.CompilerToVM.compilerToVM; import static jdk.internal.jvmci.hotspot.HotSpotVMConfig.config; import java.io.ByteArrayOutputStream; @@ -40,10 +39,6 @@ import jdk.internal.jvmci.code.CompilationResult; import jdk.internal.jvmci.code.InstalledCode; -import jdk.internal.jvmci.hotspot.HotSpotCompiledNmethod; -import jdk.internal.jvmci.hotspot.HotSpotNmethod; -import jdk.internal.jvmci.hotspot.HotSpotResolvedJavaMethod; -import jdk.internal.jvmci.hotspot.HotSpotVMConfig; import jdk.internal.jvmci.meta.ResolvedJavaMethod; import org.junit.Assert; @@ -65,17 +60,7 @@ @Override protected InstalledCode addMethod(ResolvedJavaMethod method, CompilationResult compResult) { - HotSpotResolvedJavaMethod hsMethod = (HotSpotResolvedJavaMethod) method; - HotSpotNmethod installedCode = new HotSpotNmethod(hsMethod, compResult.getName(), true); - HotSpotCompiledNmethod compiledNmethod = new HotSpotCompiledNmethod(hsMethod, compResult); - int result = compilerToVM().installCode(getTarget(), compiledNmethod, installedCode, null); - HotSpotVMConfig config = config(); - Assert.assertEquals("Error installing method " + method + ": " + config.getCodeInstallResultDescription(result), result, config.codeInstallResultOk); - - // HotSpotRuntime hsRuntime = (HotSpotRuntime) getCodeCache(); - // TTY.println(hsMethod.toString()); - // TTY.println(hsRuntime.disassemble(installedCode)); - return installedCode; + return getCodeCache().setDefaultCode(method, compResult); } SecretKey aesKey; diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/InstalledCodeExecuteHelperTest.java --- a/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/InstalledCodeExecuteHelperTest.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/InstalledCodeExecuteHelperTest.java Thu Oct 01 14:32:39 2015 -0700 @@ -25,7 +25,6 @@ import static java.lang.reflect.Modifier.isStatic; import jdk.internal.jvmci.code.InvalidInstalledCodeException; import jdk.internal.jvmci.hotspot.HotSpotInstalledCode; -import jdk.internal.jvmci.hotspot.HotSpotObjectConstantImpl; import jdk.internal.jvmci.meta.JavaConstant; import jdk.internal.jvmci.meta.JavaType; import jdk.internal.jvmci.meta.ResolvedJavaMethod; @@ -84,7 +83,7 @@ assert parameterTypes.length == args.length; for (int i = 0; i < argsToBind.length; i++) { ParameterNode param = graph.getParameter(i); - JavaConstant c = HotSpotObjectConstantImpl.forBoxedValue(parameterTypes[i].getJavaKind(), argsToBind[i]); + JavaConstant c = getSnippetReflection().forBoxed(parameterTypes[i].getJavaKind(), argsToBind[i]); ConstantNode replacement = ConstantNode.forConstant(c, getMetaAccess(), graph); param.replaceAtUsages(replacement); } diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/MemoryUsageBenchmark.java --- a/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/MemoryUsageBenchmark.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/MemoryUsageBenchmark.java Thu Oct 01 14:32:39 2015 -0700 @@ -23,6 +23,8 @@ package com.oracle.graal.hotspot.test; import static com.oracle.graal.debug.internal.MemUseTrackerImpl.getCurrentThreadAllocatedBytes; +import jdk.internal.jvmci.compiler.Compiler; +import jdk.internal.jvmci.hotspot.HotSpotCompilationRequest; import jdk.internal.jvmci.hotspot.HotSpotJVMCIRuntime; import jdk.internal.jvmci.hotspot.HotSpotJVMCIRuntimeProvider; import jdk.internal.jvmci.hotspot.HotSpotResolvedJavaMethod; @@ -135,12 +137,13 @@ // invalidate any existing compiled code method.reprofile(); - int id = method.allocateCompileId(jdk.internal.jvmci.compiler.Compiler.INVOCATION_ENTRY_BCI); - long graalEnv = 0L; + long jvmciEnv = 0L; try (MemoryUsageCloseable c = label == null ? null : new MemoryUsageCloseable(label)) { HotSpotJVMCIRuntimeProvider runtime = HotSpotJVMCIRuntime.runtime(); - CompilationTask task = new CompilationTask(runtime, (HotSpotGraalCompiler) runtime.getCompiler(), method, jdk.internal.jvmci.compiler.Compiler.INVOCATION_ENTRY_BCI, graalEnv, id, false); + int entryBCI = Compiler.INVOCATION_ENTRY_BCI; + HotSpotCompilationRequest request = new HotSpotCompilationRequest(method, entryBCI, jvmciEnv); + CompilationTask task = new CompilationTask(runtime, (HotSpotGraalCompiler) runtime.getCompiler(), request, false); task.runCompilation(); } } @@ -153,12 +156,11 @@ // invalidate any existing compiled code method.reprofile(); - int id = method.allocateCompileId(jdk.internal.jvmci.compiler.Compiler.INVOCATION_ENTRY_BCI); - long graalEnv = 0L; + long jvmciEnv = 0L; try (AllocSpy as = AllocSpy.open(methodName)) { HotSpotJVMCIRuntimeProvider runtime = HotSpotJVMCIRuntime.runtime(); - CompilationTask task = new CompilationTask(runtime, (HotSpotGraalCompiler) runtime.getCompiler(), method, jdk.internal.jvmci.compiler.Compiler.INVOCATION_ENTRY_BCI, graalEnv, id, - false); + HotSpotCompilationRequest request = new HotSpotCompilationRequest(method, Compiler.INVOCATION_ENTRY_BCI, jvmciEnv); + CompilationTask task = new CompilationTask(runtime, (HotSpotGraalCompiler) runtime.getCompiler(), request, false); task.runCompilation(); } } diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java Thu Oct 01 14:32:39 2015 -0700 @@ -34,11 +34,12 @@ import java.util.concurrent.TimeUnit; import jdk.internal.jvmci.code.BailoutException; +import jdk.internal.jvmci.code.CodeCacheProvider; import jdk.internal.jvmci.code.CompilationResult; import jdk.internal.jvmci.code.InstalledCode; import jdk.internal.jvmci.compiler.Compiler; -import jdk.internal.jvmci.hotspot.CompilerToVM; import jdk.internal.jvmci.hotspot.HotSpotCodeCacheProvider; +import jdk.internal.jvmci.hotspot.HotSpotCompilationRequest; import jdk.internal.jvmci.hotspot.HotSpotInstalledCode; import jdk.internal.jvmci.hotspot.HotSpotJVMCIRuntimeProvider; import jdk.internal.jvmci.hotspot.HotSpotNmethod; @@ -48,7 +49,6 @@ import jdk.internal.jvmci.hotspot.events.EventProvider; import jdk.internal.jvmci.hotspot.events.EventProvider.CompilationEvent; import jdk.internal.jvmci.hotspot.events.EventProvider.CompilerFailureEvent; -import jdk.internal.jvmci.meta.ResolvedJavaMethod; import jdk.internal.jvmci.service.Services; import sun.misc.Unsafe; @@ -97,10 +97,7 @@ private final HotSpotJVMCIRuntimeProvider jvmciRuntime; private final HotSpotGraalCompiler compiler; - - private final HotSpotResolvedJavaMethod method; - private final int entryBCI; - private final int id; + private final HotSpotCompilationRequest request; /** * Specifies whether the compilation result is installed as the @@ -116,23 +113,15 @@ static final com.sun.management.ThreadMXBean threadMXBean = (com.sun.management.ThreadMXBean) Management.getThreadMXBean(); } - /** - * The address of the JVMCIEnv associated with this compilation or 0L if no such object exists. - */ - private final long jvmciEnv; - - public CompilationTask(HotSpotJVMCIRuntimeProvider jvmciRuntime, HotSpotGraalCompiler compiler, HotSpotResolvedJavaMethod method, int entryBCI, long jvmciEnv, int id, boolean installAsDefault) { + public CompilationTask(HotSpotJVMCIRuntimeProvider jvmciRuntime, HotSpotGraalCompiler compiler, HotSpotCompilationRequest request, boolean installAsDefault) { this.jvmciRuntime = jvmciRuntime; this.compiler = compiler; - this.method = method; - this.entryBCI = entryBCI; - this.id = id; - this.jvmciEnv = jvmciEnv; + this.request = request; this.installAsDefault = installAsDefault; } - public ResolvedJavaMethod getMethod() { - return method; + public HotSpotResolvedJavaMethod getMethod() { + return request.getMethod(); } /** @@ -141,11 +130,11 @@ * @return compile id */ public int getId() { - return id; + return request.getId(); } public int getEntryBCI() { - return entryBCI; + return request.getEntryBCI(); } /** @@ -166,7 +155,9 @@ final long threadId = Thread.currentThread().getId(); long startCompilationTime = System.nanoTime(); HotSpotInstalledCode installedCode = null; + int entryBCI = getEntryBCI(); final boolean isOSR = entryBCI != Compiler.INVOCATION_ENTRY_BCI; + HotSpotResolvedJavaMethod method = getMethod(); // Log a compilation event. CompilationEvent compilationEvent = eventProvider.newCompilationEvent(); @@ -198,13 +189,10 @@ allocatedBytesBefore = 0L; } - try (Scope s = Debug.scope("Compiling", new DebugDumpScope(String.valueOf(id), true))) { + try (Scope s = Debug.scope("Compiling", new DebugDumpScope(String.valueOf(getId()), true))) { // Begin the compilation event. compilationEvent.begin(); - result = compiler.compile(method, entryBCI, mustRecordMethodInlining(config)); - - result.setId(getId()); } catch (Throwable e) { throw Debug.handle(e); } finally { @@ -222,13 +210,15 @@ if (printAfterCompilation) { TTY.println(getMethodDescription() + String.format(" | %4dms %5dB %5dkB", stop - start, targetCodeSize, allocatedBytes)); } else if (printCompilation) { - TTY.println(String.format("%-6d JVMCI %-70s %-45s %-50s | %4dms %5dB %5dkB", id, "", "", "", stop - start, targetCodeSize, allocatedBytes)); + TTY.println(String.format("%-6d JVMCI %-70s %-45s %-50s | %4dms %5dB %5dkB", getId(), "", "", "", stop - start, targetCodeSize, allocatedBytes)); } } } - try (DebugCloseable b = CodeInstallationTime.start()) { - installedCode = (HotSpotInstalledCode) installMethod(result); + if (result != null) { + try (DebugCloseable b = CodeInstallationTime.start()) { + installedCode = (HotSpotInstalledCode) installMethod(result); + } } stats.finish(method, installedCode); } catch (BailoutException bailout) { @@ -280,6 +270,7 @@ compilationEvent.commit(); } + long jvmciEnv = request.getJvmciEnv(); if (jvmciEnv != 0) { long ctask = UNSAFE.getAddress(jvmciEnv + config.jvmciEnvTaskOffset); assert ctask != 0L; @@ -288,8 +279,8 @@ long compilationTime = System.nanoTime() - startCompilationTime; if ((config.ciTime || config.ciTimeEach) && installedCode != null) { long timeUnitsPerSecond = TimeUnit.NANOSECONDS.convert(1, TimeUnit.SECONDS); - CompilerToVM c2vm = jvmciRuntime.getCompilerToVM(); - c2vm.notifyCompilationStatistics(id, method, entryBCI != Compiler.INVOCATION_ENTRY_BCI, compiledBytecodes, compilationTime, timeUnitsPerSecond, installedCode); + final HotSpotCodeCacheProvider codeCache = (HotSpotCodeCacheProvider) jvmciRuntime.getHostJVMCIBackend().getCodeCache(); + codeCache.notifyCompilationStatistics(getId(), method, entryBCI != Compiler.INVOCATION_ENTRY_BCI, compiledBytecodes, compilationTime, timeUnitsPerSecond, installedCode); } } } @@ -301,6 +292,7 @@ if (config.ciTime || config.ciTimeEach || CompiledBytecodes.isEnabled()) { return true; } + long jvmciEnv = request.getJvmciEnv(); if (jvmciEnv == 0 || UNSAFE.getByte(jvmciEnv + config.jvmciEnvJvmtiCanHotswapOrPostBreakpointOffset) != 0) { return true; } @@ -308,16 +300,17 @@ } private String getMethodDescription() { - return String.format("%-6d JVMCI %-70s %-45s %-50s %s", id, method.getDeclaringClass().getName(), method.getName(), method.getSignature().toMethodDescriptor(), - entryBCI == Compiler.INVOCATION_ENTRY_BCI ? "" : "(OSR@" + entryBCI + ") "); + HotSpotResolvedJavaMethod method = getMethod(); + return String.format("%-6d JVMCI %-70s %-45s %-50s %s", getId(), method.getDeclaringClass().getName(), method.getName(), method.getSignature().toMethodDescriptor(), + getEntryBCI() == Compiler.INVOCATION_ENTRY_BCI ? "" : "(OSR@" + getEntryBCI() + ") "); } @SuppressWarnings("try") private InstalledCode installMethod(final CompilationResult compResult) { - final HotSpotCodeCacheProvider codeCache = (HotSpotCodeCacheProvider) jvmciRuntime.getHostJVMCIBackend().getCodeCache(); + final CodeCacheProvider codeCache = jvmciRuntime.getHostJVMCIBackend().getCodeCache(); InstalledCode installedCode = null; - try (Scope s = Debug.scope("CodeInstall", new DebugDumpScope(String.valueOf(id), true), codeCache, method)) { - installedCode = codeCache.installMethod(method, compResult, jvmciEnv, installAsDefault); + try (Scope s = Debug.scope("CodeInstall", new DebugDumpScope(String.valueOf(getId()), true), codeCache, getMethod())) { + installedCode = codeCache.installCode(request, compResult, null, request.getMethod().getSpeculationLog(), installAsDefault); } catch (Throwable e) { throw Debug.handle(e); } @@ -326,6 +319,6 @@ @Override public String toString() { - return "Compilation[id=" + id + ", " + method.format("%H.%n(%p)") + (entryBCI == Compiler.INVOCATION_ENTRY_BCI ? "" : "@" + entryBCI) + "]"; + return "Compilation[id=" + getId() + ", " + getMethod().format("%H.%n(%p)") + (getEntryBCI() == Compiler.INVOCATION_ENTRY_BCI ? "" : "@" + getEntryBCI()) + "]"; } } diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompileTheWorld.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompileTheWorld.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompileTheWorld.java Thu Oct 01 14:32:39 2015 -0700 @@ -56,6 +56,7 @@ import java.util.stream.Collectors; import jdk.internal.jvmci.compiler.Compiler; +import jdk.internal.jvmci.hotspot.HotSpotCompilationRequest; import jdk.internal.jvmci.hotspot.HotSpotJVMCIRuntime; import jdk.internal.jvmci.hotspot.HotSpotJVMCIRuntimeProvider; import jdk.internal.jvmci.hotspot.HotSpotResolvedJavaMethod; @@ -293,7 +294,8 @@ // compile dummy method to get compiler initilized outside of the config debug override. HotSpotResolvedJavaMethod dummyMethod = (HotSpotResolvedJavaMethod) JVMCI.getRuntime().getHostJVMCIBackend().getMetaAccess().lookupJavaMethod( CompileTheWorld.class.getDeclaredMethod("dummy")); - CompilationTask task = new CompilationTask(jvmciRuntime, compiler, dummyMethod, Compiler.INVOCATION_ENTRY_BCI, 0L, dummyMethod.allocateCompileId(Compiler.INVOCATION_ENTRY_BCI), false); + int entryBCI = Compiler.INVOCATION_ENTRY_BCI; + CompilationTask task = new CompilationTask(jvmciRuntime, compiler, new HotSpotCompilationRequest(dummyMethod, entryBCI, 0L), false); task.runCompilation(); } catch (NoSuchMethodException | SecurityException e1) { e1.printStackTrace(); @@ -483,8 +485,9 @@ try { long start = System.currentTimeMillis(); long allocatedAtStart = MemUseTrackerImpl.getCurrentThreadAllocatedBytes(); - - CompilationTask task = new CompilationTask(jvmciRuntime, compiler, method, Compiler.INVOCATION_ENTRY_BCI, 0L, method.allocateCompileId(Compiler.INVOCATION_ENTRY_BCI), false); + int entryBCI = Compiler.INVOCATION_ENTRY_BCI; + HotSpotCompilationRequest request = new HotSpotCompilationRequest(method, entryBCI, 0L); + CompilationTask task = new CompilationTask(jvmciRuntime, compiler, request, false); task.runCompilation(); memoryUsed.getAndAdd(MemUseTrackerImpl.getCurrentThreadAllocatedBytes() - allocatedAtStart); diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotBackend.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotBackend.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotBackend.java Thu Oct 01 14:32:39 2015 -0700 @@ -34,7 +34,6 @@ import jdk.internal.jvmci.code.RegisterSaveLayout; import jdk.internal.jvmci.code.StackSlot; import jdk.internal.jvmci.code.ValueUtil; -import jdk.internal.jvmci.code.stack.StackIntrospection; import jdk.internal.jvmci.hotspot.HotSpotJVMCIRuntime; import jdk.internal.jvmci.hotspot.HotSpotVMConfig; import jdk.internal.jvmci.meta.Value; @@ -248,11 +247,6 @@ } @Override - public StackIntrospection getStackIntrospection() { - return runtime; - } - - @Override public HotSpotProviders getProviders() { return (HotSpotProviders) super.getProviders(); } diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotCompiledRuntimeStub.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotCompiledRuntimeStub.java Thu Oct 01 14:21:08 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,84 +0,0 @@ -/* - * Copyright (c) 2011, 2014, 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.hotspot; - -import static com.oracle.graal.hotspot.HotSpotHostBackend.UNCOMMON_TRAP_HANDLER; -import jdk.internal.jvmci.code.CompilationResult; -import jdk.internal.jvmci.code.CompilationResult.Call; -import jdk.internal.jvmci.code.CompilationResult.ConstantReference; -import jdk.internal.jvmci.code.CompilationResult.DataPatch; -import jdk.internal.jvmci.code.CompilationResult.Infopoint; -import jdk.internal.jvmci.hotspot.HotSpotCompiledCode; -import jdk.internal.jvmci.hotspot.HotSpotMetaspaceConstant; - -/** - * {@link HotSpotCompiledCode} destined for installation as a RuntimeStub. - */ -public final class HotSpotCompiledRuntimeStub extends HotSpotCompiledCode { - - public HotSpotCompiledRuntimeStub(CompilationResult compResult) { - super(compResult); - assert checkStubInvariants(compResult); - } - - /** - * Checks the conditions a compilation must satisfy to be installed as a RuntimeStub. - */ - private boolean checkStubInvariants(CompilationResult compResult) { - assert compResult.getExceptionHandlers().isEmpty() : this; - - // Stubs cannot be recompiled so they cannot be compiled with - // assumptions and there is no point in recording evol_method dependencies - assert compResult.getAssumptions() == null : "stubs should not use assumptions: " + this; - assert compResult.getMethods() == null : "stubs should not record evol_method dependencies: " + this; - - for (DataPatch data : compResult.getDataPatches()) { - if (data.reference instanceof ConstantReference) { - ConstantReference ref = (ConstantReference) data.reference; - if (ref.getConstant() instanceof HotSpotMetaspaceConstant) { - HotSpotMetaspaceConstant c = (HotSpotMetaspaceConstant) ref.getConstant(); - if (c.asResolvedJavaType() != null && c.asResolvedJavaType().getName().equals("[I")) { - // special handling for NewArrayStub - // embedding the type '[I' is safe, since it is never unloaded - continue; - } - } - } - - assert !(data.reference instanceof ConstantReference) : this + " cannot have embedded object or metadata constant: " + data.reference; - } - for (Infopoint infopoint : compResult.getInfopoints()) { - assert infopoint instanceof Call : this + " cannot have non-call infopoint: " + infopoint; - Call call = (Call) infopoint; - assert call.target instanceof HotSpotForeignCallLinkage : this + " cannot have non runtime call: " + call.target; - HotSpotForeignCallLinkage linkage = (HotSpotForeignCallLinkage) call.target; - assert !linkage.isCompiledStub() || linkage.getDescriptor().equals(UNCOMMON_TRAP_HANDLER) : this + " cannot call compiled stub " + linkage; - } - return true; - } - - @Override - public String toString() { - return name; - } -} diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotForeignCallLinkageImpl.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotForeignCallLinkageImpl.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotForeignCallLinkageImpl.java Thu Oct 01 14:32:39 2015 -0700 @@ -23,6 +23,7 @@ package com.oracle.graal.hotspot; import static com.oracle.graal.hotspot.HotSpotForeignCallLinkage.RegisterEffect.DESTROYS_REGISTERS; +import static jdk.internal.jvmci.hotspot.HotSpotJVMCIRuntime.runtime; import java.util.Set; @@ -33,7 +34,6 @@ import jdk.internal.jvmci.code.Register; import jdk.internal.jvmci.code.RegisterConfig; import jdk.internal.jvmci.code.TargetDescription; -import jdk.internal.jvmci.hotspot.CompilerToVM; import jdk.internal.jvmci.hotspot.HotSpotForeignCallTarget; import jdk.internal.jvmci.hotspot.HotSpotProxified; import jdk.internal.jvmci.meta.AllocatableValue; @@ -90,8 +90,6 @@ private final boolean reexecutable; - private final CompilerToVM vm; - /** * Creates a {@link HotSpotForeignCallLinkage}. * @@ -107,12 +105,11 @@ * re-executed. * @param killedLocations the memory locations killed by the call */ - public static HotSpotForeignCallLinkage create(MetaAccessProvider metaAccess, CodeCacheProvider codeCache, HotSpotForeignCallsProvider foreignCalls, CompilerToVM vm, - ForeignCallDescriptor descriptor, long address, RegisterEffect effect, Type outgoingCcType, Type incomingCcType, Transition transition, boolean reexecutable, - LocationIdentity... killedLocations) { + public static HotSpotForeignCallLinkage create(MetaAccessProvider metaAccess, CodeCacheProvider codeCache, HotSpotForeignCallsProvider foreignCalls, ForeignCallDescriptor descriptor, + long address, RegisterEffect effect, Type outgoingCcType, Type incomingCcType, Transition transition, boolean reexecutable, LocationIdentity... killedLocations) { CallingConvention outgoingCc = createCallingConvention(metaAccess, codeCache, descriptor, outgoingCcType); CallingConvention incomingCc = incomingCcType == null ? null : createCallingConvention(metaAccess, codeCache, descriptor, incomingCcType); - HotSpotForeignCallLinkageImpl linkage = new HotSpotForeignCallLinkageImpl(vm, descriptor, address, effect, transition, outgoingCc, incomingCc, reexecutable, killedLocations); + HotSpotForeignCallLinkageImpl linkage = new HotSpotForeignCallLinkageImpl(descriptor, address, effect, transition, outgoingCc, incomingCc, reexecutable, killedLocations); if (outgoingCcType == Type.NativeCall) { linkage.temporaries = foreignCalls.getNativeABICallerSaveRegisters(); } @@ -143,10 +140,9 @@ } } - public HotSpotForeignCallLinkageImpl(CompilerToVM vm, ForeignCallDescriptor descriptor, long address, RegisterEffect effect, Transition transition, CallingConvention outgoingCallingConvention, + public HotSpotForeignCallLinkageImpl(ForeignCallDescriptor descriptor, long address, RegisterEffect effect, Transition transition, CallingConvention outgoingCallingConvention, CallingConvention incomingCallingConvention, boolean reexecutable, LocationIdentity... killedLocations) { super(address); - this.vm = vm; this.descriptor = descriptor; this.address = address; this.effect = effect; @@ -196,7 +192,7 @@ } public long getMaxCallTargetOffset() { - return vm.getMaxCallTargetOffset(address); + return runtime().getHostJVMCIBackend().getCodeCache().getMaxCallTargetOffset(address); } public ForeignCallDescriptor getDescriptor() { diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalCompiler.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalCompiler.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalCompiler.java Thu Oct 01 14:32:39 2015 -0700 @@ -28,11 +28,12 @@ import static jdk.internal.jvmci.code.CodeUtil.getCallingConvention; import jdk.internal.jvmci.code.CallingConvention; import jdk.internal.jvmci.code.CallingConvention.Type; +import jdk.internal.jvmci.code.CompilationRequest; import jdk.internal.jvmci.code.CompilationResult; import jdk.internal.jvmci.compiler.Compiler; -import jdk.internal.jvmci.hotspot.CompilerToVM; +import jdk.internal.jvmci.hotspot.HotSpotCodeCacheProvider; +import jdk.internal.jvmci.hotspot.HotSpotCompilationRequest; import jdk.internal.jvmci.hotspot.HotSpotJVMCIRuntimeProvider; -import jdk.internal.jvmci.hotspot.HotSpotResolvedJavaMethod; import jdk.internal.jvmci.meta.JavaType; import jdk.internal.jvmci.meta.ProfilingInfo; import jdk.internal.jvmci.meta.ResolvedJavaMethod; @@ -45,6 +46,7 @@ import com.oracle.graal.debug.TTY; import com.oracle.graal.debug.TopLevelDebugConfig; import com.oracle.graal.debug.internal.DebugScope; +import com.oracle.graal.debug.query.SpecialIntrinsicGuard; import com.oracle.graal.graphbuilderconf.GraphBuilderConfiguration; import com.oracle.graal.graphbuilderconf.GraphBuilderConfiguration.Plugins; import com.oracle.graal.graphbuilderconf.IntrinsicContext; @@ -79,23 +81,23 @@ @Override @SuppressWarnings("try") - public void compileMethod(ResolvedJavaMethod method, int entryBCI, long jvmciEnv, int id) { + public void compileMethod(CompilationRequest request) { // Ensure a debug configuration for this thread is initialized if (Debug.isEnabled() && DebugScope.getConfig() == null) { DebugEnvironment.initialize(TTY.out); } - CompilationTask task = new CompilationTask(jvmciRuntime, this, (HotSpotResolvedJavaMethod) method, entryBCI, jvmciEnv, id, true); + CompilationTask task = new CompilationTask(jvmciRuntime, this, (HotSpotCompilationRequest) request, true); try (DebugConfigScope dcs = Debug.setConfig(new TopLevelDebugConfig())) { task.runCompilation(); } } public void compileTheWorld() throws Throwable { - CompilerToVM compilerToVM = jvmciRuntime.getCompilerToVM(); + HotSpotCodeCacheProvider codeCache = (HotSpotCodeCacheProvider) jvmciRuntime.getHostJVMCIBackend().getCodeCache(); int iterations = CompileTheWorldOptions.CompileTheWorldIterations.getValue(); for (int i = 0; i < iterations; i++) { - compilerToVM.resetCompilationStatistics(); + codeCache.resetCompilationStatistics(); TTY.println("CompileTheWorld : iteration " + i); CompileTheWorld ctw = new CompileTheWorld(jvmciRuntime, this); ctw.compile(); @@ -107,8 +109,10 @@ HotSpotBackend backend = graalRuntime.getHostBackend(); HotSpotProviders providers = backend.getProviders(); final boolean isOSR = entryBCI != Compiler.INVOCATION_ENTRY_BCI; + // avoid compiling the intrinsic graphs for GraalQueryAPI methods + boolean bypassIntrinsic = method.isNative() || isOSR || SpecialIntrinsicGuard.isQueryIntrinsic(method); + StructuredGraph graph = bypassIntrinsic ? null : getIntrinsicGraph(method, providers); - StructuredGraph graph = method.isNative() || isOSR ? null : getIntrinsicGraph(method, providers); if (graph == null) { SpeculationLog speculationLog = method.getSpeculationLog(); if (speculationLog != null) { @@ -186,7 +190,10 @@ } protected PhaseSuite getGraphBuilderSuite(HotSpotProviders providers, boolean isOSR) { - PhaseSuite suite = HotSpotSuitesProvider.withSimpleDebugInfoIfRequested(providers.getSuites().getDefaultGraphBuilderSuite()); + PhaseSuite suite = providers.getSuites().getDefaultGraphBuilderSuite(); + if (providers.getCodeCache().shouldDebugNonSafepoints()) { + suite = HotSpotSuitesProvider.withSimpleDebugInfo(suite); + } if (isOSR) { suite = suite.copy(); suite.appendPhase(new OnStackReplacementPhase()); diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java Thu Oct 01 14:32:39 2015 -0700 @@ -22,14 +22,12 @@ */ package com.oracle.graal.hotspot; -import static com.oracle.graal.compiler.common.GraalOptions.HotSpotPrintInlining; import static com.oracle.graal.debug.GraalDebugConfig.DebugValueSummary; import static com.oracle.graal.debug.GraalDebugConfig.Dump; import static com.oracle.graal.debug.GraalDebugConfig.Log; import static com.oracle.graal.debug.GraalDebugConfig.MethodFilter; import static com.oracle.graal.debug.GraalDebugConfig.Verify; import static com.oracle.graal.debug.GraalDebugConfig.areScopedMetricsOrTimersEnabled; -import static jdk.internal.jvmci.hotspot.CompilerToVM.compilerToVM; import static jdk.internal.jvmci.hotspot.HotSpotJVMCIRuntime.runtime; import static jdk.internal.jvmci.hotspot.HotSpotJVMCIRuntimeProvider.getArrayIndexScale; import static jdk.internal.jvmci.inittimer.InitTimer.timer; @@ -39,22 +37,19 @@ import java.util.Map; import jdk.internal.jvmci.code.Architecture; -import jdk.internal.jvmci.code.stack.InspectedFrameVisitor; import jdk.internal.jvmci.code.stack.StackIntrospection; import jdk.internal.jvmci.common.JVMCIError; -import jdk.internal.jvmci.hotspot.CompilerToVM; import jdk.internal.jvmci.hotspot.HotSpotJVMCIRuntime; import jdk.internal.jvmci.hotspot.HotSpotProxified; -import jdk.internal.jvmci.hotspot.HotSpotStackFrameReference; import jdk.internal.jvmci.hotspot.HotSpotVMConfig; import jdk.internal.jvmci.inittimer.InitTimer; import jdk.internal.jvmci.meta.JavaKind; -import jdk.internal.jvmci.meta.ResolvedJavaMethod; import jdk.internal.jvmci.runtime.JVMCIBackend; import com.oracle.graal.api.collections.CollectionsProvider; import com.oracle.graal.api.replacements.SnippetReflectionProvider; import com.oracle.graal.api.runtime.GraalRuntime; +import com.oracle.graal.compiler.common.GraalOptions; import com.oracle.graal.compiler.target.Backend; import com.oracle.graal.debug.Debug; import com.oracle.graal.debug.DebugEnvironment; @@ -98,8 +93,8 @@ CompileTheWorldOptions.overrideWithNativeOptions(config); // Only set HotSpotPrintInlining if it still has its default value (false). - if (HotSpotPrintInlining.getValue() == false) { - HotSpotPrintInlining.setValue(config.printInlining); + if (GraalOptions.HotSpotPrintInlining.getValue() == false) { + GraalOptions.HotSpotPrintInlining.setValue(config.printInlining); } CompilerConfiguration compilerConfiguration = compilerFactory.createCompilerConfiguration(); @@ -170,7 +165,7 @@ } } - BenchmarkCounters.initialize(jvmciRuntime.getCompilerToVM()); + BenchmarkCounters.initialize(jvmciRuntime); assert checkArrayIndexScaleInvariants(); @@ -223,20 +218,6 @@ return Collections.unmodifiableMap(backends); } - @Override - public T iterateFrames(ResolvedJavaMethod[] initialMethods, ResolvedJavaMethod[] matchingMethods, int initialSkip, InspectedFrameVisitor visitor) { - CompilerToVM compilerToVM = runtime().getCompilerToVM(); - HotSpotStackFrameReference current = compilerToVM.getNextStackFrame(null, initialMethods, initialSkip); - while (current != null) { - T result = visitor.visitFrame(current); - if (result != null) { - return result; - } - current = compilerToVM.getNextStackFrame(current, matchingMethods, 0); - } - return null; - } - private long runtimeStartTime; /** @@ -255,6 +236,6 @@ phaseTransition("final"); SnippetCounter.printGroups(TTY.out().out()); - BenchmarkCounters.shutdown(compilerToVM(), runtimeStartTime); + BenchmarkCounters.shutdown(runtime(), runtimeStartTime); } } diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntimeProvider.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntimeProvider.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntimeProvider.java Thu Oct 01 14:32:39 2015 -0700 @@ -23,7 +23,6 @@ package com.oracle.graal.hotspot; import jdk.internal.jvmci.code.TargetDescription; -import jdk.internal.jvmci.code.stack.StackIntrospection; import com.oracle.graal.api.runtime.GraalRuntime; import com.oracle.graal.hotspot.meta.HotSpotProviders; @@ -34,7 +33,7 @@ /** * Configuration information for the HotSpot Graal runtime. */ -public interface HotSpotGraalRuntimeProvider extends GraalRuntime, RuntimeProvider, StackIntrospection { +public interface HotSpotGraalRuntimeProvider extends GraalRuntime, RuntimeProvider { default TargetDescription getTarget() { return getHostBackend().getTarget(); diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/PrintStreamOption.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/PrintStreamOption.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/PrintStreamOption.java Thu Oct 01 14:32:39 2015 -0700 @@ -22,8 +22,6 @@ */ package com.oracle.graal.hotspot; -import static jdk.internal.jvmci.hotspot.CompilerToVM.compilerToVM; - import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; @@ -31,7 +29,8 @@ import java.io.PrintStream; import java.lang.management.ManagementFactory; -import jdk.internal.jvmci.hotspot.CompilerToVM; +import jdk.internal.jvmci.hotspot.HotSpotJVMCIRuntime; +import jdk.internal.jvmci.hotspot.HotSpotJVMCIRuntimeProvider; import jdk.internal.jvmci.options.OptionValue; /** @@ -76,8 +75,49 @@ } /** + * An output stream that redirects to {@link HotSpotJVMCIRuntimeProvider#getLogStream()}. The + * {@link HotSpotJVMCIRuntimeProvider#getLogStream()} value is only accessed the first time an + * IO operation is performed on the stream. This is required to break a deadlock in early JVMCI + * initialization. + */ + static class DelayedOutputStream extends OutputStream { + private volatile OutputStream lazy; + + private OutputStream lazy() { + if (lazy == null) { + synchronized (this) { + if (lazy == null) { + lazy = HotSpotJVMCIRuntime.runtime().getLogStream(); + } + } + } + return lazy; + } + + @Override + public void write(byte[] b, int off, int len) throws IOException { + lazy().write(b, off, len); + } + + @Override + public void write(int b) throws IOException { + lazy().write(b); + } + + @Override + public void flush() throws IOException { + lazy().flush(); + } + + @Override + public void close() throws IOException { + lazy().close(); + } + } + + /** * Gets the print stream configured by this option. If no file is configured, the print stream - * will output to {@link CompilerToVM#writeDebugOutput(byte[], int, int)}. + * will output to HotSpot's {@link HotSpotJVMCIRuntimeProvider#getLogStream() log} stream. */ public PrintStream getStream() { if (ps == null) { @@ -100,39 +140,7 @@ } } } else { - OutputStream ttyOut = new OutputStream() { - CompilerToVM vm; - - private CompilerToVM vm() { - if (vm == null) { - vm = compilerToVM(); - } - return vm; - } - - @Override - public void write(byte[] b, int off, int len) throws IOException { - if (b == null) { - throw new NullPointerException(); - } else if (off < 0 || off > b.length || len < 0 || (off + len) > b.length || (off + len) < 0) { - throw new IndexOutOfBoundsException(); - } else if (len == 0) { - return; - } - vm().writeDebugOutput(b, off, len); - } - - @Override - public void write(int b) throws IOException { - write(new byte[]{(byte) b}, 0, 1); - } - - @Override - public void flush() throws IOException { - vm().flushDebugOutput(); - } - }; - ps = new PrintStream(ttyOut); + ps = new PrintStream(new DelayedOutputStream()); } } return ps; diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/debug/BenchmarkCounters.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/debug/BenchmarkCounters.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/debug/BenchmarkCounters.java Thu Oct 01 14:32:39 2015 -0700 @@ -36,7 +36,7 @@ import java.util.concurrent.atomic.AtomicLong; import jdk.internal.jvmci.common.JVMCIError; -import jdk.internal.jvmci.hotspot.CompilerToVM; +import jdk.internal.jvmci.hotspot.HotSpotJVMCIRuntime; import jdk.internal.jvmci.hotspot.HotSpotVMConfig; import jdk.internal.jvmci.inittimer.SuppressFBWarnings; import jdk.internal.jvmci.options.Option; @@ -331,7 +331,7 @@ } } - public static void initialize(final CompilerToVM compilerToVM) { + public static void initialize(final HotSpotJVMCIRuntime jvmciRuntime) { final class BenchmarkCountersOutputStream extends CallbackOutputStream { private long startTime; @@ -347,7 +347,7 @@ switch (index) { case 2: startTime = System.nanoTime(); - BenchmarkCounters.clear(compilerToVM.collectCounters()); + BenchmarkCounters.clear(jvmciRuntime.collectCounters()); running = true; break; case 1: @@ -359,7 +359,7 @@ if (waitingForEnd) { waitingForEnd = false; running = false; - BenchmarkCounters.dump(delegate, (System.nanoTime() - startTime) / 1000000000d, compilerToVM.collectCounters(), 100); + BenchmarkCounters.dump(delegate, (System.nanoTime() - startTime) / 1000000000d, jvmciRuntime.collectCounters(), 100); } break; } @@ -398,7 +398,7 @@ } catch (InterruptedException e) { } long time = System.nanoTime(); - dump(out, (time - lastTime) / 1000000000d, compilerToVM.collectCounters(), 10); + dump(out, (time - lastTime) / 1000000000d, jvmciRuntime.collectCounters(), 10); lastTime = time; } } @@ -409,13 +409,13 @@ enabled = true; } if (enabled) { - clear(compilerToVM.collectCounters()); + clear(jvmciRuntime.collectCounters()); } } - public static void shutdown(CompilerToVM compilerToVM, long compilerStartTime) { + public static void shutdown(HotSpotJVMCIRuntime jvmciRuntime, long compilerStartTime) { if (Options.GenericDynamicCounters.getValue()) { - dump(TTY.out, (System.nanoTime() - compilerStartTime) / 1000000000d, compilerToVM.collectCounters(), 100); + dump(TTY.out, (System.nanoTime() - compilerStartTime) / 1000000000d, jvmciRuntime.collectCounters(), 100); } } } diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/DefaultHotSpotLoweringProvider.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/DefaultHotSpotLoweringProvider.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/DefaultHotSpotLoweringProvider.java Thu Oct 01 14:32:39 2015 -0700 @@ -42,10 +42,10 @@ import jdk.internal.jvmci.code.CallingConvention; import jdk.internal.jvmci.code.TargetDescription; import jdk.internal.jvmci.common.JVMCIError; -import jdk.internal.jvmci.hotspot.HotSpotObjectConstantImpl; import jdk.internal.jvmci.hotspot.HotSpotResolvedJavaField; import jdk.internal.jvmci.hotspot.HotSpotResolvedJavaMethod; import jdk.internal.jvmci.hotspot.HotSpotVMConfig; +import jdk.internal.jvmci.meta.ConstantReflectionProvider; import jdk.internal.jvmci.meta.JavaConstant; import jdk.internal.jvmci.meta.JavaKind; import jdk.internal.jvmci.meta.JavaType; @@ -155,6 +155,7 @@ protected final HotSpotGraalRuntimeProvider runtime; protected final ForeignCallsProvider foreignCalls; protected final HotSpotRegistersProvider registers; + protected final ConstantReflectionProvider constantReflection; protected CheckCastDynamicSnippets.Templates checkcastDynamicSnippets; protected InstanceOfSnippets.Templates instanceofSnippets; @@ -167,11 +168,12 @@ protected ArrayCopySnippets.Templates arraycopySnippets; public DefaultHotSpotLoweringProvider(HotSpotGraalRuntimeProvider runtime, MetaAccessProvider metaAccess, ForeignCallsProvider foreignCalls, HotSpotRegistersProvider registers, - TargetDescription target) { + ConstantReflectionProvider constantReflection, TargetDescription target) { super(metaAccess, target); this.runtime = runtime; this.foreignCalls = foreignCalls; this.registers = registers; + this.constantReflection = constantReflection; } public void initialize(HotSpotProviders providers, HotSpotVMConfig config) { @@ -532,7 +534,7 @@ } else { throw JVMCIError.shouldNotReachHere(); } - FloatingNode exceptionNode = ConstantNode.forConstant(HotSpotObjectConstantImpl.forObject(exception), metaAccess, graph); + FloatingNode exceptionNode = ConstantNode.forConstant(constantReflection.forObject(exception), metaAccess, graph); graph.replaceFixedWithFloating(node, exceptionNode); } else { diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotForeignCallsProviderImpl.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotForeignCallsProviderImpl.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotForeignCallsProviderImpl.java Thu Oct 01 14:32:39 2015 -0700 @@ -32,7 +32,6 @@ import jdk.internal.jvmci.code.CallingConvention; import jdk.internal.jvmci.code.CodeCacheProvider; -import jdk.internal.jvmci.hotspot.CompilerToVM; import jdk.internal.jvmci.hotspot.HotSpotJVMCIRuntimeProvider; import jdk.internal.jvmci.meta.LocationIdentity; import jdk.internal.jvmci.meta.MetaAccessProvider; @@ -93,8 +92,7 @@ * @param killedLocations the memory locations killed by the stub call */ public HotSpotForeignCallLinkage registerStubCall(ForeignCallDescriptor descriptor, boolean reexecutable, Transition transition, LocationIdentity... killedLocations) { - CompilerToVM vm = jvmciRuntime.getCompilerToVM(); - return register(HotSpotForeignCallLinkageImpl.create(metaAccess, codeCache, this, vm, descriptor, 0L, PRESERVES_REGISTERS, JavaCall, JavaCallee, transition, reexecutable, killedLocations)); + return register(HotSpotForeignCallLinkageImpl.create(metaAccess, codeCache, this, descriptor, 0L, PRESERVES_REGISTERS, JavaCall, JavaCallee, transition, reexecutable, killedLocations)); } /** @@ -116,8 +114,7 @@ Class resultType = descriptor.getResultType(); assert address != 0; assert transition != NOT_LEAF || resultType.isPrimitive() || Word.class.isAssignableFrom(resultType) : "non-leaf foreign calls must return objects in thread local storage: " + descriptor; - CompilerToVM vm = jvmciRuntime.getCompilerToVM(); - return register(HotSpotForeignCallLinkageImpl.create(metaAccess, codeCache, this, vm, descriptor, address, effect, outgoingCcType, null, transition, reexecutable, killedLocations)); + return register(HotSpotForeignCallLinkageImpl.create(metaAccess, codeCache, this, descriptor, address, effect, outgoingCcType, null, transition, reexecutable, killedLocations)); } /** diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntimeStub.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntimeStub.java Thu Oct 01 14:21:08 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,66 +0,0 @@ -/* - * 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.graal.hotspot.meta; - -import jdk.internal.jvmci.code.InstalledCode; -import jdk.internal.jvmci.code.InvalidInstalledCodeException; -import jdk.internal.jvmci.hotspot.HotSpotInstalledCode; -import jdk.internal.jvmci.meta.ResolvedJavaMethod; - -import com.oracle.graal.hotspot.stubs.Stub; - -/** - * Implementation of {@link InstalledCode} for code installed as a RuntimeStub. - */ -public class HotSpotRuntimeStub extends HotSpotInstalledCode { - - private final Stub stub; - - public HotSpotRuntimeStub(Stub stub) { - super(stub.toString()); - this.stub = stub; - } - - public ResolvedJavaMethod getMethod() { - return null; - } - - @Override - public boolean isValid() { - return true; - } - - @Override - public void invalidate() { - } - - @Override - public String toString() { - return String.format("InstalledRuntimeStub[stub=%s, codeBlob=0x%x]", stub, getAddress()); - } - - @Override - public Object executeVarargs(Object... args) throws InvalidInstalledCodeException { - throw new InternalError("Cannot call stub " + stub); - } -} diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotSnippetReflectionProvider.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotSnippetReflectionProvider.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotSnippetReflectionProvider.java Thu Oct 01 14:32:39 2015 -0700 @@ -24,8 +24,8 @@ import static jdk.internal.jvmci.hotspot.HotSpotVMConfig.config; import jdk.internal.jvmci.hotspot.HotSpotObjectConstant; -import jdk.internal.jvmci.hotspot.HotSpotObjectConstantImpl; import jdk.internal.jvmci.hotspot.HotSpotVMConfig; +import jdk.internal.jvmci.meta.ConstantReflectionProvider; import jdk.internal.jvmci.meta.JavaConstant; import jdk.internal.jvmci.meta.JavaKind; import jdk.internal.jvmci.meta.MetaAccessProvider; @@ -37,14 +37,16 @@ public class HotSpotSnippetReflectionProvider implements SnippetReflectionProvider { private final HotSpotGraalRuntimeProvider runtime; + private final ConstantReflectionProvider constantReflection; - public HotSpotSnippetReflectionProvider(HotSpotGraalRuntimeProvider runtime) { + public HotSpotSnippetReflectionProvider(HotSpotGraalRuntimeProvider runtime, ConstantReflectionProvider constantReflection) { this.runtime = runtime; + this.constantReflection = constantReflection; } @Override public JavaConstant forObject(Object object) { - return HotSpotObjectConstantImpl.forObject(object); + return constantReflection.forObject(object); } @Override @@ -67,7 +69,11 @@ @Override public JavaConstant forBoxed(JavaKind kind, Object value) { - return HotSpotObjectConstantImpl.forBoxedValue(kind, value); + if (kind == JavaKind.Object) { + return forObject(value); + } else { + return JavaConstant.forBoxedPrimitive(value); + } } public Object getSubstitutionGuardParameter(Class type) { diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotSuitesProvider.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotSuitesProvider.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotSuitesProvider.java Thu Oct 01 14:32:39 2015 -0700 @@ -24,8 +24,6 @@ import static com.oracle.graal.compiler.common.GraalOptions.ImmutableCode; import static com.oracle.graal.compiler.common.GraalOptions.VerifyPhases; -import static jdk.internal.jvmci.hotspot.CompilerToVM.compilerToVM; -import jdk.internal.jvmci.hotspot.CompilerToVM; import jdk.internal.jvmci.hotspot.HotSpotVMConfig; import jdk.internal.jvmci.options.DerivedOptionValue; import jdk.internal.jvmci.options.DerivedOptionValue.OptionSupplier; @@ -158,23 +156,18 @@ } /** - * Modifies the {@link GraphBuilderConfiguration} to build extra - * {@linkplain DebugInfoMode#Simple debug info} if the VM - * {@linkplain CompilerToVM#shouldDebugNonSafepoints() requests} it. + * Modifies a given {@link GraphBuilderConfiguration} to build extra + * {@linkplain DebugInfoMode#Simple debug info}. * - * @param gbs the current graph builder suite - * @return a possibly modified graph builder suite + * @param gbs the current graph builder suite to modify */ - public static PhaseSuite withSimpleDebugInfoIfRequested(PhaseSuite gbs) { - if (compilerToVM().shouldDebugNonSafepoints()) { - PhaseSuite newGbs = gbs.copy(); - GraphBuilderPhase graphBuilderPhase = (GraphBuilderPhase) newGbs.findPhase(GraphBuilderPhase.class).previous(); - GraphBuilderConfiguration graphBuilderConfig = graphBuilderPhase.getGraphBuilderConfig(); - GraphBuilderPhase newGraphBuilderPhase = new GraphBuilderPhase(graphBuilderConfig.withDebugInfoMode(DebugInfoMode.Simple)); - newGbs.findPhase(GraphBuilderPhase.class).set(newGraphBuilderPhase); - return newGbs; - } - return gbs; + public static PhaseSuite withSimpleDebugInfo(PhaseSuite gbs) { + PhaseSuite newGbs = gbs.copy(); + GraphBuilderPhase graphBuilderPhase = (GraphBuilderPhase) newGbs.findPhase(GraphBuilderPhase.class).previous(); + GraphBuilderConfiguration graphBuilderConfig = graphBuilderPhase.getGraphBuilderConfig(); + GraphBuilderPhase newGraphBuilderPhase = new GraphBuilderPhase(graphBuilderConfig.withDebugInfoMode(DebugInfoMode.Simple)); + newGbs.findPhase(GraphBuilderPhase.class).set(newGraphBuilderPhase); + return newGbs; } public LIRSuites getDefaultLIRSuites() { diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/DelimitationAPISubstitutions.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/DelimitationAPISubstitutions.java Thu Oct 01 14:32:39 2015 -0700 @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2015, 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.hotspot.replacements; + +import com.oracle.graal.api.replacements.ClassSubstitution; +import com.oracle.graal.api.replacements.MethodSubstitution; +import com.oracle.graal.debug.query.DelimitationAPI; +import com.oracle.graal.phases.common.query.nodes.InstrumentationBeginNode; +import com.oracle.graal.phases.common.query.nodes.InstrumentationEndNode; + +@ClassSubstitution(DelimitationAPI.class) +public class DelimitationAPISubstitutions { + + @MethodSubstitution(isStatic = true) + public static void instrumentationBegin(int target) { + InstrumentationBeginNode.instantiate(target, 0); + } + + @MethodSubstitution(isStatic = true) + public static void instrumentationBegin(int target, int type) { + InstrumentationBeginNode.instantiate(target, type); + } + + @MethodSubstitution(isStatic = true) + public static void instrumentationEnd() { + InstrumentationEndNode.instantiate(); + } + +} diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/GraalQueryAPISubstitutions.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/GraalQueryAPISubstitutions.java Thu Oct 01 14:32:39 2015 -0700 @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2015, 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.hotspot.replacements; + +import com.oracle.graal.api.replacements.ClassSubstitution; +import com.oracle.graal.api.replacements.MethodSubstitution; +import com.oracle.graal.debug.query.GraalQueryAPI; +import com.oracle.graal.hotspot.replacements.query.GetRootNameNode; +import com.oracle.graal.hotspot.replacements.query.GetRuntimePathNode; +import com.oracle.graal.hotspot.replacements.query.IsMethodInlinedNode; + +@ClassSubstitution(GraalQueryAPI.class) +public class GraalQueryAPISubstitutions { + + @MethodSubstitution(isStatic = true) + public static boolean isMethodCompiled() { + return true; + } + + @MethodSubstitution(isStatic = true) + public static boolean isMethodInlined() { + return IsMethodInlinedNode.instantiate(); + } + + @MethodSubstitution(isStatic = true) + public static String getRootName() { + return GetRootNameNode.instantiate(); + } + + @MethodSubstitution(isStatic = true) + public static int getAllocationType() { + return GetRuntimePathNode.instantiate(); + } + + @MethodSubstitution(isStatic = true) + public static int getLockType() { + return GetRuntimePathNode.instantiate(); + } + +} diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/HotSpotSubstitutions.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/HotSpotSubstitutions.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/HotSpotSubstitutions.java Thu Oct 01 14:32:39 2015 -0700 @@ -22,6 +22,7 @@ */ package com.oracle.graal.hotspot.replacements; +import static com.oracle.graal.compiler.common.GraalOptions.UseGraalQueries; import jdk.internal.jvmci.code.TargetDescription; import jdk.internal.jvmci.meta.MetaAccessProvider; import jdk.internal.jvmci.service.ServiceProvider; @@ -29,6 +30,8 @@ import sun.reflect.Reflection; import com.oracle.graal.api.replacements.SnippetReflectionProvider; +import com.oracle.graal.debug.query.DelimitationAPI; +import com.oracle.graal.debug.query.GraalQueryAPI; import com.oracle.graal.nodes.spi.LoweringProvider; import com.oracle.graal.nodes.spi.Replacements; import com.oracle.graal.nodes.spi.ReplacementsProvider; @@ -42,5 +45,9 @@ replacements.registerSubstitutions(Thread.class, ThreadSubstitutions.class); replacements.registerSubstitutions(Reflection.class, ReflectionSubstitutions.class); replacements.registerSubstitutions(ConstantPool.class, ConstantPoolSubstitutions.class); + if (UseGraalQueries.getValue()) { + replacements.registerSubstitutions(GraalQueryAPI.class, GraalQueryAPISubstitutions.class); + replacements.registerSubstitutions(DelimitationAPI.class, DelimitationAPISubstitutions.class); + } } } diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/query/GetRootNameNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/query/GetRootNameNode.java Thu Oct 01 14:32:39 2015 -0700 @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2015, 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.hotspot.replacements.query; + +import jdk.internal.jvmci.hotspot.HotSpotResolvedObjectType; +import jdk.internal.jvmci.meta.Constant; +import jdk.internal.jvmci.meta.ConstantReflectionProvider; +import jdk.internal.jvmci.meta.ResolvedJavaMethod; + +import com.oracle.graal.compiler.common.type.StampFactory; +import com.oracle.graal.graph.NodeClass; +import com.oracle.graal.nodeinfo.NodeInfo; +import com.oracle.graal.nodes.ConstantNode; +import com.oracle.graal.nodes.FixedNode; +import com.oracle.graal.phases.common.query.nodes.GraalQueryNode; +import com.oracle.graal.phases.common.query.nodes.InstrumentationNode; + +@NodeInfo +public final class GetRootNameNode extends GraalQueryNode { + + public static final NodeClass TYPE = NodeClass.create(GetRootNameNode.class); + + public GetRootNameNode() { + super(TYPE, StampFactory.exactNonNull(HotSpotResolvedObjectType.fromObjectClass(String.class))); + } + + @Override + public void onInlineICG(InstrumentationNode instrumentation, FixedNode position, ConstantReflectionProvider constantReflection) { + ResolvedJavaMethod method = graph().method(); + String root = method.getDeclaringClass().toJavaName() + "." + method.getName() + method.getSignature().toMethodDescriptor(); + Constant constant = constantReflection.forObject(root); + ConstantNode constantNode = graph().unique(new ConstantNode(constant, stamp())); + graph().replaceFixedWithFloating(this, constantNode); + } + + @NodeIntrinsic + public static native String instantiate(); + +} diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/query/GetRuntimePathNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/query/GetRuntimePathNode.java Thu Oct 01 14:32:39 2015 -0700 @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2015, 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.hotspot.replacements.query; + +import jdk.internal.jvmci.meta.ConstantReflectionProvider; +import jdk.internal.jvmci.meta.JavaKind; + +import com.oracle.graal.compiler.common.type.StampFactory; +import com.oracle.graal.graph.Node; +import com.oracle.graal.graph.NodeClass; +import com.oracle.graal.graph.NodeFlood; +import com.oracle.graal.nodeinfo.NodeInfo; +import com.oracle.graal.nodes.AbstractEndNode; +import com.oracle.graal.nodes.AbstractMergeNode; +import com.oracle.graal.nodes.ConstantNode; +import com.oracle.graal.nodes.FixedNode; +import com.oracle.graal.nodes.LoopEndNode; +import com.oracle.graal.nodes.ValuePhiNode; +import com.oracle.graal.phases.common.query.nodes.GraalQueryNode; +import com.oracle.graal.phases.common.query.nodes.InstrumentationNode; + +@NodeInfo +public final class GetRuntimePathNode extends GraalQueryNode { + + public static final NodeClass TYPE = NodeClass.create(GetRuntimePathNode.class); + + public GetRuntimePathNode() { + super(TYPE, StampFactory.forKind(JavaKind.Int)); + } + + private static boolean isCFGAccessible(FixedNode from, FixedNode to) { + NodeFlood flood = from.graph().createNodeFlood(); + flood.add(from); + for (Node current : flood) { + if (current instanceof LoopEndNode) { + continue; + } else if (current instanceof AbstractEndNode) { + flood.add(((AbstractEndNode) current).merge()); + } else { + flood.addAll(current.successors()); + } + } + return flood.isMarked(to); + } + + @Override + public void onInlineICG(InstrumentationNode instrumentation, FixedNode position, ConstantReflectionProvider constantReflection) { + if (instrumentation.target() instanceof AbstractMergeNode) { + AbstractMergeNode merge = (AbstractMergeNode) instrumentation.target(); + + if (isCFGAccessible(merge, position)) { + ValuePhiNode phi = graph().addWithoutUnique(new ValuePhiNode(StampFactory.intValue(), merge)); + for (int i = 0; i < merge.cfgPredecessors().count(); i++) { + phi.addInput(ConstantNode.forInt(i, merge.graph())); + } + graph().replaceFixedWithFloating(this, phi); + return; + } + } + graph().replaceFixedWithFloating(this, ConstantNode.forInt(-1, graph())); + } + + @NodeIntrinsic + public static native int instantiate(); + +} diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/query/IsMethodInlinedNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/query/IsMethodInlinedNode.java Thu Oct 01 14:32:39 2015 -0700 @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2015, 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.hotspot.replacements.query; + +import jdk.internal.jvmci.meta.ConstantReflectionProvider; +import jdk.internal.jvmci.meta.JavaKind; + +import com.oracle.graal.compiler.common.type.StampFactory; +import com.oracle.graal.graph.NodeClass; +import com.oracle.graal.nodeinfo.NodeInfo; +import com.oracle.graal.nodes.ConstantNode; +import com.oracle.graal.nodes.FixedNode; +import com.oracle.graal.phases.common.query.nodes.GraalQueryNode; +import com.oracle.graal.phases.common.query.nodes.InstrumentationNode; + +@NodeInfo +public final class IsMethodInlinedNode extends GraalQueryNode { + + public static final NodeClass TYPE = NodeClass.create(IsMethodInlinedNode.class); + + protected int original; + + public IsMethodInlinedNode() { + super(TYPE, StampFactory.forKind(JavaKind.Boolean)); + } + + @Override + public void onExtractICG(InstrumentationNode instrumentation) { + original = System.identityHashCode(instrumentation.graph()); + } + + @Override + public void onInlineICG(InstrumentationNode instrumentation, FixedNode position, ConstantReflectionProvider constantReflection) { + graph().replaceFixedWithFloating(this, ConstantNode.forBoolean(original != System.identityHashCode(instrumentation.graph()), graph())); + } + + @NodeIntrinsic + public static native boolean instantiate(); + +} diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/ForeignCallStub.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/ForeignCallStub.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/ForeignCallStub.java Thu Oct 01 14:32:39 2015 -0700 @@ -99,14 +99,14 @@ */ public ForeignCallStub(HotSpotJVMCIRuntimeProvider runtime, HotSpotProviders providers, long address, ForeignCallDescriptor descriptor, boolean prependThread, Transition transition, boolean reexecutable, LocationIdentity... killedLocations) { - super(providers, HotSpotForeignCallLinkageImpl.create(providers.getMetaAccess(), providers.getCodeCache(), providers.getForeignCalls(), runtime.getCompilerToVM(), descriptor, 0L, - PRESERVES_REGISTERS, JavaCall, JavaCallee, transition, reexecutable, killedLocations)); + super(providers, HotSpotForeignCallLinkageImpl.create(providers.getMetaAccess(), providers.getCodeCache(), providers.getForeignCalls(), descriptor, 0L, PRESERVES_REGISTERS, JavaCall, + JavaCallee, transition, reexecutable, killedLocations)); this.jvmciRuntime = runtime; this.prependThread = prependThread; Class[] targetParameterTypes = createTargetParameters(descriptor); ForeignCallDescriptor targetSig = new ForeignCallDescriptor(descriptor.getName() + ":C", descriptor.getResultType(), targetParameterTypes); - target = HotSpotForeignCallLinkageImpl.create(providers.getMetaAccess(), providers.getCodeCache(), providers.getForeignCalls(), runtime.getCompilerToVM(), targetSig, address, - DESTROYS_REGISTERS, NativeCall, NativeCall, transition, reexecutable, killedLocations); + target = HotSpotForeignCallLinkageImpl.create(providers.getMetaAccess(), providers.getCodeCache(), providers.getForeignCalls(), targetSig, address, DESTROYS_REGISTERS, NativeCall, NativeCall, + transition, reexecutable, killedLocations); } /** diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/Stub.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/Stub.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/Stub.java Thu Oct 01 14:32:39 2015 -0700 @@ -25,8 +25,7 @@ import static com.oracle.graal.compiler.GraalCompiler.emitBackEnd; import static com.oracle.graal.compiler.GraalCompiler.emitFrontEnd; import static com.oracle.graal.compiler.GraalCompiler.getProfilingInfo; -import static jdk.internal.jvmci.hotspot.CompilerToVM.compilerToVM; -import static jdk.internal.jvmci.hotspot.HotSpotVMConfig.config; +import static com.oracle.graal.hotspot.HotSpotHostBackend.UNCOMMON_TRAP_HANDLER; import java.util.ArrayList; import java.util.Collection; @@ -38,23 +37,22 @@ import jdk.internal.jvmci.code.CallingConvention; import jdk.internal.jvmci.code.CodeCacheProvider; import jdk.internal.jvmci.code.CompilationResult; +import jdk.internal.jvmci.code.CompilationResult.Call; +import jdk.internal.jvmci.code.CompilationResult.ConstantReference; +import jdk.internal.jvmci.code.CompilationResult.DataPatch; +import jdk.internal.jvmci.code.CompilationResult.Infopoint; import jdk.internal.jvmci.code.InstalledCode; import jdk.internal.jvmci.code.Register; import jdk.internal.jvmci.code.RegisterConfig; -import jdk.internal.jvmci.common.JVMCIError; -import jdk.internal.jvmci.hotspot.HotSpotCodeCacheProvider; -import jdk.internal.jvmci.hotspot.HotSpotCompiledCode; -import jdk.internal.jvmci.hotspot.HotSpotVMConfig; +import jdk.internal.jvmci.hotspot.HotSpotMetaspaceConstant; import jdk.internal.jvmci.meta.ResolvedJavaMethod; import com.oracle.graal.compiler.target.Backend; import com.oracle.graal.debug.Debug; import com.oracle.graal.debug.Debug.Scope; import com.oracle.graal.debug.internal.DebugScope; -import com.oracle.graal.hotspot.HotSpotCompiledRuntimeStub; import com.oracle.graal.hotspot.HotSpotForeignCallLinkage; import com.oracle.graal.hotspot.meta.HotSpotProviders; -import com.oracle.graal.hotspot.meta.HotSpotRuntimeStub; import com.oracle.graal.hotspot.nodes.StubStartNode; import com.oracle.graal.lir.asm.CompilationResultBuilderFactory; import com.oracle.graal.lir.phases.LIRPhase; @@ -203,23 +201,14 @@ SchedulePhase schedule = emitFrontEnd(providers, backend, graph, providers.getSuites().getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL, getProfilingInfo(graph), suites); LIRSuites lirSuites = createLIRSuites(); emitBackEnd(graph, Stub.this, incomingCc, getInstalledCodeOwner(), backend, compResult, CompilationResultBuilderFactory.Default, schedule, getRegisterConfig(), lirSuites); + assert checkStubInvariants(); } catch (Throwable e) { throw Debug.handle(e); } assert destroyedRegisters != null; try (Scope s = Debug.scope("CodeInstall")) { - Stub stub = Stub.this; - HotSpotRuntimeStub installedCode = new HotSpotRuntimeStub(stub); - HotSpotCompiledCode hsCompResult = new HotSpotCompiledRuntimeStub(compResult); - - int result = compilerToVM().installCode(backend.getTarget(), hsCompResult, installedCode, null); - HotSpotVMConfig config = config(); - if (result != config.codeInstallResultOk) { - throw new JVMCIError("Error installing stub %s: %s", Stub.this, config.getCodeInstallResultDescription(result)); - } - ((HotSpotCodeCacheProvider) codeCache).logOrDump(installedCode, compResult); - code = installedCode; + code = codeCache.installCode(null, compResult, null, null, false); } catch (Throwable e) { throw Debug.handle(e); } @@ -232,6 +221,42 @@ return code; } + /** + * Checks the conditions a compilation must satisfy to be installed as a RuntimeStub. + */ + private boolean checkStubInvariants() { + assert compResult.getExceptionHandlers().isEmpty() : this; + + // Stubs cannot be recompiled so they cannot be compiled with + // assumptions and there is no point in recording evol_method dependencies + assert compResult.getAssumptions() == null : "stubs should not use assumptions: " + this; + assert compResult.getMethods() == null : "stubs should not record evol_method dependencies: " + this; + + for (DataPatch data : compResult.getDataPatches()) { + if (data.reference instanceof ConstantReference) { + ConstantReference ref = (ConstantReference) data.reference; + if (ref.getConstant() instanceof HotSpotMetaspaceConstant) { + HotSpotMetaspaceConstant c = (HotSpotMetaspaceConstant) ref.getConstant(); + if (c.asResolvedJavaType() != null && c.asResolvedJavaType().getName().equals("[I")) { + // special handling for NewArrayStub + // embedding the type '[I' is safe, since it is never unloaded + continue; + } + } + } + + assert !(data.reference instanceof ConstantReference) : this + " cannot have embedded object or metadata constant: " + data.reference; + } + for (Infopoint infopoint : compResult.getInfopoints()) { + assert infopoint instanceof Call : this + " cannot have non-call infopoint: " + infopoint; + Call call = (Call) infopoint; + assert call.target instanceof HotSpotForeignCallLinkage : this + " cannot have non runtime call: " + call.target; + HotSpotForeignCallLinkage callLinkage = (HotSpotForeignCallLinkage) call.target; + assert !callLinkage.isCompiledStub() || callLinkage.getDescriptor().equals(UNCOMMON_TRAP_HANDLER) : this + " cannot call compiled stub " + callLinkage; + } + return true; + } + private LIRSuites createLIRSuites() { LIRSuites lirSuites = new LIRSuites(providers.getSuites().getDefaultLIRSuites()); ListIterator> moveProfiling = lirSuites.getPostAllocationOptimizationStage().findPhase(MoveProfiling.class); diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCMove.java --- a/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCMove.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCMove.java Thu Oct 01 14:32:39 2015 -0700 @@ -182,7 +182,7 @@ @Def({REG}) protected AllocatableValue result; @Use({REG}) protected AllocatableValue input; - @Use({STACK, ILLEGAL}) protected AllocatableValue temp; + @Temp({STACK, ILLEGAL}) protected AllocatableValue temp; public MoveFpGp(AllocatableValue result, AllocatableValue input, AllocatableValue temp) { super(TYPE, SIZE); diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRInstruction.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRInstruction.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRInstruction.java Thu Oct 01 14:32:39 2015 -0700 @@ -171,7 +171,7 @@ ALLOWED_FLAGS = new EnumMap<>(OperandMode.class); ALLOWED_FLAGS.put(OperandMode.USE, EnumSet.of(REG, STACK, COMPOSITE, CONST, ILLEGAL, HINT, UNINITIALIZED)); ALLOWED_FLAGS.put(ALIVE, EnumSet.of(REG, STACK, COMPOSITE, CONST, ILLEGAL, HINT, UNINITIALIZED)); - ALLOWED_FLAGS.put(TEMP, EnumSet.of(REG, COMPOSITE, CONST, ILLEGAL, HINT)); + ALLOWED_FLAGS.put(TEMP, EnumSet.of(REG, STACK, COMPOSITE, ILLEGAL, HINT)); ALLOWED_FLAGS.put(DEF, EnumSet.of(REG, STACK, COMPOSITE, ILLEGAL, HINT)); } diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/LinearScanLifetimeAnalysisPhase.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/LinearScanLifetimeAnalysisPhase.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/LinearScanLifetimeAnalysisPhase.java Thu Oct 01 14:32:39 2015 -0700 @@ -26,6 +26,7 @@ import static com.oracle.graal.lir.LIRValueUtil.asVariable; import static com.oracle.graal.lir.LIRValueUtil.isVariable; import static com.oracle.graal.lir.debug.LIRGenerationDebugContext.getSourceForOperandFromDebugContext; +import static jdk.internal.jvmci.code.ValueUtil.asRegister; import static jdk.internal.jvmci.code.ValueUtil.asStackSlot; import static jdk.internal.jvmci.code.ValueUtil.isRegister; import static jdk.internal.jvmci.code.ValueUtil.isStackSlot; @@ -272,7 +273,7 @@ */ if (isRegister(operand) && block != allocator.getLIR().getControlFlowGraph().getStartBlock()) { if (allocator.isProcessed(operand)) { - assert liveKill.get(allocator.operandNumber(operand)) : "using fixed register that is not defined in this block"; + assert liveKill.get(allocator.operandNumber(operand)) : "using fixed register " + asRegister(operand) + " that is not defined in this block " + block; } } } diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.lir/src/com/oracle/graal/lir/dfa/LocationMarkerPhase.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/dfa/LocationMarkerPhase.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/dfa/LocationMarkerPhase.java Thu Oct 01 14:32:39 2015 -0700 @@ -73,7 +73,18 @@ @Override protected boolean shouldProcessValue(Value operand) { - return (isRegister(operand) && attributes(asRegister(operand)).isAllocatable() || isStackSlot(operand)) && !operand.getLIRKind().equals(LIRKind.Illegal); + if (isRegister(operand)) { + Register reg = asRegister(operand); + if (reg.getReferenceMapIndex() < 0 || !attributes(reg).isAllocatable()) { + // register that's not allocatable or not part of the reference map + return false; + } + } else if (!isStackSlot(operand)) { + // neither register nor stack slot + return false; + } + + return !operand.getLIRKind().equals(LIRKind.Illegal); } /** diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/DeadCodeEliminationPhase.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/DeadCodeEliminationPhase.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/DeadCodeEliminationPhase.java Thu Oct 01 14:32:39 2015 -0700 @@ -22,8 +22,6 @@ */ package com.oracle.graal.phases.common; -import static com.oracle.graal.phases.common.DeadCodeEliminationPhase.Options.ReduceDCE; - import java.util.function.BiConsumer; import jdk.internal.jvmci.options.Option; @@ -75,7 +73,7 @@ @Override public void run(StructuredGraph graph) { - if (optional && ReduceDCE.getValue()) { + if (optional && Options.ReduceDCE.getValue()) { return; } diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/InliningUtil.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/InliningUtil.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/InliningUtil.java Thu Oct 01 14:32:39 2015 -0700 @@ -23,6 +23,7 @@ package com.oracle.graal.phases.common.inlining; import static com.oracle.graal.compiler.common.GraalOptions.HotSpotPrintInlining; +import static com.oracle.graal.compiler.common.GraalOptions.UseGraalQueries; import static jdk.internal.jvmci.meta.DeoptimizationAction.InvalidateReprofile; import static jdk.internal.jvmci.meta.DeoptimizationReason.NullCheckException; @@ -94,6 +95,7 @@ import com.oracle.graal.nodes.type.StampTool; import com.oracle.graal.nodes.util.GraphUtil; import com.oracle.graal.phases.common.inlining.info.InlineInfo; +import com.oracle.graal.phases.common.query.nodes.InstrumentationNode; public class InliningUtil { @@ -363,6 +365,9 @@ unwindNode = (UnwindNode) duplicates.get(unwindNode); } + if (UseGraalQueries.getValue()) { + removeAttachedInstrumentation(invoke); + } finishInlining(invoke, graph, firstCFGNode, returnNodes, unwindNode, inlineGraph.getAssumptions(), inlineGraph, canonicalizedNodes); GraphUtil.killCFG(invokeNode); @@ -753,4 +758,24 @@ throw new GraalGraphJVMCIError(e).addContext(invoke.asNode()).addContext("macroSubstitution", macroNodeClass); } } + + // exclude InstrumentationNode for inlining heuristics + public static int getNodeCount(StructuredGraph graph) { + if (UseGraalQueries.getValue()) { + return graph.getNodeCount() - graph.getNodes().filter(InstrumentationNode.class).count(); + } else { + return graph.getNodeCount(); + } + } + + public static void removeAttachedInstrumentation(Invoke invoke) { + FixedNode invokeNode = invoke.asNode(); + for (InstrumentationNode instrumentation : invokeNode.usages().filter(InstrumentationNode.class)) { + if (instrumentation.target() == invoke) { + GraphUtil.unlinkFixedNode(instrumentation); + instrumentation.safeDelete(); + } + } + } + } diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/info/MultiTypeGuardInlineInfo.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/info/MultiTypeGuardInlineInfo.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/info/MultiTypeGuardInlineInfo.java Thu Oct 01 14:32:39 2015 -0700 @@ -22,6 +22,8 @@ */ package com.oracle.graal.phases.common.inlining.info; +import static com.oracle.graal.compiler.common.GraalOptions.UseGraalQueries; + import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; @@ -241,6 +243,9 @@ assert invoke.next() == continuation; invoke.setNext(null); returnMerge.setNext(continuation); + if (UseGraalQueries.getValue()) { + InliningUtil.removeAttachedInstrumentation(invoke); + } if (returnValuePhi != null) { invoke.asNode().replaceAtUsages(returnValuePhi); } diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/info/elem/InlineableGraph.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/info/elem/InlineableGraph.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/info/elem/InlineableGraph.java Thu Oct 01 14:32:39 2015 -0700 @@ -23,6 +23,7 @@ package com.oracle.graal.phases.common.inlining.info.elem; import static com.oracle.graal.compiler.common.GraalOptions.OptCanonicalizer; +import static com.oracle.graal.compiler.common.GraalOptions.UseGraalQueries; import static com.oracle.graal.phases.common.DeadCodeEliminationPhase.Optionality.Optional; import java.util.ArrayList; @@ -44,6 +45,7 @@ import com.oracle.graal.phases.common.CanonicalizerPhase; import com.oracle.graal.phases.common.DeadCodeEliminationPhase; import com.oracle.graal.phases.common.inlining.InliningUtil; +import com.oracle.graal.phases.common.query.ExtractICGPhase; import com.oracle.graal.phases.graph.FixedNodeProbabilityCache; import com.oracle.graal.phases.tiers.HighTierContext; @@ -209,6 +211,9 @@ } assert newGraph.start().next() != null : "graph needs to be populated by the GraphBuilderSuite " + method + ", " + method.canBeInlined(); + if (UseGraalQueries.getValue()) { + new ExtractICGPhase().apply(newGraph, context); + } new DeadCodeEliminationPhase(Optional).apply(newGraph); if (OptCanonicalizer.getValue()) { @@ -223,7 +228,7 @@ @Override public int getNodeCount() { - return graph.getNodeCount(); + return InliningUtil.getNodeCount(graph); } @Override diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/policy/GreedyInliningPolicy.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/policy/GreedyInliningPolicy.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/policy/GreedyInliningPolicy.java Thu Oct 01 14:32:39 2015 -0700 @@ -49,7 +49,7 @@ } public boolean continueInlining(StructuredGraph currentGraph) { - if (currentGraph.getNodeCount() >= MaximumDesiredSize.getValue()) { + if (InliningUtil.getNodeCount(currentGraph) >= MaximumDesiredSize.getValue()) { InliningUtil.logInliningDecision("inlining is cut off by MaximumDesiredSize"); metricInliningStoppedByMaxDesiredSize.increment(); return false; diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/policy/InlineEverythingPolicy.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/policy/InlineEverythingPolicy.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/policy/InlineEverythingPolicy.java Thu Oct 01 14:32:39 2015 -0700 @@ -27,12 +27,13 @@ import com.oracle.graal.nodes.StructuredGraph; import com.oracle.graal.nodes.spi.Replacements; +import com.oracle.graal.phases.common.inlining.InliningUtil; import com.oracle.graal.phases.common.inlining.walker.MethodInvocation; public class InlineEverythingPolicy implements InliningPolicy { public boolean continueInlining(StructuredGraph graph) { - if (graph.getNodeCount() >= MaximumDesiredSize.getValue()) { + if (InliningUtil.getNodeCount(graph) >= MaximumDesiredSize.getValue()) { throw new BailoutException("Inline all calls failed. The resulting graph is too large."); } return true; diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/walker/ComputeInliningRelevance.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/walker/ComputeInliningRelevance.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/walker/ComputeInliningRelevance.java Thu Oct 01 14:32:39 2015 -0700 @@ -43,6 +43,7 @@ import com.oracle.graal.nodes.MergeNode; import com.oracle.graal.nodes.StartNode; import com.oracle.graal.nodes.StructuredGraph; +import com.oracle.graal.phases.common.inlining.InliningUtil; public class ComputeInliningRelevance { @@ -83,7 +84,7 @@ rootScope = new Scope(graph.start(), null); } else { if (nodeRelevances == null) { - nodeRelevances = Node.newIdentityMap(EXPECTED_MIN_INVOKE_COUNT + graph.getNodeCount() / EXPECTED_INVOKE_RATIO); + nodeRelevances = Node.newIdentityMap(EXPECTED_MIN_INVOKE_COUNT + InliningUtil.getNodeCount(graph) / EXPECTED_INVOKE_RATIO); } NodeWorkList workList = graph.createNodeWorkList(); Map loops = Node.newIdentityMap(EXPECTED_LOOP_COUNT); diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/query/ExtractICGPhase.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/query/ExtractICGPhase.java Thu Oct 01 14:32:39 2015 -0700 @@ -0,0 +1,217 @@ +/* + * Copyright (c) 2015, 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.phases.common.query; + +import java.util.Map; + +import com.oracle.graal.debug.Debug; +import com.oracle.graal.graph.Node; +import com.oracle.graal.graph.NodeBitMap; +import com.oracle.graal.graph.NodeFlood; +import com.oracle.graal.graph.NodePosIterator; +import com.oracle.graal.graph.Position; +import com.oracle.graal.nodeinfo.InputType; +import com.oracle.graal.nodes.AbstractEndNode; +import com.oracle.graal.nodes.AbstractLocalNode; +import com.oracle.graal.nodes.CallTargetNode; +import com.oracle.graal.nodes.FixedNode; +import com.oracle.graal.nodes.FixedWithNextNode; +import com.oracle.graal.nodes.FrameState; +import com.oracle.graal.nodes.LoopEndNode; +import com.oracle.graal.nodes.ParameterNode; +import com.oracle.graal.nodes.ReturnNode; +import com.oracle.graal.nodes.StructuredGraph; +import com.oracle.graal.nodes.ValueNode; +import com.oracle.graal.nodes.calc.FloatingNode; +import com.oracle.graal.nodes.java.MonitorEnterNode; +import com.oracle.graal.nodes.java.MonitorIdNode; +import com.oracle.graal.nodes.util.GraphUtil; +import com.oracle.graal.phases.BasePhase; +import com.oracle.graal.phases.common.DeadCodeEliminationPhase; +import com.oracle.graal.phases.common.query.nodes.GraalQueryNode; +import com.oracle.graal.phases.common.query.nodes.InstrumentationBeginNode; +import com.oracle.graal.phases.common.query.nodes.InstrumentationEndNode; +import com.oracle.graal.phases.common.query.nodes.InstrumentationNode; +import com.oracle.graal.phases.common.query.nodes.MonitorProxyNode; +import com.oracle.graal.phases.tiers.HighTierContext; + +public class ExtractICGPhase extends BasePhase { + + @Override + protected void run(StructuredGraph graph, HighTierContext context) { + for (InstrumentationBeginNode icgBegin : graph.getNodes().filter(InstrumentationBeginNode.class)) { + Instrumentation instrumentation = new Instrumentation(icgBegin); + InstrumentationNode instrumentationNode = instrumentation.createInstrumentationNode(); + + graph.addBeforeFixed(icgBegin, instrumentationNode); + Debug.dump(instrumentationNode.icg(), "After extracted ICG at " + instrumentation); + + instrumentation.unlink(); + } + + for (InstrumentationNode instrumentationNode : graph.getNodes().filter(InstrumentationNode.class)) { + for (GraalQueryNode query : instrumentationNode.icg().getNodes().filter(GraalQueryNode.class)) { + query.onExtractICG(instrumentationNode); + } + } + } + + static class Instrumentation { + + protected InstrumentationBeginNode icgBegin; + protected InstrumentationEndNode icgEnd; + protected ValueNode target; + protected NodeBitMap icgNodes; + + public Instrumentation(InstrumentationBeginNode icgBegin) { + this.icgBegin = icgBegin; + + resolveICGNodes(); + resolveTarget(); + } + + private static boolean shouldIncludeInput(Node node, NodeBitMap cfgNodes) { + if (node instanceof FloatingNode && !(node instanceof AbstractLocalNode)) { + NodePosIterator iterator = node.inputs().iterator(); + while (iterator.hasNext()) { + Position pos = iterator.nextPosition(); + if (pos.getInputType() == InputType.Value) { + continue; + } + if (!cfgNodes.isMarked(pos.get(node))) { + return false; + } + } + return true; + } + if (node instanceof CallTargetNode || node instanceof MonitorIdNode || node instanceof FrameState) { + return true; + } + return false; + } + + private void resolveICGNodes() { + NodeFlood icgCFG = icgBegin.graph().createNodeFlood(); + icgCFG.add(icgBegin.next()); + for (Node current : icgCFG) { + if (current instanceof InstrumentationEndNode) { + icgEnd = (InstrumentationEndNode) current; + } else if (current instanceof LoopEndNode) { + // do nothing + } else if (current instanceof AbstractEndNode) { + icgCFG.add(((AbstractEndNode) current).merge()); + } else { + icgCFG.addAll(current.successors()); + } + } + + NodeBitMap cfgNodes = icgCFG.getVisited(); + NodeFlood icgDFG = icgBegin.graph().createNodeFlood(); + icgDFG.addAll(cfgNodes); + for (Node current : icgDFG) { + if (current instanceof FrameState) { + continue; + } + for (Node input : current.inputs()) { + if (shouldIncludeInput(input, cfgNodes)) { + icgDFG.add(input); + } + } + } + icgNodes = icgDFG.getVisited(); + } + + private void resolveTarget() { + int offset = icgBegin.getOffset(); + if (offset < 0) { + Node pred = icgBegin; + while (offset < 0) { + pred = pred.predecessor(); + if (pred == null || !(pred instanceof FixedNode)) { + target = null; + return; + } + offset++; + } + target = (FixedNode) pred; + } else if (offset > 0) { + FixedNode next = icgEnd; + while (offset > 0) { + next = ((FixedWithNextNode) next).next(); + if (next == null || !(next instanceof FixedWithNextNode)) { + target = null; + return; + } + offset--; + } + target = next; + } + } + + public InstrumentationNode createInstrumentationNode() { + ValueNode newTarget = target; + // MonitorEnterNode may be deleted during PEA + if (newTarget instanceof MonitorEnterNode) { + newTarget = new MonitorProxyNode(newTarget, ((MonitorEnterNode) newTarget).getMonitorId()); + icgBegin.graph().addWithoutUnique(newTarget); + } + InstrumentationNode instrumentationNode = new InstrumentationNode(newTarget, icgBegin.getOffset(), icgBegin.getType()); + icgBegin.graph().addWithoutUnique(instrumentationNode); + // copy icg nodes to the InstrumentationNode instance + StructuredGraph icg = instrumentationNode.icg(); + Map replacements = Node.newMap(); + int index = 0; + for (Node current : icgNodes) { + if (current instanceof FrameState) { + continue; + } + for (Node input : current.inputs()) { + if (!(input instanceof ValueNode)) { + continue; + } + if (!icgNodes.isMarked(input) && !replacements.containsKey(input)) { + ParameterNode parameter = new ParameterNode(index++, ((ValueNode) input).stamp()); + icg.addWithoutUnique(parameter); + replacements.put(input, parameter); + instrumentationNode.addInput(input); + } + } + } + replacements = icg.addDuplicates(icgNodes, icgBegin.graph(), icgNodes.count(), replacements); + icg.start().setNext((FixedNode) replacements.get(icgBegin.next())); + replacements.get(icgEnd).replaceAtPredecessor(icg.addWithoutUnique(new ReturnNode(null))); + + new DeadCodeEliminationPhase().apply(icg, false); + return instrumentationNode; + } + + public void unlink() { + FixedNode next = icgEnd.next(); + icgEnd.setNext(null); + icgBegin.replaceAtPredecessor(next); + GraphUtil.killCFG(icgBegin); + } + + } + +} diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/query/HighTierReconcileICGPhase.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/query/HighTierReconcileICGPhase.java Thu Oct 01 14:32:39 2015 -0700 @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2015, 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.phases.common.query; + +import java.util.HashMap; +import java.util.function.Predicate; +import java.util.function.Supplier; + +import com.oracle.graal.graph.Node; +import com.oracle.graal.graph.NodeFlood; +import com.oracle.graal.nodes.AbstractEndNode; +import com.oracle.graal.nodes.FixedWithNextNode; +import com.oracle.graal.nodes.LoopEndNode; +import com.oracle.graal.nodes.StructuredGraph; +import com.oracle.graal.nodes.ValueNode; +import com.oracle.graal.nodes.java.AccessMonitorNode; +import com.oracle.graal.nodes.java.MonitorIdNode; +import com.oracle.graal.nodes.util.GraphUtil; +import com.oracle.graal.nodes.virtual.AllocatedObjectNode; +import com.oracle.graal.nodes.virtual.CommitAllocationNode; +import com.oracle.graal.nodes.virtual.VirtualObjectNode; +import com.oracle.graal.phases.Phase; +import com.oracle.graal.phases.common.query.nodes.InstrumentationNode; +import com.oracle.graal.phases.common.query.nodes.MonitorProxyNode; + +public class HighTierReconcileICGPhase extends Phase { + + @Override + protected void run(StructuredGraph graph) { + for (CommitAllocationNode commit : graph.getNodes().filter(CommitAllocationNode.class)) { + InstrumentationAggregation aggregation = new InstrumentationAggregation(commit); + + for (int objIndex = 0; objIndex < commit.getVirtualObjects().size(); objIndex++) { + VirtualObjectNode virtual = commit.getVirtualObjects().get(objIndex); + aggregation.duplicateInstrumentationIfMatch(i -> i.target() == virtual, () -> getAllocatedObject(commit, virtual)); + } + + for (int objIndex = 0; objIndex < commit.getVirtualObjects().size(); objIndex++) { + VirtualObjectNode virtual = commit.getVirtualObjects().get(objIndex); + for (MonitorIdNode monitorId : commit.getLocks(objIndex)) { + aggregation.duplicateInstrumentationIfMatch(i -> i.target() instanceof MonitorProxyNode && ((MonitorProxyNode) i.target()).getMonitorId() == monitorId, () -> new MonitorProxyNode( + getAllocatedObject(commit, virtual), monitorId)); + } + } + } + + for (InstrumentationNode instrumentationNode : graph.getNodes().filter(InstrumentationNode.class)) { + ValueNode target = instrumentationNode.target(); + if (target instanceof VirtualObjectNode) { + // at this point, we can remove InstrumentationNode whose target is still virtual. + GraphUtil.unlinkFixedNode(instrumentationNode); + instrumentationNode.safeDelete(); + } else if (target instanceof MonitorProxyNode) { + MonitorProxyNode proxy = (MonitorProxyNode) target; + if (proxy.target() == null || proxy.target().isDeleted()) { + GraphUtil.unlinkFixedNode(instrumentationNode); + instrumentationNode.safeDelete(); + } else if (proxy.target() instanceof AccessMonitorNode) { + // unproxify the target of the InstrumentationNode. + instrumentationNode.replaceFirstInput(proxy, proxy.target()); + } + } + } + } + + class InstrumentationAggregation { + + protected CommitAllocationNode commit; + protected FixedWithNextNode insertingLocation; + + public InstrumentationAggregation(CommitAllocationNode commit) { + this.commit = commit; + this.insertingLocation = commit; + } + + public void insert(InstrumentationNode instrumentationNode) { + commit.graph().addAfterFixed(insertingLocation, instrumentationNode); + insertingLocation = instrumentationNode; + } + + public void duplicateInstrumentationIfMatch(Predicate guard, Supplier newTargetSupplier) { + StructuredGraph graph = commit.graph(); + for (InstrumentationNode instrumentationNode : graph.getNodes().filter(InstrumentationNode.class)) { + // insert ICG only if the CommitAllocationNode is accessible from the + // instrumentation node + if (!(isCFGAccessible(instrumentationNode, commit) && guard.test(instrumentationNode))) { + continue; + } + InstrumentationNode clone = (InstrumentationNode) instrumentationNode.copyWithInputs(); + ValueNode newTarget = newTargetSupplier.get(); + if (!newTarget.isAlive()) { + graph.addWithoutUnique(newTarget); + } + clone.replaceFirstInput(clone.target(), newTarget); + updateVirtualInputs(clone); + insert(clone); + } + } + + private void updateVirtualInputs(InstrumentationNode clone) { + for (ValueNode input : clone.getWeakDependencies()) { + if ((input instanceof VirtualObjectNode) && (commit.getVirtualObjects().contains(input))) { + clone.replaceFirstInput(input, getAllocatedObject(commit, (VirtualObjectNode) input)); + } + } + } + + } + + private final HashMap cachedNodeFloods = new HashMap<>(); + + private boolean isCFGAccessible(InstrumentationNode from, CommitAllocationNode to) { + // we only insert InstrumentationNode during this phase, so it is fine to reuse cached + // NodeFlood. + NodeFlood flood = cachedNodeFloods.get(from); + if (flood == null) { + flood = from.graph().createNodeFlood(); + flood.add(from); + for (Node current : flood) { + if (current instanceof LoopEndNode) { + continue; + } else if (current instanceof AbstractEndNode) { + flood.add(((AbstractEndNode) current).merge()); + } else { + flood.addAll(current.successors()); + } + } + cachedNodeFloods.put(from, flood); + } + return flood.isMarked(to); + } + + private static AllocatedObjectNode getAllocatedObject(CommitAllocationNode commit, VirtualObjectNode virtual) { + for (AllocatedObjectNode object : commit.graph().getNodes().filter(AllocatedObjectNode.class)) { + if (object.getCommit() == commit && object.getVirtualObject() == virtual) { + return object; + } + } + AllocatedObjectNode object = commit.graph().addWithoutUnique(new AllocatedObjectNode(virtual)); + object.setCommit(commit); + return object; + } + +} diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/query/InlineICGPhase.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/query/InlineICGPhase.java Thu Oct 01 14:32:39 2015 -0700 @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2015, 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.phases.common.query; + +import java.util.HashSet; +import java.util.Set; + +import com.oracle.graal.nodeinfo.InputType; +import com.oracle.graal.nodes.StructuredGraph; +import com.oracle.graal.nodes.memory.MemoryAnchorNode; +import com.oracle.graal.nodes.spi.LoweringTool; +import com.oracle.graal.nodes.util.GraphUtil; +import com.oracle.graal.phases.BasePhase; +import com.oracle.graal.phases.common.CanonicalizerPhase; +import com.oracle.graal.phases.common.FloatingReadPhase; +import com.oracle.graal.phases.common.FrameStateAssignmentPhase; +import com.oracle.graal.phases.common.GuardLoweringPhase; +import com.oracle.graal.phases.common.LoweringPhase; +import com.oracle.graal.phases.common.query.nodes.GraalQueryNode; +import com.oracle.graal.phases.common.query.nodes.InstrumentationNode; +import com.oracle.graal.phases.tiers.LowTierContext; + +public class InlineICGPhase extends BasePhase { + + @Override + protected void run(StructuredGraph graph, LowTierContext context) { + // ICG may be shared amongst multiple InstrumentationNode + Set icgs = new HashSet<>(); + for (InstrumentationNode instrumentationNode : graph.getNodes().filter(InstrumentationNode.class)) { + icgs.add(instrumentationNode.icg()); + } + for (StructuredGraph icg : icgs) { + new GuardLoweringPhase().apply(icg, null); + new FrameStateAssignmentPhase().apply(icg, false); + new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.LOW_TIER).apply(icg, context); + new FloatingReadPhase(true, true).apply(icg, false); + + MemoryAnchorNode anchor = icg.add(new MemoryAnchorNode()); + icg.start().replaceAtUsages(InputType.Memory, anchor); + if (anchor.hasNoUsages()) { + anchor.safeDelete(); + } else { + icg.addAfterFixed(icg.start(), anchor); + } + } + + for (InstrumentationNode instrumentationNode : graph.getNodes().filter(InstrumentationNode.class)) { + instrumentationNode.inlineAt(instrumentationNode); + + for (GraalQueryNode query : graph.getNodes().filter(GraalQueryNode.class)) { + query.onInlineICG(instrumentationNode, instrumentationNode, context.getConstantReflection()); + } + + GraphUtil.unlinkFixedNode(instrumentationNode); + instrumentationNode.clearInputs(); + GraphUtil.killCFG(instrumentationNode); + } + + new CanonicalizerPhase().apply(graph, context); + } + +} diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/query/MidTierReconcileICGPhase.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/query/MidTierReconcileICGPhase.java Thu Oct 01 14:32:39 2015 -0700 @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2015, 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.phases.common.query; + +import com.oracle.graal.nodes.StructuredGraph; +import com.oracle.graal.nodes.ValueNode; +import com.oracle.graal.nodes.extended.FixedValueAnchorNode; +import com.oracle.graal.nodes.java.AccessMonitorNode; +import com.oracle.graal.nodes.util.GraphUtil; +import com.oracle.graal.phases.Phase; +import com.oracle.graal.phases.common.query.nodes.InstrumentationNode; +import com.oracle.graal.phases.common.query.nodes.MonitorProxyNode; + +public class MidTierReconcileICGPhase extends Phase { + + private static AccessMonitorNode unproxify(MonitorProxyNode proxy) { + for (AccessMonitorNode monitorEnter : proxy.getMonitorId().usages().filter(AccessMonitorNode.class)) { + if (monitorEnter.object() == proxy.target()) { + return monitorEnter; + } + } + return null; + } + + @Override + protected void run(StructuredGraph graph) { + for (InstrumentationNode instrumentationNode : graph.getNodes().filter(InstrumentationNode.class)) { + ValueNode target = instrumentationNode.target(); + if (target instanceof MonitorProxyNode) { + instrumentationNode.replaceFirstInput(target, unproxify((MonitorProxyNode) target)); + } else if (target instanceof FixedValueAnchorNode) { + instrumentationNode.replaceFirstInput(target, GraphUtil.unproxify(target)); + } + } + } +} diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/query/nodes/GraalQueryNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/query/nodes/GraalQueryNode.java Thu Oct 01 14:32:39 2015 -0700 @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2015, 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.phases.common.query.nodes; + +import jdk.internal.jvmci.meta.ConstantReflectionProvider; + +import com.oracle.graal.compiler.common.type.Stamp; +import com.oracle.graal.graph.NodeClass; +import com.oracle.graal.nodeinfo.NodeInfo; +import com.oracle.graal.nodes.FixedNode; +import com.oracle.graal.nodes.FixedWithNextNode; + +@NodeInfo +public abstract class GraalQueryNode extends FixedWithNextNode { + + public static final NodeClass TYPE = NodeClass.create(GraalQueryNode.class); + + public GraalQueryNode(NodeClass c, Stamp stamp) { + super(c, stamp); + } + + public void onExtractICG(@SuppressWarnings("unused") InstrumentationNode instrumentation) { + } + + public void onInlineICG(@SuppressWarnings("unused") InstrumentationNode instrumentation, @SuppressWarnings("unused") FixedNode position, + @SuppressWarnings("unused") ConstantReflectionProvider constantReflection) { + } + +} diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/query/nodes/InstrumentationBeginNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/query/nodes/InstrumentationBeginNode.java Thu Oct 01 14:32:39 2015 -0700 @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2015, 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.phases.common.query.nodes; + +import com.oracle.graal.compiler.common.type.StampFactory; +import com.oracle.graal.graph.NodeClass; +import com.oracle.graal.nodeinfo.NodeInfo; +import com.oracle.graal.nodes.FixedWithNextNode; + +@NodeInfo +public final class InstrumentationBeginNode extends FixedWithNextNode { + + public static final NodeClass TYPE = NodeClass.create(InstrumentationBeginNode.class); + + protected final int offset; + protected final int type; + + public InstrumentationBeginNode(int offset, int type) { + super(TYPE, StampFactory.forVoid()); + this.offset = offset; + this.type = type; + } + + public int getOffset() { + return offset; + } + + public int getType() { + return type; + } + + @NodeIntrinsic + public static native void instantiate(@ConstantNodeParameter int offset, @ConstantNodeParameter int type); + +} diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/query/nodes/InstrumentationEndNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/query/nodes/InstrumentationEndNode.java Thu Oct 01 14:32:39 2015 -0700 @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2015, 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.phases.common.query.nodes; + +import com.oracle.graal.compiler.common.type.StampFactory; +import com.oracle.graal.graph.NodeClass; +import com.oracle.graal.nodeinfo.NodeInfo; +import com.oracle.graal.nodes.FixedWithNextNode; + +@NodeInfo +public final class InstrumentationEndNode extends FixedWithNextNode { + + public static final NodeClass TYPE = NodeClass.create(InstrumentationEndNode.class); + + public InstrumentationEndNode() { + super(TYPE, StampFactory.forVoid()); + } + + @NodeIntrinsic + public static native void instantiate(); + +} diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/query/nodes/InstrumentationNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/query/nodes/InstrumentationNode.java Thu Oct 01 14:32:39 2015 -0700 @@ -0,0 +1,195 @@ +/* + * Copyright (c) 2015, 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.phases.common.query.nodes; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Map; + +import jdk.internal.jvmci.meta.JavaConstant; +import jdk.internal.jvmci.meta.JavaKind; + +import com.oracle.graal.compiler.common.type.StampFactory; +import com.oracle.graal.graph.Graph.DuplicationReplacement; +import com.oracle.graal.graph.Node; +import com.oracle.graal.graph.NodeClass; +import com.oracle.graal.graph.NodeInputList; +import com.oracle.graal.nodeinfo.InputType; +import com.oracle.graal.nodeinfo.NodeInfo; +import com.oracle.graal.nodes.AbstractBeginNode; +import com.oracle.graal.nodes.AbstractMergeNode; +import com.oracle.graal.nodes.ConstantNode; +import com.oracle.graal.nodes.EndNode; +import com.oracle.graal.nodes.FixedNode; +import com.oracle.graal.nodes.FixedWithNextNode; +import com.oracle.graal.nodes.FrameState; +import com.oracle.graal.nodes.MergeNode; +import com.oracle.graal.nodes.ParameterNode; +import com.oracle.graal.nodes.ReturnNode; +import com.oracle.graal.nodes.StartNode; +import com.oracle.graal.nodes.StructuredGraph; +import com.oracle.graal.nodes.StructuredGraph.AllowAssumptions; +import com.oracle.graal.nodes.ValueNode; +import com.oracle.graal.nodes.spi.Virtualizable; +import com.oracle.graal.nodes.spi.VirtualizerTool; +import com.oracle.graal.nodes.virtual.EscapeObjectState; +import com.oracle.graal.nodes.virtual.VirtualObjectNode; + +@NodeInfo +public class InstrumentationNode extends FixedWithNextNode implements Virtualizable { + + public static final NodeClass TYPE = NodeClass.create(InstrumentationNode.class); + + @OptionalInput(value = InputType.Association) protected ValueNode target; + @OptionalInput protected NodeInputList weakDependencies; + + protected StructuredGraph icg; + protected final int offset; + protected final int type; + + public InstrumentationNode(ValueNode target, int offset, int type) { + super(TYPE, StampFactory.forVoid()); + + this.target = target; + this.icg = new StructuredGraph(AllowAssumptions.YES); + this.offset = offset; + this.type = type; + + this.weakDependencies = new NodeInputList<>(this); + } + + public boolean addInput(Node node) { + return weakDependencies.add(node); + } + + public ValueNode target() { + return target; + } + + public StructuredGraph icg() { + return icg; + } + + public int offset() { + return offset; + } + + public int type() { + return type; + } + + public NodeInputList getWeakDependencies() { + return weakDependencies; + } + + public void virtualize(VirtualizerTool tool) { + // InstrumentationNode allows non-materialized inputs. During the inlining of the + // InstrumentationNode, non-materialized inputs will be replaced by null. + if (target != null) { + ValueNode alias = tool.getAlias(target); + if (alias instanceof VirtualObjectNode) { + tool.replaceFirstInput(target, alias); + } + } + for (ValueNode input : weakDependencies) { + ValueNode alias = tool.getAlias(input); + if (alias instanceof VirtualObjectNode) { + tool.replaceFirstInput(input, alias); + } + } + } + + public void inlineAt(FixedNode position) { + ArrayList nodes = new ArrayList<>(icg.getNodes().count()); + final StartNode entryPointNode = icg.start(); + FixedNode firstCFGNode = entryPointNode.next(); + ArrayList returnNodes = new ArrayList<>(4); + + for (Node icgnode : icg.getNodes()) { + if (icgnode == entryPointNode || icgnode == entryPointNode.stateAfter() || icgnode instanceof ParameterNode) { + // Do nothing. + } else { + nodes.add(icgnode); + if (icgnode instanceof ReturnNode) { + returnNodes.add((ReturnNode) icgnode); + } + } + } + + final AbstractBeginNode prevBegin = AbstractBeginNode.prevBegin(position); + DuplicationReplacement localReplacement = new DuplicationReplacement() { + + public Node replacement(Node replacement) { + if (replacement instanceof ParameterNode) { + ValueNode value = getWeakDependencies().get(((ParameterNode) replacement).index()); + if (value == null || value.isDeleted() || value instanceof VirtualObjectNode || value.stamp().getStackKind() != JavaKind.Object) { + return graph().unique(new ConstantNode(JavaConstant.NULL_POINTER, ((ParameterNode) replacement).stamp())); + } else { + return value; + } + } else if (replacement == entryPointNode) { + return prevBegin; + } + return replacement; + } + + }; + + Map duplicates = graph().addDuplicates(nodes, icg, icg.getNodeCount(), localReplacement); + FixedNode firstCFGNodeDuplicate = (FixedNode) duplicates.get(firstCFGNode); + position.replaceAtPredecessor(firstCFGNodeDuplicate); + + if (!returnNodes.isEmpty()) { + if (returnNodes.size() == 1) { + ReturnNode returnNode = (ReturnNode) duplicates.get(returnNodes.get(0)); + returnNode.replaceAndDelete(position); + } else { + ArrayList returnDuplicates = new ArrayList<>(returnNodes.size()); + for (ReturnNode returnNode : returnNodes) { + returnDuplicates.add((ReturnNode) duplicates.get(returnNode)); + } + AbstractMergeNode merge = graph().add(new MergeNode()); + + for (ReturnNode returnNode : returnDuplicates) { + EndNode endNode = graph().add(new EndNode()); + merge.addForwardEnd(endNode); + returnNode.replaceAndDelete(endNode); + } + + merge.setNext(position); + } + } + + // since we may relocate InstrumentationNodes, the FrameState can be invalid + for (Node replacee : duplicates.values()) { + if (replacee instanceof FrameState) { + FrameState oldState = (FrameState) replacee; + FrameState newState = new FrameState(null, oldState.method(), oldState.bci, 0, 0, 0, oldState.rethrowException(), oldState.duringCall(), null, + Collections. emptyList()); + graph().addWithoutUnique(newState); + oldState.replaceAtUsages(newState); + } + } + } + +} diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/query/nodes/MonitorProxyNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/query/nodes/MonitorProxyNode.java Thu Oct 01 14:32:39 2015 -0700 @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2015, 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.phases.common.query.nodes; + +import com.oracle.graal.compiler.common.type.StampFactory; +import com.oracle.graal.graph.NodeClass; +import com.oracle.graal.nodeinfo.InputType; +import com.oracle.graal.nodeinfo.NodeInfo; +import com.oracle.graal.nodes.ValueNode; +import com.oracle.graal.nodes.java.MonitorIdNode; + +@NodeInfo +public class MonitorProxyNode extends ValueNode { + + public static final NodeClass TYPE = NodeClass.create(MonitorProxyNode.class); + + @OptionalInput(value = InputType.Association) protected ValueNode target; + @OptionalInput(value = InputType.Association) protected MonitorIdNode monitorId; + + public MonitorProxyNode(ValueNode target, MonitorIdNode monitorId) { + super(TYPE, StampFactory.forVoid()); + + this.target = target; + this.monitorId = monitorId; + } + + public ValueNode target() { + return target; + } + + public MonitorIdNode getMonitorId() { + return monitorId; + } + +} diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.printer/src/com/oracle/graal/printer/NoDeadCodeVerifyHandler.java --- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/NoDeadCodeVerifyHandler.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/NoDeadCodeVerifyHandler.java Thu Oct 01 14:32:39 2015 -0700 @@ -22,8 +22,6 @@ */ package com.oracle.graal.printer; -import static com.oracle.graal.printer.NoDeadCodeVerifyHandler.Options.NDCV; - import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -64,7 +62,7 @@ private static final Map discovered = new ConcurrentHashMap<>(); public void verify(Object object, String message) { - if (NDCV.getValue() != OFF && object instanceof StructuredGraph) { + if (Options.NDCV.getValue() != OFF && object instanceof StructuredGraph) { StructuredGraph graph = (StructuredGraph) object; List before = graph.getNodes().snapshot(); new DeadCodeEliminationPhase().run(graph); @@ -75,12 +73,12 @@ before.removeAll(after); String prefix = message == null ? "" : message + ": "; JVMCIError error = new JVMCIError("%sfound dead nodes in %s: %s", prefix, graph, before); - if (NDCV.getValue() == INFO) { + if (Options.NDCV.getValue() == INFO) { System.out.println(error.getMessage()); - } else if (NDCV.getValue() == VERBOSE) { + } else if (Options.NDCV.getValue() == VERBOSE) { error.printStackTrace(System.out); } else { - assert NDCV.getValue() == FATAL; + assert Options.NDCV.getValue() == FATAL; throw error; } } diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetTemplate.java --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetTemplate.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetTemplate.java Thu Oct 01 14:32:39 2015 -0700 @@ -22,6 +22,7 @@ */ package com.oracle.graal.replacements; +import static com.oracle.graal.compiler.common.GraalOptions.UseGraalQueries; import static com.oracle.graal.debug.Debug.applyFormattingFlagsAndWidth; import static com.oracle.graal.phases.common.DeadCodeEliminationPhase.Optionality.Required; import static com.oracle.graal.replacements.SnippetTemplate.AbstractTemplates.UseSnippetTemplateCache; @@ -117,6 +118,7 @@ import com.oracle.graal.phases.common.GuardLoweringPhase; import com.oracle.graal.phases.common.LoweringPhase; import com.oracle.graal.phases.common.inlining.InliningUtil; +import com.oracle.graal.phases.common.query.nodes.InstrumentationNode; import com.oracle.graal.phases.tiers.PhaseContext; import com.oracle.graal.phases.util.Providers; import com.oracle.graal.replacements.Snippet.ConstantParameter; @@ -1336,6 +1338,20 @@ updateStamps(replacee, duplicates); + if (UseGraalQueries.getValue()) { + for (InstrumentationNode instrumentation : replaceeGraph.getNodes().filter(InstrumentationNode.class)) { + if (instrumentation.target() == replacee) { + if (instrumentation.offset() < 0) { + ReturnNode returnDuplicate = (ReturnNode) duplicates.get(returnNode); + FixedWithNextNode pred = (FixedWithNextNode) returnDuplicate.predecessor(); + instrumentation.replaceFirstInput(replacee, pred); + } else { + instrumentation.replaceFirstInput(replacee, firstCFGNodeDuplicate); + } + } + } + } + rewireMemoryGraph(replacee, duplicates); // Replace all usages of the replacee with the value returned by the snippet diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/StandardGraphBuilderPlugins.java --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/StandardGraphBuilderPlugins.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/StandardGraphBuilderPlugins.java Thu Oct 01 14:32:39 2015 -0700 @@ -23,6 +23,7 @@ package com.oracle.graal.replacements; import static jdk.internal.jvmci.code.MemoryBarriers.JMM_POST_VOLATILE_READ; +import static jdk.internal.jvmci.code.MemoryBarriers.JMM_POST_VOLATILE_WRITE; import static jdk.internal.jvmci.code.MemoryBarriers.JMM_PRE_VOLATILE_READ; import static jdk.internal.jvmci.code.MemoryBarriers.JMM_PRE_VOLATILE_WRITE; @@ -607,7 +608,7 @@ } b.add(new UnsafeStoreNode(object, offset, value, kind, LocationIdentity.any())); if (isVolatile) { - b.add(new MembarNode(JMM_PRE_VOLATILE_WRITE)); + b.add(new MembarNode(JMM_POST_VOLATILE_WRITE)); } b.getGraph().markUnsafeAccess(); return true; diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.truffle.hotspot.amd64/src/com/oracle/graal/truffle/hotspot/amd64/AMD64OptimizedCallTargetInstrumentationFactory.java --- a/graal/com.oracle.graal.truffle.hotspot.amd64/src/com/oracle/graal/truffle/hotspot/amd64/AMD64OptimizedCallTargetInstrumentationFactory.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.truffle.hotspot.amd64/src/com/oracle/graal/truffle/hotspot/amd64/AMD64OptimizedCallTargetInstrumentationFactory.java Thu Oct 01 14:32:39 2015 -0700 @@ -57,13 +57,10 @@ Register spillRegister = AMD64.r10; // TODO(mg): fix me Label doProlog = new Label(); - AMD64Address codeBlobAddress = new AMD64Address(thisRegister, getFieldOffset("address", InstalledCode.class)); + AMD64Address codeBlobAddress = new AMD64Address(thisRegister, getFieldOffset("entryPoint", InstalledCode.class)); asm.movq(spillRegister, codeBlobAddress); - asm.cmpq(spillRegister, 0); + asm.testq(spillRegister, spillRegister); asm.jcc(ConditionFlag.Equal, doProlog); - - AMD64Address verifiedEntryPointAddress = new AMD64Address(spillRegister, config.nmethodEntryOffset); - asm.movq(spillRegister, verifiedEntryPointAddress); asm.jmp(spillRegister); asm.bind(doProlog); diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.truffle.hotspot.sparc/src/com/oracle/graal/truffle/hotspot/sparc/SPARCOptimizedCallTargetInstumentationFactory.java --- a/graal/com.oracle.graal.truffle.hotspot.sparc/src/com/oracle/graal/truffle/hotspot/sparc/SPARCOptimizedCallTargetInstumentationFactory.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.truffle.hotspot.sparc/src/com/oracle/graal/truffle/hotspot/sparc/SPARCOptimizedCallTargetInstumentationFactory.java Thu Oct 01 14:32:39 2015 -0700 @@ -59,12 +59,10 @@ Register thisRegister = codeCache.getRegisterConfig().getCallingConventionRegisters(JavaCall, Object)[0]; Register spillRegister = scratch.getRegister(); Label doProlog = new Label(); - SPARCAddress codeBlobAddress = new SPARCAddress(thisRegister, getFieldOffset("address", InstalledCode.class)); - SPARCAddress verifiedEntryPointAddress = new SPARCAddress(spillRegister, config.nmethodEntryOffset); + SPARCAddress entryPointAddress = new SPARCAddress(thisRegister, getFieldOffset("entryPoint", InstalledCode.class)); - asm.ldx(codeBlobAddress, spillRegister); + asm.ldx(entryPointAddress, spillRegister); asm.compareBranch(spillRegister, 0, Equal, Xcc, doProlog, PREDICT_NOT_TAKEN, null); - asm.ldx(verifiedEntryPointAddress, spillRegister); // in delay slot asm.jmp(spillRegister); asm.nop(); asm.bind(doProlog); diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotTruffleRuntime.java --- a/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotTruffleRuntime.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotTruffleRuntime.java Thu Oct 01 14:32:39 2015 -0700 @@ -24,19 +24,18 @@ import static com.oracle.graal.compiler.GraalCompiler.compileGraph; import static com.oracle.graal.compiler.GraalCompiler.getProfilingInfo; -import static com.oracle.graal.graph.util.CollectionsAccess.newIdentityMap; -import static com.oracle.graal.hotspot.meta.HotSpotSuitesProvider.withSimpleDebugInfoIfRequested; +import static com.oracle.graal.hotspot.meta.HotSpotSuitesProvider.withSimpleDebugInfo; import static com.oracle.graal.truffle.TruffleCompilerOptions.TraceTruffleStackTraceLimit; import static com.oracle.graal.truffle.TruffleCompilerOptions.TraceTruffleTransferToInterpreter; import static com.oracle.graal.truffle.TruffleCompilerOptions.TruffleCompilationExceptionsAreThrown; import static com.oracle.graal.truffle.hotspot.UnsafeAccess.UNSAFE; import static jdk.internal.jvmci.code.CodeUtil.getCallingConvention; -import static jdk.internal.jvmci.hotspot.CompilerToVM.compilerToVM; import static jdk.internal.jvmci.hotspot.HotSpotVMConfig.config; import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.IdentityHashMap; import java.util.ListIterator; import java.util.Map; import java.util.WeakHashMap; @@ -54,7 +53,10 @@ import jdk.internal.jvmci.code.CallingConvention.Type; import jdk.internal.jvmci.code.CodeCacheProvider; import jdk.internal.jvmci.code.CompilationResult; +import jdk.internal.jvmci.code.stack.StackIntrospection; import jdk.internal.jvmci.common.JVMCIError; +import jdk.internal.jvmci.hotspot.HotSpotCodeCacheProvider; +import jdk.internal.jvmci.hotspot.HotSpotJVMCIRuntime; import jdk.internal.jvmci.hotspot.HotSpotResolvedJavaMethod; import jdk.internal.jvmci.hotspot.HotSpotSpeculationLog; import jdk.internal.jvmci.hotspot.HotSpotVMConfig; @@ -117,14 +119,14 @@ return new HotSpotTruffleRuntime(); } - private Map> compilations = newIdentityMap(); + private Map> compilations = Collections.synchronizedMap(new IdentityHashMap<>()); private final ExecutorService compileQueue; + private StackIntrospection stackIntrospection; private final Map callTargets = Collections.synchronizedMap(new WeakHashMap()); private HotSpotTruffleRuntime() { setDontInlineCallBoundaryMethod(); - lookupCallMethods(getHotSpotProviders().getMetaAccess()); installDefaultListeners(); @@ -160,6 +162,14 @@ } @Override + protected StackIntrospection getStackIntrospection() { + if (stackIntrospection == null) { + stackIntrospection = HotSpotJVMCIRuntime.runtime().getHostJVMCIBackend().getStackIntrospection(); + } + return stackIntrospection; + } + + @Override public TruffleCompiler getTruffleCompiler() { if (truffleCompiler == null) { truffleCompiler = DefaultTruffleCompiler.create(); @@ -212,7 +222,7 @@ CompilationResult compResult = compileMethod(method); CodeCacheProvider codeCache = providers.getCodeCache(); try (Scope s = Debug.scope("CodeInstall", codeCache, method)) { - codeCache.setDefaultMethod(method, compResult); + codeCache.setDefaultCode(method, compResult); } catch (Throwable e) { throw Debug.handle(e); } @@ -241,12 +251,13 @@ MetaAccessProvider metaAccess = providers.getMetaAccess(); Plugins plugins = new Plugins(new InvocationPlugins(metaAccess)); - boolean infoPoints = compilerToVM().shouldDebugNonSafepoints(); + HotSpotCodeCacheProvider codeCache = providers.getCodeCache(); + boolean infoPoints = codeCache.shouldDebugNonSafepoints(); GraphBuilderConfiguration config = infoPoints ? GraphBuilderConfiguration.getInfopointEagerDefault(plugins) : GraphBuilderConfiguration.getEagerDefault(plugins); new GraphBuilderPhase.Instance(metaAccess, providers.getStampProvider(), providers.getConstantReflection(), config, OptimisticOptimizations.ALL, null).apply(graph); - PhaseSuite graphBuilderSuite = getGraphBuilderSuite(suitesProvider); - CallingConvention cc = getCallingConvention(providers.getCodeCache(), Type.JavaCallee, graph.method(), false); + PhaseSuite graphBuilderSuite = getGraphBuilderSuite(codeCache, suitesProvider); + CallingConvention cc = getCallingConvention(codeCache, Type.JavaCallee, graph.method(), false); Backend backend = getHotSpotBackend(); CompilationResultBuilderFactory factory = getOptimizedCallTargetInstrumentationFactory(backend.getTarget().arch.getName()); return compileGraph(graph, cc, javaMethod, providers, backend, graphBuilderSuite, OptimisticOptimizations.ALL, getProfilingInfo(graph), suites, lirSuites, new CompilationResult(), factory); @@ -261,9 +272,12 @@ return getHotSpotBackend().getProviders(); } - private static PhaseSuite getGraphBuilderSuite(SuitesProvider suitesProvider) { + private static PhaseSuite getGraphBuilderSuite(CodeCacheProvider codeCache, SuitesProvider suitesProvider) { PhaseSuite graphBuilderSuite = suitesProvider.getDefaultGraphBuilderSuite(); - return withSimpleDebugInfoIfRequested(graphBuilderSuite); + if (codeCache.shouldDebugNonSafepoints()) { + graphBuilderSuite = withSimpleDebugInfo(graphBuilderSuite); + } + return graphBuilderSuite; } private static void removeInliningPhase(Suites suites) { @@ -348,9 +362,14 @@ return false; } + private static CodeCacheProvider getCodeCache() { + Providers providers = getHotSpotProviders(); + return providers.getCodeCache(); + } + @Override public void invalidateInstalledCode(OptimizedCallTarget optimizedCallTarget, Object source, CharSequence reason) { - compilerToVM().invalidateInstalledCode(optimizedCallTarget); + getCodeCache().invalidateInstalledCode(optimizedCallTarget); getCompilationNotify().notifyCompilationInvalidated(optimizedCallTarget, source, reason); } @@ -360,8 +379,16 @@ } @Override - public boolean platformEnableInfopoints() { - return compilerToVM().shouldDebugNonSafepoints(); + protected boolean platformEnableInfopoints() { + return getCodeCache().shouldDebugNonSafepoints(); + } + + @Override + protected CallMethods getCallMethods() { + if (callMethods == null) { + lookupCallMethods(getHotSpotProviders().getMetaAccess()); + } + return callMethods; } @Override diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/nfi/HotSpotNativeFunctionInterface.java --- a/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/nfi/HotSpotNativeFunctionInterface.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/nfi/HotSpotNativeFunctionInterface.java Thu Oct 01 14:32:39 2015 -0700 @@ -182,7 +182,7 @@ lirSuites, new CompilationResult(), CompilationResultBuilderFactory.Default); InstalledCode installedCode; try (Scope s = Debug.scope("CodeInstall", providers.getCodeCache(), g.method())) { - installedCode = providers.getCodeCache().addMethod(g.method(), compResult, null, null); + installedCode = providers.getCodeCache().addCode(g.method(), compResult, null, null); } catch (Throwable e) { throw Debug.handle(e); } diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.truffle.test/sl/TestCompilationThreshold.sl --- a/graal/com.oracle.graal.truffle.test/sl/TestCompilationThreshold.sl Thu Oct 01 14:21:08 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,19 +0,0 @@ -/* - * This test verifies the compilation threshold property. - */ -function test() { -} - -function main() { - /* TODO disableSplitting is required because otherwise it needs more calls to warm up. This still needs to be fixed. */ - disableSplitting(test); - threshold = getOption("TruffleCompilationThreshold"); - i = 0; - while (i < threshold -1) { - test(); - i = i + 1; - } - assertFalse(isOptimized(waitForOptimization(test))); - test(); // triggers compilation - assertTrue(isOptimized(waitForOptimization(test))); -} diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.truffle.test/sl/TestDeoptInInlinedFunction.output --- a/graal/com.oracle.graal.truffle.test/sl/TestDeoptInInlinedFunction.output Thu Oct 01 14:21:08 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -[deoptimizeWhenCompiled] -[deoptimizeWhenCompiled] diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.truffle.test/sl/TestDeoptInInlinedFunction.sl.disable --- a/graal/com.oracle.graal.truffle.test/sl/TestDeoptInInlinedFunction.sl.disable Thu Oct 01 14:21:08 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -/* - * This tests that simple arithmetic gets inlined. - */ -function add(a, b) { - deoptimizeWhenCompiled(a == 50); - return a + b; -} - - -function test() { - i = 0; - while (i < 100) { - i = add(i, 1); - } - return i; -} - -function main() { - waitForOptimization(callUntilOptimized(test, 1 == 2)); - test(); -} diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.truffle.test/sl/TestInlining.sl --- a/graal/com.oracle.graal.truffle.test/sl/TestInlining.sl Thu Oct 01 14:21:08 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -/* - * This tests that simple arithmetic gets inlined. - */ -function add(a, b) { - return a + b; -} - - -function test() { - i = 0; - while (i < 100) { - i = add(i, 1); - } - return i; -} - -function main() { - waitForOptimization(callUntilOptimized(test)); - assertTrue(isInlined(test, test, add), "add is not inlined"); -} diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.truffle.test/sl/TestInliningMaxCallerSize.sl --- a/graal/com.oracle.graal.truffle.test/sl/TestInliningMaxCallerSize.sl Thu Oct 01 14:21:08 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ -/* - * This test verifies that CallTargets cannot exceed the TruffleInliningMaxCallerSize limit when inlining. - */ -function inlinableFunction() { - generateDummyNodes(getOption("TruffleInliningMaxCallerSize") - 7); -} - -function notInlinableFunction() { - generateDummyNodes(getOption("TruffleInliningMaxCallerSize") - 6); -} - -function test1() { - inlinableFunction(); -} - -function test2() { - notInlinableFunction(); -} - -function main() { - originalMaxCallerSize = getOption("TruffleInliningMaxCallerSize"); - setOption("TruffleInliningMaxCallerSize", 20); - callUntilOptimized(test1); - assertTrue(isInlined(test1, test1, inlinableFunction), "inlinableFunction is not inlined"); - - callUntilOptimized(test2); - assertFalse(isInlined(test2, test2, notInlinableFunction), "notInlinableFunction is inlined"); - setOption("TruffleInliningMaxCallerSize", originalMaxCallerSize); -} diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.truffle.test/sl/TestInliningRecursive1.sl --- a/graal/com.oracle.graal.truffle.test/sl/TestInliningRecursive1.sl Thu Oct 01 14:21:08 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +0,0 @@ -/* - * Test recursive calls do not get inlined and do not crash. - */ -function fib(a) { - if (a == 2 || a == 1) { - return 1; - } - return fib(a-1) + fib(a-2); -} - -function test() { - i = 0; - sum = 0; - while (i < 100) { - sum = sum + fib(7); - i = i + 1; - } - return sum; -} - -function main() { - callUntilOptimized(test); -} diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.truffle.test/sl/TestInliningRecursive2.sl --- a/graal/com.oracle.graal.truffle.test/sl/TestInliningRecursive2.sl Thu Oct 01 14:21:08 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ -/* - * Tests that indirect recursions are not inlined. - */ -function fib(a) { - if (a == 2 || a == 1) { - return 1; - } - return call(fib, a-1) + call(fib, a-2) + call(void, 0); -} - -function call(f, a) { - return f(a); -} - -function void(a) { - return a; -} - -function test() { - i = 0; - sum = 0; - while (i < 100) { - sum = sum + fib(7); - i = i + 1; - } - return sum; -} - -function main() { - callUntilOptimized(test); - assertTrue(isInlined(test, test, fib), "not inlined: test -> fib"); -} diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.truffle.test/sl/TestIsCompilationConstant1.sl --- a/graal/com.oracle.graal.truffle.test/sl/TestIsCompilationConstant1.sl Thu Oct 01 14:21:08 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ - - -function testConstantValue1() { - return isCompilationConstant(42); -} - -function testConstantValue2() { - return isCompilationConstant(21 + 21); -} - -function testConstantSequence() { - 40; - return isCompilationConstant(42); -} - -function testConstantLocalVariable() { - x = 42; - return isCompilationConstant(x); -} - -function testNonConstantAdd() { - return isCompilationConstant(42 + "42"); -} - - -function main() { - callFunctionsWith("testConstant", harnessTrue); - callFunctionsWith("testNonConstant", harnessFalse); -} - -function harnessTrue(testFunction) { - callUntilOptimized(testFunction); - assertTrue(testFunction(), "test function " + testFunction + " is not constant"); -} - - -function harnessFalse(testFunction) { - callUntilOptimized(testFunction); - assertFalse(testFunction(), "test function " + testFunction + " is constant"); -} \ No newline at end of file diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.truffle.test/sl/TestOSR.sl --- a/graal/com.oracle.graal.truffle.test/sl/TestOSR.sl Thu Oct 01 14:21:08 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -function test() { - i = 0; - sum = 0; - while (i < 300000) { - sum = sum + i; - i = i + 1; - } - return sum; -} - -function main() { - test(); -} diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.truffle.test/sl/TestTruffleBoundary01.sl --- a/graal/com.oracle.graal.truffle.test/sl/TestTruffleBoundary01.sl Thu Oct 01 14:21:08 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -/* - * This test verifies that CallTargets cannot exceed the TruffleInliningMaxCallerSize limit when inlining. - */ - -function test1() { - testTruffleBoundary01(); -} -function main() { - callUntilOptimized(test1); - assertTrue(isOptimized(test1), "inlinableFunction must be compiled properly"); -} diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/AssumptionPartialEvaluationTest.java --- a/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/AssumptionPartialEvaluationTest.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/AssumptionPartialEvaluationTest.java Thu Oct 01 14:32:39 2015 -0700 @@ -22,7 +22,9 @@ */ package com.oracle.graal.truffle.test; +import org.junit.After; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; import com.oracle.graal.truffle.OptimizedCallTarget; @@ -40,6 +42,18 @@ return 42; } + @Before + public void before() { + InstrumentationTestMode.set(true); + } + + @Override + @After + public void after() { + super.after(); + InstrumentationTestMode.set(false); + } + @Test public void constantValue() { Assumption assumption = Truffle.getRuntime().createAssumption(); diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/BytecodeInterpreterPartialEvaluationTest.java --- a/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/BytecodeInterpreterPartialEvaluationTest.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/BytecodeInterpreterPartialEvaluationTest.java Thu Oct 01 14:32:39 2015 -0700 @@ -24,7 +24,9 @@ import java.util.Random; +import org.junit.After; import org.junit.Assert; +import org.junit.Before; import org.junit.Ignore; import org.junit.Test; @@ -43,6 +45,18 @@ public class BytecodeInterpreterPartialEvaluationTest extends PartialEvaluationTest { + @Before + public void before() { + InstrumentationTestMode.set(true); + } + + @Override + @After + public void after() { + super.after(); + InstrumentationTestMode.set(false); + } + public static class Bytecode { public static final byte CONST = 0; public static final byte RETURN = 1; diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/CompilerAssertsTest.java --- a/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/CompilerAssertsTest.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/CompilerAssertsTest.java Thu Oct 01 14:32:39 2015 -0700 @@ -24,7 +24,9 @@ import jdk.internal.jvmci.code.BailoutException; +import org.junit.After; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; import com.oracle.graal.truffle.test.nodes.AbstractTestNode; @@ -47,6 +49,18 @@ } + @Before + public void before() { + InstrumentationTestMode.set(true); + } + + @Override + @After + public void after() { + super.after(); + InstrumentationTestMode.set(false); + } + public static class CompilationConstantTestNode extends AbstractTestNode { @Child private AbstractTestNode child; diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/ControlFlowExceptionPartialEvaluationTest.java --- a/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/ControlFlowExceptionPartialEvaluationTest.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/ControlFlowExceptionPartialEvaluationTest.java Thu Oct 01 14:32:39 2015 -0700 @@ -22,7 +22,9 @@ */ package com.oracle.graal.truffle.test; +import org.junit.After; import org.junit.Assume; +import org.junit.Before; import org.junit.Test; import com.oracle.graal.truffle.TruffleCompilerOptions; @@ -42,6 +44,18 @@ return 42; } + @Before + public void before() { + InstrumentationTestMode.set(true); + } + + @Override + @After + public void after() { + super.after(); + InstrumentationTestMode.set(false); + } + @Test public void catchControlFlowException() { FrameDescriptor fd = new FrameDescriptor(); diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/InstrumentationPartialEvaluationTest.java --- a/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/InstrumentationPartialEvaluationTest.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/InstrumentationPartialEvaluationTest.java Thu Oct 01 14:32:39 2015 -0700 @@ -22,26 +22,6 @@ */ package com.oracle.graal.truffle.test; -import org.junit.Assert; -import org.junit.Test; - -import com.oracle.graal.truffle.test.nodes.AbstractTestNode; -import com.oracle.graal.truffle.test.nodes.ConstantTestNode; -import com.oracle.graal.truffle.test.nodes.RootTestNode; -import com.oracle.truffle.api.RootCallTarget; -import com.oracle.truffle.api.Truffle; -import com.oracle.truffle.api.frame.FrameDescriptor; -import com.oracle.truffle.api.frame.VirtualFrame; -import com.oracle.truffle.api.instrument.ASTProber; -import com.oracle.truffle.api.instrument.AdvancedInstrumentRoot; -import com.oracle.truffle.api.instrument.AdvancedInstrumentRootFactory; -import com.oracle.truffle.api.instrument.Instrument; -import com.oracle.truffle.api.instrument.Probe; -import com.oracle.truffle.api.instrument.impl.DefaultSimpleInstrumentListener; -import com.oracle.truffle.api.instrument.impl.DefaultStandardInstrumentListener; -import com.oracle.truffle.api.nodes.Node; -import com.oracle.truffle.api.nodes.NodeVisitor; - /** * Tests for a single simple PE test with various combinations of instrumentation attached. None of * the instrumentation ultimate does anything, so should compile away. @@ -52,332 +32,353 @@ return 42; } - @Test - public void constantValueUninstrumented() { - FrameDescriptor fd = new FrameDescriptor(); - AbstractTestNode result = new ConstantTestNode(42); - RootTestNode root = new RootTestNode(fd, "constantValue", result); - root.adoptChildren(); - assertPartialEvalEquals("constant42", root); - } - - @Test - public void constantValueProbedNoInstruments() { - FrameDescriptor fd = new FrameDescriptor(); - AbstractTestNode result = new ConstantTestNode(42); - RootTestNode root = new RootTestNode(fd, "constantValue", result); - root.adoptChildren(); - result.probe(); - assertPartialEvalEquals("constant42", root); - } - - @Test - public void constantValueProbedNullInstrument1() { - FrameDescriptor fd = new FrameDescriptor(); - AbstractTestNode result = new ConstantTestNode(42); - RootTestNode root = new RootTestNode(fd, "constantValue", result); - root.adoptChildren(); - Probe probe = result.probe(); - Instrument instrument = Instrument.create(new DefaultSimpleInstrumentListener(), "Null test Instrument"); - probe.attach(instrument); - assertPartialEvalEquals("constant42", root); - } - - @Test - public void constantValueProbedNullInstrument2() { - FrameDescriptor fd = new FrameDescriptor(); - AbstractTestNode result = new ConstantTestNode(42); - RootTestNode root = new RootTestNode(fd, "constantValue", result); - root.adoptChildren(); - Probe probe = result.probe(); - Instrument instrument = Instrument.create(new DefaultStandardInstrumentListener(), "Null test Instrument"); - probe.attach(instrument); - assertPartialEvalEquals("constant42", root); - } - - @Test - public void constantValueProbedNullInstrumentDisposed1() { - FrameDescriptor fd = new FrameDescriptor(); - AbstractTestNode result = new ConstantTestNode(42); - RootTestNode root = new RootTestNode(fd, "constantValue", result); - root.adoptChildren(); - Probe probe = result.probe(); - Instrument instrument = Instrument.create(new DefaultSimpleInstrumentListener(), "Null test Instrument"); - probe.attach(instrument); - instrument.dispose(); - assertPartialEvalEquals("constant42", root); - } - - @Test - public void constantValueProbedNullInstrumentDisposed2() { - FrameDescriptor fd = new FrameDescriptor(); - AbstractTestNode result = new ConstantTestNode(42); - RootTestNode root = new RootTestNode(fd, "constantValue", result); - root.adoptChildren(); - Probe probe = result.probe(); - Instrument instrument = Instrument.create(new DefaultStandardInstrumentListener(), "Null test Instrument"); - probe.attach(instrument); - instrument.dispose(); - assertPartialEvalEquals("constant42", root); - } - - @Test - public void constantValueProbedTwoNullInstruments1() { - FrameDescriptor fd = new FrameDescriptor(); - AbstractTestNode result = new ConstantTestNode(42); - RootTestNode root = new RootTestNode(fd, "constantValue", result); - root.adoptChildren(); - Probe probe = result.probe(); - Instrument instrument1 = Instrument.create(new DefaultSimpleInstrumentListener(), "Null test Instrument 1"); - probe.attach(instrument1); - Instrument instrument2 = Instrument.create(new DefaultSimpleInstrumentListener(), "Null test Instrument 2"); - probe.attach(instrument2); - assertPartialEvalEquals("constant42", root); - } - - @Test - public void constantValueProbedTwoNullInstruments2() { - FrameDescriptor fd = new FrameDescriptor(); - AbstractTestNode result = new ConstantTestNode(42); - RootTestNode root = new RootTestNode(fd, "constantValue", result); - root.adoptChildren(); - Probe probe = result.probe(); - Instrument instrument1 = Instrument.create(new DefaultStandardInstrumentListener(), "Null test Instrument 1"); - probe.attach(instrument1); - Instrument instrument2 = Instrument.create(new DefaultStandardInstrumentListener(), "Null test Instrument 2"); - probe.attach(instrument2); - assertPartialEvalEquals("constant42", root); - } - - @Test - public void constantValueProbedThreeNullInstruments1() { - FrameDescriptor fd = new FrameDescriptor(); - AbstractTestNode result = new ConstantTestNode(42); - RootTestNode root = new RootTestNode(fd, "constantValue", result); - root.adoptChildren(); - Probe probe = result.probe(); - Instrument instrument1 = Instrument.create(new DefaultSimpleInstrumentListener(), "Null test Instrument 1"); - probe.attach(instrument1); - Instrument instrument2 = Instrument.create(new DefaultSimpleInstrumentListener(), "Null test Instrument 2"); - probe.attach(instrument2); - Instrument instrument3 = Instrument.create(new DefaultSimpleInstrumentListener(), "Null test Instrument 3"); - probe.attach(instrument3); - assertPartialEvalEquals("constant42", root); - } - - @Test - public void constantValueProbedThreeNullInstruments2() { - FrameDescriptor fd = new FrameDescriptor(); - AbstractTestNode result = new ConstantTestNode(42); - RootTestNode root = new RootTestNode(fd, "constantValue", result); - root.adoptChildren(); - Probe probe = result.probe(); - Instrument instrument1 = Instrument.create(new DefaultStandardInstrumentListener(), "Null test Instrument 1"); - probe.attach(instrument1); - Instrument instrument2 = Instrument.create(new DefaultStandardInstrumentListener(), "Null test Instrument 2"); - probe.attach(instrument2); - Instrument instrument3 = Instrument.create(new DefaultStandardInstrumentListener(), "Null test Instrument 3"); - probe.attach(instrument3); - assertPartialEvalEquals("constant42", root); - } - - @Test - public void constantValueProbedThreeNullInstrumentsOneDisposed1() { - FrameDescriptor fd = new FrameDescriptor(); - AbstractTestNode result = new ConstantTestNode(42); - RootTestNode root = new RootTestNode(fd, "constantValue", result); - root.adoptChildren(); - Probe probe = result.probe(); - Instrument instrument1 = Instrument.create(new DefaultSimpleInstrumentListener(), "Null test Instrument 1"); - probe.attach(instrument1); - Instrument instrument2 = Instrument.create(new DefaultSimpleInstrumentListener(), "Null test Instrument 2"); - probe.attach(instrument2); - Instrument instrument3 = Instrument.create(new DefaultSimpleInstrumentListener(), "Null test Instrument 3"); - probe.attach(instrument3); - instrument2.dispose(); - assertPartialEvalEquals("constant42", root); - } - - @Test - public void constantValueProbedThreeNullInstrumentsOneDisposed2() { - FrameDescriptor fd = new FrameDescriptor(); - AbstractTestNode result = new ConstantTestNode(42); - RootTestNode root = new RootTestNode(fd, "constantValue", result); - root.adoptChildren(); - Probe probe = result.probe(); - Instrument instrument1 = Instrument.create(new DefaultStandardInstrumentListener(), "Null test Instrument 1"); - probe.attach(instrument1); - Instrument instrument2 = Instrument.create(new DefaultStandardInstrumentListener(), "Null test Instrument 2"); - probe.attach(instrument2); - Instrument instrument3 = Instrument.create(new DefaultStandardInstrumentListener(), "Null test Instrument 3"); - probe.attach(instrument3); - instrument2.dispose(); - assertPartialEvalEquals("constant42", root); - } - - @Test - public void constantValueInertAdvancedInstrumentRootFactory() { - FrameDescriptor fd = new FrameDescriptor(); - AbstractTestNode result = new ConstantTestNode(42); - RootTestNode root = new RootTestNode(fd, "constantValue", result); - root.adoptChildren(); - Probe testProbe = result.probe(); - // A factory that could insert a AdvancedInstrumentRoot into the AST, but which never does. - Instrument instrument = Instrument.create(null, new AdvancedInstrumentRootFactory() { - - public AdvancedInstrumentRoot createInstrumentRoot(Probe probe, Node node) { - return null; - } - }, null, "test AdvancedInstrument"); - testProbe.attach(instrument); - - // It all gets compiled away - assertPartialEvalEquals("constant42", root); - } - - @Test - public void constantValueInertAdvancedInstrumentRoot() { - FrameDescriptor fd = new FrameDescriptor(); - AbstractTestNode resultTestNode = new ConstantTestNode(42); - RootTestNode rootTestNode = new RootTestNode(fd, "constantValue", resultTestNode); - rootTestNode.adoptChildren(); - Probe testProbe = resultTestNode.probe(); - // Factory inserts a AdvancedInstrumentRoot with empty methods into instrumentation . - Instrument instrument = Instrument.create(null, new AdvancedInstrumentRootFactory() { - - @Override - public AdvancedInstrumentRoot createInstrumentRoot(Probe probe, Node node) { - return new AdvancedInstrumentRoot() { - - public String instrumentationInfo() { - return null; - } - - @Override - public Object executeRoot(Node n, VirtualFrame frame) { - return null; - } - }; - } - }, null, "test AdvancedInstrument"); - testProbe.attach(instrument); - - // It all gets compiled away. - assertPartialEvalEquals("constant42", rootTestNode); - } - - @Test - public void instrumentDeopt() { - final FrameDescriptor fd = new FrameDescriptor(); - final AbstractTestNode result = new ConstantTestNode(42); - final RootTestNode root = new RootTestNode(fd, "constantValue", result); - final Probe[] probe = new Probe[1]; - final int[] count = {1}; - count[0] = 0; - // Register a "prober" that will get applied when CallTarget gets created. - final ASTProber prober = new ASTProber() { - - @Override - public void probeAST(Node node) { - node.accept(new NodeVisitor() { - - @Override - public boolean visit(Node visitedNode) { - if (visitedNode instanceof ConstantTestNode) { - probe[0] = visitedNode.probe(); - } - return true; - } - - }); - } - }; - Probe.registerASTProber(prober); - try { - final RootCallTarget callTarget = Truffle.getRuntime().createCallTarget(root); - - // The CallTarget has one Probe, attached to the ConstantTestNode, ready to run - Assert.assertEquals(42, callTarget.call()); // Correct result - Assert.assertEquals(0, count[0]); // Didn't count anything - - // Add a counting instrument; this changes the "Probe state" and should cause a deopt - final Instrument countingInstrument = Instrument.create(new DefaultSimpleInstrumentListener() { - - @Override - public void enter(Probe p) { - count[0] = count[0] + 1; - } - }, null); - probe[0].attach(countingInstrument); - - Assert.assertEquals(42, callTarget.call()); // Correct result - Assert.assertEquals(1, count[0]); // Counted the first call - - // Remove the counting instrument; this changes the "Probe state" and should cause a - // deopt - countingInstrument.dispose(); - - Assert.assertEquals(42, callTarget.call()); // Correct result - Assert.assertEquals(1, count[0]); // Didn't count this time - } finally { - Probe.unregisterASTProber(prober); - } - - } - - /** - * Experimental feature; not yet validated. - */ - @Test - public void specialOptInstrument() { - final FrameDescriptor fd = new FrameDescriptor(); - final AbstractTestNode result = new ConstantTestNode(42); - final RootTestNode root = new RootTestNode(fd, "constantValue", result); - final Probe[] probe = new Probe[1]; - final int[] count = {1}; - count[0] = 0; - // Register a "prober" that will get applied when CallTarget gets created. - final ASTProber prober = new ASTProber() { - - @Override - public void probeAST(Node node) { - node.accept(new NodeVisitor() { - - @Override - public boolean visit(Node visitedNode) { - if (visitedNode instanceof ConstantTestNode) { - probe[0] = visitedNode.probe(); - } - return true; - } - }); - } - }; - Probe.registerASTProber(prober); - try { - final RootCallTarget callTarget = Truffle.getRuntime().createCallTarget(root); - - // The CallTarget has one Probe, attached to the ConstantTestNode, ready to run - Assert.assertEquals(42, callTarget.call()); // Correct result - - final boolean[] isCurrentlyCompiled = {false}; - final Instrument optInstrument = Instrument.create(new Instrument.TruffleOptListener() { - - @Override - public void notifyIsCompiled(boolean isCompiled) { - isCurrentlyCompiled[0] = isCompiled; - } - }); - probe[0].attach(optInstrument); - - Assert.assertEquals(42, callTarget.call()); // Correct result - Assert.assertFalse(isCurrentlyCompiled[0]); - - // TODO (mlvdv) compile, call again, and assert that isCurrentlyCompiled == true - - } finally { - Probe.unregisterASTProber(prober); - } - - } + // @Test + // public void constantValueUninstrumented() { + // FrameDescriptor fd = new FrameDescriptor(); + // AbstractTestNode result = new ConstantTestNode(42); + // RootTestNode root = new RootTestNode(fd, "constantValue", result); + // root.adoptChildren(); + // assertPartialEvalEquals("constant42", root); + // } + // + // @Test + // public void constantValueProbedNoInstruments() { + // FrameDescriptor fd = new FrameDescriptor(); + // AbstractTestNode result = new ConstantTestNode(42); + // RootTestNode root = new RootTestNode(fd, "constantValue", result); + // root.adoptChildren(); + // result.probe(); + // assertPartialEvalEquals("constant42", root); + // } + // + // @Test + // public void constantValueProbedNullInstrument1() { + // FrameDescriptor fd = new FrameDescriptor(); + // AbstractTestNode result = new ConstantTestNode(42); + // RootTestNode root = new RootTestNode(fd, "constantValue", result); + // root.adoptChildren(); + // Probe probe = result.probe(); + // Instrument instrument = Instrument.create(new DefaultSimpleInstrumentListener(), + // "Null test Instrument"); + // probe.attach(instrument); + // assertPartialEvalEquals("constant42", root); + // } + // + // @Test + // public void constantValueProbedNullInstrument2() { + // FrameDescriptor fd = new FrameDescriptor(); + // AbstractTestNode result = new ConstantTestNode(42); + // RootTestNode root = new RootTestNode(fd, "constantValue", result); + // root.adoptChildren(); + // Probe probe = result.probe(); + // Instrument instrument = Instrument.create(new DefaultStandardInstrumentListener(), + // "Null test Instrument"); + // probe.attach(instrument); + // assertPartialEvalEquals("constant42", root); + // } + // + // @Test + // public void constantValueProbedNullInstrumentDisposed1() { + // FrameDescriptor fd = new FrameDescriptor(); + // AbstractTestNode result = new ConstantTestNode(42); + // RootTestNode root = new RootTestNode(fd, "constantValue", result); + // root.adoptChildren(); + // Probe probe = result.probe(); + // Instrument instrument = Instrument.create(new DefaultSimpleInstrumentListener(), + // "Null test Instrument"); + // probe.attach(instrument); + // instrument.dispose(); + // assertPartialEvalEquals("constant42", root); + // } + // + // @Test + // public void constantValueProbedNullInstrumentDisposed2() { + // FrameDescriptor fd = new FrameDescriptor(); + // AbstractTestNode result = new ConstantTestNode(42); + // RootTestNode root = new RootTestNode(fd, "constantValue", result); + // root.adoptChildren(); + // Probe probe = result.probe(); + // Instrument instrument = Instrument.create(new DefaultStandardInstrumentListener(), + // "Null test Instrument"); + // probe.attach(instrument); + // instrument.dispose(); + // assertPartialEvalEquals("constant42", root); + // } + // + // @Test + // public void constantValueProbedTwoNullInstruments1() { + // FrameDescriptor fd = new FrameDescriptor(); + // AbstractTestNode result = new ConstantTestNode(42); + // RootTestNode root = new RootTestNode(fd, "constantValue", result); + // root.adoptChildren(); + // Probe probe = result.probe(); + // Instrument instrument1 = Instrument.create(new DefaultSimpleInstrumentListener(), + // "Null test Instrument 1"); + // probe.attach(instrument1); + // Instrument instrument2 = Instrument.create(new DefaultSimpleInstrumentListener(), + // "Null test Instrument 2"); + // probe.attach(instrument2); + // assertPartialEvalEquals("constant42", root); + // } + // + // @Test + // public void constantValueProbedTwoNullInstruments2() { + // FrameDescriptor fd = new FrameDescriptor(); + // AbstractTestNode result = new ConstantTestNode(42); + // RootTestNode root = new RootTestNode(fd, "constantValue", result); + // root.adoptChildren(); + // Probe probe = result.probe(); + // Instrument instrument1 = Instrument.create(new DefaultStandardInstrumentListener(), + // "Null test Instrument 1"); + // probe.attach(instrument1); + // Instrument instrument2 = Instrument.create(new DefaultStandardInstrumentListener(), + // "Null test Instrument 2"); + // probe.attach(instrument2); + // assertPartialEvalEquals("constant42", root); + // } + // + // @Test + // public void constantValueProbedThreeNullInstruments1() { + // FrameDescriptor fd = new FrameDescriptor(); + // AbstractTestNode result = new ConstantTestNode(42); + // RootTestNode root = new RootTestNode(fd, "constantValue", result); + // root.adoptChildren(); + // Probe probe = result.probe(); + // Instrument instrument1 = Instrument.create(new DefaultSimpleInstrumentListener(), + // "Null test Instrument 1"); + // probe.attach(instrument1); + // Instrument instrument2 = Instrument.create(new DefaultSimpleInstrumentListener(), + // "Null test Instrument 2"); + // probe.attach(instrument2); + // Instrument instrument3 = Instrument.create(new DefaultSimpleInstrumentListener(), + // "Null test Instrument 3"); + // probe.attach(instrument3); + // assertPartialEvalEquals("constant42", root); + // } + // + // @Test + // public void constantValueProbedThreeNullInstruments2() { + // FrameDescriptor fd = new FrameDescriptor(); + // AbstractTestNode result = new ConstantTestNode(42); + // RootTestNode root = new RootTestNode(fd, "constantValue", result); + // root.adoptChildren(); + // Probe probe = result.probe(); + // Instrument instrument1 = Instrument.create(new DefaultStandardInstrumentListener(), + // "Null test Instrument 1"); + // probe.attach(instrument1); + // Instrument instrument2 = Instrument.create(new DefaultStandardInstrumentListener(), + // "Null test Instrument 2"); + // probe.attach(instrument2); + // Instrument instrument3 = Instrument.create(new DefaultStandardInstrumentListener(), + // "Null test Instrument 3"); + // probe.attach(instrument3); + // assertPartialEvalEquals("constant42", root); + // } + // + // @Test + // public void constantValueProbedThreeNullInstrumentsOneDisposed1() { + // FrameDescriptor fd = new FrameDescriptor(); + // AbstractTestNode result = new ConstantTestNode(42); + // RootTestNode root = new RootTestNode(fd, "constantValue", result); + // root.adoptChildren(); + // Probe probe = result.probe(); + // Instrument instrument1 = Instrument.create(new DefaultSimpleInstrumentListener(), + // "Null test Instrument 1"); + // probe.attach(instrument1); + // Instrument instrument2 = Instrument.create(new DefaultSimpleInstrumentListener(), + // "Null test Instrument 2"); + // probe.attach(instrument2); + // Instrument instrument3 = Instrument.create(new DefaultSimpleInstrumentListener(), + // "Null test Instrument 3"); + // probe.attach(instrument3); + // instrument2.dispose(); + // assertPartialEvalEquals("constant42", root); + // } + // + // @Test + // public void constantValueProbedThreeNullInstrumentsOneDisposed2() { + // FrameDescriptor fd = new FrameDescriptor(); + // AbstractTestNode result = new ConstantTestNode(42); + // RootTestNode root = new RootTestNode(fd, "constantValue", result); + // root.adoptChildren(); + // Probe probe = result.probe(); + // Instrument instrument1 = Instrument.create(new DefaultStandardInstrumentListener(), + // "Null test Instrument 1"); + // probe.attach(instrument1); + // Instrument instrument2 = Instrument.create(new DefaultStandardInstrumentListener(), + // "Null test Instrument 2"); + // probe.attach(instrument2); + // Instrument instrument3 = Instrument.create(new DefaultStandardInstrumentListener(), + // "Null test Instrument 3"); + // probe.attach(instrument3); + // instrument2.dispose(); + // assertPartialEvalEquals("constant42", root); + // } + // + // @Test + // public void constantValueInertAdvancedInstrumentRootFactory() { + // FrameDescriptor fd = new FrameDescriptor(); + // AbstractTestNode result = new ConstantTestNode(42); + // RootTestNode root = new RootTestNode(fd, "constantValue", result); + // root.adoptChildren(); + // Probe testProbe = result.probe(); + // // A factory that could insert a AdvancedInstrumentRoot into the AST, but which never does. + // Instrument instrument = Instrument.create(null, new AdvancedInstrumentRootFactory() { + // + // public AdvancedInstrumentRoot createInstrumentRoot(Probe probe, Node node) { + // return null; + // } + // }, null, "test AdvancedInstrument"); + // testProbe.attach(instrument); + // + // // It all gets compiled away + // assertPartialEvalEquals("constant42", root); + // } + // + // @Test + // public void constantValueInertAdvancedInstrumentRoot() { + // FrameDescriptor fd = new FrameDescriptor(); + // AbstractTestNode resultTestNode = new ConstantTestNode(42); + // RootTestNode rootTestNode = new RootTestNode(fd, "constantValue", resultTestNode); + // rootTestNode.adoptChildren(); + // Probe testProbe = resultTestNode.probe(); + // // Factory inserts a AdvancedInstrumentRoot with empty methods into instrumentation . + // Instrument instrument = Instrument.create(null, new AdvancedInstrumentRootFactory() { + // + // @Override + // public AdvancedInstrumentRoot createInstrumentRoot(Probe probe, Node node) { + // return new AdvancedInstrumentRoot() { + // + // public String instrumentationInfo() { + // return null; + // } + // + // @Override + // public Object executeRoot(Node n, VirtualFrame frame) { + // return null; + // } + // }; + // } + // }, null, "test AdvancedInstrument"); + // testProbe.attach(instrument); + // + // // It all gets compiled away. + // assertPartialEvalEquals("constant42", rootTestNode); + // } + // + // @Test + // public void instrumentDeopt() { + // final FrameDescriptor fd = new FrameDescriptor(); + // final AbstractTestNode result = new ConstantTestNode(42); + // final RootTestNode root = new RootTestNode(fd, "constantValue", result); + // final Probe[] probe = new Probe[1]; + // final int[] count = {1}; + // count[0] = 0; + // // Register a "prober" that will get applied when CallTarget gets created. + // final ASTProber prober = new ASTProber() { + // + // @Override + // public void probeAST(Node node) { + // node.accept(new NodeVisitor() { + // + // @Override + // public boolean visit(Node visitedNode) { + // if (visitedNode instanceof ConstantTestNode) { + // probe[0] = visitedNode.probe(); + // } + // return true; + // } + // + // }); + // } + // }; + // Probe.registerASTProber(prober); + // try { + // final RootCallTarget callTarget = Truffle.getRuntime().createCallTarget(root); + // + // // The CallTarget has one Probe, attached to the ConstantTestNode, ready to run + // Assert.assertEquals(42, callTarget.call()); // Correct result + // Assert.assertEquals(0, count[0]); // Didn't count anything + // + // // Add a counting instrument; this changes the "Probe state" and should cause a deopt + // final Instrument countingInstrument = Instrument.create(new DefaultSimpleInstrumentListener() + // { + // + // @Override + // public void enter(Probe p) { + // count[0] = count[0] + 1; + // } + // }, null); + // probe[0].attach(countingInstrument); + // + // Assert.assertEquals(42, callTarget.call()); // Correct result + // Assert.assertEquals(1, count[0]); // Counted the first call + // + // // Remove the counting instrument; this changes the "Probe state" and should cause a + // // deopt + // countingInstrument.dispose(); + // + // Assert.assertEquals(42, callTarget.call()); // Correct result + // Assert.assertEquals(1, count[0]); // Didn't count this time + // } finally { + // Probe.unregisterASTProber(prober); + // } + // + // } + // + // /** + // * Experimental feature; not yet validated. + // */ + // @Test + // public void specialOptInstrument() { + // final FrameDescriptor fd = new FrameDescriptor(); + // final AbstractTestNode result = new ConstantTestNode(42); + // final RootTestNode root = new RootTestNode(fd, "constantValue", result); + // final Probe[] probe = new Probe[1]; + // final int[] count = {1}; + // count[0] = 0; + // // Register a "prober" that will get applied when CallTarget gets created. + // final ASTProber prober = new ASTProber() { + // + // @Override + // public void probeAST(Node node) { + // node.accept(new NodeVisitor() { + // + // @Override + // public boolean visit(Node visitedNode) { + // if (visitedNode instanceof ConstantTestNode) { + // probe[0] = visitedNode.probe(); + // } + // return true; + // } + // }); + // } + // }; + // Probe.registerASTProber(prober); + // try { + // final RootCallTarget callTarget = Truffle.getRuntime().createCallTarget(root); + // + // // The CallTarget has one Probe, attached to the ConstantTestNode, ready to run + // Assert.assertEquals(42, callTarget.call()); // Correct result + // + // final boolean[] isCurrentlyCompiled = {false}; + // final Instrument optInstrument = Instrument.create(new Instrument.TruffleOptListener() { + // + // @Override + // public void notifyIsCompiled(boolean isCompiled) { + // isCurrentlyCompiled[0] = isCompiled; + // } + // }); + // probe[0].attach(optInstrument); + // + // Assert.assertEquals(42, callTarget.call()); // Correct result + // Assert.assertFalse(isCurrentlyCompiled[0]); + // + // // TODO (mlvdv) compile, call again, and assert that isCurrentlyCompiled == true + // + // } finally { + // Probe.unregisterASTProber(prober); + // } + // + // } } diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/InstrumentationTestMode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/InstrumentationTestMode.java Thu Oct 01 14:32:39 2015 -0700 @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2015, 2015, 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.truffle.test; + +import static org.junit.Assert.fail; + +import java.lang.reflect.Field; + +import com.oracle.truffle.api.instrument.Instrumenter; +import com.oracle.truffle.api.vm.PolyglotEngine; + +public class InstrumentationTestMode { + + public static void set(boolean enable) { + + try { + final PolyglotEngine vm = PolyglotEngine.buildNew().build(); + final Field instrumenterField = vm.getClass().getDeclaredField("instrumenter"); + instrumenterField.setAccessible(true); + final Object instrumenter = instrumenterField.get(vm); + final java.lang.reflect.Field testVMField = Instrumenter.class.getDeclaredField("testVM"); + testVMField.setAccessible(true); + if (enable) { + testVMField.set(instrumenter, vm); + } else { + testVMField.set(instrumenter, null); + } + } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException ex) { + fail("Reflective access to Instrumenter for testing"); + } + + } +} diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/ReadOnlyArrayListPartialEvaluationTest.java --- a/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/ReadOnlyArrayListPartialEvaluationTest.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/ReadOnlyArrayListPartialEvaluationTest.java Thu Oct 01 14:32:39 2015 -0700 @@ -22,6 +22,8 @@ */ package com.oracle.graal.truffle.test; +import org.junit.After; +import org.junit.Before; import org.junit.Test; import com.oracle.graal.truffle.test.nodes.AbstractTestNode; @@ -35,6 +37,18 @@ return 42; } + @Before + public void before() { + InstrumentationTestMode.set(true); + } + + @Override + @After + public void after() { + super.after(); + InstrumentationTestMode.set(false); + } + @Test public void constantValue() { FrameDescriptor fd = new FrameDescriptor(); diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/SLTruffleGraalTestSuite.java --- a/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/SLTruffleGraalTestSuite.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/SLTruffleGraalTestSuite.java Thu Oct 01 14:32:39 2015 -0700 @@ -42,7 +42,7 @@ import com.oracle.truffle.sl.test.SLTestSuite; @RunWith(SLTestRunner.class) -@SLTestSuite({"graal/com.oracle.graal.truffle.test/sl", "sl"}) +@SLTestSuite({"sl"}) public class SLTruffleGraalTestSuite { public static void main(String[] args) throws Exception { diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/SimplePartialEvaluationTest.java --- a/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/SimplePartialEvaluationTest.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/SimplePartialEvaluationTest.java Thu Oct 01 14:32:39 2015 -0700 @@ -25,7 +25,9 @@ import jdk.internal.jvmci.code.BailoutException; import jdk.internal.jvmci.code.SourceStackTrace; +import org.junit.After; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; import com.oracle.graal.replacements.PEGraphDecoder; @@ -54,6 +56,18 @@ return 42; } + @Before + public void before() { + InstrumentationTestMode.set(true); + } + + @Override + @After + public void after() { + super.after(); + InstrumentationTestMode.set(false); + } + @Test public void constantValue() { FrameDescriptor fd = new FrameDescriptor(); diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/TruffleDirectCallNodeTest.java --- a/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/TruffleDirectCallNodeTest.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/TruffleDirectCallNodeTest.java Thu Oct 01 14:32:39 2015 -0700 @@ -24,6 +24,8 @@ import static org.junit.Assert.assertTrue; +import org.junit.After; +import org.junit.Before; import org.junit.Test; import com.oracle.truffle.api.CallTarget; @@ -34,6 +36,16 @@ public class TruffleDirectCallNodeTest { + @Before + public void before() { + InstrumentationTestMode.set(true); + } + + @After + public void after() { + InstrumentationTestMode.set(false); + } + @Test public void testCanBeClonedWithoutParent() { final RootNode rootNode = new RootNode(MockLanguage.class, null, null) { diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/TruffleEnsureVirtualizedTest.java --- a/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/TruffleEnsureVirtualizedTest.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/TruffleEnsureVirtualizedTest.java Thu Oct 01 14:32:39 2015 -0700 @@ -24,7 +24,9 @@ import jdk.internal.jvmci.code.BailoutException; +import org.junit.After; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; import com.oracle.graal.api.directives.GraalDirectives; @@ -63,6 +65,18 @@ public static boolean booleanField; public static Object field; + @Before + public void before() { + InstrumentationTestMode.set(true); + } + + @Override + @After + public void after() { + super.after(); + InstrumentationTestMode.set(false); + } + @Test public void test1() { testEnsureVirtualized(false, new TestNode() { diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/nodes/AbstractTestNode.java --- a/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/nodes/AbstractTestNode.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/nodes/AbstractTestNode.java Thu Oct 01 14:32:39 2015 -0700 @@ -23,7 +23,6 @@ package com.oracle.graal.truffle.test.nodes; import com.oracle.truffle.api.frame.VirtualFrame; -import com.oracle.truffle.api.instrument.ProbeNode.WrapperNode; import com.oracle.truffle.api.nodes.Node; public abstract class AbstractTestNode extends Node { @@ -32,15 +31,5 @@ super(null); } - @Override - public boolean isInstrumentable() { - return true; - } - - @Override - public WrapperNode createWrapperNode() { - return new WrapperTestNode(this); - } - public abstract int execute(VirtualFrame frame); } diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/nodes/RootTestNode.java --- a/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/nodes/RootTestNode.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/nodes/RootTestNode.java Thu Oct 01 14:32:39 2015 -0700 @@ -25,7 +25,6 @@ import com.oracle.graal.truffle.test.MockLanguage; import com.oracle.truffle.api.frame.FrameDescriptor; import com.oracle.truffle.api.frame.VirtualFrame; -import com.oracle.truffle.api.instrument.Probe; import com.oracle.truffle.api.nodes.NodeInfo; import com.oracle.truffle.api.nodes.RootNode; @@ -47,11 +46,6 @@ } @Override - public void applyInstrumentation() { - Probe.applyASTProbers(node); - } - - @Override public String toString() { return name; } diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/nodes/WrapperTestNode.java --- a/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/nodes/WrapperTestNode.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/nodes/WrapperTestNode.java Thu Oct 01 14:32:39 2015 -0700 @@ -23,10 +23,10 @@ package com.oracle.graal.truffle.test.nodes; import com.oracle.truffle.api.frame.VirtualFrame; +import com.oracle.truffle.api.instrument.EventHandlerNode; import com.oracle.truffle.api.instrument.KillException; import com.oracle.truffle.api.instrument.Probe; -import com.oracle.truffle.api.instrument.ProbeNode; -import com.oracle.truffle.api.instrument.ProbeNode.WrapperNode; +import com.oracle.truffle.api.instrument.WrapperNode; import com.oracle.truffle.api.nodes.Node; /** @@ -35,7 +35,7 @@ public final class WrapperTestNode extends AbstractTestNode implements WrapperNode { @Child private AbstractTestNode child; - @Child private ProbeNode probeNode; + @Child private EventHandlerNode eventHandlerNode; public WrapperTestNode(AbstractTestNode child) { this.child = child; @@ -46,16 +46,12 @@ } @Override - public boolean isInstrumentable() { - return false; - } - - public void insertProbe(ProbeNode newProbeNode) { - this.probeNode = newProbeNode; + public void insertEventHandlerNode(EventHandlerNode eventHandler) { + this.eventHandlerNode = eventHandler; } public Probe getProbe() { - return probeNode.getProbe(); + return eventHandlerNode.getProbe(); } @Override @@ -65,15 +61,15 @@ @Override public int execute(VirtualFrame frame) { - probeNode.enter(child, frame); + eventHandlerNode.enter(child, frame); try { final int result = child.execute(frame); - probeNode.returnValue(child, frame, result); + eventHandlerNode.returnValue(child, frame, result); return result; } catch (KillException e) { throw (e); } catch (Exception e) { - probeNode.returnExceptional(child, frame, e); + eventHandlerNode.returnExceptional(child, frame, e); throw (e); } diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.truffle.test/src/sl/TestCompilationThreshold.sl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.truffle.test/src/sl/TestCompilationThreshold.sl Thu Oct 01 14:32:39 2015 -0700 @@ -0,0 +1,19 @@ +/* + * This test verifies the compilation threshold property. + */ +function test() { +} + +function main() { + /* TODO disableSplitting is required because otherwise it needs more calls to warm up. This still needs to be fixed. */ + disableSplitting(test); + threshold = getOption("TruffleCompilationThreshold"); + i = 0; + while (i < threshold -1) { + test(); + i = i + 1; + } + assertFalse(isOptimized(waitForOptimization(test))); + test(); // triggers compilation + assertTrue(isOptimized(waitForOptimization(test))); +} diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.truffle.test/src/sl/TestDeoptInInlinedFunction.output --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.truffle.test/src/sl/TestDeoptInInlinedFunction.output Thu Oct 01 14:32:39 2015 -0700 @@ -0,0 +1,2 @@ +[deoptimizeWhenCompiled] +[deoptimizeWhenCompiled] diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.truffle.test/src/sl/TestDeoptInInlinedFunction.sl.disable --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.truffle.test/src/sl/TestDeoptInInlinedFunction.sl.disable Thu Oct 01 14:32:39 2015 -0700 @@ -0,0 +1,21 @@ +/* + * This tests that simple arithmetic gets inlined. + */ +function add(a, b) { + deoptimizeWhenCompiled(a == 50); + return a + b; +} + + +function test() { + i = 0; + while (i < 100) { + i = add(i, 1); + } + return i; +} + +function main() { + waitForOptimization(callUntilOptimized(test, 1 == 2)); + test(); +} diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.truffle.test/src/sl/TestInlining.sl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.truffle.test/src/sl/TestInlining.sl Thu Oct 01 14:32:39 2015 -0700 @@ -0,0 +1,20 @@ +/* + * This tests that simple arithmetic gets inlined. + */ +function add(a, b) { + return a + b; +} + + +function test() { + i = 0; + while (i < 100) { + i = add(i, 1); + } + return i; +} + +function main() { + waitForOptimization(callUntilOptimized(test)); + assertTrue(isInlined(test, test, add), "add is not inlined"); +} diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.truffle.test/src/sl/TestInliningMaxCallerSize.sl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.truffle.test/src/sl/TestInliningMaxCallerSize.sl Thu Oct 01 14:32:39 2015 -0700 @@ -0,0 +1,29 @@ +/* + * This test verifies that CallTargets cannot exceed the TruffleInliningMaxCallerSize limit when inlining. + */ +function inlinableFunction() { + generateDummyNodes(getOption("TruffleInliningMaxCallerSize") - 7); +} + +function notInlinableFunction() { + generateDummyNodes(getOption("TruffleInliningMaxCallerSize") - 6); +} + +function test1() { + inlinableFunction(); +} + +function test2() { + notInlinableFunction(); +} + +function main() { + originalMaxCallerSize = getOption("TruffleInliningMaxCallerSize"); + setOption("TruffleInliningMaxCallerSize", 20); + callUntilOptimized(test1); + assertTrue(isInlined(test1, test1, inlinableFunction), "inlinableFunction is not inlined"); + + callUntilOptimized(test2); + assertFalse(isInlined(test2, test2, notInlinableFunction), "notInlinableFunction is inlined"); + setOption("TruffleInliningMaxCallerSize", originalMaxCallerSize); +} diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.truffle.test/src/sl/TestInliningRecursive1.sl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.truffle.test/src/sl/TestInliningRecursive1.sl Thu Oct 01 14:32:39 2015 -0700 @@ -0,0 +1,23 @@ +/* + * Test recursive calls do not get inlined and do not crash. + */ +function fib(a) { + if (a == 2 || a == 1) { + return 1; + } + return fib(a-1) + fib(a-2); +} + +function test() { + i = 0; + sum = 0; + while (i < 100) { + sum = sum + fib(7); + i = i + 1; + } + return sum; +} + +function main() { + callUntilOptimized(test); +} diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.truffle.test/src/sl/TestInliningRecursive2.sl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.truffle.test/src/sl/TestInliningRecursive2.sl Thu Oct 01 14:32:39 2015 -0700 @@ -0,0 +1,32 @@ +/* + * Tests that indirect recursions are not inlined. + */ +function fib(a) { + if (a == 2 || a == 1) { + return 1; + } + return call(fib, a-1) + call(fib, a-2) + call(void, 0); +} + +function call(f, a) { + return f(a); +} + +function void(a) { + return a; +} + +function test() { + i = 0; + sum = 0; + while (i < 100) { + sum = sum + fib(7); + i = i + 1; + } + return sum; +} + +function main() { + callUntilOptimized(test); + assertTrue(isInlined(test, test, fib), "not inlined: test -> fib"); +} diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.truffle.test/src/sl/TestIsCompilationConstant1.sl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.truffle.test/src/sl/TestIsCompilationConstant1.sl Thu Oct 01 14:32:39 2015 -0700 @@ -0,0 +1,40 @@ + + +function testConstantValue1() { + return isCompilationConstant(42); +} + +function testConstantValue2() { + return isCompilationConstant(21 + 21); +} + +function testConstantSequence() { + 40; + return isCompilationConstant(42); +} + +function testConstantLocalVariable() { + x = 42; + return isCompilationConstant(x); +} + +function testNonConstantAdd() { + return isCompilationConstant(42 + "42"); +} + + +function main() { + callFunctionsWith("testConstant", harnessTrue); + callFunctionsWith("testNonConstant", harnessFalse); +} + +function harnessTrue(testFunction) { + callUntilOptimized(testFunction); + assertTrue(testFunction(), "test function " + testFunction + " is not constant"); +} + + +function harnessFalse(testFunction) { + callUntilOptimized(testFunction); + assertFalse(testFunction(), "test function " + testFunction + " is constant"); +} \ No newline at end of file diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.truffle.test/src/sl/TestOSR.sl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.truffle.test/src/sl/TestOSR.sl Thu Oct 01 14:32:39 2015 -0700 @@ -0,0 +1,13 @@ +function test() { + i = 0; + sum = 0; + while (i < 300000) { + sum = sum + i; + i = i + 1; + } + return sum; +} + +function main() { + test(); +} diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.truffle.test/src/sl/TestTruffleBoundary01.sl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.truffle.test/src/sl/TestTruffleBoundary01.sl Thu Oct 01 14:32:39 2015 -0700 @@ -0,0 +1,11 @@ +/* + * This test verifies that CallTargets cannot exceed the TruffleInliningMaxCallerSize limit when inlining. + */ + +function test1() { + testTruffleBoundary01(); +} +function main() { + callUntilOptimized(test1); + assertTrue(isOptimized(test1), "inlinableFunction must be compiled properly"); +} diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/GraalTruffleRuntime.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/GraalTruffleRuntime.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/GraalTruffleRuntime.java Thu Oct 01 14:32:39 2015 -0700 @@ -39,7 +39,6 @@ import jdk.internal.jvmci.meta.ResolvedJavaMethod; import jdk.internal.jvmci.service.Services; -import com.oracle.graal.api.runtime.Graal; import com.oracle.graal.debug.Debug; import com.oracle.graal.debug.Debug.Scope; import com.oracle.graal.debug.TTY; @@ -76,16 +75,12 @@ private ArrayList includes; private ArrayList excludes; - private StackIntrospection stackIntrospection; - protected ResolvedJavaMethod[] callNodeMethod; - protected ResolvedJavaMethod[] callTargetMethod; - protected ResolvedJavaMethod[] anyFrameMethod; - private final List compilationListeners = new ArrayList<>(); private final GraalTruffleCompilationListener compilationNotify = new DispatchTruffleCompilationListener(); protected TruffleCompiler truffleCompiler; protected LoopNodeFactory loopNodeFactory; + protected CallMethods callMethods; public GraalTruffleRuntime() { Runtime.getRuntime().addShutdownHook(new Thread(this::shutdown)); @@ -127,9 +122,7 @@ } protected void lookupCallMethods(MetaAccessProvider metaAccess) { - callNodeMethod = new ResolvedJavaMethod[]{metaAccess.lookupJavaMethod(GraalFrameInstance.CallNodeFrame.METHOD)}; - callTargetMethod = new ResolvedJavaMethod[]{metaAccess.lookupJavaMethod(GraalFrameInstance.CallTargetFrame.METHOD)}; - anyFrameMethod = new ResolvedJavaMethod[]{callNodeMethod[0], callTargetMethod[0]}; + callMethods = CallMethods.lookup(metaAccess); } @Override @@ -202,36 +195,32 @@ @TruffleBoundary @Override public T iterateFrames(FrameInstanceVisitor visitor) { - initStackIntrospection(); + StackIntrospection stackIntrospection = getStackIntrospection(); InspectedFrameVisitor inspectedFrameVisitor = new InspectedFrameVisitor() { private boolean skipNext = false; public T visitFrame(InspectedFrame frame) { if (skipNext) { - assert frame.isMethod(callTargetMethod[0]); + assert frame.isMethod(getCallMethods().callTargetMethod[0]); skipNext = false; return null; } - if (frame.isMethod(callNodeMethod[0])) { + if (frame.isMethod(getCallMethods().callNodeMethod[0])) { skipNext = true; return visitor.visitFrame(new GraalFrameInstance.CallNodeFrame(frame)); } else { - assert frame.isMethod(callTargetMethod[0]); + assert frame.isMethod(getCallMethods().callTargetMethod[0]); return visitor.visitFrame(new GraalFrameInstance.CallTargetFrame(frame, false)); } } }; - return stackIntrospection.iterateFrames(anyFrameMethod, anyFrameMethod, 1, inspectedFrameVisitor); + return stackIntrospection.iterateFrames(getCallMethods().anyFrameMethod, getCallMethods().anyFrameMethod, 1, inspectedFrameVisitor); } - private void initStackIntrospection() { - if (stackIntrospection == null) { - stackIntrospection = Graal.getRequiredCapability(StackIntrospection.class); - } - } + protected abstract StackIntrospection getStackIntrospection(); @Override public FrameInstance getCallerFrame() { @@ -241,9 +230,7 @@ @TruffleBoundary @Override public FrameInstance getCurrentFrame() { - initStackIntrospection(); - - return stackIntrospection.iterateFrames(callTargetMethod, callTargetMethod, 0, frame -> new GraalFrameInstance.CallTargetFrame(frame, true)); + return getStackIntrospection().iterateFrames(getCallMethods().callTargetMethod, getCallMethods().callTargetMethod, 0, frame -> new GraalFrameInstance.CallTargetFrame(frame, true)); } public T getCapability(Class capability) { @@ -337,6 +324,10 @@ protected abstract boolean platformEnableInfopoints(); + protected CallMethods getCallMethods() { + return callMethods; + } + private final class DispatchTruffleCompilationListener implements GraalTruffleCompilationListener { public void notifyCompilationQueued(OptimizedCallTarget target) { @@ -384,4 +375,20 @@ } } + + protected static final class CallMethods { + protected final ResolvedJavaMethod[] callNodeMethod; + protected final ResolvedJavaMethod[] callTargetMethod; + protected final ResolvedJavaMethod[] anyFrameMethod; + + private CallMethods(MetaAccessProvider metaAccess) { + this.callNodeMethod = new ResolvedJavaMethod[]{metaAccess.lookupJavaMethod(GraalFrameInstance.CallNodeFrame.METHOD)}; + this.callTargetMethod = new ResolvedJavaMethod[]{metaAccess.lookupJavaMethod(GraalFrameInstance.CallTargetFrame.METHOD)}; + this.anyFrameMethod = new ResolvedJavaMethod[]{callNodeMethod[0], callTargetMethod[0]}; + } + + public static CallMethods lookup(MetaAccessProvider metaAccess) { + return new CallMethods(metaAccess); + } + } } diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompiler.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompiler.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompiler.java Thu Oct 01 14:32:39 2015 -0700 @@ -215,7 +215,7 @@ InstalledCode installedCode; try (Scope s = Debug.scope("CodeInstall", providers.getCodeCache()); DebugCloseable a = CodeInstallationTime.start(); DebugCloseable c = CodeInstallationMemUse.start()) { - installedCode = providers.getCodeCache().addMethod(graph.method(), result, graph.getSpeculationLog(), predefinedInstalledCode); + installedCode = providers.getCodeCache().addCode(graph.method(), result, graph.getSpeculationLog(), predefinedInstalledCode); } catch (Throwable e) { throw Debug.handle(e); } diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleConstantReflectionProvider.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleConstantReflectionProvider.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleConstantReflectionProvider.java Thu Oct 01 14:32:39 2015 -0700 @@ -120,6 +120,10 @@ return graalConstantReflection.forString(value); } + public JavaConstant forObject(Object value) { + return graalConstantReflection.forObject(value); + } + public ResolvedJavaType asJavaType(Constant constant) { return graalConstantReflection.asJavaType(constant); } diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/substitutions/TruffleGraphBuilderPlugins.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/substitutions/TruffleGraphBuilderPlugins.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/substitutions/TruffleGraphBuilderPlugins.java Thu Oct 01 14:32:39 2015 -0700 @@ -256,6 +256,18 @@ return true; } }); + r.register1("isPartialEvaluationConstant", Object.class, new InvocationPlugin() { + public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) { + if ((value instanceof BoxNode ? ((BoxNode) value).getValue() : value).isConstant()) { + b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(true)); + } else if (canDelayIntrinsification) { + return false; + } else { + b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(false)); + } + return true; + } + }); r.register1("materialize", Object.class, new InvocationPlugin() { public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) { b.add(new ForceMaterializeNode(value)); diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/PartialEscapeClosure.java --- a/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/PartialEscapeClosure.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/PartialEscapeClosure.java Thu Oct 01 14:32:39 2015 -0700 @@ -22,6 +22,8 @@ */ package com.oracle.graal.virtual.phases.ea; +import static com.oracle.graal.compiler.common.GraalOptions.UseGraalQueries; + import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; @@ -71,6 +73,7 @@ import com.oracle.graal.nodes.spi.VirtualizableAllocation; import com.oracle.graal.nodes.spi.VirtualizerTool; import com.oracle.graal.nodes.virtual.VirtualObjectNode; +import com.oracle.graal.phases.common.query.nodes.InstrumentationNode; import com.oracle.graal.phases.schedule.SchedulePhase; public abstract class PartialEscapeClosure> extends EffectsClosure { @@ -187,6 +190,10 @@ return true; } } + if (UseGraalQueries.getValue() && (node instanceof InstrumentationNode)) { + // ignore inputs for InstrumentationNode + return false; + } processNodeInputs((ValueNode) node, nextFixedNode, state, effects); } diff -r a19722cd3dd2 -r dfb01e333fc5 graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/PartialEscapePhase.java --- a/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/PartialEscapePhase.java Thu Oct 01 14:21:08 2015 -0700 +++ b/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/PartialEscapePhase.java Thu Oct 01 14:32:39 2015 -0700 @@ -24,7 +24,6 @@ import static com.oracle.graal.compiler.common.GraalOptions.EscapeAnalysisIterations; import static com.oracle.graal.compiler.common.GraalOptions.EscapeAnalyzeOnly; -import static com.oracle.graal.virtual.phases.ea.PartialEscapePhase.Options.OptEarlyReadElimination; import java.util.Set; @@ -55,11 +54,11 @@ private final BasePhase cleanupPhase; public PartialEscapePhase(boolean iterative, CanonicalizerPhase canonicalizer) { - this(iterative, OptEarlyReadElimination.getValue(), canonicalizer, null); + this(iterative, Options.OptEarlyReadElimination.getValue(), canonicalizer, null); } public PartialEscapePhase(boolean iterative, CanonicalizerPhase canonicalizer, BasePhase cleanupPhase) { - this(iterative, OptEarlyReadElimination.getValue(), canonicalizer, cleanupPhase); + this(iterative, Options.OptEarlyReadElimination.getValue(), canonicalizer, cleanupPhase); } public PartialEscapePhase(boolean iterative, boolean readElimination, CanonicalizerPhase canonicalizer, BasePhase cleanupPhase) { diff -r a19722cd3dd2 -r dfb01e333fc5 mx.graal/suite.py --- a/mx.graal/suite.py Thu Oct 01 14:21:08 2015 -0700 +++ b/mx.graal/suite.py Thu Oct 01 14:32:39 2015 -0700 @@ -6,7 +6,7 @@ "suites": [ { "name" : "jvmci", - "version" : "111882d99400aae882d0a8caebb53733646ded8b", + "version" : "c33f0cb02b34763c55dafa5589dca932e91d3b71", "urls" : [ {"url" : "http://lafo.ssw.uni-linz.ac.at/hg/graal-jvmci-8", "kind" : "hg"}, {"url" : "https://curio.ssw.jku.at/nexus/content/repositories/snapshots", "kind" : "binary"}, @@ -14,7 +14,7 @@ }, { "name" : "truffle", - "version" : "09d91119929f4246837ddbe911ddcb18d744efd0", + "version" : "371045b1312d412bafa29882e6c3f7bfe6c0f8f1", "urls" : [ {"url" : "http://lafo.ssw.uni-linz.ac.at/hg/truffle", "kind" : "hg"}, {"url" : "https://curio.ssw.jku.at/nexus/content/repositories/snapshots", "kind" : "binary"},