src/hotspot/share/gc/z/zHeap.cpp
changeset 59040 1251d78fafbf
parent 58815 a4cdca87152b
child 59254 58f842703bc5
equal deleted inserted replaced
59039:c60978f87d45 59040:1251d78fafbf
    38 #include "gc/z/zVerify.hpp"
    38 #include "gc/z/zVerify.hpp"
    39 #include "gc/z/zWorkers.inline.hpp"
    39 #include "gc/z/zWorkers.inline.hpp"
    40 #include "logging/log.hpp"
    40 #include "logging/log.hpp"
    41 #include "memory/iterator.hpp"
    41 #include "memory/iterator.hpp"
    42 #include "memory/resourceArea.hpp"
    42 #include "memory/resourceArea.hpp"
       
    43 #include "runtime/handshake.hpp"
    43 #include "runtime/safepoint.hpp"
    44 #include "runtime/safepoint.hpp"
    44 #include "runtime/thread.hpp"
    45 #include "runtime/thread.hpp"
    45 #include "utilities/debug.hpp"
    46 #include "utilities/debug.hpp"
    46 
    47 
    47 static const ZStatSampler ZSamplerHeapUsedBeforeMark("Memory", "Heap Used Before Mark", ZStatUnitBytes);
    48 static const ZStatSampler ZSamplerHeapUsedBeforeMark("Memory", "Heap Used Before Mark", ZStatUnitBytes);
   313   ZResurrection::block();
   314   ZResurrection::block();
   314 
   315 
   315   // Process weak roots
   316   // Process weak roots
   316   _weak_roots_processor.process_weak_roots();
   317   _weak_roots_processor.process_weak_roots();
   317 
   318 
   318   // Prepare to unload unused classes and code
   319   // Prepare to unload stale metadata and nmethods
   319   _unload.prepare();
   320   _unload.prepare();
   320 
   321 
   321   return true;
   322   return true;
   322 }
   323 }
   323 
   324 
   324 void ZHeap::set_soft_reference_policy(bool clear) {
   325 void ZHeap::set_soft_reference_policy(bool clear) {
   325   _reference_processor.set_soft_reference_policy(clear);
   326   _reference_processor.set_soft_reference_policy(clear);
   326 }
   327 }
       
   328 
       
   329 class ZRendezvousClosure : public ThreadClosure {
       
   330 public:
       
   331   virtual void do_thread(Thread* thread) {}
       
   332 };
   327 
   333 
   328 void ZHeap::process_non_strong_references() {
   334 void ZHeap::process_non_strong_references() {
   329   // Process Soft/Weak/Final/PhantomReferences
   335   // Process Soft/Weak/Final/PhantomReferences
   330   _reference_processor.process_references();
   336   _reference_processor.process_references();
   331 
   337 
   332   // Process concurrent weak roots
   338   // Process concurrent weak roots
   333   _weak_roots_processor.process_concurrent_weak_roots();
   339   _weak_roots_processor.process_concurrent_weak_roots();
   334 
   340 
   335   // Unload unused classes and code
   341   // Unlink stale metadata and nmethods
   336   _unload.unload();
   342   _unload.unlink();
       
   343 
       
   344   // Perform a handshake. This is needed 1) to make sure that stale
       
   345   // metadata and nmethods are no longer observable. And 2), to
       
   346   // prevent the race where a mutator first loads an oop, which is
       
   347   // logically null but not yet cleared. Then this oop gets cleared
       
   348   // by the reference processor and resurrection is unblocked. At
       
   349   // this point the mutator could see the unblocked state and pass
       
   350   // this invalid oop through the normal barrier path, which would
       
   351   // incorrectly try to mark the oop.
       
   352   ZRendezvousClosure cl;
       
   353   Handshake::execute(&cl);
       
   354 
       
   355   // Purge stale metadata and nmethods that were unlinked
       
   356   _unload.purge();
   337 
   357 
   338   // Unblock resurrection of weak/phantom references
   358   // Unblock resurrection of weak/phantom references
   339   ZResurrection::unblock();
   359   ZResurrection::unblock();
   340 
   360 
   341   // Enqueue Soft/Weak/Final/PhantomReferences. Note that this
   361   // Enqueue Soft/Weak/Final/PhantomReferences. Note that this
   403 }
   423 }
   404 
   424 
   405 void ZHeap::relocate_start() {
   425 void ZHeap::relocate_start() {
   406   assert(SafepointSynchronize::is_at_safepoint(), "Should be at safepoint");
   426   assert(SafepointSynchronize::is_at_safepoint(), "Should be at safepoint");
   407 
   427 
   408   // Finish unloading of classes and code
   428   // Finish unloading stale metadata and nmethods
   409   _unload.finish();
   429   _unload.finish();
   410 
   430 
   411   // Flip address view
   431   // Flip address view
   412   flip_to_remapped();
   432   flip_to_remapped();
   413 
   433