Andreas Gampe | 319dbe8 | 2017-01-09 16:42:21 -0800 | [diff] [blame^] | 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 "monitors.h" |
| 18 | |
| 19 | #include <stdio.h> |
| 20 | |
| 21 | #include "base/macros.h" |
| 22 | #include "jni.h" |
| 23 | #include "openjdkjvmti/jvmti.h" |
| 24 | #include "ScopedUtfChars.h" |
| 25 | |
| 26 | #include "ti-agent/common_helper.h" |
| 27 | #include "ti-agent/common_load.h" |
| 28 | |
| 29 | namespace art { |
| 30 | namespace Test923Monitors { |
| 31 | |
| 32 | |
| 33 | static jlong MonitorToLong(jrawMonitorID id) { |
| 34 | return static_cast<jlong>(reinterpret_cast<uintptr_t>(id)); |
| 35 | } |
| 36 | |
| 37 | static jrawMonitorID LongToMonitor(jlong l) { |
| 38 | return reinterpret_cast<jrawMonitorID>(static_cast<uintptr_t>(l)); |
| 39 | } |
| 40 | |
| 41 | extern "C" JNIEXPORT jlong JNICALL Java_Main_createRawMonitor( |
| 42 | JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED) { |
| 43 | jrawMonitorID id; |
| 44 | jvmtiError result = jvmti_env->CreateRawMonitor("dummy", &id); |
| 45 | if (JvmtiErrorToException(env, result)) { |
| 46 | return 0; |
| 47 | } |
| 48 | return MonitorToLong(id); |
| 49 | } |
| 50 | |
| 51 | extern "C" JNIEXPORT void JNICALL Java_Main_destroyRawMonitor( |
| 52 | JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED, jlong l) { |
| 53 | jvmtiError result = jvmti_env->DestroyRawMonitor(LongToMonitor(l)); |
| 54 | JvmtiErrorToException(env, result); |
| 55 | } |
| 56 | |
| 57 | extern "C" JNIEXPORT void JNICALL Java_Main_rawMonitorEnter( |
| 58 | JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED, jlong l) { |
| 59 | jvmtiError result = jvmti_env->RawMonitorEnter(LongToMonitor(l)); |
| 60 | JvmtiErrorToException(env, result); |
| 61 | } |
| 62 | |
| 63 | extern "C" JNIEXPORT void JNICALL Java_Main_rawMonitorExit( |
| 64 | JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED, jlong l) { |
| 65 | jvmtiError result = jvmti_env->RawMonitorExit(LongToMonitor(l)); |
| 66 | JvmtiErrorToException(env, result); |
| 67 | } |
| 68 | |
| 69 | extern "C" JNIEXPORT void JNICALL Java_Main_rawMonitorWait( |
| 70 | JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED, jlong l, jlong millis) { |
| 71 | jvmtiError result = jvmti_env->RawMonitorWait(LongToMonitor(l), millis); |
| 72 | JvmtiErrorToException(env, result); |
| 73 | } |
| 74 | |
| 75 | extern "C" JNIEXPORT void JNICALL Java_Main_rawMonitorNotify( |
| 76 | JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED, jlong l) { |
| 77 | jvmtiError result = jvmti_env->RawMonitorNotify(LongToMonitor(l)); |
| 78 | JvmtiErrorToException(env, result); |
| 79 | } |
| 80 | |
| 81 | extern "C" JNIEXPORT void JNICALL Java_Main_rawMonitorNotifyAll( |
| 82 | JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED, jlong l) { |
| 83 | jvmtiError result = jvmti_env->RawMonitorNotifyAll(LongToMonitor(l)); |
| 84 | JvmtiErrorToException(env, result); |
| 85 | } |
| 86 | |
| 87 | // Don't do anything |
| 88 | jint OnLoad(JavaVM* vm, |
| 89 | char* options ATTRIBUTE_UNUSED, |
| 90 | void* reserved ATTRIBUTE_UNUSED) { |
| 91 | if (vm->GetEnv(reinterpret_cast<void**>(&jvmti_env), JVMTI_VERSION_1_0)) { |
| 92 | printf("Unable to get jvmti env!\n"); |
| 93 | return 1; |
| 94 | } |
| 95 | SetAllCapabilities(jvmti_env); |
| 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | } // namespace Test923Monitors |
| 100 | } // namespace art |