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

Albert Mingkun Yang ayang at openjdk.java.net
Tue May 25 06:43:51 UTC 2021


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.

> 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.

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

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


More information about the hotspot-runtime-dev mailing list