blob: 7f97c05a7346f69745cc3b40c90d139e22d441a3 [file] [log] [blame]
Alex Lightce568642017-09-05 16:54:25 -07001/*
2 * Copyright (C) 2013 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 <pthread.h>
18
19#include <cstdio>
20#include <iostream>
21#include <vector>
22
23#include "android-base/logging.h"
24#include "jni.h"
25#include "jvmti.h"
26
27#include "scoped_local_ref.h"
28#include "scoped_primitive_array.h"
29
30// Test infrastructure
31#include "jvmti_helper.h"
32#include "test_env.h"
33
34namespace art {
35namespace Test1930MonitorInfo {
36
37extern "C" JNIEXPORT void JNICALL Java_art_Test1930_executeLockedNative(JNIEnv* env,
38 jclass klass,
39 jobject run,
40 jobject l) {
41 ScopedLocalRef<jclass> runnable(env, env->FindClass("java/lang/Runnable"));
42 if (env->ExceptionCheck()) {
43 return;
44 }
45 jmethodID method = env->GetMethodID(runnable.get(), "run", "()V");
46
47 if (env->ExceptionCheck()) {
48 return;
49 }
50 jmethodID printMethod = env->GetStaticMethodID(klass, "printPreLock", "(Ljava/lang/Object;)V");
51 if (env->ExceptionCheck()) {
52 return;
53 }
54
55 env->CallStaticVoidMethod(klass, printMethod, l);
56 if (env->ExceptionCheck()) {
57 return;
58 }
59 if (env->MonitorEnter(l) != 0) {
60 return;
61 }
62 env->CallVoidMethod(run, method);
63 env->MonitorExit(l);
64}
65
66} // namespace Test1930MonitorInfo
67} // namespace art