Skip to content

Commit d722adc

Browse files
committed
v7
1 parent 9d8b49c commit d722adc

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

ddprof-lib/src/main/cpp/jvmThread.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*/
55

66
#include "jvmThread.h"
7-
87
#include "j9/j9Ext.h"
98

109
pthread_key_t JVMThread::_thread_key = pthread_key_t(-1);
@@ -20,18 +19,18 @@ bool JVMThread::initialize() {
2019
for (int i = 0; i < 1024; i++) {
2120
if (pthread_getspecific((pthread_key_t)i) == current_thread) {
2221
_thread_key = pthread_key_t(i);
23-
return true;
22+
break;
2423
}
2524
}
2625

2726
assert(_tid != nullptr);
28-
assert(_eetop != nullptr);
27+
assert(!VM::isHotspot() || _eetop != nullptr);
2928

3029
if (VM::isHotspot()) {
3130
VMThread::initialize(current_thread);
3231
}
3332

34-
return false;
33+
return true;
3534
}
3635

3736
void* JVMThread::current_thread_slow() {
@@ -51,12 +50,12 @@ void* JVMThread::current_thread_slow() {
5150
if ((_eetop = env->GetFieldID(thread_class, "eetop", "J")) == NULL) {
5251
// No such field - probably not a HotSpot JVM
5352
env->ExceptionClear();
54-
return nullptr;
5553
}
5654

5755
if (VM::isOpenJ9()) {
5856
return J9Ext::j9thread_self();
5957
} else {
58+
assert(_eetop != nullptr);
6059
return (void*)env->GetLongField(thread, _eetop);
6160
}
6261
}

ddprof-lib/src/main/cpp/jvmThread.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ class JVMThread {
4646
}
4747

4848
static void* fromJavaThread(JNIEnv* env, jthread thread) {
49-
return (void*)env->GetLongField(thread, _eetop);
49+
if (_eetop != nullptr) {
50+
return (void*)env->GetLongField(thread, _eetop);
51+
} else {
52+
return nullptr;
53+
}
5054
}
5155

5256
static inline jlong javaThreadId(JNIEnv* env, jthread thread) {

0 commit comments

Comments
 (0)