changeset 54324:22f0f09da5ba

8221929: Update JVMCI Reviewed-by: never
author kvn
date Wed, 03 Apr 2019 11:14:42 -0700
parents 530fc1427d02
children 393a74bd3136
files src/hotspot/share/classfile/javaClasses.cpp src/hotspot/share/classfile/javaClasses.hpp src/hotspot/share/compiler/compileBroker.cpp src/hotspot/share/compiler/compilerDefinitions.cpp src/hotspot/share/gc/cms/concurrentMarkSweepGeneration.cpp src/hotspot/share/gc/g1/g1CollectedHeap.cpp src/hotspot/share/gc/parallel/psMarkSweep.cpp src/hotspot/share/gc/parallel/psParallelCompact.cpp src/hotspot/share/gc/serial/genMarkSweep.cpp src/hotspot/share/gc/shared/parallelCleaning.cpp src/hotspot/share/gc/shared/parallelCleaning.hpp src/hotspot/share/jvmci/jvmciCompilerToVM.cpp src/hotspot/share/jvmci/jvmciRuntime.cpp src/hotspot/share/prims/jvmtiImpl.cpp src/hotspot/share/runtime/vmOperations.cpp
diffstat 15 files changed, 113 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/classfile/javaClasses.cpp	Thu Mar 28 10:15:57 2019 -0700
+++ b/src/hotspot/share/classfile/javaClasses.cpp	Wed Apr 03 11:14:42 2019 -0700
@@ -2633,6 +2633,7 @@
   }
 }
 
+#if INCLUDE_JVMCI
 void java_lang_StackTraceElement::decode(Handle mirror, methodHandle method, int bci, Symbol*& methodname, Symbol*& filename, int& line_number) {
   int method_id = method->orig_method_idnum();
   int cpref = method->name_index();
@@ -2669,6 +2670,7 @@
     line_number = Backtrace::get_line_number(method, bci);
   }
 }
+#endif // INCLUDE_JVMCI
 
 Method* java_lang_StackFrameInfo::get_method(Handle stackFrame, InstanceKlass* holder, TRAPS) {
   HandleMark hm(THREAD);
--- a/src/hotspot/share/classfile/javaClasses.hpp	Thu Mar 28 10:15:57 2019 -0700
+++ b/src/hotspot/share/classfile/javaClasses.hpp	Wed Apr 03 11:14:42 2019 -0700
@@ -1369,8 +1369,10 @@
   static void compute_offsets();
   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
 
+#if INCLUDE_JVMCI
   static void decode(Handle mirror, int method, int version, int bci, int cpref, Symbol*& methodName, Symbol*& fileName, int& lineNumber);
   static void decode(Handle mirror, methodHandle method, int bci, Symbol*& methodName, Symbol*& fileName, int& lineNumber);
+#endif
 
   // Debugging
   friend class JavaClasses;
--- a/src/hotspot/share/compiler/compileBroker.cpp	Thu Mar 28 10:15:57 2019 -0700
+++ b/src/hotspot/share/compiler/compileBroker.cpp	Wed Apr 03 11:14:42 2019 -0700
@@ -1611,7 +1611,6 @@
 
   {
     // Must switch to native to allocate ci_env
-    HandleMark hm(thread);
     ThreadToNativeFromVM ttn(thread);
     ciEnv ci_env(NULL, system_dictionary_modification_counter);
     // Cache Jvmti state
--- a/src/hotspot/share/compiler/compilerDefinitions.cpp	Thu Mar 28 10:15:57 2019 -0700
+++ b/src/hotspot/share/compiler/compilerDefinitions.cpp	Wed Apr 03 11:14:42 2019 -0700
@@ -265,7 +265,17 @@
     if (UseJVMCINativeLibrary) {
       // SVM compiled code requires more stack space
       if (FLAG_IS_DEFAULT(CompilerThreadStackSize)) {
-        FLAG_SET_DEFAULT(CompilerThreadStackSize, 2*M);
+        // Duplicate logic in the implementations of os::create_thread
+        // so that we can then double the computed stack size. Once
+        // the stack size requirements of SVM are better understood,
+        // this logic can be pushed down into os::create_thread.
+        int stack_size = CompilerThreadStackSize;
+        if (stack_size == 0) {
+          stack_size = VMThreadStackSize;
+        }
+        if (stack_size != 0) {
+          FLAG_SET_DEFAULT(CompilerThreadStackSize, stack_size * 2);
+        }
       }
     } else {
       // Adjust the on stack replacement percentage to avoid early
--- a/src/hotspot/share/gc/cms/concurrentMarkSweepGeneration.cpp	Thu Mar 28 10:15:57 2019 -0700
+++ b/src/hotspot/share/gc/cms/concurrentMarkSweepGeneration.cpp	Wed Apr 03 11:14:42 2019 -0700
@@ -5268,10 +5268,8 @@
       // Prune dead klasses from subklass/sibling/implementor lists.
       Klass::clean_weak_klass_links(purged_class);
 
-#if INCLUDE_JVMCI
       // Clean JVMCI metadata handles.
-      JVMCI::do_unloading(&_is_alive_closure, purged_class);
-#endif
+      JVMCI_ONLY(JVMCI::do_unloading(&_is_alive_closure, purged_class));
     }
   }
 
--- a/src/hotspot/share/gc/g1/g1CollectedHeap.cpp	Thu Mar 28 10:15:57 2019 -0700
+++ b/src/hotspot/share/gc/g1/g1CollectedHeap.cpp	Wed Apr 03 11:14:42 2019 -0700
@@ -79,9 +79,6 @@
 #include "gc/shared/taskqueue.inline.hpp"
 #include "gc/shared/weakProcessor.inline.hpp"
 #include "gc/shared/workerPolicy.hpp"
-#if INCLUDE_JVMCI
-#include "jvmci/jvmci.hpp"
-#endif
 #include "logging/log.hpp"
 #include "memory/allocation.hpp"
 #include "memory/iterator.hpp"
@@ -3277,10 +3274,6 @@
   uint num_workers = workers()->active_workers();
   ParallelCleaningTask unlink_task(is_alive, num_workers, class_unloading_occurred, false);
   workers()->run_task(&unlink_task);
-#if INCLUDE_JVMCI
-  // No parallel processing of JVMCI metadata handles for now.
-  JVMCI::do_unloading(is_alive, class_unloading_occurred);
-#endif
 }
 
 // Clean string dedup data structures.
