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

8260605: Various java.lang.invoke cleanups #2300

Closed
wants to merge 9 commits into from

Conversation

cl4es
Copy link
Member

@cl4es cl4es commented Jan 28, 2021

  • Remove unused code
  • Inline and simplify the bootstrap method invocation code (remove pointless reboxing checks etc)
  • Apply pattern matching to make some code more readable

Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

Reviewers

Download

To checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/2300/head:pull/2300
$ git checkout pull/2300

To update a local copy of the PR:
$ git checkout pull/2300
$ git pull https://git.openjdk.java.net/jdk pull/2300/head

@bridgekeeper
Copy link

bridgekeeper bot commented Jan 28, 2021

👋 Welcome back redestad! 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 Jan 28, 2021
@openjdk
Copy link

openjdk bot commented Jan 28, 2021

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

  • core-libs
  • hotspot-compiler

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.

@openjdk openjdk bot added hotspot-compiler hotspot-compiler-dev@openjdk.org core-libs core-libs-dev@openjdk.org labels Jan 28, 2021
@mlbridge
Copy link

mlbridge bot commented Jan 28, 2021

Webrevs

@bridgekeeper
Copy link

bridgekeeper bot commented Mar 1, 2021

@cl4es This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@@ -339,8 +339,8 @@ private ClassWriter classFilePrologue() {
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES);
setClassWriter(cw);
cw.visit(Opcodes.V1_8, NOT_ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_SUPER,
CLASS_PREFIX + className, null, INVOKER_SUPER_NAME, null);
cw.visitSource(SOURCE_PREFIX + className, null);
CLASS_PREFIX.concat(className), null, INVOKER_SUPER_NAME, null);
Copy link
Member

Choose a reason for hiding this comment

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

I prefer to use the existing common pattern using + as I believe this gain is in the noise.

Copy link
Member Author

Choose a reason for hiding this comment

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

The goal here was to remove/reduce allocations and excess calls - and using String.concat might have been excessive.

The bulk of the overhead is the potentially many CLASS_PREFIX + className calls, often via className(). Calculating this once and storing it in an instance field prefixedClassName is more profitable and help better disambiguates between className and className() - which sound like they should be the same but aren't.

result = invokeWithManyArguments(bootstrapMethod, caller, name, type, argv);
maybeReBoxElements(argv);
if (argv.length > 6) {
result = invokeWithManyArguments(bootstrapMethod, caller, name, type, argv);
Copy link
Member

Choose a reason for hiding this comment

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

it'd be cleaner to move this to the default case in line 162 and 174 instead of having this special if-block.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch!

@@ -415,7 +409,6 @@ public static MethodType genericMethodType(int objectArgCount) {
*/
public MethodType changeParameterType(int num, Class<?> nptype) {
if (parameterType(num) == nptype) return this;
checkPtype(nptype);
Copy link
Member

Choose a reason for hiding this comment

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

nptype is never void but what about the check if nptype is not null?

Copy link
Member Author

Choose a reason for hiding this comment

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

Other methods that delegate to makeImpl aren't doing up-front validation, so this change was made to get things more in line. It might be good to spell out that makeImpl does these checks for all its callers, though. (The makeImpl fast-path that execute before the validation can never return an invalid MethodType)

Copy link
Member

Choose a reason for hiding this comment

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

Generally we have a public API implementation to check the arguments upfront for readability. In particular for this case, the validation cost is negligible and removing the validation makes the code unclear where the validation is done. I prefer to keep the validation there. It should check that nptype is non-null and not void.class.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I mis-read your comment. I now see that makeImpl does the argument validation. Adding the comment would be helpful.

@@ -85,6 +85,7 @@

/** Name of new class */
private final String className;
private final String prefixedClassName;
Copy link
Member

Choose a reason for hiding this comment

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

Adding a field for the class name is a good change. I was tempted to rename className at one point to name which can be a class name in internal form or a simple name. It now makes more sense to do the renaming s/className/name and s/prefixedClassName/className. What do you think?

Copy link
Member

@mlchung mlchung left a comment

Choose a reason for hiding this comment

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

Thanks for doing the renames. Looks good.

@openjdk
Copy link

openjdk bot commented Mar 17, 2021

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

8260605: Various java.lang.invoke cleanups

Reviewed-by: mchung

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

  • 24afa36: 8263726: divideToIntegralValue typo on BigDecimal documentation
  • cdf78e4: 8262298: G1BarrierSetC2::step_over_gc_barrier fails with assert "bad barrier shape"
  • 7674da4: 8262398: Shenandoah: Disable nmethod barrier and stack watermark when running with passive mode
  • 4f4ca0e: 8261671: X86 I2L conversion can be skipped for certain masked positive values
  • 5d87a21: 8263361: Incorrect arraycopy stub selected by C2 for SATB collectors
  • e152cc0: 8263677: Improve Character.isLowerCase/isUpperCase lookups
  • b63b5d4: 8263732: ProblemList serviceability/sa/ClhsdbSymbol.java on ZGC
  • 000012a: 8148937: (str) Adapt StringJoiner for Compact Strings
  • a707fcb: 8263723: [BACKOUT] MoveAndUpdateClosure::do_addr calls function with side-effects in an assert
  • 86e9cd9: 8263667: Avoid running GitHub actions on branches named pr/*
  • ... and 106 more: https://git.openjdk.java.net/jdk/compare/fdd3941121aad3975c7b448bb11e50f9943b7af7...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 17, 2021
@cl4es
Copy link
Member Author

cl4es commented Mar 18, 2021

/integrate

@openjdk openjdk bot closed this Mar 18, 2021
@openjdk openjdk bot added integrated Pull request has been integrated and removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Mar 18, 2021
@openjdk
Copy link

openjdk bot commented Mar 18, 2021

@cl4es Since your change was applied there have been 128 commits pushed to the master branch:

  • 9cd21b6: 8263590: Rawtypes warnings should be produced for pattern matching in instanceof
  • ff52f29: 8260716: Assert in MacroAssembler::clear_mem with -XX:-IdealizeClearArrayNode
  • 72b82fd: 8263725: JFR oldobject tests are not run when GCs are specified explicitly
  • 444a80b: 8263455: NMT: assert on registering a region which completely engulfs an existing region
  • 2b93ae0: 8261480: MetaspaceShared::preload_and_dump should check exceptions
  • 81ba578: 8263676: AArch64: one potential bug in C1 LIRGenerator::generate_address()
  • 9225a23: 8263108: Class initialization deadlock in java.lang.constant
  • 5d5813a: 8263757: Remove serviceability/sa/ClhsdClasses.java from ZGC problem list
  • 50ff0d4: 8263756: Fix ZGC ProblemList entry for serviceability/sa/ClhsdbSymbol.java
  • 99b39aa: 8262807: Note assumptions of core reflection modeling and parameter handling
  • ... and 118 more: https://git.openjdk.java.net/jdk/compare/fdd3941121aad3975c7b448bb11e50f9943b7af7...master

Your commit was automatically rebased without conflicts.

Pushed as commit 63eae8f.

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

@cl4es cl4es deleted the invoke_cleanup branch March 18, 2021 13:05
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 hotspot-compiler hotspot-compiler-dev@openjdk.org integrated Pull request has been integrated
2 participants