author | pchelko |
Mon, 16 Jun 2014 17:13:58 +0400 | |
changeset 25197 | 533f45be322f |
parent 17373 | 7d8bb2a8787e |
child 35572 | c864053d0405 |
permissions | -rw-r--r-- |
15793
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
1 |
/* |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
4 |
* |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
8 |
* |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
13 |
* accompanied this code). |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
14 |
* |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
18 |
* |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
21 |
* questions. |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
22 |
*/ |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
23 |
|
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
24 |
import java.io.InputStream; |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
25 |
import java.nio.file.Files; |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
26 |
import java.nio.file.Path; |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
27 |
import java.nio.file.Paths; |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
28 |
import java.nio.file.StandardCopyOption; |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
29 |
|
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
30 |
/** |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
31 |
* Dump a class file for a class on the class path in the current directory |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
32 |
*/ |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
33 |
public class ClassFileInstaller { |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
34 |
/** |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
35 |
* @param args The names of the classes to dump |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
36 |
* @throws Exception |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
37 |
*/ |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
38 |
public static void main(String... args) throws Exception { |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
39 |
for (String arg : args) { |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
40 |
ClassLoader cl = ClassFileInstaller.class.getClassLoader(); |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
41 |
|
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
42 |
// Convert dotted class name to a path to a class file |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
43 |
String pathName = arg.replace('.', '/').concat(".class"); |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
44 |
InputStream is = cl.getResourceAsStream(pathName); |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
45 |
|
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
46 |
// Create the class file's package directory |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
47 |
Path p = Paths.get(pathName); |
17373
7d8bb2a8787e
8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
15793
diff
changeset
|
48 |
if (pathName.contains("/")) { |
7d8bb2a8787e
8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
15793
diff
changeset
|
49 |
Files.createDirectories(p.getParent()); |
7d8bb2a8787e
8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
15793
diff
changeset
|
50 |
} |
15793
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
51 |
// Create the class file |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
52 |
Files.copy(is, p, StandardCopyOption.REPLACE_EXISTING); |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
53 |
} |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
54 |
} |
4867678e3517
8006753: fix failed for JDK-8002415 White box testing API for HotSpot
mgerdin
parents:
diff
changeset
|
55 |
} |