Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/serviceability/jvmti/SuspendWithRawMonitorEnter/libSuspendWithRawMonitorEnter.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
static jrawMonitorID threadLock = NULL;
31
static char threadLockName[] = "threadLock";
32
33
#define LOG(...) \
34
do { \
35
printf(__VA_ARGS__); \
36
printf("\n"); \
37
fflush(stdout); \
38
} while (0)
39
40
JNIEXPORT jint JNICALL
41
Java_SuspendWithRawMonitorEnter_createRawMonitor(JNIEnv *jni, jclass cls) {
42
return jvmti->CreateRawMonitor(threadLockName, &threadLock);
43
}
44
45
JNIEXPORT jint JNICALL
46
Java_SuspendWithRawMonitorEnter_destroyRawMonitor(JNIEnv *jni, jclass cls) {
47
return jvmti->DestroyRawMonitor(threadLock);
48
}
49
50
JNIEXPORT jint JNICALL
51
Java_SuspendWithRawMonitorEnter_suspendThread(JNIEnv *jni, jclass cls, jthread thr) {
52
return jvmti->SuspendThread(thr);
53
}
54
55
JNIEXPORT jint JNICALL
56
Java_SuspendWithRawMonitorEnterWorker_rawMonitorEnter(JNIEnv *jni, jclass cls) {
57
return jvmti->RawMonitorEnter(threadLock);
58
}
59
60
JNIEXPORT jint JNICALL
61
Java_SuspendWithRawMonitorEnterWorker_rawMonitorExit(JNIEnv *jni, jclass cls) {
62
return jvmti->RawMonitorExit(threadLock);
63
}
64
65
JNIEXPORT jint JNICALL
66
Java_SuspendWithRawMonitorEnterWorker_resumeThread(JNIEnv *jni, jclass cls, jthread thr) {
67
return jvmti->ResumeThread(thr);
68
}
69
70
71
/** Agent library initialization. */
72
73
JNIEXPORT jint JNICALL
74
Agent_OnLoad(JavaVM *jvm, char *options, void *reserved) {
75
LOG("\nAgent_OnLoad started");
76
77
// create JVMTI environment
78
if (jvm->GetEnv((void **) (&jvmti), JVMTI_VERSION) != JNI_OK) {
79
return JNI_ERR;
80
}
81
82
// add specific capabilities for suspending thread
83
jvmtiCapabilities suspendCaps;
84
memset(&suspendCaps, 0, sizeof(suspendCaps));
85
suspendCaps.can_suspend = 1;
86
87
jvmtiError err = jvmti->AddCapabilities(&suspendCaps);
88
if (err != JVMTI_ERROR_NONE) {
89
return JNI_ERR;
90
}
91
LOG("Agent_OnLoad finished\n");
92
return JNI_OK;
93
}
94
95
}
96
97