RFR: 8358772: Template-Framework Library: Primitive Types
Manuel Hässig
mhaessig at openjdk.org
Thu Jun 12 11:04:29 UTC 2025
On Fri, 6 Jun 2025 13:25:48 GMT, Emanuel Peter <epeter at openjdk.org> wrote:
> I would like to add primitive type support to the template framework library.
>
> In follow-up work, we will use these types in random expression generation - but they can also already be useful on their own now.
>
> I encountered an issue with some methods that return `Token` from the `TemplateFramework`, such as `Hook.insert` and `addDataName`. Since `Token` was package private, this class could not be used in some places where automatic type inference is required. I now refactored the code, so that the `Token` is just an empty interface, and all the methods are moved to a separate class `TokenParser`.
>
> Original experiments from here: https://github.com/openjdk/jdk/pull/23418
Another great addition to the Template Framework! Thank you for your continued effort, @eme64.
The broad strokes look good to me, but I have some remarks about a few details.
test/hotspot/jtreg/compiler/lib/template_framework/library/CodeGenerationDataNameType.java line 35:
> 33: * additional functionality for code generation. These types with their extended
> 34: * functionality can be used with many other code generation facilities in the
> 35: * lbrary, such as generating random {@code Expression}s.
Suggestion:
* library, such as generating random {@code Expression}s.
Typo nit
test/hotspot/jtreg/compiler/lib/template_framework/library/PrimitiveType.java line 71:
> 69: @Override
> 70: public boolean isSubtypeOf(DataName.Type other) {
> 71: return (other instanceof PrimitiveType pt) && pt.kind == kind;
Perhaps it would be useful to implement the primitive type subtyping rules from [JLS §4.10.1](https://docs.oracle.com/javase/specs/jls/se24/html/jls-4.html#jls-4.10.1). I can imagine that it might help generating more diverse programs with random variables of random primitive types. That might help with fuzzing IGVN optimizations on ranges?
test/hotspot/jtreg/compiler/lib/template_framework/library/PrimitiveType.java line 148:
> 146: * @return true iff the type is a floating type.
> 147: */
> 148: public boolean isFloating() {
Suggestion:
/**
* Indicates if the type is a floating point type.
*
* @return true iff the type is a floating point type.
*/
public boolean isFloating() {
Feel free to ignore: I would have called this `isFp()` or something like that, because my brain associates "floating" by itself as someting that is not pinned in place.
test/hotspot/jtreg/testlibrary_tests/template_framework/examples/TestPrimitiveTypes.java line 73:
> 71:
> 72: // p.xyz.InnerTest.main();
> 73: comp.invoke("p.xyz.InnerTest", "main", new Object[] {});
Personally, I would remove the comments here, since this is not a tutorial about the compile framework and the code is self-explanatory (the methods match the comments pretty well).
test/hotspot/jtreg/testlibrary_tests/template_framework/examples/TestPrimitiveTypes.java line 76:
> 74: }
> 75:
> 76: // Generate a source Java file as String
Suggestion:
// Generate a Java source file as String
This way it's consistent with the comments above.
-------------
Changes requested by mhaessig (Author).
PR Review: https://git.openjdk.org/jdk/pull/25672#pullrequestreview-2920480403
PR Review Comment: https://git.openjdk.org/jdk/pull/25672#discussion_r2142310785
PR Review Comment: https://git.openjdk.org/jdk/pull/25672#discussion_r2142329195
PR Review Comment: https://git.openjdk.org/jdk/pull/25672#discussion_r2142341594
PR Review Comment: https://git.openjdk.org/jdk/pull/25672#discussion_r2142358396
PR Review Comment: https://git.openjdk.org/jdk/pull/25672#discussion_r2142345363
More information about the hotspot-compiler-dev
mailing list