Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CompiledMethodLoad/compmethload001/compmethload001.cpp
40955 views
1
/*
2
* Copyright (c) 2003, 2018, 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 <stdio.h>
25
#include <string.h>
26
#include <jvmti.h>
27
#include "agent_common.h"
28
29
#include "nsk_tools.h"
30
#include "JVMTITools.h"
31
#include "jvmti_tools.h"
32
33
extern "C" {
34
35
#define STATUS_FAILED 2
36
#define PASSED 0
37
38
static volatile jint result = PASSED;
39
static jvmtiEnv *jvmti = NULL;
40
static jvmtiEventCallbacks callbacks;
41
static jvmtiCapabilities caps;
42
43
/** callback functions **/
44
void JNICALL
45
VMInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thr) {
46
NSK_DISPLAY0("VMInit event received\n\n");
47
48
if (!NSK_JVMTI_VERIFY(jvmti_env->GenerateEvents(JVMTI_EVENT_COMPILED_METHOD_LOAD))) {
49
NSK_COMPLAIN0("TEST FAILED: unable to generate events to represent the current state of the VM\n");
50
result = STATUS_FAILED;
51
}
52
}
53
54
void JNICALL
55
CompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, jint code_size,
56
const void* code_addr, jint map_length, const jvmtiAddrLocationMap* map,
57
const void* compile_info) {
58
char *name;
59
char *sig;
60
char *generic;
61
jvmtiPhase phase;
62
63
NSK_DISPLAY0("CompiledMethodLoad event received for:\n");
64
65
if (!NSK_JVMTI_VERIFY(jvmti_env->GetMethodName(method, &name, &sig, &generic))) {
66
result = STATUS_FAILED;
67
NSK_COMPLAIN0("TEST FAILURE: unable to obtain method info\n");
68
return;
69
}
70
NSK_DISPLAY4("\tmethod: name=\"%s\" signature=\"%s\"\n\tcompiled code size=%d\n\tnumber of address location map entries=%d\n",
71
name, sig, code_size, map_length);
72
73
if (!NSK_JVMTI_VERIFY(jvmti_env->GetPhase(&phase))) {
74
result = STATUS_FAILED;
75
NSK_COMPLAIN0("TEST FAILURE: unable to obtain phase of the VM execution\n");
76
return;
77
}
78
79
if (phase != JVMTI_PHASE_LIVE) {
80
result = STATUS_FAILED;
81
NSK_COMPLAIN1("TEST FAILED: CompiledMethodLoad event received during non-live phase %s\n",
82
TranslatePhase(phase));
83
}
84
else
85
NSK_DISPLAY0("CHECK PASSED: CompiledMethodLoad event received during the live phase as expected\n\n");
86
}
87
/************************/
88
89
JNIEXPORT jint JNICALL
90
Java_nsk_jvmti_CompiledMethodLoad_compmethload001_check(
91
JNIEnv *env, jobject obj) {
92
if (!caps.can_generate_compiled_method_load_events)
93
return PASSED;
94
95
return result;
96
}
97
98
#ifdef STATIC_BUILD
99
JNIEXPORT jint JNICALL Agent_OnLoad_compmethload001(JavaVM *jvm, char *options, void *reserved) {
100
return Agent_Initialize(jvm, options, reserved);
101
}
102
JNIEXPORT jint JNICALL Agent_OnAttach_compmethload001(JavaVM *jvm, char *options, void *reserved) {
103
return Agent_Initialize(jvm, options, reserved);
104
}
105
JNIEXPORT jint JNI_OnLoad_compmethload001(JavaVM *jvm, char *options, void *reserved) {
106
return JNI_VERSION_1_8;
107
}
108
#endif
109
jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
110
/* init framework and parse options */
111
if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
112
return JNI_ERR;
113
114
/* create JVMTI environment */
115
if (!NSK_VERIFY((jvmti =
116
nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
117
return JNI_ERR;
118
119
/* add capability to generate compiled method events */
120
memset(&caps, 0, sizeof(jvmtiCapabilities));
121
caps.can_generate_compiled_method_load_events = 1;
122
if (!NSK_JVMTI_VERIFY(jvmti->AddCapabilities(&caps)))
123
return JNI_ERR;
124
125
if (!NSK_JVMTI_VERIFY(jvmti->GetCapabilities(&caps)))
126
return JNI_ERR;
127
128
if (!caps.can_generate_compiled_method_load_events)
129
NSK_DISPLAY0("Warning: generation of compiled method events is not implemented\n");
130
131
/* set event callback */
132
NSK_DISPLAY0("setting event callbacks ...\n");
133
(void) memset(&callbacks, 0, sizeof(callbacks));
134
callbacks.VMInit = &VMInit;
135
callbacks.CompiledMethodLoad = &CompiledMethodLoad;
136
if (!NSK_JVMTI_VERIFY(jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks))))
137
return JNI_ERR;
138
139
NSK_DISPLAY0("setting event callbacks done\nenabling VMInit, CompiledMethodLoad event ...\n");
140
if (!NSK_JVMTI_VERIFY(jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_VM_INIT, NULL)))
141
return JNI_ERR;
142
if (!NSK_JVMTI_VERIFY(jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_COMPILED_METHOD_LOAD, NULL)))
143
return JNI_ERR;
144
NSK_DISPLAY0("enabling the events done\n\n");
145
146
return JNI_OK;
147
}
148
149
}
150
151