diff options
Diffstat (limited to 'test/924-threads/threads.cc')
| -rw-r--r-- | test/924-threads/threads.cc | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/test/924-threads/threads.cc b/test/924-threads/threads.cc index 4abf8fcf93..d35eaa8365 100644 --- a/test/924-threads/threads.cc +++ b/test/924-threads/threads.cc @@ -100,5 +100,42 @@ extern "C" JNIEXPORT jint JNICALL Java_Main_getThreadState( return state; } +extern "C" JNIEXPORT jobjectArray JNICALL Java_Main_getAllThreads( + JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED) { + jint thread_count; + jthread* threads; + + jvmtiError result = jvmti_env->GetAllThreads(&thread_count, &threads); + if (JvmtiErrorToException(env, result)) { + return nullptr; + } + + auto callback = [&](jint index) { + return threads[index]; + }; + jobjectArray ret = CreateObjectArray(env, thread_count, "java/lang/Thread", callback); + + jvmti_env->Deallocate(reinterpret_cast<unsigned char*>(threads)); + + return ret; +} + +extern "C" JNIEXPORT jlong JNICALL Java_Main_getTLS( + JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED, jthread thread) { + void* tls; + jvmtiError result = jvmti_env->GetThreadLocalStorage(thread, &tls); + if (JvmtiErrorToException(env, result)) { + return 0; + } + return static_cast<jlong>(reinterpret_cast<uintptr_t>(tls)); +} + +extern "C" JNIEXPORT void JNICALL Java_Main_setTLS( + JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED, jthread thread, jlong val) { + const void* tls = reinterpret_cast<void*>(static_cast<uintptr_t>(val)); + jvmtiError result = jvmti_env->SetThreadLocalStorage(thread, tls); + JvmtiErrorToException(env, result); +} + } // namespace Test924Threads } // namespace art |