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

8303820: Simplify type metadata #12924

Closed
wants to merge 5 commits into from

Conversation

mcimadamore
Copy link
Contributor

@mcimadamore mcimadamore commented Mar 8, 2023

This patch simplifies the TypeMetadata API. TypeMetadata can be used as a side-channel, to attach extra information to a javac type (type annotations, constant values).

While TypeMetadata provides the right knobs to compare types (see Type::equalsIgnoreMetadata), which is used uniformly across the type-system related routines (e.g. subtyping, type equality and type containment), the TypeMetadata API is also rather cumbersome to use.

The only way to add a new metadata to a type is to "combine" the metadata into an existing one, which feels odd, and probably too biased by the type annotations requirements.

This patch simplifies this: now TypeMetadata is a simple marker interface. There can be many implementations - one is Annotations (used to store type annotations), another is ConstantValue (used to store a type's constant value).

A type is then associated with a List<TypeMetadata>, and there are methods to add/drop/get metadata. These methods are used to provide support for annotated and constant types.

The resulting code feels simpler: to add a new metadata, one only has to define a new class/record inside TypeMetadata, and that's pretty much it. Javac will truck the metadata around in the correct way (as it did before).


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

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 12924

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

Using diff file

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

getMetadata now returns Optional to allow for more functional style
cloneWithMetadata is now protected
@bridgekeeper
Copy link

bridgekeeper bot commented Mar 8, 2023

👋 Welcome back mcimadamore! 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 openjdk bot added the rfr Pull request is ready for review label Mar 8, 2023
@openjdk
Copy link

openjdk bot commented Mar 8, 2023

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

  • compiler

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 compiler compiler-dev@openjdk.org label Mar 8, 2023
@mlbridge
Copy link

mlbridge bot commented Mar 8, 2023

Webrevs

@@ -328,7 +323,7 @@ public <Z> Type map(TypeMapping<Z> mapping) {
* and with given constant value
*/
public Type constType(Object constValue) {
Copy link
Contributor

Choose a reason for hiding this comment

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

so now any type can have a constant value? shouldn't this be restricted to primitives and Strings?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah - not sure which way to go - in reality we have a also a couple of types which implement this method and just return this. Only the toplevel Type declaration throws. I'm happy to revert to the old ways if that is preferred - it was mostly a way not to duplicate the method body twice (but that's not a big deal).

Copy link
Contributor

Choose a reason for hiding this comment

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

I would keep the original semantics and we can relax it later if needed, but I don't have a strong preference tbh

@vicente-romero-oracle
Copy link
Contributor

nice patch, nice simplification, just added a question

Copy link
Contributor

@vicente-romero-oracle vicente-romero-oracle 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 thanks

@openjdk
Copy link

openjdk bot commented Mar 9, 2023

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

8303820: Simplify type metadata

Reviewed-by: vromero

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 20 new commits pushed to the master branch:

  • 4655b79: 8294982: Implementation of Classfile API
  • 1e9942a: 8303881: Mixed, minor cleanup in jdk.compiler
  • 7e01534: 8303467: Serial: Refactor reference processor
  • 713def0: 8303105: LoopRangeStrideTest fails IR verification on x86
  • 34a9246: 8274264: Not all of G1 young collection verification honors the verification type
  • a7e308a: 8303576: addIdentitiesToKeystore in KeystoreImpl.m needs CFRelease call in early potential CHECK_NULL return
  • dd79410: 8303509: Socket setTrafficClass does not work for IPv4 connections when IPv6 enabled
  • dc523a5: 8300258: C2: vectorization fails on simple ByteBuffer loop
  • 5e232cf: 8303564: C2: "Bad graph detected in build_loop_late" after a CMove is wrongly split thru phi
  • 8cfd74f: 8302976: C2 intrinsification of Float.floatToFloat16 and Float.float16ToFloat yields different result than the interpreter
  • ... and 10 more: https://git.openjdk.org/jdk/compare/8eaf84f09476b08ed421efe74d7554e2b29bc5a7...master

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.

➡️ 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 Mar 9, 2023
@mcimadamore
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Mar 10, 2023

Going to push as commit b9951dd.
Since your change was applied there have been 38 commits pushed to the master branch:

  • 75d6306: 8303349: Simplify link format for generic types in index pages
  • b1d89f3: 8294971: jdk.jlink jdk.tools.jimage.JImageTask is using ASM to verify classes
  • 0f26d09: 8303822: gtestMain should give more helpful output
  • e26cc52: 8303624: The java.lang.Thread.FieldHolder can be null for JNI attaching threads
  • d06308c: 8302360: Atomic*.compareAndExchange Javadoc unclear
  • 8b740b4: 8302779: HelidonAppTest.java fails with "assert(_cb == CodeCache::find_blob(pc())) failed: Must be the same" or SIGSEGV
  • 562c8fc: 8303691: Fedora based devkit build should load more packages from archive location
  • e930b63: 8303924: ProblemList serviceability/sa/UniqueVtableTest.java on Linux
  • af0ca78: 8303609: ProblemList serviceability/sa/TestSysProps.java with ZGC
  • 8b0eb72: 8289765: JDI EventSet/resume/resume008 failed with "ERROR: suspendCounts don't match for : VirtualThread-unparker"
  • ... and 28 more: https://git.openjdk.org/jdk/compare/8eaf84f09476b08ed421efe74d7554e2b29bc5a7...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Mar 10, 2023

@mcimadamore Pushed as commit b9951dd.

💡 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
compiler compiler-dev@openjdk.org integrated Pull request has been integrated
2 participants