RFR: 8273597: Rectify Thread::is_ConcurrentGC_thread()
Stefan Karlsson
stefank at openjdk.java.net
Fri Sep 10 13:48:39 UTC 2021
On Fri, 10 Sep 2021 12:39:14 GMT, Per Liden <pliden at openjdk.org> wrote:
> `Thread::is_ConcurrentGC_thread()` behaves differently to all other `Thread::is_xxx_thread()` functions, in the sense that it doesn't directly map to a distinct `Thread` sub-class. Instead, `is_ConcurrentGC_thread()` can today return true for both `ConcurrentGCThread` and `GangWorker`. These two classes have no super/sub-class relation. This is confusing and and potentially dangerous.
>
> It would be reasonable to think that code like this would be correct:
>
>
> if (thread->is_ConcurrentGC_thread()) {
> conc_thread = static_cast<ConcurrentGCThread*>(thread);
> ...
> }
>
>
> but it's not, since we might try to cast a `GangWorker` to a `ConcurrentGCThread`. And again, these two classes have no super/sub-class relation.
>
> I propose that we clean this up, so that `is_ConcurrentGCThread()` only returns true for threads inheriting from `ConcurrentGCThread`. The main side-effect is that a handful of asserts need to be adjusted. In return, the code example above would become legal, and we can also remove some cruft from `WorkGang`/`GangWorker`.
Thanks for cleaning this up.
src/hotspot/share/code/nmethod.cpp line 1563:
> 1561: DEBUG_ONLY(bool called_by_gc = Universe::heap()->is_gc_active() ||
> 1562: Thread::current()->is_ConcurrentGC_thread() ||
> 1563: Thread::current()->is_Worker_thread();)
Three places use the same condition. Did you consider creating a helper function?
src/hotspot/share/gc/parallel/parallelScavengeHeap.hpp line 122:
> 120: _old_pool(NULL),
> 121: _workers("GC Thread",
> 122: ParallelGCThreads) { }
Consider moving this up to the line above, like the G1 code.
-------------
Marked as reviewed by stefank (Reviewer).
PR: https://git.openjdk.java.net/jdk/pull/5463
More information about the shenandoah-dev
mailing list