-
Notifications
You must be signed in to change notification settings - Fork 729
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
Conversation
523fa4d
to
0f9b798
Compare
0f9b798
to
18686bf
Compare
18686bf
to
8c6327c
Compare
@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:
|
ce37313
to
5b73f6e
Compare
fixing error in testng.xml |
9290593
to
a84e8a0
Compare
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 |
There was a problem hiding this 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.
85c48a1
to
e754615
Compare
Class implements |
extra implements are included here #4030 |
* not represent an array. | ||
*/ | ||
public Class<?> componentType() { | ||
return this.getComponentType(); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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)); | ||
} |
There was a problem hiding this comment.
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
e754615
to
504d2c9
Compare
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. |
There was a problem hiding this 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(); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
504d2c9
to
6f7659f
Compare
Jenkins compile win jdk11 |
Jenkins test sanity zlinux jdk12 |
e87f7f1
to
6f7659f
Compare
sorry that push was a mistake :( |
@theresa-m Is this branch back to being ready to PR test and merge? |
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 |
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 |
f8fa669
to
fc4a0c0
Compare
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)); |
There was a problem hiding this comment.
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));
fc4a0c0
to
722a0ce
Compare
- Class.componentType - Class.describeConstable - Class.descriptorString - Class arrayType Signed-off-by: Theresa Mammarella <[email protected]>
722a0ce
to
e416518
Compare
Jenkins test sanity zlinux jdk12 |
failing tests are related to #4661 |
Same known failures - |
Depends on (see #4195):
Signed-off-by: Theresa Mammarella [email protected]