changeset 13630:b1838411e896

Use compile ids assigned by hotspot
author Tom Rodriguez <tom.rodriguez@oracle.com>
date Tue, 14 Jan 2014 10:14:31 -0800
parents 5348da19751d
children 11c46696a655
files graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CompilationResult.java graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/HotSpotCryptoSubstitutionTest.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompileTheWorld.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotCompiledNmethod.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotCodeCacheProvider.java src/share/vm/compiler/compileBroker.hpp src/share/vm/graal/graalCodeInstaller.cpp src/share/vm/graal/graalCompilerToVM.cpp src/share/vm/graal/graalJavaAccess.hpp src/share/vm/prims/jni.cpp
diffstat 14 files changed, 75 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CompilationResult.java	Tue Jan 14 10:14:28 2014 -0800
+++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CompilationResult.java	Tue Jan 14 10:14:31 2014 -0800
@@ -380,6 +380,9 @@
         }
     }
 
+    private int id = -1;
+    private int entryBCI = -1;
+
     private final List<Infopoint> infopoints = new ArrayList<>();
     private final List<DataPatch> dataReferences = new ArrayList<>();
     private final List<ExceptionHandler> exceptionHandlers = new ArrayList<>();
@@ -420,6 +423,34 @@
         this.name = name;
     }
 
+    /**
+     * @return the compile id
+     */
+    public int getId() {
+        return id;
+    }
+
+    /**
+     * @param id the compile id to set
+     */
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    /**
+     * @return the entryBCI
+     */
+    public int getEntryBCI() {
+        return entryBCI;
+    }
+
+    /**
+     * @param entryBCI the entryBCI to set
+     */
+    public void setEntryBCI(int entryBCI) {
+        this.entryBCI = entryBCI;
+    }
+
     public void setAssumptions(Assumptions assumptions) {
         this.assumptions = assumptions;
     }
@@ -527,11 +558,11 @@
      * Records an instruction mark within this method.
      * 
      * @param codePos the position in the code that is covered by the handler
-     * @param id the identifier for this mark
+     * @param markId the identifier for this mark
      * @param references an array of other marks that this mark references
      */
