# HG changeset patch # User Matthias Grimmer # Date 1382525218 -7200 # Node ID 7d5c3ffbee6485bf7c553c5c9e11bf644ffa9cd3 # Parent ecd85445f77a7c4a41e362f421d5490f6b7b81f1 Refactoring of the frame prologue injection diff -r ecd85445f77a -r 7d5c3ffbee64 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 Wed Oct 23 12:45:57 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotCodeCacheProvider.java Wed Oct 23 12:46:58 2013 +0200 @@ -174,7 +174,7 @@ return code; } - public InstalledCode addDefaultMethod(ResolvedJavaMethod method, CompilationResult compResult) { + public InstalledCode setDefaultMethod(ResolvedJavaMethod method, CompilationResult compResult) { HotSpotResolvedJavaMethod hotspotMethod = (HotSpotResolvedJavaMethod) method; return installMethod(hotspotMethod, StructuredGraph.INVOCATION_ENTRY_BCI, compResult); } diff -r ecd85445f77a -r 7d5c3ffbee64 graal/com.oracle.graal.truffle.hotspot.amd64/src/com/oracle/graal/truffle/hotspot/amd64/util/OptimizedCallTargetFieldInfo.java --- a/graal/com.oracle.graal.truffle.hotspot.amd64/src/com/oracle/graal/truffle/hotspot/amd64/util/OptimizedCallTargetFieldInfo.java Wed Oct 23 12:45:57 2013 +0200 +++ b/graal/com.oracle.graal.truffle.hotspot.amd64/src/com/oracle/graal/truffle/hotspot/amd64/util/OptimizedCallTargetFieldInfo.java Wed Oct 23 12:46:58 2013 +0200 @@ -38,32 +38,26 @@ public static int getCodeBlobFieldOffset() { if (codeBlobFieldOffset == -1) { - try { - HotSpotInstalledCode.class.getDeclaredField("codeBlob").setAccessible(true); - Field codeBlobField = HotSpotInstalledCode.class.getDeclaredField("codeBlob"); - codeBlobFieldOffset = (int) unsafe.objectFieldOffset(codeBlobField); - } catch (NoSuchFieldException | SecurityException e) { - throw GraalInternalError.shouldNotReachHere(); - } - return codeBlobFieldOffset; - } else { - return codeBlobFieldOffset; + codeBlobFieldOffset = getFieldOffset("codeBlob", HotSpotInstalledCode.class); } + return codeBlobFieldOffset; } public static int getCompiledMethodFieldOffset() { if (compiledMethodFieldOffset == -1) { - try { - OptimizedCallTarget.class.getDeclaredField("compiledMethod").setAccessible(true); - Field compiledMethodField = OptimizedCallTarget.class.getDeclaredField("compiledMethod"); - compiledMethodFieldOffset = (int) unsafe.objectFieldOffset(compiledMethodField); - } catch (NoSuchFieldException | SecurityException e) { - throw GraalInternalError.shouldNotReachHere(); - } - return compiledMethodFieldOffset; - } else { - return compiledMethodFieldOffset; + compiledMethodFieldOffset = getFieldOffset("compiledMethod", OptimizedCallTarget.class); + } + return compiledMethodFieldOffset; + + } + + private static int getFieldOffset(String name, Class container) { + try { + container.getDeclaredField(name).setAccessible(true); + Field field = container.getDeclaredField(name); + return (int) unsafe.objectFieldOffset(field); + } catch (NoSuchFieldException | SecurityException e) { + throw GraalInternalError.shouldNotReachHere(); } } - } diff -r ecd85445f77a -r 7d5c3ffbee64 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 Wed Oct 23 12:45:57 2013 +0200 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/GraalTruffleRuntime.java Wed Oct 23 12:46:58 2013 +0200 @@ -62,16 +62,8 @@ private Replacements truffleReplacements; private ArrayList includes; private ArrayList excludes; - private final CodeCacheProvider codeCacheProvider; - private final ResolvedJavaMethod callMethod; - private final CompilationResult callCompilationResult; private GraalTruffleRuntime() { - Providers providers = getGraalProviders(); - MetaAccessProvider metaAccess = providers.getMetaAccess(); - codeCacheProvider = providers.getCodeCache(); - callMethod = metaAccess.lookupJavaMethod(getCallMethod()); - callCompilationResult = compileMethod(callMethod, providers); installOptimizedCallTargetCallMethod(); } @@ -165,8 +157,11 @@ } } - public void installOptimizedCallTargetCallMethod() { - codeCacheProvider.addDefaultMethod(callMethod, callCompilationResult); + public static void installOptimizedCallTargetCallMethod() { + Providers providers = getGraalProviders(); + MetaAccessProvider metaAccess = providers.getMetaAccess(); + ResolvedJavaMethod resolvedCallMethod = metaAccess.lookupJavaMethod(getCallMethod()); + providers.getCodeCache().setDefaultMethod(resolvedCallMethod, compileMethod(resolvedCallMethod)); } private static Method getCallMethod() { @@ -179,7 +174,8 @@ return method; } - private static CompilationResult compileMethod(ResolvedJavaMethod javaMethod, Providers providers) { + private static CompilationResult compileMethod(ResolvedJavaMethod javaMethod) { + Providers providers = getGraalProviders(); MetaAccessProvider metaAccess = providers.getMetaAccess(); Suites suites = Graal.getRequiredCapability(RuntimeProvider.class).getHostBackend().getSuites().createSuites(); suites.getHighTier().findPhase(InliningPhase.class).remove(); diff -r ecd85445f77a -r 7d5c3ffbee64 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 Wed Oct 23 12:45:57 2013 +0200 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java Wed Oct 23 12:46:58 2013 +0200 @@ -71,16 +71,12 @@ @Override public Object call(PackedFrame caller, Arguments args) { - return callHelper(caller, args); - } - - private Object callHelper(PackedFrame caller, Arguments args) { if (compiledMethod != null && compiledMethod.isValid()) { TruffleRuntime runtime = Truffle.getRuntime(); if (runtime instanceof GraalTruffleRuntime) { OUT.printf("[truffle] reinstall OptimizedCallTarget.call code with frame prolog shortcut."); OUT.println(); - ((GraalTruffleRuntime) runtime).installOptimizedCallTargetCallMethod(); + GraalTruffleRuntime.installOptimizedCallTargetCallMethod(); } } if (TruffleCallTargetProfiling.getValue()) { diff -r ecd85445f77a -r 7d5c3ffbee64 graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/substitutions/OptimizedCallTargetSubstitutions.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/substitutions/OptimizedCallTargetSubstitutions.java Wed Oct 23 12:45:57 2013 +0200 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/substitutions/OptimizedCallTargetSubstitutions.java Wed Oct 23 12:46:58 2013 +0200 @@ -37,9 +37,6 @@ public static native Object call(OptimizedCallTarget target, PackedFrame caller, Arguments args); @MacroSubstitution(macro = NeverInlineMacroNode.class, isStatic = false) - public static native Object callHelper(OptimizedCallTarget target, PackedFrame caller, Arguments args); - - @MacroSubstitution(macro = NeverInlineMacroNode.class, isStatic = false) public static native Object interpreterCall(OptimizedCallTarget target, PackedFrame caller, Arguments args); @MacroSubstitution(macro = NeverInlineMacroNode.class, isStatic = false)