author | iignatyev |
Thu, 02 Aug 2018 14:40:55 -0700 | |
changeset 51287 | 7b1ddbafa134 |
parent 50735 | 2f2af62dfac7 |
permissions | -rw-r--r-- |
40927
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
1 |
/* |
50405
449cbde4c40c
8204165: Filter out tests requiring class unloading when ClassUnloading is disabled
stefank
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. |
40927
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
4 |
* |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
8 |
* |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
13 |
* accompanied this code). |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
14 |
* |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
18 |
* |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
21 |
* questions. |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
22 |
*/ |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
23 |
|
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
24 |
/* |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
25 |
* @test |
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50405
diff
changeset
|
26 |
* @bug 8165246 8010319 |
40927
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
27 |
* @summary Test has_previous_versions flag and processing during class unloading. |
50405
449cbde4c40c
8204165: Filter out tests requiring class unloading when ClassUnloading is disabled
stefank
parents:
47216
diff
changeset
|
28 |
* @requires vm.opt.final.ClassUnloading |
40927
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
29 |
* @library /test/lib |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
30 |
* @modules java.base/jdk.internal.misc |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
31 |
* @modules java.compiler |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
32 |
* java.instrument |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
33 |
* jdk.jartool/sun.tools.jar |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
34 |
* @run main RedefineClassHelper |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
35 |
* @run main/othervm RedefinePreviousVersions test |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
36 |
*/ |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
37 |
|
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
38 |
import jdk.test.lib.process.ProcessTools; |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
39 |
import jdk.test.lib.process.OutputAnalyzer; |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
40 |
|
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50405
diff
changeset
|
41 |
// package access top-level classes to avoid problem with RedefineClassHelper |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50405
diff
changeset
|
42 |
// and nested types. |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50405
diff
changeset
|
43 |
|
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50405
diff
changeset
|
44 |
class RedefinePreviousVersions_B { } |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50405
diff
changeset
|
45 |
|
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50405
diff
changeset
|
46 |
class RedefinePreviousVersions_Running { |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50405
diff
changeset
|
47 |
public static volatile boolean stop = false; |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50405
diff
changeset
|
48 |
public static volatile boolean running = false; |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50405
diff
changeset
|
49 |
static void localSleep() { |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50405
diff
changeset
|
50 |
try { |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50405
diff
changeset
|
51 |
Thread.sleep(10); // sleep for 10 ms |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50405
diff
changeset
|
52 |
} catch(InterruptedException ie) { |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50405
diff
changeset
|
53 |
} |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50405
diff
changeset
|
54 |
} |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50405
diff
changeset
|
55 |
|
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50405
diff
changeset
|
56 |
public static void infinite() { |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50405
diff
changeset
|
57 |
running = true; |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50405
diff
changeset
|
58 |
while (!stop) { localSleep(); } |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50405
diff
changeset
|
59 |
} |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50405
diff
changeset
|
60 |
} |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50405
diff
changeset
|
61 |
|
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50405
diff
changeset
|
62 |
|
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50405
diff
changeset
|
63 |
|
40927
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
64 |
public class RedefinePreviousVersions { |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
65 |
|
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
66 |
public static String newB = |
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50405
diff
changeset
|
67 |
"class RedefinePreviousVersions_B {" + |
40927
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
68 |
"}"; |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
69 |
|
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
70 |
public static String newRunning = |
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50405
diff
changeset
|
71 |
"class RedefinePreviousVersions_Running {" + |
40927
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
72 |
" public static volatile boolean stop = true;" + |
43426
f949081d8be8
8172246: [TESTBUG] runtime/RedefineTests/RedefinePreviousVersions.java 'Class unloading: has_previous_versions = true' missing from stdout/stderr
coleenp
parents:
40927
diff
changeset
|
73 |
" public static volatile boolean running = true;" + |
40927
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
74 |
" static void localSleep() { }" + |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
75 |
" public static void infinite() { }" + |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
76 |
"}"; |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
77 |
|
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
78 |
public static void main(String[] args) throws Exception { |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
79 |
|
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
80 |
if (args.length > 0) { |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
81 |
|
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
82 |
// java -javaagent:redefineagent.jar -Xlog:stuff RedefinePreviousVersions |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
83 |
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( "-javaagent:redefineagent.jar", |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
84 |
"-Xlog:redefine+class+iklass+add=trace,redefine+class+iklass+purge=trace", |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
85 |
"RedefinePreviousVersions"); |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
86 |
new OutputAnalyzer(pb.start()) |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
87 |
.shouldContain("Class unloading: has_previous_versions = false") |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
88 |
.shouldContain("Class unloading: has_previous_versions = true") |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
89 |
.shouldHaveExitValue(0); |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
90 |
return; |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
91 |
} |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
92 |
|
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
93 |
// Redefine a class and create some garbage |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
94 |
// Since there are no methods running, the previous version is never added to the |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
95 |
// previous_version_list and the flag _has_previous_versions should stay false |
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50405
diff
changeset
|
96 |
RedefineClassHelper.redefineClass(RedefinePreviousVersions_B.class, newB); |
40927
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
97 |
|
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
98 |
for (int i = 0; i < 10 ; i++) { |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
99 |
String s = new String("some garbage"); |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
100 |
System.gc(); |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
101 |
} |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
102 |
|
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
103 |
// Start a class that has a method running |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
104 |
new Thread() { |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
105 |
public void run() { |
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50405
diff
changeset
|
106 |
RedefinePreviousVersions_Running.infinite(); |
40927
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
107 |
} |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
108 |
}.start(); |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
109 |
|
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50405
diff
changeset
|
110 |
while (!RedefinePreviousVersions_Running.running) { |
43426
f949081d8be8
8172246: [TESTBUG] runtime/RedefineTests/RedefinePreviousVersions.java 'Class unloading: has_previous_versions = true' missing from stdout/stderr
coleenp
parents:
40927
diff
changeset
|
111 |
Thread.sleep(10); // sleep for 10 ms |
f949081d8be8
8172246: [TESTBUG] runtime/RedefineTests/RedefinePreviousVersions.java 'Class unloading: has_previous_versions = true' missing from stdout/stderr
coleenp
parents:
40927
diff
changeset
|
112 |
} |
f949081d8be8
8172246: [TESTBUG] runtime/RedefineTests/RedefinePreviousVersions.java 'Class unloading: has_previous_versions = true' missing from stdout/stderr
coleenp
parents:
40927
diff
changeset
|
113 |
|
40927
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
114 |
// Since a method of newRunning is running, this class should be added to the previous_version_list |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
115 |
// of Running, and _has_previous_versions should return true at class unloading. |
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50405
diff
changeset
|
116 |
RedefineClassHelper.redefineClass(RedefinePreviousVersions_Running.class, newRunning); |
40927
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
117 |
|
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
118 |
for (int i = 0; i < 10 ; i++) { |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
119 |
String s = new String("some garbage"); |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
120 |
System.gc(); |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
121 |
} |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
122 |
|
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
123 |
// purge should clean everything up, except Xcomp it might not. |
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50405
diff
changeset
|
124 |
RedefinePreviousVersions_Running.stop = true; |
40927
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
125 |
|
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
126 |
for (int i = 0; i < 10 ; i++) { |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
127 |
String s = new String("some garbage"); |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
128 |
System.gc(); |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
129 |
} |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
130 |
} |
59f3c8a69541
8165246: [REDO] InstanceKlass::_previous_version_count goes negative
coleenp
parents:
diff
changeset
|
131 |
} |