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

Replaced getUnsafeInstance.defineClass by MethodHandles.privateLookupIn #19

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.io.IOException;
import java.io.OutputStream;
import java.lang.annotation.Annotation;
import java.lang.invoke.MethodHandles;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.security.ProtectionDomain;
Expand Down Expand Up @@ -1231,14 +1232,10 @@ else if (!genericParameterBuilders.isEmpty()) {

_hasBeenCreated = true;

_generatedClass = (Class<T>) getUnsafeInstance().defineClass(
fullName,
classBytes,
0,
classBytes.length,
Thread.currentThread().getContextClassLoader(),
_protectionDomain
);
MethodHandles.Lookup lookup = MethodHandles.lookup();
MethodHandles.Lookup privateLookup = MethodHandles.privateLookupIn(Class.forName(fullName), lookup);
Copy link
Owner

Choose a reason for hiding this comment

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

Did you test this? I don't see how Class.forName(fullName) could work, since the class doesn't exist until the next line.

Copy link
Author

Choose a reason for hiding this comment

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

hi!

it is definitely tested in usual workloads. Is there some cornercase you think is sure to hit those lines?

Copy link
Contributor

@nbauma109 nbauma109 Feb 2, 2022

Choose a reason for hiding this comment

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

@mstrobel : You have unit tests that cover that part of the code
@judovana: I'm confused how you can test this without changing JDK version from 1.7 to 11 in the build.gradle? I've run the build and I have 31 test failures (that can be reduced to 15 with the PR #35), failures such as variable renames that appear trivial at first but can cause collisions and loss of meaningful naming (x instead of b for boolean, etc...) and compiler methods such as makeConcatWithConstants not interpreted anymore (@mstrobel: was that supported?)

_generatedClass = (Class<T>)privateLookup.defineClass(classBytes);


RuntimeHelpers.ensureClassInitialized(_generatedClass);

Expand Down