author | chegar |
Tue, 09 Aug 2011 16:39:04 +0100 | |
changeset 10150 | dee4cb73adc3 |
parent 5506 | 202f599c92aa |
child 28095 | 194aecee3901 |
permissions | -rw-r--r-- |
272
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
1 |
/* |
5506 | 2 |
* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. |
272
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
4 |
* |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
8 |
* |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
13 |
* accompanied this code). |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
14 |
* |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
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. |
|
272
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
22 |
*/ |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
23 |
|
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
24 |
import java.lang.instrument.*; |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
25 |
import java.net.*; |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
26 |
import java.io.*; |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
27 |
import java.security.*; |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
28 |
|
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
29 |
/** |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
30 |
* Test Java Agent |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
31 |
* |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
32 |
* @author Daryl Puryear |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
33 |
* @copyright 1999-2004 Wily Technology, Inc. All rights reserved. |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
34 |
*/ |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
35 |
public class ParallelTransformerLoaderAgent |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
36 |
{ |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
37 |
private static URL sURL; |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
38 |
private static ClassLoader sClassLoader; |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
39 |
|
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
40 |
public static synchronized ClassLoader |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
41 |
getClassLoader() |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
42 |
{ |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
43 |
return sClassLoader; |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
44 |
} |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
45 |
|
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
46 |
public static synchronized void |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
47 |
generateNewClassLoader() |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
48 |
{ |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
49 |
sClassLoader = new URLClassLoader(new URL[] {sURL}); |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
50 |
} |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
51 |
|
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
52 |
public static void |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
53 |
premain( String agentArgs, |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
54 |
Instrumentation instrumentation) |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
55 |
throws Exception |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
56 |
{ |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
57 |
if (agentArgs == null || agentArgs == "") |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
58 |
{ |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
59 |
System.err.println("Error: No jar file name provided, test will not run."); |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
60 |
return; |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
61 |
} |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
62 |
|
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
63 |
sURL = (new File(agentArgs)).toURL(); |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
64 |
System.out.println("Using jar file: " + sURL); |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
65 |
generateNewClassLoader(); |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
66 |
|
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
67 |
instrumentation.addTransformer(new TestTransformer()); |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
68 |
} |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
69 |
|
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
70 |
private static class TestTransformer |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
71 |
implements ClassFileTransformer |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
72 |
{ |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
73 |
public byte[] |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
74 |
transform( ClassLoader loader, |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
75 |
String className, |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
76 |
Class classBeingRedefined, |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
77 |
ProtectionDomain protectionDomain, |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
78 |
byte[] classfileBuffer) |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
79 |
throws IllegalClassFormatException |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
80 |
{ |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
81 |
String tName = Thread.currentThread().getName(); |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
82 |
// In 160_03 and older, transform() is called |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
83 |
// with the "system_loader_lock" held and that |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
84 |
// prevents the bootstrap class loaded from |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
85 |
// running in parallel. If we add a slight sleep |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
86 |
// delay here when the transform() call is not |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
87 |
// main or TestThread, then the deadlock in |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
88 |
// 160_03 and older is much more reproducible. |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
89 |
if (!tName.equals("main") && !tName.equals("TestThread")) { |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
90 |
System.out.println("Thread '" + tName + |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
91 |
"' has called transform()"); |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
92 |
try { |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
93 |
Thread.sleep(500); |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
94 |
} catch (InterruptedException ie) { |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
95 |
} |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
96 |
} |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
97 |
|
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
98 |
// load additional classes when called from other threads |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
99 |
if (!tName.equals("main")) |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
100 |
{ |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
101 |
loadClasses(3); |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
102 |
} |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
103 |
return null; |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
104 |
} |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
105 |
|
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
106 |
public static void |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
107 |
loadClasses( int index) |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
108 |
{ |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
109 |
ClassLoader loader = ParallelTransformerLoaderAgent.getClassLoader(); |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
110 |
try |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
111 |
{ |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
112 |
Class.forName("TestClass" + index, true, loader); |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
113 |
} |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
114 |
catch (Exception e) |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
115 |
{ |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
116 |
e.printStackTrace(); |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
117 |
} |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
118 |
} |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
119 |
} |
c4e0a3afe6f2
5088398: 3/2 java.lang.instrument TCK test deadlock (test11)
dcubed
parents:
diff
changeset
|
120 |
} |