From 93d0f4e36b21bfb1ad0deebc6eefb3eed04e31e4 Mon Sep 17 00:00:00 2001 From: William Kemper Date: Fri, 15 Dec 2023 11:16:08 -0800 Subject: [PATCH] Extra assertions that gc state synchronization is correct --- src/hotspot/share/gc/shenandoah/shenandoahHeap.hpp | 1 + .../share/gc/shenandoah/shenandoahVMOperations.cpp | 11 +++++++++++ .../share/gc/shenandoah/shenandoahVMOperations.hpp | 2 ++ 3 files changed, 14 insertions(+) diff --git a/src/hotspot/share/gc/shenandoah/shenandoahHeap.hpp b/src/hotspot/share/gc/shenandoah/shenandoahHeap.hpp index da0990a22f702..1873ee040e3f7 100644 --- a/src/hotspot/share/gc/shenandoah/shenandoahHeap.hpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahHeap.hpp @@ -298,6 +298,7 @@ class ShenandoahHeap : public CollectedHeap, public ShenandoahSpaceInfo { public: char gc_state() const; void set_gc_state_all_threads(); + bool has_gc_state_changed() { return _gc_state_changed; } void set_concurrent_mark_in_progress(bool in_progress); void set_evacuation_in_progress(bool in_progress); diff --git a/src/hotspot/share/gc/shenandoah/shenandoahVMOperations.cpp b/src/hotspot/share/gc/shenandoah/shenandoahVMOperations.cpp index 730cc992f0ec9..970f99ad0f563 100644 --- a/src/hotspot/share/gc/shenandoah/shenandoahVMOperations.cpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahVMOperations.cpp @@ -35,12 +35,23 @@ #include "interpreter/oopMapCache.hpp" #include "memory/universe.hpp" +bool VM_ShenandoahOperation::doit_prologue() { + assert(!ShenandoahHeap::heap()->has_gc_state_changed(), "GC State can only be changed on a safepoint."); + return true; +} + +void VM_ShenandoahOperation::doit_epilogue() { + assert(!ShenandoahHeap::heap()->has_gc_state_changed(), "GC State was not synchronized to java threads."); +} + bool VM_ShenandoahReferenceOperation::doit_prologue() { + VM_ShenandoahOperation::doit_prologue(); Heap_lock->lock(); return true; } void VM_ShenandoahReferenceOperation::doit_epilogue() { + VM_ShenandoahOperation::doit_epilogue(); OopMapCache::cleanup_old_entries(); if (Universe::has_reference_pending_list()) { Heap_lock->notify_all(); diff --git a/src/hotspot/share/gc/shenandoah/shenandoahVMOperations.hpp b/src/hotspot/share/gc/shenandoah/shenandoahVMOperations.hpp index f794bec5b34e6..a385f4f71be51 100644 --- a/src/hotspot/share/gc/shenandoah/shenandoahVMOperations.hpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahVMOperations.hpp @@ -48,6 +48,8 @@ class VM_ShenandoahOperation : public VM_Operation { public: VM_ShenandoahOperation() : _gc_id(GCId::current()) {}; virtual bool skip_thread_oop_barriers() const { return true; } + bool doit_prologue() override; + void doit_epilogue() override; }; class VM_ShenandoahReferenceOperation : public VM_ShenandoahOperation {