--- a/src/hotspot/share/gc/parallel/psMarkSweep.cpp	Thu Mar 28 10:15:57 2019 -0700
+++ b/src/hotspot/share/gc/parallel/psMarkSweep.cpp	Wed Apr 03 11:14:42 2019 -0700
@@ -50,9 +50,6 @@
 #include "gc/shared/referenceProcessorPhaseTimes.hpp"
 #include "gc/shared/spaceDecorator.hpp"
 #include "gc/shared/weakProcessor.hpp"
-#if INCLUDE_JVMCI
-#include "jvmci/jvmci.hpp"
-#endif
 #include "logging/log.hpp"
 #include "oops/oop.inline.hpp"
 #include "runtime/biasedLocking.hpp"
@@ -65,6 +62,9 @@
 #include "utilities/align.hpp"
 #include "utilities/events.hpp"
 #include "utilities/stack.inline.hpp"
+#if INCLUDE_JVMCI
+#include "jvmci/jvmci.hpp"
+#endif
 
 elapsedTimer        PSMarkSweep::_accumulated_time;
 jlong               PSMarkSweep::_time_of_last_gc   = 0;
@@ -566,10 +566,8 @@
     // Prune dead klasses from subklass/sibling/implementor lists.
     Klass::clean_weak_klass_links(purged_class);
 
-#if INCLUDE_JVMCI
     // Clean JVMCI metadata handles.
-    JVMCI::do_unloading(is_alive_closure(), purged_class);
-#endif
+    JVMCI_ONLY(JVMCI::do_unloading(is_alive_closure(), purged_class));
   }
 
   _gc_tracer->report_object_count_after_gc(is_alive_closure());
--- a/src/hotspot/share/gc/parallel/psParallelCompact.cpp	Thu Mar 28 10:15:57 2019 -0700
+++ b/src/hotspot/share/gc/parallel/psParallelCompact.cpp	Wed Apr 03 11:14:42 2019 -0700
@@ -54,9 +54,6 @@
 #include "gc/shared/referenceProcessorPhaseTimes.hpp"
 #include "gc/shared/spaceDecorator.hpp"
 #include "gc/shared/weakProcessor.hpp"
