Skip to content

Commit 1c7a131

Browse files
committedMay 20, 2021
8267350: Archived old interface extends interface with default method causes crash
Reviewed-by: iklam, minqi
1 parent 005d8a7 commit 1c7a131

File tree

6 files changed

+196
-1
lines changed

6 files changed

+196
-1
lines changed
 

‎src/hotspot/share/oops/instanceKlass.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -2370,7 +2370,11 @@ void InstanceKlass::metaspace_pointers_do(MetaspaceClosure* it) {
23702370
it->push(&_local_interfaces);
23712371
it->push(&_transitive_interfaces);
23722372
it->push(&_method_ordering);
2373-
it->push(&_default_vtable_indices);
2373+
if (!is_rewritten()) {
2374+
it->push(&_default_vtable_indices, MetaspaceClosure::_writable);
2375+
} else {
2376+
it->push(&_default_vtable_indices);
2377+
}
23742378
it->push(&_fields);
23752379

23762380
if (itable_length() > 0) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright (c) 2021, 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 8267350
27+
* @summary CDS support of old classes with major version < JDK_6 (50) for static archive.
28+
* Test an old interface extends another interface which has a default method.
29+
* @requires vm.cds
30+
* @library /test/lib
31+
* @compile test-classes/InfDefMeth.java
32+
* @compile test-classes/OldInfDefMeth.jasm
33+
* @compile test-classes/OldInfDefMethImpl.java
34+
* @compile test-classes/OldInfDefMethApp.java
35+
* @run driver OldInfExtendsInfDefMeth
36+
*/
37+
38+
import jdk.test.lib.cds.CDSTestUtils;
39+
import jdk.test.lib.process.OutputAnalyzer;
40+
41+
public class OldInfExtendsInfDefMeth {
42+
public static void main(String[] args) throws Exception {
43+
String mainClass = "OldInfDefMethApp";
44+
String namePrefix = "oldinfdefmeth";
45+
String appClasses[] = TestCommon.list("InfDefMeth", "OldInfDefMeth", "OldInfDefMethImpl", mainClass);
46+
JarBuilder.build(namePrefix, appClasses);
47+
String appJar = TestCommon.getTestJar(namePrefix + ".jar");
48+
49+
boolean dynamicMode = CDSTestUtils.DYNAMIC_DUMP;
50+
51+
// create archive with class list
52+
OutputAnalyzer output = TestCommon.dump(appJar, appClasses, "-Xlog:class+load,cds=debug,verification=trace");
53+
TestCommon.checkExecReturn(output, 0,
54+
dynamicMode ? true : false,
55+
"Pre JDK 6 class not supported by CDS: 49.0 OldInfDefMeth");
56+
57+
// run with archive
58+
TestCommon.run(
59+
"-cp", appJar,
60+
"-Xlog:class+load,cds=debug,verification=trace",
61+
mainClass)
62+
.assertNormalExit(out -> {
63+
out.shouldContain("Verifying class OldInfDefMeth with old format")
64+
.shouldContain("Verifying class OldInfDefMethImpl with new format");
65+
if (!dynamicMode) {
66+
out.shouldContain("InfDefMeth source: shared objects file")
67+
.shouldContain("OldInfDefMeth source: shared objects file")
68+
.shouldContain("OldInfDefMethImpl source: shared objects file");
69+
} else {
70+
// InfDefMeth has version >=50 so it should be loaded from the
71+
// dynamic archive.
72+
out.shouldContain("InfDefMeth source: shared objects file (top)")
73+
// Old classes were already linked before dynamic dump happened,
74+
// so they couldn't be archived.
75+
.shouldMatch(".class.load.*OldInfDefMeth source:.*oldinfdefmeth.jar")
76+
.shouldMatch(".class.load.*OldInfDefMethImpl source:.*oldinfdefmeth.jar");
77+
}
78+
});
79+
}
80+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (c) 2021, 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+
public interface InfDefMeth {
25+
default public int size() { return 0;};
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (c) 2021, 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+
public interface OldInfDefMeth
25+
implements InfDefMeth
26+
version 49:0
27+
{
28+
public abstract Method SayHello:"()Ljava/lang/String;";
29+
30+
} // end Class OldInfDefMeth
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 2021, 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+
public class OldInfDefMethApp {
25+
public static void main(String args[]) {
26+
OldInfDefMethImpl o = new OldInfDefMethImpl();
27+
System.out.println(o.SayHello());
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (c) 2021, 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+
public class OldInfDefMethImpl implements OldInfDefMeth {
25+
public String SayHello() { return "Hello from OldInfDefMethImpl"; }
26+
}

0 commit comments

Comments
 (0)
Please sign in to comment.