-
Notifications
You must be signed in to change notification settings - Fork 39
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
8343449: Nashorn method handle debug logging breaks with log4j-jul #19
Conversation
The `MethodHandleFactory` and especially its `FUNC` static field are heavily used during the static initialization process. To prevent nullability problems in the static `MethodHandleFactory` fields, `StandardMethodHandleFunctionality` relies on `DebugLogger.DISABLED_LOGGER.isEnabled()` being `false` during the initialization process. If this assumption fails (as described in apache/logging-log4j2#3119) the static initialization fails. We improve the above failsafe by: - Replacing the `StandardMethodHandleFunctionality.log` field with a static `MethodHandleFactory.log` field. - The new `log` field is placed last, so it holds the value `null` until the end of static initialization. - All the usages of the `log` fields are checked to ensure that they contain a null-check.
Hi @ppkarwasz, welcome to this OpenJDK project and thanks for contributing! We do not recognize you as Contributor and need to ensure you have signed the Oracle Contributor Agreement (OCA). If you have not signed the OCA, please follow the instructions. Please fill in your GitHub username in the "Username" field of the application. Once you have signed the OCA, please let us know by writing If you already are an OpenJDK Author, Committer or Reviewer, please click here to open a new issue so that we can record that fact. Please use "Add GitHub user ppkarwasz" as summary for the issue. If you are contributing this work on behalf of your employer and your employer has signed the OCA, please let us know by writing |
@ppkarwasz This change now passes all automated pre-integration checks. 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 no new commits pushed to the As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@szegedi) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
...g.openjdk.nashorn/share/classes/org/openjdk/nashorn/internal/lookup/MethodHandleFactory.java
Outdated
Show resolved
Hide resolved
Okay, I dug into this a bit more and also in the analysis in apache/logging-log4j2#3119. Why would OTOH, it's possible that maybe |
The comparison between the configured level and Lines 76 to 81 in 2eb88e4
is basically equivalent to: this.logger.setLevel(loggerLevel);
this.enabled = this.logger.getLevel() != Level.OFF; In
A logger can not be created with If Log4j API is used together with the Log4j Core implementation, we have an option (cf. In general the usage of
Therefore I believe that the code that modifies the logging configuration should be in |
...g.openjdk.nashorn/share/classes/org/openjdk/nashorn/internal/lookup/MethodHandleFactory.java
Outdated
Show resolved
Hide resolved
I think the initialization order here is rather brittle and unfortunate. This could all be avoided if private static final MethodHandle TRACE;
private static final MethodHandle TRACE_RETURN;
private static final MethodHandle TRACE_RETURN_VOID;
static {
try {
TRACE = LOOKUP.findStatic(MethodHandleFactory.class, "traceArgs", MethodType.methodType(void.class, DebugLogger.class, String.class, int.class, Object[].class));
TRACE_RETURN = LOOKUP.findStatic(MethodHandleFactory.class, "traceReturn", MethodType.methodType(Object.class, DebugLogger.class, Object.class));
TRACE_RETURN_VOID = LOOKUP.findStatic(MethodHandleFactory.class, "traceReturnVoid", MethodType.methodType(void.class, DebugLogger.class));
} catch (NoSuchMethodException | IllegalAccessException e) {
throw new LookupException(e);
}
} And also keeping the rest of your changes. |
MethodHandleFactory
MethodHandleFactory
MethodHandleFactory
Alright, I created a JBS issue for this. If you sign the OCA we can move forward with this. |
Thanks.
I submitted it on Tuesday, but it still has a status of "Under review". |
That's fine, I'm sure it'll work its way through in a few days. |
...g.openjdk.nashorn/share/classes/org/openjdk/nashorn/internal/lookup/MethodHandleFactory.java
Outdated
Show resolved
Hide resolved
...g.openjdk.nashorn/share/classes/org/openjdk/nashorn/internal/lookup/MethodHandleFactory.java
Outdated
Show resolved
Hide resolved
...g.openjdk.nashorn/share/classes/org/openjdk/nashorn/internal/lookup/MethodHandleFactory.java
Outdated
Show resolved
Hide resolved
...g.openjdk.nashorn/share/classes/org/openjdk/nashorn/internal/lookup/MethodHandleFactory.java
Outdated
Show resolved
Hide resolved
...g.openjdk.nashorn/share/classes/org/openjdk/nashorn/internal/lookup/MethodHandleFactory.java
Outdated
Show resolved
Hide resolved
I removed a couple of additional |
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.
Looks great! Thank you for taking the time to do this.
/sponsor |
@szegedi The change author (@ppkarwasz) must issue an |
/integrate auto |
@ppkarwasz This pull request will be automatically integrated when it is ready |
/integrate |
/sponsor |
Going to push as commit 5e78947. |
@szegedi @ppkarwasz Pushed as commit 5e78947. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
The
MethodHandleFactory
and especially itsFUNC
static field are heavily used during the static initialization process.To prevent nullability problems in the static
MethodHandleFactory
fields,StandardMethodHandleFunctionality
relies onDebugLogger.DISABLED_LOGGER.isEnabled()
beingfalse
during the initialization process.If this assumption is true, static
MethodHandleFactory
fields will not be accessed byStandardMethodHandleFunctionality
.If this assumption, however, fails (as described in apache/logging-log4j2#3119) the static initialization fails with some unforeseen NPEs.
We improve the above machanism by:
StandardMethodHandleFunctionality.log
field with a static field in the top level class.log
field is placed last, so it holds the valuenull
until the end of static initialization.log
fields are checked to ensure that they contain a null-check.Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/nashorn.git pull/19/head:pull/19
$ git checkout pull/19
Update a local copy of the PR:
$ git checkout pull/19
$ git pull https://git.openjdk.org/nashorn.git pull/19/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 19
View PR using the GUI difftool:
$ git pr show -t 19
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/nashorn/pull/19.diff