8067836: The Universe::flush_foo methods belong in CodeCache.
authorcoleenp
Tue, 06 Jan 2015 19:30:28 -0500
changeset 28374 0558e321c027
parent 28373 26fdc99d32f8
child 28382 a076f426416d
child 28468 b8e9517bf6b9
8067836: The Universe::flush_foo methods belong in CodeCache. Summary: Move this code to CodeCache. Reviewed-by: kbarrett, kvn
hotspot/src/share/vm/classfile/systemDictionary.cpp
hotspot/src/share/vm/code/codeCache.cpp
hotspot/src/share/vm/code/codeCache.hpp
hotspot/src/share/vm/memory/universe.cpp
hotspot/src/share/vm/memory/universe.hpp
hotspot/src/share/vm/oops/method.cpp
hotspot/src/share/vm/prims/jvmtiRedefineClasses.cpp
hotspot/src/share/vm/prims/methodHandles.cpp
--- a/hotspot/src/share/vm/classfile/systemDictionary.cpp	Mon Jan 05 22:50:59 2015 -0500
+++ b/hotspot/src/share/vm/classfile/systemDictionary.cpp	Tue Jan 06 19:30:28 2015 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015, 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
@@ -32,6 +32,7 @@
 #include "classfile/stringTable.hpp"
 #include "classfile/systemDictionary.hpp"
 #include "classfile/vmSymbols.hpp"
+#include "code/codeCache.hpp"
 #include "compiler/compileBroker.hpp"
 #include "interpreter/bytecodeStream.hpp"
 #include "interpreter/interpreter.hpp"
@@ -1627,7 +1628,7 @@
   // Note: must be done *after* linking k into the hierarchy (was bug 12/9/97)
   // Also, first reinitialize vtable because it may have gotten out of synch
   // while the new class wasn't connected to the class hierarchy.
-  Universe::flush_dependents_on(k);
+  CodeCache::flush_dependents_on(k);
 }
 
 // ----------------------------------------------------------------------------
--- a/hotspot/src/share/vm/code/codeCache.cpp	Mon Jan 05 22:50:59 2015 -0500
+++ b/hotspot/src/share/vm/code/codeCache.cpp	Tue Jan 06 19:30:28 2015 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015, 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
@@ -1005,6 +1005,117 @@
   }
 }
 
