Mercurial > hg > graal-jvmci-8
annotate test/testlibrary/RedefineClassHelper.java @ 23855:dceb9ec3b9b9
8147567: InterpreterRuntime::post_field_access not updated for boolean in JDK-8132051
Reviewed-by: coleenp
author | kevinw |
---|---|
date | Tue, 19 Jan 2016 15:35:12 +0000 |
parents | 3e5e398431a8 |
children |
rev | line source |
---|---|
23183
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
1 /* |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
4 * |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
8 * |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
13 * accompanied this code). |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
14 * |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
18 * |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
21 * questions. |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
22 */ |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
23 |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
24 import java.io.PrintWriter; |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
25 import java.lang.instrument.*; |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
26 import com.oracle.java.testlibrary.*; |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
27 |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
28 /* |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
29 * Helper class to write tests that redefine classes. |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
30 * When main method is run, it will create a redefineagent.jar that can be used |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
31 * with the -javaagent option to support redefining classes in jtreg tests. |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
32 * |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
33 * See sample test in test/testlibrary_tests/RedefineClassTest.java |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
34 */ |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
35 public class RedefineClassHelper { |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
36 |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
37 public static Instrumentation instrumentation; |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
38 public static void premain(String agentArgs, Instrumentation inst) { |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
39 instrumentation = inst; |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
40 } |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
41 |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
42 /** |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
43 * Redefine a class |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
44 * |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
45 * @param clazz Class to redefine |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
46 * @param javacode String with the new java code for the class to be redefined |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
47 */ |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
48 public static void redefineClass(Class clazz, String javacode) throws Exception { |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
49 byte[] bytecode = InMemoryJavaCompiler.compile(clazz.getName(), javacode); |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
50 redefineClass(clazz, bytecode); |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
51 } |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
52 |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
53 /** |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
54 * Redefine a class |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
55 * |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
56 * @param clazz Class to redefine |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
57 * @param bytecode byte[] with the new class |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
58 */ |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
59 public static void redefineClass(Class clazz, byte[] bytecode) throws Exception { |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
60 instrumentation.redefineClasses(new ClassDefinition(clazz, bytecode)); |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
61 } |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
62 |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
63 /** |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
64 * Main method to be invoked before test to create the redefineagent.jar |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
65 */ |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
66 public static void main(String[] args) throws Exception { |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
67 ClassFileInstaller.main("RedefineClassHelper"); |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
68 |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
69 PrintWriter pw = new PrintWriter("MANIFEST.MF"); |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
70 pw.println("Premain-Class: RedefineClassHelper"); |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
71 pw.println("Can-Redefine-Classes: true"); |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
72 pw.close(); |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
73 |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
74 sun.tools.jar.Main jarTool = new sun.tools.jar.Main(System.out, System.err, "jar"); |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
75 if (!jarTool.run(new String[] { "-cmf", "MANIFEST.MF", "redefineagent.jar", "RedefineClassHelper.class" })) { |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
76 throw new Exception("jar operation failed"); |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
77 } |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
78 } |
3e5e398431a8
8044364: runtime/RedefineFinalizer test fails on windows
ctornqvi
parents:
diff
changeset
|
79 } |