RFR: 8359412: Template-Framework Library: Operations and Expressions
Emanuel Peter
epeter at openjdk.org
Thu Sep 18 06:48:36 UTC 2025
On Wed, 17 Sep 2025 11:10:09 GMT, Manuel Hässig <mhaessig at openjdk.org> wrote:
>> Impliementing ideas from original draft PR: https://github.com/openjdk/jdk/pull/23418 ([Exceptions](https://github.com/openjdk/jdk/pull/23418/files#diff-77e7db8cc0c5e02786e1c993362f98fabe219042eb342fdaffc09fd11380259dR41), [ExpressionFuzzer](https://github.com/openjdk/jdk/pull/23418/files#diff-01844ca5cb007f5eab5fa4195f2f1378d4e7c64ba477fba64626c98ff4054038R66)).
>>
>> Specifically, I'm extending the Template Library with `Expression`s, and lists of `Operations` (some basic Expressions). These Expressions can easily be nested and then filled with arguments, and applied in a `Template`.
>>
>> Details, in **order you should review**:
>> - `Operations.java`: maps lots of primitive operators as Expressions.
>> - `Expression.java`: the fundamental engine behind Expressions.
>> - `examples/TestExpressions.java`: basic example using Expressions, filling them with random constants.
>> - `tests/TestExpression.java`: correctness test of Expression machinery.
>> - `compiler/igvn/ExpressionFuzzer.java`: expression fuzzer for primitive type expressions, including input range/bits constraints and output range/bits verification.
>> - `PrimitiveType.java`: added `LibraryRNG` facility. We already had `type.con()` which gave us random constants. But we also want to have `type.callLibraryRNG()` so that we can insert a call to a random number generator of the corresponding primitive type. I use this facility in the `ExpressionFuzzer.java` to generate random arguments for the expressions.
>> - `examples/TestPrimitiveTypes.java`: added a `LibraryRNG` example, that tests that has a weak test for randomness: we should have at least 2 different value in 1000 calls.
>>
>> If the reviewers absolutely insist, I could split out `LibraryRNG` into a separate RFE. But it's really not that much code, and has direct use in the `Expression` examples.
>>
>> **Future Work**:
>> - Use `Expression`s in a loop over arrays / MemorySegment: fuzz auto-vectorization.
>> - Use `Expression`s to model more operations:
>> - `Vector API`, more arithmetic operations like from `Math` classes etc.
>> - Ensure that the constraints / checksum mechanic in `compiler/igvn/ExpressionFuzzer.java` work, using IR rules. We may even need to add new IGVN optimizations. Add unsigned constraints.
>> - Find a way to delay IGVN optimizations to test worklist notification: For example, we could add a new testing operator call `TestUtils.delay(x) -> x`, which is intrinsified as some new `DelayNode` that in normal circumstances just fol...
>
> test/hotspot/jtreg/compiler/lib/template_framework/library/Expression.java line 358:
>
>> 356: tokens.add(arguments.get(i));
>> 357: }
>> 358: tokens.add(strings.get(strings.size()-1));
>
> Suggestion:
>
> tokens.add(strings.getLast());
>
> A wee bit easier to read.
Did not know this was a thing, nice :)
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/26885#discussion_r2357700924
More information about the hotspot-compiler-dev
mailing list