Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
d21a8aa
JDK-8344942
eme64 Mar 25, 2025
8cdf16a
fix whitespace
eme64 Mar 25, 2025
8b6d7ae
whitespace
eme64 Mar 25, 2025
0263454
whitespace
eme64 Mar 25, 2025
a10d6fa
fix tests
eme64 Mar 25, 2025
ededf45
Merge branch 'master' into JDK-8344942-TemplateFramework-v3
eme64 Mar 27, 2025
e5796bf
Merge branch 'master' into JDK-8344942-TemplateFramework-v3
eme64 Mar 31, 2025
85bcc6e
Apply suggestions from code review
eme64 Mar 31, 2025
5e501e9
move library
eme64 Mar 31, 2025
b7e0f2b
manual merge
eme64 Mar 31, 2025
fa69d6d
fix hashtag
eme64 Mar 31, 2025
7707980
For Christian: example and more intro
eme64 Mar 31, 2025
be1c0ee
typo
eme64 Apr 1, 2025
084fe12
Suggestions by Christian
eme64 May 7, 2025
c4e5184
Whitespace
eme64 May 7, 2025
fae7ced
Merge branch 'master' into JDK-8344942-TemplateFramework-v3
eme64 May 7, 2025
9c95f6a
3 more suggestions by Christian
eme64 May 7, 2025
f689a90
More suggestions by Christian
eme64 May 7, 2025
b161b66
More for Christian
eme64 May 7, 2025
f09c536
improve comment
eme64 May 12, 2025
f240f9a
Refactoring TemplateWithArgs -> Filled/Unfilled Template
eme64 May 12, 2025
78d3249
fix links to Template
eme64 May 12, 2025
0871fcd
more documentation fixes
eme64 May 12, 2025
95d44f3
Review suggestions by Roberto
eme64 May 14, 2025
e09b8a1
Apply suggestions from code review
eme64 May 14, 2025
ec52074
another idea from Manuel
eme64 May 14, 2025
102c307
Apply suggestions from code review
eme64 May 14, 2025
63d0326
Apply suggestions from code review
eme64 May 14, 2025
737e906
more small fixes
eme64 May 14, 2025
725f617
Merge branch 'JDK-8344942-TemplateFramework-v3' of https://github.com…
eme64 May 14, 2025
ed1eead
more applied suggestions
eme64 May 14, 2025
3bc12ca
The big refactoring
eme64 May 15, 2025
61b2119
fix small things
eme64 May 15, 2025
a4efe45
fix typo
eme64 May 15, 2025
76cbd83
Manuel: link Strings consistently
eme64 May 15, 2025
0416dd7
Apply suggestions from code review
eme64 May 16, 2025
6661425
fix return comments for Manuel
eme64 May 16, 2025
8652421
Elaborate why there is only one Renderer
eme64 May 16, 2025
68f87cd
apply offline suggestions by Christian
eme64 May 16, 2025
f19fe2d
Apply suggestions from code review
eme64 May 16, 2025
6b83ea3
Apply suggestions from code review
eme64 May 16, 2025
f655f13
fix up review suggestions
eme64 May 16, 2025
aac9f54
more offline suggestions by Christian
eme64 May 16, 2025
3637038
Name test with subtyping
eme64 May 16, 2025
f504775
Apply suggestions from code review
eme64 May 16, 2025
c9c484c
Update test/hotspot/jtreg/compiler/lib/template_framework/Token.java
eme64 May 16, 2025
398a7c1
fix to addName
eme64 May 16, 2025
3a7493c
fix whitespaces from applied suggestions
eme64 May 16, 2025
cc60064
improve tutorial for Names part1
eme64 May 16, 2025
df3ff71
improve Name tutorial part2
eme64 May 16, 2025
fcbd76a
tutorial with mutable and subtyping
eme64 May 16, 2025
aedc509
Offline review
eme64 May 19, 2025
ec7aab9
DataName / StructuralName refactoring
eme64 May 20, 2025
8e779f4
Update test/hotspot/jtreg/compiler/lib/template_framework/library/Hoo…
eme64 May 20, 2025
bb61983
Update test/hotspot/jtreg/compiler/lib/template_framework/Template.java
eme64 May 20, 2025
05e9683
Update test/hotspot/jtreg/compiler/lib/template_framework/Template.java
eme64 May 20, 2025
f9457b4
more for Roberto
eme64 May 20, 2025
ab4f358
Hook.set -> Hook.anchor
eme64 May 20, 2025
880908a
test for small and large weights -> expect exception
eme64 May 20, 2025
7c40075
more tests for StructuralName
eme64 May 20, 2025
8d3318d
Add verification to avoid duplicate names
eme64 May 20, 2025
dc70aed
tests for name duplication
eme64 May 21, 2025
4206d64
generateWithHashtagAndDollarReplacements2
eme64 May 21, 2025
b4193e8
verify hashtag and dollar names, add tests
eme64 May 21, 2025
4363a92
implement brackets for dollar and hashtag
eme64 May 21, 2025
28b4eaa
document syntax of dollar and hashtag
eme64 May 21, 2025
cb17dfb
improve documentation in TestTemplate.java
eme64 May 21, 2025
3705c85
generateWithDataNamesAndScopes tutorial
eme64 May 21, 2025
62d4c49
move order in tutorial
eme64 May 21, 2025
e85fa9a
Apply suggestions from code review
eme64 May 22, 2025
5c27763
remove comment line for Roberto
eme64 May 22, 2025
bd79554
Apply suggestions from code review
eme64 May 22, 2025
e7827a0
Apply suggestions from code review
eme64 May 23, 2025
e380a15
Update test/hotspot/jtreg/testlibrary_tests/template_framework/exampl…
eme64 May 23, 2025
8892a3a
static final
eme64 May 23, 2025
8acc300
more from Manuel
eme64 May 23, 2025
341e602
move verification
eme64 May 23, 2025
3c4e1ce
Merge branch 'JDK-8344942-TemplateFramework-v3' of https://github.com…
eme64 May 23, 2025
981330d
Apply suggestions from code review
eme64 May 31, 2025
724e0d8
Apply suggestions from code review
eme64 May 31, 2025
b6dc63c
Update test/hotspot/jtreg/testlibrary_tests/template_framework/exampl…
eme64 May 31, 2025
4624d30
more from Christian
eme64 May 31, 2025
03c9514
rename template arguments
eme64 May 31, 2025
2d18fca
good practice
eme64 May 31, 2025
ea2bb65
more suggestions applied
eme64 May 31, 2025
68b45b1
more improvements
eme64 Jun 1, 2025
ab20c21
more fixes from Christian
eme64 Jun 1, 2025
ccc132b
wip refactor parsing dollar and hashtag
eme64 Jun 1, 2025
21d3f50
dollar and hashtag parsing validatiaon
eme64 Jun 2, 2025
6354c8b
validation tests
eme64 Jun 2, 2025
cb7037e
Merge branch 'master' into JDK-8344942-TemplateFramework-v3
eme64 Jun 2, 2025
d8f6625
Apply suggestions from code review
eme64 Jun 2, 2025
30059e6
Apply suggestions from code review
eme64 Jun 2, 2025
310d7d8
more for Christian
eme64 Jun 3, 2025
455cd43
remove unnecessary Type.name()
eme64 Jun 3, 2025
fa3d086
rename View -> FilteredSet
eme64 Jun 3, 2025
6ef7127
add some hashes
eme64 Jun 3, 2025
3efb9fc
Apply suggestions from code review
eme64 Jun 3, 2025
3f0beb4
more for Christian
eme64 Jun 3, 2025
7292387
fix whitespaces from applied suggestion
eme64 Jun 3, 2025
0ec0949
Apply suggestions from code review
eme64 Jun 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package compiler.lib.template_framework;

