changeset 3683:345c3bbf9c3c

store RiCompiledMethod in nmethod and: * invalidate RiCompiledMethod when the nmethod is invalidated * invalidate the nmethod when the RiCompiledMethod object is GC'ed
author Lukas Stadler <lukas.stadler@jku.at>
date Fri, 18 Nov 2011 11:54:07 +0100
parents 6c04a4f268e5
children 1976ebe361c2
files src/share/vm/code/nmethod.cpp src/share/vm/code/nmethod.hpp src/share/vm/graal/graalVMEntries.cpp
diffstat 3 files changed, 46 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/code/nmethod.cpp	Fri Nov 18 11:52:59 2011 +0100
+++ b/src/share/vm/code/nmethod.cpp	Fri Nov 18 11:54:07 2011 +0100
@@ -44,6 +44,9 @@
 #ifdef SHARK
 #include "shark/sharkCompiler.hpp"
 #endif
+#ifdef GRAAL
+#include "graal/graalJavaAccess.hpp"
+#endif
 
 #ifdef DTRACE_ENABLED
 
@@ -463,6 +466,8 @@
   _saved_nmethod_link      = NULL;
   _compiler                = NULL;
 
+  _graal_compiled_method   = NULL;
+
 #ifdef HAVE_DTRACE_H
   _trap_offset             = 0;
 #endif // def HAVE_DTRACE_H
@@ -1295,6 +1300,13 @@
       return false;
     }
 
+#ifdef GRAAL
+    if (_graal_compiled_method != NULL) {
+      HotSpotCompiledMethod::set_nmethod(_graal_compiled_method, 0);
+      _graal_compiled_method = NULL;
+    }
+#endif
+
     // The caller can be calling the method statically or through an inline
     // cache call.
     if (!is_osr_method() && !is_not_entrant()) {
@@ -1593,6 +1605,10 @@
     return;
   }
 
