On 26/03/2026 13:22, Some Java user wrote:
:

That approach (passing the `target` dir as agent argument through `-javaagent`) might cause problems for concurrent builds, e.g. a Gradle build which concurrently runs tests with different JDK versions. In that case the agent cannot use a static file name for the bootstrap JAR since the concurrent runs might overwrite each others files. So it would again have to create unique / temp files in that directory. Creating temp files in `target` might be somewhat better than creating them in the OS temp dir, but it is also not so great. Especially if the user does not run `mvn clean ...` / `gradle clean ...` that often, for better build performance.

Have you tried giving each test run its own temp directory?


So if an agent was able to delete the file passed to `appendToBootstrapClassLoaderSearch`, that might really be the easiest solution for agent implementations.

This amounts to deleting a JAR file on bootstrap class path while the VM is running.

Note that opening the JAR file with FILE_SHARE_DELETE won't address the on Windows. While the delete may appear to work, the semantics are not the same as Unix and there will be an error somewhere else if something attempts to create a new JAR file with the same name.


Actually, maybe part of the problem is that `appendToBootstrapClassLoaderSearch` takes a JarFile in the first place. I guess from a theoretical perspective something like a `Function<String, byte[]>` (but probably as dedicated interface with `throws IOException`) or a JarInputStream would suffice? Though maybe supporting that within the JVM implementation would be difficult?

It would be feasible to have the VM upcall to invoke this function.

The lower level JVMTI AddToBootstrapClassLoaderSearch (Java agents are implemented as a JVMTI agent) is more flexible in that it allows directories to be added too. It might not be terrible to add overloads of the Instrumentation.appendToXXX methods to take a directory. It wouldn't be hard to try that and see if any issues come up.

-Alan


Reply via email to