Skip to content

Commit 58c7115

Browse files
committed
TruffleFile API does not allow discovery of free and used space on filesystem.
1 parent 6622b17 commit 58c7115

File tree

10 files changed

+491
-18
lines changed

10 files changed

+491
-18
lines changed

sdk/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ This changelog summarizes major changes between GraalVM SDK versions. The main f
1111
* GR-61448 Compilation id (`CompId`) was added to the `opt done` truffle compilation logs. This id matches the compilation id in the output of deoptimization, compilation and code cache logs on HotSpot and SubstrateVM.
1212
* GR-31495 Added the ability to specify language and instrument specific options using `Source.Builder.option(String, String)`. See the language and or tool specific documentation for available options. Available source options may also be reflected using `Instrument.getSourceOptions()` and `Language.getSourceOptions()`.
1313
* GR-55223 The option sandbox.MaxStackFrames is no longer mandatory for the UNTRUSTED polyglot sandbox policy thanks to improved deoptimization handling of compiled code.
14+
* GR-64488 FileSystem implementations can now provide disk-related metadata, such as [total size](https://www.graalvm.org/truffle/javadoc/org/graalvm/polyglot/io/FileSystem.html#getTotalSpace(java.nio.file.Path)), [usable space](https://www.graalvm.org/truffle/javadoc/org/graalvm/polyglot/io/FileSystem.html#getUsableSpace(java.nio.file.Path)), and [unallocated space](https://www.graalvm.org/truffle/javadoc/org/graalvm/polyglot/io/FileSystem.html#getUnallocatedSpace(java.nio.file.Path)).
1415

1516
## Version 24.2.0
1617
* GR-54905 When using Truffle NFI with the Panama backend, native access must now be granted to the Truffle module instead of the NFI Panama module. Use the `--enable-native-access=org.graalvm.truffle` Java command line option to enable the native access for the NFI Panama backend.

sdk/src/org.graalvm.polyglot/snapshot.sigtest

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,9 @@ meth public java.lang.String getSeparator()
713713
meth public java.nio.charset.Charset getEncoding(java.nio.file.Path)
714714
meth public java.nio.file.Path getTempDirectory()
715715
meth public java.nio.file.Path readSymbolicLink(java.nio.file.Path) throws java.io.IOException
716+
meth public long getTotalSpace(java.nio.file.Path) throws java.io.IOException
717+
meth public long getUnallocatedSpace(java.nio.file.Path) throws java.io.IOException
718+
meth public long getUsableSpace(java.nio.file.Path) throws java.io.IOException
716719
meth public static org.graalvm.polyglot.io.FileSystem allowInternalResourceAccess(org.graalvm.polyglot.io.FileSystem)
717720
meth public static org.graalvm.polyglot.io.FileSystem allowLanguageHomeAccess(org.graalvm.polyglot.io.FileSystem)
718721
anno 0 java.lang.Deprecated(boolean forRemoval=false, java.lang.String since="")

sdk/src/org.graalvm.polyglot/src/org/graalvm/polyglot/io/FileSystem.java

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -435,6 +435,63 @@ default boolean isSameFile(Path path1, Path path2, LinkOption... options) throws
435435
return toRealPath(path1, options).equals(toRealPath(path2, options));
436436
}
437437

