Skip to content

Commit af5932e

Browse files
committed
8361055: Serial: Inline SerialHeap::process_roots
Reviewed-by: tschatzl, kbarrett, stefank
1 parent 3b0da29 commit af5932e

File tree

6 files changed

+62
-79
lines changed

6 files changed

+62
-79
lines changed

src/hotspot/share/gc/serial/defNewGeneration.cpp

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
*
2323
*/
2424

25+
#include "classfile/classLoaderDataGraph.hpp"
2526
#include "gc/serial/cardTableRS.hpp"
2627
#include "gc/serial/serialGcRefProcProxyTask.hpp"
2728
#include "gc/serial/serialHeap.inline.hpp"
@@ -38,8 +39,10 @@
3839
#include "gc/shared/gcTimer.hpp"
3940
#include "gc/shared/gcTrace.hpp"
4041
#include "gc/shared/gcTraceTime.inline.hpp"
42+
#include "gc/shared/oopStorageSet.inline.hpp"
4143
#include "gc/shared/referencePolicy.hpp"
4244
#include "gc/shared/referenceProcessorPhaseTimes.hpp"
45+
#include "gc/shared/scavengableNMethods.hpp"
4346
#include "gc/shared/space.hpp"
4447
#include "gc/shared/spaceDecorator.hpp"
4548
#include "gc/shared/strongRootsScope.hpp"
@@ -605,21 +608,31 @@ bool DefNewGeneration::collect(bool clear_all_soft_refs) {
605608

606609
{
607610
StrongRootsScope srs(0);
608-
RootScanClosure root_cl{this};
609-
CLDScanClosure cld_cl{this};
610-
611-
MarkingNMethodClosure code_cl(&root_cl,
612-
NMethodToOopClosure::FixRelocations,
613-
false /* keepalive_nmethods */);
614-
615-
HeapWord* saved_top_in_old_gen = _old_gen->space()->top();
616-
heap->process_roots(SerialHeap::SO_ScavengeCodeCache,
617-
&root_cl,
618-
&cld_cl,
619-
&cld_cl,
620-
&code_cl);
621-
622-
_old_gen->scan_old_to_young_refs(saved_top_in_old_gen);
611+
RootScanClosure oop_closure{this};
612+
CLDScanClosure cld_closure{this};
613+
614+
MarkingNMethodClosure nmethod_closure(&oop_closure,
615+
NMethodToOopClosure::FixRelocations,
616+
false /* keepalive_nmethods */);
617+
618+
// Starting tracing from roots, there are 4 kinds of roots in young-gc.
619+
//
620+
// 1. old-to-young pointers; processing them before relocating other kinds
621+
// of roots.
622+
_old_gen->scan_old_to_young_refs();
623+
624+
// 2. CLD; visit all (strong+weak) clds with the same closure, because we
625+
// don't perform class unloading during young-gc.
626+
ClassLoaderDataGraph::cld_do(&cld_closure);
627+
628+
// 3. Threads stack frames and nmethods.
629+
// Only nmethods that contain pointers into-young need to be processed
630+
// during young-gc, and they are tracked in ScavengableNMethods
631+
Threads::oops_do(&oop_closure, nullptr);
632+
ScavengableNMethods::nmethods_do(&nmethod_closure);
633+
634+
// 4. VM internal roots.
635+
OopStorageSet::strong_oops_do(&oop_closure);
623636
}
624637

625638
// "evacuate followers".

src/hotspot/share/gc/serial/serialFullGC.cpp

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "gc/shared/gcTrace.hpp"
5050
#include "gc/shared/gcTraceTime.inline.hpp"
5151
#include "gc/shared/modRefBarrierSet.hpp"
52+
#include "gc/shared/oopStorageSet.inline.hpp"
5253
#include "gc/shared/preservedMarks.inline.hpp"
5354
#include "gc/shared/referencePolicy.hpp"
5455
#include "gc/shared/referenceProcessorPhaseTimes.hpp"
@@ -66,6 +67,7 @@
6667
#include "oops/oop.inline.hpp"
6768
#include "oops/typeArrayOop.inline.hpp"
6869
#include "runtime/prefetch.inline.hpp"
70+
#include "runtime/threads.hpp"
6971
#include "utilities/align.hpp"
7072
#include "utilities/copy.hpp"
7173
#include "utilities/events.hpp"
@@ -483,13 +485,22 @@ void SerialFullGC::phase1_mark(bool clear_all_softrefs) {
483485
{
484486
StrongRootsScope srs(0);
485487

486-
CLDClosure* weak_cld_closure = ClassUnloading ? nullptr : &follow_cld_closure;
487-
MarkingNMethodClosure mark_code_closure(&follow_root_closure, !NMethodToOopClosure::FixRelocations, true);
488-
gch->process_roots(SerialHeap::SO_None,
489-
&follow_root_closure,
490-
&follow_cld_closure,
491-
weak_cld_closure,
492-
&mark_code_closure);
488+
MarkingNMethodClosure mark_code_closure(&follow_root_closure,
489+
!NMethodToOopClosure::FixRelocations,
490+
true);
491+
492+
// Start tracing from roots, there are 3 kinds of roots in full-gc.
493+
//
494+
// 1. CLD. This method internally takes care of whether class loading is
495+
// enabled or not, applying the closure to both strong and weak or only
496+
// strong CLDs.
497+
ClassLoaderDataGraph::always_strong_cld_do(&follow_cld_closure);
498+
499+
// 2. Threads stack frames and active nmethods in them.
500+
Threads::oops_do(&follow_root_closure, &mark_code_closure);
501+
502+
// 3. VM internal roots.
503+
OopStorageSet::strong_oops_do(&follow_root_closure);
493504
}
494505

495506
// Process reference objects found during marking
@@ -717,13 +728,20 @@ void SerialFullGC::invoke_at_safepoint(bool clear_all_softrefs) {
717728

718729
ClassLoaderDataGraph::verify_claimed_marks_cleared(ClassLoaderData::_claim_stw_fullgc_adjust);
719730

720-
NMethodToOopClosure code_closure(&adjust_pointer_closure, NMethodToOopClosure::FixRelocations);
721-
gch->process_roots(SerialHeap::SO_AllCodeCache,
722-
&adjust_pointer_closure,
723-
&adjust_cld_closure,
724-
&adjust_cld_closure,
725-
&code_closure);
731+
// Remap strong and weak roots in adjust phase.
732+
// 1. All (strong and weak) CLDs.
733+
ClassLoaderDataGraph::cld_do(&adjust_cld_closure);
734+
735+
// 2. Threads stack frames. No need to visit on-stack nmethods, because all
736+
// nmethods are visited in one go via CodeCache::nmethods_do.
737+
Threads::oops_do(&adjust_pointer_closure, nullptr);
738+
NMethodToOopClosure nmethod_cl(&adjust_pointer_closure, NMethodToOopClosure::FixRelocations);
739+
CodeCache::nmethods_do(&nmethod_cl);
740+
741+
// 3. VM internal roots
742+
OopStorageSet::strong_oops_do(&adjust_pointer_closure);
726743

744+
// 4. VM internal weak roots
727745
WeakProcessor::oops_do(&adjust_pointer_closure);
728746

729747
adjust_marks();

src/hotspot/share/gc/serial/serialHeap.cpp

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -513,38 +513,6 @@ HeapWord* SerialHeap::satisfy_failed_allocation(size_t size, bool is_tlab) {
513513
return nullptr;
514514
}
515515

516-
void SerialHeap::process_roots(ScanningOption so,
517-
OopClosure* strong_roots,
518-
CLDClosure* strong_cld_closure,
519-
CLDClosure* weak_cld_closure,
520-
NMethodToOopClosure* code_roots) {
521-
// General roots.
522-
assert(code_roots != nullptr, "code root closure should always be set");
523-
524-
ClassLoaderDataGraph::roots_cld_do(strong_cld_closure, weak_cld_closure);
525-
526-
// Only process code roots from thread stacks if we aren't visiting the entire CodeCache anyway
527-
NMethodToOopClosure* roots_from_code_p = (so & SO_AllCodeCache) ? nullptr : code_roots;
528-
529-
Threads::oops_do(strong_roots, roots_from_code_p);
530-
531-
OopStorageSet::strong_oops_do(strong_roots);
532-
533-
if (so & SO_ScavengeCodeCache) {
534-
assert(code_roots != nullptr, "must supply closure for code cache");
535-
536-
// We only visit parts of the CodeCache when scavenging.
537-
ScavengableNMethods::nmethods_do(code_roots);
538-
}
539-
if (so & SO_AllCodeCache) {
540-
assert(code_roots != nullptr, "must supply closure for code cache");
541-
542-
// CMSCollector uses this to do intermediate-strength collections.
543-
// We scan the entire code cache, since CodeCache::do_unloading is not called.
544-
CodeCache::nmethods_do(code_roots);
545-
}
546-
}
547-
548516
template <typename OopClosureType>
549517
static void oop_iterate_from(OopClosureType* blk, ContiguousSpace* space, HeapWord** from) {
550518
assert(*from != nullptr, "precondition");

src/hotspot/share/gc/serial/serialHeap.hpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -222,23 +222,7 @@ class SerialHeap : public CollectedHeap {
222222
// generations in a fully generational heap.
223223
CardTableRS* rem_set() { return _rem_set; }
224224

225-
// The ScanningOption determines which of the roots
226-
// the closure is applied to:
227-
// "SO_None" does none;
228-
enum ScanningOption {
229-
SO_None = 0x0,
230-
SO_AllCodeCache = 0x8,
231-
SO_ScavengeCodeCache = 0x10
232-
};
233-
234225
public:
235-
// Apply closures on various roots in Young GC or marking/adjust phases of Full GC.
236-
void process_roots(ScanningOption so,
237-
OopClosure* strong_roots,
238-
CLDClosure* strong_cld_closure,
239-
CLDClosure* weak_cld_closure,
240-
NMethodToOopClosure* code_roots);
241-
242226
// Set the saved marks of generations, if that makes sense.
243227
// In particular, if any generation might iterate over the oops
244228
// in other generations, it should call this method.

src/hotspot/share/gc/serial/tenuredGeneration.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,8 @@ HeapWord* TenuredGeneration::block_start(const void* addr) const {
277277
}
278278
}
279279

280-
void TenuredGeneration::scan_old_to_young_refs(HeapWord* saved_top_in_old_gen) {
281-
_rs->scan_old_to_young_refs(this, saved_top_in_old_gen);
280+
void TenuredGeneration::scan_old_to_young_refs() {
281+
_rs->scan_old_to_young_refs(this, space()->top());
282282
}
283283

284284
TenuredGeneration::TenuredGeneration(ReservedSpace rs,

src/hotspot/share/gc/serial/tenuredGeneration.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class TenuredGeneration: public Generation {
104104

105105
HeapWord* block_start(const void* addr) const;
106106

107-
void scan_old_to_young_refs(HeapWord* saved_top_in_old_gen);
107+
void scan_old_to_young_refs();
108108

109109
bool is_in(const void* p) const;
110110

0 commit comments

Comments
 (0)