Skip to content

8174222: LambdaMetafactory: validate inputs and improve documentation #4346

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

Closed
wants to merge 9 commits into from

Conversation

dansmithcode
Copy link

@dansmithcode dansmithcode commented Jun 3, 2021

Standardizes and better specifies the errors thrown by LambdaMetafactory, including for inputs that would not be generated by javac.

Does some renaming of core parameters/fields to better reflect their purpose.

In the implementation, stops using ACC_BRIDGE for any methods, which is not a good fit for what these methods do (they don't delegate to each other, but all invoke the same implementation method).


Progress

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

Issue

  • JDK-8174222: LambdaMetafactory: validate inputs and improve documentation

Reviewers

Reviewing

Using git

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

Update a local copy of the PR:
$ git checkout pull/4346
$ git pull https://git.openjdk.java.net/jdk pull/4346/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 4346

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/4346.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 3, 2021

👋 Welcome back dlsmith! 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 Jun 3, 2021
@openjdk
Copy link

openjdk bot commented Jun 3, 2021

@dansmithcode 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 3, 2021
@dansmithcode
Copy link
Author

CSR was completed months ago: JDK-8221255. Just never got around to pushing the changes. Since then, InnerClassLambdaMetafactory was changed significantly, but the the public API is unchanged.

@dansmithcode
Copy link
Author

In testing, I discovered one issue leading to an internal error: JDK-8268192. I commented out my test case and will follow up on that issue separately.

@mlbridge
Copy link

mlbridge bot commented Jun 3, 2021

Webrevs

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.

Looks fine to me. The CSR was approved for 13 and its fixVersion should be updated to 17.

@@ -0,0 +1,306 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
Copy link
Member

Choose a reason for hiding this comment

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

copyright year needs update.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed. And I bumped it on the other files, too.

Copy link
Member

@PaulSandoz PaulSandoz left a comment

Choose a reason for hiding this comment

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

Code looks good, nice test.

@openjdk
Copy link

openjdk bot commented Jun 3, 2021

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

8174222: LambdaMetafactory: validate inputs and improve documentation

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

  • 7e41ca3: 8266957: SA has not followed JDK-8220587 and JDK-8224965
  • 6ff978a: 8267204: Expose access to underlying streams in Reporter
  • 76b54a1: 8263512: [macos_aarch64] issues with calling va_args functions from invoke_native
  • 4e6748c: 8267687: ModXNode::Ideal optimization is better than Parse::do_irem
  • 48dc72b: 8268272: Remove JDK-8264874 changes because Graal was removed.
  • 20b6312: 8268151: Vector API toShuffle optimization
  • 64ec8b3: 8212155: Race condition when posting dynamic_code_generated event leads to JVM crash
  • cd0678f: 8199318: add idempotent copy operation for Map.Entry
  • b27599b: 8268222: javax/xml/jaxp/unittest/transform/Bug6216226Test.java failed, cannot delete file
  • 59a539f: 8268129: LibraryLookup::ofDefault leaks symbols from loaded libraries
  • ... and 39 more: https://git.openjdk.java.net/jdk/compare/1ae934e09d1a55bce4079153d3bfccd30657a0ea...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 Jun 3, 2021
@mlbridge
Copy link

mlbridge bot commented Jun 3, 2021

Mailing list message from Joe Darcy on core-libs-dev:

Yes, the CSR should be re-reviewed before the change goes in.

I've changed the CSR status to indicate it needs another review.

-Joe

On 6/3/2021 4:07 PM, Mandy Chung wrote:

1 similar comment
@mlbridge
Copy link

mlbridge bot commented Jun 3, 2021

Mailing list message from Joe Darcy on core-libs-dev:

Yes, the CSR should be re-reviewed before the change goes in.

I've changed the CSR status to indicate it needs another review.

-Joe

On 6/3/2021 4:07 PM, Mandy Chung wrote:

* are violated, or the lookup context
* does not have private access privileges.
* instances of the interface named by {@code factoryType}
* @throws LambdaConversionException If {@code caller} does not have private
Copy link
Member

@mlchung mlchung Jun 4, 2021

Choose a reason for hiding this comment

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

One additional comment:

The lookup access has been extended since 14 to include MODULE and ORIGINAL access.
Lookup::hasFullPrivilegeAccess returns true if the lookup has PRIVATE and MODULE which means that this lookup is not teleported from another module via Lookup::in and MethodHandles::privateLookupIn.

What privilege do you expect the caller lookup should have? I believe full privilege access is the appropriate privilege. The ORIGINAL access is stricter as the lookup must be created from the original lookup class.

[1] shows what access a Lookup has when being produced via different APIs.

[1] https://download.java.net/java/early_access/jdk17/docs/api/java.base/java/lang/invoke/MethodHandles.Lookup.html#access-modes

Copy link
Author

Choose a reason for hiding this comment

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

Thanks, yes I think hasFullPrivilegeAccess is what we want. I updated the javadoc, along with the actual check. Thanks for catching!

if (!type.isInstance(result)) {
throw new IllegalArgumentException("argument has wrong type");
}
return type.cast(result);
Copy link
Member

Choose a reason for hiding this comment

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

Can we just use a return (T) result as there will always be a checked cast on the caller's end, and this call seems redundant? The only shortcoming is that the call will raise an unchecked warning that needs to be suppressed. Or is this negligible after hotspot optimization?

Copy link
Author

@dansmithcode dansmithcode Jun 4, 2021

Choose a reason for hiding this comment

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

Eh, the scale here is quite small (never more than, say, 20 items), and an instanceof + a cast is a routine coding style that I'd expect to be optimized away. Doesn't seem worth the maintenance noise of a @SuppressWarnings.

final Class<?>[] markerInterfaces; // Additional marker interfaces to be implemented
final MethodType[] additionalBridges; // Signatures of additional methods to bridge
final Class<?>[] interfaces; // Additional interfaces to be implemented
final MethodType[] bridges; // Signatures of additional methods to bridge
Copy link
Contributor

Choose a reason for hiding this comment

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

If you are removing ACC_BRIDGE from additional generated methods, then perhaps this parameter name could also be changed? altMethods (as alternative methods perhaps?)

Copy link
Author

Choose a reason for hiding this comment

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

Yes, it was sort of a half-done move. You're right, we should rename these (and, more importantly, in the public LambdaMetafactory API). Done. Also renamed interfaces --> altInterfaces.

@@ -309,8 +309,8 @@ private LambdaMetafactory() {}
* {@code interfaceMethodType}.
* @return a CallSite whose target can be used to perform capture, generating
* instances of the interface named by {@code factoryType}
* @throws LambdaConversionException If {@code caller} does not have private
* access privileges, or if {@code interfaceMethodName} is not a valid JVM
* @throws LambdaConversionException If {@code caller} does not have full privilege
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @throws LambdaConversionException If {@code caller} does not have full privilege
* @throws LambdaConversionException If {@code caller} does not have {@linkplain Lookup#hasFullPrivilegeAccess full privilege}

Copy link
Author

Choose a reason for hiding this comment

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

It's hard to see in the diff, but this link just appeared in the javadoc a few lines above. Stylistically, doesn't seem like it should be linked again.

Copy link
Member

Choose a reason for hiding this comment

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

I didn't realize it's already linked, thanks. So what you have is fine then.

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.

Can you also rename the parameter names in java.lang.invoke.LambdaProxyClassArchive methods to match the new ones?

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Jun 4, 2021
@dansmithcode
Copy link
Author

Can you also rename the parameter names in java.lang.invoke.LambdaProxyClassArchive methods to match the new ones?

Hmm, that expands the reach of the patch a bit—into native HotSpot code—but I've given it a try. Let me know if it looks like I've broken something. :-)

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 going beyond the java code. Looks good.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jun 5, 2021
@dansmithcode
Copy link
Author

/integrate

@openjdk openjdk bot closed this Jun 7, 2021
@openjdk openjdk bot added integrated Pull request has been integrated and removed ready Pull request is ready to be integrated labels Jun 7, 2021
@openjdk
Copy link

openjdk bot commented Jun 7, 2021

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

  • 5e557d8: 8266967: debug.cpp utility find() should print Java Object fields.
  • c7c77fd: 8255557: Decouple GCM from CipherCore
  • e546ae2: 8268296: ScopedMemoryAccess build error with readonly filesystems
  • 81600dc: 8191441: (Process) add Readers and Writer access to java.lang.Process streams
  • 7e55569: 8261549: Adjust memory size in MTLTexurePool.m
  • e663ba9: 8268299: jvms tag produces incorrect URL
  • 3396b69: 8254129: IR Test Framework to support regex-based matching on the IR in JTreg compiler tests
  • 270ec97: 8268331: Fix crash in humongous object eager reclaim logging
  • ea8274f: 8267875: Shenandoah: Duplicated code in ShenandoahBarrierSetC2::ideal_node()
  • a91f971: 8268267: Remove -Djavatest.security.noSecurityManager=true from jtreg runs
  • ... and 75 more: https://git.openjdk.java.net/jdk/compare/1ae934e09d1a55bce4079153d3bfccd30657a0ea...master

Your commit was automatically rebased without conflicts.

Pushed as commit fc08af5.

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

@openjdk openjdk bot removed the rfr Pull request is ready for review label Jun 7, 2021
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
Development

Successfully merging this pull request may close these issues.

5 participants