Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
129 commits
Select commit Hold shift + click to select a range
469fd32
Testing ObjectCount event with Shenandoah
pf0n Jul 9, 2025
73f2b17
Merge branch 'master' of https://github.com/pf0n/jdk
pf0n Jul 9, 2025
48ab9c8
Revert "8358533: Improve performance of java.io.Reader.readAllLines"
pf0n Jul 9, 2025
3da9f89
Testing ObjectCount event with Shenandoah collector
pf0n Jul 9, 2025
ec5ad1a
Created ObjectCount event tests for G1Full and ParallelOld
pf0n Jul 9, 2025
354deee
Initiated GC for ObjectCount testing
pf0n Jul 9, 2025
359caff
Removed unnecessary duplicate calls to ObjectCountEventVerifier in Ob…
pf0n Jul 10, 2025
adea2fc
ObjectCount event test with g1 full
pf0n Jul 14, 2025
c535645
Separated ObjectCount and ObjectCountAfterGC
pf0n Jul 15, 2025
a135b2d
Minimize code duplication by adding templates to ObjectCountEvent sender
pf0n Jul 16, 2025
4826229
ObjectCount data will be emitted if ObjectCountAfterGC is sending data
pf0n Jul 16, 2025
00b15d6
Delete src/hotspot/share/gc/shared/objectCountAfterGCEventSender.cpp
pf0n Jul 16, 2025
461b71c
Delete src/hotspot/share/gc/shared/objectCountAfterGCEventSender.hpp
pf0n Jul 16, 2025
33aa1da
Delete src/hotspot/share/gc/shared/objectCountEventSender.cpp
pf0n Jul 16, 2025
cb368f6
Delete src/hotspot/share/gc/shared/objectCountEventSender.hpp
pf0n Jul 16, 2025
3d05ece
Added object counting to Shenandoah
pf0n Jul 17, 2025
523ec03
Merge branch 'test/shen-oc' of https://github.com/pf0n/jdk into test/…
pf0n Jul 17, 2025
f412082
Merge branch 'master' of https://github.com/pf0n/jdk
pf0n Jul 17, 2025
82bb883
Templates for ObjectCountEventSenderClosure
pf0n Jul 17, 2025
405e0d9
Updated file for objectCountEventSenderTemplate.hpp
pf0n Jul 17, 2025
d1a1e6b
Updated header gaurds for objectCountEventSenderTemplate.hpp
pf0n Jul 17, 2025
a868e9b
Removed whitespace changes
pf0n Jul 18, 2025
16eee14
Attempt to fix assert error
pf0n Jul 18, 2025
e4747f2
Removed iostream in objectCountEventSenderTemplate
pf0n Jul 18, 2025
0a9c094
Add template for the method that reports object count and updated res…
pf0n Jul 18, 2025
b88dce2
Reverting back to old commit
pf0n Jul 21, 2025
5f912be
Uncommented report_object_count_after_gc
pf0n Jul 21, 2025
08fc38c
Added KlassInfoTable to ObjectCount class
pf0n Jul 21, 2025
4c02ed1
Restored objectCountEventSender
pf0n Jul 22, 2025
520f534
Efficient implementation of ObjectCountAfterGC
pf0n Jul 22, 2025
b3b5706
New closure for object counting
pf0n Jul 22, 2025
5f77ceb
Delete src/hotspot/share/gc/shared/objectCountEventSenderTemplate.hpp
pf0n Jul 22, 2025
5466e0e
Atomic operations implemented in record_instance and merge_entry
pf0n Jul 22, 2025
afe3f12
Merge branch 'test/shen-oc' of https://github.com/pf0n/jdk into test/…
pf0n Jul 23, 2025
6c6e966
Included objectCountEventSender.hpp in objectCountClosure.cpp
pf0n Jul 23, 2025
57d4ea0
Added clearing entries method for KlassInfoTable
pf0n Jul 23, 2025
1c371b2
Removed inheritance from objectCountClosure
pf0n Jul 23, 2025
b1d8145
Templatized should_send_event in ObjectCountClosure
pf0n Jul 23, 2025
24523e7
Added include services gaurd to should_send_event()
pf0n Jul 23, 2025
dd3cd66
Attempt to fix incomplete type error
pf0n Jul 23, 2025
69f0813
Trying to fix forward declaration of 'class Mutex' error
pf0n Jul 23, 2025
eff8b16
Fixed assert error in debug build
pf0n Jul 24, 2025
5bf562b
Attempt to remove to unnecessary include for header files
pf0n Jul 24, 2025
f3957f0
Removed memory/heapInspection.hpp
pf0n Jul 24, 2025
9ab1d45
Changed the report_object_count function to call the get_table method…
pf0n Jul 24, 2025
0d5b154
Trying to fix debug build errors
pf0n Jul 24, 2025
8319955
Trying to fix incomplete type error for 'Mutex'
pf0n Jul 24, 2025
046be80
Included runtime/mutex in object count closure files
pf0n Jul 24, 2025
016196b
Trying to fix build error
pf0n Jul 24, 2025
35043ee
Trying to fix forward declaration of 'class KlassInfoTable'
pf0n Jul 24, 2025
3b3ed70
Added runtime/mutex to objectCountClosure
pf0n Jul 24, 2025
fd0418c
trying to fix debug errors
pf0n Jul 24, 2025
97028a7
Added include services to objectCountClosure.cpp
pf0n Jul 24, 2025
5de6cc9
Added extra check to see if ObjectCountAfterGC is enabled in report_o…
pf0n Jul 24, 2025
0d2a8a8
Removed universe.hpp
pf0n Jul 25, 2025
15859c1
Removed mutex header file in objectCountClosure files
pf0n Jul 25, 2025
f555bfa
Readded mutex header file in objectCountClosure files
pf0n Jul 25, 2025
a794546
Removed unnecessary atomic operations in merge_entry
pf0n Jul 25, 2025
bbc5ff0
Added comments for public methods in ObjectCountClosure
pf0n Jul 25, 2025
fc6b101
KlassInfoEntry will be deleted after sending event for that entry
pf0n Jul 27, 2025
0cdffed
Report object count outside of safepoint
pf0n Jul 28, 2025
1f67cf5
Create ObjectCountClosure to be a StackObj
pf0n Jul 29, 2025
96b07b4
Merge branch 'openjdk:master' into test/shen-oc
pf0n Jul 29, 2025
b2c7950
New closure that combines marking and object counting into one
pf0n Jul 31, 2025
88f5be1
No longer need ObjectCountClosure class
pf0n Jul 31, 2025
f5c69bc
Removed objectCountClosure.hpp in gcTrace
pf0n Jul 31, 2025
89cd068
Removed cit member from the ObjectCountEventSenderClosure
pf0n Aug 1, 2025
2a932fb
Restored cit in object count event sender
pf0n Aug 1, 2025
e06c698
Entry is always at the head when iterating
pf0n Aug 1, 2025
bb6fffd
Delete entry in the middle of bucket
pf0n Aug 1, 2025
1121469
Assert to check if KlassInfoEntry was deleted + comments
pf0n Aug 4, 2025
92ab0cb
Removed explicit template instantiation and added test for ObjectCoun…
pf0n Aug 4, 2025
0075cea
Subtract the total object size from the total table size to fix shoul…
pf0n Aug 5, 2025
120b290
Put ShenandoahMarkRefsAndCountClosure at appropriate places
pf0n Aug 5, 2025
5ae6563
Removed redundant check to see if object is null
pf0n Aug 5, 2025
911df7b
Testing thread local KlassInfoTables
pf0n Aug 5, 2025
a1c2ae1
Threads now have their own instance of a KlassInfoTable and merging p…
pf0n Aug 6, 2025
e65781c
Merge branch 'master' of https://github.com/pf0n/jdk
pf0n Aug 6, 2025
92755bb
Merge remote-tracking branch 'origin/master' into test/shen-thread-lo…
pf0n Aug 6, 2025
67e381c
Merge branch 'openjdk:master' into test/shen-thread-local-tables
pf0n Aug 6, 2025
0c7f751
Merge branch 'test/shen-thread-local-tables' of https://github.com/pf…
pf0n Aug 6, 2025
546d746
Removed unnecessary #include statements
pf0n Aug 6, 2025
61f67c8
fixup! Removed unnecessary #include statements
pf0n Aug 6, 2025
4b0a2f7
Created gcTrace.inline.hpp and objectCountEventSender.inline.hpp for …
pf0n Aug 6, 2025
0817661
Fix for requestable event not declared
pf0n Aug 7, 2025
10f31fc
added compiliation guards
pf0n Aug 7, 2025
37a1e6c
Merge branch 'openjdk:master' into test/shen-aggregate-closure
pf0n Aug 7, 2025
c86dd4a
General comments + Mutex for merging tables
pf0n Aug 7, 2025
e9531f2
Merge branch 'test/shen-aggregate-closure' of https://github.com/pf0n…
pf0n Aug 7, 2025
23ede8c
Merge branch 'master' of https://github.com/pf0n/jdk
pf0n Aug 7, 2025
8a910e0
Safety checks
pf0n Aug 8, 2025
f85b098
Fix assert error for genshen
pf0n Aug 11, 2025
ec0c7c0
Remove templates for should_send_event + Restructured logic for repor…
pf0n Aug 23, 2025
67ebc62
Templatized ObjectCountEventSenderClosure class
pf0n Aug 24, 2025
e32f528
Merge remote-tracking branch 'origin/master' into test/shen-aggregate…
pf0n Aug 24, 2025
bee4128
New lock called TableMerge_lock
pf0n Aug 24, 2025
da84897
src/hotspot/share
pf0n Aug 24, 2025
729f413
Do not allow object counting for GenShen and only create cit if JFR i…
pf0n Aug 25, 2025
2fa61d3
More documentation for method
pf0n Aug 25, 2025
3d2bdeb
Stronger assertion for ShenandoahObjectCountClosure
pf0n Aug 25, 2025
2c32f70
Don't reuse the same KlassInfoTable
pf0n Aug 26, 2025
8b091f2
Removed unused method in heapInspection.hpp
pf0n Aug 26, 2025
fce96de
Accidentally pushed a char
pf0n Aug 26, 2025
0dd3c90
Removed extra whitespace
pf0n Aug 26, 2025
ba3bee7
Merge branch 'master' of https://github.com/pf0n/jdk
pf0n Aug 26, 2025
b208281
Reverted changes on master branch that were pushed accidentally
pf0n Aug 26, 2025
749ccb2
Merge remote-tracking branch 'origin/master' into test/shen-aggregate…
pf0n Aug 26, 2025
17ab239
Merged master + Removed unnecessary test files
pf0n Aug 26, 2025
fbfe8b4
Whitespace error
pf0n Aug 26, 2025
af4f638
Merge branch 'openjdk:master' into master
pf0n Aug 27, 2025
41cbb05
Merge remote-tracking branch 'origin/master' into test/shen-aggregate…
pf0n Aug 27, 2025
ee8a1eb
Fixed an inaccurate comment
pf0n Aug 28, 2025
508d0f2
Fixed an inaccurate comment
pf0n Aug 28, 2025
184144e
Merge branch 'test/shen-aggregate-closure' of https://github.com/pf0n…
pf0n Aug 28, 2025
6cb5421
Merge branch 'test/shen-aggregate-closure' of https://github.com/pf0n…
pf0n Aug 28, 2025
582da8e
Merge branch 'test/shen-aggregate-closure' of https://github.com/pf0n…
pf0n Aug 28, 2025
242942b
Merge branch 'test/shen-aggregate-closure' of https://github.com/pf0n…
pf0n Aug 28, 2025
296924f
Merge branch 'test/shen-aggregate-closure' of https://github.com/pf0n…
pf0n Aug 28, 2025
1686fb3
8366122: Shenandoah: Implement efficient support for object count aft…
pf0n Aug 28, 2025
87466a3
Compilation guards to reduce compile time for event
pf0n Aug 28, 2025
855bd55
Merge branch '8366122/shen-object-count-after-gc' into test/shen-aggr…
pf0n Aug 28, 2025
0ce22eb
Reverting changes back to original state for some files
pf0n Aug 29, 2025
6023ee0
Merging master
pf0n Aug 30, 2025
668fdae
Deleted objectCountEventSender.inline.hpp
pf0n Sep 2, 2025
68e21c1
Comment on why return value was changed to bool
pf0n Sep 2, 2025
4cd254f
Merge branch 'master' of https://github.com/openjdk/jdk into test/she…
pf0n Sep 2, 2025
11ef54f
Renamed variables, better comment, included guard, removed mutex header
pf0n Sep 3, 2025
2328362
Readded mutex
pf0n Sep 3, 2025
8ce74f8
Testing to see if filtering objects work
pf0n Sep 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions src/hotspot/share/gc/shared/gcTrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include "gc/shared/gcId.hpp"
#include "gc/shared/gcTimer.hpp"
#include "gc/shared/gcTrace.hpp"
#include "gc/shared/objectCountEventSender.hpp"
#include "gc/shared/referenceProcessorStats.hpp"
#include "memory/heapInspection.hpp"
#include "memory/resourceArea.hpp"
Expand Down Expand Up @@ -74,31 +73,6 @@ void GCTracer::report_gc_reference_stats(const ReferenceProcessorStats& rps) con
}

