JDK-8230935 : [nestmates] update jdk.vm.ci.runtime.test.TestResolvedJavaType test to verify lambdas as hidden class
  • Type: Sub-task
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: repo-valhalla
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2019-09-12
  • Updated: 2020-03-06
  • Resolved: 2020-03-05
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
repo-valhallaFixed
Related Reports
Relates :  
Description
compiler/jvmci/jdk.vm.ci.runtime.test/src/jdk/vm/ci/runtime/test/TestResolvedJavaType.java 
compiler/jvmci/jdk.vm.ci.runtime.test/src/jdk/vm/ci/runtime/test/TestMetaAccessProvider.java 

This looks to me that JVMCI or the test harness needs to add support for hidden classes:
    private static boolean isUnsafeAnoymous(ResolvedJavaType type) {
        return type.getHostClass() != null;
    }


JavaTest Message: JUnit Failure: getHostClassTest(jdk.vm.ci.runtime.test.TestResolvedJavaType): null
java.lang.AssertionError
	at org.junit.Assert.fail(Assert.java:92)
	at org.junit.Assert.assertTrue(Assert.java:43)
	at org.junit.Assert.assertNotNull(Assert.java:526)
	at org.junit.Assert.assertNotNull(Assert.java:537)
	at jdk.vm.ci.runtime.test.TestResolvedJavaType.getHostClassTest(TestResolvedJavaType.java:167)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:61)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
	at org.junit.runners.Suite.runChild(Suite.java:128)
	at org.junit.runners.Suite.runChild(Suite.java:24)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:136)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:127)
	at org.junit.runner.JUnitCore.runClasses(JUnitCore.java:76)
	at com.sun.javatest.regtest.agent.JUnitRunner.main(JUnitRunner.java:76)
	at com.sun.javatest.regtest.agent.JUnitRunner.main(JUnitRunner.java:43)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:61)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	at com.sun.javatest.regtest.agent.MainWrapper$MainThread.run(MainWrapper.java:127)
	at java.base/java.lang.Thread.run(Thread.java:830)
Comments
Thank you, Mandy
06-03-2020

Changeset: https://hg.openjdk.java.net/valhalla/valhalla/rev/e624ea4194e9 This has been pushed the valhalla nestmate repo. It'll be integrated together with JEP 371.
05-03-2020

