Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/serviceability/monitoring/ThreadInfo/GetLockOwnerName/libGetLockOwnerName.cpp
41161 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 jint JNICALL
39
Java_GetLockOwnerName_wait4ContendedEnter(JNIEnv *jni, jclass cls, jthread thr) {
40
jvmtiError err;
41
jint thread_state;
42
do {
43
err = jvmti->GetThreadState(thr, &thread_state);
44
if (err != JVMTI_ERROR_NONE) {
45
return err;
46
}
47
if ((thread_state & JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER) != 0) {
48
// For this test, we need the contended monitor reference and
49
// that is saved right after the thread state is updated so we
50
// only return from this function when we have both.
51
jobject monitor_ptr;
52
err = jvmti->GetCurrentContendedMonitor(thr, &monitor_ptr);
53
if (err != JVMTI_ERROR_NONE) {
54
return err;
55
}
56
if (monitor_ptr != NULL) {
57
break;
58
}
59
}
60
} while (true);
61
return err;
62
}
63
64
/** Agent library initialization. */
65
66
JNIEXPORT jint JNICALL
67
Agent_OnLoad(JavaVM *jvm, char *options, void *reserved) {
68
LOG("\nAgent_OnLoad started");
69
70
// create JVMTI environment
71
if (jvm->GetEnv((void **) (&jvmti), JVMTI_VERSION) != JNI_OK) {
72
return JNI_ERR;
73
}
74
75
// add capabilities needed for this test
76
jvmtiCapabilities needCaps;
77
memset(&needCaps, 0, sizeof(needCaps));
78
needCaps.can_get_current_contended_monitor = 1;
79
80
jvmtiError err = jvmti->AddCapabilities(&needCaps);
81
if (err != JVMTI_ERROR_NONE) {
82
return JNI_ERR;
83
}
84
LOG("Agent_OnLoad finished\n");
85
return JNI_OK;
86
}
87
88
}
89
90