RFR: 8313224: Avoid calling JavaThread::current() in MemAllocator::Allocation constructor [v2]

Coleen Phillimore coleenp at openjdk.org
Thu Aug 10 15:05:59 UTC 2023


On Fri, 28 Jul 2023 04:46:00 GMT, Ioi Lam <iklam at openjdk.org> wrote:

>> src/hotspot/share/gc/shared/memAllocator.cpp line 100:
>> 
>>> 98: 
>>> 99: public:
>>> 100:   PreserveObj(Thread* thread, oop* obj_ptr)
>> 
>> Why did you change this? Following through the usage call chain it is only used by the `_thread` from `Allocation` which has to be a `JavaThread`.
>
> I wanted to minimize the use of `JavaThread`. Most of the MemAllocator APIs take `Thread`, so any occurrence of `JavaThread` looks suspicious and may cause people to unwittingly cast from `Thread` to `JavaThread` in the future.

This is a most confusing set of classes.  Why doesn't MemAllocator take a JavaThread?  Which _thread does this code use?  I think the more specific type is generally better. It doesn't seem like a bad thing for the caller to be required to have a JavaThread.  Its caller does have a JavaThread.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/15058#discussion_r1290256875


More information about the hotspot-gc-dev mailing list