author | alanb |
Fri, 07 Apr 2017 08:05:54 +0000 | |
changeset 44545 | 83b611b88ac8 |
parent 40691 | 6e84cac08e9a |
permissions | -rw-r--r-- |
2 | 1 |
/* |
30376
2ccf2cf7ea48
8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents:
26205
diff
changeset
|
2 |
* Copyright (c) 2005, 2015, 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 |
|
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 |
* |
|
5506 | 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. |
|
2 | 22 |
*/ |
23 |
||
24 |
/** |
|
25 |
* @test |
|
26 |
* @bug 6263319 |
|
40691
6e84cac08e9a
8158628: test/java/lang/instrument/NativeMethodPrefixAgent.java: Error occurred during initialization of VM: Failed to start tracing backend.
rehn
parents:
36427
diff
changeset
|
27 |
* @requires ((vm.opt.StartFlightRecording == null) | (vm.opt.StartFlightRecording == false)) & ((vm.opt.FlightRecorder == null) | (vm.opt.FlightRecorder == false)) |
2 | 28 |
* @summary test setNativeMethodPrefix |
29 |
* @author Robert Field, Sun Microsystems |
|
30 |
* |
|
30376
2ccf2cf7ea48
8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents:
26205
diff
changeset
|
31 |
* @modules java.base/jdk.internal.org.objectweb.asm |
33402
1156d495a525
8140336: Add @modules for exported dependencies to jdk_core tests
shurailine
parents:
30376
diff
changeset
|
32 |
* java.management |
1156d495a525
8140336: Add @modules for exported dependencies to jdk_core tests
shurailine
parents:
30376
diff
changeset
|
33 |
* java.instrument |
277
9d9c1747de00
6528548: 4/4 NativeMethodPrefixAgent.java times out intermittently in nightly
dcubed
parents:
2
diff
changeset
|
34 |
* @run shell/timeout=240 MakeJAR2.sh NativeMethodPrefixAgent NativeMethodPrefixApp 'Can-Retransform-Classes: true' 'Can-Set-Native-Method-Prefix: true' |
36427
1be706dbb3b8
8151100: Test java/lang/instrument/NativeMethodPrefixAgent.java can't attempt to do CheckIntrinsics
mgronlun
parents:
33402
diff
changeset
|
35 |
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:-CheckIntrinsics -javaagent:NativeMethodPrefixAgent.jar NativeMethodPrefixApp |
2 | 36 |
*/ |
37 |
||
38 |
import java.lang.instrument.*; |
|
39 |
import java.security.ProtectionDomain; |
|
40 |
import java.io.*; |
|
41 |
||
26205
c073791a67de
8037082: java/lang/instrument/NativeMethodPrefixAgent.java failing
jbachorik
parents:
5506
diff
changeset
|
42 |
import asmlib.*; |
2 | 43 |
|
44 |
class NativeMethodPrefixAgent { |
|
45 |
||
46 |
static ClassFileTransformer t0, t1, t2; |
|
47 |
static Instrumentation inst; |
|
48 |
||
49 |
static class Tr implements ClassFileTransformer { |
|
50 |
final String trname; |
|
51 |
final int transformId; |
|
52 |
||
53 |
Tr(int transformId) { |
|
54 |
this.trname = "tr" + transformId; |
|
55 |
this.transformId = transformId; |
|
56 |
} |
|
57 |
||
58 |
public byte[] |
|
59 |
transform( |
|
60 |
ClassLoader loader, |
|
61 |
String className, |
|
62 |
Class<?> classBeingRedefined, |
|
63 |
ProtectionDomain protectionDomain, |
|
64 |
byte[] classfileBuffer) { |
|
65 |
boolean redef = classBeingRedefined != null; |
|
66 |
System.out.println(trname + ": " + |
|
67 |
(redef? "Retransforming " : "Loading ") + className); |
|
68 |
if (className != null) { |
|
69 |
try { |
|
26205
c073791a67de
8037082: java/lang/instrument/NativeMethodPrefixAgent.java failing
jbachorik
parents:
5506
diff
changeset
|
70 |
byte[] newcf = Instrumentor.instrFor(classfileBuffer) |
c073791a67de
8037082: java/lang/instrument/NativeMethodPrefixAgent.java failing
jbachorik
parents:
5506
diff
changeset
|
71 |
.addNativeMethodTrackingInjection( |
c073791a67de
8037082: java/lang/instrument/NativeMethodPrefixAgent.java failing
jbachorik
parents:
5506
diff
changeset
|
72 |
"wrapped_" + trname + "_", |
c073791a67de
8037082: java/lang/instrument/NativeMethodPrefixAgent.java failing
jbachorik
parents:
5506
diff
changeset
|
73 |
(h)->{ |
c073791a67de
8037082: java/lang/instrument/NativeMethodPrefixAgent.java failing
jbachorik
parents:
5506
diff
changeset
|
74 |
h.push(h.getName()); |
c073791a67de
8037082: java/lang/instrument/NativeMethodPrefixAgent.java failing
jbachorik
parents:
5506
diff
changeset
|
75 |
h.push(transformId); |
c073791a67de
8037082: java/lang/instrument/NativeMethodPrefixAgent.java failing
jbachorik
parents:
5506
diff
changeset
|
76 |
h.invokeStatic("bootreporter/StringIdCallbackReporter", "tracker", "(Ljava/lang/String;I)V", false); |
c073791a67de
8037082: java/lang/instrument/NativeMethodPrefixAgent.java failing
jbachorik
parents:
5506
diff
changeset
|
77 |
}) |
c073791a67de
8037082: java/lang/instrument/NativeMethodPrefixAgent.java failing
jbachorik
parents:
5506
diff
changeset
|
78 |
.apply(); |
c073791a67de
8037082: java/lang/instrument/NativeMethodPrefixAgent.java failing
jbachorik
parents:
5506
diff
changeset
|
79 |
/*** debugging ... |
c073791a67de
8037082: java/lang/instrument/NativeMethodPrefixAgent.java failing
jbachorik
parents:
5506
diff
changeset
|
80 |
if (newcf != null) { |
c073791a67de
8037082: java/lang/instrument/NativeMethodPrefixAgent.java failing
jbachorik
parents:
5506
diff
changeset
|
81 |
String fname = trname + (redef?"_redef" : "") + "/" + className; |
c073791a67de
8037082: java/lang/instrument/NativeMethodPrefixAgent.java failing
jbachorik
parents:
5506
diff
changeset
|
82 |
System.err.println("dumping to: " + fname); |
c073791a67de
8037082: java/lang/instrument/NativeMethodPrefixAgent.java failing
jbachorik
parents:
5506
diff
changeset
|
83 |
write_buffer(fname + "_before.class", classfileBuffer); |
c073791a67de
8037082: java/lang/instrument/NativeMethodPrefixAgent.java failing
jbachorik
parents:
5506
diff
changeset
|
84 |
write_buffer(fname + "_instr.class", newcf); |
c073791a67de
8037082: java/lang/instrument/NativeMethodPrefixAgent.java failing
jbachorik
parents:
5506
diff
changeset
|
85 |
} |
c073791a67de
8037082: java/lang/instrument/NativeMethodPrefixAgent.java failing
jbachorik
parents:
5506
diff
changeset
|
86 |
***/ |
c073791a67de
8037082: java/lang/instrument/NativeMethodPrefixAgent.java failing
jbachorik
parents:
5506
diff
changeset
|
87 |
|
2 | 88 |
return redef? null : newcf; |
89 |
} catch (Throwable ex) { |
|
90 |
System.err.println("ERROR: Injection failure: " + ex); |
|
91 |
ex.printStackTrace(); |
|
92 |
System.err.println("Returning bad class file, to cause test failure"); |
|
93 |
return new byte[0]; |
|
94 |
} |
|
95 |
} |
|
96 |
return null; |
|
97 |
} |
|
98 |
||
99 |
} |
|
100 |
||
101 |
// for debugging |
|
102 |
static void write_buffer(String fname, byte[]buffer) { |
|
103 |
try { |
|
26205
c073791a67de
8037082: java/lang/instrument/NativeMethodPrefixAgent.java failing
jbachorik
parents:
5506
diff
changeset
|
104 |
File f = new File(fname); |
c073791a67de
8037082: java/lang/instrument/NativeMethodPrefixAgent.java failing
jbachorik
parents:
5506
diff
changeset
|
105 |
if (!f.getParentFile().exists()) { |
c073791a67de
8037082: java/lang/instrument/NativeMethodPrefixAgent.java failing
jbachorik
parents:
5506
diff
changeset
|
106 |
f.getParentFile().mkdirs(); |
c073791a67de
8037082: java/lang/instrument/NativeMethodPrefixAgent.java failing
jbachorik
parents:
5506
diff
changeset
|
107 |
} |
c073791a67de
8037082: java/lang/instrument/NativeMethodPrefixAgent.java failing
jbachorik
parents:
5506
diff
changeset
|
108 |
try (FileOutputStream outStream = new FileOutputStream(f)) { |
c073791a67de
8037082: java/lang/instrument/NativeMethodPrefixAgent.java failing
jbachorik
parents:
5506
diff
changeset
|
109 |
outStream.write(buffer, 0, buffer.length); |
c073791a67de
8037082: java/lang/instrument/NativeMethodPrefixAgent.java failing
jbachorik
parents:
5506
diff
changeset
|
110 |
} |
c073791a67de
8037082: java/lang/instrument/NativeMethodPrefixAgent.java failing
jbachorik
parents:
5506
diff
changeset
|
111 |
} catch (IOException ex) { |
2 | 112 |
System.err.println("EXCEPTION in write_buffer: " + ex); |
113 |
} |
|
114 |
} |
|
115 |
||
116 |
public static void |
|
117 |
premain (String agentArgs, Instrumentation instArg) |
|
118 |
throws IOException, IllegalClassFormatException, |
|
119 |
ClassNotFoundException, UnmodifiableClassException { |
|
120 |
inst = instArg; |
|
121 |
System.out.println("Premain"); |
|
122 |
||
123 |
t1 = new Tr(1); |
|
124 |
t2 = new Tr(2); |
|
125 |
t0 = new Tr(0); |
|
126 |
inst.addTransformer(t1, true); |
|
127 |
inst.addTransformer(t2, false); |
|
128 |
inst.addTransformer(t0, true); |
|
129 |
instArg.setNativeMethodPrefix(t0, "wrapped_tr0_"); |
|
130 |
instArg.setNativeMethodPrefix(t1, "wrapped_tr1_"); |
|
131 |
instArg.setNativeMethodPrefix(t2, "wrapped_tr2_"); |
|
132 |
||
133 |
// warm up: cause load of transformer classes before used during class load |
|
134 |
instArg.retransformClasses(Runtime.class); |
|
135 |
} |
|
136 |
} |