Skip to content

Commit fd89b33

Browse files
author
Doug Simon
committed
8316992: Potential null pointer from get_current_thread JVMCI helper function.
Reviewed-by: thartmann
1 parent d1c8215 commit fd89b33

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

src/hotspot/share/jvmci/jvmciCompilerToVM.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -179,20 +179,11 @@ Handle JavaArgumentUnboxer::next_arg(BasicType expectedType) {
179179
CompilerThreadCanCallJava ccj(thread, __is_hotspot); \
180180
JVMCIENV_FROM_JNI(JVMCI::compilation_tick(thread), env); \
181181

182-
static JavaThread* get_current_thread(bool allow_null=true) {
183-
Thread* thread = Thread::current_or_null_safe();
184-
if (thread == nullptr) {
185-
assert(allow_null, "npe");
186-
return nullptr;
187-
}
188-
return JavaThread::cast(thread);
189-
}
190-
191182
// Entry to native method implementation that transitions
192183
// current thread to '_thread_in_vm'.
193184
#define C2V_VMENTRY(result_type, name, signature) \
194185
JNIEXPORT result_type JNICALL c2v_ ## name signature { \
195-
JavaThread* thread = get_current_thread(); \
186+
JavaThread* thread = JavaThread::current_or_null(); \
196187
if (thread == nullptr) { \
197188
env->ThrowNew(JNIJVMCI::InternalError::clazz(), \
198189
err_msg("Cannot call into HotSpot from JVMCI shared library without attaching current thread")); \
@@ -203,7 +194,7 @@ static JavaThread* get_current_thread(bool allow_null=true) {
203194

204195
#define C2V_VMENTRY_(result_type, name, signature, result) \
205196
JNIEXPORT result_type JNICALL c2v_ ## name signature { \
206-
JavaThread* thread = get_current_thread(); \
197+
JavaThread* thread = JavaThread::current_or_null(); \
207198
if (thread == nullptr) { \
208199
env->ThrowNew(JNIJVMCI::InternalError::clazz(), \
209200
err_msg("Cannot call into HotSpot from JVMCI shared library without attaching current thread")); \
@@ -219,7 +210,7 @@ static JavaThread* get_current_thread(bool allow_null=true) {
219210
// current thread to '_thread_in_vm'.
220211
#define C2V_VMENTRY_PREFIX(result_type, name, signature) \
221212
JNIEXPORT result_type JNICALL c2v_ ## name signature { \
222-
JavaThread* thread = get_current_thread();
213+
JavaThread* thread = JavaThread::current_or_null();
223214

224215
#define C2V_END }
225216

@@ -2616,7 +2607,7 @@ static void attachSharedLibraryThread(JNIEnv* env, jbyteArray name, jboolean as_
26162607
if (res != JNI_OK) {
26172608
JNI_THROW("attachSharedLibraryThread", InternalError, err_msg("Trying to attach thread returned %d", res));
26182609
}
2619-
JavaThread* thread = get_current_thread(false);
2610+
JavaThread* thread = JavaThread::thread_from_jni_environment(hotspotEnv);
26202611
const char* attach_error;
26212612
{
26222613
// Transition to VM

0 commit comments

Comments
 (0)