Skip to content

Commit bd3bc2c

Browse files
author
Thomas Schatzl
committedOct 20, 2023
8317350: Move code cache purging out of CodeCache::UnloadingScope
Reviewed-by: ayang, iwalulya
1 parent 292aad2 commit bd3bc2c

File tree

7 files changed

+54
-34
lines changed

7 files changed

+54
-34
lines changed
 

‎src/hotspot/share/code/codeCache.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,6 @@ CodeCache::UnloadingScope::UnloadingScope(BoolObjectClosure* is_alive)
10361036
CodeCache::UnloadingScope::~UnloadingScope() {
10371037
IsUnloadingBehaviour::set_current(_saved_behaviour);
10381038
DependencyContext::cleaning_end();
1039-
CodeCache::flush_unlinked_nmethods();
10401039
}
10411040

10421041
void CodeCache::verify_oops() {

‎src/hotspot/share/code/codeCache.hpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,7 @@ class CodeCache : AllStatic {
179179

180180
// GC support
181181
static void verify_oops();
182-
// If any oops are not marked this method unloads (i.e., breaks root links
183-
// to) any unmarked codeBlobs in the cache. Sets "marked_for_unloading"
184-
// to "true" iff some code got unloaded.
185-
// "unloading_occurred" controls whether metadata should be cleaned because of class unloading.
182+
// Scope object managing code cache unloading behavior.
186183
class UnloadingScope: StackObj {
187184
ClosureIsUnloadingBehaviour _is_unloading_behaviour;
188185
IsUnloadingBehaviour* _saved_behaviour;

‎src/hotspot/share/gc/g1/g1ConcurrentMark.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -1694,9 +1694,12 @@ void G1ConcurrentMark::weak_refs_work() {
16941694
// Unload Klasses, String, Code Cache, etc.
16951695
if (ClassUnloadingWithConcurrentMark) {
16961696
GCTraceTime(Debug, gc, phases) debug("Class Unloading", _gc_timer_cm);
1697-
CodeCache::UnloadingScope scope(&g1_is_alive);
1698-
bool purged_classes = SystemDictionary::do_unloading(_gc_timer_cm);
1699-
_g1h->complete_cleaning(purged_classes);
1697+
{
1698+
CodeCache::UnloadingScope scope(&g1_is_alive);
1699+
bool unloading_occurred = SystemDictionary::do_unloading(_gc_timer_cm);
1700+
_g1h->complete_cleaning(unloading_occurred);
1701+
}
1702+
CodeCache::flush_unlinked_nmethods();
17001703
}
17011704
}
17021705

‎src/hotspot/share/gc/g1/g1FullCollector.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,13 @@ void G1FullCollector::phase1_mark_live_objects() {
319319
// Class unloading and cleanup.
320320
if (ClassUnloading) {
321321
GCTraceTime(Debug, gc, phases) debug("Phase 1: Class Unloading and Cleanup", scope()->timer());
322-
CodeCache::UnloadingScope unloading_scope(&_is_alive);
323-
// Unload classes and purge the SystemDictionary.
324-
bool purged_class = SystemDictionary::do_unloading(scope()->timer());
325-
_heap->complete_cleaning(purged_class);
322+
{
323+
CodeCache::UnloadingScope unloading_scope(&_is_alive);
324+
// Unload classes and purge the SystemDictionary.
325+
bool unloading_occurred = SystemDictionary::do_unloading(scope()->timer());
326+
_heap->complete_cleaning(unloading_occurred);
327+
}
328+
CodeCache::flush_unlinked_nmethods();
326329
}
327330

328331
{

‎src/hotspot/share/gc/parallel/psParallelCompact.cpp

+14-7
Original file line numberDiff line numberDiff line change
@@ -2052,19 +2052,26 @@ void PSParallelCompact::marking_phase(ParallelOldTracer *gc_tracer) {
20522052

20532053
{
20542054
GCTraceTime(Debug, gc, phases) tm_m("Class Unloading", &_gc_timer);
2055-
CodeCache::UnloadingScope scope(is_alive_closure());
20562055

2057-
// Follow system dictionary roots and unload classes.
2058-
bool purged_class = SystemDictionary::do_unloading(&_gc_timer);
2056+
bool unloading_occurred;
2057+
{
2058+
CodeCache::UnloadingScope scope(is_alive_closure());
2059+
2060+
// Follow system dictionary roots and unload classes.
2061+
unloading_occurred = SystemDictionary::do_unloading(&_gc_timer);
2062+
2063+
// Unload nmethods.
2064+
CodeCache::do_unloading(unloading_occurred);
2065+
}
20592066

2060-
// Unload nmethods.
2061-
CodeCache::do_unloading(purged_class);
2067+
// Release unloaded nmethods's memory.
2068+
CodeCache::flush_unlinked_nmethods();
20622069

20632070
// Prune dead klasses from subklass/sibling/implementor lists.
2064-
Klass::clean_weak_klass_links(purged_class);
2071+
Klass::clean_weak_klass_links(unloading_occurred);
20652072

20662073
// Clean JVMCI metadata handles.
2067-
JVMCI_ONLY(JVMCI::do_unloading(purged_class));
2074+
JVMCI_ONLY(JVMCI::do_unloading(unloading_occurred));
20682075
}
20692076

20702077
{

‎src/hotspot/share/gc/serial/genMarkSweep.cpp

+14-7
Original file line numberDiff line numberDiff line change
@@ -199,19 +199,26 @@ void GenMarkSweep::mark_sweep_phase1(bool clear_all_softrefs) {
199199

200200
{
201201
GCTraceTime(Debug, gc, phases) tm_m("Class Unloading", gc_timer());
202-
CodeCache::UnloadingScope scope(&is_alive);
203202

204-
// Unload classes and purge the SystemDictionary.
205-
bool purged_class = SystemDictionary::do_unloading(gc_timer());
203+
bool unloading_occurred;
204+
{
205+
CodeCache::UnloadingScope scope(&is_alive);
206206

207-
// Unload nmethods.
208-
CodeCache::do_unloading(purged_class);
207+
// Unload classes and purge the SystemDictionary.
208+
unloading_occurred = SystemDictionary::do_unloading(gc_timer());
209+
210+
// Unload nmethods.
211+
CodeCache::do_unloading(unloading_occurred);
212+
}
213+
214+
// Release unloaded nmethod's memory.
215+
CodeCache::flush_unlinked_nmethods();
209216

210217
// Prune dead klasses from subklass/sibling/implementor lists.
211-
Klass::clean_weak_klass_links(purged_class);
218+
Klass::clean_weak_klass_links(unloading_occurred);
212219

213220
// Clean JVMCI metadata handles.
214-
JVMCI_ONLY(JVMCI::do_unloading(purged_class));
221+
JVMCI_ONLY(JVMCI::do_unloading(unloading_occurred));
215222
}
216223

217224
{

‎src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp

+12-8
Original file line numberDiff line numberDiff line change
@@ -1811,14 +1811,18 @@ void ShenandoahHeap::stw_unload_classes(bool full_gc) {
18111811
ShenandoahPhaseTimings::full_gc_purge_class_unload :
18121812
ShenandoahPhaseTimings::degen_gc_purge_class_unload;
18131813
ShenandoahIsAliveSelector is_alive;
1814-
CodeCache::UnloadingScope scope(is_alive.is_alive_closure());
1815-
ShenandoahGCPhase gc_phase(phase);
1816-
ShenandoahGCWorkerPhase worker_phase(phase);
1817-
bool purged_class = SystemDictionary::do_unloading(gc_timer());
1818-
1819-
uint num_workers = _workers->active_workers();
1820-
ShenandoahClassUnloadingTask unlink_task(phase, num_workers, purged_class);
1821-
_workers->run_task(&unlink_task);
1814+
{
1815+
CodeCache::UnloadingScope scope(is_alive.is_alive_closure());
1816+
ShenandoahGCPhase gc_phase(phase);
1817+
ShenandoahGCWorkerPhase worker_phase(phase);
1818+
bool unloading_occurred = SystemDictionary::do_unloading(gc_timer());
1819+
1820+
uint num_workers = _workers->active_workers();
1821+
ShenandoahClassUnloadingTask unlink_task(phase, num_workers, unloading_occurred);
1822+
_workers->run_task(&unlink_task);
1823+
}
1824+
// Release unloaded nmethods's memory.
1825+
CodeCache::flush_unlinked_nmethods();
18221826
}
18231827

18241828
{

0 commit comments

Comments
 (0)