Skip to content

Commit 88507f0

Browse files
christianhaeublzakkak
authored andcommitted
Fix UnixFileSystemAccessors.reinitialize(...).
(cherry picked from commit d0cb4a0)
1 parent 92e772e commit 88507f0

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/FileSystemProviderSupport.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
import com.oracle.svm.core.feature.InternalFeature;
5050
import com.oracle.svm.core.option.HostedOptionKey;
5151

52+
import jdk.internal.util.StaticProperty;
53+
5254
public final class FileSystemProviderSupport {
5355

5456
public static class Options {
@@ -193,12 +195,12 @@ final class Target_sun_nio_fs_UnixFileSystem {
193195
private Target_sun_nio_fs_UnixPath rootDirectory;
194196

195197
/**
196-
* Flag to check if re-initialization at run time already happened. The initial value of this
197-
* flag in the image heap is non-zero, and it is set to zero when re-initialization is done.
198-
* This ensures that UnixFileSystem instances allocated at run time are not re-initialized,
199-
* because they are allocated with the field value. Note that UnixFileSystem instances should
200-
* not be allocated at run time, since only the singleton from the image heap should exist.
201-
* However, there were JDK bugs in various JDK versions where unwanted allocations happened.
198+
* Flag to check if reinitialization at run time is needed. For objects in the image heap, this
199+
* field is initially non-zero and set to zero after reinitialization. If UnixFileSystem
200+
* instances are allocated at run time, the field will be set to zero right away (default value)
201+
* as there is no need for reinitialization. Note that UnixFileSystem instances should not be
202+
* allocated at run time, as only the singleton from the image heap should exist. However, there
203+
* were JDK bugs in various JDK versions where unwanted allocations happened.
202204
*/
203205
@Inject //
204206
@RecomputeFieldValue(kind = Kind.Custom, declClass = NeedsReinitializationProvider.class)//
@@ -293,6 +295,10 @@ static void setRootDirectory(Target_sun_nio_fs_UnixFileSystem that, Target_sun_n
293295
that.injectedRootDirectory = value;
294296
}
295297

298+
// @BasedOnJDKFile("https://github.com/openjdk/jdk21u-dev/blob/jdk-21.0.7-ga/src/java.base/linux/classes/sun/nio/fs/LinuxFileSystem.java#L44-L46")
299+
// @BasedOnJDKFile("https://github.com/openjdk/jdk21u-dev/blob/jdk-21.0.7-ga/src/java.base/linux/classes/sun/nio/fs/LinuxFileSystemProvider.java#L45-L47")
300+
// @BasedOnJDKFile("https://github.com/openjdk/jdk21u-dev/blob/jdk-21.0.7-ga/src/java.base/unix/classes/sun/nio/fs/UnixFileSystemProvider.java#L77-L79")
301+
// @BasedOnJDKFile("https://github.com/openjdk/jdk21u-dev/blob/jdk-21.0.7-ga/src/java.base/unix/classes/sun/nio/fs/UnixFileSystem.java#L80-L107")
296302
private static synchronized void reinitialize(Target_sun_nio_fs_UnixFileSystem that) {
297303
if (that.needsReinitialization != NeedsReinitializationProvider.STATUS_NEEDS_REINITIALIZATION) {
298304
/* Field initialized is volatile, so double-checked locking is OK. */
@@ -309,10 +315,10 @@ private static synchronized void reinitialize(Target_sun_nio_fs_UnixFileSystem t
309315
* with the same value it is already set to, so this is harmless. All other field writes are
310316
* redirected to the set-accessors of this class and write the injected fields.
311317
*
312-
* Note that the `System.getProperty("user.dir")` value is always used when re-initializing
313-
* a UnixFileSystem, which is not the case with the WindowsFileSystem (JDK-8066709).
318+
* Note that the `StaticProperty.userDir()` value is always used when re-initializing a
319+
* UnixFileSystem, which is not the case with the WindowsFileSystem (JDK-8066709).
314320
*/
315-
that.originalConstructor(that.provider, System.getProperty("user.dir"));
321+
that.originalConstructor(that.provider, StaticProperty.userDir());
316322

317323
/*
318324
* Now the object is completely re-initialized and can be used by any thread without

0 commit comments

Comments
 (0)