Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/serviceability/jvmti/VMEvent/libVMEventTest.c
41153 views
1
/*
2
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
3
* Copyright (c) 2018, Google and/or its affiliates. All rights reserved.
4
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
*
6
* This code is free software; you can redistribute it and/or modify it
7
* under the terms of the GNU General Public License version 2 only, as
8
* published by the Free Software Foundation.
9
*
10
* This code is distributed in the hope that it will be useful, but WITHOUT
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13
* version 2 for more details (a copy is included in the LICENSE file that
14
* accompanied this code).
15
*
16
* You should have received a copy of the GNU General Public License version
17
* 2 along with this work; if not, write to the Free Software Foundation,
18
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19
*
20
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21
* or visit www.oracle.com if you need additional information or have any
22
* questions.
23
*/
24
25
#include <string.h>
26
#include "jvmti.h"
27
28
#ifdef __cplusplus
29
extern "C" {
30
#endif
31
32
#ifndef JNI_ENV_ARG
33
34
#ifdef __cplusplus
35
#define JNI_ENV_ARG(x)
36
#define JNI_ENV_ARGS2(x, y) y
37
#define JNI_ENV_ARGS3(x, y, z) y, z
38
#define JNI_ENV_ARGS4(x, y, z, w) y, z, w
39
#define JNI_ENV_PTR(x) x
40
#else
41
#define JNI_ENV_ARG(x) x
42
#define JNI_ENV_ARGS2(x,y) x, y
43
#define JNI_ENV_ARGS3(x, y, z) x, y, z
44
#define JNI_ENV_ARGS4(x, y, z, w) x, y, z, w
45
#define JNI_ENV_PTR(x) (*x)
46
#endif
47
48
#endif
49
50
extern JNIEXPORT void JNICALL VMObjectAlloc(jvmtiEnv *jvmti,
51
JNIEnv* jni,
52
jthread thread,
53
jobject object,
54
jclass klass,
55
jlong size) {
56
char *signature = NULL;
57
jvmtiError error = (*jvmti)->GetClassSignature(jvmti, klass, &signature, NULL);
58
59
if (error != JVMTI_ERROR_NONE || signature == NULL) {
60
JNI_ENV_PTR(jni)->FatalError(
61
JNI_ENV_ARGS2(jni, "Failed during the GetClassSignature call"));
62
}
63
64
// If it is our test class, call clone now.
65
if (!strcmp(signature, "LMyPackage/VMEventRecursionTest;")) {
66
jmethodID clone_method =
67
JNI_ENV_PTR(jni)->GetMethodID(JNI_ENV_ARGS4(jni, klass, "clone", "()Ljava/lang/Object;"));
68
69
if (JNI_ENV_PTR(jni)->ExceptionOccurred(JNI_ENV_ARG(jni))) {
70
JNI_ENV_PTR(jni)->FatalError(
71
JNI_ENV_ARGS2(jni, "Failed during the GetMethodID call"));
72
}
73
74
JNI_ENV_PTR(jni)->CallObjectMethod(JNI_ENV_ARGS3(jni, object, clone_method));
75
76
if (JNI_ENV_PTR(jni)->ExceptionOccurred(JNI_ENV_ARG(jni))) {
77
JNI_ENV_PTR(jni)->FatalError(
78
JNI_ENV_ARGS2(jni, "Failed during the CallObjectMethod call"));
79
}
80
}
81
}
82
83
extern JNIEXPORT void JNICALL OnVMInit(jvmtiEnv *jvmti, JNIEnv *jni, jthread thread) {
84
(*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, JVMTI_EVENT_VM_OBJECT_ALLOC, NULL);
85
}
86
87
extern JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *jvm, char *options,
88
void *reserved) {
89
jvmtiEnv *jvmti;
90
jvmtiEventCallbacks callbacks;
91
jvmtiCapabilities caps;
92
93
if ((*jvm)->GetEnv(jvm, (void **) (&jvmti), JVMTI_VERSION) != JNI_OK) {
94
return JNI_ERR;
95
}
96
97
memset(&callbacks, 0, sizeof(callbacks));
98
callbacks.VMObjectAlloc = &VMObjectAlloc;
99
callbacks.VMInit = &OnVMInit;
100
101
memset(&caps, 0, sizeof(caps));
102
caps.can_generate_vm_object_alloc_events = 1;
103
(*jvmti)->AddCapabilities(jvmti, &caps);
104
105
(*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(jvmtiEventCallbacks));
106
(*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, JVMTI_EVENT_VM_INIT, NULL);
107
return 0;
108
}
109
110
#ifdef __cplusplus
111
}
112
#endif
113
114