Skip to content

Commit d2c6be9

Browse files
committed
8317350: Move code cache purging out of CodeCache::UnloadingScope
Backport-of: bd3bc2c6181668b5856732666dc251136b7fbb99
1 parent c094d7e commit d2c6be9

File tree

7 files changed

+54
-34
lines changed

7 files changed

+54
-34
lines changed

src/hotspot/share/code/codeCache.cpp

Lines changed: 0 additions & 1 deletion
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

Lines changed: 1 addition & 4 deletions
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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,9 +1684,12 @@ void G1ConcurrentMark::weak_refs_work() {
16841684
// Unload Klasses, String, Code Cache, etc.
16851685
if (ClassUnloadingWithConcurrentMark) {
16861686
GCTraceTime(Debug, gc, phases) debug("Class Unloading", _gc_timer_cm);
1687-
CodeCache::UnloadingScope scope(&g1_is_alive);
1688-
bool purged_classes = SystemDictionary::do_unloading(_gc_timer_cm);
1689-
_g1h->complete_cleaning(purged_classes);
1687+
{
1688+
CodeCache::UnloadingScope scope(&g1_is_alive);
1689+
bool unloading_occurred = SystemDictionary::do_unloading(_gc_timer_cm);
1690+
_g1h->complete_cleaning(unloading_occurred);
1691+
}
1692+
CodeCache::flush_unlinked_nmethods();
16901693
}
16911694
}
16921695

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

Lines changed: 7 additions & 4 deletions
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

Lines changed: 14 additions & 7 deletions
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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,19 +195,26 @@ void GenMarkSweep::mark_sweep_phase1(bool clear_all_softrefs) {
195195

196196
{
197197
GCTraceTime(Debug, gc, phases) tm_m("Class Unloading", gc_timer());
198-
CodeCache::UnloadingScope scope(&is_alive);
199198

200-
// Unload classes and purge the SystemDictionary.
201-
bool purged_class = SystemDictionary::do_unloading(gc_timer());
199+
bool unloading_occurred;
200+
{
201+
CodeCache::UnloadingScope scope(&is_alive);
202202

203-
// Unload nmethods.
204-
CodeCache::do_unloading(purged_class);
203+
// Unload classes and purge the SystemDictionary.
204+
unloading_occurred = SystemDictionary::do_unloading(gc_timer());
205+
206+
// Unload nmethods.
207+
CodeCache::do_unloading(unloading_occurred);
208+
}
209+
210+
// Release unloaded nmethod's memory.
211+
CodeCache::flush_unlinked_nmethods();
205212

206213
// Prune dead klasses from subklass/sibling/implementor lists.
207-
Klass::clean_weak_klass_links(purged_class);
214+
Klass::clean_weak_klass_links(unloading_occurred);
208215

209216
// Clean JVMCI metadata handles.
210-
JVMCI_ONLY(JVMCI::do_unloading(purged_class));
217+
JVMCI_ONLY(JVMCI::do_unloading(unloading_occurred));
211218
}
212219

213220
{

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,14 +1773,18 @@ void ShenandoahHeap::stw_unload_classes(bool full_gc) {
17731773
ShenandoahPhaseTimings::full_gc_purge_class_unload :
17741774
ShenandoahPhaseTimings::degen_gc_purge_class_unload;
17751775
ShenandoahIsAliveSelector is_alive;
1776-
CodeCache::UnloadingScope scope(is_alive.is_alive_closure());
1777-
ShenandoahGCPhase gc_phase(phase);
1778-
ShenandoahGCWorkerPhase worker_phase(phase);
1779-
bool purged_class = SystemDictionary::do_unloading(gc_timer());
1780-
1781-
uint num_workers = _workers->active_workers();
1782-
ShenandoahClassUnloadingTask unlink_task(phase, num_workers, purged_class);
1783-
_workers->run_task(&unlink_task);
1776+
{
1777+
CodeCache::UnloadingScope scope(is_alive.is_alive_closure());
1778+
ShenandoahGCPhase gc_phase(phase);
1779+
ShenandoahGCWorkerPhase worker_phase(phase);
1780+
bool unloading_occurred = SystemDictionary::do_unloading(gc_timer());
1781+
1782+
uint num_workers = _workers->active_workers();
1783+
ShenandoahClassUnloadingTask unlink_task(phase, num_workers, unloading_occurred);
1784+
_workers->run_task(&unlink_task);
1785+
}
1786+
// Release unloaded nmethods's memory.
1787+
CodeCache::flush_unlinked_nmethods();
17841788
}
17851789

17861790
{

0 commit comments

Comments
 (0)