author | sspitsyn |
Sat, 09 Jul 2016 21:41:14 -0700 | |
changeset 39739 | 5d058d6bd245 |
parent 37807 | 78e5cb21ca13 |
child 42338 | a60f280f803c |
permissions | -rw-r--r-- |
2 | 1 |
/* |
36511 | 2 |
* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
||
26 |
||
27 |
package sun.instrument; |
|
28 |
||
29 |
import java.lang.reflect.Method; |
|
36511 | 30 |
import java.lang.reflect.Module; |
2 | 31 |
import java.lang.reflect.AccessibleObject; |
32 |
||
33 |
import java.lang.instrument.ClassFileTransformer; |
|
34 |
import java.lang.instrument.ClassDefinition; |
|
35 |
import java.lang.instrument.Instrumentation; |
|
36 |
||
37 |
import java.security.AccessController; |
|
38 |
import java.security.PrivilegedAction; |
|
39 |
import java.security.ProtectionDomain; |
|
40 |
||
36511 | 41 |
import java.util.Objects; |
2 | 42 |
import java.util.jar.JarFile; |
43 |
||
44 |
/* |
|
45 |
* Copyright 2003 Wily Technology, Inc. |
|
46 |
*/ |
|
47 |
||
48 |
/** |
|
49 |
* The Java side of the JPLIS implementation. Works in concert with a native JVMTI agent |
|
50 |
* to implement the JPLIS API set. Provides both the Java API implementation of |
|
51 |
* the Instrumentation interface and utility Java routines to support the native code. |
|
52 |
* Keeps a pointer to the native data structure in a scalar field to allow native |
|
53 |
* processing behind native methods. |
|
54 |
*/ |
|
55 |
public class InstrumentationImpl implements Instrumentation { |
|
56 |
private final TransformerManager mTransformerManager; |
|
57 |
private TransformerManager mRetransfomableTransformerManager; |
|
58 |
// needs to store a native pointer, so use 64 bits |
|
59 |
private final long mNativeAgent; |
|
60 |
private final boolean mEnvironmentSupportsRedefineClasses; |
|
61 |
private volatile boolean mEnvironmentSupportsRetransformClassesKnown; |
|
62 |
private volatile boolean mEnvironmentSupportsRetransformClasses; |
|
63 |
private final boolean mEnvironmentSupportsNativeMethodPrefix; |
|
64 |
||
65 |
private |
|
66 |
InstrumentationImpl(long nativeAgent, |
|
67 |
boolean environmentSupportsRedefineClasses, |
|
68 |
boolean environmentSupportsNativeMethodPrefix) { |
|
69 |
mTransformerManager = new TransformerManager(false); |
|
70 |
mRetransfomableTransformerManager = null; |
|
71 |
mNativeAgent = nativeAgent; |
|
72 |
mEnvironmentSupportsRedefineClasses = environmentSupportsRedefineClasses; |
|
73 |
mEnvironmentSupportsRetransformClassesKnown = false; // false = need to ask |
|
74 |
mEnvironmentSupportsRetransformClasses = false; // don't know yet |
|
75 |
mEnvironmentSupportsNativeMethodPrefix = environmentSupportsNativeMethodPrefix; |
|
76 |
} |
|
77 |
||
78 |
public void |
|
79 |
addTransformer(ClassFileTransformer transformer) { |
|
80 |
addTransformer(transformer, false); |
|
81 |
} |
|
82 |
||
83 |
public synchronized void |
|
84 |
addTransformer(ClassFileTransformer transformer, boolean canRetransform) { |
|
85 |
if (transformer == null) { |
|
86 |
throw new NullPointerException("null passed as 'transformer' in addTransformer"); |
|
87 |
} |
|
88 |
if (canRetransform) { |
|
89 |
if (!isRetransformClassesSupported()) { |
|
90 |
throw new UnsupportedOperationException( |
|
91 |
"adding retransformable transformers is not supported in this environment"); |
|
92 |
} |
|
93 |
if (mRetransfomableTransformerManager == null) { |
|
94 |
mRetransfomableTransformerManager = new TransformerManager(true); |
|
95 |
} |
|
96 |
mRetransfomableTransformerManager.addTransformer(transformer); |
|
97 |
if (mRetransfomableTransformerManager.getTransformerCount() == 1) { |
|
98 |
setHasRetransformableTransformers(mNativeAgent, true); |
|
99 |
} |
|
100 |
} else { |
|
101 |
mTransformerManager.addTransformer(transformer); |
|
102 |
} |
|
103 |
} |
|
104 |
||
105 |
public synchronized boolean |
|
106 |
removeTransformer(ClassFileTransformer transformer) { |
|
107 |
if (transformer == null) { |
|
108 |
throw new NullPointerException("null passed as 'transformer' in removeTransformer"); |
|
109 |
} |
|
110 |
TransformerManager mgr = findTransformerManager(transformer); |
|
111 |
if (mgr != null) { |
|
112 |
mgr.removeTransformer(transformer); |
|
113 |
if (mgr.isRetransformable() && mgr.getTransformerCount() == 0) { |
|
114 |
setHasRetransformableTransformers(mNativeAgent, false); |
|
115 |
} |
|
116 |
return true; |
|
117 |
} |
|
118 |
return false; |
|
119 |
} |
|
120 |
||
121 |
public boolean |
|
122 |
isModifiableClass(Class<?> theClass) { |
|
123 |
if (theClass == null) { |
|
124 |
throw new NullPointerException( |
|
125 |
"null passed as 'theClass' in isModifiableClass"); |
|
126 |
} |
|
127 |
return isModifiableClass0(mNativeAgent, theClass); |
|
128 |
} |
|
129 |
||
130 |
public boolean |
|
131 |
isRetransformClassesSupported() { |
|
132 |
// ask lazily since there is some overhead |
|
133 |
if (!mEnvironmentSupportsRetransformClassesKnown) { |
|
134 |
mEnvironmentSupportsRetransformClasses = isRetransformClassesSupported0(mNativeAgent); |
|
135 |
mEnvironmentSupportsRetransformClassesKnown = true; |
|
136 |
} |
|
137 |
return mEnvironmentSupportsRetransformClasses; |
|
138 |
} |
|
139 |
||
140 |
public void |
|
11125
99b115114fa3
7117357: Warnings in sun.instrument, tools and other sun.* classes
alanb
parents:
5506
diff
changeset
|
141 |
retransformClasses(Class<?>... classes) { |
2 | 142 |
if (!isRetransformClassesSupported()) { |
143 |
throw new UnsupportedOperationException( |
|
144 |
"retransformClasses is not supported in this environment"); |
|
145 |
} |
|
146 |
retransformClasses0(mNativeAgent, classes); |
|
147 |
} |
|
148 |
||
149 |
public boolean |
|
150 |
isRedefineClassesSupported() { |
|
151 |
return mEnvironmentSupportsRedefineClasses; |
|
152 |
} |
|
153 |
||
154 |
public void |
|
11125
99b115114fa3
7117357: Warnings in sun.instrument, tools and other sun.* classes
alanb
parents:
5506
diff
changeset
|
155 |
redefineClasses(ClassDefinition... definitions) |
2 | 156 |
throws ClassNotFoundException { |
157 |
if (!isRedefineClassesSupported()) { |
|
158 |
throw new UnsupportedOperationException("redefineClasses is not supported in this environment"); |
|
159 |
} |
|
160 |
if (definitions == null) { |
|
161 |
throw new NullPointerException("null passed as 'definitions' in redefineClasses"); |
|
162 |
} |
|
163 |
for (int i = 0; i < definitions.length; ++i) { |
|
164 |
if (definitions[i] == null) { |
|
165 |
throw new NullPointerException("element of 'definitions' is null in redefineClasses"); |
|
166 |
} |
|
167 |
} |
|
168 |
if (definitions.length == 0) { |
|
169 |
return; // short-circuit if there are no changes requested |
|
170 |
} |
|
171 |
||
172 |
redefineClasses0(mNativeAgent, definitions); |
|
173 |
} |
|
174 |
||
20754
3d7b2fafc34b
8025967: addition of -Werror broke the old build
valeriep
parents:
14342
diff
changeset
|
175 |
@SuppressWarnings("rawtypes") |
2 | 176 |
public Class[] |
177 |
getAllLoadedClasses() { |
|
178 |
return getAllLoadedClasses0(mNativeAgent); |
|
179 |
} |
|
180 |
||
20754
3d7b2fafc34b
8025967: addition of -Werror broke the old build
valeriep
parents:
14342
diff
changeset
|
181 |
@SuppressWarnings("rawtypes") |
2 | 182 |
public Class[] |
183 |
getInitiatedClasses(ClassLoader loader) { |
|
184 |
return getInitiatedClasses0(mNativeAgent, loader); |
|
185 |
} |
|
186 |
||
187 |
public long |
|
188 |
getObjectSize(Object objectToSize) { |
|
189 |
if (objectToSize == null) { |
|
190 |
throw new NullPointerException("null passed as 'objectToSize' in getObjectSize"); |
|
191 |
} |
|
192 |
return getObjectSize0(mNativeAgent, objectToSize); |
|
193 |
} |
|
194 |
||
195 |
public void |
|
196 |
appendToBootstrapClassLoaderSearch(JarFile jarfile) { |
|
197 |
appendToClassLoaderSearch0(mNativeAgent, jarfile.getName(), true); |
|
198 |
} |
|
199 |
||
200 |
public void |
|
201 |
appendToSystemClassLoaderSearch(JarFile jarfile) { |
|
202 |
appendToClassLoaderSearch0(mNativeAgent, jarfile.getName(), false); |
|
203 |
} |
|
204 |
||
205 |
public boolean |
|
206 |
isNativeMethodPrefixSupported() { |
|
207 |
return mEnvironmentSupportsNativeMethodPrefix; |
|
208 |
} |
|
209 |
||
210 |
public synchronized void |
|
211 |
setNativeMethodPrefix(ClassFileTransformer transformer, String prefix) { |
|
212 |
if (!isNativeMethodPrefixSupported()) { |
|
213 |
throw new UnsupportedOperationException( |
|
214 |
"setNativeMethodPrefix is not supported in this environment"); |
|
215 |
} |
|
216 |
if (transformer == null) { |
|
217 |
throw new NullPointerException( |
|
218 |
"null passed as 'transformer' in setNativeMethodPrefix"); |
|
219 |
} |
|
220 |
TransformerManager mgr = findTransformerManager(transformer); |
|
221 |
if (mgr == null) { |
|
222 |
throw new IllegalArgumentException( |
|
223 |
"transformer not registered in setNativeMethodPrefix"); |
|
224 |
} |
|
225 |
mgr.setNativeMethodPrefix(transformer, prefix); |
|
226 |
String[] prefixes = mgr.getNativeMethodPrefixes(); |
|
227 |
setNativeMethodPrefixes(mNativeAgent, prefixes, mgr.isRetransformable()); |
|
228 |
} |
|
229 |
||
36511 | 230 |
@Override |
231 |
public void addModuleReads(Module module, Module other) { |
|
232 |
Objects.requireNonNull(module); |
|
233 |
Objects.requireNonNull(other); |
|
234 |
jdk.internal.module.Modules.addReads(module, other); |
|
235 |
} |
|
236 |
||
237 |
||
2 | 238 |
private TransformerManager |
239 |
findTransformerManager(ClassFileTransformer transformer) { |
|
240 |
if (mTransformerManager.includesTransformer(transformer)) { |
|
241 |
return mTransformerManager; |
|
242 |
} |
|
243 |
if (mRetransfomableTransformerManager != null && |
|
244 |
mRetransfomableTransformerManager.includesTransformer(transformer)) { |
|
245 |
return mRetransfomableTransformerManager; |
|
246 |
} |
|
247 |
return null; |
|
248 |
} |
|
249 |
||
250 |
||
251 |
/* |
|
252 |
* Natives |
|
253 |
*/ |
|
254 |
private native boolean |
|
255 |
isModifiableClass0(long nativeAgent, Class<?> theClass); |
|
256 |
||
257 |
private native boolean |
|
258 |
isRetransformClassesSupported0(long nativeAgent); |
|
259 |
||
260 |
private native void |
|
261 |
setHasRetransformableTransformers(long nativeAgent, boolean has); |
|
262 |
||
263 |
private native void |
|
264 |
retransformClasses0(long nativeAgent, Class<?>[] classes); |
|
265 |
||
266 |
private native void |
|
267 |
redefineClasses0(long nativeAgent, ClassDefinition[] definitions) |
|
268 |
throws ClassNotFoundException; |
|
269 |
||
20754
3d7b2fafc34b
8025967: addition of -Werror broke the old build
valeriep
parents:
14342
diff
changeset
|
270 |
@SuppressWarnings("rawtypes") |
2 | 271 |
private native Class[] |
272 |
getAllLoadedClasses0(long nativeAgent); |
|
273 |
||
20754
3d7b2fafc34b
8025967: addition of -Werror broke the old build
valeriep
parents:
14342
diff
changeset
|
274 |
@SuppressWarnings("rawtypes") |
2 | 275 |
private native Class[] |
276 |
getInitiatedClasses0(long nativeAgent, ClassLoader loader); |
|
277 |
||
278 |
private native long |
|
279 |
getObjectSize0(long nativeAgent, Object objectToSize); |
|
280 |
||
281 |
private native void |
|
282 |
appendToClassLoaderSearch0(long nativeAgent, String jarfile, boolean bootLoader); |
|
283 |
||
284 |
private native void |
|
285 |
setNativeMethodPrefixes(long nativeAgent, String[] prefixes, boolean isRetransformable); |
|
286 |
||
287 |
static { |
|
288 |
System.loadLibrary("instrument"); |
|
289 |
} |
|
290 |
||
291 |
/* |
|
292 |
* Internals |
|
293 |
*/ |
|
294 |
||
295 |
||
296 |
// Enable or disable Java programming language access checks on a |
|
297 |
// reflected object (for example, a method) |
|
298 |
private static void setAccessible(final AccessibleObject ao, final boolean accessible) { |
|
299 |
AccessController.doPrivileged(new PrivilegedAction<Object>() { |
|
300 |
public Object run() { |
|
301 |
ao.setAccessible(accessible); |
|
302 |
return null; |
|
303 |
}}); |
|
304 |
} |
|
305 |
||
306 |
// Attempt to load and start an agent |
|
307 |
private void |
|
308 |
loadClassAndStartAgent( String classname, |
|
309 |
String methodname, |
|
310 |
String optionsString) |
|
311 |
throws Throwable { |
|
312 |
||
313 |
ClassLoader mainAppLoader = ClassLoader.getSystemClassLoader(); |
|
314 |
Class<?> javaAgentClass = mainAppLoader.loadClass(classname); |
|
315 |
||
316 |
Method m = null; |
|
317 |
NoSuchMethodException firstExc = null; |
|
318 |
boolean twoArgAgent = false; |
|
319 |
||
274
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
320 |
// The agent class must have a premain or agentmain method that |
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
321 |
// has 1 or 2 arguments. We check in the following order: |
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
322 |
// |
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
323 |
// 1) declared with a signature of (String, Instrumentation) |
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
324 |
// 2) declared with a signature of (String) |
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
325 |
// 3) inherited with a signature of (String, Instrumentation) |
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
326 |
// 4) inherited with a signature of (String) |
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
327 |
// |
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
328 |
// So the declared version of either 1-arg or 2-arg always takes |
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
329 |
// primary precedence over an inherited version. After that, the |
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
330 |
// 2-arg version takes precedence over the 1-arg version. |
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
331 |
// |
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
332 |
// If no method is found then we throw the NoSuchMethodException |
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
333 |
// from the first attempt so that the exception text indicates |
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
334 |
// the lookup failed for the 2-arg method (same as JDK5.0). |
2 | 335 |
|
336 |
try { |
|
274
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
337 |
m = javaAgentClass.getDeclaredMethod( methodname, |
11125
99b115114fa3
7117357: Warnings in sun.instrument, tools and other sun.* classes
alanb
parents:
5506
diff
changeset
|
338 |
new Class<?>[] { |
274
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
339 |
String.class, |
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
340 |
java.lang.instrument.Instrumentation.class |
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
341 |
} |
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
342 |
); |
2 | 343 |
twoArgAgent = true; |
344 |
} catch (NoSuchMethodException x) { |
|
345 |
// remember the NoSuchMethodException |
|
346 |
firstExc = x; |
|
347 |
} |
|
348 |
||
349 |
if (m == null) { |
|
274
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
350 |
// now try the declared 1-arg method |
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
351 |
try { |
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
352 |
m = javaAgentClass.getDeclaredMethod(methodname, |
11125
99b115114fa3
7117357: Warnings in sun.instrument, tools and other sun.* classes
alanb
parents:
5506
diff
changeset
|
353 |
new Class<?>[] { String.class }); |
274
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
354 |
} catch (NoSuchMethodException x) { |
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
355 |
// ignore this exception because we'll try |
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
356 |
// two arg inheritance next |
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
357 |
} |
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
358 |
} |
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
359 |
|
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
360 |
if (m == null) { |
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
361 |
// now try the inherited 2-arg method |
2 | 362 |
try { |
274
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
363 |
m = javaAgentClass.getMethod( methodname, |
11125
99b115114fa3
7117357: Warnings in sun.instrument, tools and other sun.* classes
alanb
parents:
5506
diff
changeset
|
364 |
new Class<?>[] { |
274
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
365 |
String.class, |
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
366 |
java.lang.instrument.Instrumentation.class |
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
367 |
} |
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
368 |
); |
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
369 |
twoArgAgent = true; |
2 | 370 |
} catch (NoSuchMethodException x) { |
274
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
371 |
// ignore this exception because we'll try |
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
372 |
// one arg inheritance next |
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
373 |
} |
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
374 |
} |
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
375 |
|
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
376 |
if (m == null) { |
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
377 |
// finally try the inherited 1-arg method |
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
378 |
try { |
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
379 |
m = javaAgentClass.getMethod(methodname, |
11125
99b115114fa3
7117357: Warnings in sun.instrument, tools and other sun.* classes
alanb
parents:
5506
diff
changeset
|
380 |
new Class<?>[] { String.class }); |
274
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
381 |
} catch (NoSuchMethodException x) { |
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
382 |
// none of the methods exists so we throw the |
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
383 |
// first NoSuchMethodException as per 5.0 |
2 | 384 |
throw firstExc; |
385 |
} |
|
386 |
} |
|
387 |
||
388 |
// the premain method should not be required to be public, |
|
389 |
// make it accessible so we can call it |
|
274
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
390 |
// Note: The spec says the following: |
d0ca9ee56273
6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents:
2
diff
changeset
|
391 |
// The agent class must implement a public static premain method... |
2 | 392 |
setAccessible(m, true); |
393 |
||
394 |
// invoke the 1 or 2-arg method |
|
395 |
if (twoArgAgent) { |
|
396 |
m.invoke(null, new Object[] { optionsString, this }); |
|
397 |
} else { |
|
398 |
m.invoke(null, new Object[] { optionsString }); |
|
399 |
} |
|
400 |
} |
|
401 |
||
402 |
// WARNING: the native code knows the name & signature of this method |
|
403 |
private void |
|
404 |
loadClassAndCallPremain( String classname, |
|
405 |
String optionsString) |
|
406 |
throws Throwable { |
|
407 |
||
408 |
loadClassAndStartAgent( classname, "premain", optionsString ); |
|
409 |
} |
|
410 |
||
411 |
||
412 |
// WARNING: the native code knows the name & signature of this method |
|
413 |
private void |
|
414 |
loadClassAndCallAgentmain( String classname, |
|
415 |
String optionsString) |
|
416 |
throws Throwable { |
|
417 |
||
418 |
loadClassAndStartAgent( classname, "agentmain", optionsString ); |
|
419 |
} |
|
420 |
||
421 |
// WARNING: the native code knows the name & signature of this method |
|
422 |
private byte[] |
|
39739
5d058d6bd245
8159147: Add ClassLoader parameter to new ClassFileTransformer transform method
sspitsyn
parents:
37807
diff
changeset
|
423 |
transform( Module module, |
5d058d6bd245
8159147: Add ClassLoader parameter to new ClassFileTransformer transform method
sspitsyn
parents:
37807
diff
changeset
|
424 |
ClassLoader loader, |
2 | 425 |
String classname, |
11125
99b115114fa3
7117357: Warnings in sun.instrument, tools and other sun.* classes
alanb
parents:
5506
diff
changeset
|
426 |
Class<?> classBeingRedefined, |
2 | 427 |
ProtectionDomain protectionDomain, |
428 |
byte[] classfileBuffer, |
|
429 |
boolean isRetransformer) { |
|
430 |
TransformerManager mgr = isRetransformer? |
|
431 |
mRetransfomableTransformerManager : |
|
432 |
mTransformerManager; |
|
36511 | 433 |
// module is null when not a class load or when loading a class in an |
434 |
// unnamed module and this is the first type to be loaded in the package. |
|
435 |
if (module == null) { |
|
436 |
if (classBeingRedefined != null) { |
|
437 |
module = classBeingRedefined.getModule(); |
|
438 |
} else { |
|
37807
78e5cb21ca13
8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
36511
diff
changeset
|
439 |
module = (loader == null) ? jdk.internal.loader.BootLoader.getUnnamedModule() |
78e5cb21ca13
8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
36511
diff
changeset
|
440 |
: loader.getUnnamedModule(); |
36511 | 441 |
} |
442 |
} |
|
2 | 443 |
if (mgr == null) { |
444 |
return null; // no manager, no transform |
|
445 |
} else { |
|
36511 | 446 |
return mgr.transform( module, |
39739
5d058d6bd245
8159147: Add ClassLoader parameter to new ClassFileTransformer transform method
sspitsyn
parents:
37807
diff
changeset
|
447 |
loader, |
2 | 448 |
classname, |
449 |
classBeingRedefined, |
|
450 |
protectionDomain, |
|
451 |
classfileBuffer); |
|
452 |
} |
|
453 |
} |
|
454 |
} |