RFR: 8307944: ClassFileDumper should only load java.nio.file.Path if enabled

Mandy Chung mchung at openjdk.org
Thu May 25 20:45:34 UTC 2023


Change `ClassFileDumper` constructor to take a `String` rather than `Path` to avoid the file system implementation classes loaded during startup.  In addition, `FilePermission` also causes the default file system to be initialized. 

This patch changes `ClassFileDumper` to validate the given path only if it's enabled and not to use limited `doPrivileged` to avoid the initialization of `FilePermission` class and the file system implementation classes by default.

This patch also changes `ClassFileDumper::write` to use `File` instead of `Path` because of JDK-8306678.  `OperatingSystem::<clinit>` causes `Enum::valueOf` to be called which calls core reflection which in turns invokes method handles.   If `-Djdk.invoke.MethodHandle.dumpMethodHandleInternals` is set, VM initialization would fail because `BootLoader::<clinit>` causes `ClassLoaderHelper` to initialize which in turn causes `OperatingSystem` be initialized.   If additional LFs are spinned and dumped, if `ClassFileDumper` uses `Path` for writing, `FileSystems::getDefault` would fail with `NullPointerException` because it calls `BootLoader.loadLibrary` which is not fully initialized. 

A separate issue will be filed to follow up the startup overhead of `OperatingSystem`.

-------------

Commit messages:
 - 8307944: ClassFileDumper should only load java.nio.file.Path if enabled

Changes: https://git.openjdk.org/jdk/pull/14160/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=14160&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8307944
  Stats: 184 lines in 6 files changed: 85 ins; 56 del; 43 mod
  Patch: https://git.openjdk.org/jdk/pull/14160.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/14160/head:pull/14160

PR: https://git.openjdk.org/jdk/pull/14160


More information about the core-libs-dev mailing list