Skip to content

Commit 135f209

Browse files
davleopoDoug Simon
authored and
Doug Simon
committed
8238190: [JVMCI] Fix single implementor speculation for diamond shapes
Reviewed-by: kvn
1 parent f2b7509 commit 135f209

File tree

2 files changed

+103
-1
lines changed

2 files changed

+103
-1
lines changed

src/hotspot/share/oops/instanceKlass.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,7 @@ void InstanceKlass::add_implementor(Klass* k) {
11721172
Klass* ik = implementor();
11731173
if (ik == NULL) {
11741174
set_implementor(k);
1175-
} else if (ik != this) {
1175+
} else if (ik != this && ik != k) {
11761176
// There is already an implementor. Use itself as an indicator of
11771177
// more than one implementors.
11781178
set_implementor(this);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* Copyright (c) 2020, 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 8238190
27+
* @summary Verify single interface implementor recording supports diamond-shaped class hierarchies
28+
* @requires vm.jvmci
29+
* @library ../../../../../
30+
* @modules java.base/jdk.internal.reflect
31+
* jdk.internal.vm.ci/jdk.vm.ci.meta
32+
* jdk.internal.vm.ci/jdk.vm.ci.runtime
33+
* jdk.internal.vm.ci/jdk.vm.ci.common
34+
* java.base/jdk.internal.misc
35+
* @run junit/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:-UseJVMCICompiler jdk.vm.ci.runtime.test.TestSingleImplementor
36+
*/
37+
38+
package jdk.vm.ci.runtime.test;
39+
40+
import org.junit.Assert;
41+
import org.junit.Test;
42+
43+
import jdk.vm.ci.meta.ResolvedJavaType;
44+
45+
46+
public class TestSingleImplementor extends TypeUniverse {
47+
48+
static int SideEffect;
49+
50+
interface I {
51+
void foo();
52+
}
53+
54+
interface I1 extends I {
55+
}
56+
57+
interface I2 extends I {
58+
}
59+
60+
static class Impl implements I1, I2 {
61+
@Override
62+
public void foo() {
63+
SideEffect = 42;
64+
}
65+
}
66+
67+
public static void snippetDiamond(I i) {
68+
i.foo();
69+
}
70+
71+
@Test
72+
public void testDiamondShape() throws Throwable {
73+
snippetDiamond(new Impl());
74+
ResolvedJavaType interfaceType = metaAccess.lookupJavaType(I.class);
75+
ResolvedJavaType implementationType = metaAccess.lookupJavaType(Impl.class);
76+
Assert.assertEquals(implementationType, interfaceType.getSingleImplementor());
77+
}
78+
79+
interface IF1 {
80+
void foo();
81+
}
82+
83+
static class Impl1 implements IF1 {
84+
@Override
85+
public void foo() {
86+
SideEffect = 43;
87+
}
88+
}
89+
90+
public static void snippetRegular(IF1 i) {
91+
i.foo();
92+
}
93+
94+
@Test
95+
public void testRegularShape() throws Throwable {
96+
snippetRegular(new Impl1());
97+
ResolvedJavaType interfaceType = metaAccess.lookupJavaType(IF1.class);
98+
ResolvedJavaType implementationType = metaAccess.lookupJavaType(Impl1.class);
99+
Assert.assertEquals(implementationType, interfaceType.getSingleImplementor());
100+
}
101+
102+
}

0 commit comments

Comments
 (0)