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

8315810: Reimplement sun.reflect.ReflectionFactory::newConstructorForSerialization with method handles #15600

Closed
wants to merge 4 commits into from

Conversation

mlchung
Copy link
Member

@mlchung mlchung commented Sep 6, 2023

This reimplements sun.reflect.ReflectionFactory::newConstructorForSerialization with method handles.

This API currently generates the bytecode which fails the verification because new C; invokespecial A() where the given class C and invoke a no-arg constructor of C's first non-Serializable superclass A is not a valid operation per the VM specification. VM special cases the classes generated for reflection to skip verification for the constructors generated for serialization and externalization. This change will allow such VM hack to be removed.

A jdk.reflect.useOldSerializableConstructor system property can be set to use the old implementation in case if customers run into any compatibility issue. I expect this change has very low compatibility risk. This system property is undocumented and will be removed in a future release.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Change requires CSR request JDK-8315811 to be approved
  • Commit message must refer to an issue

Issues

  • JDK-8315810: Reimplement sun.reflect.ReflectionFactory::newConstructorForSerialization with method handles (Enhancement - P3)
  • JDK-8315811: Reimplement sun.reflect.ReflectionFactory::newConstructorForSerialization with method handles (CSR)

Reviewers

Contributors

  • Chen Liang <liach@openjdk.org>

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 15600

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 6, 2023

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

@mlchung
Copy link
Member Author

mlchung commented Sep 6, 2023

/contributor add liach

@openjdk openjdk bot added the rfr Pull request is ready for review label Sep 6, 2023
@openjdk
Copy link

openjdk bot commented Sep 6, 2023

@mlchung
Contributor Chen Liang <liach@openjdk.org> successfully added.

@openjdk
Copy link

openjdk bot commented Sep 6, 2023

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

  • core-libs
  • security

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 security security-dev@openjdk.org core-libs core-libs-dev@openjdk.org labels Sep 6, 2023
@mlchung
Copy link
Member Author

mlchung commented Sep 6, 2023

/label remove security

@openjdk openjdk bot removed the security security-dev@openjdk.org label Sep 6, 2023
@openjdk
Copy link

openjdk bot commented Sep 6, 2023

@mlchung
The security label was successfully removed.

@mlbridge
Copy link

mlbridge bot commented Sep 6, 2023

Webrevs

@openjdk openjdk bot added the csr Pull request needs approved CSR before integration label Sep 6, 2023
@mlchung mlchung changed the title 8315810: Reimplement ReflectionFactory::newConstructorForSerialization with method handles 8315810: Reimplement sun.reflect.ReflectionFactory::newConstructorForSerialization with method handles Sep 6, 2023
@ExE-Boss
Copy link

ExE-Boss commented Sep 6, 2023

See also: JDK‑8307575 (GH‑13853)

@@ -194,7 +194,8 @@ private boolean isIllegalArgument(RuntimeException ex) {
private void checkReceiver(Object o) {
// NOTE: will throw NullPointerException, as specified, if o is null
if (!declaringClass.isAssignableFrom(o.getClass())) {
throw new IllegalArgumentException("object is not an instance of declaring class");
throw new IllegalArgumentException("object of type " + o.getClass().getName()
+ " is not an instance of " + declaringClass.getName());
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
+ " is not an instance of " + declaringClass.getName());
+ " is not an instance of " + declaringClass.getName());

Comment on lines 377 to 384
langReflectAccess.
getConstructorSlot(constructorToCall),
langReflectAccess.
getConstructorSignature(constructorToCall),
langReflectAccess.
getConstructorAnnotations(constructorToCall),
langReflectAccess.
getConstructorParameterAnnotations(constructorToCall));
Copy link
Contributor

Choose a reason for hiding this comment

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

This would be easier to read if either the line length or the indentation was modified.

}


Copy link
Contributor

Choose a reason for hiding this comment

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

Extra blank line.

Comment on lines +3542 to +3552
private static boolean constructorInSuperclass(Class<?> decl, Constructor<?> ctor) {
if (decl == ctor.getDeclaringClass())
return true;

Class<?> cl = decl;
while ((cl = cl.getSuperclass()) != null) {
if (cl == ctor.getDeclaringClass()) {
return true;
}
}
return false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it break encapsulation too much to export and use the same method from jdk.internal.reflect.MethodHandleAccessorFactory.
Maybe not worth it for a small utility method.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's a small utility and I think it's ok to leave it this way.

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.

LGTM

@openjdk
Copy link

openjdk bot commented Sep 13, 2023

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

8315810: Reimplement sun.reflect.ReflectionFactory::newConstructorForSerialization with method handles

Co-authored-by: Chen Liang <liach@openjdk.org>
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 24 new commits pushed to the master branch:

  • 3b0a6d2: 8314226: Series of colon-style fallthrough switch cases with guards compiled incorrectly
  • ff240a9: 8316087: Test SignedLoggerFinderTest.java is still failing
  • a731a24: 8315934: RISC-V: Disable conservative fences per vendor
  • b3dad24: 8316021: Serial: Remove unused Generation::post_compact
  • f9ab115: 8316050: Use hexadecimal encoding in MemorySegment::toString
  • f804f86: 8314612: TestUnorderedReduction.java fails with -XX:MaxVectorSize=32 and -XX:+AlignVector
  • f8df754: 8311207: Cleanup for Optimization for UUID.toString
  • fecd2fd: 8315898: Open source swing JMenu tests
  • bb6b3f2: 8315761: Open source few swing JList and JMenuBar tests
  • 2d168c5: 8313202: MutexLocker should disallow null Mutexes
  • ... and 14 more: https://git.openjdk.org/jdk/compare/d75d9774c806e4bf73caa69cd78c31a132e4c812...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 ready Pull request is ready to be integrated and removed csr Pull request needs approved CSR before integration labels Sep 13, 2023
@mlchung
Copy link
Member Author

mlchung commented Sep 14, 2023

/integrate

@openjdk
Copy link

openjdk bot commented Sep 14, 2023

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

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Sep 14, 2023

@mlchung Pushed as commit 5cea53d.

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

@mlchung mlchung deleted the reflect-serializable-ctor branch October 4, 2023 21:08
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