RFR: 8268164: Adopt cast notation for WorkerThread conversions
Stefan Karlsson
stefank at openjdk.java.net
Thu Jun 3 12:29:36 UTC 2021
On Thu, 3 Jun 2021 11:59:35 GMT, Albert Mingkun Yang <ayang at openjdk.org> wrote:
> > I wonder if it wouldn't be nicer to be able to write:
> > ```
> > WorkerThread::current()->id()
> > ```
>
> That will cause a compiling error:
>
> ```
> src/hotspot/share/gc/shared/referenceProcessor.cpp:933:35: error: no member named 'id' in 'Thread'
> id = WorkerThread::current()->id();
> ~~~~~~~~~~~~~~~~~~~~~~~ ^
> 1 error generated.
> ```
>
> `WorkerThread` doesn't have a static `current()` method, so it will get the one from `Thread`, which returns a `Thread*`. However, `id()` is only defined for `WorkerThread`, not `Thread`.
Looks like you just called Thread::current() via WorkerThread. I mean that it would be nice if you could create a function that looked something like this:
static WorkerThread* WorkerThread::current() {
return WorkerThread::cast(Thread::current());
}
-------------
PR: https://git.openjdk.java.net/jdk/pull/4334
More information about the hotspot-dev
mailing list