-    public Mark recordMark(int codePos, Object id, Mark[] references) {
-        Mark mark = new Mark(codePos, id, references);
+    public Mark recordMark(int codePos, Object markId, Mark[] references) {
+        Mark mark = new Mark(codePos, markId, references);
         marks.add(mark);
         return mark;
     }
--- a/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/HotSpotCryptoSubstitutionTest.java	Tue Jan 14 10:14:28 2014 -0800
+++ b/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/HotSpotCryptoSubstitutionTest.java	Tue Jan 14 10:14:31 2014 -0800
@@ -49,7 +49,7 @@
     protected InstalledCode addMethod(ResolvedJavaMethod method, CompilationResult compResult) {
         HotSpotResolvedJavaMethod hsMethod = (HotSpotResolvedJavaMethod) method;
         HotSpotNmethod installedCode = new HotSpotNmethod(hsMethod, compResult.getName(), true);
-        HotSpotCompiledNmethod compiledNmethod = new HotSpotCompiledNmethod(hsMethod, StructuredGraph.INVOCATION_ENTRY_BCI, compResult);
+        HotSpotCompiledNmethod compiledNmethod = new HotSpotCompiledNmethod(hsMethod, compResult);
         CodeInstallResult result = runtime().getCompilerToVM().installCode(compiledNmethod, installedCode, null);
         Assert.assertEquals("Error installing method " + method + ": " + result, result, CodeInstallResult.OK);
 
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java	Tue Jan 14 10:14:28 2014 -0800
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java	Tue Jan 14 10:14:31 2014 -0800
@@ -184,7 +184,8 @@
                 OptimisticOptimizations optimisticOpts = getOptimisticOpts(profilingInfo);
                 result = compileGraph(graph, cc, method, providers, backend, backend.getTarget(), graphCache, getGraphBuilderSuite(providers), optimisticOpts, profilingInfo,
                                 method.getSpeculationLog(), suites, true, new CompilationResult(), CompilationResultBuilderFactory.Default);
-
+                result.setId(getId());
+                result.setEntryBCI(entryBCI);
             } catch (Throwable e) {
                 throw Debug.handle(e);
             } finally {
@@ -254,7 +255,7 @@
         final HotSpotCodeCacheProvider codeCache = backend.getProviders().getCodeCache();
         HotSpotInstalledCode installedCode = null;
         try (Scope s = Debug.scope("CodeInstall", new DebugDumpScope(String.valueOf(id), true), codeCache, method)) {
-            installedCode = codeCache.installMethod(method, entryBCI, compResult);
+            installedCode = codeCache.installMethod(method, compResult);
         } catch (Throwable e) {
             throw Debug.handle(e);
         }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompileTheWorld.java	Tue Jan 14 10:14:28 2014 -0800
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompileTheWorld.java	Tue Jan 14 10:14:31 2014 -0800
@@ -41,6 +41,7 @@
 import com.oracle.graal.hotspot.HotSpotOptions.OptionConsumer;
 import com.oracle.graal.hotspot.bridge.*;
 import com.oracle.graal.hotspot.meta.*;
+import com.oracle.graal.nodes.*;
 import com.oracle.graal.options.*;
 import com.oracle.graal.options.OptionValue.OverrideScope;
 import com.oracle.graal.phases.tiers.*;
@@ -350,7 +351,7 @@
         try {
             long start = System.currentTimeMillis();
 
-            int id = vmToCompiler.allocateCompileTaskId();
+            int id = vmToCompiler.allocateCompileTaskId(method, StructuredGraph.INVOCATION_ENTRY_BCI);
             HotSpotBackend backend = runtime.getHostBackend();
             CompilationTask task = new CTWCompilationTask(backend, method, id);
             task.runCompilation(false);
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotCompiledNmethod.java	Tue Jan 14 10:14:28 2014 -0800
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotCompiledNmethod.java	Tue Jan 14 10:14:31 2014 -0800
@@ -33,10 +33,12 @@
     private static final long serialVersionUID = 1492412603674834024L;
     public final HotSpotResolvedJavaMethod method;
     public final int entryBCI;
+    public final int id;
 
-    public HotSpotCompiledNmethod(HotSpotResolvedJavaMethod method, int entryBCI, CompilationResult compResult) {
+    public HotSpotCompiledNmethod(HotSpotResolvedJavaMethod method, CompilationResult compResult) {
         super(compResult);
         this.method = method;
-        this.entryBCI = entryBCI;
+        this.entryBCI = compResult.getEntryBCI();
+        this.id = compResult.getId();
     }
 }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java	Tue Jan 14 10:14:28 2014 -0800
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java	Tue Jan 14 10:14:31 2014 -0800
@@ -257,4 +257,9 @@
      * Collects the current values of all Graal benchmark counters, summed up over all threads.
      */
     long[] collectCounters();
+
+    /**
+     * Generate a unique id to identify the result of the compile.
+     */
+    int allocateCompileId(HotSpotResolvedJavaMethod method, int entryBCI);
 }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java	Tue Jan 14 10:14:28 2014 -0800
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java	Tue Jan 14 10:14:31 2014 -0800
@@ -168,4 +168,6 @@
     public static native Object executeCompiledMethodIntrinsic(Object arg1, Object arg2, Object arg3, HotSpotInstalledCode hotspotInstalledCode) throws InvalidInstalledCodeException;
 
     public native long[] collectCounters();
+
+    public native int allocateCompileId(HotSpotResolvedJavaMethod method, int entryBCI);
 }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java	Tue Jan 14 10:14:28 2014 -0800
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java	Tue Jan 14 10:14:31 2014 -0800
@@ -32,8 +32,6 @@
 import java.security.*;
 import java.util.*;
 import java.util.concurrent.*;
-import java.util.concurrent.atomic.*;
-
 import com.oracle.graal.api.meta.*;
 import com.oracle.graal.compiler.*;
 import com.oracle.graal.compiler.CompilerThreadFactory.DebugConfigAccess;
@@ -87,7 +85,6 @@
     private final HotSpotGraalRuntime runtime;
 
     private ThreadPoolExecutor compileQueue;
-    private AtomicInteger compileTaskIds = new AtomicInteger();
 
     private volatile boolean bootstrapRunning;
 
@@ -99,8 +96,8 @@
         this.runtime = runtime;
     }
 
