Skip to content

Commit c16f70e

Browse files
[GR-64647] Fix UnixFileSystemAccessors.reinitialize(...).
PullRequest: graal/20688
2 parents 73a626e + d0cb4a0 commit c16f70e

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

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

+14-9
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
4747
import com.oracle.svm.core.feature.InternalFeature;
4848
import com.oracle.svm.core.option.HostedOptionKey;
49+
import com.oracle.svm.core.util.BasedOnJDKFile;
4950
import com.oracle.svm.core.util.VMError;
5051

5152
import jdk.graal.compiler.options.Option;
@@ -195,12 +196,12 @@ final class Target_sun_nio_fs_UnixFileSystem {
195196
private Target_sun_nio_fs_UnixPath rootDirectory;
196197

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

299+
@BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-25+20/src/java.base/linux/classes/sun/nio/fs/LinuxFileSystem.java#L44-L46")
300+
@BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-25+20/src/java.base/linux/classes/sun/nio/fs/LinuxFileSystemProvider.java#L45-L47")
301+
@BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-25+20/src/java.base/unix/classes/sun/nio/fs/UnixFileSystemProvider.java#L75-L77")
302+
@BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-25+20/src/java.base/unix/classes/sun/nio/fs/UnixFileSystem.java#L78-L108")
298303
private static synchronized void reinitialize(Target_sun_nio_fs_UnixFileSystem that) {
299304
if (that.needsReinitialization != NeedsReinitializationProvider.STATUS_NEEDS_REINITIALIZATION) {
300305
/* Field initialized is volatile, so double-checked locking is OK. */
@@ -311,10 +316,10 @@ private static synchronized void reinitialize(Target_sun_nio_fs_UnixFileSystem t
311316
* with the same value it is already set to, so this is harmless. All other field writes are
312317
* redirected to the set-accessors of this class and write the injected fields.
313318
*
314-
* Note that the `System.getProperty("user.dir")` value is always used when re-initializing
315-
* a UnixFileSystem, which is not the case with the WindowsFileSystem (JDK-8066709).
319+
* Note that the `StaticProperty.userDir()` value is always used when re-initializing a
320+
* UnixFileSystem, which is not the case with the WindowsFileSystem (JDK-8066709).
316321
*/
317-
that.originalConstructor(that.provider, System.getProperty(UserSystemProperty.DIR));
322+
that.originalConstructor(that.provider, StaticProperty.userDir());
318323

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

0 commit comments

Comments
 (0)