• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
28 namespace art {
29 namespace Test923Monitors {
30 
31 
MonitorToLong(jrawMonitorID id)32 static jlong MonitorToLong(jrawMonitorID id) {
33   return static_cast<jlong>(reinterpret_cast<uintptr_t>(id));
34 }
35 
LongToMonitor(jlong l)36 static jrawMonitorID LongToMonitor(jlong l) {
37   return reinterpret_cast<jrawMonitorID>(static_cast<uintptr_t>(l));
38 }
39 
Java_art_Test923_createRawMonitor(JNIEnv * env,jclass Main_klass ATTRIBUTE_UNUSED)40 extern "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("placeholder", &id);
44   if (JvmtiErrorToException(env, jvmti_env, result)) {
45     return 0;
46   }
47   return MonitorToLong(id);
48 }
49 
Java_art_Test923_destroyRawMonitor(JNIEnv * env,jclass Main_klass ATTRIBUTE_UNUSED,jlong l)50 extern "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 
Java_art_Test923_rawMonitorEnter(JNIEnv * env,jclass Main_klass ATTRIBUTE_UNUSED,jlong l)56 extern "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 
Java_art_Test923_rawMonitorExit(JNIEnv * env,jclass Main_klass ATTRIBUTE_UNUSED,jlong l)62 extern "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 
Java_art_Test923_rawMonitorWait(JNIEnv * env,jclass Main_klass ATTRIBUTE_UNUSED,jlong l,jlong millis)68 extern "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 
Java_art_Test923_rawMonitorNotify(JNIEnv * env,jclass Main_klass ATTRIBUTE_UNUSED,jlong l)74 extern "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 
Java_art_Test923_rawMonitorNotifyAll(JNIEnv * env,jclass Main_klass ATTRIBUTE_UNUSED,jlong l)80 extern "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