Skip to content

Commit 340a845

Browse files
Use unattached threads as GC worker threads.
1 parent 35325d6 commit 340a845

File tree

20 files changed

+292
-198
lines changed

20 files changed

+292
-198
lines changed

substratevm/mx.substratevm/suite.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,8 @@
364364
],
365365
"dependencies": [
366366
"com.oracle.svm.core",
367+
# TEMP (chaeubl): must not directly access the posix APIs
368+
"com.oracle.svm.core.posix"
367369
],
368370
"requires" : [
369371
"jdk.management",

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,6 @@ public void collect(GCCause cause) {
146146
collect(cause, false);
147147
}
148148

149-
@SuppressWarnings("static-method")
150-
public void initialize() {
151-
if (ParallelGC.isEnabled()) {
152-
ParallelGC.singleton().startWorkerThreads();
153-
}
154-
}
155-
156149
public void maybeCollectOnAllocation() {
157150
boolean outOfMemory = false;
158151
if (hasNeverCollectPolicy()) {
@@ -208,6 +201,10 @@ private void collectOperation(CollectionVMOperationData data) {
208201
assert VMOperation.isGCInProgress() : "Collection should be a VMOperation.";
209202
assert getCollectionEpoch().equal(data.getRequestingEpoch());
210203

204+
if (SubstrateOptions.UseParallelGC.getValue()) {
205+
ParallelGC.singleton().initialize();
206+
}
207+
211208
timers.mutator.closeAt(data.getRequestingNanoTime());
212209
startCollectionOrExit();
213210

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,6 @@ public void noteCopiedReferent() {
223223
@Override
224224
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
225225
public void noteUnmodifiedReference() {
226-
// TEMP (chaeubl): this counter would break
227226
unmodifiedReference += 1L;
228227
}
229228

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,16 @@
4242
import org.graalvm.word.UnsignedWord;
4343

4444
import com.oracle.svm.core.MemoryWalker;
45+
import com.oracle.svm.core.NeverInline;
4546
import com.oracle.svm.core.SubstrateDiagnostics;
4647
import com.oracle.svm.core.SubstrateDiagnostics.DiagnosticThunk;
4748
import com.oracle.svm.core.SubstrateDiagnostics.DiagnosticThunkRegistry;
4849
import com.oracle.svm.core.SubstrateDiagnostics.ErrorContext;
4950
import com.oracle.svm.core.SubstrateOptions;
5051
import com.oracle.svm.core.SubstrateUtil;
51-
import com.oracle.svm.core.NeverInline;
52-
import com.oracle.svm.core.heap.RestrictHeapAccess;
52+
import com.oracle.svm.core.Uninterruptible;
5353
import com.oracle.svm.core.annotate.Substitute;
5454
import com.oracle.svm.core.annotate.TargetClass;
55-
import com.oracle.svm.core.Uninterruptible;
5655
import com.oracle.svm.core.config.ConfigurationValues;
5756
import com.oracle.svm.core.genscavenge.AlignedHeapChunk.AlignedHeader;
5857
import com.oracle.svm.core.genscavenge.ThreadLocalAllocation.Descriptor;
@@ -70,6 +69,7 @@
7069
import com.oracle.svm.core.heap.ReferenceHandler;
7170
import com.oracle.svm.core.heap.ReferenceHandlerThread;
7271
import com.oracle.svm.core.heap.ReferenceInternals;
72+
import com.oracle.svm.core.heap.RestrictHeapAccess;
7373
import com.oracle.svm.core.heap.RuntimeCodeInfoGCSupport;
7474
import com.oracle.svm.core.jdk.UninterruptibleUtils.AtomicReference;
7575
import com.oracle.svm.core.locks.VMCondition;
@@ -242,11 +242,6 @@ GCImpl getGCImpl() {
242242
return gcImpl;
243243
}
244244

245-
@Override
246-
public void initGC() {
247-
gcImpl.initialize();
248-
}
249-
250245
@Override
251246
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
252247
public boolean isAllocationDisallowed() {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ Object getForwardedObject(Pointer ptr) {
411411
Object getForwardedObject(Pointer ptr, UnsignedWord header) {
412412
assert isForwardedHeader(header);
413413
if (ReferenceAccess.singleton().haveCompressedReferences()) {
414-
// TEMP (chaeubl):
414+
// TODO (chaeubl): fix this
415415
// if (ReferenceAccess.singleton().getCompressEncoding().hasShift()) {
416416
if (false) {
417417
// References compressed with shift have no bits to spare, so the forwarding
@@ -435,7 +435,7 @@ void installForwardingPointer(Object original, Object copy) {
435435
assert !isPointerToForwardedObject(Word.objectToUntrackedPointer(original));
436436
UnsignedWord forwardHeader;
437437
if (ReferenceAccess.singleton().haveCompressedReferences()) {
438-
// TEMP (chaeubl):
438+
// TODO (chaeubl): fix this
439439
// if (ReferenceAccess.singleton().getCompressEncoding().hasShift()) {
440440
if (false) {
441441
// Compression with a shift uses all bits of a reference, so store the forwarding
@@ -460,7 +460,7 @@ Object installForwardingPointerParallel(Object original, UnsignedWord originalHe
460460
UnsignedWord forwardHeader;
461461
boolean hasShift = false;
462462
if (ReferenceAccess.singleton().haveCompressedReferences()) {
463-
// TEMP (chaeubl):
463+
// TODO (chaeubl): fix this
464464
// if (ReferenceAccess.singleton().getCompressEncoding().hasShift()) {
465465
if (false) {
466466
forwardHeader = WordFactory.unsigned(0xe0e0e0e0e0e0e0e0L);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ private Pointer allocateMemory(UnsignedWord objectSize) {
196196
private Pointer allocateMemoryParallel(UnsignedWord objectSize) {
197197
Pointer result = WordFactory.nullPointer();
198198
/* Fast-path: try allocating in the thread local allocation chunk. */
199-
AlignedHeapChunk.AlignedHeader oldChunk = ParallelGC.getAllocationChunk();
199+
AlignedHeapChunk.AlignedHeader oldChunk = ParallelGC.singleton().getAllocationChunk();
200200
if (oldChunk.isNonNull()) {
201201
result = AlignedHeapChunk.allocateMemory(oldChunk, objectSize);
202202
}
@@ -214,7 +214,7 @@ private Pointer allocateMemoryParallel(UnsignedWord objectSize) {
214214
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
215215
private static Pointer retractAllocation(UnsignedWord objectSize) {
216216
assert ParallelGC.isEnabled() && ParallelGC.isInParallelPhase();
217-
AlignedHeapChunk.AlignedHeader oldChunk = ParallelGC.getAllocationChunk();
217+
AlignedHeapChunk.AlignedHeader oldChunk = ParallelGC.singleton().getAllocationChunk();
218218
assert oldChunk.isNonNull();
219219
return AlignedHeapChunk.retractAllocation(oldChunk, objectSize);
220220
}
@@ -239,7 +239,7 @@ private Pointer allocateInNewChunkParallel(AlignedHeapChunk.AlignedHeader oldChu
239239
ParallelGC.mutex.unlock();
240240
}
241241
if (newChunk.isNonNull()) {
242-
ParallelGC.setAllocationChunk(newChunk);
242+
ParallelGC.singleton().setAllocationChunk(newChunk);
243243
return AlignedHeapChunk.allocateMemory(newChunk, objectSize);
244244
}
245245
return WordFactory.nullPointer();

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,14 +307,12 @@ private boolean fitsInSurvivors(HeapChunk.Header<?> chunk, boolean isAligned) {
307307
return unalignedChunkFitsInSurvivors((UnalignedHeapChunk.UnalignedHeader) chunk);
308308
}
309309

310-
// TEMP (chaeubl): this is problematic but it isn't called or?
311310
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
312311
private boolean alignedChunkFitsInSurvivors() {
313312
UnsignedWord sum = survivorsToSpacesAccounting.getChunkBytes().add(HeapParameters.getAlignedHeapChunkSize());
314313
return sum.belowOrEqual(GCImpl.getPolicy().getSurvivorSpacesCapacity());
315314
}
316315

317-
// TEMP (chaeubl): this is problematic but it isn't called or?
318316
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
319317
private boolean unalignedChunkFitsInSurvivors(UnalignedHeapChunk.UnalignedHeader chunk) {
320318
UnsignedWord size = UnalignedHeapChunk.getCommittedObjectMemory(chunk);

substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/parallel/ChunkBuffer.java

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929
import org.graalvm.compiler.api.replacements.Fold;
3030
import org.graalvm.nativeimage.ImageSingletons;
31+
import org.graalvm.nativeimage.Platform;
32+
import org.graalvm.nativeimage.Platforms;
3133
import org.graalvm.nativeimage.impl.UnmanagedMemorySupport;
3234
import org.graalvm.word.Pointer;
3335
import org.graalvm.word.WordFactory;
@@ -50,9 +52,15 @@ static int wordSize() {
5052
return ConfigurationValues.getTarget().wordSize;
5153
}
5254

55+
@Platforms(Platform.HOSTED_ONLY.class)
5356
ChunkBuffer() {
57+
}
58+
59+
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
60+
public void initialize() {
5461
this.size = INITIAL_SIZE;
55-
this.buffer = malloc(this.size);
62+
// TODO (petermz): needs proper error handling
63+
this.buffer = ImageSingletons.lookup(UnmanagedMemorySupport.class).malloc(WordFactory.unsigned(this.size));
5664
}
5765

5866
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
@@ -62,7 +70,8 @@ void push(Pointer ptr) {
6270
int oldSize = size;
6371
size *= 2;
6472
assert top < size;
65-
buffer = realloc(buffer, size);
73+
// TODO (petermz): needs proper error handling
74+
buffer = ImageSingletons.lookup(UnmanagedMemorySupport.class).realloc(buffer, WordFactory.unsigned(size));
6675
}
6776
buffer.writeWord(top, ptr);
6877
top += wordSize();
@@ -89,22 +98,8 @@ boolean isEmpty() {
8998
return top == 0;
9099
}
91100

92-
void release() {
93-
free(buffer);
94-
}
95-
96-
private static Pointer malloc(int bytes) {
97-
// TEMP (chaeubl): needs proper error handling
98-
return ImageSingletons.lookup(UnmanagedMemorySupport.class).malloc(WordFactory.unsigned(bytes));
99-
}
100-
101101
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
102-
private static Pointer realloc(Pointer orig, int newSize) {
103-
// TEMP (chaeubl): needs proper error handling
104-
return ImageSingletons.lookup(UnmanagedMemorySupport.class).realloc(orig, WordFactory.unsigned(newSize));
105-
}
106-
107-
private static void free(Pointer ptr) {
108-
ImageSingletons.lookup(UnmanagedMemorySupport.class).free(ptr);
102+
void release() {
103+
ImageSingletons.lookup(UnmanagedMemorySupport.class).free(buffer);
109104
}
110105
}

0 commit comments

Comments
 (0)