-    public int allocateCompileTaskId() {
-        return compileTaskIds.incrementAndGet();
+    public int allocateCompileTaskId(HotSpotResolvedJavaMethod method, int entryBCI) {
+        return runtime.getCompilerToVM().allocateCompileId(method, entryBCI);
     }
 
     public void startCompiler(boolean bootstrapEnabled) throws Throwable {
@@ -562,7 +559,7 @@
             if (method.tryToQueueForCompilation()) {
                 assert method.isQueuedForCompilation();
 
-                int id = allocateCompileTaskId();
+                int id = allocateCompileTaskId(method, entryBCI);
                 HotSpotBackend backend = runtime.getHostBackend();
                 CompilationTask task = new CompilationTask(backend, method, entryBCI, id);
 
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotCodeCacheProvider.java	Tue Jan 14 10:14:28 2014 -0800
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotCodeCacheProvider.java	Tue Jan 14 10:14:31 2014 -0800
@@ -37,7 +37,6 @@
 import com.oracle.graal.hotspot.bridge.*;
 import com.oracle.graal.hotspot.bridge.CompilerToVM.CodeInstallResult;
 import com.oracle.graal.java.*;
-import com.oracle.graal.nodes.*;
 import com.oracle.graal.printer.*;
 
 /**
@@ -168,9 +167,9 @@
         return installedCode;
     }
 
-    public HotSpotInstalledCode installMethod(HotSpotResolvedJavaMethod method, int entryBCI, CompilationResult compResult) {
+    public HotSpotInstalledCode installMethod(HotSpotResolvedJavaMethod method, CompilationResult compResult) {
         HotSpotInstalledCode installedCode = new HotSpotNmethod(method, compResult.getName(), true);
-        runtime.getCompilerToVM().installCode(new HotSpotCompiledNmethod(method, entryBCI, compResult), installedCode, method.getSpeculationLog());
+        runtime.getCompilerToVM().installCode(new HotSpotCompiledNmethod(method, compResult), installedCode, method.getSpeculationLog());
         return logOrDump(installedCode, compResult);
     }
 
@@ -178,7 +177,7 @@
     public InstalledCode addMethod(ResolvedJavaMethod method, CompilationResult compResult) {
         HotSpotResolvedJavaMethod hotspotMethod = (HotSpotResolvedJavaMethod) method;
         HotSpotInstalledCode code = new HotSpotNmethod(hotspotMethod, compResult.getName(), false);
-        CodeInstallResult result = runtime.getCompilerToVM().installCode(new HotSpotCompiledNmethod(hotspotMethod, -1, compResult), code, null);
+        CodeInstallResult result = runtime.getCompilerToVM().installCode(new HotSpotCompiledNmethod(hotspotMethod, compResult), code, null);
         if (result != CodeInstallResult.OK) {
             return null;
         }
@@ -187,13 +186,13 @@
 
     public InstalledCode setDefaultMethod(ResolvedJavaMethod method, CompilationResult compResult) {
         HotSpotResolvedJavaMethod hotspotMethod = (HotSpotResolvedJavaMethod) method;
-        return installMethod(hotspotMethod, StructuredGraph.INVOCATION_ENTRY_BCI, compResult);
+        return installMethod(hotspotMethod, compResult);
     }
 
     public InstalledCode addExternalMethod(ResolvedJavaMethod method, CompilationResult compResult) {
         HotSpotResolvedJavaMethod javaMethod = (HotSpotResolvedJavaMethod) method;
         HotSpotInstalledCode icode = new HotSpotNmethod(javaMethod, compResult.getName(), false, true);
-        HotSpotCompiledNmethod compiled = new HotSpotCompiledNmethod(javaMethod, -1, compResult);
+        HotSpotCompiledNmethod compiled = new HotSpotCompiledNmethod(javaMethod, compResult);
         CompilerToVM vm = runtime.getCompilerToVM();
         CodeInstallResult result = vm.installCode(compiled, icode, null);
         if (result != CodeInstallResult.OK) {
--- a/src/share/vm/compiler/compileBroker.hpp	Tue Jan 14 10:14:28 2014 -0800
+++ b/src/share/vm/compiler/compileBroker.hpp	Tue Jan 14 10:14:31 2014 -0800
@@ -321,7 +321,6 @@
   static void init_compiler_threads(int c1_compiler_count, int c2_compiler_count);
   static bool compilation_is_complete  (methodHandle method, int osr_bci, int comp_level);
   static bool compilation_is_prohibited(methodHandle method, int osr_bci, int comp_level);
-  static uint assign_compile_id        (methodHandle method, int osr_bci);
   static bool is_compile_blocking      (methodHandle method, int osr_bci);
   static void preload_classes          (methodHandle method, TRAPS);
 
@@ -386,6 +385,8 @@
                                  int hot_count,
                                  const char* comment, Thread* thread);
 
+  static uint assign_compile_id        (methodHandle method, int osr_bci);
+
   static void compiler_thread_loop();
   static uint get_compilation_id() { return _compilation_id; }
 
--- a/src/share/vm/graal/graalCodeInstaller.cpp	Tue Jan 14 10:14:28 2014 -0800
+++ b/src/share/vm/graal/graalCodeInstaller.cpp	Tue Jan 14 10:14:31 2014 -0800
@@ -401,8 +401,9 @@
     nmethod* nm = NULL;
     methodHandle method = getMethodFromHotSpotMethod(HotSpotCompiledNmethod::method(compiled_code));
     jint entry_bci = HotSpotCompiledNmethod::entryBCI(compiled_code);
+    jint id = HotSpotCompiledNmethod::id(compiled_code);
     result = GraalEnv::register_method(method, nm, entry_bci, &_offsets, _custom_stack_area_offset, &buffer, stack_slots, _debug_recorder->_oopmaps, &_exception_handler_table,
-        GraalCompiler::instance(), _debug_recorder, _dependencies, NULL, -1, false, leaf_graph_ids, installed_code, triggered_deoptimizations);
+        GraalCompiler::instance(), _debug_recorder, _dependencies, NULL, id, false, leaf_graph_ids, installed_code, triggered_deoptimizations);
     cb = nm;
   }
 
--- a/src/share/vm/graal/graalCompilerToVM.cpp	Tue Jan 14 10:14:28 2014 -0800
+++ b/src/share/vm/graal/graalCompilerToVM.cpp	Tue Jan 14 10:14:31 2014 -0800
@@ -815,6 +815,15 @@
   return (jlongArray) JNIHandles::make_local(arrayOop);
 C2V_END
 
+C2V_VMENTRY(int, allocateCompileId, (JNIEnv *env, jobject, jobject hotspot_method, int entry_bci))
+  HandleMark hm;
+  ResourceMark rm;
+  Method* method = getMethodFromHotSpotMethod(JNIHandles::resolve(hotspot_method));
+  MutexLocker locker(MethodCompileQueue_lock, thread);
+  return CompileBroker::assign_compile_id(method, entry_bci);
+C2V_END
+
+
 #define CC (char*)  /*cast a literal from (const char*)*/
 #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &(c2v_ ## f))
 
@@ -875,6 +884,7 @@
   {CC"readUnsafeUncompressedPointer", CC"("OBJECT"J)"OBJECT,                                            FN_PTR(readUnsafeUncompressedPointer)},
   {CC"readUnsafeKlassPointer",        CC"("OBJECT")J",                                                  FN_PTR(readUnsafeKlassPointer)},
   {CC"collectCounters",               CC"()[J",                                                         FN_PTR(collectCounters)},
+  {CC"allocateCompileId",             CC"("HS_RESOLVED_METHOD"I)I",                                     FN_PTR(allocateCompileId)},
 };
 
 int CompilerToVM_methods_count() {
--- a/src/share/vm/graal/graalJavaAccess.hpp	Tue Jan 14 10:14:28 2014 -0800
+++ b/src/share/vm/graal/graalJavaAccess.hpp	Tue Jan 14 10:14:31 2014 -0800
@@ -99,6 +99,7 @@
   start_class(HotSpotCompiledNmethod)                                                                                                                          \
     oop_field(HotSpotCompiledNmethod, method, "Lcom/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod;")                                                     \
     int_field(HotSpotCompiledNmethod, entryBCI)                                                                                                                \
+    int_field(HotSpotCompiledNmethod, id)                                                                                                                \
   end_class                                                                                                                                                    \
   start_class(HotSpotCompiledRuntimeStub)                                                                                                                      \
     oop_field(HotSpotCompiledRuntimeStub, stubName, "Ljava/lang/String;")                                                                                      \
--- a/src/share/vm/prims/jni.cpp	Tue Jan 14 10:14:28 2014 -0800
+++ b/src/share/vm/prims/jni.cpp	Tue Jan 14 10:14:31 2014 -0800
@@ -5179,7 +5179,7 @@
     if (graal_compiler != NULL) {
       graal_compiler->initialize();
     } else {
-      assert(!UseCompiler, "why isn't there are compiler?");
+      assert(!UseCompiler, "why isn't there any compiler?");
     }
 #endif