RFR: 8268368: Adopt cast notation for JavaThread conversions [v2]

Stefan Karlsson stefank at openjdk.java.net
Tue Jun 22 10:24:31 UTC 2021


On Tue, 22 Jun 2021 07:17:00 GMT, Guoxiong Li <gli at openjdk.org> wrote:

>> Hi all,
>> 
>> Considering the consistency of `JavaThread` and other threads, such as WorkerThread and CompilerThread, `JavaThread` could use a method named `cast` to replace the method `Thread::as_Java_thread()`. It can reduce the Thread's knowledge about the subtypes.
>> 
>> This patch removes two methods, `JavaThread* Thread::as_Java_thread()` and `const JavaThread* Thread::as_Java_thread() const`, of the class `Thread` and adds two static methods, `JavaThread* cast(Thread* t)` and `const JavaThread* cast(const Thread* t)`, to the class `JavaThread`. Correspondingly, the code of the method `JavaThread::current()` need to be adjusted and many places where the method `Thread::as_Java_thread()` is used need to use `JavaThread::cast` instead.
>> 
>> Test:
>> tier1 passed locally.
>> 
>> Thanks for taking the time to review.
>> 
>> Best Regards,
>> -- Guoxiong
>
> Guoxiong Li has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Fix incorrect use of the method cast

Marked as reviewed by stefank (Reviewer).

src/hotspot/share/runtime/thread.hpp line 1432:

> 1430:     assert(t->is_Java_thread(), "incorrect cast to const JavaThread");
> 1431:     return static_cast<const JavaThread*>(t);
> 1432:   }

Now that you've written the code in-place, you could  remove the `inline` specifier.

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

PR: https://git.openjdk.java.net/jdk/pull/4546


More information about the serviceability-dev mailing list