| 1 |
/* |
| 2 |
* Copyright (C) 2017 The Android Open Source Project |
| 3 |
* |
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
* you may not use this file except in compliance with the License. |
| 6 |
* You may obtain a copy of the License at |
| 7 |
* |
| 8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
* |
| 10 |
* Unless required by applicable law or agreed to in writing, software |
| 11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
* See the License for the specific language governing permissions and |
| 14 |
* limitations under the License. |
| 15 |
*/ |
| 16 |
|
| 17 |
#include <atomic> |
| 18 |
|
| 19 |
#include "android-base/logging.h" |
| 20 |
#include "jni.h" |
| 21 |
#include "scoped_local_ref.h" |
| 22 |
#include "scoped_primitive_array.h" |
| 23 |
|
| 24 |
#include "jvmti.h" |
| 25 |
|
| 26 |
// Test infrastructure |
| 27 |
#include "jvmti_helper.h" |
| 28 |
#include "test_env.h" |
| 29 |
|
| 30 |
namespace art { |
| 31 |
namespace Test1941DisposeStress { |
| 32 |
|
| 33 |
extern "C" JNIEXPORT void JNICALL Java_art_Test1941_setTracingOn(JNIEnv* env, |
| 34 |
jclass, |
| 35 |
jthread thr, |
| 36 |
jboolean enable) { |
| 37 |
JvmtiErrorToException(env, |
| 38 |
jvmti_env, |
| 39 |
jvmti_env->SetEventNotificationMode(enable ? JVMTI_ENABLE : JVMTI_DISABLE, |
| 40 |
JVMTI_EVENT_SINGLE_STEP, |
| 41 |
thr)); |
| 42 |
} |
| 43 |
|
| 44 |
extern "C" JNIEXPORT jlong JNICALL Java_art_Test1941_AllocEnv(JNIEnv* env, jclass) { |
| 45 |
JavaVM* vm = nullptr; |
| 46 |
if (env->GetJavaVM(&vm) != 0) { |
| 47 |
ScopedLocalRef<jclass> rt_exception(env, env->FindClass("java/lang/RuntimeException")); |
| 48 |
env->ThrowNew(rt_exception.get(), "Unable to get JavaVM"); |
| 49 |
return -1; |
| 50 |
} |
| 51 |
jvmtiEnv* new_env = nullptr; |
| 52 |
if (vm->GetEnv(reinterpret_cast<void**>(&new_env), JVMTI_VERSION_1_0) != 0) { |
| 53 |
ScopedLocalRef<jclass> rt_exception(env, env->FindClass("java/lang/RuntimeException")); |
| 54 |
env->ThrowNew(rt_exception.get(), "Unable to create new jvmtiEnv"); |
| 55 |
return -1; |
| 56 |
} |
| 57 |
return static_cast<jlong>(reinterpret_cast<intptr_t>(new_env)); |
| 58 |
} |
| 59 |
|
| 60 |
extern "C" JNIEXPORT void JNICALL Java_art_Test1941_FreeEnv(JNIEnv* env, |
| 61 |
jclass, |
| 62 |
jlong jvmti_env_ptr) { |
| 63 |
JvmtiErrorToException(env, |
| 64 |
jvmti_env, |
| 65 |
reinterpret_cast<jvmtiEnv*>(jvmti_env_ptr)->DisposeEnvironment()); |
| 66 |
} |
| 67 |
|
| 68 |
} // namespace Test1941DisposeStress |
| 69 |
} // namespace art |
| 70 |
|