+  if (_graal_compiled_method != NULL && can_unload(is_alive, keep_alive, (oop*)&_graal_compiled_method, unloading_occurred)) {
+    return;
+  }
+
   // Exception cache
   ExceptionCache* ec = exception_cache();
   while (ec != NULL) {
@@ -1707,6 +1723,7 @@
 
   // Compiled code
   f->do_oop((oop*) &_method);
+  f->do_oop((oop*) &_graal_compiled_method);
   if (!do_strong_roots_only) {
     // weak roots processing phase -- update ExceptionCache oops
     ExceptionCache* ec = exception_cache();
--- a/src/share/vm/code/nmethod.hpp	Fri Nov 18 11:52:59 2011 +0100
+++ b/src/share/vm/code/nmethod.hpp	Fri Nov 18 11:54:07 2011 +0100
@@ -116,6 +116,8 @@
   int       _entry_bci;        // != InvocationEntryBci if this nmethod is an on-stack replacement method
   jmethodID _jmethod_id;       // Cache of method()->jmethod_id()
 
+  oop       _graal_compiled_method;
+
   // To support simple linked-list chaining of nmethods:
   nmethod*  _osr_link;         // from instanceKlass::osr_nmethods_head
   nmethod*  _scavenge_root_link; // from CodeCache::scavenge_root_nmethods
@@ -539,6 +541,10 @@
   // Evolution support. We make old (discarded) compiled methods point to new methodOops.
   void set_method(methodOop method) { _method = method; }
 
+
+  oop graal_compiled_method() { return _graal_compiled_method; }
+  void set_graal_compiled_method(oop compiled_method) { _graal_compiled_method = compiled_method; }
+
   // GC support
   void do_unloading(BoolObjectClosure* is_alive, OopClosure* keep_alive,
                     bool unloading_occurred);
--- a/src/share/vm/graal/graalVMEntries.cpp	Fri Nov 18 11:52:59 2011 +0100
+++ b/src/share/vm/graal/graalVMEntries.cpp	Fri Nov 18 11:54:07 2011 +0100
@@ -934,6 +934,8 @@
   set_int(env, config, "klassOopOffset", java_lang_Class::klass_offset_in_bytes());
   set_boolean(env, config, "isPollingPageFar", Assembler::is_polling_page_far());
 
+  set_int(env, config, "nmethodEntryOffset", nmethod::verified_entry_point_offset());
+
   BarrierSet* bs = Universe::heap()->barrier_set();
   switch (bs->kind()) {
     case BarrierSet::CardTableModRef:
@@ -969,8 +971,8 @@
   return config;
 }
 
-// public long installMethod(HotSpotTargetMethod targetMethod, boolean installCode);
-JNIEXPORT jlong JNICALL Java_com_oracle_graal_hotspot_VMEntries_installMethod(JNIEnv *jniEnv, jobject, jobject targetMethod, jboolean install_code) {
+// public HotSpotCompiledMethod installMethod(HotSpotTargetMethod targetMethod, boolean installCode);
+JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_VMEntries_installMethod(JNIEnv *jniEnv, jobject, jobject targetMethod, jboolean install_code) {
   VM_ENTRY_MARK;
   nmethod* nm = NULL;
   if (CURRENT_ENV == NULL) {
@@ -981,8 +983,24 @@
   } else {
     ResourceMark rm;
     CodeInstaller installer(JNIHandles::resolve(targetMethod), nm, install_code != 0);
+
+    if (CURRENT_ENV->failing()) {
+      tty->print_cr("failing: %s", CURRENT_ENV->failure_reason());
+    }
   }
-  return (jlong) nm;
+
+  // if install_code is true then we installed the code into the given method, no need to return an RiCompiledMethod
+  if (!install_code && nm != NULL) {
+    instanceKlass::cast(HotSpotCompiledMethod::klass())->initialize(CHECK_NULL);
+    Handle obj = instanceKlass::cast(HotSpotCompiledMethod::klass())->allocate_permanent_instance(CHECK_NULL);
+    assert(obj() != NULL, "must succeed in allocating instance");
+    HotSpotCompiledMethod::set_nmethod(obj, (jlong) nm);
+    HotSpotCompiledMethod::set_method(obj, HotSpotTargetMethod::method(targetMethod));
+    nm->set_graal_compiled_method(obj());
+    return JNIHandles::make_local(obj());
+  } else {
+    return NULL;
+  }
 }
 
 // public HotSpotProxy installStub(HotSpotTargetMethod targetMethod, String name);
@@ -1037,6 +1055,7 @@
 #define TARGET_METHOD   "Lcom/oracle/max/graal/hotspot/HotSpotTargetMethod;"
 #define CONFIG          "Lcom/oracle/max/graal/hotspot/HotSpotVMConfig;"
 #define HS_METHOD       "Lcom/oracle/max/graal/hotspot/HotSpotMethod;"
+#define HS_COMP_METHOD  "Lcom/oracle/max/graal/hotspot/HotSpotCompiledMethod;"
 #define CI_CONSTANT     "Lcom/sun/cri/ci/CiConstant;"
 #define CI_KIND         "Lcom/sun/cri/ci/CiKind;"
 #define CI_RUNTIME_CALL "Lcom/sun/cri/ci/CiRuntimeCall;"
@@ -1075,7 +1094,7 @@
   {CC"getMaxCallTargetOffset",            CC"("CI_RUNTIME_CALL")J",                   FN_PTR(Java_com_oracle_graal_hotspot_VMEntries_getMaxCallTargetOffset)},
   {CC"getType",                           CC"("CLASS")"TYPE,                          FN_PTR(Java_com_oracle_graal_hotspot_VMEntries_getType)},
   {CC"getConfiguration",                  CC"()"CONFIG,                               FN_PTR(Java_com_oracle_graal_hotspot_VMEntries_getConfiguration)},
-  {CC"installMethod",                     CC"("TARGET_METHOD"Z)J",                    FN_PTR(Java_com_oracle_graal_hotspot_VMEntries_installMethod)},
+  {CC"installMethod",                     CC"("TARGET_METHOD"Z)"HS_COMP_METHOD,       FN_PTR(Java_com_oracle_graal_hotspot_VMEntries_installMethod)},
   {CC"installStub",                       CC"("TARGET_METHOD")"PROXY,                 FN_PTR(Java_com_oracle_graal_hotspot_VMEntries_installStub)},
   {CC"recordBailout",                     CC"("STRING")V",                            FN_PTR(Java_com_oracle_graal_hotspot_VMEntries_recordBailout)},
   {CC"notifyJavaQueue",                   CC"()V",                                    FN_PTR(Java_com_oracle_graal_hotspot_VMEntries_notifyJavaQueue)}