Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/instrument/JPLISAgent.h
38767 views
1
/*
2
* Copyright (c) 2003, 2008, 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
/*
27
* Copyright 2003 Wily Technology, Inc.
28
*/
29
30
#ifndef _JPLISAGENT_H_
31
#define _JPLISAGENT_H_
32
33
#include <jni.h>
34
#include <jvmti.h>
35
36
#ifdef __cplusplus
37
extern "C" {
38
#endif
39
40
/*
41
* The JPLISAgent manages the initialization all of the Java programming language Agents.
42
* It also supports the native method bridge between the JPLIS and the JVMTI.
43
* It maintains a single JVMTI Env that all JPL agents share.
44
* It parses command line requests and creates individual Java agents.
45
*/
46
47
48
/*
49
* Forward definitions
50
*/
51
struct _JPLISAgent;
52
53
typedef struct _JPLISAgent JPLISAgent;
54
typedef struct _JPLISEnvironment JPLISEnvironment;
55
56
57
/* constants for class names and methods names and such
58
these all must stay in sync with Java code & interfaces
59
*/
60
#define JPLIS_INSTRUMENTIMPL_CLASSNAME "sun/instrument/InstrumentationImpl"
61
#define JPLIS_INSTRUMENTIMPL_CONSTRUCTOR_METHODNAME "<init>"
62
#define JPLIS_INSTRUMENTIMPL_CONSTRUCTOR_METHODSIGNATURE "(JZZ)V"
63
#define JPLIS_INSTRUMENTIMPL_PREMAININVOKER_METHODNAME "loadClassAndCallPremain"
64
#define JPLIS_INSTRUMENTIMPL_PREMAININVOKER_METHODSIGNATURE "(Ljava/lang/String;Ljava/lang/String;)V"
65
#define JPLIS_INSTRUMENTIMPL_AGENTMAININVOKER_METHODNAME "loadClassAndCallAgentmain"
66
#define JPLIS_INSTRUMENTIMPL_AGENTMAININVOKER_METHODSIGNATURE "(Ljava/lang/String;Ljava/lang/String;)V"
67
#define JPLIS_INSTRUMENTIMPL_TRANSFORM_METHODNAME "transform"
68
#define JPLIS_INSTRUMENTIMPL_TRANSFORM_METHODSIGNATURE \
69
"(Ljava/lang/ClassLoader;Ljava/lang/String;Ljava/lang/Class;Ljava/security/ProtectionDomain;[BZ)[B"
70
71
72
/*
73
* Error messages
74
*/
75
#define JPLIS_ERRORMESSAGE_CANNOTSTART "processing of -javaagent failed"
76
77
78
/*
79
* Our initialization errors
80
*/
81
typedef enum {
82
JPLIS_INIT_ERROR_NONE,
83
JPLIS_INIT_ERROR_CANNOT_CREATE_NATIVE_AGENT,
84
JPLIS_INIT_ERROR_FAILURE,
85
JPLIS_INIT_ERROR_ALLOCATION_FAILURE,
86
JPLIS_INIT_ERROR_AGENT_CLASS_NOT_SPECIFIED
87
} JPLISInitializationError;
88
89
90
struct _JPLISEnvironment {
91
jvmtiEnv * mJVMTIEnv; /* the JVM TI environment */
92
JPLISAgent * mAgent; /* corresponding agent */
93
jboolean mIsRetransformer; /* indicates if special environment */
94
};
95
96
struct _JPLISAgent {
97
JavaVM * mJVM; /* handle to the JVM */
98
JPLISEnvironment mNormalEnvironment; /* for every thing but retransform stuff */
99
JPLISEnvironment mRetransformEnvironment;/* for retransform stuff only */
100
jobject mInstrumentationImpl; /* handle to the Instrumentation instance */
101
jmethodID mPremainCaller; /* method on the InstrumentationImpl that does the premain stuff (cached to save lots of lookups) */
102
jmethodID mAgentmainCaller; /* method on the InstrumentationImpl for agents loaded via attach mechanism */
103
jmethodID mTransform; /* method on the InstrumentationImpl that does the class file transform */
104
jboolean mRedefineAvailable; /* cached answer to "does this agent support redefine" */
105
jboolean mRedefineAdded; /* indicates if can_redefine_classes capability has been added */
106
jboolean mNativeMethodPrefixAvailable; /* cached answer to "does this agent support prefixing" */
107
jboolean mNativeMethodPrefixAdded; /* indicates if can_set_native_method_prefix capability has been added */
108
char const * mAgentClassName; /* agent class name */
109
char const * mOptionsString; /* -javaagent options string */
110
};
111
112
/*
113
* JVMTI event handlers
114
*/
115
116
/* VMInit event handler. Installed during OnLoad, then removed during VMInit. */
117
extern void JNICALL
118
eventHandlerVMInit( jvmtiEnv * jvmtienv,
119
JNIEnv * jnienv,
120
jthread thread);
121
122
/* ClassFileLoadHook event handler. Installed during VMInit, then left in place forever. */
123
extern void JNICALL
124
eventHandlerClassFileLoadHook( jvmtiEnv * jvmtienv,
125
JNIEnv * jnienv,
126
jclass class_being_redefined,
127
jobject loader,
128
const char* name,
129
jobject protectionDomain,
130
jint class_data_len,
131
const unsigned char* class_data,
132
jint* new_class_data_len,
133
unsigned char** new_class_data);
134
135
/*
136
* Main entry points for the JPLIS JVMTI agent code
137
*/
138
139
/* looks up the environment instance. returns null if there isn't one */
140
extern JPLISEnvironment *
141
getJPLISEnvironment(jvmtiEnv * jvmtienv);
142
143
/* Creates a new JPLIS agent.
144
* Returns error if the agent cannot be created and initialized.
145
* The JPLISAgent* pointed to by agent_ptr is set to the new broker,
146
* or NULL if an error has occurred.
147
*/
148
extern JPLISInitializationError
149
createNewJPLISAgent(JavaVM * vm, JPLISAgent **agent_ptr);
150
151
/* Adds can_redefine_classes capability */
152
extern void
153
addRedefineClassesCapability(JPLISAgent * agent);
154
155
/* Add the can_set_native_method_prefix capability */
156
extern void
157
addNativeMethodPrefixCapability(JPLISAgent * agent);
158
159
/* Add the can_maintain_original_method_order capability (for testing) */
160
extern void
161
addOriginalMethodOrderCapability(JPLISAgent * agent);
162
163
164
/* Our JPLIS agent is paralleled by a Java InstrumentationImpl instance.
165
* This routine uses JNI to create and initialized the Java instance.
166
* Returns true if it succeeds, false otherwise.
167
*/
168
extern jboolean
169
createInstrumentationImpl( JNIEnv * jnienv,
170
JPLISAgent * agent);
171
172
173
/* during OnLoad phase (command line parsing)
174
* record the parameters of -javaagent
175
*/
176
extern JPLISInitializationError
177
recordCommandLineData( JPLISAgent * agent,
178
const char * agentClass,
179
const char * optionsString );
180
181
/* Swaps the start phase event handlers out and the live phase event handlers in.
182
* Also used in attach to enabled live phase event handlers.
183
* Returns true if it succeeds, false otherwise.
184
*/
185
extern jboolean
186
setLivePhaseEventHandlers( JPLISAgent * agent);
187
188
/* Loads the Java agent according to the already processed command line. For each,
189
* loads the Java agent class, then calls the premain method.
190
* Returns true if all Java agent classes are loaded and all premain methods complete with no exceptions,
191
* false otherwise.
192
*/
193
extern jboolean
194
startJavaAgent( JPLISAgent * agent,
195
JNIEnv * jnienv,
196
const char * classname,
197
const char * optionsString,
198
jmethodID agentMainMethod);
199
200
201
/* during VMInit processing
202
* this is how the invocation engine (callback wrapper) tells us to start up all the javaagents
203
*/
204
extern jboolean
205
processJavaStart( JPLISAgent * agent,
206
JNIEnv * jnienv);
207
208
/* on an ongoing basis,
209
* this is how the invocation engine (callback wrapper) tells us to process a class file
210
*/
211
extern void
212
transformClassFile( JPLISAgent * agent,
213
JNIEnv * jnienv,
214
jobject loader,
215
const char* name,
216
jclass classBeingRedefined,
217
jobject protectionDomain,
218
jint class_data_len,
219
const unsigned char* class_data,
220
jint* new_class_data_len,
221
unsigned char** new_class_data,
222
jboolean is_retransformer);
223
224
/* on an ongoing basis,
225
* Return the environment with the retransformation capability.
226
* Create it if it doesn't exist.
227
*/
228
extern jvmtiEnv *
229
retransformableEnvironment(JPLISAgent * agent);
230
231
/* on an ongoing basis,
232
* these are implementations of the Instrumentation services.
233
* Most are simple covers for JVMTI access services. These are the guts of the InstrumentationImpl
234
* native methods.
235
*/
236
extern jboolean
237
isModifiableClass(JNIEnv * jnienv, JPLISAgent * agent, jclass clazz);
238
239
extern jboolean
240
isRetransformClassesSupported(JNIEnv * jnienv, JPLISAgent * agent);
241
242
extern void
243
setHasRetransformableTransformers(JNIEnv * jnienv, JPLISAgent * agent, jboolean has);
244
245
extern void
246
retransformClasses(JNIEnv * jnienv, JPLISAgent * agent, jobjectArray classes);
247
248
extern void
249
redefineClasses(JNIEnv * jnienv, JPLISAgent * agent, jobjectArray classDefinitions);
250
251
extern jobjectArray
252
getAllLoadedClasses(JNIEnv * jnienv, JPLISAgent * agent);
253
254
extern jobjectArray
255
getInitiatedClasses(JNIEnv * jnienv, JPLISAgent * agent, jobject classLoader);
256
257
extern jlong
258
getObjectSize(JNIEnv * jnienv, JPLISAgent * agent, jobject objectToSize);
259
260
extern void
261
appendToClassLoaderSearch(JNIEnv * jnienv, JPLISAgent * agent, jstring jarFile, jboolean isBootLoader);
262
263
extern void
264
setNativeMethodPrefixes(JNIEnv * jnienv, JPLISAgent * agent, jobjectArray prefixArray,
265
jboolean isRetransformable);
266
267
#define jvmti(a) a->mNormalEnvironment.mJVMTIEnv
268
269
/*
270
* A set of macros for insulating the JLI method callers from
271
* JVMTI_ERROR_WRONG_PHASE return codes.
272
*/
273
274
/* for a JLI method where "blob" is executed before simply returning */
275
#define check_phase_blob_ret(ret, blob) \
276
if ((ret) == JVMTI_ERROR_WRONG_PHASE) { \
277
blob; \
278
return; \
279
}
280
281
/* for a JLI method where simply returning is benign */
282
#define check_phase_ret(ret) \
283
if ((ret) == JVMTI_ERROR_WRONG_PHASE) { \
284
return; \
285
}
286
287
/* for a JLI method where returning zero (0) is benign */
288
#define check_phase_ret_0(ret) \
289
if ((ret) == JVMTI_ERROR_WRONG_PHASE) { \
290
return 0; \
291
}
292
293
/* for a JLI method where returning one (1) is benign */
294
#define check_phase_ret_1(ret) \
295
if ((ret) == JVMTI_ERROR_WRONG_PHASE) { \
296
return 1; \
297
}
298
299
/* for a case where a specific "blob" must be returned */
300
#define check_phase_ret_blob(ret, blob) \
301
if ((ret) == JVMTI_ERROR_WRONG_PHASE) { \
302
return (blob); \
303
}
304
305
/* for a JLI method where returning false is benign */
306
#define check_phase_ret_false(ret) \
307
if ((ret) == JVMTI_ERROR_WRONG_PHASE) { \
308
return (jboolean) 0; \
309
}
310
311
#ifdef __cplusplus
312
} /* extern "C" */
313
#endif /* __cplusplus */
314
315
316
#endif
317
318