changeset 8969:a8441ccaff15

8151539: Remove duplicate AlwaysTrueClosures Reviewed-by: tschatzl, mgerdin, kbarrett, drwhite
author stefank
date Tue, 15 Mar 2016 10:11:02 +0100
parents 7fe2cda84af1
children 4fdf42cda0d5
files src/share/vm/gc_implementation/g1/g1MarkSweep.cpp src/share/vm/gc_implementation/parallelScavenge/psMarkSweep.cpp src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.cpp src/share/vm/memory/genCollectedHeap.cpp src/share/vm/memory/iterator.hpp src/share/vm/memory/referenceProcessor.cpp src/share/vm/prims/whitebox.cpp src/share/vm/runtime/jniHandles.cpp src/share/vm/runtime/jniHandles.hpp
diffstat 9 files changed, 27 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/gc_implementation/g1/g1MarkSweep.cpp	Thu Apr 25 05:12:03 2019 +0100
+++ b/src/share/vm/gc_implementation/g1/g1MarkSweep.cpp	Tue Mar 15 10:11:02 2016 +0100
@@ -237,12 +237,6 @@
   }
 };
 
-class G1AlwaysTrueClosure: public BoolObjectClosure {
-public:
-  bool do_object_b(oop p) { return true; }
-};
-static G1AlwaysTrueClosure always_true;
-
 void G1MarkSweep::mark_sweep_phase3() {
   G1CollectedHeap* g1h = G1CollectedHeap::heap();
 
@@ -266,7 +260,7 @@
 
   // Now adjust pointers in remaining weak roots.  (All of which should
   // have been cleared if they pointed to non-surviving objects.)
-  JNIHandles::weak_oops_do(&always_true, &GenMarkSweep::adjust_pointer_closure);
+  JNIHandles::weak_oops_do(&GenMarkSweep::adjust_pointer_closure);
 
   if (G1StringDedup::is_enabled()) {
     G1StringDedup::oops_do(&GenMarkSweep::adjust_pointer_closure);
--- a/src/share/vm/gc_implementation/parallelScavenge/psMarkSweep.cpp	Thu Apr 25 05:12:03 2019 +0100
+++ b/src/share/vm/gc_implementation/parallelScavenge/psMarkSweep.cpp	Tue Mar 15 10:11:02 2016 +0100
@@ -594,13 +594,6 @@
   old_gen->precompact();
 }
 
-// This should be moved to the shared markSweep code!
-class PSAlwaysTrueClosure: public BoolObjectClosure {
-public:
-  bool do_object_b(oop p) { return true; }
-};
-static PSAlwaysTrueClosure always_true;
-
 void PSMarkSweep::mark_sweep_phase3() {
   // Adjust the pointers to reflect the new locations
   GCTraceTime tm("phase 3", PrintGCDetails && Verbose, true, _gc_timer, _gc_tracer->gc_id());
@@ -630,7 +623,7 @@
   // Now adjust pointers in remaining weak roots.  (All of which should
   // have been cleared if they pointed to non-surviving objects.)
   // Global (weak) JNI handles
-  JNIHandles::weak_oops_do(&always_true, adjust_pointer_closure());
+  JNIHandles::weak_oops_do(adjust_pointer_closure());
 
   CodeBlobToOopClosure adjust_from_blobs(adjust_pointer_closure(), CodeBlobToOopClosure::FixRelocations);
   CodeCache::blobs_do(&adjust_from_blobs);
--- a/src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.cpp	Thu Apr 25 05:12:03 2019 +0100
+++ b/src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.cpp	Tue Mar 15 10:11:02 2016 +0100
@@ -2441,13 +2441,6 @@
   cld->oops_do(&mark_and_push_closure, &follow_klass_closure, true);
 }
 
-// This should be moved to the shared markSweep code!
-class PSAlwaysTrueClosure: public BoolObjectClosure {
-public:
-  bool do_object_b(oop p) { return true; }
-};
-static PSAlwaysTrueClosure always_true;
-
 void PSParallelCompact::adjust_roots() {
   // Adjust the pointers to reflect the new locations
   GCTraceTime tm("adjust roots", print_phases(), true, &_gc_timer, _gc_tracer.gc_id());
@@ -2470,7 +2463,7 @@
   // Now adjust pointers in remaining weak roots.  (All of which should
   // have been cleared if they pointed to non-surviving objects.)
   // Global (weak) JNI handles
-  JNIHandles::weak_oops_do(&always_true, adjust_pointer_closure());
+  JNIHandles::weak_oops_do(adjust_pointer_closure());
 
   CodeBlobToOopClosure adjust_from_blobs(adjust_pointer_closure(), CodeBlobToOopClosure::FixRelocations);
   CodeCache::blobs_do(&adjust_from_blobs);
--- a/src/share/vm/memory/genCollectedHeap.cpp	Thu Apr 25 05:12:03 2019 +0100
+++ b/src/share/vm/memory/genCollectedHeap.cpp	Tue Mar 15 10:11:02 2016 +0100
@@ -745,14 +745,8 @@
 }
 
 
-class AlwaysTrueClosure: public BoolObjectClosure {
-public:
-  bool do_object_b(oop p) { return true; }
-};
-static AlwaysTrueClosure always_true;
-
 void GenCollectedHeap::gen_process_weak_roots(OopClosure* root_closure) {
-  JNIHandles::weak_oops_do(&always_true, root_closure);
+  JNIHandles::weak_oops_do(root_closure);
   for (int i = 0; i < _n_gens; i++) {
     _gens[i]->ref_processor()->weak_oops_do(root_closure);
   }
--- a/src/share/vm/memory/iterator.hpp	Thu Apr 25 05:12:03 2019 +0100
+++ b/src/share/vm/memory/iterator.hpp	Tue Mar 15 10:11:02 2016 +0100
@@ -219,6 +219,16 @@
   virtual bool do_object_b(oop obj) = 0;
 };
 
+class AlwaysTrueClosure: public BoolObjectClosure {
+ public:
+  bool do_object_b(oop p) { return true; }
+};
+
+class AlwaysFalseClosure : public BoolObjectClosure {
+ public:
+  bool do_object_b(oop p) { return false; }
+};
+
 // Applies an oop closure to all ref fields in objects iterated over in an
 // object iteration.
 class ObjectToOopClosure: public ObjectClosure {
--- a/src/share/vm/memory/referenceProcessor.cpp	Thu Apr 25 05:12:03 2019 +0100
+++ b/src/share/vm/memory/referenceProcessor.cpp	Tue Mar 15 10:11:02 2016 +0100
@@ -275,11 +275,6 @@
 #ifndef PRODUCT
 // Calculate the number of jni handles.
 uint ReferenceProcessor::count_jni_refs() {
-  class AlwaysAliveClosure: public BoolObjectClosure {
-  public:
-    virtual bool do_object_b(oop obj) { return true; }
-  };
-
   class CountHandleClosure: public OopClosure {
   private:
     int _count;
@@ -290,8 +285,7 @@
     int count() { return _count; }
   };
   CountHandleClosure global_handle_count;
-  AlwaysAliveClosure always_alive;
-  JNIHandles::weak_oops_do(&always_alive, &global_handle_count);
+  JNIHandles::weak_oops_do(&global_handle_count);
   return global_handle_count.count();
 }
 #endif
--- a/src/share/vm/prims/whitebox.cpp	Thu Apr 25 05:12:03 2019 +0100
+++ b/src/share/vm/prims/whitebox.cpp	Tue Mar 15 10:11:02 2016 +0100
@@ -26,6 +26,7 @@
 
 #include "memory/metadataFactory.hpp"
 #include "memory/metaspaceShared.hpp"
+#include "memory/iterator.hpp"
 #include "memory/universe.hpp"
 #include "oops/oop.inline.hpp"
 
@@ -583,11 +584,6 @@
   bool allow_nested_vm_operations() const        { return true; }
 };
 
-class AlwaysFalseClosure : public BoolObjectClosure {
- public:
-  bool do_object_b(oop p) { return false; }
-};
-
 static AlwaysFalseClosure always_false;
 
 class VM_WhiteBoxCleanMethodData : public VM_WhiteBoxOperation {
--- a/src/share/vm/runtime/jniHandles.cpp	Thu Apr 25 05:12:03 2019 +0100
+++ b/src/share/vm/runtime/jniHandles.cpp	Tue Mar 15 10:11:02 2016 +0100
@@ -24,6 +24,7 @@
 
 #include "precompiled.hpp"
 #include "classfile/systemDictionary.hpp"
+#include "memory/iterator.hpp"
 #include "oops/oop.inline.hpp"
 #include "prims/jvmtiExport.hpp"
 #include "runtime/jniHandles.hpp"
@@ -129,6 +130,12 @@
 }
 
 
+void JNIHandles::weak_oops_do(OopClosure* f) {
+  AlwaysTrueClosure always_true;
+  weak_oops_do(&always_true, f);
+}
+
+
 void JNIHandles::initialize() {
   _global_handles      = JNIHandleBlock::allocate_block();
   _weak_global_handles = JNIHandleBlock::allocate_block();
@@ -186,11 +193,6 @@
 }
 
 
-class AlwaysAliveClosure: public BoolObjectClosure {
-public:
-  bool do_object_b(oop obj) { return true; }
-};
-
 class CountHandleClosure: public OopClosure {
 private:
   int _count;
@@ -212,9 +214,8 @@
          "JNIHandles not initialized");
 
   CountHandleClosure global_handle_count;
-  AlwaysAliveClosure always_alive;
   oops_do(&global_handle_count);
-  weak_oops_do(&always_alive, &global_handle_count);
+  weak_oops_do(&global_handle_count);
 
   st->print_cr("JNI global references: %d", global_handle_count.count());
   st->cr();
@@ -231,10 +232,9 @@
 
 void JNIHandles::verify() {
   VerifyHandleClosure verify_handle;
-  AlwaysAliveClosure always_alive;
 
   oops_do(&verify_handle);
-  weak_oops_do(&always_alive, &verify_handle);
+  weak_oops_do(&verify_handle);
 }
 
 
--- a/src/share/vm/runtime/jniHandles.hpp	Thu Apr 25 05:12:03 2019 +0100
+++ b/src/share/vm/runtime/jniHandles.hpp	Tue Mar 15 10:11:02 2016 +0100
@@ -86,6 +86,8 @@
   static void oops_do(OopClosure* f);
   // Traversal of weak global handles. Unreachable oops are cleared.
   static void weak_oops_do(BoolObjectClosure* is_alive, OopClosure* f);
+  // Traversal of weak global handles.
+  static void weak_oops_do(OopClosure* f);
 };