438+
/**
439+
* Returns the size, in bytes, of the file store that contains the given {@code path}. If the
440+
* file store's size exceeds {@link Long#MAX_VALUE}, {@code Long.MAX_VALUE} is returned.
441+
*
442+
* @param path the path whose file store size is to be determined
443+
* @return the size of the file store in bytes
444+
* @throws UnsupportedOperationException if the file system does not support retrieving file
445+
* store information
446+
* @throws IOException if an I/O error occurs while accessing the file store
447+
* @throws SecurityException if the {@link FileSystem} implementation denied the operation
448+
* @since 25.0.0
449+
*/
450+
default long getTotalSpace(Path path) throws IOException {
451+
throw new UnsupportedOperationException("TotalSpace is not supported");
452+
}
453+
454+
/**
455+
* Returns the number of unallocated bytes in the file store that contains the given
456+
* {@code path}. The returned value represents the raw free space on the storage device,
457+
* regardless of access permissions or user quotas. If the number of unallocated bytes exceeds
458+
* {@link Long#MAX_VALUE}, {@code Long.MAX_VALUE} is returned. Note that the value may be
459+
* imprecise, as it can change at any time due to external I/O operations, including those
460+
* performed outside this virtual machine.
461+
*
462+
* @param path the path whose file store is to be queried
463+
* @return the number of unallocated bytes
464+
* @throws UnsupportedOperationException if the file system does not support retrieving file
465+
* store information
466+
* @throws IOException if an I/O error occurs while accessing the file store
467+
* @throws SecurityException if the {@link FileSystem} implementation denied the operation
468+
* @since 25.0.0
469+
*/
470+
default long getUnallocatedSpace(Path path) throws IOException {
471+
throw new UnsupportedOperationException("UnallocatedSpace is not supported");
472+
}
473+
474+
/**
475+
* Returns the number of bytes available to this Java virtual machine on the file store that
476+
* contains the given {@code path}. Unlike {@link #getUnallocatedSpace(Path)}, this method
477+
* accounts for operating system-level restrictions, user quotas, and file system permissions,
478+
* and therefore may return a smaller value. If the available space exceeds
479+
* {@link Long#MAX_VALUE}, {@code Long.MAX_VALUE} is returned. Note that the returned value may
480+
* be imprecise, as it can change at any time due to external I/O activity, including operations
481+
* performed outside this virtual machine.
482+
*
483+
* @param path the path whose file store is to be queried
484+
* @return the number of usable bytes available to this Java virtual machine
485+
* @throws UnsupportedOperationException if the file system does not support retrieving file
486+
* store information
487+
* @throws IOException if an I/O error occurs while accessing the file store
488+
* @throws SecurityException if the {@link FileSystem} implementation denied the operation
489+
* @since 25.0.0
490+
*/
491+
default long getUsableSpace(Path path) throws IOException {
492+
throw new UnsupportedOperationException("UsableSpace is not supported");
493+
}
494+
438495
/**
439496
* Creates a {@link FileSystem} implementation based on the host Java NIO. The returned instance
440497
* can be used as a delegate by a decorating {@link FileSystem}.

truffle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ This changelog summarizes major changes between Truffle versions relevant to lan
1717
* GR-64533 By default every specialization is now included for {@link GenerateUncached}, except specializations that require a {@link Specialization#limit() limit} and are replaced, those are excluded by default. By setting `@Specialization(excludeForUncached=..)` explicitly the default behavior can be overridden, e.g. to include or exclude a specialization for uncached. Specializations which are no longer compatible with uncached will produce a warning instead of an error for compatibility reasons until all languages are migrated. It is therefore expected that language implementations may see new warnings with this version.
1818
* GR-64124 Added `BytecodeOSRNode.pollOSRBackEdge(BytecodeOSRNode, int)` that supports batch polling for bytecode OSR. Using this method avoids checking for bytecode OSR on every loop backedge.
1919
* GR-64124 Deprecated `BytecodeOSRNode.pollOSRBackEdge(BytecodeOSRNode)`. Use `BytecodeOSRNode.pollOSRBackEdge(BytecodeOSRNode, int)` instead. Please note that the old method did call `TruffleSafepoint.poll(Node)`, but the the new method does not. Please double check that your bytecode interpreter polls Truffle safepoints at loop back-edges.
20+
* GR-64488 Added `TruffleFile#getFileStoreInfo()` providing access to disk-related metadata such as total size, usable space, and unallocated space.
2021

2122
## Version 24.2.0
2223
* GR-60636 Truffle now stops compiling when the code cache fills up on HotSpot. A warning is printed when that happens.

0 commit comments

Comments
 (0)