Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ public static short safeToShort(int v) {
return (short) v;
}

public static int safeToUInt(long v) {
assert isUInt(v);
return (int) v;
}

public static int safeToInt(long v) {
assert isInt(v);
return (int) v;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
import com.oracle.svm.core.thread.PlatformThreads;
import com.oracle.svm.core.thread.VMOperation;
import com.oracle.svm.core.thread.VMThreads;
import com.oracle.svm.core.threadlocal.VMThreadLocalMTSupport;
import com.oracle.svm.core.util.TimeUtils;
import com.oracle.svm.core.util.VMError;

Expand Down Expand Up @@ -179,7 +180,6 @@ boolean collectWithoutAllocating(GCCause cause, boolean forceFullGC) {
int size = SizeOf.get(CollectionVMOperationData.class);
CollectionVMOperationData data = StackValue.get(size);
UnmanagedMemoryUtil.fill((Pointer) data, WordFactory.unsigned(size), (byte) 0);
data.setNativeVMOperation(collectOperation);
data.setCauseId(cause.getId());
data.setRequestingEpoch(getCollectionEpoch());
data.setRequestingNanoTime(System.nanoTime());
Expand Down Expand Up @@ -947,7 +947,9 @@ private void walkThreadLocals() {
if (SubstrateOptions.MultiThreaded.getValue()) {
Timer walkThreadLocalsTimer = timers.walkThreadLocals.open();
try {
ThreadLocalMTWalker.walk(greyToBlackObjRefVisitor);
for (IsolateThread isolateThread = VMThreads.firstThread(); isolateThread.isNonNull(); isolateThread = VMThreads.nextThread(isolateThread)) {
VMThreadLocalMTSupport.singleton().walk(isolateThread, greyToBlackObjRefVisitor);
}
} finally {
walkThreadLocalsTimer.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ public boolean walkImageHeapObjects(ObjectVisitor visitor) {
@Override
public boolean walkCollectedHeapObjects(ObjectVisitor visitor) {
VMOperation.guaranteeInProgressAtSafepoint("Must only be called at a safepoint");
ThreadLocalAllocation.disableAndFlushForAllThreads();
return getYoungGeneration().walkObjects(visitor) && getOldGeneration().walkObjects(visitor);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
import org.graalvm.nativeimage.Platforms;

import com.oracle.svm.core.SubstrateGCOptions;
import com.oracle.svm.core.util.DuplicatedInNativeCode;
import com.oracle.svm.core.code.CodeInfo;
import com.oracle.svm.core.code.CodeInfoAccess;
import com.oracle.svm.core.code.RuntimeCodeCache.CodeInfoVisitor;
import com.oracle.svm.core.code.RuntimeCodeInfoAccess;
import com.oracle.svm.core.code.UntetheredCodeInfoAccess;
import com.oracle.svm.core.heap.ObjectReferenceVisitor;
import com.oracle.svm.core.util.DuplicatedInNativeCode;

/**
* References from the runtime compiled code to the Java heap must be considered either strong or
Expand All @@ -58,7 +58,7 @@ final class RuntimeCodeCacheWalker implements CodeInfoVisitor {

@Override
@DuplicatedInNativeCode
public <T extends CodeInfo> boolean visitCode(T codeInfo) {
public boolean visitCode(CodeInfo codeInfo) {
if (RuntimeCodeInfoAccess.areAllObjectsOnImageHeap(codeInfo)) {
return true;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ public PosixRawFileOperationSupport(boolean useNativeByteOrder) {
super(useNativeByteOrder);
}

@Override
public RawFileDescriptor create(File file, FileCreationMode creationMode, FileAccessMode accessMode) {
String path = file.getPath();
int flags = parseMode(creationMode) | parseMode(accessMode);

try (CTypeConversion.CCharPointerHolder cPath = CTypeConversion.toCString(path)) {
return WordFactory.signed(Fcntl.NoTransitions.open(cPath.get(), flags, DEFAULT_PERMISSIONS));
}
}

@Override
public RawFileDescriptor open(File file, FileAccessMode mode) {
String path = file.getPath();
Expand Down Expand Up @@ -83,24 +93,24 @@ public boolean close(RawFileDescriptor fd) {

@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
@Override
public SignedWord size(RawFileDescriptor fd) {
public long size(RawFileDescriptor fd) {
int posixFd = getPosixFileDescriptor(fd);
return PosixStat.getSize(posixFd);
}

@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
@Override
public SignedWord position(RawFileDescriptor fd) {
public long position(RawFileDescriptor fd) {
int posixFd = getPosixFileDescriptor(fd);
return Unistd.NoTransitions.lseek(posixFd, WordFactory.signed(0), Unistd.SEEK_CUR());
return Unistd.NoTransitions.lseek(posixFd, WordFactory.signed(0), Unistd.SEEK_CUR()).rawValue();
}

@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
@Override
public boolean seek(RawFileDescriptor fd, SignedWord position) {
public boolean seek(RawFileDescriptor fd, long position) {
int posixFd = getPosixFileDescriptor(fd);
SignedWord newPos = Unistd.NoTransitions.lseek(posixFd, position, Unistd.SEEK_SET());
return position.equal(newPos);
SignedWord newPos = Unistd.NoTransitions.lseek(posixFd, WordFactory.signed(position), Unistd.SEEK_SET());
return position == newPos.rawValue();
}

@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
Expand All @@ -127,15 +137,15 @@ public boolean write(RawFileDescriptor fd, Pointer data, UnsignedWord size) {

@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
@Override
public SignedWord read(RawFileDescriptor fd, Pointer buffer, UnsignedWord bufferSize) {
public long read(RawFileDescriptor fd, Pointer buffer, UnsignedWord bufferSize) {
int posixFd = getPosixFileDescriptor(fd);

SignedWord readBytes;
do {
readBytes = Unistd.NoTransitions.read(posixFd, buffer, bufferSize);
} while (readBytes.equal(-1) && LibC.errno() == Errno.EINTR());

return readBytes;
return readBytes.rawValue();
}

@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
Expand All @@ -145,14 +155,25 @@ private static int getPosixFileDescriptor(RawFileDescriptor fd) {
return result;
}

private static int parseMode(FileCreationMode mode) {
switch (mode) {
case CREATE:
return Fcntl.O_CREAT() | Fcntl.O_EXCL();
case CREATE_OR_REPLACE:
return Fcntl.O_CREAT() | Fcntl.O_TRUNC();
default:
throw VMError.shouldNotReachHere();
}
}

private static int parseMode(FileAccessMode mode) {
switch (mode) {
case READ:
return Fcntl.O_RDONLY();
case READ_WRITE:
return Fcntl.O_RDWR() | Fcntl.O_CREAT();
return Fcntl.O_RDWR();
case WRITE:
return Fcntl.O_WRONLY() | Fcntl.O_CREAT();
return Fcntl.O_WRONLY();
default:
throw VMError.shouldNotReachHere();
}
Expand All @@ -162,14 +183,14 @@ private static int parseMode(FileAccessMode mode) {
@AutomaticallyRegisteredFeature
class PosixRawFileOperationFeature implements InternalFeature {
@Override
public void beforeAnalysis(BeforeAnalysisAccess access) {
public void afterRegistration(AfterRegistrationAccess access) {
ByteOrder nativeByteOrder = ByteOrder.nativeOrder();
assert nativeByteOrder == ByteOrder.LITTLE_ENDIAN || nativeByteOrder == ByteOrder.BIG_ENDIAN;

PosixRawFileOperationSupport littleEndianSupport = new PosixRawFileOperationSupport(ByteOrder.LITTLE_ENDIAN == nativeByteOrder);
PosixRawFileOperationSupport bigEndianSupport = new PosixRawFileOperationSupport(ByteOrder.BIG_ENDIAN == nativeByteOrder);
PosixRawFileOperationSupport nativeByteOrderSupport = nativeByteOrder == ByteOrder.LITTLE_ENDIAN ? littleEndianSupport : bigEndianSupport;
PosixRawFileOperationSupport littleEndian = new PosixRawFileOperationSupport(ByteOrder.LITTLE_ENDIAN == nativeByteOrder);
PosixRawFileOperationSupport bigEndian = new PosixRawFileOperationSupport(ByteOrder.BIG_ENDIAN == nativeByteOrder);
PosixRawFileOperationSupport nativeOrder = nativeByteOrder == ByteOrder.LITTLE_ENDIAN ? littleEndian : bigEndian;

ImageSingletons.add(RawFileOperationSupportHolder.class, new RawFileOperationSupportHolder(littleEndianSupport, bigEndianSupport, nativeByteOrderSupport));
ImageSingletons.add(RawFileOperationSupportHolder.class, new RawFileOperationSupportHolder(littleEndian, bigEndian, nativeOrder));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@

import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platforms;
import org.graalvm.word.SignedWord;
import org.graalvm.word.WordFactory;

import com.oracle.svm.core.Uninterruptible;
import com.oracle.svm.core.graal.stackvalue.UnsafeStackValue;
Expand All @@ -54,7 +52,7 @@ public static boolean isOpen(int fd) {
}

@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
public static SignedWord getSize(int fd) {
public static long getSize(int fd) {
long size = -1;
if (Platform.includedIn(Platform.LINUX.class)) {
LinuxStat.stat64 stat = UnsafeStackValue.get(LinuxStat.stat64.class);
Expand All @@ -67,7 +65,7 @@ public static SignedWord getSize(int fd) {
size = stat.st_size();
}
}
return WordFactory.signed(size);
return size;
}

@Platforms(Platform.HOSTED_ONLY.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ public class Fcntl {
@CConstant
public static native int O_CREAT();

@CConstant
public static native int O_TRUNC();

@CConstant
public static native int O_EXCL();

public static class NoTransitions {
@CFunction(value = "openSII", transition = Transition.NO_TRANSITION)
public static native int open(CCharPointer pathname, int flags, int mode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
import com.oracle.svm.core.util.VMError;

/**
* Legacy implementation, only used by other legacy code (see GR-44538).
*
* Posix implementation of allocation-free output stream created from FileOutputStream.
*
* The limitation to Linux and Darwin is necessary because the implementation currently uses
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
import org.graalvm.nativeimage.ProcessProperties;
import org.graalvm.nativeimage.VMRuntime;

import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
import com.oracle.svm.core.feature.InternalFeature;
import com.oracle.svm.core.jdk.RuntimeSupport;
import com.oracle.svm.core.log.Log;
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;

import sun.misc.Signal;
import sun.misc.SignalHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,27 +142,28 @@ private static int runCore() {
*/
private static int runCore0() {
try {
if (SubstrateOptions.ParseRuntimeOptions.getValue()) {
/*
* When options are not parsed yet, it is also too early to run the startup hooks
* because they often depend on option values. The user is expected to manually run
* the startup hooks after setting all option values.
*/
VMRuntime.initialize();
}

if (SubstrateOptions.DumpHeapAndExit.getValue()) {
if (VMInspectionOptions.hasHeapDumpSupport()) {
String absoluteHeapDumpPath = SubstrateOptions.getHeapDumpPath(SubstrateOptions.Name.getValue() + ".hprof");
VMRuntime.dumpHeap(absoluteHeapDumpPath, true);
System.out.println("Heap dump created at '" + absoluteHeapDumpPath + "'.");
return 0;
} else {
System.err.println("Unable to dump heap. Heap dumping is only supported for native executables built with `" + VMInspectionOptions.getHeapdumpsCommandArgument() + "`.");
System.err.println("Unable to dump heap. Heap dumping is only supported on Linux and MacOS for native executables built with `" +
VMInspectionOptions.getHeapdumpsCommandArgument() + "`.");
return 1;
}
}

if (SubstrateOptions.ParseRuntimeOptions.getValue()) {
/*
* When options are not parsed yet, it is also too early to run the startup hooks
* because they often depend on option values. The user is expected to manually run
* the startup hooks after setting all option values.
*/
VMRuntime.initialize();
}

ThreadListenerSupport.get().beforeThreadRun();

// Ensure that native code using JNI_GetCreatedJavaVMs finds this isolate.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.graalvm.compiler.options.OptionType;
import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platform.WINDOWS;
import org.graalvm.nativeimage.Platforms;

import com.oracle.svm.core.option.APIOption;
import com.oracle.svm.core.option.HostedOptionKey;
Expand All @@ -61,6 +62,7 @@ public final class VMInspectionOptions {
public static final HostedOptionKey<LocatableMultiOptionValue.Strings> EnableMonitoringFeatures = new HostedOptionKey<>(LocatableMultiOptionValue.Strings.buildWithCommaDelimiter(),
VMInspectionOptions::validateEnableMonitoringFeatures);

@Platforms(Platform.HOSTED_ONLY.class)
public static void validateEnableMonitoringFeatures(@SuppressWarnings("unused") OptionKey<?> optionKey) {
Set<String> enabledFeatures = getEnabledMonitoringFeatures();
if (enabledFeatures.contains(MONITORING_DEFAULT_NAME)) {
Expand All @@ -77,6 +79,7 @@ public static void validateEnableMonitoringFeatures(@SuppressWarnings("unused")
}
}

@Platforms(Platform.HOSTED_ONLY.class)
private static String getDefaultMonitoringCommandArgument() {
return SubstrateOptionsParser.commandArgument(EnableMonitoringFeatures, MONITORING_DEFAULT_NAME);
}
Expand All @@ -86,7 +89,7 @@ public static String getHeapdumpsCommandArgument() {
return SubstrateOptionsParser.commandArgument(EnableMonitoringFeatures, MONITORING_HEAPDUMP_NAME);
}

public static Set<String> getEnabledMonitoringFeatures() {
private static Set<String> getEnabledMonitoringFeatures() {
return new HashSet<>(EnableMonitoringFeatures.getValue().values());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@
import org.graalvm.word.UnsignedWord;
import org.graalvm.word.WordFactory;

import com.oracle.svm.core.NeverInline;
import com.oracle.svm.core.SubstrateOptions;
import com.oracle.svm.core.SubstrateUtil;
import com.oracle.svm.core.NeverInline;
import com.oracle.svm.core.heap.RestrictHeapAccess;
import com.oracle.svm.core.Uninterruptible;
import com.oracle.svm.core.c.NonmovableArray;
import com.oracle.svm.core.c.NonmovableArrays;
import com.oracle.svm.core.deopt.DeoptimizedFrame;
import com.oracle.svm.core.deopt.Deoptimizer;
import com.oracle.svm.core.deopt.SubstrateInstalledCode;
import com.oracle.svm.core.heap.RestrictHeapAccess;
import com.oracle.svm.core.option.RuntimeOptionKey;
import com.oracle.svm.core.stack.JavaStackWalker;
import com.oracle.svm.core.stack.StackFrameVisitor;
Expand Down Expand Up @@ -322,6 +322,6 @@ public interface CodeInfoVisitor {
* continue, else false.
*/
@RestrictHeapAccess(access = RestrictHeapAccess.Access.NO_ALLOCATION, reason = "Must not allocate while visiting code.")
<T extends CodeInfo> boolean visitCode(T codeInfo);
boolean visitCode(CodeInfo codeInfo);
}
}
Loading