Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/serviceability/jvmti/RedefineClasses/RedefineDoubleDelete.java
41153 views
1
/*
2
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
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.
22
*/
23
24
/*
25
* @test
26
* @bug 8178870 8010319
27
* @summary Redefine class with CFLH twice to test deleting the cached_class_file
28
* @requires vm.jvmti
29
* @library /test/lib
30
* @modules java.base/jdk.internal.misc
31
* @modules java.compiler
32
* java.instrument
33
* jdk.jartool/sun.tools.jar
34
* @run main RedefineClassHelper
35
* @run main/othervm/native -Xlog:redefine+class+load+exceptions -agentlib:RedefineDoubleDelete -javaagent:redefineagent.jar RedefineDoubleDelete
36
*/
37
38
// package access top-level class to avoid problem with RedefineClassHelper
39
// and nested types.
40
41
// The ClassFileLoadHook for this class turns foo into faa and prints out faa.
42
class RedefineDoubleDelete_B {
43
int faa() { System.out.println("foo"); return 1; }
44
}
45
46
public class RedefineDoubleDelete {
47
48
// Class gets a redefinition error because it adds a data member
49
public static String newB =
50
"class RedefineDoubleDelete_B {" +
51
" int count1 = 0;" +
52
"}";
53
54
public static String newerB =
55
"class RedefineDoubleDelete_B { " +
56
" int faa() { System.out.println(\"baa\"); return 2; }" +
57
"}";
58
59
public static void main(String args[]) throws Exception {
60
61
RedefineDoubleDelete_B b = new RedefineDoubleDelete_B();
62
int val = b.faa();
63
if (val != 1) {
64
throw new RuntimeException("return value wrong " + val);
65
}
66
67
// Redefine B twice to get cached_class_file in both B scratch classes
68
try {
69
RedefineClassHelper.redefineClass(RedefineDoubleDelete_B.class, newB);
70
} catch (java.lang.UnsupportedOperationException e) {
71
// this is expected
72
}
73
try {
74
RedefineClassHelper.redefineClass(RedefineDoubleDelete_B.class, newB);
75
} catch (java.lang.UnsupportedOperationException e) {
76
// this is expected
77
}
78
79
// Do a full GC.
80
System.gc();
81
82
// Redefine with a compatible class
83
RedefineClassHelper.redefineClass(RedefineDoubleDelete_B.class, newerB);
84
val = b.faa();
85
if (val != 2) {
86
throw new RuntimeException("return value wrong " + val);
87
}
88
89
// Do another full GC to clean things up.
90
System.gc();
91
}
92
}
93
94