RFR: 8344942: Template-Based Testing Framework [v61]
Emanuel Peter
epeter at openjdk.org
Sun Jun 1 06:02:05 UTC 2025
On Sun, 1 Jun 2025 05:42:37 GMT, Emanuel Peter <epeter at openjdk.org> wrote:
>> The `nextTemplateFrameId` starts at zero, and is incremented for every Template instantiation.
>> The `templateClass` has `nextTemplateFrameId=1`. If there was any use of `$`, it would append `_1`.
>> For `template1.asToken(1)` we have `nextTemplateFrameId=2` -> produces the `var_2`.
>> Generally, the API does not make any guarantees about what id we give, it is just unique.
>>
>> Is that ok for you?
>
> Ah, I guess the comment above talks about `var_1, var_2 ...` hmm. I suppose I can add another comment for that in the test code.
Wrote this:
255 var templateClass = Template.make(() -> body(
+ 256 // The Template Framework API only guarantees that every Template use
+ 257 // has a unique ID. When using the Templates, all we need is that
+ 258 // variables from different Template uses do not conflict. But it can
+ 259 // be helpful to understand how the IDs are produced. The implementation
+ 260 // simply gives the first Template use the ID=1, and increments from there.
+ 261 //
+ 262 // In this example, the templateClass is the first Template use, and
+ 263 // has ID=1. We never use a dollar replacement here, so the code will
+ 264 // not show any "_1".
265 """
266 package p.xyz;
267
268 public class InnerTest3 {
269 public static void main() {
270 """,
+ 271 // Second Template use: ID=2 -> var_2
272 template1.asToken(1),
+ 273 // Third Template use: ID=3 -> var_3
274 template1.asToken(7),
+ 275 // Fourth Template use with template2, no use of dollar, so
+ 276 // no "_4" shows up in the generated code. Internally, it
+ 277 // calls template1, shich is the fifth Template use, with
+ 278 // ID = 5 -> var_5
279 template2.asToken(2),
+ 280 // Sixth and Seventh Template use -> var_7
281 template2.asToken(5),
+ 282 // Eighth Template use with template4 -> var_8.
+ 283 // Ninth Template use with internal call to template3,
+ 284 // The local "$var" turns to "var_9", but the Template
+ 285 // argument captured value = "var_8" from the outer
+ 286 // template use of $("var").
287 template4.asToken(),
288 """
289 }
290 }
291 """
292 ));
293
294 // Render templateClass to String.
295 return templateClass.render();
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/24217#discussion_r2118771773
More information about the hotspot-compiler-dev
mailing list