Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DynamicCodeGenerated/dyncodgen001/dyncodgen001.cpp
40951 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 <string.h>
25
#include "jvmti.h"
26
#include "agent_common.h"
27
#include "jni_tools.h"
28
#include "jvmti_tools.h"
29
30
extern "C" {
31
32
/* ========================================================================== */
33
34
/* scaffold objects */
35
static jlong timeout = 0;
36
37
/* test objects */
38
static int eventsCount;
39
40
/* ========================================================================== */
41
42
/* check if any DynamicCodeGenerated events received */
43
static int checkDynamicCodeGeneratedEvents() {
44
45
NSK_DISPLAY1("DynamicCodeGenerated events received: %d\n", eventsCount);
46
47
if (eventsCount == 0) {
48
NSK_DISPLAY0("# WARNING: no DynamicCodeGenerated events\n");
49
NSK_DISPLAY0("# (dynamic code may not be generated at all)\n");
50
}
51
52
return NSK_TRUE;
53
}
54
55
/* ========================================================================== */
56
57
JNIEXPORT void JNICALL
58
DynamicCodeGenerated(jvmtiEnv* jvmti,
59
const char* name, const void* address, jint length) {
60
61
NSK_DISPLAY3("DynamicCodeGenerated: \"%s\", address=0x%p, length=%d\n",
62
name, address, length);
63
64
eventsCount++;
65
}
66
67
/* ========================================================================== */
68
69
/* agent algorithm */
70
static void JNICALL
71
agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {
72
73
/* wait for debuggee start */
74
if (!nsk_jvmti_waitForSync(timeout))
75
return;
76
77
/* testcase #1: check if any DynamicCodeGenerated events received*/
78
NSK_DISPLAY0("Testcase #1: check if any DynamicCodeGenerated events received\n");
79
if (!checkDynamicCodeGeneratedEvents())
80
nsk_jvmti_setFailStatus();
81
82
/* resume debugee after last sync */
83
if (!nsk_jvmti_resumeSync())
84
return;
85
}
86
87
/* ========================================================================== */
88
89
/* agent library initialization */
90
#ifdef STATIC_BUILD
91
JNIEXPORT jint JNICALL Agent_OnLoad_dyncodgen001(JavaVM *jvm, char *options, void *reserved) {
92
return Agent_Initialize(jvm, options, reserved);
93
}
94
JNIEXPORT jint JNICALL Agent_OnAttach_dyncodgen001(JavaVM *jvm, char *options, void *reserved) {
95
return Agent_Initialize(jvm, options, reserved);
96
}
97
JNIEXPORT jint JNI_OnLoad_dyncodgen001(JavaVM *jvm, char *options, void *reserved) {
98
return JNI_VERSION_1_8;
99
}
100
#endif
101
jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
102
jvmtiEnv* jvmti = NULL;
103
jvmtiEventCallbacks callbacks;
104
105
/* init framework and parse options */
106
if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
107
return JNI_ERR;
108
109
timeout = nsk_jvmti_getWaitTime() * 60000;
110
NSK_DISPLAY1("Timeout: %d msc\n", (int)timeout);
111
112
/* create JVMTI environment */
113
if (!NSK_VERIFY((jvmti =
114
nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
115
return JNI_ERR;
116
117
memset(&callbacks, 0, sizeof(callbacks));
118
callbacks.DynamicCodeGenerated = &DynamicCodeGenerated;
119
if (!NSK_JVMTI_VERIFY(jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks))))
120
return JNI_ERR;
121
122
/* enable DynamicCodeGenerated event */
123
if (!NSK_JVMTI_VERIFY(
124
jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_DYNAMIC_CODE_GENERATED, NULL)))
125
return JNI_ERR;
126
127
/* register agent proc and arg */
128
if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
129
return JNI_ERR;
130
131
return JNI_OK;
132
}
133
134
/* ========================================================================== */
135
136
}
137
138