Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/serviceability/jvmti/SuspendWithObjectMonitorWait/libSuspendWithObjectMonitorWait.cpp
41153 views
1
/*
2
* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
#include <string.h>
25
#include "jvmti.h"
26
27
extern "C" {
28
29
static jvmtiEnv* jvmti = NULL;
30
31
#define LOG(...) \
32
do { \
33
printf(__VA_ARGS__); \
34
printf("\n"); \
35
fflush(stdout); \
36
} while (0)
37
38
JNIEXPORT int JNICALL
39
Java_SuspendWithObjectMonitorWait_suspendThread(JNIEnv *jni, jclass cls, jthread thr) {
40
return jvmti->SuspendThread(thr);
41
}
42
43
JNIEXPORT jint JNICALL
44
Java_SuspendWithObjectMonitorWaitWorker_resumeThread(JNIEnv *jni, jclass cls, jthread thr) {
45
return jvmti->ResumeThread(thr);
46
}
47
48
JNIEXPORT jint JNICALL
49
Java_SuspendWithObjectMonitorWait_wait4ContendedEnter(JNIEnv *jni, jclass cls, jthread thr) {
50
jvmtiError err;
51
jint thread_state;
52
do {
53
err = jvmti->GetThreadState(thr, &thread_state);
54
if (err != JVMTI_ERROR_NONE) {
55
return err;
56
}
57
} while ((thread_state & JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER) == 0);
58
return err;
59
}
60
61
62
/** Agent library initialization. */
63
64
JNIEXPORT jint JNICALL
65
Agent_OnLoad(JavaVM *jvm, char *options, void *reserved) {
66
LOG("\nAgent_OnLoad started");
67
68
// create JVMTI environment
69
if (jvm->GetEnv((void **) (&jvmti), JVMTI_VERSION) != JNI_OK) {
70
return JNI_ERR;
71
}
72
73
// add specific capabilities for suspending thread
74
jvmtiCapabilities suspendCaps;
75
memset(&suspendCaps, 0, sizeof(suspendCaps));
76
suspendCaps.can_suspend = 1;
77
78
jvmtiError err = jvmti->AddCapabilities(&suspendCaps);
79
if (err != JVMTI_ERROR_NONE) {
80
return JNI_ERR;
81
}
82
LOG("Agent_OnLoad finished\n");
83
return JNI_OK;
84
}
85
86
}
87
88