RFR: 8252476: as_Worker_thread() doesn't check what it intends [v2]

David Holmes david.holmes at oracle.com
Tue May 25 06:51:00 UTC 2021


On 25/05/2021 4:43 pm, Albert Mingkun Yang wrote:
> On Tue, 25 May 2021 01:17:16 GMT, David Holmes <dholmes at openjdk.org> wrote:
> 
>>> Albert Mingkun Yang has updated the pull request incrementally with one additional commit since the last revision:
>>>
>>>    review
>>
>> src/hotspot/share/runtime/thread.hpp line 1593:
>>
>>> 1591:
>>> 1592: inline WorkerThread* Thread::as_Worker_thread() const {
>>> 1593:   assert(is_Worker_thread(), "Dubious cast to WorkerThread*?");
>>
>> More than dubious I would say, just plain wrong.
> 
> Fixed.

Thanks.

>> src/hotspot/share/runtime/thread.hpp line 1594:
>>
>>> 1592: inline WorkerThread* Thread::as_Worker_thread() const {
>>> 1593:   assert(is_Worker_thread(), "Dubious cast to WorkerThread*?");
>>> 1594:   return (WorkerThread*)this;
>>
>> Can you use static_cast here rather the C-style cast please.
> 
> I get an compiling error, `static_cast from 'const Thread *' to 'WorkerThread *', which are not related by inheritance, is not allowed`. As `WorkerThread` is only declared in this context, the compiler doesn't know the inheritance relation here.

Ah I see. That is a downside of moving the NJT declarations to 
nonJavaThread.hpp :(

Thanks,
David

> -------------
> 
> PR: https://git.openjdk.java.net/jdk/pull/4167
> 


More information about the hotspot-runtime-dev mailing list