blob: 158b22cce60f2702853ede02d0e492b44378cd0f [file] [log] [blame]
Alex Light88fd7202017-06-30 08:31:59 -07001/*
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 <atomic>
18
19#include "android-base/logging.h"
20#include "jni.h"
21#include "scoped_local_ref.h"
22#include "scoped_primitive_array.h"
23
24#include "jvmti.h"
25
26// Test infrastructure
27#include "jvmti_helper.h"
28#include "test_env.h"
29
30namespace art {
31namespace Test1908NativeSuspendResume {
32
33std::atomic<bool> done(false);
34std::atomic<bool> started(false);
35std::atomic<bool> resumed(false);
36std::atomic<bool> resuming(false);
37
38extern "C" JNIEXPORT jint JNICALL Java_art_Test1908_nativeSpinAndResume(JNIEnv*,
39 jclass,
40 jthread thr) {
41 while (!done.load()) {
42 started.store(true);
43 }
44 resuming.store(true);
45 jint ret = jvmti_env->ResumeThread(thr);
46 resumed.store(true);
47 return ret;
48}
49
50extern "C" JNIEXPORT jboolean JNICALL Java_art_Test1908_isNativeThreadSpinning(JNIEnv*, jclass) {
51 return started.load();
52}
53
54extern "C" JNIEXPORT void JNICALL Java_art_Test1908_waitForNativeResumeStarted(JNIEnv*, jclass) {
55 while (!resuming.load()) {}
56}
57
58extern "C" JNIEXPORT void JNICALL Java_art_Test1908_waitForNativeResumeFinished(JNIEnv*, jclass) {
59 while (!resumed.load()) {}
60}
61
62extern "C" JNIEXPORT void JNICALL Java_art_Test1908_nativeResume(JNIEnv*, jclass) {
63 done.store(true);
64}
65
66} // namespace Test1908NativeSuspendResume
67} // namespace art