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