+// Flushes compiled methods dependent on dependee.
+void CodeCache::flush_dependents_on(instanceKlassHandle dependee) {
+  assert_lock_strong(Compile_lock);
+
+  if (number_of_nmethods_with_dependencies() == 0) return;
+
+  // CodeCache can only be updated by a thread_in_VM and they will all be
+  // stopped during the safepoint so CodeCache will be safe to update without
+  // holding the CodeCache_lock.
+
+  KlassDepChange changes(dependee);
+
+  // Compute the dependent nmethods
+  if (mark_for_deoptimization(changes) > 0) {
+    // At least one nmethod has been marked for deoptimization
+    VM_Deoptimize op;
+    VMThread::execute(&op);
+  }
+}
+
+// Flushes compiled methods dependent on a particular CallSite
+// instance when its target is different than the given MethodHandle.
+void CodeCache::flush_dependents_on(Handle call_site, Handle method_handle) {
+  assert_lock_strong(Compile_lock);
+
+  if (number_of_nmethods_with_dependencies() == 0) return;
+
+  // CodeCache can only be updated by a thread_in_VM and they will all be
+  // stopped during the safepoint so CodeCache will be safe to update without
+  // holding the CodeCache_lock.
+
+  CallSiteDepChange changes(call_site(), method_handle());
+
+  // Compute the dependent nmethods that have a reference to a
+  // CallSite object.  We use InstanceKlass::mark_dependent_nmethod
+  // directly instead of CodeCache::mark_for_deoptimization because we
+  // want dependents on the call site class only not all classes in
+  // the ContextStream.
+  int marked = 0;
+  {
+    MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
+    InstanceKlass* call_site_klass = InstanceKlass::cast(call_site->klass());
+    marked = call_site_klass->mark_dependent_nmethods(changes);
+  }
+  if (marked > 0) {
+    // At least one nmethod has been marked for deoptimization
+    VM_Deoptimize op;
+    VMThread::execute(&op);
+  }
+}
+
+#ifdef HOTSWAP
+// Flushes compiled methods dependent on dependee in the evolutionary sense
+void CodeCache::flush_evol_dependents_on(instanceKlassHandle ev_k_h) {
+  // --- Compile_lock is not held. However we are at a safepoint.
+  assert_locked_or_safepoint(Compile_lock);
+  if (number_of_nmethods_with_dependencies() == 0) return;
+
+  // CodeCache can only be updated by a thread_in_VM and they will all be
+  // stopped during the safepoint so CodeCache will be safe to update without
+  // holding the CodeCache_lock.
+
+  // Compute the dependent nmethods
+  if (mark_for_evol_deoptimization(ev_k_h) > 0) {
+    // At least one nmethod has been marked for deoptimization
+
+    // All this already happens inside a VM_Operation, so we'll do all the work here.
+    // Stuff copied from VM_Deoptimize and modified slightly.
+
+    // We do not want any GCs to happen while we are in the middle of this VM operation
+    ResourceMark rm;
+    DeoptimizationMarker dm;
+
+    // Deoptimize all activations depending on marked nmethods
+    Deoptimization::deoptimize_dependents();
+
+    // Make the dependent methods not entrant (in VM_Deoptimize they are made zombies)
+    make_marked_nmethods_not_entrant();
+  }
+}
+#endif // HOTSWAP
+
+
+// Flushes compiled methods dependent on dependee
+void CodeCache::flush_dependents_on_method(methodHandle m_h) {
+  // --- Compile_lock is not held. However we are at a safepoint.
+  assert_locked_or_safepoint(Compile_lock);
+
+  // CodeCache can only be updated by a thread_in_VM and they will all be
+  // stopped dring the safepoint so CodeCache will be safe to update without
+  // holding the CodeCache_lock.
+
+  // Compute the dependent nmethods
+  if (mark_for_deoptimization(m_h()) > 0) {
+    // At least one nmethod has been marked for deoptimization
+
+    // All this already happens inside a VM_Operation, so we'll do all the work here.
+    // Stuff copied from VM_Deoptimize and modified slightly.
+
+    // We do not want any GCs to happen while we are in the middle of this VM operation
+    ResourceMark rm;
+    DeoptimizationMarker dm;
+
+    // Deoptimize all activations depending on marked nmethods
+    Deoptimization::deoptimize_dependents();
+
+    // Make the dependent methods not entrant (in VM_Deoptimize they are made zombies)
+    make_marked_nmethods_not_entrant();
+  }
+}
+
 void CodeCache::verify() {
   assert_locked_or_safepoint(CodeCache_lock);
   FOR_ALL_HEAPS(heap) {
--- a/hotspot/src/share/vm/code/codeCache.hpp	Mon Jan 05 22:50:59 2015 -0500
+++ b/hotspot/src/share/vm/code/codeCache.hpp	Tue Jan 06 19:30:28 2015 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015, 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
@@ -209,16 +209,28 @@
   static void verify_icholder_relocations();
 
   // Deoptimization
+ private:
   static int  mark_for_deoptimization(DepChange& changes);
 #ifdef HOTSWAP
   static int  mark_for_evol_deoptimization(instanceKlassHandle dependee);
 #endif // HOTSWAP
 
+ public:
   static void mark_all_nmethods_for_deoptimization();
   static int  mark_for_deoptimization(Method* dependee);
   static void make_marked_nmethods_zombies();
   static void make_marked_nmethods_not_entrant();
 
+  // Flushing and deoptimization
+  static void flush_dependents_on(instanceKlassHandle dependee);
+  static void flush_dependents_on(Handle call_site, Handle method_handle);
+#ifdef HOTSWAP
+  // Flushing and deoptimization in case of evolution
+  static void flush_evol_dependents_on(instanceKlassHandle dependee);
+#endif // HOTSWAP
+  // Support for fullspeed debugging
+  static void flush_dependents_on_method(methodHandle dependee);
+
   // tells how many nmethods have dependencies
   static int number_of_nmethods_with_dependencies();
 
--- a/hotspot/src/share/vm/memory/universe.cpp	Mon Jan 05 22:50:59 2015 -0500
+++ b/hotspot/src/share/vm/memory/universe.cpp	Tue Jan 06 19:30:28 2015 -0500
@@ -1074,119 +1074,6 @@
 }
 
 
-// %%% The Universe::flush_foo methods belong in CodeCache.
-
-// Flushes compiled methods dependent on dependee.
-void Universe::flush_dependents_on(instanceKlassHandle dependee) {
-  assert_lock_strong(Compile_lock);
-
-  if (CodeCache::number_of_nmethods_with_dependencies() == 0) return;
-
-  // CodeCache can only be updated by a thread_in_VM and they will all be
-  // stopped during the safepoint so CodeCache will be safe to update without
-  // holding the CodeCache_lock.
-
-  KlassDepChange changes(dependee);
-
-  // Compute the dependent nmethods
-  if (CodeCache::mark_for_deoptimization(changes) > 0) {
-    // At least one nmethod has been marked for deoptimization
-    VM_Deoptimize op;
-    VMThread::execute(&op);
-  }
-}
-
-// Flushes compiled methods dependent on a particular CallSite
-// instance when its target is different than the given MethodHandle.
-void Universe::flush_dependents_on(Handle call_site, Handle method_handle) {
-  assert_lock_strong(Compile_lock);
-
-  if (CodeCache::number_of_nmethods_with_dependencies() == 0) return;
-
-  // CodeCache can only be updated by a thread_in_VM and they will all be
-  // stopped during the safepoint so CodeCache will be safe to update without
-  // holding the CodeCache_lock.
-
-  CallSiteDepChange changes(call_site(), method_handle());
-
-  // Compute the dependent nmethods that have a reference to a
-  // CallSite object.  We use InstanceKlass::mark_dependent_nmethod
-  // directly instead of CodeCache::mark_for_deoptimization because we
-  // want dependents on the call site class only not all classes in
-  // the ContextStream.
-  int marked = 0;
-  {
-    MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
-    InstanceKlass* call_site_klass = InstanceKlass::cast(call_site->klass());
-    marked = call_site_klass->mark_dependent_nmethods(changes);
-  }
-  if (marked > 0) {
-    // At least one nmethod has been marked for deoptimization
-    VM_Deoptimize op;
-    VMThread::execute(&op);
-  }
-}
-
-#ifdef HOTSWAP
-// Flushes compiled methods dependent on dependee in the evolutionary sense
-void Universe::flush_evol_dependents_on(instanceKlassHandle ev_k_h) {
-  // --- Compile_lock is not held. However we are at a safepoint.
-  assert_locked_or_safepoint(Compile_lock);
-  if (CodeCache::number_of_nmethods_with_dependencies() == 0) return;
-
-  // CodeCache can only be updated by a thread_in_VM and they will all be
-  // stopped during the safepoint so CodeCache will be safe to update without
-  // holding the CodeCache_lock.
-
-  // Compute the dependent nmethods
-  if (CodeCache::mark_for_evol_deoptimization(ev_k_h) > 0) {
-    // At least one nmethod has been marked for deoptimization
-
-    // All this already happens inside a VM_Operation, so we'll do all the work here.
-    // Stuff copied from VM_Deoptimize and modified slightly.
-
-    // We do not want any GCs to happen while we are in the middle of this VM operation
-    ResourceMark rm;
-    DeoptimizationMarker dm;
-
-    // Deoptimize all activations depending on marked nmethods
-    Deoptimization::deoptimize_dependents();
-
-    // Make the dependent methods not entrant (in VM_Deoptimize they are made zombies)
-    CodeCache::make_marked_nmethods_not_entrant();
-  }
-}
-#endif // HOTSWAP
-
-
-// Flushes compiled methods dependent on dependee
-void Universe::flush_dependents_on_method(methodHandle m_h) {
-  // --- Compile_lock is not held. However we are at a safepoint.
-  assert_locked_or_safepoint(Compile_lock);
-
-  // CodeCache can only be updated by a thread_in_VM and they will all be
-  // stopped dring the safepoint so CodeCache will be safe to update without
-  // holding the CodeCache_lock.
-
-  // Compute the dependent nmethods
-  if (CodeCache::mark_for_deoptimization(m_h()) > 0) {
-    // At least one nmethod has been marked for deoptimization
-
-    // All this already happens inside a VM_Operation, so we'll do all the work here.
-    // Stuff copied from VM_Deoptimize and modified slightly.
-
-    // We do not want any GCs to happen while we are in the middle of this VM operation
-    ResourceMark rm;
-    DeoptimizationMarker dm;
-
-    // Deoptimize all activations depending on marked nmethods
-    Deoptimization::deoptimize_dependents();
-
-    // Make the dependent methods not entrant (in VM_Deoptimize they are made zombies)
-    CodeCache::make_marked_nmethods_not_entrant();
-  }
-}
-
 void Universe::print() {
   print_on(gclog_or_tty);
 }
--- a/hotspot/src/share/vm/memory/universe.hpp	Mon Jan 05 22:50:59 2015 -0500
+++ b/hotspot/src/share/vm/memory/universe.hpp	Tue Jan 06 19:30:28 2015 -0500
@@ -484,16 +484,6 @@
   static uintptr_t verify_mark_bits()         PRODUCT_RETURN0;
   static uintptr_t verify_mark_mask()         PRODUCT_RETURN0;
 
-  // Flushing and deoptimization
-  static void flush_dependents_on(instanceKlassHandle dependee);
-  static void flush_dependents_on(Handle call_site, Handle method_handle);
-#ifdef HOTSWAP
-  // Flushing and deoptimization in case of evolution
-  static void flush_evol_dependents_on(instanceKlassHandle dependee);
-#endif // HOTSWAP
-  // Support for fullspeed debugging
-  static void flush_dependents_on_method(methodHandle dependee);
-
   // Compiler support
   static int base_vtable_size()               { return _base_vtable_size; }
 };
