-
Notifications
You must be signed in to change notification settings - Fork 923
Reduce metaspace usage by moving to method handles instead of auxiliary classes. #2448
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
Draft
aardvark179
wants to merge
3
commits into
mozilla:master
Choose a base branch
from
aardvark179:aardvark179-metaspace-usage
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
176 changes: 115 additions & 61 deletions
176
rhino/src/main/java/org/mozilla/javascript/optimizer/Bootstrapper.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
rhino/src/main/java/org/mozilla/javascript/optimizer/MHJSCode.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| package org.mozilla.javascript.optimizer; | ||
|
|
||
| import java.lang.invoke.MethodHandle; | ||
| import java.lang.invoke.MethodHandles; | ||
| import java.lang.invoke.MethodType; | ||
| import java.lang.reflect.InvocationTargetException; | ||
| import org.mozilla.classfile.ClassFileWriter; | ||
| import org.mozilla.javascript.JSCode; | ||
| import org.mozilla.javascript.ScriptOrFn; | ||
|
|
||
| /** Subclass of {@link JSCode} for compiled Java methods. */ | ||
| public abstract class MHJSCode<T extends ScriptOrFn<T>> extends JSCode<T> { | ||
|
|
||
| /** | ||
| * Builder environment used in the creation of {@link OptJSCode} objects. This hold information | ||
| * on whether literals will need to be initialised, and a reference to the class containing the | ||
| * method implementation once it has been built. | ||
| */ | ||
| public static class BuilderEnv { | ||
| boolean hasRegExpLiterals; | ||
| boolean hasTemplateLiterals; | ||
| Class<?> compiledClass; | ||
| final String className; | ||
|
|
||
| public BuilderEnv(String className) { | ||
| this.className = className; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * A builder for {@link OptJSCode}. Holds the builder environment, names and types of execute | ||
| * and resume methods, an index within the set of descriptors owned by the class, and the built | ||
| * version of the object (used to avoid generating duplicate classes at runtime). | ||
| */ | ||
| public abstract static class Builder<T extends ScriptOrFn<T>> extends JSCode.Builder<T> { | ||
| final BuilderEnv env; | ||
| String methodName; | ||
| String methodType; | ||
| String resumeName; | ||
| String resumeType; | ||
| int index; | ||
| MHJSCode<T> built; | ||
|
|
||
| public Builder(BuilderEnv env) { | ||
| this.env = env; | ||
| } | ||
|
|
||
| @Override | ||
| public JSCode<T> build() { | ||
| if (built != null) { | ||
| return built; | ||
| } | ||
| try { | ||
| MethodHandles.Lookup lookup = | ||
| (MethodHandles.Lookup) | ||
| env.compiledClass | ||
| .getDeclaredMethod("getLookup") | ||
| .invoke(env.compiledClass); | ||
| MethodHandle exec = | ||
| lookup.findStatic( | ||
| env.compiledClass, | ||
| methodName, | ||
| MethodType.fromMethodDescriptorString( | ||
| methodType, env.compiledClass.getClassLoader())); | ||
| MethodHandle resume = null; | ||
| if (resumeName != null) { | ||
| resume = | ||
| lookup.findStatic( | ||
| env.compiledClass, | ||
| resumeName, | ||
| MethodType.fromMethodDescriptorString( | ||
| resumeType, env.compiledClass.getClassLoader())); | ||
| } | ||
| return buildCode(exec, resume); | ||
| } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { | ||
| throw new Error("Gnerated class did not contain expected methods", e); | ||
| } | ||
| } | ||
|
|
||
| protected abstract MHJSCode<T> buildCode(MethodHandle exec, MethodHandle resume); | ||
|
|
||
| public abstract void buildByteCode(ClassFileWriter cfw, String mainClass); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you keep trying to sneak this in unrelated PRs... 🤣 here's an actual one: #2451