| 22 | JavaVM *GetJVM() { return g_jvm; } |
| 23 | |
| 24 | JNIEnv *AttachCurrentThread() { |
| 25 | JNIEnv *env = nullptr; |
| 26 | |
| 27 | JavaVMAttachArgs args; |
| 28 | args.version = JNI_VERSION_1_4; |
| 29 | args.name = nullptr; |
| 30 | args.group = nullptr; |
| 31 | args.name = std::to_string(gettid()).data(); |
| 32 | |
| 33 | jint ret = g_jvm->AttachCurrentThread(&env, &args); |
| 34 | // LOGI("AttachCurrentThread:name=%s,ret=%d", (args.name == nullptr ? "[null]" : args.name), ret); |
| 35 | assert(JNI_OK == ret); |
| 36 | return env; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Get a JNIEnv* valid for this thread, regardless of whether |
no test coverage detected