RFR: 8367531: Template Framework: use scopes and tokens instead of misbehaving immediate-return-queries [v33]
Emanuel Peter
epeter at openjdk.org
Thu Nov 20 09:33:38 UTC 2025
On Tue, 18 Nov 2025 08:30:48 GMT, Emanuel Peter <epeter at openjdk.org> wrote:
>> I got some feedback from users of the Template Framework, especially @galderz . And personally, I already was slightly unsatisfied by some of the issues described below, but did not expect it to be as bad as it is.
>>
>> So I'm sorry, but I think we need to do a significant re-design. It is now still early enough, and only trivial changes are required for the "real" uses of the framework. Only the framework internal tests require significant changes.
>>
>> Many thanks to @galderz for trying out the framework, and reporting the issues. And thanks to @chhagedorn for spending a few hours in an offline meeting discussing the issue.
>>
>> **Major issue with Template Framework: lambda vs token order**
>>
>> The template rendering involves some state, such as keeping track of hashtag replacements, names and fuel cost.
>> Some methods have side-effects (`addDataName`, `let`, ...) and others are simple queries (`sample`, ...).
>> Sadly, the first version of the template framework was not very consistent, and created tokens (deferred evaluation, during token evaluation) for some, and for others it queried the state and returned the result immediately (during lambda execution). One nasty consequence is that an immediately returning query can "float" above a state affecting token. For example, `addDataName` generated a token (so that we know if it is to be added for the template frame or a hook anchoring frame), but answered sampling queries immediately (because that means we can use the returned value immediately and make decisions based on it immediately, which is nice). Looking at the example below, this had the confusing result that `addDataName` only generates a token at first, then `sample` does not have that name available yet, and only later during token evaluation is the name actually added.
>>
>> var testTemplate = Template.make(() -> body(
>> ...
>> addDataName("name", someType, MUTABLE),
>> let("name", dataNames(MUTABLE).exactOf(someType).sample().name()),
>> ...
>> ));
>>
>>
>> **Two possible solutions: all-in on lambda execution or all-in on tokens**
>>
>> First, I thought I want to go all-in on lambda execution, and have everything have immediate effect and return results immediately. This would have the nice effect that the user feels like they are directly in control of the execution order. But I did not find a good way without exposing too many internals to the user, or getting rid of the nice "token lists" we currently have inside Templates (the...
>
> Emanuel Peter has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains 142 additional commits since the last revision:
>
> - Merge branch 'master' into JDK-8367531-fix-addDataName
> - fix up documentation for Roberto
> - Apply suggestions from code review
>
> Co-authored-by: Christian Hagedorn <christian.hagedorn at oracle.com>
> - Apply suggestions from code review
>
> Co-authored-by: Roberto Castañeda Lozano <robcasloz at users.noreply.github.com>
> - Apply suggestions from code review
>
> Co-authored-by: Roberto Castañeda Lozano <robcasloz at users.noreply.github.com>
> - document hashtag locality for Roberto
> - inflate abreviations to full names
> - better documentation, inspired by Christian
> - Update test/hotspot/jtreg/compiler/lib/template_framework/ScopeToken.java
>
> Co-authored-by: Christian Hagedorn <christian.hagedorn at oracle.com>
> - Update test/hotspot/jtreg/compiler/lib/template_framework/Template.java
>
> Co-authored-by: Christian Hagedorn <christian.hagedorn at oracle.com>
> - ... and 132 more: https://git.openjdk.org/jdk/compare/4f1dcaf7...79377438
Testing was very slow, but finally completed :)
Thanks again to all the reviewers @chhagedorn @mhaessig @robcasloz !
And also to @galderz for running taking the time to work with the Framework, and reporting difficulties. That gave me the motivation to fix things :)
-------------
PR Comment: https://git.openjdk.org/jdk/pull/27255#issuecomment-3556861771
More information about the hotspot-compiler-dev
mailing list