diff -r 711da7dc077d test/hotspot/jtreg/compiler/jvmci/jdk.vm.ci.runtime.test/src/jdk/vm/ci/runtime/test/TestMetaAccessProvider.java --- a/test/hotspot/jtreg/compiler/jvmci/jdk.vm.ci.runtime.test/src/jdk/vm/ci/runtime/test/TestMetaAccessProvider.java Fri Feb 28 12:16:11 2020 -0800 +++ b/test/hotspot/jtreg/compiler/jvmci/jdk.vm.ci.runtime.test/src/jdk/vm/ci/runtime/test/TestMetaAccessProvider.java Wed Mar 04 02:41:25 2020 +0530 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -68,7 +68,22 @@ metaAccess.encodeDeoptActionAndReason(DEOPT_ACTION, DEOPT_REASON, DEBUG_IDS[3]).asInt() }; - private static boolean isUnsafeAnoymous(ResolvedJavaType type) { + private static boolean isHiddenClass(Class<?> cls) { + if (cls.isHiddenClass()) { + return true; + } + + // Check array of hidden type. + while (cls.getComponentType() != null) { + cls = cls.getComponentType(); + } + if (cls.isHiddenClass()) { + return true; + } + return false; + } + + private static boolean isUnsafeAnonymous(ResolvedJavaType type) { return type.getHostClass() != null; } @@ -77,7 +92,7 @@ for (Class<?> c : classes) { ResolvedJavaType type = metaAccess.lookupJavaType(c); assertNotNull(c.toString(), type); - if (!isUnsafeAnoymous(type)) { + if (!isHiddenClass(c) && !isUnsafeAnonymous(type)) { assertEquals(c.toString(), type.getName(), toInternalName(c.getName())); assertEquals(c.toString(), type.getName(), toInternalName(type.toJavaName())); assertEquals(c.toString(), c.getName(), type.toClassName()); @@ -98,7 +113,7 @@ ResolvedJavaType[] result = metaAccess.lookupJavaTypes(classes.toArray(new Class<?>[classes.size()])); int counter = 0; for (Class<?> aClass : classes) { - if (!isUnsafeAnoymous(result[counter])) { + if (!isHiddenClass(aClass) && !isUnsafeAnonymous(result[counter])) { assertEquals("Unexpected javaType: " + result[counter] + " while expecting of class: " + aClass, result[counter].toClassName(), aClass.getName()); } counter++; diff -r 711da7dc077d test/hotspot/jtreg/compiler/jvmci/jdk.vm.ci.runtime.test/src/jdk/vm/ci/runtime/test/TestResolvedJavaType.java --- a/test/hotspot/jtreg/compiler/jvmci/jdk.vm.ci.runtime.test/src/jdk/vm/ci/runtime/test/TestResolvedJavaType.java Fri Feb 28 12:16:11 2020 -0800 +++ b/test/hotspot/jtreg/compiler/jvmci/jdk.vm.ci.runtime.test/src/jdk/vm/ci/runtime/test/TestResolvedJavaType.java Wed Mar 04 02:41:25 2020 +0530 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,7 +25,8 @@ * @test * @requires vm.jvmci * @library ../../../../../ - * @modules java.base/jdk.internal.reflect + * @modules java.base/jdk.internal.org.objectweb.asm + * java.base/jdk.internal.reflect * jdk.internal.vm.ci/jdk.vm.ci.meta * jdk.internal.vm.ci/jdk.vm.ci.runtime * jdk.internal.vm.ci/jdk.vm.ci.common @@ -65,6 +66,7 @@ import org.junit.Test; +import jdk.internal.org.objectweb.asm.*; import jdk.internal.reflect.ConstantPool; import jdk.vm.ci.common.JVMCIError; import jdk.vm.ci.meta.Assumptions.AssumptionResult; @@ -156,15 +158,26 @@ } } + private static Class<?> anonClass() throws Exception { + ClassWriter cw = new ClassWriter(0); + cw.visit(Opcodes.V1_8, Opcodes.ACC_FINAL + Opcodes.ACC_SUPER, "Anon", null, "java/lang/Object", null); + FieldVisitor intField = cw.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "intField", "I", null, 0); + intField.visitEnd(); + cw.visitEnd(); + return unsafe.defineAnonymousClass(TypeUniverse.class, cw.toByteArray(), null); + } + @Test - public void getHostClassTest() { + public void getHostClassTest() throws Exception { + ResolvedJavaType type = metaAccess.lookupJavaType(anonClass()); + ResolvedJavaType host = type.getHostClass(); + assertNotNull(host); for (Class<?> c : classes) { - ResolvedJavaType type = metaAccess.lookupJavaType(c); - ResolvedJavaType host = type.getHostClass(); - if (!type.equals(predicateType)) { - assertNull(host); - } else { - assertNotNull(host); + type = metaAccess.lookupJavaType(c); + host = type.getHostClass(); + assertNull(host); + if (type.equals(predicateType)) { + assertTrue(c.isHiddenClass()); } } @@ -176,9 +189,10 @@ Supplier<Runnable> lambda = () -> () -> System.out.println("run"); ResolvedJavaType lambdaType = metaAccess.lookupJavaType(lambda.getClass()); ResolvedJavaType nestedLambdaType = metaAccess.lookupJavaType(lambda.get().getClass()); - assertNotNull(lambdaType.getHostClass()); - assertNotNull(nestedLambdaType.getHostClass()); - assertEquals(lambdaType.getHostClass(), nestedLambdaType.getHostClass()); + assertNull(lambdaType.getHostClass()); + assertTrue(lambda.getClass().isHiddenClass()); + assertNull(nestedLambdaType.getHostClass()); + assertTrue(lambda.get().getClass().isHiddenClass()); } @Test (END)
03-03-2020

http://cr.openjdk.java.net/~jcm/8230935/webrev/
03-03-2020

just made similar guard for hidden class like vmanon class.
03-03-2020

This hidden class has a suffix with "/" + "0x00007f0e31eaf9d8" which is expected. The VM anonymous class has been using the same format as well.
02-03-2020

seems tests need to be updated for hidden classes. will modify getHostClass test, as lambdas don't use vmanon any more. will use other means to test getHostClass test coverage.. will update TestMetaAccessProvider.java for HiddenClass usage.
02-03-2020

Depending on what the test is trying to do, this could be a test bug. Does it need to distinguish between hidden and unsafe-anonymous classes?
25-02-2020

Sure, Thank you.
25-09-2019

[~jcm] Please, look.
24-09-2019

[~kvn] please reassign.
12-09-2019

compiler/jvmci/jdk.vm.ci.runtime.test/src/jdk/vm/ci/runtime/test/TestResolvedJavaType.java is temporarily put on test/hotspot/jtreg/ProblemList.txt Please update test/hotspot/jtreg/ProblemList.txt when this issue is resolved.
12-09-2019