Skip to content

[DRAFT] [lworld] Test scalarization and call conventions for different value class shapes #1522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 21 commits into
base: lworld
Choose a base branch
from

Conversation

galderz
Copy link
Contributor

@galderz galderz commented Aug 15, 2025

This is a very early draft for a template-based test (temporarily called TestOne) that addresses some of the requirements of JDK-8364421.

NOTE: the PR also includes the commits to add template-based testing framework since that's not yet in lworld, and also adds 68e4a60 so that Boolean types are supported in checkEQ.

This test has surfaced JDK-8365590 bug, and as I focus on that bug, I thought it'd be a good moment to share what I've done so far with the test and get some feedback.

The test is very simple so far, creating value classes that contain a single field, testing for each of the primitive types. I also started testing having this field be a primitive array type and that's when I encountered JDK-8365590.

I've tried to create value classes that had multiple fields, but I've hit some obstacles here so I've just added a very basic test:

First, I tried to use data names to create value classes that would have N fields, and have these fields initialized via a constructor, but I couldn't get it to work. So the example present in the test uses external data structures to keep track of these fields, their types, their initial values...etc. I have discussed these issues in more detail with @chhagedorn and bounced some ideas of how to improve data names, but these need to be discussed in more detail.

The second obstacle I found is related to nuances on when value classes with multiple fields will be scalarized, when these classes are part of another value classes. Depending on the combination of fields, they can be considered that they can be flattened or not, so handling this in a test like this would need to track the sizes of each fields, add them up, and decide whether the test should be positive on scalarization or negative. I traced this logic to FieldLayoutBuilder::compute_inline_class_layout and the way _nullable_layout_size_in_bytes is then used to decide whether to flatten or not. I've been using PrintFieldLayout option to see what nullable flat layout values each of these box instances would have.

So, given these complexities of multiple fields, I'm might keep TestOne (note: name is temporary) focused on value classes with a single field. And then have another test with multiple fields.


Progress

  • Change must not contain extraneous whitespace

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/valhalla.git pull/1522/head:pull/1522
$ git checkout pull/1522

Update a local copy of the PR:
$ git checkout pull/1522
$ git pull https://git.openjdk.org/valhalla.git pull/1522/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 1522

View PR using the GUI difftool:
$ git pr show -t 1522

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/valhalla/pull/1522.diff

Using Webrev

Link to Webrev Comment

eme64 and others added 21 commits July 31, 2025 11:28
Co-authored-by: Tobias Hartmann <[email protected]>
Co-authored-by: Tobias Holenstein <[email protected]>
Co-authored-by: Theo Weidmann <[email protected]>
Co-authored-by: Roberto Castañeda Lozano <[email protected]>
Co-authored-by: Christian Hagedorn <[email protected]>
Co-authored-by: Manuel Hässig <[email protected]>
Reviewed-by: chagedorn, mhaessig, rcastanedalo
* The most basic of tests
* Switch to more precise IRNode failure conditions
* Disable EA, easily test with non-value class and add report stdout
* Simplify and align with Box1/test1
* Use @check instead of @run
* Make it public to access it from template
* Port test over to the template framework
* Parameterize box type
@bridgekeeper
Copy link

bridgekeeper bot commented Aug 15, 2025

👋 Welcome back galder! A progress list of the required criteria for merging this PR into lworld will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Aug 15, 2025

@galderz This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

[DRAFT] [lworld] Test scalarization and call conventions for different value class shapes

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 2 new commits pushed to the lworld branch:

  • ed21796: 8364483: [lworld] Pre-register migrated classes in class loaders
  • 4ce51bf: [lworld] Remove redundant DTraceAlloc/Method probes

Please see this link for an up-to-date comparison between the source branch of this pull request and the lworld branch.
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added ready Pull request is ready to be integrated rfr Pull request is ready for review labels Aug 15, 2025
@mlbridge
Copy link

mlbridge bot commented Aug 15, 2025

Webrevs

Copy link
Contributor

@eme64 eme64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is in draft state. But I thought I'd have a look since you are trying to use the template framework. That's exciting :)

Comment on lines +225 to +247
static final class IntArrayType implements CodeGenerationDataNameType {
@Override
public Object con() {
return "new int[]{%s}".formatted(
CodeGenerationDataNameType.ints().con()
);
}

@Override
public String name() {
return "int[]";
}

@Override
public boolean isSubtypeOf(DataName.Type other) {
return other instanceof IntArrayType;
}

@Override
public String toString() {
return name();
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to have some sort of array type in the mainline library as well.

Comment on lines +215 to +223
static TemplateToken hashField(FieldConstant field) {
return Template.make("FIELD", (FieldConstant f) -> body(
let("BOXED", f.type.boxedTypeName()),
let("FIELD_NAME", f.name()),
"""
#BOXED.hashCode(#FIELD_NAME) +
"""
)).asToken(field);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you don't actually need any arguments in the Template here. You are already capturing field in the lambda.

Comment on lines +208 to +210
"""
0;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should probably rather joint a list of strings with " + ", rather than letting the hashField add the + that may feel a little lost there 😅

Comment on lines +170 to +172
final List<FieldConstant> fields = fieldTypes.stream()
.map(fieldType -> FieldConstant.of(fieldId.getAndIncrement(), fieldType))
.toList();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need the constants associated with the fields here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And what is the id good for?

Comment on lines +101 to +104
record FieldConstant(Object value, int id, PrimitiveType type) {
String name() {
return "v" + id;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of the id here? Do you ever need it, or just the name()?

static TemplateToken field(FieldConstant field) {
return Template.make("FIELD", (FieldConstant f) -> body(
let("FIELD_TYPE", f.type),
let("FIELD_VALUE", f.value),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the only place where you use the value of FieldConstant? Why not just get a field.type.con() right here? Maybe I'm missing some part of the design here.

"""
static value class $Box {
""",
fields(fields),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, I did not know that one could have both a local variable and a method with the same name! Even if Java lets you do it, it seems a bit confusing to me 😅 Maybe call the method generateFields?

@eme64
Copy link
Contributor

eme64 commented Aug 18, 2025

And it would be nice to see if we cannot use DataName for fields, and StructuralName for methods (maybe it is just a small issue with how to use the framework). But it's not a necessity: if you feel like modeling it separately that is also fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready Pull request is ready to be integrated rfr Pull request is ready for review
Development

Successfully merging this pull request may close these issues.

2 participants