Skip to content
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

JDK-8289106: Add model of class file versions to core reflection #9299

Closed
wants to merge 20 commits into from

Conversation

jddarcy
Copy link
Member

@jddarcy jddarcy commented Jun 27, 2022


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
  • Change requires a CSR request to be approved

Issues

  • JDK-8289106: Add model of class file versions to core reflection
  • JDK-8289419: Add model of class file versions to core reflection (CSR)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 9299

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 27, 2022

👋 Welcome back darcy! 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.

@jddarcy jddarcy marked this pull request as draft June 27, 2022 20:28
@openjdk
Copy link

openjdk bot commented Jun 27, 2022

@jddarcy The following label will be automatically applied to this pull request:

  • core-libs

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

@openjdk openjdk bot added the core-libs core-libs-dev@openjdk.org label Jun 27, 2022
@jddarcy jddarcy marked this pull request as ready for review June 28, 2022 22:23
@jddarcy
Copy link
Member Author

jddarcy commented Jun 28, 2022

Sending this enum to model class file format versions out for some review comments before starting to write the tests and CSR, etc.

The class file format has a rich structure that evolves over time. That evolution includes adding access flags (as modeled by the recently-added java.lang.reflect.AccessFlag enum) as well as JVM attributes (not currently modeled in core reflection). The current docs in the ClassFileFormatVersion enum partially recount the changes in each version; more of the history is encoded in the various tables in JVMS, such as 4.4-B, 4.4-C, and 4.7-B. The intention at this point is not have ClassFileFormatVersion fully model and describe the class file evolution, although that information is of use to some clients and may be added in the future.

Given access flags and a notion of class file format versioning, a natural question to be able to answer is "in what class file format versions is this access flag supported and on what structures?" Abstractly, there are a variety of ways that information could be encoded included:

public static boolean isSupported(AccessFlag, AccessFlag.Location, ClassFileFormatVersion)
public static Set locations((AccessFlag, ClassFileFormatVersion)

The current version in the PR uses a locations(ClassFileFormatVersion) instance method defined on AccessFlag instead. This design puts the primacy on the AccessFlag dimension, but it would be possible to transpose this and make the class file format the prime factor instead (i.e. ClassFileFormatVersion.supportedFlags(AccessFlag.Location)) or even AccessFlag.Location.

@openjdk openjdk bot added the rfr Pull request is ready for review label Jun 28, 2022
@mlbridge
Copy link

mlbridge bot commented Jun 28, 2022

@openjdk openjdk bot added the csr Pull request needs approved CSR before integration label Jun 28, 2022
@RogerRiggs
Copy link
Contributor

A static method to map from classfile version (as in the JVMS) to ClassFileVersion enum will be useful too.

@jddarcy
Copy link
Member Author

jddarcy commented Jun 29, 2022

A static method to map from classfile version (as in the JVMS) to ClassFileVersion enum will be useful too.

Just to confirm, you're asking for a method that would map 63 to RELEASE_19, 64 to RELEASE_20, etc.?

Seems reasonable, although there will need to be special treating for 45 since both RELEASE_0 and RELEASE_1 have a major number of 45.

@RogerRiggs
Copy link
Contributor

I'm thinking of the case where I'm reading class file bytes and pull out the major classfile version and want to map it to the enum. If the semantic was the "earliest version" supporting the major version then it would be unambiguous.

@jddarcy
Copy link
Member Author

jddarcy commented Jun 29, 2022

I'm thinking of the case where I'm reading class file bytes and pull out the major classfile version and want to map it to the enum. If the semantic was the "earliest version" supporting the major version then it would be unambiguous.

Method to map from major class file version added.

@asotona
Copy link
Member

asotona commented Jul 7, 2022

I like the proposed concept and Classfile Processing API is definitely one of the potential consumers.

@mlchung
Copy link
Member

mlchung commented Jul 11, 2022

This ClassFileFormatVersion API is a good proposal. It can also reference java.class.version system property to map to the latest class file format version.

@jddarcy
Copy link
Member Author

jddarcy commented Jul 14, 2022

This ClassFileFormatVersion API is a good proposal. It can also reference java.class.version system property to map to the latest class file format version.

Good idea Mandy; I'll add that reference and start working on the implementation of the partially implemented method. Thanks.

@openjdk openjdk bot removed the rfr Pull request is ready for review label Jul 28, 2022
@jddarcy
Copy link
Member Author

jddarcy commented Jul 28, 2022

Updated the PR with implementations and tests for the version-specific location method.

CSR ready for review.

@openjdk openjdk bot added the rfr Pull request is ready for review label Jul 28, 2022
@@ -98,28 +98,56 @@ public enum AccessFlag {
*/
PUBLIC(Modifier.PUBLIC, true,
Set.of(Location.CLASS, Location.FIELD, Location.METHOD,
Location.INNER_CLASS)),
Location.INNER_CLASS)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there another way to implement this that does not create 19 anonymous classes with a single overloaded method?

Copy link

Choose a reason for hiding this comment

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

Probably by creating and using shared instances of java.util.Function which would also allow deduplicating the code.

Copy link
Member Author

Choose a reason for hiding this comment

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

Is there another way to implement this that does not create 19 anonymous classes with a single overloaded method?

Overriding a method in an enum constant specific class is one way to implement constant-specific behavior. Textually, I thought it had the advantage of having the class file version specific behavior close to the latest version behavior.

This could be refactored in various ways, such as having AccessFlag.locations(ClassFileFormatVersion cffv) start with a switch over the location which implemented the enum constant specific behavior. Or the set of parameters of the enum constructor could be augmented to cover more cases (empty until $VERSION, then $LOCATIONS, etc.), with constant-specific overrides just constants with unique patterns like STRICT.

Copy link
Contributor

Choose a reason for hiding this comment

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

True, many ways to factor the code. Another possibility is add a field to the enum that holds a java.util.Function<Iteger, Set<Location>>) and initialize it each with a lambda of the code now in the locations(cffv) method that maps the cffv to the set of locations.

Copy link
Member Author

Choose a reason for hiding this comment

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

True, many ways to factor the code. Another possibility is add a field to the enum that holds a java.util.Function<Iteger, Set<Location>>) and initialize it each with a lambda of the code now in the locations(cffv) method that maps the cffv to the set of locations.

Pushed a refactoring to use lambdas; thanks.

@openjdk openjdk bot removed the csr Pull request needs approved CSR before integration label Aug 8, 2022
Copy link
Contributor

@RogerRiggs RogerRiggs left a comment

Choose a reason for hiding this comment

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

Looks good.

*/
RELEASE_20(64);

private int major;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could be final?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure; that is a better expression of the intent of the field. Will change before pushing; thanks.

@openjdk
Copy link

openjdk bot commented Aug 16, 2022

@jddarcy 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:

8289106: Add model of class file versions to core reflection

Reviewed-by: rriggs

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 no new commits pushed to the master branch. If another commit should be pushed before you perform the /integrate command, your PR will be automatically rebased. If you prefer to avoid any potential automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Aug 16, 2022
@jddarcy
Copy link
Member Author

jddarcy commented Aug 16, 2022

/integrate

@openjdk
Copy link

openjdk bot commented Aug 16, 2022

Going to push as commit e44e3f0.

@openjdk openjdk bot added the integrated Pull request has been integrated label Aug 16, 2022
@openjdk openjdk bot closed this Aug 16, 2022
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Aug 16, 2022
@openjdk
Copy link

openjdk bot commented Aug 16, 2022

@jddarcy Pushed as commit e44e3f0.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org integrated Pull request has been integrated
5 participants