Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/serviceability/jvmti/GetClassMethods/libOverpassMethods.cpp
41153 views
1
/*
2
* Copyright (c) 2020, 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. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
#include <stdio.h>
27
#include <string.h>
28
#include "jvmti.h"
29
30
#ifdef __cplusplus
31
extern "C" {
32
#endif
33
34
#define ACC_STATIC 0x0008
35
36
static jvmtiEnv *jvmti = NULL;
37
38
JNIEXPORT
39
jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) {
40
return JNI_VERSION_9;
41
}
42
43
JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *vm, char *options, void *reserved) {
44
vm->GetEnv((void **)&jvmti, JVMTI_VERSION_11);
45
46
if (options != NULL && strcmp(options, "maintain_original_method_order") == 0) {
47
printf("Enabled capability: maintain_original_method_order\n");
48
jvmtiCapabilities caps = {};
49
caps.can_maintain_original_method_order = 1;
50
51
jvmtiError err = jvmti->AddCapabilities(&caps);
52
if (err != JVMTI_ERROR_NONE) {
53
printf("Agent_OnLoad: AddCapabilities failed with error: %d\n", err);
54
return JNI_ERR;
55
}
56
}
57
return JNI_OK;
58
}
59
60
JNIEXPORT jobjectArray JNICALL Java_OverpassMethods_getJVMTIDeclaredMethods(JNIEnv *env, jclass static_klass, jclass klass) {
61
jint method_count = 0;
62
jmethodID* methods = NULL;
63
jvmtiError err = jvmti->GetClassMethods(klass, &method_count, &methods);
64
if (err != JVMTI_ERROR_NONE) {
65
printf("GetClassMethods failed with error: %d\n", err);
66
return NULL;
67
}
68
69
jclass method_cls = env->FindClass("java/lang/reflect/Method");
70
if (method_cls == NULL) {
71
printf("FindClass (Method) failed\n");
72
return NULL;
73
}
74
jobjectArray array = env->NewObjectArray(method_count, method_cls, NULL);
75
if (array == NULL) {
76
printf("NewObjectArray failed\n");
77
return NULL;
78
}
79
80
for (int i = 0; i < method_count; i++) {
81
jint modifiers = 0;
82
err = jvmti->GetMethodModifiers(methods[i], &modifiers);
83
if (err != JVMTI_ERROR_NONE) {
84
printf("GetMethodModifiers failed with error: %d\n", err);
85
return NULL;
86
}
87
88
jobject m = env->ToReflectedMethod(klass, methods[i], (modifiers & ACC_STATIC) == ACC_STATIC);
89
if (array == NULL) {
90
printf("ToReflectedMethod failed\n");
91
return NULL;
92
}
93
env->SetObjectArrayElement(array, i, m);
94
95
env->DeleteLocalRef(m);
96
}
97
jvmti->Deallocate((unsigned char *)methods);
98
99
return array;
100
}
101
#ifdef __cplusplus
102
}
103
#endif
104
105