RFR: 8344942: Template-Based Testing Framework [v61]
Christian Hagedorn
chagedorn at openjdk.org
Mon Jun 2 12:12:11 UTC 2025
On Sun, 1 Jun 2025 15:56:18 GMT, Emanuel Peter <epeter at openjdk.org> wrote:
>> Another question which is not evidently clear by following the examples: Can and should (not) you use the same hook inside the hook itself, i.e.:
>>
>> Hooks.CLASS_HOOK.anchor(
>> Hooks.CLASS_HOOK.anchor(
>> // ...
>>
>> This is probably not done on purpose but such a situation could arise when nesting more templates and suddenly one anchors the same hook again?
>
> I extended the explanations:
>
> ~ 397 // We saw the use of custom hooks above, but now we look at the use of CLASS_HOOK and METHOD_HOOK.
> ~ 398 // By convention, we use the CLASS_HOOK for class scopes, and METHOD_HOOK for method scopes.
> + 399 // Whenever we open a class scope, we should anchor a CLASS_HOOK for that scope, and whenever we
> + 400 // open a method, we should anchor a METHOD_HOOK. Conversely, this allows us to check if we are
> + 401 // inside a class or method scope by querying "isAnchored". This convention helps us when building
> + 402 // a large library of Templates. But if you are writing your own self-contained set of Templates,
> + 403 // you do not have to follow this convention.
> + 404 //
> + 405 // Hooks are "re-entrant", that is we can anchor the same hook inside a scope that we already
> + 406 // anchored it previously. The "Hook.insert" always goes to the innermost anchoring of that
> + 407 // hook. There are cases where "re-entrant" Hooks are helpful such as nested classes, where
> + 408 // there is a class scope inside another class scope. Similarly, we can nest lambda bodies
> + 409 // inside method bodies, so also METHOD_HOOK can be used in such a "re-entrant" way.
>
>
> We could consider having both "re-entrant" and "non-re-entrant" Hooks. But I'm not yet convinced it is a very useful feature. Sure, there could be some confusion with nested hooks. But I think that confusion to code generation, because we can also nest class and method/lambda scopes.
>
> What do you think?
The updated explanation is very good of making clear when we could/want to have nested hooks.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/24217#discussion_r2120955442
More information about the hotspot-compiler-dev
mailing list