--- a/hotspot/src/share/vm/oops/method.cpp	Mon Jan 05 22:50:59 2015 -0500
+++ b/hotspot/src/share/vm/oops/method.cpp	Tue Jan 06 19:30:28 2015 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015, 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
@@ -25,6 +25,7 @@
 #include "precompiled.hpp"
 #include "classfile/metadataOnStackMark.hpp"
 #include "classfile/systemDictionary.hpp"
+#include "code/codeCache.hpp"
 #include "code/debugInfoRec.hpp"
 #include "gc_interface/collectedHeap.inline.hpp"
 #include "interpreter/bytecodeStream.hpp"
@@ -1727,7 +1728,7 @@
     // Deoptimize all dependents on this method
     HandleMark hm(thread);
     methodHandle mh(thread, method);
-    Universe::flush_dependents_on_method(mh);
+    CodeCache::flush_dependents_on_method(mh);
   }
 }
 
--- a/hotspot/src/share/vm/prims/jvmtiRedefineClasses.cpp	Mon Jan 05 22:50:59 2015 -0500
+++ b/hotspot/src/share/vm/prims/jvmtiRedefineClasses.cpp	Tue Jan 06 19:30:28 2015 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2015, 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
@@ -3766,7 +3766,7 @@
   // All dependencies have been recorded from startup or this is a second or
   // subsequent use of RedefineClasses
   if (JvmtiExport::all_dependencies_are_recorded()) {
-    Universe::flush_evol_dependents_on(k_h);
+    CodeCache::flush_evol_dependents_on(k_h);
   } else {
     CodeCache::mark_all_nmethods_for_deoptimization();
 
--- a/hotspot/src/share/vm/prims/methodHandles.cpp	Mon Jan 05 22:50:59 2015 -0500
+++ b/hotspot/src/share/vm/prims/methodHandles.cpp	Tue Jan 06 19:30:28 2015 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2015, 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
@@ -24,6 +24,7 @@
 
 #include "precompiled.hpp"
 #include "classfile/stringTable.hpp"
+#include "code/codeCache.hpp"
 #include "compiler/compileBroker.hpp"
 #include "interpreter/interpreter.hpp"
 #include "interpreter/oopMapCache.hpp"
@@ -1245,7 +1246,7 @@
   {
     // Walk all nmethods depending on this call site.
     MutexLocker mu(Compile_lock, thread);
-    Universe::flush_dependents_on(call_site, target);
+    CodeCache::flush_dependents_on(call_site, target);
     java_lang_invoke_CallSite::set_target(call_site(), target());
   }
 }
@@ -1257,7 +1258,7 @@
   {
     // Walk all nmethods depending on this call site.
     MutexLocker mu(Compile_lock, thread);
-    Universe::flush_dependents_on(call_site, target);
+    CodeCache::flush_dependents_on(call_site, target);
     java_lang_invoke_CallSite::set_target_volatile(call_site(), target());
   }
 }