# HG changeset patch # User Thomas Wuerthinger # Date 1397568157 -7200 # Node ID dbb1fe8348e6cb63432d59010f067459038ef5eb # Parent 2c940b1a48d8d61e82973695545d4ac077157afe Allow to supply predefined installed code object when adding a method to the code cache. diff -r 2c940b1a48d8 -r dbb1fe8348e6 graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CodeCacheProvider.java --- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CodeCacheProvider.java Tue Apr 15 15:01:40 2014 +0200 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CodeCacheProvider.java Tue Apr 15 15:22:37 2014 +0200 @@ -34,18 +34,18 @@ /** * Adds the given compilation result as an implementation of the given method without making it * the default implementation. - * + * * @param method a method to which the executable code is begin added * @param compResult the compilation result to be added * @param speculationLog the speculation log to be used * @return a reference to the compiled and ready-to-run code or null if the code installation * failed */ - InstalledCode addMethod(ResolvedJavaMethod method, CompilationResult compResult, SpeculationLog speculationLog); + InstalledCode addMethod(ResolvedJavaMethod method, CompilationResult compResult, SpeculationLog speculationLog, InstalledCode predefinedInstalledCode); /** * Sets the given compilation result as the default implementation of the given method. - * + * * @param method a method to which the executable code is begin added * @param compResult the compilation result to be added * @return a reference to the compiled and ready-to-run code or null if the code installation @@ -55,11 +55,11 @@ /** * Returns a disassembly of some compiled code. - * + * * @param compResult some compiled code * @param installedCode the result of installing the code in {@code compResult} or null if the * code has not yet been installed - * + * * @return a disassembly. This will be of length 0 if the runtime does not support * disassembling. */ @@ -73,7 +73,7 @@ /** * Minimum size of the stack area reserved for outgoing parameters. This area is reserved in all * cases, even when the compiled method has no regular call instructions. - * + * * @return the minimum size of the outgoing parameter area in bytes */ int getMinimumOutgoingSize(); diff -r 2c940b1a48d8 -r dbb1fe8348e6 graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/InstalledCode.java --- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/InstalledCode.java Tue Apr 15 15:01:40 2014 +0200 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/InstalledCode.java Tue Apr 15 15:22:37 2014 +0200 @@ -26,7 +26,7 @@ * Represents a compiled instance of a method. It may have been invalidated or removed in the * meantime. */ -public abstract class InstalledCode { +public class InstalledCode { /** * Raw address of this code blob. @@ -77,6 +77,7 @@ * @param args the array of object arguments * @return the value returned by the executed code */ + @SuppressWarnings("unused") public Object executeVarargs(Object... args) throws InvalidInstalledCodeException { return null; } diff -r 2c940b1a48d8 -r dbb1fe8348e6 graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/package-info.java --- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/package-info.java Tue Apr 15 15:01:40 2014 +0200 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/package-info.java Tue Apr 15 15:22:37 2014 +0200 @@ -23,7 +23,7 @@ /** * Package that defines the interface between a Java application that wants to install code and the runtime. * The runtime provides in implementation of the {@link com.oracle.graal.api.code.CodeCacheProvider} interface. - * The method {@link com.oracle.graal.api.code.CodeCacheProvider#addMethod(com.oracle.graal.api.meta.ResolvedJavaMethod, CompilationResult, SpeculationLog)} + * The method {@link com.oracle.graal.api.code.CodeCacheProvider#addMethod(com.oracle.graal.api.meta.ResolvedJavaMethod, CompilationResult, SpeculationLog, InstalledCode)} * can be used to install code for a given method. */ package com.oracle.graal.api.code; diff -r 2c940b1a48d8 -r dbb1fe8348e6 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 Tue Apr 15 15:01:40 2014 +0200 +++ b/graal/com.oracle.graal.asm.test/src/com/oracle/graal/asm/test/AssemblerTest.java Tue Apr 15 15:22:37 2014 +0200 @@ -61,7 +61,7 @@ byte[] targetCode = test.generateCode(compResult, codeCache.getTarget(), registerConfig, cc); compResult.setTargetCode(targetCode, targetCode.length); - InstalledCode code = codeCache.addMethod(method, compResult, null); + InstalledCode code = codeCache.addMethod(method, compResult, null, null); DisassemblerProvider dis = Graal.getRequiredCapability(RuntimeProvider.class).getHostBackend().getDisassembler(); if (dis != null) { diff -r 2c940b1a48d8 -r dbb1fe8348e6 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 Tue Apr 15 15:01:40 2014 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java Tue Apr 15 15:22:37 2014 +0200 @@ -675,7 +675,7 @@ } protected InstalledCode addMethod(final ResolvedJavaMethod method, final CompilationResult compResult) { - return getCodeCache().addMethod(method, compResult, null); + return getCodeCache().addMethod(method, compResult, null, null); } /** diff -r 2c940b1a48d8 -r dbb1fe8348e6 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 Tue Apr 15 15:01:40 2014 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java Tue Apr 15 15:22:37 2014 +0200 @@ -312,7 +312,7 @@ } try (TimerCloseable b = CodeInstallationTime.start()) { - installedCode = installMethod(result); + installedCode = (HotSpotInstalledCode) installMethod(result); if (!isOSR) { ProfilingInfo profile = method.getProfilingInfo(); profile.setCompilerIRSize(StructuredGraph.class, graph.getNodeCount()); @@ -385,9 +385,9 @@ MetaUtil.format("%H::%n(%p)", method), isOSR ? "@ " + entryBCI + " " : "", method.getCodeSize())); } - private HotSpotInstalledCode installMethod(final CompilationResult compResult) { + private InstalledCode installMethod(final CompilationResult compResult) { final HotSpotCodeCacheProvider codeCache = backend.getProviders().getCodeCache(); - HotSpotInstalledCode installedCode = null; + InstalledCode installedCode = null; try (Scope s = Debug.scope("CodeInstall", new DebugDumpScope(String.valueOf(id), true), codeCache, method)) { installedCode = codeCache.installMethod(method, compResult); } catch (Throwable e) { diff -r 2c940b1a48d8 -r dbb1fe8348e6 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotCodeCacheProvider.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotCodeCacheProvider.java Tue Apr 15 15:01:40 2014 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotCodeCacheProvider.java Tue Apr 15 15:22:37 2014 +0200 @@ -196,7 +196,7 @@ return runtime.getConfig().runtimeCallStackSize; } - public HotSpotInstalledCode logOrDump(HotSpotInstalledCode installedCode, CompilationResult compResult) { + public InstalledCode logOrDump(InstalledCode installedCode, CompilationResult compResult) { if (Debug.isDumpEnabled()) { Debug.dump(new Object[]{compResult, installedCode}, "After code installation"); } @@ -206,7 +206,7 @@ return installedCode; } - public HotSpotInstalledCode installMethod(HotSpotResolvedJavaMethod method, CompilationResult compResult) { + public InstalledCode installMethod(HotSpotResolvedJavaMethod method, CompilationResult compResult) { if (compResult.getId() == -1) { compResult.setId(method.allocateCompileId(compResult.getEntryBCI())); } @@ -216,17 +216,21 @@ } @Override - public InstalledCode addMethod(ResolvedJavaMethod method, CompilationResult compResult, SpeculationLog log) { + public InstalledCode addMethod(ResolvedJavaMethod method, CompilationResult compResult, SpeculationLog log, InstalledCode predefinedInstalledCode) { HotSpotResolvedJavaMethod hotspotMethod = (HotSpotResolvedJavaMethod) method; if (compResult.getId() == -1) { compResult.setId(hotspotMethod.allocateCompileId(compResult.getEntryBCI())); } - HotSpotInstalledCode code = new HotSpotNmethod(hotspotMethod, compResult.getName(), false); - CodeInstallResult result = runtime.getCompilerToVM().installCode(new HotSpotCompiledNmethod(target, hotspotMethod, compResult), code, log); + InstalledCode installedCode = predefinedInstalledCode; + if (installedCode == null) { + HotSpotInstalledCode code = new HotSpotNmethod(hotspotMethod, compResult.getName(), false); + installedCode = code; + } + CodeInstallResult result = runtime.getCompilerToVM().installCode(new HotSpotCompiledNmethod(target, hotspotMethod, compResult), installedCode, log); if (result != CodeInstallResult.OK) { return null; } - return logOrDump(code, compResult); + return logOrDump(installedCode, compResult); } @Override diff -r 2c940b1a48d8 -r dbb1fe8348e6 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nfi/HotSpotNativeFunctionInterface.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nfi/HotSpotNativeFunctionInterface.java Tue Apr 15 15:01:40 2014 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nfi/HotSpotNativeFunctionInterface.java Tue Apr 15 15:22:37 2014 +0200 @@ -161,7 +161,7 @@ DefaultProfilingInfo.get(TriState.UNKNOWN), null, suites, new CompilationResult(), CompilationResultBuilderFactory.Default); InstalledCode installedCode; try (Scope s = Debug.scope("CodeInstall", providers.getCodeCache(), g.method())) { - installedCode = providers.getCodeCache().addMethod(g.method(), compResult, null); + installedCode = providers.getCodeCache().addMethod(g.method(), compResult, null, null); } return installedCode; } diff -r 2c940b1a48d8 -r dbb1fe8348e6 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 Tue Apr 15 15:01:40 2014 +0200 +++ b/graal/com.oracle.graal.truffle.hotspot.amd64/src/com/oracle/graal/truffle/hotspot/amd64/AMD64OptimizedCallTargetInstrumentationFactory.java Tue Apr 15 15:22:37 2014 +0200 @@ -65,7 +65,7 @@ asm.cmpq(spillRegister, 0); asm.jcc(ConditionFlag.Equal, doProlog); - AMD64Address codeBlobAddress = new AMD64Address(spillRegister, getFieldOffset("codeBlob", HotSpotInstalledCode.class)); + AMD64Address codeBlobAddress = new AMD64Address(spillRegister, getFieldOffset("address", InstalledCode.class)); asm.movq(spillRegister, codeBlobAddress); asm.cmpq(spillRegister, 0); asm.jcc(ConditionFlag.Equal, doProlog); diff -r 2c940b1a48d8 -r dbb1fe8348e6 graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotOptimizedCallTarget.java --- a/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotOptimizedCallTarget.java Tue Apr 15 15:01:40 2014 +0200 +++ b/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotOptimizedCallTarget.java Tue Apr 15 15:22:37 2014 +0200 @@ -63,21 +63,13 @@ } private Object callHelper(Object[] args) { - if (installedCode != null && installedCode.isValid()) { + if (installedCode.isValid()) { reinstallCallMethodShortcut(); } if (TruffleCallTargetProfiling.getValue()) { callCount++; } - if (CompilerDirectives.injectBranchProbability(CompilerDirectives.FASTPATH_PROBABILITY, installedCode != null)) { - try { - return installedCode.executeVarargs(new Object[]{this, args}); - } catch (InvalidInstalledCodeException ex) { - return compiledCodeInvalidated(args); - } - } else { - return interpreterCall(args); - } + return interpreterCall(args); } private static void reinstallCallMethodShortcut() { @@ -119,11 +111,10 @@ compilationProfile.reportInterpreterCall(); if (compilationEnabled && compilationPolicy.shouldCompile(compilationProfile)) { - InstalledCode code = compile(); - if (code != null && code.isValid()) { - this.installedCode = code; + compile(); + if (installedCode.isValid()) { try { - return code.executeVarargs(new Object[]{this, args}); + return installedCode.executeVarargs(new Object[]{this, args}); } catch (InvalidInstalledCodeException ex) { return compiledCodeInvalidated(args); } @@ -145,20 +136,14 @@ } @Override - public InstalledCode compile() { - if (isCompiling()) { - if (installedCodeTask.isDone()) { - return receiveInstalledCode(); - } - return null; - } else { + public void compile() { + if (!isCompiling()) { performInlining(); logOptimizingQueued(this); this.installedCodeTask = compiler.compile(this); if (!TruffleBackgroundCompilation.getValue()) { - return receiveInstalledCode(); + receiveInstalledCode(); } - return null; } } diff -r 2c940b1a48d8 -r dbb1fe8348e6 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/PartialEvaluationTest.java --- a/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/PartialEvaluationTest.java Tue Apr 15 15:01:40 2014 +0200 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/PartialEvaluationTest.java Tue Apr 15 15:22:37 2014 +0200 @@ -64,7 +64,7 @@ protected InstalledCode assertPartialEvalEquals(String methodName, RootNode root, Object[] arguments) { Assumptions assumptions = new Assumptions(true); StructuredGraph actual = partialEval(root, arguments, assumptions, true); - InstalledCode result = truffleCompiler.compileMethodHelper(actual, assumptions, root.toString(), getSpeculationLog()); + InstalledCode result = truffleCompiler.compileMethodHelper(actual, assumptions, root.toString(), getSpeculationLog(), null); StructuredGraph expected = parseForComparison(methodName); removeFrameStates(actual); Assert.assertEquals(getCanonicalGraphString(expected, true, true), getCanonicalGraphString(actual, true, true)); diff -r 2c940b1a48d8 -r dbb1fe8348e6 graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java Tue Apr 15 15:01:40 2014 +0200 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java Tue Apr 15 15:22:37 2014 +0200 @@ -53,6 +53,7 @@ public OptimizedCallTarget(RootNode rootNode, int invokeCounter, int compilationThreshold, boolean compilationEnabled, CompilationPolicy compilationPolicy) { super(rootNode); + this.installedCode = new InstalledCode(); this.compilationEnabled = compilationEnabled; this.compilationPolicy = compilationPolicy; this.compilationProfile = new CompilationProfile(compilationThreshold, invokeCounter, rootNode.toString()); @@ -84,7 +85,7 @@ @Override public String toString() { String superString = super.toString(); - if (installedCode != null) { + if (installedCode.isValid()) { superString += " "; } if (splitSource != null) { @@ -100,7 +101,7 @@ @Override public abstract Object call(Object... args); - public abstract InstalledCode compile(); + public abstract void compile(); public final Object callInlined(Object[] arguments) { if (CompilerDirectives.inInterpreter()) { diff -r 2c940b1a48d8 -r dbb1fe8348e6 graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerImpl.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerImpl.java Tue Apr 15 15:01:40 2014 +0200 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerImpl.java Tue Apr 15 15:22:37 2014 +0200 @@ -151,18 +151,14 @@ long timePartialEvaluationFinished = System.nanoTime(); int nodeCountPartialEval = graph.getNodeCount(); - InstalledCode compiledMethod = compileMethodHelper(graph, assumptions, compilable.toString(), compilable.getSpeculationLog()); + InstalledCode compiledMethod = compileMethodHelper(graph, assumptions, compilable.toString(), compilable.getSpeculationLog(), null); long timeCompilationFinished = System.nanoTime(); int nodeCountLowered = graph.getNodeCount(); - if (compiledMethod == null) { + if (!compiledMethod.isValid()) { throw new BailoutException("Could not install method, code cache is full!"); } - if (!compiledMethod.isValid()) { - return null; - } - if (TraceTruffleCompilation.getValue()) { byte[] code = compiledMethod.getCode(); int calls = OptimizedCallUtils.countCalls(compilable); @@ -188,7 +184,7 @@ return sourceSection != null ? sourceSection.toString() : "n/a"; } - public InstalledCode compileMethodHelper(StructuredGraph graph, Assumptions assumptions, String name, SpeculationLog speculationLog) { + public InstalledCode compileMethodHelper(StructuredGraph graph, Assumptions assumptions, String name, SpeculationLog speculationLog, InstalledCode predefinedInstalledCode) { try (Scope s = Debug.scope("TruffleFinal")) { Debug.dump(graph, "After TruffleTier"); } catch (Throwable e) { @@ -224,7 +220,7 @@ InstalledCode installedCode; try (Scope s = Debug.scope("CodeInstall", providers.getCodeCache()); TimerCloseable a = CodeInstallationTime.start()) { - installedCode = providers.getCodeCache().addMethod(graph.method(), result, speculationLog); + installedCode = providers.getCodeCache().addMethod(graph.method(), result, speculationLog, predefinedInstalledCode); } catch (Throwable e) { throw Debug.handle(e); }