-#if INCLUDE_JVMCI
-#include "jvmci/jvmci.hpp"
-#endif
 #include "logging/log.hpp"
 #include "memory/iterator.inline.hpp"
 #include "memory/resourceArea.hpp"
@@ -80,6 +77,9 @@
 #include "utilities/formatBuffer.hpp"
 #include "utilities/macros.hpp"
 #include "utilities/stack.inline.hpp"
+#if INCLUDE_JVMCI
+#include "jvmci/jvmci.hpp"
+#endif
 
 #include <math.h>
 
@@ -2180,10 +2180,8 @@
     // Prune dead klasses from subklass/sibling/implementor lists.
     Klass::clean_weak_klass_links(purged_class);
 
-#if INCLUDE_JVMCI
     // Clean JVMCI metadata handles.
-    JVMCI::do_unloading(is_alive_closure(), purged_class);
-#endif
+    JVMCI_ONLY(JVMCI::do_unloading(is_alive_closure(), purged_class));
   }
 
   _gc_tracer.report_object_count_after_gc(is_alive_closure());
--- a/src/hotspot/share/gc/serial/genMarkSweep.cpp	Thu Mar 28 10:15:57 2019 -0700
+++ b/src/hotspot/share/gc/serial/genMarkSweep.cpp	Wed Apr 03 11:14:42 2019 -0700
@@ -46,9 +46,6 @@
 #include "gc/shared/space.hpp"
 #include "gc/shared/strongRootsScope.hpp"
 #include "gc/shared/weakProcessor.hpp"
-#if INCLUDE_JVMCI
-#include "jvmci/jvmci.hpp"
-#endif
 #include "oops/instanceRefKlass.hpp"
 #include "oops/oop.inline.hpp"
 #include "prims/jvmtiExport.hpp"
@@ -59,6 +56,9 @@
 #include "utilities/copy.hpp"
 #include "utilities/events.hpp"
 #include "utilities/stack.inline.hpp"
+#if INCLUDE_JVMCI
+#include "jvmci/jvmci.hpp"
+#endif
 
 void GenMarkSweep::invoke_at_safepoint(ReferenceProcessor* rp, bool clear_all_softrefs) {
   assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint");
@@ -237,10 +237,8 @@
     // Prune dead klasses from subklass/sibling/implementor lists.
     Klass::clean_weak_klass_links(purged_class);
 
-#if INCLUDE_JVMCI
     // Clean JVMCI metadata handles.
-    JVMCI::do_unloading(&is_alive, purged_class);
-#endif
+    JVMCI_ONLY(JVMCI::do_unloading(&is_alive, purged_class));
   }
 
   gc_tracer()->report_object_count_after_gc(&is_alive);
--- a/src/hotspot/share/gc/shared/parallelCleaning.cpp	Thu Mar 28 10:15:57 2019 -0700
+++ b/src/hotspot/share/gc/shared/parallelCleaning.cpp	Wed Apr 03 11:14:42 2019 -0700
@@ -30,6 +30,9 @@
 #include "logging/log.hpp"
 #include "memory/resourceArea.hpp"
 #include "logging/log.hpp"
+#if INCLUDE_JVMCI
+#include "jvmci/jvmci.hpp"
+#endif
 
 StringDedupCleaningTask::StringDedupCleaningTask(BoolObjectClosure* is_alive,
                                                  OopClosure* keep_alive,
@@ -158,6 +161,28 @@
   }
 }
 
