Skip to content

Commit 8d388cc

Browse files
committed
8346457: AOT cache creation crashes with "assert(pair_at(i).match() < pair_at(i+1).match()) failed: unsorted table entries"
Reviewed-by: iklam, dholmes
1 parent d723597 commit 8d388cc

File tree

3 files changed

+170
-1
lines changed

3 files changed

+170
-1
lines changed

src/hotspot/share/cds/metaspaceShared.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -987,8 +987,10 @@ bool MetaspaceShared::try_link_class(JavaThread* current, InstanceKlass* ik) {
987987
ik->external_name());
988988
CLEAR_PENDING_EXCEPTION;
989989
SystemDictionaryShared::set_class_has_failed_verification(ik);
990+
} else {
991+
assert(!SystemDictionaryShared::has_class_failed_verification(ik), "sanity");
992+
ik->compute_has_loops_flag_for_methods();
990993
}
991-
ik->compute_has_loops_flag_for_methods();
992994
BytecodeVerificationLocal = saved;
993995
return true;
994996
} else {
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (c) 2024, 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+
/*
26+
* @test
27+
* @bug 8346457
28+
* @summary VM should not crash during AOT cache creation when encountering a
29+
* class with VerifyError.
30+
* @requires vm.cds
31+
* @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds/test-classes
32+
* @compile test-classes/BadLookupSwitch.jcod
33+
* @run driver jdk.test.lib.helpers.ClassFileInstaller -jar badlookupswitch.jar BadLookupSwitch
34+
* @run driver CreateAOTCacheVerifyError
35+
*/
36+
37+
import jdk.test.lib.helpers.ClassFileInstaller;
38+
import jdk.test.lib.process.OutputAnalyzer;
39+
40+
public class CreateAOTCacheVerifyError {
41+
42+
public static void main(String[] args) throws Exception {
43+
String appJar = ClassFileInstaller.getJarPath("badlookupswitch.jar");
44+
String classList[] = { BadLookupSwitch.class.getName() };
45+
OutputAnalyzer out = TestCommon.testDump(appJar, classList);
46+
out.shouldContain("Preload Warning: Verification failed for BadLookupSwitch");
47+
out.shouldHaveExitValue(0);
48+
}
49+
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
* Copyright (c) 2024, 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+
class BadLookupSwitch {
26+
0xCAFEBABE;
27+
0;
28+
50;
29+
[] { // Constant Pool
30+
; // first element is empty
31+
class #12; // #1 at 0x0A
32+
class #15; // #2 at 0x0D
33+
Method #2 #4; // #3 at 0x10
34+
NameAndType #6 #5; // #4 at 0x15
35+
Utf8 "()V"; // #5 at 0x1A
36+
Utf8 "<init>"; // #6 at 0x20
37+
Utf8 "Code"; // #7 at 0x29
38+
Utf8 "ConstantValue"; // #8 at 0x30
39+
Utf8 "Exceptions"; // #9 at 0x40
40+
Utf8 "LineNumberTable"; // #10 at 0x4D
41+
Utf8 "LocalVariables"; // #11 at 0x5F
42+
Utf8 "BadLookupSwitch"; // #12 at 0x70
43+
Utf8 "SourceFile"; // #13 at 0x76
44+
Utf8 "f.java"; // #14 at 0x83
45+
Utf8 "java/lang/Object"; // #15 at 0x8C
46+
Utf8 "m"; // #16 at 0x9F
47+
Utf8 "StackMapTable"; // #17
48+
} // Constant Pool
49+
50+
0x0020; // access
51+
#1;// this_cpx
52+
#2;// super_cpx
53+
54+
[0] { // Interfaces
55+
} // Interfaces
56+
57+
[0] { // fields
58+
} // fields
59+
60+
[2] { // methods
61+
{ // Member at 0xAF
62+
0x0001; // access
63+
#16; // name_cpx
64+
#5; // sig_cpx
65+
[] { // Attributes
66+
Attr(#7) { // Code at 0xB7
67+
1; // max_stack
68+
1; // max_locals
69+
Bytes[29] {
70+
0x04AB00000000001B; // iconst_1;
71+
/* right:
72+
0x0000000200000001; // lookupswitch 27 2 1 27 2 27;
73+
0x0000001B00000002;
74+
0x0000001B;
75+
end right */
76+
// wrong:
77+
0x0000000200000002; // lookupswitch 27 2 2 27 1 27;
78+
0x0000001B00000001;
79+
0x0000001B;
80+
// end wrong
81+
0xB1; // return
82+
};
83+
[0] { // Traps
84+
} // end Traps
85+
[] { // Attributes
86+
Attr(#17) { // StackMap
87+
[] { //
88+
255b, 28, []{O,1}, []{};
89+
}
90+
} // end StackMap
91+
} // Attributes
92+
} // end Code
93+
} // Attributes
94+
} // Member
95+
;
96+
{ // Member at 0xD6
97+
0x0000; // access
98+
#6; // name_cpx
99+
#5; // sig_cpx
100+
[1] { // Attributes
101+
Attr(#7) { // Code at 0xDE
102+
1; // max_stack
103+
1; // max_locals
104+
Bytes[5] {
105+
0x2AB70003B1;
106+
};
107+
[0] { // Traps
108+
} // end Traps
109+
[] { // Attributes
110+
} // Attributes
111+
} // end Code
112+
} // Attributes
113+
} // Member
114+
} // methods
115+
116+
[] { // Attributes
117+
} // Attributes
118+
} // end class

0 commit comments

Comments
 (0)