Skip to content

Commit bfa46f0

Browse files
albertnetymkDavid Holmes
andcommitted
8252476: as_Worker_thread() doesn't check what it intends
Co-authored-by: David Holmes <dholmes@openjdk.org> Reviewed-by: iklam, kbarrett
1 parent 37bc4e2 commit bfa46f0

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

src/hotspot/share/gc/shared/referenceProcessor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "oops/oop.inline.hpp"
4141
#include "runtime/java.hpp"
4242
#include "runtime/nonJavaThread.hpp"
43+
#include "runtime/thread.inline.hpp"
4344

4445
ReferencePolicy* ReferenceProcessor::_always_clear_soft_ref_policy = NULL;
4546
ReferencePolicy* ReferenceProcessor::_default_soft_ref_policy = NULL;

src/hotspot/share/runtime/nonJavaThread.hpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,6 @@ class WorkerThread: public NamedThread {
106106
WorkerThread() : _id(0) { }
107107
virtual bool is_Worker_thread() const { return true; }
108108

109-
virtual WorkerThread* as_Worker_thread() const {
110-
assert(is_Worker_thread(), "Dubious cast to WorkerThread*?");
111-
return (WorkerThread*) this;
112-
}
113-
114109
void set_id(uint work_id) { _id = work_id; }
115110
uint id() const { return _id; }
116111
};

src/hotspot/share/runtime/thread.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ class Thread: public ThreadShadow {
355355
virtual bool is_active_Java_thread() const { return false; }
356356

357357
// Casts
358-
virtual WorkerThread* as_Worker_thread() const { return NULL; }
358+
inline const WorkerThread* as_Worker_thread() const;
359359
inline JavaThread* as_Java_thread();
360360
inline const JavaThread* as_Java_thread() const;
361361

src/hotspot/share/runtime/thread.inline.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "runtime/orderAccess.hpp"
3232
#include "runtime/safepoint.hpp"
3333
#include "runtime/thread.hpp"
34+
#include "runtime/nonJavaThread.hpp"
3435

3536
#if defined(__APPLE__) && defined(AARCH64)
3637
#include "runtime/os.hpp"
@@ -64,6 +65,11 @@ inline void Thread::set_threads_hazard_ptr(ThreadsList* new_list) {
6465
Atomic::release_store_fence(&_threads_hazard_ptr, new_list);
6566
}
6667

68+
inline const WorkerThread* Thread::as_Worker_thread() const {
69+
assert(is_Worker_thread(), "incorrect cast to const WorkerThread");
70+
return static_cast<const WorkerThread*>(this);
71+
}
72+
6773
#if defined(__APPLE__) && defined(AARCH64)
6874
inline void Thread::init_wx() {
6975
assert(this == Thread::current(), "should only be called for current thread");

0 commit comments

Comments
 (0)