+#if INCLUDE_JVMCI
+JVMCICleaningTask::JVMCICleaningTask(BoolObjectClosure* is_alive) :
+  _is_alive(is_alive),
+  _cleaning_claimed(0) {
+}
+
+bool JVMCICleaningTask::claim_cleaning_task() {
+  if (_cleaning_claimed) {
+    return false;
+  }
+
+  return Atomic::cmpxchg(1, &_cleaning_claimed, 0) == 0;
+}
+
+void JVMCICleaningTask::work(bool unloading_occurred) {
+  // One worker will clean JVMCI metadata handles.
+  if (EnableJVMCI && claim_cleaning_task()) {
+    JVMCI::do_unloading(_is_alive, unloading_occurred);
+  }
+}
+#endif // INCLUDE_JVMCI
+
 ParallelCleaningTask::ParallelCleaningTask(BoolObjectClosure* is_alive,
                                            uint num_workers,
                                            bool unloading_occurred,
@@ -166,6 +191,9 @@
   _unloading_occurred(unloading_occurred),
   _string_dedup_task(is_alive, NULL, resize_dedup_table),
   _code_cache_task(num_workers, is_alive, unloading_occurred),
+#if INCLUDE_JVMCI
+  _jvmci_cleaning_task(is_alive),
+#endif
   _klass_cleaning_task() {
 }
 
@@ -182,5 +210,6 @@
   // processed if there was no unloading.
   if (_unloading_occurred) {
     _klass_cleaning_task.work();
+    JVMCI_ONLY(_jvmci_cleaning_task.work(_unloading_occurred);)
   }
 }
--- a/src/hotspot/share/gc/shared/parallelCleaning.hpp	Thu Mar 28 10:15:57 2019 -0700
+++ b/src/hotspot/share/gc/shared/parallelCleaning.hpp	Wed Apr 03 11:14:42 2019 -0700
@@ -87,6 +87,21 @@
   void work();
 };
 
+#if INCLUDE_JVMCI
+class JVMCICleaningTask : public StackObj {
+  BoolObjectClosure* _is_alive;
+  volatile int       _cleaning_claimed;
+
+public:
+  JVMCICleaningTask(BoolObjectClosure* is_alive);
+  // Clean JVMCI metadata handles.
+  void work(bool unloading_occurred);
+
+private:
+  bool claim_cleaning_task();
+};
+#endif
+
 // Do cleanup of some weakly held data in the same parallel task.
 // Assumes a non-moving context.
 class ParallelCleaningTask : public AbstractGangTask {
@@ -94,6 +109,9 @@
   bool                    _unloading_occurred;
   StringDedupCleaningTask _string_dedup_task;
   CodeCacheUnloadingTask  _code_cache_task;
+#if INCLUDE_JVMCI
+  JVMCICleaningTask       _jvmci_cleaning_task;
+#endif
   KlassCleaningTask       _klass_cleaning_task;
 
 public:
--- a/src/hotspot/share/jvmci/jvmciCompilerToVM.cpp	Thu Mar 28 10:15:57 2019 -0700
+++ b/src/hotspot/share/jvmci/jvmciCompilerToVM.cpp	Wed Apr 03 11:14:42 2019 -0700
@@ -2054,10 +2054,31 @@
 }
 
 C2V_VMENTRY(jlongArray, registerNativeMethods, (JNIEnv* env, jobject, jclass mirror))
+  if (!UseJVMCINativeLibrary) {
+    JVMCI_THROW_MSG_0(UnsatisfiedLinkError, "JVMCI shared library is not enabled (requires -XX:+UseJVMCINativeLibrary)");
+  }
+  if (!JVMCIENV->is_hotspot()) {
+    JVMCI_THROW_MSG_0(UnsatisfiedLinkError, "Cannot call registerNativeMethods from JVMCI shared library");
+  }
   void* shared_library = JVMCIEnv::get_shared_library_handle();
   if (shared_library == NULL) {
+    // Ensure the JVMCI shared library runtime is initialized.
+    JVMCIEnv __peer_jvmci_env__(false, __FILE__, __LINE__);
+    JVMCIEnv* peerEnv = &__peer_jvmci_env__;
+    HandleMark hm;
+    JVMCIRuntime* runtime = JVMCI::compiler_runtime();
+    JVMCIObject receiver = runtime->get_HotSpotJVMCIRuntime(peerEnv);
+    if (peerEnv->has_pending_exception()) {
+      peerEnv->describe_pending_exception(true);
+      JVMCI_THROW_MSG_0(InternalError, "Error initializing JVMCI runtime");
+    }
+    shared_library = JVMCIEnv::get_shared_library_handle();
+  }
+
+  if (shared_library == NULL) {
     JVMCI_THROW_MSG_0(UnsatisfiedLinkError, "JVMCI shared library is unavailable");
   }
