# HG changeset patch # User Doug Simon # Date 1443531303 -7200 # Node ID b415eaae0aa9a466ab974815d51b720306b4c447 # Parent f8a090c89bf47cd86f7297c2338331e5c7391687 expanded CodeCacheProvider so that it supports all forms of code installation and made CompilerToVM.installCode package-private diff -r f8a090c89bf4 -r b415eaae0aa9 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 Mon Sep 28 21:23:34 2015 +0200 +++ b/graal/com.oracle.graal.asm.test/src/com/oracle/graal/asm/test/AssemblerTest.java Tue Sep 29 14:55:03 2015 +0200 @@ -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 f8a090c89bf4 -r b415eaae0aa9 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 Mon Sep 28 21:23:34 2015 +0200 +++ b/graal/com.oracle.graal.code/src/com/oracle/graal/code/DisassemblerProvider.java Tue Sep 29 14:55:03 2015 +0200 @@ -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 f8a090c89bf4 -r b415eaae0aa9 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 Mon Sep 28 21:23:34 2015 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerAssumptionsTest.java Tue Sep 29 14:55:03 2015 +0200 @@ -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 f8a090c89bf4 -r b415eaae0aa9 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 Mon Sep 28 21:23:34 2015 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java Tue Sep 29 14:55:03 2015 +0200 @@ -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 f8a090c89bf4 -r b415eaae0aa9 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 Mon Sep 28 21:23:34 2015 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/deopt/MonitorDeoptTest.java Tue Sep 29 14:55:03 2015 +0200 @@ -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 f8a090c89bf4 -r b415eaae0aa9 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 Mon Sep 28 21:23:34 2015 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/tutorial/InvokeGraal.java Tue Sep 29 14:55:03 2015 +0200 @@ -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 f8a090c89bf4 -r b415eaae0aa9 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 Mon Sep 28 21:23:34 2015 +0200 +++ b/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/HotSpotCryptoSubstitutionTest.java Tue Sep 29 14:55:03 2015 +0200 @@ -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 f8a090c89bf4 -r b415eaae0aa9 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 Mon Sep 28 21:23:34 2015 +0200 +++ b/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/MemoryUsageBenchmark.java Tue Sep 29 14:55:03 2015 +0200 @@ -137,13 +137,12 @@ // invalidate any existing compiled code method.reprofile(); - int id = method.allocateCompileId(jdk.internal.jvmci.compiler.Compiler.INVOCATION_ENTRY_BCI); long jvmciEnv = 0L; try (MemoryUsageCloseable c = label == null ? null : new MemoryUsageCloseable(label)) { HotSpotJVMCIRuntimeProvider runtime = HotSpotJVMCIRuntime.runtime(); int entryBCI = Compiler.INVOCATION_ENTRY_BCI; - HotSpotCompilationRequest request = new HotSpotCompilationRequest(method, entryBCI, jvmciEnv, id); + HotSpotCompilationRequest request = new HotSpotCompilationRequest(method, entryBCI, jvmciEnv); CompilationTask task = new CompilationTask(runtime, (HotSpotGraalCompiler) runtime.getCompiler(), request, false); task.runCompilation(); } @@ -157,11 +156,10 @@ // invalidate any existing compiled code method.reprofile(); - int id = method.allocateCompileId(jdk.internal.jvmci.compiler.Compiler.INVOCATION_ENTRY_BCI); long jvmciEnv = 0L; try (AllocSpy as = AllocSpy.open(methodName)) { HotSpotJVMCIRuntimeProvider runtime = HotSpotJVMCIRuntime.runtime(); - HotSpotCompilationRequest request = new HotSpotCompilationRequest(method, Compiler.INVOCATION_ENTRY_BCI, jvmciEnv, id); + HotSpotCompilationRequest request = new HotSpotCompilationRequest(method, Compiler.INVOCATION_ENTRY_BCI, jvmciEnv); CompilationTask task = new CompilationTask(runtime, (HotSpotGraalCompiler) runtime.getCompiler(), request, false); task.runCompilation(); } diff -r f8a090c89bf4 -r b415eaae0aa9 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 Mon Sep 28 21:23:34 2015 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java Tue Sep 29 14:55:03 2015 +0200 @@ -192,10 +192,7 @@ 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 { @@ -218,8 +215,10 @@ } } - 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) { @@ -311,7 +310,7 @@ final HotSpotCodeCacheProvider codeCache = (HotSpotCodeCacheProvider) jvmciRuntime.getHostJVMCIBackend().getCodeCache(); InstalledCode installedCode = null; try (Scope s = Debug.scope("CodeInstall", new DebugDumpScope(String.valueOf(getId()), true), codeCache, getMethod())) { - installedCode = codeCache.installMethod(getMethod(), compResult, request.getJvmciEnv(), installAsDefault); + installedCode = codeCache.installCode(request, compResult, null, request.getMethod().getSpeculationLog(), installAsDefault); } catch (Throwable e) { throw Debug.handle(e); } diff -r f8a090c89bf4 -r b415eaae0aa9 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 Mon Sep 28 21:23:34 2015 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompileTheWorld.java Tue Sep 29 14:55:03 2015 +0200 @@ -295,7 +295,7 @@ HotSpotResolvedJavaMethod dummyMethod = (HotSpotResolvedJavaMethod) JVMCI.getRuntime().getHostJVMCIBackend().getMetaAccess().lookupJavaMethod( CompileTheWorld.class.getDeclaredMethod("dummy")); int entryBCI = Compiler.INVOCATION_ENTRY_BCI; - CompilationTask task = new CompilationTask(jvmciRuntime, compiler, new HotSpotCompilationRequest(dummyMethod, entryBCI, 0L, dummyMethod.allocateCompileId(entryBCI)), false); + CompilationTask task = new CompilationTask(jvmciRuntime, compiler, new HotSpotCompilationRequest(dummyMethod, entryBCI, 0L), false); task.runCompilation(); } catch (NoSuchMethodException | SecurityException e1) { e1.printStackTrace(); @@ -486,7 +486,7 @@ long start = System.currentTimeMillis(); long allocatedAtStart = MemUseTrackerImpl.getCurrentThreadAllocatedBytes(); int entryBCI = Compiler.INVOCATION_ENTRY_BCI; - HotSpotCompilationRequest request = new HotSpotCompilationRequest(method, entryBCI, 0L, method.allocateCompileId(entryBCI)); + HotSpotCompilationRequest request = new HotSpotCompilationRequest(method, entryBCI, 0L); CompilationTask task = new CompilationTask(jvmciRuntime, compiler, request, false); task.runCompilation(); diff -r f8a090c89bf4 -r b415eaae0aa9 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 Mon Sep 28 21:23:34 2015 +0200 +++ /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 f8a090c89bf4 -r b415eaae0aa9 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 Mon Sep 28 21:23:34 2015 +0200 +++ /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 f8a090c89bf4 -r b415eaae0aa9 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 Mon Sep 28 21:23:34 2015 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/Stub.java Tue Sep 29 14:55:03 2015 +0200 @@ -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 f8a090c89bf4 -r b415eaae0aa9 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 Mon Sep 28 21:23:34 2015 +0200 +++ b/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotTruffleRuntime.java Tue Sep 29 14:55:03 2015 +0200 @@ -212,7 +212,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); } diff -r f8a090c89bf4 -r b415eaae0aa9 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 Mon Sep 28 21:23:34 2015 +0200 +++ b/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/nfi/HotSpotNativeFunctionInterface.java Tue Sep 29 14:55:03 2015 +0200 @@ -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 f8a090c89bf4 -r b415eaae0aa9 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 Mon Sep 28 21:23:34 2015 +0200 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompiler.java Tue Sep 29 14:55:03 2015 +0200 @@ -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 f8a090c89bf4 -r b415eaae0aa9 mx.graal/suite.py --- a/mx.graal/suite.py Mon Sep 28 21:23:34 2015 +0200 +++ b/mx.graal/suite.py Tue Sep 29 14:55:03 2015 +0200 @@ -6,7 +6,7 @@ "suites": [ { "name" : "jvmci", - "version" : "bec9cd4e731ae36000b5eb0110b849b9775e28d6", + "version" : "545590b1ab83c00b653ec3143ff876a0c42306c4", "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"},