Skip to content

8357220: Introduce a BSMAttributeEntry struct #25298

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 2 commits into
base: master
Choose a base branch
from

Conversation

jdksjolen
Copy link
Contributor

@jdksjolen jdksjolen commented May 19, 2025

Hi,

The constant pool currently has a lot of methods specific to extracting parts of the operands array. What this array actually is, is a sequence of bootstrap method attribute entries, where each entry has the following components:

struct BSMAE {
  u2 bootstrap_method_index;
  u2 argument_count;
  u2 arguments[argument_count];
}

We can removes some of these operands array specific methods, and instead allows you to extract BSMAttributeEntrys which you can then use to extract its piece wise components. This makes for a nicer interface, and a bit easier to come into as a reader of the code, as it more closely mirrors the JVMS.

Please consider!

Testing: Currently GHA, running tier1-tier3


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8357220: Introduce a BSMAttributeEntry struct (Enhancement - P4)

Contributors

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 25298

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/25298.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented May 19, 2025

👋 Welcome back jsjolen! A progress list of the required criteria for merging this PR into master 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 May 19, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk
Copy link

openjdk bot commented May 19, 2025

@jdksjolen The following labels will be automatically applied to this pull request:

  • hotspot
  • serviceability

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command.

@jdksjolen
Copy link
Contributor Author

/contributor /contributor add @rose00

@openjdk
Copy link

openjdk bot commented May 19, 2025

@jdksjolen Syntax: /contributor (add|remove) [@user | openjdk-user | Full Name <email@address>]. For example:

  • /contributor add @openjdk-bot
  • /contributor add duke
  • /contributor add J. Duke <[email protected]>

User names can only be used for users in the census associated with this repository. For other contributors you need to supply the full name and email address.

@jdksjolen jdksjolen changed the title Introduce BSMAttributeEntry 8357220 May 19, 2025
@openjdk openjdk bot changed the title 8357220 8357220: Introduce a BSMAttributeEntry struct May 19, 2025
@jdksjolen
Copy link
Contributor Author

/contributor add @rose00

@openjdk
Copy link

openjdk bot commented May 19, 2025

@jdksjolen
Contributor John R Rose <[email protected]> successfully added.

@jdksjolen jdksjolen marked this pull request as ready for review May 19, 2025 10:03
@openjdk openjdk bot added the rfr Pull request is ready for review label May 19, 2025
@mlbridge
Copy link

mlbridge bot commented May 19, 2025

Webrevs

Comment on lines +124 to +126
private static int INDY_BSM_OFFSET = 0;
private static int INDY_ARGC_OFFSET = 1;
private static int INDY_ARGV_OFFSET = 2;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the SA code that references these fields still correct? It seems the references are from the ClassWriter, which we don't have very good test coverage for. Probably this is a bug that is not being detected.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The references are still correct, as we haven't changed the struct layout. We're also not planning on doing so. I don't think that there is a bug here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok. It's just unusual to see constants like these that are needed by SA but serve no purpose in hotspot.

Copy link
Contributor

@coleenp coleenp May 29, 2025

Choose a reason for hiding this comment

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

It does seem like you want to mirror these constants from the vmStructs side like it was rather than defining them here in the SA. I see why you did this but maybe you can add the constants to BSMAttributeEntry and declare them constants using declare_constant(BSMAttributeEntry::_indy...).
In case you change them at some later time.

Comment on lines -573 to -578
enum {
_indy_bsm_offset = 0, // CONSTANT_MethodHandle bsm
_indy_argc_offset = 1, // u2 argc
_indy_argv_offset = 2 // u2 argv[argc]
};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@plummercj , this is where the enum constants come from.

Comment on lines +124 to +126
private static int INDY_BSM_OFFSET = 0;
private static int INDY_ARGC_OFFSET = 1;
private static int INDY_ARGV_OFFSET = 2;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The references are still correct, as we haven't changed the struct layout. We're also not planning on doing so. I don't think that there is a bug here.

Copy link
Member

@lfoltan lfoltan left a comment

Choose a reason for hiding this comment

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

Overall looks good, a couple of comments below.

@@ -77,6 +77,36 @@ class CPKlassSlot {
}
};

class BSMAttributeEntry {
Copy link
Member

Choose a reason for hiding this comment

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

Please consider moving the description comment from lines #569-#572 ahead of this structure

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This?

  // The first part of the operands array consists of an index into the second part.
  // Extract a 32-bit index value from the first part.

Wouldn't it be better to leave it where it is, but add a comment ahead of the structure?

u2* argument_indexes() {
return reinterpret_cast<u2*>(this + 1);
}

Copy link
Member

Choose a reason for hiding this comment

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

Remove blank lines at #92, #95, #103

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We typically keep a space before we change access modifier, let's keep that pattern in here. We can tighten up the rest of the code according to your suggestions, however.

}

int argument_index(int n) const {
assert(checked_cast<u2>(n) < _argument_count, "oob");
Copy link
Member

Choose a reason for hiding this comment

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

Should the assert contain a check that _argument_count is >= 0 as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think so, it's a u2 so that's just part of its type.

int next_offset = bootstrap_operand_limit(cp_index));
assert(end_offset == next_offset, "matched ending");
return argc;
int bsmai = bootstrap_methods_attribute_index(cp_index);
Copy link
Member

Choose a reason for hiding this comment

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

The "matched ending" assert was the only code that used bootstrap_operand_limit(), so that method could be removed as well. This comment applies to bootstrap_operand_base() as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice!

private static int INDY_BSM_OFFSET;
private static int INDY_ARGC_OFFSET;
private static int INDY_ARGV_OFFSET;
private static int INDY_BSM_OFFSET = 0;
Copy link
Member

Choose a reason for hiding this comment

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

Please update the copyright of this file.

Copy link
Contributor Author

@jdksjolen jdksjolen left a comment

Choose a reason for hiding this comment

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

Thank you for the review Lois! I've addressed most of your comments, but I didn't add any documentation for the BSMAttributeEntry (yet).

u2* argument_indexes() {
return reinterpret_cast<u2*>(this + 1);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We typically keep a space before we change access modifier, let's keep that pattern in here. We can tighten up the rest of the code according to your suggestions, however.

}

int argument_index(int n) const {
assert(checked_cast<u2>(n) < _argument_count, "oob");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think so, it's a u2 so that's just part of its type.

int next_offset = bootstrap_operand_limit(cp_index));
assert(end_offset == next_offset, "matched ending");
return argc;
int bsmai = bootstrap_methods_attribute_index(cp_index);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice!

@@ -77,6 +77,36 @@ class CPKlassSlot {
}
};

class BSMAttributeEntry {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This?

  // The first part of the operands array consists of an index into the second part.
  // Extract a 32-bit index value from the first part.

Wouldn't it be better to leave it where it is, but add a comment ahead of the structure?

Copy link
Contributor

@coleenp coleenp left a comment

Choose a reason for hiding this comment

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

I think this looks like a nice improvement but I thought operands was going to turn into two arrays? Also there's probably a better name than 'operands' maybe bsm_operands?

Comment on lines +124 to +126
private static int INDY_BSM_OFFSET = 0;
private static int INDY_ARGC_OFFSET = 1;
private static int INDY_ARGV_OFFSET = 2;
Copy link
Contributor

@coleenp coleenp May 29, 2025

Choose a reason for hiding this comment

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

It does seem like you want to mirror these constants from the vmStructs side like it was rather than defining them here in the SA. I see why you did this but maybe you can add the constants to BSMAttributeEntry and declare them constants using declare_constant(BSMAttributeEntry::_indy...).
In case you change them at some later time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

4 participants