Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8269956: [lworld] javac should generate ldc LPoint; for class literal Point.class #501

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -4403,6 +4403,16 @@ public void visitSelect(JCFieldAccess tree) {

// Attribute the qualifier expression, and determine its symbol (if any).
Type site = attribTree(tree.selected, env, new ResultInfo(skind, Type.noType));
Assert.check(site == tree.selected.type);
if (tree.name == names._class && site.isPrimitiveClass()) {
/* JDK-8269956: Where a reflective (class) literal is needed, the unqualified Point.class is
* always the "primary" mirror - representing the primitive reference runtime type - thereby
* always matching the behavior of Object::getClass
*/
if (!tree.selected.hasTag(SELECT) || ((JCFieldAccess) tree.selected).name != names.val) {
tree.selected.setType(site = site.referenceProjection());
}
}
if (!pkind().contains(KindSelector.TYP_PCK))
site = capture(site); // Capture field access

@@ -4104,7 +4104,15 @@ public void visitSelect(JCFieldAccess tree) {
tree.selected.hasTag(SELECT) &&
TreeInfo.name(tree.selected) == names._super &&
!types.isDirectSuperInterface(((JCFieldAccess)tree.selected).selected.type.tsym, currentClass);
/* JDK-8269956: Where a reflective (class) literal is needed, the unqualified Point.class is
* always the "primary" mirror - representing the primitive reference runtime type - thereby
* always matching the behavior of Object::getClass
*/
boolean needPrimaryMirror = tree.name == names._class && tree.selected.type.isPrimitiveReferenceType();
tree.selected = translate(tree.selected);
if (needPrimaryMirror && tree.selected.type.isPrimitiveClass()) {
tree.selected.setType(tree.selected.type.referenceProjection());
}
if (tree.name == names._class) {
result = classOf(tree.selected);
}
@@ -101,10 +101,10 @@ public class TestBufferTearing {

static {
try {
Class<?> clazz = MyValue.class;
Class<?> clazz = MyValue.class.asValueType();
MethodHandles.Lookup lookup = MethodHandles.lookup();

MethodType mt = MethodType.methodType(MyValue.class);
MethodType mt = MethodType.methodType(MyValue.class.asValueType());
incrementAndCheck_mh = lookup.findVirtual(clazz, "incrementAndCheck", mt);
} catch (NoSuchMethodException | IllegalAccessException e) {
e.printStackTrace();
@@ -51,14 +51,14 @@ public class TestCallingConvention {
Class<?> clazz = TestCallingConvention.class;
MethodHandles.Lookup lookup = MethodHandles.lookup();

MethodType mt = MethodType.methodType(MyValue2.class, boolean.class);
MethodType mt = MethodType.methodType(MyValue2.class.asValueType(), boolean.class);
test32_mh = lookup.findVirtual(clazz, "test32_interp", mt);

mt = MethodType.methodType(Object.class, boolean.class);
test33_mh = lookup.findVirtual(clazz, "test33_interp", mt);

mt = MethodType.methodType(int.class);
test37_mh = lookup.findVirtual(Test37Value.class, "test", mt);
test37_mh = lookup.findVirtual(Test37Value.class.asValueType(), "test", mt);
} catch (NoSuchMethodException | IllegalAccessException e) {
e.printStackTrace();
throw new RuntimeException("Method handle lookup failed");
@@ -290,7 +290,7 @@ public void test12_verifier() {
public long test13_interp(MyValue2 v, MyValue1[] va, boolean deopt) {
if (deopt) {
// uncommon trap
deoptimize("test13", MyValue2.class, MyValue1[].class, boolean.class, long.class);
deoptimize("test13", MyValue2.class.asValueType(), MyValue1[].class, boolean.class, long.class);
}
return v.hash() + va[0].hash() + va[1].hash();
}
@@ -112,7 +112,7 @@ public class TestDeoptimizationWhenBuffering {
Class<?> clazz = TestDeoptimizationWhenBuffering.class;
MethodHandles.Lookup lookup = MethodHandles.lookup();

MethodType mt = MethodType.methodType(MyValue1.class);
MethodType mt = MethodType.methodType(MyValue1.class.asValueType());
test9_mh = lookup.findStatic(clazz, "test9Callee", mt);
test10_mh = lookup.findStatic(clazz, "test10Callee", mt);
} catch (NoSuchMethodException | IllegalAccessException e) {
@@ -206,7 +206,7 @@ public static void main(String[] args) throws Throwable {
Asserts.assertEQ(args[0], "C1", "unsupported mode");
Method m = MyValue1.class.getMethod("testWithField", int.class);
WHITE_BOX.makeMethodNotCompilable(m, COMP_LEVEL_FULL_OPTIMIZATION, false);
m = TestDeoptimizationWhenBuffering.class.getMethod("test3Callee", MyValue1.class);
m = TestDeoptimizationWhenBuffering.class.getMethod("test3Callee", MyValue1.class.asValueType());
WHITE_BOX.makeMethodNotCompilable(m, COMP_LEVEL_FULL_OPTIMIZATION, false);
m = TestDeoptimizationWhenBuffering.class.getMethod("test9Callee");
WHITE_BOX.makeMethodNotCompilable(m, COMP_LEVEL_FULL_OPTIMIZATION, false);
@@ -75,14 +75,14 @@ public boolean test1(Class<?> supercls, Class<?> subcls) {
public void test1_verifier() {
Asserts.assertTrue(test1(java.util.AbstractList.class, java.util.ArrayList.class), "test1_1 failed");
Asserts.assertTrue(test1(MyValue1.ref.class, MyValue1.ref.class), "test1_2 failed");
Asserts.assertTrue(test1(MyValue1.class, MyValue1.class), "test1_3 failed");
Asserts.assertTrue(test1(MyValue1.ref.class, MyValue1.class), "test1_4 failed");
Asserts.assertFalse(test1(MyValue1.class, MyValue1.ref.class), "test1_5 failed");
Asserts.assertTrue(test1(MyValue1.class.asValueType(), MyValue1.class.asValueType()), "test1_3 failed");
Asserts.assertTrue(test1(MyValue1.ref.class, MyValue1.class.asValueType()), "test1_4 failed");
Asserts.assertFalse(test1(MyValue1.class.asValueType(), MyValue1.ref.class), "test1_5 failed");
Asserts.assertTrue(test1(Object.class, java.util.ArrayList.class), "test1_6 failed");
Asserts.assertTrue(test1(Object.class, MyValue1.ref.class), "test1_7 failed");
Asserts.assertTrue(test1(Object.class, MyValue1.class), "test1_8 failed");
Asserts.assertTrue(test1(Object.class, MyValue1.class.asValueType()), "test1_8 failed");
Asserts.assertTrue(!test1(MyValue1.ref.class, Object.class), "test1_9 failed");
Asserts.assertTrue(!test1(MyValue1.class, Object.class), "test1_10 failed");
Asserts.assertTrue(!test1(MyValue1.class.asValueType(), Object.class), "test1_10 failed");
}

// Verify that Class::isAssignableFrom checks with statically known classes are folded
@@ -91,14 +91,14 @@ public void test1_verifier() {
public boolean test2() {
boolean check1 = java.util.AbstractList.class.isAssignableFrom(java.util.ArrayList.class);
boolean check2 = MyValue1.ref.class.isAssignableFrom(MyValue1.ref.class);
boolean check3 = MyValue1.class.isAssignableFrom(MyValue1.class);
boolean check4 = MyValue1.ref.class.isAssignableFrom(MyValue1.class);
boolean check5 = !MyValue1.class.isAssignableFrom(MyValue1.ref.class);
boolean check3 = MyValue1.class.asValueType().isAssignableFrom(MyValue1.class.asValueType());
boolean check4 = MyValue1.ref.class.isAssignableFrom(MyValue1.class.asValueType());
boolean check5 = !MyValue1.class.asValueType().isAssignableFrom(MyValue1.ref.class);
boolean check6 = Object.class.isAssignableFrom(java.util.ArrayList.class);
boolean check7 = Object.class.isAssignableFrom(MyValue1.ref.class);
boolean check8 = Object.class.isAssignableFrom(MyValue1.class);
boolean check8 = Object.class.isAssignableFrom(MyValue1.class.asValueType());
boolean check9 = !MyValue1.ref.class.isAssignableFrom(Object.class);
boolean check10 = !MyValue1.class.isAssignableFrom(Object.class);
boolean check10 = !MyValue1.class.asValueType().isAssignableFrom(Object.class);
return check1 && check2 && check3 && check4 && check5 && check6 && check7 && check8 && check9 && check10;
}

@@ -173,7 +173,7 @@ public Object[] test7(Class<?> componentType, int len) {
public void test7_verifier() {
int len = Math.abs(rI) % 42;
long hash = MyValue1.createDefaultDontInline().hashPrimitive();
Object[] va = test7(MyValue1.class, len);
Object[] va = test7(MyValue1.class.asValueType(), len);
for (int i = 0; i < len; ++i) {
Asserts.assertEQ(((MyValue1)va[i]).hashPrimitive(), hash);
}
@@ -188,7 +188,7 @@ public boolean test8(Class c, MyValue1 vt) {
@Run(test = "test8")
public void test8_verifier() {
MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
boolean result = test8(MyValue1.class, vt);
boolean result = test8(MyValue1.class.asValueType(), vt);
Asserts.assertTrue(result);
result = test8(MyValue1.ref.class, vt);
Asserts.assertTrue(result);
@@ -217,7 +217,7 @@ public Object test10(Class c, MyValue1 vt) {
@Run(test = "test10")
public void test10_verifier() {
MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
Object result = test10(MyValue1.class, vt);
Object result = test10(MyValue1.class.asValueType(), vt);
Asserts.assertEQ(((MyValue1)result).hash(), vt.hash());
}

@@ -238,7 +238,7 @@ public void test11_verifier() {

@Test()
public Object test12(MyValue1 vt) {
return MyValue1.class.cast(vt);
return MyValue1.class.asValueType().cast(vt);
}

@Run(test = "test12")
@@ -366,11 +366,11 @@ public void test20_verifier() {
private static final boolean V1_FLATTENED;
static {
try {
Field xField = MyValue1.class.getDeclaredField("x");
Field xField = MyValue1.class.asValueType().getDeclaredField("x");
X_OFFSET = U.objectFieldOffset(xField);
Field yField = MyValue1.class.getDeclaredField("y");
Field yField = MyValue1.class.asValueType().getDeclaredField("y");
Y_OFFSET = U.objectFieldOffset(yField);
Field v1Field = MyValue1.class.getDeclaredField("v1");
Field v1Field = MyValue1.class.asValueType().getDeclaredField("v1");
V1_OFFSET = U.objectFieldOffset(v1Field);
V1_FLATTENED = U.isFlattened(v1Field);
} catch (Exception e) {
@@ -788,7 +788,7 @@ public void test41_verifier() {
MyValue1.ref vt = MyValue1.createWithFieldsInline(rI, rL);
boolean result = test41(MyValue1.ref.class, vt);
Asserts.assertTrue(result);
result = test41(MyValue1.class, vt);
result = test41(MyValue1.class.asValueType(), vt);
Asserts.assertTrue(result);
}

@@ -891,10 +891,10 @@ public Object test48(Class c, MyValue1.ref vt) {
@Run(test = "test48")
public void test48_verifier() {
MyValue1.ref vt = MyValue1.createWithFieldsInline(rI, rL);
Object result = test48(MyValue1.class, vt);
Object result = test48(MyValue1.class.asValueType(), vt);
Asserts.assertEQ(((MyValue1)result).hash(), vt.hash());
try {
test48(MyValue1.class, null);
test48(MyValue1.class.asValueType(), null);
throw new RuntimeException("should have thrown");
} catch (NullPointerException npe) {
}
@@ -922,7 +922,7 @@ public void test50_verifier() {
MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
MyValue1[] va = new MyValue1[42];
MyValue1.ref[] vba = new MyValue1.ref[42];
Object result = test50(MyValue1.class, vt);
Object result = test50(MyValue1.class.asValueType(), vt);
Asserts.assertEQ(((MyValue1)result).hash(), vt.hash());
result = test50(MyValue1.ref.class, vt);
Asserts.assertEQ(((MyValue1)result).hash(), vt.hash());
@@ -933,7 +933,7 @@ public void test50_verifier() {
result = test50(MyValue1.ref[].class, va);
Asserts.assertEQ(result, va);
try {
test50(MyValue1.class, null);
test50(MyValue1.class.asValueType(), null);
throw new RuntimeException("should have thrown");
} catch (NullPointerException npe) {
}
@@ -1112,11 +1112,11 @@ public boolean test58(Class<?> c1, Class<?> c2) throws Exception {

@Run(test = "test58")
public void test58_verifier() throws Exception {
boolean res = test58(MyValue1.class, MyValue1.class);
boolean res = test58(MyValue1.class.asValueType(), MyValue1.class.asValueType());
Asserts.assertTrue(res);
res = test58(Object.class, MyValue1.class);
res = test58(Object.class, MyValue1.class.asValueType());
Asserts.assertFalse(res);
res = test58(MyValue1.class, Object.class);
res = test58(MyValue1.class.asValueType(), Object.class);
Asserts.assertFalse(res);
}

@@ -1133,7 +1133,7 @@ public void test59(Class<?> c) throws Exception {
public void test59_verifier() throws Exception {
test59(Integer.class);
try {
test59(MyValue1.class);
test59(MyValue1.class.asValueType());
throw new RuntimeException("test59 failed: synchronization on inline type should not succeed");
} catch (IllegalMonitorStateException e) {

@@ -1150,10 +1150,10 @@ public boolean test60(Class<?> c1, Class<?> c2, boolean b1, boolean b2) throws E

@Run(test = "test60")
public void test60_verifier() throws Exception {
Asserts.assertTrue(test60(MyValue1.class, MyValue1.class, false, false));
Asserts.assertFalse(test60(MyValue1.class, MyValue2.class, false, false));
Asserts.assertFalse(test60(MyValue1.class, MyValue1.class, false, true));
Asserts.assertFalse(test60(MyValue1.class, MyValue1.class, true, false));
Asserts.assertFalse(test60(MyValue1.class, MyValue1.class, true, true));
Asserts.assertTrue(test60(MyValue1.class.asValueType(), MyValue1.class.asValueType(), false, false));
Asserts.assertFalse(test60(MyValue1.class.asValueType(), MyValue2.class, false, false));
Asserts.assertFalse(test60(MyValue1.class.asValueType(), MyValue1.class.asValueType(), false, true));
Asserts.assertFalse(test60(MyValue1.class.asValueType(), MyValue1.class.asValueType(), true, false));
Asserts.assertFalse(test60(MyValue1.class.asValueType(), MyValue1.class.asValueType(), true, true));
}
}
@@ -52,28 +52,28 @@ public class TestMethodHandles {
Class<?> clazz = TestMethodHandles.class;
MethodHandles.Lookup lookup = MethodHandles.lookup();

MethodType mt = MethodType.methodType(MyValue3.class);
MethodType mt = MethodType.methodType(MyValue3.class.asValueType());
test1_mh = lookup.findVirtual(clazz, "test1_target", mt);
test2_mh = lookup.findVirtual(clazz, "test2_target", mt);
test3_mh = lookup.findVirtual(clazz, "test3_target", mt);

MethodType test4_mt1 = MethodType.methodType(int.class, MyValue1.class);
MethodType test4_mt2 = MethodType.methodType(MyValue1.class);
MethodType test4_mt1 = MethodType.methodType(int.class, MyValue1.class.asValueType());
MethodType test4_mt2 = MethodType.methodType(MyValue1.class.asValueType());
MethodHandle test4_mh1 = lookup.findStatic(clazz, "test4_helper1", test4_mt1);
MethodHandle test4_mh2 = lookup.findStatic(clazz, "test4_helper2", test4_mt2);
test4_mh = MethodHandles.filterReturnValue(test4_mh2, test4_mh1);

MethodType test5_mt = MethodType.methodType(int.class, MyValue1.class);
MethodType test5_mt = MethodType.methodType(int.class, MyValue1.class.asValueType());
test5_mh = lookup.findVirtual(clazz, "test5_target", test5_mt);

MethodType test6_mt = MethodType.methodType(MyValue3.class);
MethodType test6_mt = MethodType.methodType(MyValue3.class.asValueType());
MethodHandle test6_mh1 = lookup.findVirtual(clazz, "test6_target1", test6_mt);
MethodHandle test6_mh2 = lookup.findVirtual(clazz, "test6_target2", test6_mt);
MethodType boolean_mt = MethodType.methodType(boolean.class);
MethodHandle test6_mh_test = lookup.findVirtual(clazz, "test6_test", boolean_mt);
test6_mh = MethodHandles.guardWithTest(test6_mh_test, test6_mh1, test6_mh2);

MethodType myvalue2_mt = MethodType.methodType(MyValue2.class);
MethodType myvalue2_mt = MethodType.methodType(MyValue2.class.asValueType());
test7_mh1 = lookup.findStatic(clazz, "test7_target1", myvalue2_mt);
MethodHandle test7_mh2 = lookup.findStatic(clazz, "test7_target2", myvalue2_mt);
MethodHandle test7_mh_test = lookup.findStatic(clazz, "test7_test", boolean_mt);
@@ -88,7 +88,7 @@ public class TestMethodHandles {
MethodHandles.dropArguments(test8_mh1, 0, MethodHandle.class),
MethodHandles.invoker(myvalue2_mt));

MethodType test9_mt = MethodType.methodType(MyValue3.class);
MethodType test9_mt = MethodType.methodType(MyValue3.class.asValueType());
MethodHandle test9_mh1 = lookup.findVirtual(clazz, "test9_target1", test9_mt);
MethodHandle test9_mh2 = lookup.findVirtual(clazz, "test9_target2", test9_mt);
MethodHandle test9_mh3 = lookup.findVirtual(clazz, "test9_target3", test9_mt);
@@ -99,12 +99,12 @@ public class TestMethodHandles {
test9_mh1,
MethodHandles.guardWithTest(test9_mh_test2, test9_mh2, test9_mh3));

MethodType test10_mt = MethodType.methodType(MyValue2.class);
MethodType test10_mt = MethodType.methodType(MyValue2.class.asValueType());
MethodHandle test10_mh1 = lookup.findStatic(clazz, "test10_target1", test10_mt);
test10_mh2 = lookup.findStatic(clazz, "test10_target2", test10_mt);
test10_mh3 = lookup.findStatic(clazz, "test10_target3", test10_mt);
MethodType test10_mt2 = MethodType.methodType(boolean.class);
MethodType test10_mt3 = MethodType.methodType(MyValue2.class);
MethodType test10_mt3 = MethodType.methodType(MyValue2.class.asValueType());
MethodHandle test10_mh_test1 = lookup.findStatic(clazz, "test10_test1", test10_mt2);
MethodHandle test10_mh_test2 = lookup.findStatic(clazz, "test10_test2", test10_mt2);
test10_mh = MethodHandles.guardWithTest(test10_mh_test1,
@@ -1735,7 +1735,7 @@ public void runTest(Method m, Object[] args, int warmup, int nullMode, boolean[]
if (args[i] != null && !parameterTypes[0].isInstance(args[i])) {
continue;
}
if (args[i] == null && parameterTypes[0] == MyValue1.class) {
if (args[i] == null && parameterTypes[0] == MyValue1.class.asValueType()) {
continue;
}
if (parameterCount == 1) {
@@ -1757,7 +1757,7 @@ public void runTest(Method m, Object[] args, int warmup, int nullMode, boolean[]
if (args[j] != null && !parameterTypes[1].isInstance(args[j])) {
continue;
}
if (args[j] == null && parameterTypes[1] == MyValue1.class) {
if (args[j] == null && parameterTypes[1] == MyValue1.class.asValueType()) {
continue;
}
System.out.print("Testing " + m.getName() + "(" + args[i] + ", " + args[j] + ")");