8315810: Reimplement sun.reflect.ReflectionFactory::newConstructorForSerialization with method handles#15600
8315810: Reimplement sun.reflect.ReflectionFactory::newConstructorForSerialization with method handles#15600mlchung wants to merge 4 commits intoopenjdk:masterfrom
Conversation
|
👋 Welcome back mchung! A progress list of the required criteria for merging this PR into |
|
/contributor add liach |
|
@mlchung |
|
/label remove security |
|
@mlchung |
Webrevs
|
|
See also: JDK‑8307575 (GH‑13853) |
src/java.base/share/classes/jdk/internal/reflect/MethodHandleAccessorFactory.java
Show resolved
Hide resolved
| 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()); |
There was a problem hiding this comment.
| + " is not an instance of " + declaringClass.getName()); | |
| + " is not an instance of " + declaringClass.getName()); |
…serializable-ctor
| langReflectAccess. | ||
| getConstructorSlot(constructorToCall), | ||
| langReflectAccess. | ||
| getConstructorSignature(constructorToCall), | ||
| langReflectAccess. | ||
| getConstructorAnnotations(constructorToCall), | ||
| langReflectAccess. | ||
| getConstructorParameterAnnotations(constructorToCall)); |
There was a problem hiding this comment.
This would be easier to read if either the line length or the indentation was modified.
| return ctor; | ||
| } | ||
|
|
||
|
|
| 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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
It's a small utility and I think it's ok to leave it this way.
|
@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: 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
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 |
|
/integrate |
|
Going to push as commit 5cea53d.
Your commit was automatically rebased without conflicts. |
This reimplements
sun.reflect.ReflectionFactory::newConstructorForSerializationwith method handles.This API currently generates the bytecode which fails the verification because
new C; invokespecial A()where the given classCand invoke a no-arg constructor ofC's first non-SerializablesuperclassAis 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.useOldSerializableConstructorsystem 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
Issues
Reviewers
Contributors
<liach@openjdk.org>Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/15600/head:pull/15600$ git checkout pull/15600Update a local copy of the PR:
$ git checkout pull/15600$ git pull https://git.openjdk.org/jdk.git pull/15600/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 15600View PR using the GUI difftool:
$ git pr show -t 15600Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/15600.diff
Webrev
Link to Webrev Comment