+
   if (mirror == NULL) {
     JVMCI_THROW_0(NullPointerException);
   }
@@ -2070,10 +2091,6 @@
   for (int i = 0; i < iklass->methods()->length(); i++) {
     Method* method = iklass->methods()->at(i);
     if (method->is_native()) {
-      if (method->has_native_function()) {
-        JVMCI_THROW_MSG_0(UnsatisfiedLinkError, err_msg("Cannot overwrite existing native implementation for %s",
-            method->name_and_sig_as_C_string()));
-      }
 
       // Compute argument size
       int args_size = 1                             // JNIEnv
@@ -2098,10 +2115,15 @@
         st.print_raw(long_name);
         os::print_jni_name_suffix_on(&st, args_size);
         jni_name = st.as_string();
+        entry = (address) os::dll_lookup(shared_library, jni_name);
       }
       if (entry == NULL) {
         JVMCI_THROW_MSG_0(UnsatisfiedLinkError, method->name_and_sig_as_C_string());
       }
+      if (method->has_native_function() && entry != method->native_function()) {
+        JVMCI_THROW_MSG_0(UnsatisfiedLinkError, err_msg("Cannot overwrite existing native implementation for %s",
+            method->name_and_sig_as_C_string()));
+      }
       method->set_native_function(entry, Method::native_bind_event_is_interesting);
       if (PrintJNIResolving) {
         tty->print_cr("[Dynamic-linking native method %s.%s ... JNI]",
--- a/src/hotspot/share/jvmci/jvmciRuntime.cpp	Thu Mar 28 10:15:57 2019 -0700
+++ b/src/hotspot/share/jvmci/jvmciRuntime.cpp	Wed Apr 03 11:14:42 2019 -0700
@@ -309,7 +309,7 @@
         if (klass->class_loader_data()->is_unloading()) {
           // This needs to be marked so that it's no longer scanned
           // but can't be put on the free list yet. The
-          // ReferenceCleaner will set this to NULL and
+          // HandleCleaner will set this to NULL and
           // put it on the free list.
           jlong old_value = Atomic::cmpxchg((jlong) (ptr_tag), (jlong*)handle, (jlong) value);
           if (old_value == (jlong) value) {
--- a/src/hotspot/share/prims/jvmtiImpl.cpp	Thu Mar 28 10:15:57 2019 -0700
+++ b/src/hotspot/share/prims/jvmtiImpl.cpp	Wed Apr 03 11:14:42 2019 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -81,7 +81,6 @@
 
 void
 JvmtiAgentThread::call_start_function() {
-    HandleMark hm(this);
     ThreadToNativeFromVM transition(this);
     _start_fn(_env->jvmti_external(), jni_environment(), (void*)_start_arg);
 }
--- a/src/hotspot/share/runtime/vmOperations.cpp	Thu Mar 28 10:15:57 2019 -0700
+++ b/src/hotspot/share/runtime/vmOperations.cpp	Wed Apr 03 11:14:42 2019 -0700
@@ -435,16 +435,20 @@
       if (thr!=thr_cur && thr->thread_state() == _thread_in_native) {
         num_active++;
         if (thr->is_Compiler_thread()) {
+#if INCLUDE_JVMCI
           CompilerThread* ct = (CompilerThread*) thr;
-          if (ct->compiler() == NULL || !ct->compiler()->is_jvmci()) {
+          if (ct->compiler() == NULL || !ct->compiler()->is_jvmci() || !UseJVMCINativeLibrary) {
             num_active_compiler_thread++;
           } else {
-            // When using a Java based JVMCI compiler, it's possible
-            // for one compiler thread to grab a Java lock, enter
-            // HotSpot and go to sleep on the shutdown safepoint.
-            // Another JVMCI compiler thread can then attempt grab
-            // the lock and thus never make progress.
+            // When using a compiler in a JVMCI shared library, it's possible
+            // for one compiler thread to grab a lock in the shared library,
+            // enter HotSpot and go to sleep on the shutdown safepoint. Another
+            // JVMCI shared library compiler thread can then attempt to grab the
+            // lock and thus never make progress.
           }
+#else
+          num_active_compiler_thread++;
+#endif
         }
       }
     }