--- old/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp 2015-04-01 13:20:02.099812852 +0200 +++ new/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp 2015-04-01 13:20:01.975812857 +0200 @@ -1770,6 +1770,11 @@ _g1h = this; + _workers = new FlexibleWorkGang("GC Thread", ParallelGCThreads, + /* are_GC_task_threads */true, + /* are_ConcurrentGC_threads */false); + _workers->initialize_workers(); + _allocator = G1Allocator::create_allocator(_g1h); _humongous_object_threshold_in_words = HeapRegion::GrainWords / 2; @@ -1854,7 +1859,8 @@ = new G1SATBCardTableLoggingModRefBS(reserved_region()); bs->initialize(); assert(bs->is_a(BarrierSet::G1SATBCTLogging), "sanity"); - set_barrier_set(bs); + _barrier_set = bs; + oopDesc::set_bs(bs); // Also create a G1 rem set. _g1_rem_set = new G1RemSet(this, g1_barrier_set()); @@ -2035,6 +2041,11 @@ return HeapRegion::max_region_size(); } +void G1CollectedHeap::post_initialize() { + CollectedHeap::post_initialize(); + ref_processing_init(); +} + void G1CollectedHeap::ref_processing_init() { // Reference processing in G1 currently works as follows: // @@ -2071,7 +2082,6 @@ // * Discovery is atomic - i.e. not concurrent. // * Reference discovery will not need a barrier. - SharedHeap::ref_processing_init(); MemRegion mr = reserved_region(); // Concurrent Mark ref processor @@ -2158,6 +2168,10 @@ guarantee(!cl.failures(), "all GC time stamps should have been reset"); } +void G1CollectedHeap::set_heap_lock_held_for_gc(bool value) { + _thread_holds_heap_lock_for_gc = value; +} + bool G1CollectedHeap::heap_lock_held_for_gc() { Thread* t = Thread::current(); return Heap_lock->owned_by_self() @@ -2507,11 +2521,6 @@ } }; -void G1CollectedHeap::space_iterate(SpaceClosure* cl) { - SpaceClosureRegionClosure blk(cl); - heap_region_iterate(&blk); -} - void G1CollectedHeap::heap_region_iterate(HeapRegionClosure* cl) const { _hrm.iterate(cl); } --- old/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp 2015-04-01 13:20:02.371812840 +0200 +++ new/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp 2015-04-01 13:20:02.255812845 +0200 @@ -76,6 +76,7 @@ class EvacuationFailedInfo; class nmethod; class Ticks; +class FlexibleWorkGang; typedef OverflowTaskQueue RefToScanQueue; typedef GenericTaskQueueSet RefToScanQueueSet; @@ -204,6 +205,8 @@ // The one and only G1CollectedHeap, so static functions can find it. static G1CollectedHeap* _g1h; + FlexibleWorkGang* _workers; + static size_t _humongous_object_threshold_in_words; // The secondary free list which contains regions that have been @@ -605,6 +608,7 @@ void enqueue_discovered_references(uint no_of_gc_workers); public: + FlexibleWorkGang* workers() const { return _workers; } G1Allocator* allocator() { return _allocator; @@ -630,8 +634,8 @@ inline AllocationContextStats& allocation_context_stats(); // Do anything common to GC's. - virtual void gc_prologue(bool full); - virtual void gc_epilogue(bool full); + void gc_prologue(bool full); + void gc_epilogue(bool full); inline void set_humongous_is_live(oop obj); @@ -1000,6 +1004,9 @@ // Return the (conservative) maximum heap alignment for any G1 heap static size_t conservative_max_heap_alignment(); + // Does operations required after initialization has been done. + void post_initialize(); + // Initialize weak reference processing. virtual void ref_processing_init(); @@ -1114,11 +1121,10 @@ // or the calling thread is a par gc thread and the heap_lock is held // by the vm thread doing a gc operation. bool heap_lock_held_for_gc(); - - void set_heap_lock_held_for_gc(bool value) { _thread_holds_heap_lock_for_gc = value; } - #endif // PRODUCT + void set_heap_lock_held_for_gc(bool value) PRODUCT_RETURN; + // If G1VerifyBitmaps is set, verify that the marking bitmaps for // the given region do not have any spurious marks. If errors are // detected, print appropriate error messages and crash. @@ -1273,9 +1279,6 @@ object_iterate(cl); } - // Iterate over all spaces in use in the heap, in ascending address order. - virtual void space_iterate(SpaceClosure* cl); - // Iterate over heap regions, in address order, terminating the // iteration early if the "doHeapRegion" method returns "true". void heap_region_iterate(HeapRegionClosure* blk) const; @@ -1320,7 +1323,7 @@ // A CollectedHeap will contain some number of spaces. This finds the // space containing a given address, or else returns NULL. - virtual Space* space_containing(const void* addr) const; + Space* space_containing(const void* addr) const; // Returns the HeapRegion that contains addr. addr must not be NULL. template --- old/src/share/vm/gc_interface/collectedHeap.hpp 2015-04-01 13:20:02.591812831 +0200 +++ new/src/share/vm/gc_interface/collectedHeap.hpp 2015-04-01 13:20:02.483812835 +0200 @@ -207,7 +207,7 @@ // In many heaps, there will be a need to perform some initialization activities // after the Universe is fully formed, but before general heap allocation is allowed. // This is the correct place to place such initialization methods. - virtual void post_initialize() = 0; + virtual void post_initialize(); // Stop any onging concurrent work and prepare for exit. virtual void stop() {} --- old/src/share/vm/memory/genCollectedHeap.cpp 2015-04-01 13:20:02.811812822 +0200 +++ new/src/share/vm/memory/genCollectedHeap.cpp 2015-04-01 13:20:02.695812827 +0200 @@ -85,6 +85,14 @@ _full_collections_completed(0) { assert(policy != NULL, "Sanity check"); + if (UseConcMarkSweepGC) { + _workers = new FlexibleWorkGang("GC Thread", ParallelGCThreads, + /* are_GC_task_threads */true, + /* are_ConcurrentGC_threads */false); + _workers->initialize_workers(); + } else { + _workers = NULL; + } } jint GenCollectedHeap::initialize() { @@ -118,7 +126,8 @@ initialize_reserved_region((HeapWord*)heap_rs.base(), (HeapWord*)(heap_rs.base() + heap_rs.size())); _rem_set = collector_policy()->create_rem_set(reserved_region()); - set_barrier_set(rem_set()->bs()); + _barrier_set = rem_set()->bs(); + oopDesc::set_bs(_barrier_set); _gch = this; @@ -166,7 +175,8 @@ } void GenCollectedHeap::post_initialize() { - SharedHeap::post_initialize(); + CollectedHeap::post_initialize(); + ref_processing_init(); GenCollectorPolicy *policy = (GenCollectorPolicy *)collector_policy(); guarantee(policy->is_generation_policy(), "Illegal policy type"); assert((_young_gen->kind() == Generation::DefNew) || @@ -185,7 +195,6 @@ } void GenCollectedHeap::ref_processing_init() { - SharedHeap::ref_processing_init(); _young_gen->ref_processor_init(); _old_gen->ref_processor_init(); } @@ -560,7 +569,8 @@ } void GenCollectedHeap::set_par_threads(uint t) { - SharedHeap::set_par_threads(t); + assert(t == 0 || !UseSerialGC, "Cannot have parallel threads"); + CollectedHeap::set_par_threads(t); set_n_termination(t); } @@ -1093,11 +1103,6 @@ } } -void GenCollectedHeap::space_iterate(SpaceClosure* cl) { - _young_gen->space_iterate(cl, true); - _old_gen->space_iterate(cl, true); -} - bool GenCollectedHeap::is_maximal_no_gc() const { return _young_gen->is_maximal_no_gc() && _old_gen->is_maximal_no_gc(); } --- old/src/share/vm/memory/genCollectedHeap.hpp 2015-04-01 13:20:03.031812813 +0200 +++ new/src/share/vm/memory/genCollectedHeap.hpp 2015-04-01 13:20:02.915812817 +0200 @@ -31,6 +31,7 @@ #include "memory/sharedHeap.hpp" class SubTasksDone; +class FlexibleWorkGang; // A "GenCollectedHeap" is a SharedHeap that uses generational // collection. It has two generations, young and old. @@ -93,6 +94,8 @@ // In block contents verification, the number of header words to skip NOT_PRODUCT(static size_t _skip_header_HeapWords;) + FlexibleWorkGang* _workers; + protected: // Helper functions for allocation HeapWord* attempt_allocation(size_t size, @@ -125,6 +128,8 @@ public: GenCollectedHeap(GenCollectorPolicy *policy); + FlexibleWorkGang* workers() const { return _workers; } + GCStats* gc_stats(int level) const; // Returns JNI_OK on success @@ -331,7 +336,6 @@ _old_gen->update_gc_stats(current_level, full); } - // Override. bool no_gc_in_progress() { return !is_gc_active(); } // Override. @@ -363,8 +367,6 @@ // If "old_to_young" determines the order. void generation_iterate(GenClosure* cl, bool old_to_young); - void space_iterate(SpaceClosure* cl); - // Return "true" if all generations have reached the // maximal committed limit that they can reach, without a garbage // collection. @@ -531,8 +533,8 @@ void record_gen_tops_before_GC() PRODUCT_RETURN; protected: - virtual void gc_prologue(bool full); - virtual void gc_epilogue(bool full); + void gc_prologue(bool full); + void gc_epilogue(bool full); }; #endif // SHARE_VM_MEMORY_GENCOLLECTEDHEAP_HPP --- old/src/share/vm/memory/sharedHeap.cpp 2015-04-01 13:20:03.231812804 +0200 +++ new/src/share/vm/memory/sharedHeap.cpp 2015-04-01 13:20:03.119812809 +0200 @@ -36,25 +36,8 @@ #include "utilities/workgroup.hpp" SharedHeap::SharedHeap() : - CollectedHeap(), - _workers(NULL) -{ - if (UseConcMarkSweepGC || UseG1GC) { - _workers = new FlexibleWorkGang("GC Thread", ParallelGCThreads, - /* are_GC_task_threads */true, - /* are_ConcurrentGC_threads */false); - if (_workers == NULL) { - vm_exit_during_initialization("Failed necessary allocation."); - } else { - _workers->initialize_workers(); - } - } -} - -void SharedHeap::set_par_threads(uint t) { - assert(t == 0 || !UseSerialGC, "Cannot have parallel threads"); - _n_par_threads = t; -} + CollectedHeap() +{} SharedHeap::StrongRootsScope::StrongRootsScope(SharedHeap* heap, bool activate) : MarkScope(activate), _sh(heap) @@ -69,16 +52,3 @@ SharedHeap::StrongRootsScope::~StrongRootsScope() { Threads::assert_all_threads_claimed(); } - -void SharedHeap::set_barrier_set(BarrierSet* bs) { - _barrier_set = bs; - // Cached barrier set for fast access in oops - oopDesc::set_bs(bs); -} - -void SharedHeap::post_initialize() { - CollectedHeap::post_initialize(); - ref_processing_init(); -} - -void SharedHeap::ref_processing_init() {} --- old/src/share/vm/memory/sharedHeap.hpp 2015-04-01 13:20:03.427812796 +0200 +++ new/src/share/vm/memory/sharedHeap.hpp 2015-04-01 13:20:03.315812801 +0200 @@ -26,27 +26,12 @@ #define SHARE_VM_MEMORY_SHAREDHEAP_HPP #include "gc_interface/collectedHeap.hpp" -#include "memory/generation.hpp" // A "SharedHeap" is an implementation of a java heap for HotSpot. This // is an abstract class: there may be many different kinds of heaps. This // class defines the functions that a heap must implement, and contains // infrastructure common to all heaps. -class Generation; -class BarrierSet; -class GenRemSet; -class Space; -class SpaceClosure; -class OopClosure; -class OopsInGenClosure; -class ObjectClosure; -class SubTasksDone; -class WorkGang; -class FlexibleWorkGang; -class CollectorPolicy; -class KlassClosure; - // Note on use of FlexibleWorkGang's for GC. // There are three places where task completion is determined. // In @@ -101,39 +86,12 @@ class SharedHeap : public CollectedHeap { friend class VMStructs; - friend class VM_GC_Operation; - friend class VM_CGC_Operation; - protected: - // If we're doing parallel GC, use this gang of threads. - FlexibleWorkGang* _workers; - // Full initialization is done in a concrete subtype's "initialize" // function. SharedHeap(); public: - void set_barrier_set(BarrierSet* bs); - - // Does operations required after initialization has been done. - virtual void post_initialize(); - - // Initialization of ("weak") reference processing support - virtual void ref_processing_init(); - - // Iteration functions. - void oop_iterate(ExtendedOopClosure* cl) = 0; - - // Iterate over all spaces in use in the heap, in an undefined order. - virtual void space_iterate(SpaceClosure* cl) = 0; - - // A SharedHeap will contain some number of spaces. This finds the - // space whose reserved area contains the given address, or else returns - // NULL. - virtual Space* space_containing(const void* addr) const = 0; - - bool no_gc_in_progress() { return !is_gc_active(); } - // Note, the below comment needs to be updated to reflect the changes // introduced by JDK-8076225. This should be done as part of JDK-8076289. // @@ -174,25 +132,6 @@ StrongRootsScope(SharedHeap* heap, bool activate = true); ~StrongRootsScope(); }; - - private: - - public: - FlexibleWorkGang* workers() const { return _workers; } - - // The functions below are helper functions that a subclass of - // "SharedHeap" can use in the implementation of its virtual - // functions. - -public: - - // Do anything common to GC's. - virtual void gc_prologue(bool full) = 0; - virtual void gc_epilogue(bool full) = 0; - - // Sets the number of parallel threads that will be doing tasks - // (such as process roots) subsequently. - virtual void set_par_threads(uint t); -}; + }; #endif // SHARE_VM_MEMORY_SHAREDHEAP_HPP