record AddNameToken(Name name) implements Token {}
51 changes: 51 additions & 0 deletions test/hotspot/jtreg/compiler/lib/template_framework/Code.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package compiler.lib.template_framework;

import java.util.List;

/**
* This class collects code, i.e. {@link String}s or {@link List}s of {@link String}s.
* All the {@link String}s are later collected in a {@link StringBuilder}. If we used a {@link StringBuilder}
* directly to collect the {@link String}s, we could not as easily insert code at an "earlier" position, i.e.
* reaching out to a {@link Hook#anchor}.
*/
sealed interface Code permits Code.Token, Code.CodeList {

record Token(String s) implements Code {
@Override
public void renderTo(StringBuilder builder) {
builder.append(s);
}
}

record CodeList(List<Code> list) implements Code {
@Override
public void renderTo(StringBuilder builder) {
list.forEach(code -> code.renderTo(builder));
}
}

void renderTo(StringBuilder builder);
}
156 changes: 156 additions & 0 deletions test/hotspot/jtreg/compiler/lib/template_framework/CodeFrame.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/*
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package compiler.lib.template_framework;

import java.util.HashMap;
import java.util.Map;
import java.util.ArrayList;
import java.util.List;

/**
* The {@link CodeFrame} represents a frame (i.e. scope) of code, appending {@link Code} to the {@code 'codeList'}
* as {@link Token}s are rendered, and adding names to the {@link NameSet}s with {@link Template#addStructuralName}/
* {@link Template#addDataName}. {@link Hook}s can be added to a frame, which allows code to be inserted at that
* location later. When a {@link Hook} is {@link Hook#anchor}ed, it separates the Template into an outer and inner
* {@link CodeFrame}, ensuring that names that are added inside the inner frame are only available inside that frame.
*
* <p>
* On the other hand, each {@link TemplateFrame} represents the frame (or scope) of exactly one use of a
* Template.
*
* <p>
* For simple Template nesting, the {@link CodeFrame}s and {@link TemplateFrame}s overlap exactly.
* However, when using {@link Hook#insert}, we simply nest {@link TemplateFrame}s, going further "in",
* but we jump to an outer {@link CodeFrame}, ensuring that we insert {@link Code} at the outer frame,
* and operating on the names of the outer frame. Once the {@link Hook#insert}ion is complete, we jump
* back to the caller {@link TemplateFrame} and {@link CodeFrame}.
*/
class CodeFrame {
public final CodeFrame parent;
private final List<Code> codeList = new ArrayList<>();
private final Map<Hook, Code.CodeList> hookCodeLists = new HashMap<>();

/**
* The {@link NameSet} is used for variable and fields etc.
*/
private final NameSet names;

private CodeFrame(CodeFrame parent, boolean isTransparentForNames) {
this.parent = parent;
if (parent == null) {
// NameSet without any parent.
this.names = new NameSet(null);
} else if (isTransparentForNames) {
// We use the same NameSet as the parent - makes it transparent.
this.names = parent.names;
} else {
// New NameSet, to make sure we have a nested scope for the names.
this.names = new NameSet(parent.names);
}
}

/**
* Creates a base frame, which has no {@link #parent}.
*/
public static CodeFrame makeBase() {
return new CodeFrame(null, false);
}

/**
* Creates a normal frame, which has a {@link #parent} and which defines an inner
* {@link NameSet}, for the names that are generated inside this frame. Once this
* frame is exited, the name from inside this frame are not available anymore.
*/
public static CodeFrame make(CodeFrame parent) {
return new CodeFrame(parent, false);
}

/**
* Creates a special frame, which has a {@link #parent} but uses the {@link NameSet}
* from the parent frame, allowing {@link Template#addDataName}/
* {@link Template#addStructuralName} to persist in the outer frame when the current frame
* is exited. This is necessary for {@link Hook#insert}, where we would possibly want to
* make field or variable definitions during the insertion that are not just local to the
* insertion but affect the {@link CodeFrame} that we {@link Hook#anchor} earlier and are
* now {@link Hook#insert}ing into.
*/
public static CodeFrame makeTransparentForNames(CodeFrame parent) {
return new CodeFrame(parent, true);
}

void addString(String s) {
codeList.add(new Code.Token(s));
}

void addCode(Code code) {
codeList.add(code);
}

void addHook(Hook hook) {
if (hasHook(hook)) {
// This should never happen, as we add a dedicated CodeFrame for each hook.
throw new RuntimeException("Internal error: Duplicate Hook in CodeFrame: " + hook.name());
}
hookCodeLists.put(hook, new Code.CodeList(new ArrayList<>()));
}

private boolean hasHook(Hook hook) {
return hookCodeLists.containsKey(hook);
}

CodeFrame codeFrameForHook(Hook hook) {
CodeFrame current = this;
while (current != null) {
if (current.hasHook(hook)) {
return current;
}
current = current.parent;
}
return null;
}

void addName(Name name) {
names.add(name);
}

Name sampleName(NameSet.Predicate predicate) {
return names.sample(predicate);
}

int countNames(NameSet.Predicate predicate) {
return names.count(predicate);
}

boolean hasAnyNames(NameSet.Predicate predicate) {
return names.hasAny(predicate);
}

List<Name> listNames(NameSet.Predicate predicate) {
return names.toList(predicate);
}

Code getCode() {
return new Code.CodeList(codeList);
}
}
Loading