|
7 | 7 | #include <string.h> |
8 | 8 | #include <unistd.h> |
9 | 9 | #include <stdarg.h> |
10 | | -#include "hotspot/vmStructs.h" |
| 10 | +#include "hotspot/vmStructs.inline.h" |
11 | 11 | #include "vmEntry.h" |
12 | 12 | #include "jniHelper.h" |
13 | 13 | #include "jvmHeap.h" |
@@ -79,7 +79,7 @@ DECLARE_LONG_CONSTANTS_DO(INIT_LONG_CONSTANT, INIT_LONG_CONSTANT) |
79 | 79 | #undef INIT_INT_CONSTANT |
80 | 80 | #undef INIT_LONG_CONSTANT |
81 | 81 |
|
82 | | - |
| 82 | +jfieldID VMStructs::_eetop = NULL; |
83 | 83 | jfieldID VMStructs::_klass = NULL; |
84 | 84 | intptr_t VMStructs::_env_offset = -1; |
85 | 85 | void* VMStructs::_java_thread_vtbl[6]; |
@@ -605,26 +605,27 @@ void VMStructs::checkNativeBinding(jvmtiEnv *jvmti, JNIEnv *jni, |
605 | 605 | jvmti->Deallocate((unsigned char *)method_name); |
606 | 606 | } |
607 | 607 |
|
608 | | -void VMThread::initialize(void* current) { |
609 | | - VMThread* vm_thread = VMThread::cast(current); |
| 608 | +void* VMThread::initialize(jthread thread) { |
| 609 | + JNIEnv* env = VM::jni(); |
| 610 | + jclass thread_class = env->FindClass("java/lang/Thread"); |
| 611 | + if (thread_class == NULL) { |
| 612 | + env->ExceptionClear(); |
| 613 | + return nullptr; |
| 614 | + } |
| 615 | + |
| 616 | + // Get eetop field - a bridge from Java Thread to VMThread |
| 617 | + if ((_eetop = env->GetFieldID(thread_class, "eetop", "J")) == NULL) { |
| 618 | + // No such field - probably not a HotSpot JVM |
| 619 | + env->ExceptionClear(); |
| 620 | + return nullptr; |
| 621 | + } |
| 622 | + |
| 623 | + VMThread* vm_thread = fromJavaThread(env, thread); |
610 | 624 | assert(vm_thread != nullptr); |
611 | 625 | _has_native_thread_id = _thread_osthread_offset >= 0 && _osthread_id_offset >= 0; |
612 | | - JNIEnv* env = VM::jni(); |
613 | 626 | _env_offset = (intptr_t)env - (intptr_t)vm_thread; |
614 | 627 | memcpy(_java_thread_vtbl, vm_thread->vtable(), sizeof(_java_thread_vtbl)); |
615 | | -} |
616 | | - |
617 | | -VMThread* VMThread::current() { |
618 | | - return VMThread::cast(JVMThread::current()); |
619 | | -} |
620 | | - |
621 | | -int VMThread::nativeThreadId(JNIEnv* jni, jthread thread) { |
622 | | -// assert(_has_native_thread_id); |
623 | | - if (_has_native_thread_id) { |
624 | | - VMThread* vm_thread = cast(JVMThread::fromJavaThread(jni, thread)); |
625 | | - return vm_thread != NULL ? vm_thread->osThreadId() : -1; |
626 | | - } |
627 | | - return -1; |
| 628 | + return (void*)vm_thread; |
628 | 629 | } |
629 | 630 |
|
630 | 631 | int VMThread::osThreadId() { |
|
0 commit comments