#if INCLUDE_SERVICES
class ObjectCountEventSenderClosure : public KlassInfoClosure {
const double _size_threshold_percentage;
const size_t _total_size_in_words;
const Ticks _timestamp;

public:
ObjectCountEventSenderClosure(size_t total_size_in_words, const Ticks& timestamp) :
_size_threshold_percentage(ObjectCountCutOffPercent / 100),
_total_size_in_words(total_size_in_words),
_timestamp(timestamp)
{}

virtual void do_cinfo(KlassInfoEntry* entry) {
if (should_send_event(entry)) {
ObjectCountEventSender::send(entry, _timestamp);
}
}

private:
bool should_send_event(const KlassInfoEntry* entry) const {
double percentage_of_heap = ((double) entry->words()) / _total_size_in_words;
return percentage_of_heap >= _size_threshold_percentage;
}
};

void GCTracer::report_object_count_after_gc(BoolObjectClosure* is_alive_cl, WorkerThreads* workers) {
assert(is_alive_cl != nullptr, "Must supply function to check liveness");

Expand Down
33 changes: 33 additions & 0 deletions src/hotspot/share/gc/shared/gcTrace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
#include "gc/shared/gcId.hpp"
#include "gc/shared/gcName.hpp"
#include "gc/shared/gcWhen.hpp"
#include "gc/shared/objectCountEventSender.hpp"
#include "gc/shared/workerThread.hpp"
#include "memory/heapInspection.hpp"
#include "memory/metaspace.hpp"
#include "memory/referenceType.hpp"
#include "utilities/macros.hpp"
Expand Down Expand Up @@ -92,6 +94,33 @@ class ParallelOldGCInfo {
void* dense_prefix() const { return _dense_prefix; }
};

#if INCLUDE_SERVICES
class ObjectCountEventSenderClosure : public KlassInfoClosure {
const double _size_threshold_percentage;
const size_t _total_size_in_words;
const Ticks _timestamp;

public:
ObjectCountEventSenderClosure(size_t total_size_in_words, const Ticks& timestamp) :
_size_threshold_percentage(ObjectCountCutOffPercent / 100),
_total_size_in_words(total_size_in_words),
_timestamp(timestamp)
{}

virtual void do_cinfo(KlassInfoEntry* entry) {
if (should_send_event(entry)) {
ObjectCountEventSender::send(entry, _timestamp);
}
}

private:
bool should_send_event(const KlassInfoEntry* entry) const {
double percentage_of_heap = ((double) entry->words()) / _total_size_in_words;
return percentage_of_heap >= _size_threshold_percentage;
}
};
#endif // INCLUDE_SERVICES

class GCTracer {
protected:
SharedGCInfo _shared_gc_info;
Expand All @@ -104,6 +133,10 @@ class GCTracer {
void report_metaspace_summary(GCWhen::Type when, const MetaspaceSummary& metaspace_summary) const;
void report_gc_reference_stats(const ReferenceProcessorStats& rp) const;
void report_object_count_after_gc(BoolObjectClosure* object_filter, WorkerThreads* workers) NOT_SERVICES_RETURN;
// Report object count without performing a heap inspection. This method will
// only work if there's a global KlassInfoTable in the heap.
template <typename T>
void report_object_count() NOT_SERVICES_RETURN;
void report_cpu_time_event(double user_time, double system_time, double real_time) const;

protected:
Expand Down
25 changes: 25 additions & 0 deletions src/hotspot/share/gc/shared/gcTrace.inline.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef SHARE_GC_SHARED_GCTRACE_INLINE_HPP
#define SHARE_GC_SHARED_GCTRACE_INLINE_HPP

#include "gc/shared/gcTrace.hpp"
#include "memory/heapInspection.hpp"
#include "utilities/macros.hpp"

#if INCLUDE_SERVICES
template <typename T>
void GCTracer::report_object_count() {
if (!ObjectCountEventSender::should_send_event()) {
return;
}

T* heap = T::heap();
KlassInfoTable* cit = heap->get_cit();

if (!cit->allocation_failed()) {
ObjectCountEventSenderClosure event_sender(cit->size_of_instances_in_words(), Ticks::now());
cit->iterate(&event_sender);
}
}
#endif // INCLUDE_SERVICES

#endif // SHARE_GC_SHARED_GCTRACE_INLINE_HPP
1 change: 0 additions & 1 deletion src/hotspot/share/gc/shared/objectCountEventSender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
*
*/


#include "gc/shared/gcId.hpp"
#include "gc/shared/objectCountEventSender.hpp"
#include "jfr/jfrEvents.hpp"
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/gc/shared/objectCountEventSender.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
#ifndef SHARE_GC_SHARED_OBJECTCOUNTEVENTSENDER_HPP
#define SHARE_GC_SHARED_OBJECTCOUNTEVENTSENDER_HPP

#include "gc/shared/gcTrace.hpp"
#include "memory/allStatic.hpp"
#include "memory/heapInspection.hpp"
#include "utilities/globalDefinitions.hpp"
#include "utilities/macros.hpp"
#include "utilities/ticks.hpp"
Expand Down
27 changes: 26 additions & 1 deletion src/hotspot/share/gc/shenandoah/shenandoahClosures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "code/nmethod.hpp"
#include "gc/shared/stringdedup/stringDedup.hpp"
#include "gc/shenandoah/shenandoahGenerationType.hpp"
#include "gc/shenandoah/shenandoahObjectCountClosure.hpp"
#include "gc/shenandoah/shenandoahTaskqueue.hpp"
#include "memory/iterator.hpp"
#include "runtime/javaThread.hpp"
Expand Down Expand Up @@ -73,7 +74,8 @@ class ShenandoahMarkRefsSuperClosure : public ShenandoahSuperClosure {

protected:
template <class T, ShenandoahGenerationType GENERATION>
void work(T *p);
// Return true if object was not previously marked strong by another thread.
bool work(T *p);

public:
inline ShenandoahMarkRefsSuperClosure(ShenandoahObjToScanQueue* q, ShenandoahReferenceProcessor* rp, ShenandoahObjToScanQueue* old_q);
Expand Down Expand Up @@ -106,6 +108,29 @@ class ShenandoahMarkRefsClosure : public ShenandoahMarkRefsSuperClosure {
virtual void do_oop(oop* p) { do_oop_work(p); }
};

#if INCLUDE_JFR
template <ShenandoahGenerationType GENERATION>
class ShenandoahMarkRefsAndCountClosure : public ShenandoahMarkRefsSuperClosure {
private:
ShenandoahObjectCountClosure* _count;
template <class T>
inline void do_oop_work(T* p) {
// Count newly marked strong references to avoid double counting.
const bool newly_marked_strong = work<T, GENERATION>(p);
if (newly_marked_strong) {
_count->do_oop(p);
}
}

public:
ShenandoahMarkRefsAndCountClosure(ShenandoahObjToScanQueue* q, ShenandoahReferenceProcessor* rp, ShenandoahObjToScanQueue* old_q, ShenandoahObjectCountClosure* count) :
ShenandoahMarkRefsSuperClosure(q, rp, old_q), _count(count) {};

virtual void do_oop(narrowOop* p) { do_oop_work(p); }
virtual void do_oop(oop* p) { do_oop_work(p); }
};
#endif // INCLUDE_JFR

class ShenandoahForwardedIsAliveClosure : public BoolObjectClosure {
private:
ShenandoahMarkingContext* const _mark_context;
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/gc/shenandoah/shenandoahClosures.inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ ShenandoahMarkRefsSuperClosure::ShenandoahMarkRefsSuperClosure(ShenandoahObjToSc
_weak(false) {}

template<class T, ShenandoahGenerationType GENERATION>
inline void ShenandoahMarkRefsSuperClosure::work(T* p) {
ShenandoahMark::mark_through_ref<T, GENERATION>(p, _queue, _old_queue, _mark_context, _weak);
inline bool ShenandoahMarkRefsSuperClosure::work(T* p) {
return ShenandoahMark::mark_through_ref<T, GENERATION>(p, _queue, _old_queue, _mark_context, _weak);
}

ShenandoahForwardedIsAliveClosure::ShenandoahForwardedIsAliveClosure() :
Expand Down
4 changes: 4 additions & 0 deletions src/hotspot/share/gc/shenandoah/shenandoahConcurrentGC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "gc/shared/barrierSetNMethod.hpp"
#include "gc/shared/collectorCounters.hpp"
#include "gc/shared/continuationGCSupport.inline.hpp"
#include "gc/shared/gcTrace.inline.hpp"
#include "gc/shenandoah/shenandoahBreakpoint.hpp"
#include "gc/shenandoah/shenandoahClosures.inline.hpp"
#include "gc/shenandoah/shenandoahCollectorPolicy.hpp"
Expand Down Expand Up @@ -314,6 +315,9 @@ void ShenandoahConcurrentGC::vmop_entry_final_mark() {
heap->try_inject_alloc_failure();
VM_ShenandoahFinalMarkStartEvac op(this);
VMThread::execute(&op); // jump to entry_final_mark under safepoint
// Do not report object count during a safepoint
assert(!ShenandoahSafepoint::is_at_shenandoah_safepoint(), "Should not be at safepoint");
heap->tracer()->report_object_count<ShenandoahHeap>();
}

void ShenandoahConcurrentGC::vmop_entry_init_update_refs() {
Expand Down
24 changes: 21 additions & 3 deletions src/hotspot/share/gc/shenandoah/shenandoahConcurrentMark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*
*/


#include "gc/shared/objectCountEventSender.hpp"
#include "gc/shared/satbMarkQueue.hpp"
#include "gc/shared/strongRootsScope.hpp"
#include "gc/shared/taskTerminator.hpp"
Expand All @@ -33,6 +33,7 @@
#include "gc/shenandoah/shenandoahGeneration.hpp"
#include "gc/shenandoah/shenandoahHeap.inline.hpp"
#include "gc/shenandoah/shenandoahMark.inline.hpp"
#include "gc/shenandoah/shenandoahObjectCountClosure.hpp"
#include "gc/shenandoah/shenandoahPhaseTimings.hpp"
#include "gc/shenandoah/shenandoahReferenceProcessor.hpp"
#include "gc/shenandoah/shenandoahRootProcessor.inline.hpp"
Expand All @@ -45,6 +46,7 @@
#include "runtime/continuation.hpp"
#include "runtime/threads.hpp"


template <ShenandoahGenerationType GENERATION>
class ShenandoahConcurrentMarkingTask : public WorkerTask {
private:
Expand Down Expand Up @@ -170,8 +172,24 @@ void ShenandoahMarkConcurrentRootsTask<GENERATION>::work(uint worker_id) {
ShenandoahObjToScanQueue* q = _queue_set->queue(worker_id);
ShenandoahObjToScanQueue* old_q = (_old_queue_set == nullptr) ?
nullptr : _old_queue_set->queue(worker_id);
ShenandoahMarkRefsClosure<GENERATION> cl(q, _rp, old_q);
_root_scanner.roots_do(&cl, worker_id);

#if INCLUDE_JFR
// Use object counting closure if ObjectCount or ObjectCountAfterGC event is enabled.
const bool object_count_enabled = ObjectCountEventSender::should_send_event();
if (object_count_enabled && !ShenandoahHeap::heap()->mode()->is_generational()) {
KlassInfoTable* const global_cit = ShenandoahHeap::heap()->get_cit();
KlassInfoTable local_cit(false);
ShenandoahIsAliveClosure is_alive;
ShenandoahObjectCountClosure count(&local_cit, &is_alive);
ShenandoahMarkRefsAndCountClosure<GENERATION> cl(q, _rp, old_q, &count);
_root_scanner.roots_do(&cl, worker_id);
count.merge_table(global_cit);
} else
#endif // INCLUDE_JFR
{
ShenandoahMarkRefsClosure<GENERATION> cl(q, _rp, old_q);
_root_scanner.roots_do(&cl, worker_id);
}
}

void ShenandoahConcurrentMark::mark_concurrent_roots() {
Expand Down
9 changes: 9 additions & 0 deletions src/hotspot/share/gc/shenandoah/shenandoahControlThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ void ShenandoahControlThread::run_service() {
assert (!gc_requested || cause != GCCause::_last_gc_cause, "GC cause should be set");

if (gc_requested) {
// Create the KlassInfoTable for Shenandoah only if JFR is enabled.
#if INCLUDE_JFR
KlassInfoTable cit(false);
heap->set_cit(&cit);
#endif // INCLUDE_JFR

// Cannot uncommit bitmap slices during concurrent reset
ShenandoahNoUncommitMark forbid_region_uncommit(heap);

Expand Down Expand Up @@ -224,6 +230,9 @@ void ShenandoahControlThread::run_service() {

// Print Metaspace change following GC (if logging is enabled).
MetaspaceUtils::print_metaspace_change(meta_sizes);
#if INCLUDE_JFR
heap->set_cit(nullptr);
#endif // INCLUDE_JFR
}

// Check if we have seen a new target for soft max heap size or if a gc was requested.
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ ShenandoahHeap::ShenandoahHeap(ShenandoahCollectorPolicy* policy) :
_active_generation(nullptr),
_initial_size(0),
_committed(0),
_cit(nullptr),
_max_workers(MAX3(ConcGCThreads, ParallelGCThreads, 1U)),
_workers(nullptr),
_safepoint_workers(nullptr),
Expand Down
8 changes: 7 additions & 1 deletion src/hotspot/share/gc/shenandoah/shenandoahHeap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "gc/shenandoah/shenandoahPadding.hpp"
#include "gc/shenandoah/shenandoahSharedVariables.hpp"
#include "gc/shenandoah/shenandoahUnload.hpp"
#include "memory/heapInspection.hpp"
#include "memory/metaspace.hpp"
#include "services/memoryManager.hpp"
#include "utilities/globalDefinitions.hpp"
Expand Down Expand Up @@ -228,7 +229,8 @@ class ShenandoahHeap : public CollectedHeap {
shenandoah_padding(0);
volatile size_t _committed;
shenandoah_padding(1);

// Used for JFR object count event support.
KlassInfoTable* _cit;
void increase_used(const ShenandoahAllocRequest& req);

public:
Expand All @@ -252,6 +254,10 @@ class ShenandoahHeap : public CollectedHeap {

void set_soft_max_capacity(size_t v);

// Setter & accessor for class histogram
inline void set_cit(KlassInfoTable* cit);
inline KlassInfoTable* get_cit();

// ---------- Periodic Tasks
//
public:
Expand Down
12 changes: 12 additions & 0 deletions src/hotspot/share/gc/shenandoah/shenandoahHeap.inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "gc/shenandoah/shenandoahMarkingContext.inline.hpp"
#include "gc/shenandoah/shenandoahThreadLocalData.hpp"
#include "gc/shenandoah/shenandoahWorkGroup.hpp"
#include "memory/heapInspection.hpp"
#include "oops/compressedOops.inline.hpp"
#include "oops/oop.inline.hpp"
#include "runtime/atomic.hpp"
Expand Down Expand Up @@ -647,4 +648,15 @@ inline ShenandoahMarkingContext* ShenandoahHeap::marking_context() const {
return _marking_context;
}

inline void ShenandoahHeap::set_cit(KlassInfoTable* cit) {
assert(_cit == nullptr || cit == nullptr, "Overwriting an existing histogram");
assert(_cit != nullptr || cit != nullptr, "Already cleared");
_cit = cit;
}

inline KlassInfoTable* ShenandoahHeap::get_cit() {
assert(_cit != nullptr, "KlassInfoTable is null");
return _cit;
}

#endif // SHARE_GC_SHENANDOAH_SHENANDOAHHEAP_INLINE_HPP
24 changes: 20 additions & 4 deletions src/hotspot/share/gc/shenandoah/shenandoahMark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/



#include "gc/shared/objectCountEventSender.hpp"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See previous comment about template method definitions in a .inline.hpp, and inclusion of the .inline.hpp here.

#include "gc/shenandoah/shenandoahBarrierSet.hpp"
#include "gc/shenandoah/shenandoahClosures.inline.hpp"
#include "gc/shenandoah/shenandoahGeneration.hpp"
Expand Down Expand Up @@ -69,9 +69,25 @@ void ShenandoahMark::mark_loop_prework(uint w, TaskTerminator *t, ShenandoahRefe
Closure cl(q, rp, old_q);
mark_loop_work<Closure, GENERATION, CANCELLABLE, STRING_DEDUP>(&cl, ld, w, t, req);
} else {
using Closure = ShenandoahMarkRefsClosure<GENERATION>;
Closure cl(q, rp, old_q);
mark_loop_work<Closure, GENERATION, CANCELLABLE, STRING_DEDUP>(&cl, ld, w, t, req);
#if INCLUDE_JFR
// Use object counting closure if ObjectCount or ObjectCountAfterGC event is enabled.
const bool object_count_enabled = ObjectCountEventSender::should_send_event();
if (object_count_enabled && !ShenandoahHeap::heap()->mode()->is_generational()) {
KlassInfoTable* const global_cit = ShenandoahHeap::heap()->get_cit();
KlassInfoTable local_cit(false);
ShenandoahIsAliveClosure is_alive;
ShenandoahObjectCountClosure count(&local_cit, &is_alive);
using Closure = ShenandoahMarkRefsAndCountClosure<GENERATION>;
Closure cl(q, rp, old_q, &count);
mark_loop_work<Closure, GENERATION, CANCELLABLE, STRING_DEDUP>(&cl, ld, w, t, req);
count.merge_table(global_cit);
} else
#endif // INCLUDE_JFR
{
using Closure = ShenandoahMarkRefsClosure<GENERATION>;
Closure cl(q, rp, old_q);
mark_loop_work<Closure, GENERATION, CANCELLABLE, STRING_DEDUP>(&cl, ld, w, t, req);
}
}

heap->flush_liveness_cache(w);
Expand Down
Loading