author | jbachorik |
Tue, 21 Jan 2014 13:04:55 +0100 | |
changeset 22353 | d09e3ff5fd63 |
parent 21310 | 4595a9405051 |
child 30327 | 14a05668b003 |
permissions | -rw-r--r-- |
16021
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
1 |
/* |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
4 |
* |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
8 |
* |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
13 |
* accompanied this code). |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
14 |
* |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
18 |
* |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
21 |
* questions. |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
22 |
*/ |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
23 |
|
21310
4595a9405051
8025238: nsk/jvmti/scenarios/bcinstr/BI04/bi04t002 crashed with SIGSEGV
sla
parents:
16021
diff
changeset
|
24 |
import com.sun.management.DiagnosticCommandMBean; |
16021
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
25 |
import java.io.File; |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
26 |
import java.io.FileInputStream; |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
27 |
import java.io.InputStream; |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
28 |
import java.lang.instrument.ClassDefinition; |
21310
4595a9405051
8025238: nsk/jvmti/scenarios/bcinstr/BI04/bi04t002 crashed with SIGSEGV
sla
parents:
16021
diff
changeset
|
29 |
import java.lang.management.ManagementFactory; |
4595a9405051
8025238: nsk/jvmti/scenarios/bcinstr/BI04/bi04t002 crashed with SIGSEGV
sla
parents:
16021
diff
changeset
|
30 |
import java.lang.management.ThreadInfo; |
16021
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
31 |
import java.lang.reflect.InvocationTargetException; |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
32 |
import java.lang.reflect.Method; |
21310
4595a9405051
8025238: nsk/jvmti/scenarios/bcinstr/BI04/bi04t002 crashed with SIGSEGV
sla
parents:
16021
diff
changeset
|
33 |
import java.util.concurrent.CountDownLatch; |
4595a9405051
8025238: nsk/jvmti/scenarios/bcinstr/BI04/bi04t002 crashed with SIGSEGV
sla
parents:
16021
diff
changeset
|
34 |
import sun.management.ManagementFactoryHelper; |
16021
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
35 |
|
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
36 |
/** |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
37 |
* When an exception is thrown, the JVM collects just enough information |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
38 |
* about the stack trace to be able to create a full fledged stack trace |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
39 |
* (StackTraceElement[]). The backtrace contains this information and the |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
40 |
* JVM must make sure that the data in the backtrace is still usable after |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
41 |
* a class redefinition. |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
42 |
* |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
43 |
* After the PermGen removal there was a bug when the last reference to a Method |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
44 |
* was in the backtrace. The class of the method was kept alive, because of the |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
45 |
* mirror stored in the backtrace, but the old versions of the redefined method |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
46 |
* could be freed, since class redefinition didn't know about the backtraces. |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
47 |
*/ |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
48 |
public class RedefineMethodInBacktraceApp { |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
49 |
public static void main(String args[]) throws Exception { |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
50 |
System.out.println("Hello from RedefineMethodInBacktraceApp!"); |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
51 |
|
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
52 |
new RedefineMethodInBacktraceApp().doTest(); |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
53 |
|
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
54 |
System.exit(0); |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
55 |
} |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
56 |
|
21310
4595a9405051
8025238: nsk/jvmti/scenarios/bcinstr/BI04/bi04t002 crashed with SIGSEGV
sla
parents:
16021
diff
changeset
|
57 |
public static CountDownLatch stop = new CountDownLatch(1); |
4595a9405051
8025238: nsk/jvmti/scenarios/bcinstr/BI04/bi04t002 crashed with SIGSEGV
sla
parents:
16021
diff
changeset
|
58 |
public static CountDownLatch called = new CountDownLatch(1); |
4595a9405051
8025238: nsk/jvmti/scenarios/bcinstr/BI04/bi04t002 crashed with SIGSEGV
sla
parents:
16021
diff
changeset
|
59 |
|
16021
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
60 |
private void doTest() throws Exception { |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
61 |
doMethodInBacktraceTest(); |
21310
4595a9405051
8025238: nsk/jvmti/scenarios/bcinstr/BI04/bi04t002 crashed with SIGSEGV
sla
parents:
16021
diff
changeset
|
62 |
doMethodInBacktraceTestB(); |
16021
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
63 |
} |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
64 |
|
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
65 |
private void doMethodInBacktraceTest() throws Exception { |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
66 |
Throwable t = getThrowableFromMethodToRedefine(); |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
67 |
|
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
68 |
doRedefine(RedefineMethodInBacktraceTarget.class); |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
69 |
|
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
70 |
doClassUnloading(); |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
71 |
|
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
72 |
touchRedefinedMethodInBacktrace(t); |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
73 |
} |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
74 |
|
21310
4595a9405051
8025238: nsk/jvmti/scenarios/bcinstr/BI04/bi04t002 crashed with SIGSEGV
sla
parents:
16021
diff
changeset
|
75 |
private void doMethodInBacktraceTestB() throws Exception { |
4595a9405051
8025238: nsk/jvmti/scenarios/bcinstr/BI04/bi04t002 crashed with SIGSEGV
sla
parents:
16021
diff
changeset
|
76 |
// Start a thread which blocks in method |
4595a9405051
8025238: nsk/jvmti/scenarios/bcinstr/BI04/bi04t002 crashed with SIGSEGV
sla
parents:
16021
diff
changeset
|
77 |
Thread t = new Thread(RedefineMethodInBacktraceTargetB::methodToRedefine); |
4595a9405051
8025238: nsk/jvmti/scenarios/bcinstr/BI04/bi04t002 crashed with SIGSEGV
sla
parents:
16021
diff
changeset
|
78 |
t.setDaemon(true); |
4595a9405051
8025238: nsk/jvmti/scenarios/bcinstr/BI04/bi04t002 crashed with SIGSEGV
sla
parents:
16021
diff
changeset
|
79 |
t.start(); |
4595a9405051
8025238: nsk/jvmti/scenarios/bcinstr/BI04/bi04t002 crashed with SIGSEGV
sla
parents:
16021
diff
changeset
|
80 |
|
4595a9405051
8025238: nsk/jvmti/scenarios/bcinstr/BI04/bi04t002 crashed with SIGSEGV
sla
parents:
16021
diff
changeset
|
81 |
// Wait here until the new thread is in the method we want to redefine |
4595a9405051
8025238: nsk/jvmti/scenarios/bcinstr/BI04/bi04t002 crashed with SIGSEGV
sla
parents:
16021
diff
changeset
|
82 |
called.await(); |
4595a9405051
8025238: nsk/jvmti/scenarios/bcinstr/BI04/bi04t002 crashed with SIGSEGV
sla
parents:
16021
diff
changeset
|
83 |
|
4595a9405051
8025238: nsk/jvmti/scenarios/bcinstr/BI04/bi04t002 crashed with SIGSEGV
sla
parents:
16021
diff
changeset
|
84 |
// Now redefine the class while the method is still on the stack of the new thread |
4595a9405051
8025238: nsk/jvmti/scenarios/bcinstr/BI04/bi04t002 crashed with SIGSEGV
sla
parents:
16021
diff
changeset
|
85 |
doRedefine(RedefineMethodInBacktraceTargetB.class); |
4595a9405051
8025238: nsk/jvmti/scenarios/bcinstr/BI04/bi04t002 crashed with SIGSEGV
sla
parents:
16021
diff
changeset
|
86 |
|
4595a9405051
8025238: nsk/jvmti/scenarios/bcinstr/BI04/bi04t002 crashed with SIGSEGV
sla
parents:
16021
diff
changeset
|
87 |
// Do thread dumps in two different ways (to exercise different code paths) |
4595a9405051
8025238: nsk/jvmti/scenarios/bcinstr/BI04/bi04t002 crashed with SIGSEGV
sla
parents:
16021
diff
changeset
|
88 |
// while the old class is still on the stack |
4595a9405051
8025238: nsk/jvmti/scenarios/bcinstr/BI04/bi04t002 crashed with SIGSEGV
sla
parents:
16021
diff
changeset
|
89 |
|
4595a9405051
8025238: nsk/jvmti/scenarios/bcinstr/BI04/bi04t002 crashed with SIGSEGV
sla
parents:
16021
diff
changeset
|
90 |
ThreadInfo[] tis = ManagementFactory.getThreadMXBean().dumpAllThreads(false, false); |
4595a9405051
8025238: nsk/jvmti/scenarios/bcinstr/BI04/bi04t002 crashed with SIGSEGV
sla
parents:
16021
diff
changeset
|
91 |
for(ThreadInfo ti : tis) { |
4595a9405051
8025238: nsk/jvmti/scenarios/bcinstr/BI04/bi04t002 crashed with SIGSEGV
sla
parents:
16021
diff
changeset
|
92 |
System.out.println(ti); |
4595a9405051
8025238: nsk/jvmti/scenarios/bcinstr/BI04/bi04t002 crashed with SIGSEGV
sla
parents:
16021
diff
changeset
|
93 |
} |
4595a9405051
8025238: nsk/jvmti/scenarios/bcinstr/BI04/bi04t002 crashed with SIGSEGV
sla
parents:
16021
diff
changeset
|
94 |
|
4595a9405051
8025238: nsk/jvmti/scenarios/bcinstr/BI04/bi04t002 crashed with SIGSEGV
sla
parents:
16021
diff
changeset
|
95 |
String[] threadPrintArgs = {}; |
4595a9405051
8025238: nsk/jvmti/scenarios/bcinstr/BI04/bi04t002 crashed with SIGSEGV
sla
parents:
16021
diff
changeset
|
96 |
Object[] dcmdArgs = {threadPrintArgs}; |
4595a9405051
8025238: nsk/jvmti/scenarios/bcinstr/BI04/bi04t002 crashed with SIGSEGV
sla
parents:
16021
diff
changeset
|
97 |
String[] signature = {String[].class.getName()}; |
4595a9405051
8025238: nsk/jvmti/scenarios/bcinstr/BI04/bi04t002 crashed with SIGSEGV
sla
parents:
16021
diff
changeset
|
98 |
DiagnosticCommandMBean dcmd = ManagementFactoryHelper.getDiagnosticCommandMBean(); |
4595a9405051
8025238: nsk/jvmti/scenarios/bcinstr/BI04/bi04t002 crashed with SIGSEGV
sla
parents:
16021
diff
changeset
|
99 |
System.out.println(dcmd.invoke("threadPrint", dcmdArgs, signature)); |
4595a9405051
8025238: nsk/jvmti/scenarios/bcinstr/BI04/bi04t002 crashed with SIGSEGV
sla
parents:
16021
diff
changeset
|
100 |
|
4595a9405051
8025238: nsk/jvmti/scenarios/bcinstr/BI04/bi04t002 crashed with SIGSEGV
sla
parents:
16021
diff
changeset
|
101 |
// release the thread |
4595a9405051
8025238: nsk/jvmti/scenarios/bcinstr/BI04/bi04t002 crashed with SIGSEGV
sla
parents:
16021
diff
changeset
|
102 |
stop.countDown(); |
4595a9405051
8025238: nsk/jvmti/scenarios/bcinstr/BI04/bi04t002 crashed with SIGSEGV
sla
parents:
16021
diff
changeset
|
103 |
} |
4595a9405051
8025238: nsk/jvmti/scenarios/bcinstr/BI04/bi04t002 crashed with SIGSEGV
sla
parents:
16021
diff
changeset
|
104 |
|
16021
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
105 |
private static Throwable getThrowableFromMethodToRedefine() throws Exception { |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
106 |
Class<RedefineMethodInBacktraceTarget> c = |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
107 |
RedefineMethodInBacktraceTarget.class; |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
108 |
Method method = c.getMethod("methodToRedefine"); |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
109 |
|
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
110 |
Throwable thrownFromMethodToRedefine = null; |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
111 |
try { |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
112 |
method.invoke(null); |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
113 |
} catch (InvocationTargetException e) { |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
114 |
thrownFromMethodToRedefine = e.getCause(); |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
115 |
if (!(thrownFromMethodToRedefine instanceof RuntimeException)) { |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
116 |
throw e; |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
117 |
} |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
118 |
} |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
119 |
method = null; |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
120 |
c = null; |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
121 |
|
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
122 |
return thrownFromMethodToRedefine; |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
123 |
} |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
124 |
|
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
125 |
private static void doClassUnloading() { |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
126 |
// This will clean out old, unused redefined methods. |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
127 |
System.gc(); |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
128 |
} |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
129 |
|
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
130 |
private static void touchRedefinedMethodInBacktrace(Throwable throwable) { |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
131 |
// Make sure that we can convert the backtrace, which is referring to |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
132 |
// the redefined method, to a StrackTraceElement[] without crashing. |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
133 |
throwable.getStackTrace(); |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
134 |
} |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
135 |
|
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
136 |
private static void doRedefine(Class<?> clazz) throws Exception { |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
137 |
// Load the second version of this class. |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
138 |
File f = new File(clazz.getName() + ".class"); |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
139 |
System.out.println("Reading test class from " + f.getAbsolutePath()); |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
140 |
InputStream redefineStream = new FileInputStream(f); |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
141 |
|
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
142 |
byte[] redefineBuffer = NamedBuffer.loadBufferFromStream(redefineStream); |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
143 |
|
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
144 |
ClassDefinition redefineParamBlock = new ClassDefinition( |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
145 |
clazz, redefineBuffer); |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
146 |
|
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
147 |
RedefineMethodInBacktraceAgent.getInstrumentation().redefineClasses( |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
148 |
new ClassDefinition[] {redefineParamBlock}); |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
149 |
} |
471eee27e770
8006506: Add test for redefining methods in backtraces to java/lang/instrument tests
stefank
parents:
diff
changeset
|
150 |
} |