8276205: Shenandoah: CodeCache_lock should always be held for initializing code cache iteration

Reviewed-by: shade
This commit is contained in:
Zhengyu Gu 2021-11-01 19:38:49 +00:00
parent 977154400b
commit 99b7b95e01
2 changed files with 6 additions and 2 deletions

View File

@ -355,12 +355,15 @@ ShenandoahCodeRootsIterator::ShenandoahCodeRootsIterator() :
_par_iterator(CodeCache::heaps()), _par_iterator(CodeCache::heaps()),
_table_snapshot(NULL) { _table_snapshot(NULL) {
assert(SafepointSynchronize::is_at_safepoint(), "Must be at safepoint"); assert(SafepointSynchronize::is_at_safepoint(), "Must be at safepoint");
MutexLocker locker(CodeCache_lock, Mutex::_no_safepoint_check_flag);
_table_snapshot = ShenandoahCodeRoots::table()->snapshot_for_iteration(); _table_snapshot = ShenandoahCodeRoots::table()->snapshot_for_iteration();
} }
ShenandoahCodeRootsIterator::~ShenandoahCodeRootsIterator() { ShenandoahCodeRootsIterator::~ShenandoahCodeRootsIterator() {
MonitorLocker locker(CodeCache_lock, Mutex::_no_safepoint_check_flag);
ShenandoahCodeRoots::table()->finish_iteration(_table_snapshot); ShenandoahCodeRoots::table()->finish_iteration(_table_snapshot);
_table_snapshot = NULL; _table_snapshot = NULL;
locker.notify_all();
} }
void ShenandoahCodeRootsIterator::possibly_parallel_blobs_do(CodeBlobClosure *f) { void ShenandoahCodeRootsIterator::possibly_parallel_blobs_do(CodeBlobClosure *f) {

View File

@ -158,7 +158,7 @@ ShenandoahConcurrentRootScanner::ShenandoahConcurrentRootScanner(uint n_workers,
_codecache_snapshot(NULL), _codecache_snapshot(NULL),
_phase(phase) { _phase(phase) {
if (!ShenandoahHeap::heap()->unload_classes()) { if (!ShenandoahHeap::heap()->unload_classes()) {
CodeCache_lock->lock_without_safepoint_check(); MutexLocker locker(CodeCache_lock, Mutex::_no_safepoint_check_flag);
_codecache_snapshot = ShenandoahCodeRoots::table()->snapshot_for_iteration(); _codecache_snapshot = ShenandoahCodeRoots::table()->snapshot_for_iteration();
} }
update_tlab_stats(); update_tlab_stats();
@ -167,8 +167,9 @@ ShenandoahConcurrentRootScanner::ShenandoahConcurrentRootScanner(uint n_workers,
ShenandoahConcurrentRootScanner::~ShenandoahConcurrentRootScanner() { ShenandoahConcurrentRootScanner::~ShenandoahConcurrentRootScanner() {
if (!ShenandoahHeap::heap()->unload_classes()) { if (!ShenandoahHeap::heap()->unload_classes()) {
MonitorLocker locker(CodeCache_lock, Mutex::_no_safepoint_check_flag);
ShenandoahCodeRoots::table()->finish_iteration(_codecache_snapshot); ShenandoahCodeRoots::table()->finish_iteration(_codecache_snapshot);
CodeCache_lock->unlock(); locker.notify_all();
} }
} }