In the Thread class we have:
virtual WorkerThread* as_Worker_thread() const { return NULL; }
and then in WorkerThread we have:
virtual WorkerThread* as_Worker_thread() const {
assert(is_Worker_thread(), "Dubious cast to WorkerThread*?");
return (WorkerThread*) this;
}
The intent is clear, but the use of virtual functions means this doesn't work as expected. The assertion can never fire because this is the implementation inside the WorkerThread class so you only call this method when you are guaranteed to have a WorkerThread instance. If you happen to call as_Worker_thread on a non-WorkerThread you will just get NULL and no assertion.
If you wanted to use virtual functions then the correct way to implement this would be:
In Thread class:
virtual WorkerThread* as_Worker_thread() const {
assert(false, "incorrect cast to WorkerThread");
return NULL;
}
and in WorkerThread class simply:
virtual WorkerThread* as_Worker_thread() const { return this; }
Or without virtual functions you use the same pattern as as_Compiler_thread (relative to JavaThread) and simply have the following in the Thread class:
WorkerThread* as_Worker_thread() const {
assert(is_Worker_thread(), "Dubious cast to WorkerThread*?");
return (WorkerThread*) this;
}