blob: 9afe22de042f7bfaec813b557e155297ab82d38b [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
Andreas Gampe027444b2017-03-31 12:49:07 -070019#include "android-base/macros.h"
Andreas Gampe319dbe82017-01-09 16:42:21 -080020#include "jni.h"
Andreas Gampe5e03a302017-03-13 13:10:00 -070021#include "jvmti.h"
Andreas Gampe027444b2017-03-31 12:49:07 -070022#include "scoped_utf_chars.h"
Andreas Gampe319dbe82017-01-09 16:42:21 -080023
Andreas Gampe3f46c962017-03-30 10:26:59 -070024// Test infrastructure
25#include "jvmti_helper.h"
26#include "test_env.h"
Andreas Gampe319dbe82017-01-09 16:42:21 -080027
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
Andreas Gampe46651672017-04-07 09:00:04 -070040extern "C" JNIEXPORT jlong JNICALL Java_art_Test923_createRawMonitor(
Andreas Gampe319dbe82017-01-09 16:42:21 -080041 JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED) {
42 jrawMonitorID id;
43 jvmtiError result = jvmti_env->CreateRawMonitor("dummy", &id);
Andreas Gampe3f46c962017-03-30 10:26:59 -070044 if (JvmtiErrorToException(env, jvmti_env, result)) {
Andreas Gampe319dbe82017-01-09 16:42:21 -080045 return 0;
46 }
47 return MonitorToLong(id);
48}
49
Andreas Gampe46651672017-04-07 09:00:04 -070050extern "C" JNIEXPORT void JNICALL Java_art_Test923_destroyRawMonitor(
Andreas Gampe319dbe82017-01-09 16:42:21 -080051 JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED, jlong l) {
52 jvmtiError result = jvmti_env->DestroyRawMonitor(LongToMonitor(l));
Andreas Gampe3f46c962017-03-30 10:26:59 -070053 JvmtiErrorToException(env, jvmti_env, result);
Andreas Gampe319dbe82017-01-09 16:42:21 -080054}
55
Andreas Gampe46651672017-04-07 09:00:04 -070056extern "C" JNIEXPORT void JNICALL Java_art_Test923_rawMonitorEnter(
Andreas Gampe319dbe82017-01-09 16:42:21 -080057 JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED, jlong l) {
58 jvmtiError result = jvmti_env->RawMonitorEnter(LongToMonitor(l));
Andreas Gampe3f46c962017-03-30 10:26:59 -070059 JvmtiErrorToException(env, jvmti_env, result);
Andreas Gampe319dbe82017-01-09 16:42:21 -080060}
61
Andreas Gampe46651672017-04-07 09:00:04 -070062extern "C" JNIEXPORT void JNICALL Java_art_Test923_rawMonitorExit(
Andreas Gampe319dbe82017-01-09 16:42:21 -080063 JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED, jlong l) {
64 jvmtiError result = jvmti_env->RawMonitorExit(LongToMonitor(l));
Andreas Gampe3f46c962017-03-30 10:26:59 -070065 JvmtiErrorToException(env, jvmti_env, result);
Andreas Gampe319dbe82017-01-09 16:42:21 -080066}
67
Andreas Gampe46651672017-04-07 09:00:04 -070068extern "C" JNIEXPORT void JNICALL Java_art_Test923_rawMonitorWait(
Andreas Gampe319dbe82017-01-09 16:42:21 -080069 JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED, jlong l, jlong millis) {
70 jvmtiError result = jvmti_env->RawMonitorWait(LongToMonitor(l), millis);
Andreas Gampe3f46c962017-03-30 10:26:59 -070071 JvmtiErrorToException(env, jvmti_env, result);
Andreas Gampe319dbe82017-01-09 16:42:21 -080072}
73
Andreas Gampe46651672017-04-07 09:00:04 -070074extern "C" JNIEXPORT void JNICALL Java_art_Test923_rawMonitorNotify(
Andreas Gampe319dbe82017-01-09 16:42:21 -080075 JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED, jlong l) {
76 jvmtiError result = jvmti_env->RawMonitorNotify(LongToMonitor(l));
Andreas Gampe3f46c962017-03-30 10:26:59 -070077 JvmtiErrorToException(env, jvmti_env, result);
Andreas Gampe319dbe82017-01-09 16:42:21 -080078}
79
Andreas Gampe46651672017-04-07 09:00:04 -070080extern "C" JNIEXPORT void JNICALL Java_art_Test923_rawMonitorNotifyAll(
Andreas Gampe319dbe82017-01-09 16:42:21 -080081 JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED, jlong l) {
82 jvmtiError result = jvmti_env->RawMonitorNotifyAll(LongToMonitor(l));
Andreas Gampe3f46c962017-03-30 10:26:59 -070083 JvmtiErrorToException(env, jvmti_env, result);
Andreas Gampe319dbe82017-01-09 16:42:21 -080084}
85
Andreas Gampe319dbe82017-01-09 16:42:21 -080086} // namespace Test923Monitors
87} // namespace art