diff src/share/vm/graal/graalVMEntries.cpp @ 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 136ea96eb7f8
children 5c8fc9f05960
line wrap: on
line diff
--- 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)}