-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Agent should not open java.lang
package to unnamed module of the application class loader
#1334
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
Conversation
@marchof foreseeing your question about why this is still a draft 😉 because the code requires polishing and the addition of in-code comments, I plan to work on this a bit later. But of course, feel free to review to provide your suggestions/comments - as usual, they are more than welcome 🤗 |
First of all, thanks for digging deeper into this! I was too fast in closing this issue. Just some high level remarks:
|
} | ||
|
||
Instrumentation.class.getMethod("redefineModule", // |
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.
Maybe for consistency and better readability this code can be extracted to a private method like getModule()
e69755a
to
223a599
Compare
…the application class loader
Sure. First of all for such a test case we need a "stable" private JDK API 😆 e.g.
because IMO less likely that any of the constructors of Secondly on 9 <= JDK < 16 we either need
leads to
instead of
on JDK < 9
so for simplicity I propose to test only JDK >= 16. Finally to test the agent we need to
And I'll work on addressing other comments a bit later. |
👍 |
Note that custom ClassLoader delegates to the parent for everything except
so ASM classes for bytecode generation are still loaded by the same ClassLoader as before if that's your concern. Unfortunately to create ClassLoader only for public Class<?> loadClass(String name)
throws ClassNotFoundException {
- if (!name.startsWith(InjectedClassRuntime.class.getName())) {
+ if (!name.equals(Lookup.class.getName())) {
return super.loadClass(name);
} while retaining
because according to https://docs.oracle.com/javase/specs/jvms/se17/html/jvms-5.html#jvms-5.4.3.1
reference to This means that to use custom ClassLoader only for Currently So I pushed two commits: Both achieve the same result. What are the benefits of the second one over the first one? Custom ClassLoader and And a bit fewer CPU cycles at runtime creation because of fewer Strings comparisons in custom ClassLoader. Then some of these saved CPU cycles are wasted on reflective call of
and only two of them
will be defined by this custom ClassLoader. Also to me seems that the second one requires the addition of even more in-code comments than the first one, e.g. to explain use of Thus I'm really not sure whether the second commit is actually needed or not. @marchof WDYT? |
java.base
module to unnamed module of the application class loaderjava.lang
package to unnamed module of the application class loader
org.jacoco.core/src/org/jacoco/core/runtime/InjectedClassRuntime.java
Outdated
Show resolved
Hide resolved
Hi @Godin, now as it properly encapsulated in But in |
@@ -58,58 +55,23 @@ public static void premain(final String options, final Instrumentation inst) | |||
private static IRuntime createRuntime(final Instrumentation inst) |
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.
To further encapsulate the implementation details of InjectedClassRuntime
I would add a static method isSupported()
to this class. The code here in PreMain then reduces to:
private static IRuntime createRuntime(final Instrumentation inst)
throws Exception {
if (InjectedClassRuntime.isSupported()) {
return InjectedClassRuntime.createFor(inst);
} else {
return ModifiedSystemClassRuntime.createFor(inst,
"java/lang/UnknownError");
}
}
org.jacoco.core/src/org/jacoco/core/runtime/InjectedClassRuntime.java
Outdated
Show resolved
Hide resolved
This reverts commit 6049ed3.
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.
Wow very impressed by all the technical details of this fix! I only have two minor cleanup proposals.
@marchof actually maybe I myself have one more 😆 I have a feeling that maybe better to move |
I fully agree, except that |
Here are some ideas about name:
Also what do you think about just moving the method into |
I wonder whether this |
Seems that the change b865890 causes failure https://ci.eclipse.org/glassfish/job/hk2/job/PR-819/3/console. I've not investigated fully, it's possible that upgrade proposed in needs some additional modifications. Reporting just for cross-linking, while it's relatively fresh. |
Evgeny, thanks for checking. |
Since jacoco 0.8.9 it does not open the java.lang package anymore, so we need to do that on our own. See "Agent should not open java.lang package to unnamed module of the application class loader" jacoco/jacoco#1334
Since jacoco 0.8.9 it does not open the java.lang package anymore, so we need to do that on our own. See "Agent should not open java.lang package to unnamed module of the application class loader" jacoco/jacoco#1334
Since jacoco 0.8.9 it does not open the java.lang package anymore, so we need to do that on our own. See "Agent should not open java.lang package to unnamed module of the application class loader" jacoco/jacoco#1334
This is only for JDK >= 16. Without this fix some unit tests that uses Mockito will fail with the following error: ``` Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @cafebabe ``` We notice this error only after upgrade JaCoCo to version 0.8.9 because prior this version the error was being hide by a side effect of JaCoCo. See: jacoco/jacoco#1334 See: jacoco/jacoco#1328 See: #86 (comment) See: #86 (comment) See: #86 (comment) See: #87 This is a workaround and the added profile should be removed in the future in order of a definitive fix (maybe Mockito upgrade). This reverts commit 31a8d68.
This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [org.apache.maven.plugins:maven-compiler-plugin](https://maven.apache.org/plugins/) | build | minor | `3.10.1` -> `3.11.0` | | [org.jacoco:jacoco-maven-plugin](https://www.jacoco.org/jacoco/trunk/doc/maven.html) ([source](https://github.com/jacoco/jacoco)) | build | patch | `0.8.8` -> `0.8.10` | | [com.graphhopper:graphhopper-map-matching](https://www.graphhopper.com) ([source](https://github.com/graphhopper/graphhopper)) | compile | patch | `7.0` -> `7.0-testgithub6` | | [com.graphhopper:graphhopper-core](https://www.graphhopper.com) ([source](https://github.com/graphhopper/graphhopper)) | compile | patch | `7.0` -> `7.0-testgithub6` | | [org.springframework.boot:spring-boot-starter-parent](https://spring.io/projects/spring-boot) ([source](https://github.com/spring-projects/spring-boot)) | parent | patch | `3.0.5` -> `3.0.6` | --- ### Release Notes <details> <summary>jacoco/jacoco</summary> ### [`v0.8.10`](https://github.com/jacoco/jacoco/releases/tag/v0.8.10): 0.8.10 [Compare Source](jacoco/jacoco@v0.8.9...v0.8.10) #### Fixed bugs - Agent should not require configuration of permissions for `SecurityManager` outside of its `codeBase` (GitHub [#​1425](jacoco/jacoco#1425)). ### [`v0.8.9`](https://github.com/jacoco/jacoco/releases/tag/v0.8.9): 0.8.9 [Compare Source](jacoco/jacoco@v0.8.8...v0.8.9) #### New Features - JaCoCo now officially supports Java 19 and 20 (GitHub [#​1371](jacoco/jacoco#1371), [#​1386](jacoco/jacoco#1386)). - Experimental support for Java 21 class files (GitHub [#​1386](jacoco/jacoco#1386)). - Add parameter to include the current project in the `report-aggregate` Maven goal (GitHub [#​1007](jacoco/jacoco#1007)). - Component accessors generated by the Java compilers for records are filtered out during generation of report. Contributed by Tesla Zhang (GitHub [#​1393](jacoco/jacoco#1393)). #### Fixed bugs - Agent should not open `java.lang` package to unnamed module of the application class loader (GitHub [#​1334](jacoco/jacoco#1334)). #### Non-functional Changes - JaCoCo now depends on ASM 9.5 (GitHub [#​1299](jacoco/jacoco#1299), [#​1368](jacoco/jacoco#1368), [#​1416](jacoco/jacoco#1416)). - JaCoCo build now requires JDK 11 (GitHub [#​1413](jacoco/jacoco#1413)). </details> <details> <summary>graphhopper/graphhopper</summary> ### [`v7.0-pre2`](graphhopper/graphhopper@7.0-pre1...7.0-pre2) [Compare Source](graphhopper/graphhopper@7.0-pre1...7.0-pre2...
This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [org.apache.maven.plugins:maven-compiler-plugin](https://maven.apache.org/plugins/) | build | minor | `3.10.1` -> `3.11.0` | | [org.jacoco:jacoco-maven-plugin](https://www.jacoco.org/jacoco/trunk/doc/maven.html) ([source](https://github.com/jacoco/jacoco)) | build | patch | `0.8.8` -> `0.8.10` | | [com.graphhopper:graphhopper-map-matching](https://www.graphhopper.com) ([source](https://github.com/graphhopper/graphhopper)) | compile | patch | `7.0` -> `7.0-testgithub6` | | [com.graphhopper:graphhopper-core](https://www.graphhopper.com) ([source](https://github.com/graphhopper/graphhopper)) | compile | patch | `7.0` -> `7.0-testgithub6` | | [org.springframework.boot:spring-boot-starter-parent](https://spring.io/projects/spring-boot) ([source](https://github.com/spring-projects/spring-boot)) | parent | patch | `3.0.5` -> `3.0.6` | --- ### Release Notes <details> <summary>jacoco/jacoco</summary> ### [`v0.8.10`](https://github.com/jacoco/jacoco/releases/tag/v0.8.10): 0.8.10 [Compare Source](jacoco/jacoco@v0.8.9...v0.8.10) #### Fixed bugs - Agent should not require configuration of permissions for `SecurityManager` outside of its `codeBase` (GitHub [#​1425](jacoco/jacoco#1425)). ### [`v0.8.9`](https://github.com/jacoco/jacoco/releases/tag/v0.8.9): 0.8.9 [Compare Source](jacoco/jacoco@v0.8.8...v0.8.9) #### New Features - JaCoCo now officially supports Java 19 and 20 (GitHub [#​1371](jacoco/jacoco#1371), [#​1386](jacoco/jacoco#1386)). - Experimental support for Java 21 class files (GitHub [#​1386](jacoco/jacoco#1386)). - Add parameter to include the current project in the `report-aggregate` Maven goal (GitHub [#​1007](jacoco/jacoco#1007)). - Component accessors generated by the Java compilers for records are filtered out during generation of report. Contributed by Tesla Zhang (GitHub [#​1393](jacoco/jacoco#1393)). #### Fixed bugs - Agent should not open `java.lang` package to unnamed module of the application class loader (GitHub [#​1334](jacoco/jacoco#1334)). #### Non-functional Changes - JaCoCo now depends on ASM 9.5 (GitHub [#​1299](jacoco/jacoco#1299), [#​1368](jacoco/jacoco#1368), [#​1416](jacoco/jacoco#1416)). - JaCoCo build now requires JDK 11 (GitHub [#​1413](jacoco/jacoco#1413)). </details> <details> <summary>graphhopper/graphhopper</summary> ### [`v7.0-pre2`](graphhopper/graphhopper@7.0-pre1...7.0-pre2) [Compare Source](graphhopper/graphhopper@7.0-pre1...7.0-pre2...
Fixes #1328