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

Methods and tests for jep334 Class #4157

Merged
merged 1 commit into from
Feb 22, 2019

Conversation

theresa-m
Copy link
Contributor

@theresa-m theresa-m commented Dec 31, 2018

  • Class.componentType
  • Class.describeConstable
  • Class.descriptorString
  • Class arrayType

Depends on (see #4195):

Signed-off-by: Theresa Mammarella [email protected]

@theresa-m theresa-m force-pushed the jep334_class branch 2 times, most recently from 523fa4d to 0f9b798 Compare January 3, 2019 00:35
@gacholio
Copy link
Contributor

gacholio commented Jan 7, 2019

@andrewcraik New native Class.arrayType should be recognized by the JIT if we this think it will be called a lot. The expected case is a few instructions, so making a call every time seems wasteful. The sequence should be:

result = clazz->arrayClass;
if (NULL == result) {
   // unexpected - put in snippet?
   result = clazz.arrayType();
}

@theresa-m theresa-m force-pushed the jep334_class branch 3 times, most recently from ce37313 to 5b73f6e Compare January 8, 2019 15:35
@theresa-m
Copy link
Contributor Author

fixing error in testng.xml

@theresa-m theresa-m force-pushed the jep334_class branch 2 times, most recently from 9290593 to a84e8a0 Compare January 9, 2019 16:27
@theresa-m
Copy link
Contributor Author

Found an issue with my Class.describeConstable implementation when I was testing VarHandleDesc. I've added more tests to Test_Class to reproduce the issue and fixed describeConstable

Copy link
Contributor

@gacholio gacholio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have reviewed only the code for the new native.

@pshipton
Copy link
Member

Class implements TypeDescriptor.OfField<Class<?>>, Constable
http://cr.openjdk.java.net/~iris/se/12/build/latest/api/java.base/java/lang/Class.html

@theresa-m
Copy link
Contributor Author

extra implements are included here #4030

* not represent an array.
*/
public Class<?> componentType() {
return this.getComponentType();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for the this.

}

private void describeConstableTestGeneral(String testName, Class<?> testClass) {
Optional<ClassDesc> optionalDesc = testClass.describeConstable();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use .orElseThrow() and let the test code throw if the Optional is empty. The test harness knows how to fail tests for unexpected exceptions.

* - componentType(): wrapper for Class.getComponentType(), not tested
*/
public class Test_Class {
public static Logger logger = Logger.getLogger(Test_Class.class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tabs vs spaces

Class<?> resolvedClass;
try {
resolvedClass = (Class<?>)desc.resolveConstantDesc(MethodHandles.lookup());
} catch(ReflectiveOperationException e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let this code throw - the test framework knows how to fail tests for this

public void testClassDescriptorString() {
/* primitive type test */
logger.debug("testClassDescriptorString: Primitive test result is: " + primitiveTest.descriptorString() + " expected: " + primitiveResult);
Assert.assertTrue(primitiveTest.descriptorString().equals(primitiveResult));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a small number of primitives - Z, B, C, S, I, F, D, J, & V. Seems like we should test them all:

Something like:

Object[][] primitiveData = {
	{ boolean.class, "Z" },
	{ byte.class, "B" },
	{ char.class, "C" },
	{ short.class, "S" },
	{ int.class, "I" },
	{ float.class, "F" },
	{ double.class, "D" },
	{ long.class, "J" },
	{ void.class, "V" }
};
for (Object[] params : primitiveData) {
	Assert.assertEquals(((Class<?>)params[0]).descriptorString(), params[1]);
}


/* ArrayType test */
logger.debug("testClassDescriptorString: Array test result is: " + arrayTest.descriptorString() + " expected: " + arrayResult);
Assert.assertTrue(arrayTest.descriptorString().equals(arrayResult));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something similar to the suggestion above can be done for the primitive array cases.... actually, the Object subclasses can be rolled into the same kind of tests

String arrayString = array.descriptorString();
logger.debug(testName + ": Descriptor of component is: " + result + " descriptor of array is: " + arrayString);
Assert.assertTrue(arrayString.equals("[" + result));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add a test case for the class of a lambda expression?

Runnable r = () -> System.out.println("a");
// This should succeed
ClassDesc desc = r.getClass().describeConstanble();

desc.getDescriptorString() should also succeed but the value returned will be different in each run

but resolveConstantDesc(MethodHandles.lookup()) should fail

@theresa-m
Copy link
Contributor Author

I added a helper for the arrayType() method that throws an IllegalArgumentException when the instance class is void.class to replicate the ri's behavior.

Copy link
Member

@DanHeidinga DanHeidinga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from the very minor naming convention, this looks good

}

private native Class<?> arrayTypeHelper();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The more typical naming convention is adding impl to the method name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just pushed the rename.

@DanHeidinga
Copy link
Member

Jenkins compile win jdk11

@DanHeidinga
Copy link
Member

Jenkins test sanity zlinux jdk12

@theresa-m
Copy link
Contributor Author

sorry that push was a mistake :(

@DanHeidinga
Copy link
Member

@theresa-m Is this branch back to being ready to PR test and merge?

@theresa-m
Copy link
Contributor Author

Right now it's dependent on #4105 only for the reason that the rest of the Java12andUp xml files are there. I just assumed String would be merged first since it was approved at the time. I can also move that commit with the other test files here so the tests will run properly

@theresa-m
Copy link
Contributor Author

theresa-m commented Feb 21, 2019

okay I've just added the rest of the test files to this pr too. now it won't matter which one goes in first

tests will now be run properly for pr builds here

String originalDescriptor = testClass.descriptorString();
String newDescriptor = resolvedClass.descriptorString();
logger.debug(testName + ": Descriptor of original class is: " + originalDescriptor + " descriptor of ClassDesc is: " + newDescriptor);
Assert.assertTrue(testClass.equals(resolvedClass));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one last improvement to this line. previously was comparing strings

Assert.assertTrue(originalDescriptor.equals(newDescriptor));

- Class.componentType
- Class.describeConstable
- Class.descriptorString
- Class arrayType

Signed-off-by: Theresa Mammarella <[email protected]>
@DanHeidinga
Copy link
Member

Jenkins test sanity zlinux jdk12

@theresa-m
Copy link
Contributor Author

failing tests are related to #4661

@DanHeidinga
Copy link
Member

Same known failures - com.ibm.j9.jsr292.api.MethodHandleAPI_defineClass.test_defineClass_ClassBytes_CorruptedArray

@DanHeidinga DanHeidinga merged commit 1440bcf into eclipse-openj9:master Feb 22, 2019
@theresa-m theresa-m deleted the jep334_class branch February 25, 2019 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants