Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
171 commits
Select commit Hold shift + click to select a range
687bec4
JDK-8344942
eme64 Dec 2, 2024
82347d8
stub
eme64 Dec 2, 2024
991c884
experiment with finding local variable
eme64 Dec 2, 2024
4a876e5
parse local variables and replacements
eme64 Dec 2, 2024
bbf8960
improve parsing
eme64 Dec 3, 2024
f17ccb8
some early stubs
eme64 Dec 3, 2024
57a4437
renaming
eme64 Dec 3, 2024
5a5588f
fix syntax issues
eme64 Dec 3, 2024
8cb212d
add ClassScope
eme64 Dec 3, 2024
23172b2
adding code, newline, indentation
eme64 Dec 3, 2024
ad460f1
add exception
eme64 Dec 3, 2024
1f5a755
nicely split templated and nonTemplated
eme64 Dec 3, 2024
4d46a52
start handling templated
eme64 Dec 3, 2024
a899a2a
parse replacement
eme64 Dec 3, 2024
21641af
wip parse replacement
eme64 Dec 3, 2024
ba7e120
parse key-value pair for generator
eme64 Dec 3, 2024
f092ee9
stub for generator call
eme64 Dec 3, 2024
323653d
stub of code stream
eme64 Dec 3, 2024
b7f980c
CodeStream toString
eme64 Dec 3, 2024
7a9e63a
handle replacement repeats
eme64 Dec 3, 2024
a019e65
prepare for recursive generator call
eme64 Dec 3, 2024
c68ffb7
add code generator library
eme64 Dec 3, 2024
0e4da3a
first code generator with lambda
eme64 Dec 3, 2024
4ce33f9
comments
eme64 Dec 4, 2024
f598830
refactor scope to a class
eme64 Dec 4, 2024
b413f4e
class -> base scope refactor
eme64 Dec 4, 2024
e42eb39
stub for SelectorCodeGenerator
eme64 Dec 4, 2024
1dcf3c9
choose
eme64 Dec 4, 2024
73860c0
fuel for nesting
eme64 Dec 4, 2024
5a2f071
refactor indentation
eme64 Dec 4, 2024
d3c734d
improve indentation handling
eme64 Dec 4, 2024
713d157
add split
eme64 Dec 4, 2024
72988ca
programmatic, and start on variables
eme64 Dec 4, 2024
2ff5845
variable sampling wip
eme64 Dec 4, 2024
e1744b5
wip adding variables
eme64 Dec 4, 2024
823a22c
add local variables
eme64 Dec 5, 2024
3858a3a
variable sampling works - not yet mutability
eme64 Dec 5, 2024
8da4f83
improve templates
eme64 Dec 5, 2024
83ce5a8
declare as static
eme64 Dec 5, 2024
27afa77
variable load/store
eme64 Dec 5, 2024
6e9ffb2
check empty variable name
eme64 Dec 5, 2024
51a0704
more ideas
eme64 Dec 5, 2024
6e81141
parse scope open/close
eme64 Dec 5, 2024
fc2a12b
add stub for method and class scope
eme64 Dec 5, 2024
9098042
inject class/method scopes in template
eme64 Dec 5, 2024
fee1a5b
idea
eme64 Dec 5, 2024
6b3411e
refactor indentation a little
eme64 Dec 6, 2024
ac9b120
refactoring and wip on dispatch
eme64 Dec 6, 2024
820e039
impl dispatch
eme64 Dec 6, 2024
c95bc3b
rm totalVariables optimization - won't work with dispatch/prepend
eme64 Dec 6, 2024
a78e27c
refactor to be able to pass param and variable names
eme64 Dec 6, 2024
835b0aa
pass parameters and variable names as parameters
eme64 Dec 6, 2024
e90bd64
update ideas
eme64 Dec 6, 2024
da9b540
fix order of dispatched blocks
eme64 Dec 6, 2024
091c6df
add variables to class and method scope
eme64 Dec 6, 2024
61dbd3b
wip scope tracing
eme64 Dec 8, 2024
0b9d215
set debug context
eme64 Dec 8, 2024
ce4c55b
more tracing for scopes
eme64 Dec 9, 2024
f4035de
better int example, and proper int_con impl
eme64 Dec 9, 2024
d4202f1
scope for parameters get
eme64 Dec 9, 2024
e6329bc
verify parameter list
eme64 Dec 9, 2024
fad1e2c
refactor finding method/class scope
eme64 Dec 9, 2024
0f9ca93
move comments
eme64 Dec 9, 2024
9cb5678
simplify single template instantiation
eme64 Dec 9, 2024
8cd9543
parameter test
eme64 Dec 9, 2024
d5a93af
TestInstantiationOfManyTests wip
eme64 Dec 9, 2024
5a4016d
parameters for TestClassInstantiator
eme64 Dec 9, 2024
f4d07e5
list of parameters for cross-product
eme64 Dec 9, 2024
485c737
refactor parameters cross product
eme64 Dec 10, 2024
cbfd5d1
instantiate templates selectively
eme64 Dec 10, 2024
a883ff1
shared replacement state for bundled templates
eme64 Dec 10, 2024
a58ae44
repeat instantiation
eme64 Dec 10, 2024
2a164f6
custom library example + some library refactoring
eme64 Dec 10, 2024
40f4788
repeat wip
eme64 Dec 10, 2024
d4e106e
instantiator for CodeGenerator, and working repeat
eme64 Dec 10, 2024
638f5b9
cleanup
eme64 Dec 10, 2024
cfd1a4f
create base klass
eme64 Dec 10, 2024
4769110
pass replacements as arguments/parameters
eme64 Dec 10, 2024
f027cba
generate klasses and subklasses
eme64 Dec 10, 2024
a9554e1
add fields
eme64 Dec 11, 2024
5008137
allocate from random class and set random field
eme64 Dec 11, 2024
71306ea
TestListOfOperators.java
eme64 Dec 11, 2024
5ecaa76
update ideas / todos
eme64 Dec 11, 2024
d0ebd25
test generators
eme64 Dec 11, 2024
8dc7020
fill and special ints
eme64 Dec 11, 2024
d705709
mixed int generator
eme64 Dec 11, 2024
0117bda
add long generators
eme64 Dec 12, 2024
485d748
first parts of verify
eme64 Dec 12, 2024
9236886
verify all array types and native memory segment
eme64 Dec 12, 2024
d383c20
compare object array, i.e. recursive array
eme64 Dec 12, 2024
65edcf4
recursive refactor for Verify
eme64 Dec 12, 2024
47de91e
pass context refactoring
eme64 Dec 12, 2024
ac0508e
unbox verify
eme64 Dec 12, 2024
81f2370
compact test
eme64 Dec 12, 2024
637aaae
non-equal tests
eme64 Dec 12, 2024
79048ff
cleanup
eme64 Dec 12, 2024
29a904c
verify example
eme64 Dec 12, 2024
34977f5
initialize test values
eme64 Dec 12, 2024
ef8d8a5
rm files of other PRs
eme64 Dec 12, 2024
e7a13fb
update ideas
eme64 Dec 13, 2024
c39c302
some cleanup
eme64 Dec 13, 2024
99a73ec
refactor name and fuel cost
eme64 Dec 13, 2024
24246dd
more documentation
eme64 Dec 13, 2024
57c83df
renaming
eme64 Dec 13, 2024
f27b029
more docs
eme64 Dec 13, 2024
6f1f0ad
even more documentation
eme64 Dec 13, 2024
c65e4a3
documentation for exception
eme64 Dec 13, 2024
a0f7050
desc for Template
eme64 Dec 16, 2024
0423cd0
better documentation
eme64 Dec 16, 2024
d59da0c
more docs for template
eme64 Dec 16, 2024
0b3a9a8
more documentation for selector
eme64 Dec 16, 2024
81ffd00
small refactor and more docs
eme64 Dec 16, 2024
9add152
even more docs
eme64 Dec 16, 2024
1a9d6fd
more docs for parameters
eme64 Dec 16, 2024
4f9db16
more docs and more final
eme64 Dec 16, 2024
57d5d38
more documentation
eme64 Dec 16, 2024
a79b846
even more docs
eme64 Dec 16, 2024
6276124
refactoring
eme64 Dec 16, 2024
2b0979c
readme stub
eme64 Dec 16, 2024
cae46cb
more readme v2
eme64 Dec 16, 2024
8c5d2e5
more links
eme64 Dec 16, 2024
b27489a
simple example for readme
eme64 Dec 16, 2024
3dcfa22
more readme
eme64 Dec 16, 2024
ecf2463
more docs
eme64 Dec 16, 2024
be8c24c
more docs
eme64 Dec 16, 2024
0c22a20
some basic testing for template
eme64 Dec 16, 2024
c8dbef6
more testing for template
eme64 Dec 16, 2024
8869945
extend testing more
eme64 Dec 16, 2024
5b3f959
custom library template instantiation
eme64 Dec 16, 2024
ac176be
add todo
eme64 Dec 16, 2024
6077472
add test for TestClassInstantiator
eme64 Dec 17, 2024
0da2a8a
test some first library calls
eme64 Dec 17, 2024
e393eb5
add dispatch test
eme64 Dec 18, 2024
e4a2bf6
add testClassInstantiatorAndDispatch
eme64 Dec 18, 2024
5c15ed3
cleanup library, convert TestWIP to TestRandomCode
eme64 Dec 18, 2024
ef856ed
small refactor
eme64 Dec 18, 2024
b911a93
testing choose
eme64 Dec 19, 2024
8e97043
test variable definition and sampling, refactor library a little for it
eme64 Dec 19, 2024
895219b
refactor def_var/field
eme64 Dec 19, 2024
dae124f
rename to add_var
eme64 Dec 19, 2024
3060a41
fix variable test
eme64 Dec 19, 2024
bdccc58
fix whitespace and rename code to method_code
eme64 Dec 19, 2024
8bcf8c6
temporarily add generators so we can already use them
eme64 Dec 20, 2024
c6b1a8c
refactor error messages for parameters.get and refactor int_con with …
eme64 Dec 20, 2024
1529784
refactor and more documentation
eme64 Dec 20, 2024
994999a
add testIntCon
eme64 Dec 20, 2024
b374e40
add testLongCon
eme64 Dec 20, 2024
4626282
TestRandomConstants add long test, need to add L to long_con
eme64 Dec 20, 2024
756d9ad
testFuel
eme64 Dec 20, 2024
5b4014f
move random code generation to the corresponding test
eme64 Dec 20, 2024
eaee3a0
loop example, must refactor local variable definition
eme64 Dec 20, 2024
b424fb0
some recursive call tests
eme64 Dec 20, 2024
1d78077
add test for sampling field
eme64 Dec 20, 2024
d2baed4
rename final -> immutable
eme64 Dec 20, 2024
ed46d8f
sample from mutable/immutable
eme64 Dec 20, 2024
899df4c
more random code
eme64 Dec 20, 2024
cdf4a77
bool random generator, and con method to dispatch to any type
eme64 Jan 3, 2025
9bee4db
Predicate for Selector
eme64 Jan 3, 2025
3230c85
rebalance and define var/fields
eme64 Jan 3, 2025
c9594dc
Merge branch 'master' into JDK-8344942-TemplateFramework
eme64 Jan 3, 2025
3e64b37
copyright 2025
eme64 Jan 3, 2025
6ad6204
stub of TestWithGeneratorsIRAndVerify.java
eme64 Jan 3, 2025
3529fcc
handle imports
eme64 Jan 3, 2025
f0a7a16
more code
eme64 Jan 3, 2025
1887594
rm old generators
eme64 Jan 13, 2025
ed4a1a1
new generators
eme64 Jan 13, 2025
3e5e2a1
fix tests for new genrators
eme64 Jan 13, 2025
d27abcc
improve IR test
eme64 Jan 14, 2025
abe64df
rm old generators
eme64 Jan 16, 2025
7a8b5d4
Merge branch 'master' into JDK-8344942-TemplateFramework
eme64 Jan 16, 2025
137d3f1
adapt to new Generators
eme64 Jan 16, 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
54 changes: 54 additions & 0 deletions test/hotspot/jtreg/compiler/lib/template_framework/BaseScope.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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;

/**
* {link BaseScope} is the outer-most scope, and determines the {@link CodeGeneratorLibrary} which is used.
*/
final class BaseScope extends Scope {
public static final int DEFAULT_FUEL = 50;
private final CodeGeneratorLibrary codeGeneratorLibrary;

public BaseScope(long fuel, CodeGeneratorLibrary codeGeneratorLibrary) {
super(null, fuel);
this.codeGeneratorLibrary = (codeGeneratorLibrary != null) ? codeGeneratorLibrary
: CodeGeneratorLibrary.standard();
}

public BaseScope(CodeGeneratorLibrary codeGeneratorLibrary) {
this(DEFAULT_FUEL, codeGeneratorLibrary);
};

@Override
public CodeGeneratorLibrary library() {
return codeGeneratorLibrary;
}

/**
* Collect all the generated code and return it as a String.
*/
public String toString() {
return stream.toString();
}
}
43 changes: 43 additions & 0 deletions test/hotspot/jtreg/compiler/lib/template_framework/ClassScope.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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;

/**
* The {@link ClassScope} sets the scope of a class body, i.e. after its opening bracked and before its
* closing bracket. This allows dispatching {@link CodeGenerator}s to the top of the class body, for
* example for field declarations, see {@link DispatchScope#dispatch}. In {@link Template}s, a
* {@link ClassScope} is opened with {@code #open(class)} and closed with {@code #close(class)}.
*/
final class ClassScope extends DispatchScope {

/**
* Create a new {@link MethodScope}.
*
* @param parent Parent scope or null if the new scope is an outermost scope.
* @param fuel Remaining fuel for recursive {@link CodeGenerator} instantiations.
*/
public ClassScope(Scope parent, long fuel) {
super(parent, fuel);
}
}
209 changes: 209 additions & 0 deletions test/hotspot/jtreg/compiler/lib/template_framework/CodeGenerator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
/*
* 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.Map;

/**
* A {@link CodeGenerator} is used to instantiate code into a scope. This instantiated code may be genrated recursively
* i.e. the {@link CodeGenerator} instantiation may recursively instantiate other {@link CodeGenerator}s.
*/
public sealed abstract class CodeGenerator permits Template, ProgrammaticCodeGenerator, SelectorCodeGenerator {

/**
* Every {@link CodeGenerator} must have an unique name. The name is used to find {@link CodeGenerator}s in the
* {@link CodeGeneratorLibrary}, and also in the {@link Scope} trace printed if the Template Framework encounters
* an error.
*/
public final String name;


/**
* The fuel cost indicates the approximate logarithmic execution cost of the code generated by the
* {@link CodeGenerator}. When CodeGenerators are called recursively, the fuel cost is subtracted from the
* remaining fuel of the {@link Scope}. Once the scope runs out of fuel, the recursion is supposed to stop.
*/
public final int fuelCost;

/**
* Create a new {@link CodeGenerator}.
*
* @param name Name of the generator, can be used for lookup in the
* {@link CodeGeneratorLibrary} if the {@link Template}
* is added to a library.
* @param fuelCost The {@link fuelCost} for the {@link CodeGenerator}.
*/
CodeGenerator(String name, int fuelCost) {
this.name = name;
this.fuelCost = fuelCost;
}

/**
* Instantiate the CodeGenerator.
*
* @param scope Scope into which the code is generated.
* @param parameters Provides the parameters for the instantiation, as well as a unique ID for identifier
* name generation (e.g. variable of method names).
*/
public abstract void instantiate(Scope scope, Parameters parameters);

/**
* Helper facility to instantiate CodeGenerators more easily. It creates a unique Parameter set which can
* be further populated with {@link where}.
*/
public final class Instantiator {
private final CodeGenerator codeGenerator;
private final Parameters parameters;
private boolean isUsed;
private CodeGeneratorLibrary library;

Instantiator(CodeGenerator codeGenerator) {

Check failure on line 81 in test/hotspot/jtreg/compiler/lib/template_framework/CodeGenerator.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-22483

Whitespace error

Column 0: tab
this.codeGenerator = codeGenerator;
this.parameters = new Parameters();
this.library = null;
}

/**
* Add a parameter key-value pair.
*
* @param paramKey The name of the parameter.
* @param paramValue The value to be set.
* @return The Instantiator for chaining.
*/
public Instantiator where(String paramKey, String paramValue) {
parameters.add(paramKey, paramValue);
return this;
}

/**
* Add all parameter key-value pairs.
*
* @param parameterMap Map containing the key-value pairs.
* @return The Instantiator for chaining.
*/
public Instantiator where(Map<String,String> parameterMap) {
parameters.add(parameterMap);
return this;
}

/**
* Set a custom library for the instantiation.
*
* @param library The custom library.
* @return The Instantiator for chaining.
*/
public Instantiator with(CodeGeneratorLibrary library) {
if (this.library != null) {
throw new TemplateFrameworkException("Cannot set custom library twice.");
}
this.library = library;
return this;
}

/**
* Instantiate the CodeGenerator to a String, using the prepared parameters.
* This is useful for the outer-most instantiation, as it directly results in a String.
*
* @return The String resulting from the instantiation.
*/
public String instantiate() {
if (isUsed) {
throw new TemplateFrameworkException("Repeated use of Instantiator not allowed.");
}
isUsed = true;
BaseScope scope = new BaseScope(library);
codeGenerator.instantiate(scope, parameters);
scope.close();
return scope.toString();
}

/**
* Instantiate the CodeGenerator into a specified scope, using the prepared parameters.
* This is useful for recursive instantiations.
*
* @param scope Scope into which the code is generated.
*/
public void instantiate(Scope scope) {
if (isUsed) {
throw new TemplateFrameworkException("Repeated use of Instantiator not allowed.");
}
isUsed = true;
Scope nestedScope = new Scope(scope, scope.fuel);
codeGenerator.instantiate(nestedScope, parameters);
nestedScope.close();
scope.stream.addCodeStream(nestedScope.stream);
}
}

/**
* Create an {@link Instantiator}, which already has a first parameter key-value pair.
*
* @param paramKey The name of the parameter.
* @param paramValue The value to be set.
* @return The Instantiator.
*/
public final Instantiator where(String paramKey, String paramValue) {
return new Instantiator(this).where(paramKey, paramValue);
}

/**
* Create an {@link Instantiator}, which already has all parameter key-value pairs from the provided map.
*
* @param parameterMap Map containing the key-value pairs.
* @return The Instantiator.
*/
public final Instantiator where(Map<String,String> parameterMap) {
return new Instantiator(this).where(parameterMap);
}

/**
* Create an {@link Instantiator}, which already has set a custom library.
*
* @param library The custom library.
* @return The Instantiator for chaining.
*/
public Instantiator with(CodeGeneratorLibrary library) {
return new Instantiator(this).with(library);
}

/**
* Instantiate the CodeGenerator to a String, using the prepared parameters.
* This is useful for the outer-most instantiation, as it directly results in a String.
*
* @return The String resulting from the instantiation.
*/
public final String instantiate() {
return new Instantiator(this).instantiate();
}

/**
* Instantiate the CodeGenerator into a specified scope, using the prepared parameters.
* This is useful for recursive instantiations.
*
* @param scope Scope into which the code is generated.
*/
public final void instantiate(Scope scope) {
new Instantiator(this).instantiate(scope);
}
}
Loading