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 <stdio.h> 18 19#include "android-base/macros.h" 20#include "jni.h" 21#include "jvmti.h" 22#include "scoped_utf_chars.h" 23 24// Test infrastructure 25#include "jvmti_helper.h" 26#include "test_env.h" 27 28namespace art { 29namespace Test923Monitors { 30 31 32static jlong MonitorToLong(jrawMonitorID id) { 33 return static_cast<jlong>(reinterpret_cast<uintptr_t>(id)); 34} 35 36static jrawMonitorID LongToMonitor(jlong l) { 37 return reinterpret_cast<jrawMonitorID>(static_cast<uintptr_t>(l)); 38} 39 40extern "C" JNIEXPORT jlong JNICALL Java_art_Test923_createRawMonitor( 41 JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED) { 42 jrawMonitorID id; 43 jvmtiError result = jvmti_env->CreateRawMonitor("dummy", &id); 44 if (JvmtiErrorToException(env, jvmti_env, result)) { 45 return 0; 46 } 47 return MonitorToLong(id); 48} 49 50extern "C" JNIEXPORT void JNICALL Java_art_Test923_destroyRawMonitor( 51 JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED, jlong l) { 52 jvmtiError result = jvmti_env->DestroyRawMonitor(LongToMonitor(l)); 53 JvmtiErrorToException(env, jvmti_env, result); 54} 55 56extern "C" JNIEXPORT void JNICALL Java_art_Test923_rawMonitorEnter( 57 JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED, jlong l) { 58 jvmtiError result = jvmti_env->RawMonitorEnter(LongToMonitor(l)); 59 JvmtiErrorToException(env, jvmti_env, result); 60} 61 62extern "C" JNIEXPORT void JNICALL Java_art_Test923_rawMonitorExit( 63 JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED, jlong l) { 64 jvmtiError result = jvmti_env->RawMonitorExit(LongToMonitor(l)); 65 JvmtiErrorToException(env, jvmti_env, result); 66} 67 68extern "C" JNIEXPORT void JNICALL Java_art_Test923_rawMonitorWait( 69 JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED, jlong l, jlong millis) { 70 jvmtiError result = jvmti_env->RawMonitorWait(LongToMonitor(l), millis); 71 JvmtiErrorToException(env, jvmti_env, result); 72} 73 74extern "C" JNIEXPORT void JNICALL Java_art_Test923_rawMonitorNotify( 75 JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED, jlong l) { 76 jvmtiError result = jvmti_env->RawMonitorNotify(LongToMonitor(l)); 77 JvmtiErrorToException(env, jvmti_env, result); 78} 79 80extern "C" JNIEXPORT void JNICALL Java_art_Test923_rawMonitorNotifyAll( 81 JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED, jlong l) { 82 jvmtiError result = jvmti_env->RawMonitorNotifyAll(LongToMonitor(l)); 83 JvmtiErrorToException(env, jvmti_env, result); 84} 85 86} // namespace Test923Monitors 87} // namespace art 88