Skip to content

Commit 06fb7cb

Browse files
[GR-10518] Heap dumping.
PullRequest: graal/13889
2 parents b2265d5 + dd0b4d4 commit 06fb7cb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+3493
-269
lines changed

compiler/src/org.graalvm.compiler.core.common/src/org/graalvm/compiler/core/common/NumUtil.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ public static short safeToShort(int v) {
126126
return (short) v;
127127
}
128128

129+
public static int safeToUInt(long v) {
130+
assert isUInt(v);
131+
return (int) v;
132+
}
133+
129134
public static int safeToInt(long v) {
130135
assert isInt(v);
131136
return (int) v;

substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/GCImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
import com.oracle.svm.core.thread.PlatformThreads;
9191
import com.oracle.svm.core.thread.VMOperation;
9292
import com.oracle.svm.core.thread.VMThreads;
93+
import com.oracle.svm.core.threadlocal.VMThreadLocalMTSupport;
9394
import com.oracle.svm.core.util.TimeUtils;
9495
import com.oracle.svm.core.util.VMError;
9596

@@ -179,7 +180,6 @@ boolean collectWithoutAllocating(GCCause cause, boolean forceFullGC) {
179180
int size = SizeOf.get(CollectionVMOperationData.class);
180181
CollectionVMOperationData data = StackValue.get(size);
181182
UnmanagedMemoryUtil.fill((Pointer) data, WordFactory.unsigned(size), (byte) 0);
182-
data.setNativeVMOperation(collectOperation);
183183
data.setCauseId(cause.getId());
184184
data.setRequestingEpoch(getCollectionEpoch());
185185
data.setRequestingNanoTime(System.nanoTime());
@@ -947,7 +947,9 @@ private void walkThreadLocals() {
947947
if (SubstrateOptions.MultiThreaded.getValue()) {
948948
Timer walkThreadLocalsTimer = timers.walkThreadLocals.open();
949949
try {
950-
ThreadLocalMTWalker.walk(greyToBlackObjRefVisitor);
950+
for (IsolateThread isolateThread = VMThreads.firstThread(); isolateThread.isNonNull(); isolateThread = VMThreads.nextThread(isolateThread)) {
951+
VMThreadLocalMTSupport.singleton().walk(isolateThread, greyToBlackObjRefVisitor);
952+
}
951953
} finally {
952954
walkThreadLocalsTimer.close();
953955
}

substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/HeapImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ public boolean walkImageHeapObjects(ObjectVisitor visitor) {
457457
@Override
458458
public boolean walkCollectedHeapObjects(ObjectVisitor visitor) {
459459
VMOperation.guaranteeInProgressAtSafepoint("Must only be called at a safepoint");
460+
ThreadLocalAllocation.disableAndFlushForAllThreads();
460461
return getYoungGeneration().walkObjects(visitor) && getOldGeneration().walkObjects(visitor);
461462
}
462463

substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/RuntimeCodeCacheWalker.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@
2929
import org.graalvm.nativeimage.Platforms;
3030

3131
import com.oracle.svm.core.SubstrateGCOptions;
32-
import com.oracle.svm.core.util.DuplicatedInNativeCode;
3332
import com.oracle.svm.core.code.CodeInfo;
3433
import com.oracle.svm.core.code.CodeInfoAccess;
3534
import com.oracle.svm.core.code.RuntimeCodeCache.CodeInfoVisitor;
3635
import com.oracle.svm.core.code.RuntimeCodeInfoAccess;
3736
import com.oracle.svm.core.code.UntetheredCodeInfoAccess;
3837
import com.oracle.svm.core.heap.ObjectReferenceVisitor;
38+
import com.oracle.svm.core.util.DuplicatedInNativeCode;
3939

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

5959
@Override
6060
@DuplicatedInNativeCode
61-
public <T extends CodeInfo> boolean visitCode(T codeInfo) {
61+
public boolean visitCode(CodeInfo codeInfo) {
6262
if (RuntimeCodeInfoAccess.areAllObjectsOnImageHeap(codeInfo)) {
6363
return true;
6464
}

substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/ThreadLocalMTWalker.java

Lines changed: 0 additions & 52 deletions
This file was deleted.

substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/PosixRawFileOperationSupport.java

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ public PosixRawFileOperationSupport(boolean useNativeByteOrder) {
5555
super(useNativeByteOrder);
5656
}
5757

58+
@Override
59+
public RawFileDescriptor create(File file, FileCreationMode creationMode, FileAccessMode accessMode) {
60+
String path = file.getPath();
61+
int flags = parseMode(creationMode) | parseMode(accessMode);
62+
63+
try (CTypeConversion.CCharPointerHolder cPath = CTypeConversion.toCString(path)) {
64+
return WordFactory.signed(Fcntl.NoTransitions.open(cPath.get(), flags, DEFAULT_PERMISSIONS));
65+
}
66+
}
67+
5868
@Override
5969
public RawFileDescriptor open(File file, FileAccessMode mode) {
6070
String path = file.getPath();
@@ -83,24 +93,24 @@ public boolean close(RawFileDescriptor fd) {
8393

8494
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
8595
@Override
86-
public SignedWord size(RawFileDescriptor fd) {
96+
public long size(RawFileDescriptor fd) {
8797
int posixFd = getPosixFileDescriptor(fd);
8898
return PosixStat.getSize(posixFd);
8999
}
90100

91101
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
92102
@Override
93-
public SignedWord position(RawFileDescriptor fd) {
103+
public long position(RawFileDescriptor fd) {
94104
int posixFd = getPosixFileDescriptor(fd);
95-
return Unistd.NoTransitions.lseek(posixFd, WordFactory.signed(0), Unistd.SEEK_CUR());
105+
return Unistd.NoTransitions.lseek(posixFd, WordFactory.signed(0), Unistd.SEEK_CUR()).rawValue();
96106
}
97107

98108
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
99109
@Override
100-
public boolean seek(RawFileDescriptor fd, SignedWord position) {
110+
public boolean seek(RawFileDescriptor fd, long position) {
101111
int posixFd = getPosixFileDescriptor(fd);
102-
SignedWord newPos = Unistd.NoTransitions.lseek(posixFd, position, Unistd.SEEK_SET());
103-
return position.equal(newPos);
112+
SignedWord newPos = Unistd.NoTransitions.lseek(posixFd, WordFactory.signed(position), Unistd.SEEK_SET());
113+
return position == newPos.rawValue();
104114
}
105115

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

128138
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
129139
@Override
130-
public SignedWord read(RawFileDescriptor fd, Pointer buffer, UnsignedWord bufferSize) {
140+
public long read(RawFileDescriptor fd, Pointer buffer, UnsignedWord bufferSize) {
131141
int posixFd = getPosixFileDescriptor(fd);
132142

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

138-
return readBytes;
148+
return readBytes.rawValue();
139149
}
140150

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

158+
private static int parseMode(FileCreationMode mode) {
159+
switch (mode) {
160+
case CREATE:
161+
return Fcntl.O_CREAT() | Fcntl.O_EXCL();
162+
case CREATE_OR_REPLACE:
163+
return Fcntl.O_CREAT() | Fcntl.O_TRUNC();
164+
default:
165+
throw VMError.shouldNotReachHere();
166+
}
167+
}
168+
148169
private static int parseMode(FileAccessMode mode) {
149170
switch (mode) {
150171
case READ:
151172
return Fcntl.O_RDONLY();
152173
case READ_WRITE:
153-
return Fcntl.O_RDWR() | Fcntl.O_CREAT();
174+
return Fcntl.O_RDWR();
154175
case WRITE:
155-
return Fcntl.O_WRONLY() | Fcntl.O_CREAT();
176+
return Fcntl.O_WRONLY();
156177
default:
157178
throw VMError.shouldNotReachHere();
158179
}
@@ -162,14 +183,14 @@ private static int parseMode(FileAccessMode mode) {
162183
@AutomaticallyRegisteredFeature
163184
class PosixRawFileOperationFeature implements InternalFeature {
164185
@Override
165-
public void beforeAnalysis(BeforeAnalysisAccess access) {
186+
public void afterRegistration(AfterRegistrationAccess access) {
166187
ByteOrder nativeByteOrder = ByteOrder.nativeOrder();
167188
assert nativeByteOrder == ByteOrder.LITTLE_ENDIAN || nativeByteOrder == ByteOrder.BIG_ENDIAN;
168189

169-
PosixRawFileOperationSupport littleEndianSupport = new PosixRawFileOperationSupport(ByteOrder.LITTLE_ENDIAN == nativeByteOrder);
170-
PosixRawFileOperationSupport bigEndianSupport = new PosixRawFileOperationSupport(ByteOrder.BIG_ENDIAN == nativeByteOrder);
171-
PosixRawFileOperationSupport nativeByteOrderSupport = nativeByteOrder == ByteOrder.LITTLE_ENDIAN ? littleEndianSupport : bigEndianSupport;
190+
PosixRawFileOperationSupport littleEndian = new PosixRawFileOperationSupport(ByteOrder.LITTLE_ENDIAN == nativeByteOrder);
191+
PosixRawFileOperationSupport bigEndian = new PosixRawFileOperationSupport(ByteOrder.BIG_ENDIAN == nativeByteOrder);
192+
PosixRawFileOperationSupport nativeOrder = nativeByteOrder == ByteOrder.LITTLE_ENDIAN ? littleEndian : bigEndian;
172193

173-
ImageSingletons.add(RawFileOperationSupportHolder.class, new RawFileOperationSupportHolder(littleEndianSupport, bigEndianSupport, nativeByteOrderSupport));
194+
ImageSingletons.add(RawFileOperationSupportHolder.class, new RawFileOperationSupportHolder(littleEndian, bigEndian, nativeOrder));
174195
}
175196
}

substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/PosixStat.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626

2727
import org.graalvm.nativeimage.Platform;
2828
import org.graalvm.nativeimage.Platforms;
29-
import org.graalvm.word.SignedWord;
30-
import org.graalvm.word.WordFactory;
3129

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

5654
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
57-
public static SignedWord getSize(int fd) {
55+
public static long getSize(int fd) {
5856
long size = -1;
5957
if (Platform.includedIn(Platform.LINUX.class)) {
6058
LinuxStat.stat64 stat = UnsafeStackValue.get(LinuxStat.stat64.class);
@@ -67,7 +65,7 @@ public static SignedWord getSize(int fd) {
6765
size = stat.st_size();
6866
}
6967
}
70-
return WordFactory.signed(size);
68+
return size;
7169
}
7270

7371
@Platforms(Platform.HOSTED_ONLY.class)

substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Fcntl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ public class Fcntl {
5050
@CConstant
5151
public static native int O_CREAT();
5252

53+
@CConstant
54+
public static native int O_TRUNC();
55+
56+
@CConstant
57+
public static native int O_EXCL();
58+
5359
public static class NoTransitions {
5460
@CFunction(value = "openSII", transition = Transition.NO_TRANSITION)
5561
public static native int open(CCharPointer pathname, int flags, int mode);

substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/heapdump/AllocationFreeFileOutputStreamPosix.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
import com.oracle.svm.core.util.VMError;
4242

4343
/**
44+
* Legacy implementation, only used by other legacy code (see GR-44538).
45+
*
4446
* Posix implementation of allocation-free output stream created from FileOutputStream.
4547
*
4648
* The limitation to Linux and Darwin is necessary because the implementation currently uses

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/DumpHeapOnSignalFeature.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333
import org.graalvm.nativeimage.ProcessProperties;
3434
import org.graalvm.nativeimage.VMRuntime;
3535

36+
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
3637
import com.oracle.svm.core.feature.InternalFeature;
3738
import com.oracle.svm.core.jdk.RuntimeSupport;
3839
import com.oracle.svm.core.log.Log;
39-
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
4040

4141
import sun.misc.Signal;
4242
import sun.misc.SignalHandler;

0 commit comments

Comments
 (0)