--- old/src/share/vm/gc/g1/g1CollectedHeap.cpp 2017-02-20 12:07:12.857493671 +0100 +++ new/src/share/vm/gc/g1/g1CollectedHeap.cpp 2017-02-20 12:07:12.721492996 +0100 @@ -3531,6 +3531,8 @@ class G1StringSymbolTableUnlinkTask : public AbstractGangTask { private: BoolObjectClosure* _is_alive; + G1StringDedupUnlinkOrOopsDoClosure _dedup_closure; + int _initial_string_table_size; int _initial_symbol_table_size; @@ -3542,12 +3544,16 @@ int _symbols_processed; int _symbols_removed; + bool _process_string_dedup; + public: - G1StringSymbolTableUnlinkTask(BoolObjectClosure* is_alive, bool process_strings, bool process_symbols) : + G1StringSymbolTableUnlinkTask(BoolObjectClosure* is_alive, bool process_strings, bool process_symbols, bool process_string_dedup) : AbstractGangTask("String/Symbol Unlinking"), _is_alive(is_alive), + _dedup_closure(is_alive, NULL, false), _process_strings(process_strings), _strings_processed(0), _strings_removed(0), - _process_symbols(process_symbols), _symbols_processed(0), _symbols_removed(0) { + _process_symbols(process_symbols), _symbols_processed(0), _symbols_removed(0), + _process_string_dedup(process_string_dedup) { _initial_string_table_size = StringTable::the_table()->table_size(); _initial_symbol_table_size = SymbolTable::the_table()->table_size(); @@ -3590,6 +3596,9 @@ Atomic::add(symbols_processed, &_symbols_processed); Atomic::add(symbols_removed, &_symbols_removed); } + if (_process_string_dedup) { + G1StringDedup::parallel_unlink(&_dedup_closure, worker_id); + } } size_t strings_processed() const { return (size_t)_strings_processed; } @@ -3831,9 +3840,9 @@ public: // The constructor is run in the VMThread. - G1ParallelCleaningTask(BoolObjectClosure* is_alive, bool process_strings, bool process_symbols, uint num_workers, bool unloading_occurred) : + G1ParallelCleaningTask(BoolObjectClosure* is_alive, uint num_workers, bool unloading_occurred) : AbstractGangTask("Parallel Cleaning"), - _string_symbol_task(is_alive, process_strings, process_symbols), + _string_symbol_task(is_alive, true, true, G1StringDedup::is_enabled()), _code_cache_task(num_workers, is_alive, unloading_occurred), _klass_cleaning_task(is_alive) { } @@ -3862,23 +3871,26 @@ }; -void G1CollectedHeap::parallel_cleaning(BoolObjectClosure* is_alive, - bool process_strings, - bool process_symbols, - bool class_unloading_occurred) { +void G1CollectedHeap::full_cleaning(BoolObjectClosure* is_alive, + bool class_unloading_occurred) { uint n_workers = workers()->active_workers(); - G1ParallelCleaningTask g1_unlink_task(is_alive, process_strings, process_symbols, - n_workers, class_unloading_occurred); + G1ParallelCleaningTask g1_unlink_task(is_alive, n_workers, class_unloading_occurred); workers()->run_task(&g1_unlink_task); } -void G1CollectedHeap::unlink_string_and_symbol_table(BoolObjectClosure* is_alive, - bool process_strings, bool process_symbols) { - { // Timing scope - G1StringSymbolTableUnlinkTask g1_unlink_task(is_alive, process_strings, process_symbols); - workers()->run_task(&g1_unlink_task); +void G1CollectedHeap::partial_cleaning(BoolObjectClosure* is_alive, + bool process_strings, + bool process_symbols, + bool process_string_dedup) { + if (!process_strings && !process_symbols && !process_string_dedup) { + // Nothing to clean. + return; } + + G1StringSymbolTableUnlinkTask g1_unlink_task(is_alive, process_strings, process_symbols, process_string_dedup); + workers()->run_task(&g1_unlink_task); + } class G1RedirtyLoggedCardsTask : public AbstractGangTask { --- old/src/share/vm/gc/g1/g1CollectedHeap.hpp 2017-02-20 12:07:13.617497439 +0100 +++ new/src/share/vm/gc/g1/g1CollectedHeap.hpp 2017-02-20 12:07:13.485496785 +0100 @@ -1403,12 +1403,11 @@ // after a full GC. void rebuild_strong_code_roots(); - // Delete entries for dead interned string and clean up unreferenced symbols - // in symbol table, possibly in parallel. - void unlink_string_and_symbol_table(BoolObjectClosure* is_alive, bool unlink_strings = true, bool unlink_symbols = true); + // Partial cleaning used when class unloading is disabled. + void partial_cleaning(BoolObjectClosure* is_alive, bool unlink_strings, bool unlink_symbols, bool unlink_string_dedup); - // Parallel phase of unloading/cleaning after G1 concurrent mark. - void parallel_cleaning(BoolObjectClosure* is_alive, bool process_strings, bool process_symbols, bool class_unloading_occurred); + // Full parallel cleaning when class unloading is enabled. + void full_cleaning(BoolObjectClosure* is_alive, bool class_unloading_occurred); // Redirty logged cards in the refinement queue. void redirty_logged_cards(); --- old/src/share/vm/gc/g1/g1ConcurrentMark.cpp 2017-02-20 12:07:14.225500454 +0100 +++ new/src/share/vm/gc/g1/g1ConcurrentMark.cpp 2017-02-20 12:07:14.097499819 +0100 @@ -1659,10 +1659,6 @@ _workers->run_task(&enq_task_proxy); } -void G1ConcurrentMark::weakRefsWorkParallelPart(BoolObjectClosure* is_alive, bool purged_classes) { - G1CollectedHeap::heap()->parallel_cleaning(is_alive, true, true, purged_classes); -} - void G1ConcurrentMark::weakRefsWork(bool clear_all_soft_refs) { if (has_overflown()) { // Skip processing the discovered references if we have @@ -1775,22 +1771,15 @@ // Unload Klasses, String, Symbols, Code Cache, etc. if (ClassUnloadingWithConcurrentMark) { - bool purged_classes; - - { - GCTraceTime(Debug, gc, phases) trace("System Dictionary Unloading", _gc_timer_cm); - purged_classes = SystemDictionary::do_unloading(&g1_is_alive, false /* Defer klass cleaning */); - } - - { - GCTraceTime(Debug, gc, phases) trace("Parallel Unloading", _gc_timer_cm); - weakRefsWorkParallelPart(&g1_is_alive, purged_classes); - } - } + GCTraceTime(Debug, gc, phases) debug("Class Unloading", _gc_timer_cm); + bool purged_classes = SystemDictionary::do_unloading(&g1_is_alive, false /* Defer klass cleaning */); + g1h->full_cleaning(&g1_is_alive, purged_classes); + } else { + GCTraceTime(Debug, gc, phases) debug("Cleanup", _gc_timer_cm); + // No need to clean string table and symbol table as they are treated as strong roots when + // class unloading is disabled. + g1h->partial_cleaning(&g1_is_alive, false, false, G1StringDedup::is_enabled()); - if (G1StringDedup::is_enabled()) { - GCTraceTime(Debug, gc, phases) trace("String Deduplication Unlink", _gc_timer_cm); - G1StringDedup::unlink(&g1_is_alive); } } --- old/src/share/vm/gc/g1/g1MarkSweep.cpp 2017-02-20 12:07:14.933503965 +0100 +++ new/src/share/vm/gc/g1/g1MarkSweep.cpp 2017-02-20 12:07:14.797503291 +0100 @@ -170,22 +170,10 @@ // Unload classes and purge the SystemDictionary. bool purged_class = SystemDictionary::do_unloading(&GenMarkSweep::is_alive); - // Unload nmethods. - CodeCache::do_unloading(&GenMarkSweep::is_alive, purged_class); - - // Prune dead klasses from subklass/sibling/implementor lists. - Klass::clean_weak_klass_links(&GenMarkSweep::is_alive); - } - - { - GCTraceTime(Debug, gc, phases) trace("Scrub String and Symbol Tables", gc_timer()); - // Delete entries for dead interned string and clean up unreferenced symbols in symbol table. - g1h->unlink_string_and_symbol_table(&GenMarkSweep::is_alive); - } - - if (G1StringDedup::is_enabled()) { - GCTraceTime(Debug, gc, phases) trace("String Deduplication Unlink", gc_timer()); - G1StringDedup::unlink(&GenMarkSweep::is_alive); + g1h->full_cleaning(&GenMarkSweep::is_alive, purged_class); + } else { + GCTraceTime(Debug, gc, phases) trace("Cleanup", gc_timer()); + g1h->partial_cleaning(&GenMarkSweep::is_alive, true, true, G1StringDedup::is_enabled()); } if (VerifyDuringGC) { --- old/src/share/vm/gc/g1/g1StringDedup.cpp 2017-02-20 12:07:15.601507277 +0100 +++ new/src/share/vm/gc/g1/g1StringDedup.cpp 2017-02-20 12:07:15.473506643 +0100 @@ -116,6 +116,12 @@ unlink_or_oops_do(is_alive, NULL, false /* allow_resize_and_rehash */); } +void G1StringDedup::parallel_unlink(G1StringDedupUnlinkOrOopsDoClosure* unlink, uint worker_id) { + assert(is_enabled(), "String deduplication not enabled"); + G1StringDedupQueue::unlink_or_oops_do(unlink); + G1StringDedupTable::unlink_or_oops_do(unlink, worker_id); +} + // // Task for parallel unlink_or_oops_do() operation on the deduplication queue // and table. --- old/src/share/vm/gc/g1/g1StringDedup.hpp 2017-02-20 12:07:16.237510431 +0100 +++ new/src/share/vm/gc/g1/g1StringDedup.hpp 2017-02-20 12:07:16.109509796 +0100 @@ -90,6 +90,7 @@ class ThreadClosure; class outputStream; class G1StringDedupTable; +class G1StringDedupUnlinkOrOopsDoClosure; class G1GCPhaseTimes; // @@ -130,6 +131,7 @@ static void oops_do(OopClosure* keep_alive); static void unlink(BoolObjectClosure* is_alive); + static void parallel_unlink(G1StringDedupUnlinkOrOopsDoClosure* unlink, uint worker_id); static void unlink_or_oops_do(BoolObjectClosure* is_alive, OopClosure* keep_alive, bool allow_resize_and_rehash, G1GCPhaseTimes* phase_times = NULL);