blob: 4baa530ec213b29e911c912fecccb9a66ffc4624 [file] [log] [blame]
Andreas Gampe319dbe82017-01-09 16:42:21 -08001/*
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
Andreas Gampe319dbe82017-01-09 16:42:21 -080017#include <stdio.h>
18
19#include "base/macros.h"
20#include "jni.h"
21#include "openjdkjvmti/jvmti.h"
22#include "ScopedUtfChars.h"
23
24#include "ti-agent/common_helper.h"
25#include "ti-agent/common_load.h"
26
27namespace art {
28namespace Test923Monitors {
29
30
31static jlong MonitorToLong(jrawMonitorID id) {
32 return static_cast<jlong>(reinterpret_cast<uintptr_t>(id));
33}
34
35static jrawMonitorID LongToMonitor(jlong l) {
36 return reinterpret_cast<jrawMonitorID>(static_cast<uintptr_t>(l));
37}
38
39extern "C" JNIEXPORT jlong JNICALL Java_Main_createRawMonitor(
40 JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED) {
41 jrawMonitorID id;
42 jvmtiError result = jvmti_env->CreateRawMonitor("dummy", &id);
43 if (JvmtiErrorToException(env, result)) {
44 return 0;
45 }
46 return MonitorToLong(id);
47}
48
49extern "C" JNIEXPORT void JNICALL Java_Main_destroyRawMonitor(
50 JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED, jlong l) {
51 jvmtiError result = jvmti_env->DestroyRawMonitor(LongToMonitor(l));
52 JvmtiErrorToException(env, result);
53}
54
55extern "C" JNIEXPORT void JNICALL Java_Main_rawMonitorEnter(
56 JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED, jlong l) {
57 jvmtiError result = jvmti_env->RawMonitorEnter(LongToMonitor(l));
58 JvmtiErrorToException(env, result);
59}
60
61extern "C" JNIEXPORT void JNICALL Java_Main_rawMonitorExit(
62 JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED, jlong l) {
63 jvmtiError result = jvmti_env->RawMonitorExit(LongToMonitor(l));
64 JvmtiErrorToException(env, result);
65}
66
67extern "C" JNIEXPORT void JNICALL Java_Main_rawMonitorWait(
68 JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED, jlong l, jlong millis) {
69 jvmtiError result = jvmti_env->RawMonitorWait(LongToMonitor(l), millis);
70 JvmtiErrorToException(env, result);
71}
72
73extern "C" JNIEXPORT void JNICALL Java_Main_rawMonitorNotify(
74 JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED, jlong l) {
75 jvmtiError result = jvmti_env->RawMonitorNotify(LongToMonitor(l));
76 JvmtiErrorToException(env, result);
77}
78
79extern "C" JNIEXPORT void JNICALL Java_Main_rawMonitorNotifyAll(
80 JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED, jlong l) {
81 jvmtiError result = jvmti_env->RawMonitorNotifyAll(LongToMonitor(l));
82 JvmtiErrorToException(env, result);
83}
84
Andreas Gampe319dbe82017-01-09 16:42:21 -080085} // namespace Test923Monitors
86} // namespace art