Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach050/attach050Agent00.cpp
40951 views
1
/*
2
* Copyright (c) 2008, 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
#include <stdio.h>
24
#include <stdlib.h>
25
#include <string.h>
26
#include <jni.h>
27
#include <jvmti.h>
28
#include <aod.h>
29
#include <jvmti_aod.h>
30
31
#define ON_UNLOAD_MARKER "attach050.on_unload"
32
33
extern "C" {
34
35
/*
36
* This agent gets JVMTI environment and calls nsk_aod_agentLoaded and
37
* nsk_aod_agentFinished from Agent_OnAttach. It also has
38
* Agent_OnUnload function that prints marker string to the stdout,
39
* providing a means for the test runner to check whether
40
* Agent_OnUnload is called on agent unload during VM shutdown.
41
*/
42
43
#ifdef STATIC_BUILD
44
JNIEXPORT jint JNI_OnLoad_attach050Agent00(JavaVM *jvm, char *options, void *reserved) {
45
return JNI_VERSION_1_8;
46
}
47
#endif
48
49
JNIEXPORT jint JNICALL
50
#ifdef STATIC_BUILD
51
Agent_OnAttach_attach050Agent00(JavaVM *vm, char *optionsString, void *reserved)
52
#else
53
Agent_OnAttach(JavaVM *vm, char *optionsString, void *reserved)
54
#endif
55
{
56
jvmtiEnv* jvmti;
57
JNIEnv* jni = NULL;
58
Options* options = NULL;
59
const char* agentName;
60
61
options = (Options*) nsk_aod_createOptions(optionsString);
62
if (!NSK_VERIFY(options != NULL))
63
return JNI_ERR;
64
65
agentName = nsk_aod_getOptionValue(options, NSK_AOD_AGENT_NAME_OPTION);
66
67
jni = (JNIEnv*) nsk_aod_createJNIEnv(vm);
68
if (jni == NULL)
69
return JNI_ERR;
70
71
jvmti = nsk_jvmti_createJVMTIEnv(vm, reserved);
72
if (!NSK_VERIFY(jvmti != NULL))
73
return JNI_ERR;
74
75
NSK_DISPLAY1("%s: initialization was done\n", agentName);
76
77
if (!NSK_VERIFY(nsk_aod_agentLoaded(jni, agentName)))
78
return JNI_ERR;
79
80
nsk_aod_agentFinished(jni, agentName, 1);
81
82
return JNI_OK;
83
}
84
85
86
/* agent library shutdown */
87
JNIEXPORT void JNICALL
88
#ifdef STATIC_BUILD
89
Agent_OnUnload_attach050Agent00(JavaVM *jvm)
90
#else
91
Agent_OnUnload(JavaVM *jvm)
92
#endif
93
{
94
fprintf(stdout, "%s%s", ON_UNLOAD_MARKER, "\n");
95
fflush(stdout);
96
}
97
98
}
99
100