Skip to content

Commit 428b760

Browse files
Review feedback.
1 parent af3eacb commit 428b760

File tree

8 files changed

+44
-38
lines changed

8 files changed

+44
-38
lines changed

substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/graal/GenScavengeAllocationSnippets.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public static Object formatObjectSnippet(Word memory, DynamicHub hub, boolean re
7272
int layoutEncoding = hubNonNull.getLayoutEncoding();
7373
UnsignedWord size = LayoutEncoding.getInstanceSize(layoutEncoding);
7474
Word objectHeader = encodeAsObjectHeader(hubNonNull, rememberedSet, false);
75-
return base().formatObject(objectHeader, size, memory, fillContents, emitMemoryBarrier, false, snippetCounters);
75+
return alloc().formatObject(objectHeader, size, memory, fillContents, emitMemoryBarrier, false, snippetCounters);
7676
}
7777

7878
@Snippet
@@ -83,9 +83,9 @@ public static Object formatArraySnippet(Word memory, DynamicHub hub, int length,
8383
int layoutEncoding = hubNonNull.getLayoutEncoding();
8484
UnsignedWord size = LayoutEncoding.getArraySize(layoutEncoding, length);
8585
Word objectHeader = encodeAsObjectHeader(hubNonNull, rememberedSet, unaligned);
86-
Object obj = base().formatArray(objectHeader, size, length, memory, fillContents, fillStartOffset,
86+
Object obj = alloc().formatArray(objectHeader, size, length, memory, fillContents, fillStartOffset,
8787
false, false, supportsBulkZeroing, supportsOptimizedFilling, snippetCounters);
88-
base().emitMemoryBarrierIf(emitMemoryBarrier);
88+
alloc().emitMemoryBarrierIf(emitMemoryBarrier);
8989
return obj;
9090
}
9191

@@ -102,15 +102,15 @@ public static Object allocateStoredContinuationInstance(@ConstantParameter Dynam
102102
* because objects are immutable once filled and are then written only by GC.
103103
*/
104104
int arrayLength = StoredContinuationImpl.PAYLOAD_OFFSET + payloadSize - byteArrayBaseOffset;
105-
Object result = base().allocateArrayImpl(SubstrateAllocationSnippets.encodeAsTLABObjectHeader(byteArrayHub), arrayLength, byteArrayBaseOffset, 0,
105+
Object result = alloc().allocateArrayImpl(SubstrateAllocationSnippets.encodeAsTLABObjectHeader(byteArrayHub), arrayLength, byteArrayBaseOffset, 0,
106106
AllocationSnippets.FillContent.WITH_GARBAGE_IF_ASSERTIONS_ENABLED,
107107
SubstrateAllocationSnippets.afterArrayLengthOffset(), false, false, false, false, profilingData);
108108
UnsignedWord arrayHeader = ObjectHeaderImpl.readHeaderFromObject(result);
109109
Word header = encodeAsObjectHeader(hub, ObjectHeaderImpl.hasRememberedSet(arrayHeader), ObjectHeaderImpl.isUnalignedHeader(arrayHeader));
110-
base().initializeObjectHeader(Word.objectToUntrackedPointer(result), header, false);
110+
alloc().initializeObjectHeader(Word.objectToUntrackedPointer(result), header, false);
111111
ObjectAccess.writeObject(result, hub.getMonitorOffset(), null, LocationIdentity.init());
112112
StoredContinuationImpl.initializeNewlyAllocated(result, payloadSize);
113-
base().emitMemoryBarrierIf(true);
113+
alloc().emitMemoryBarrierIf(true);
114114
return PiNode.piCastToSnippetReplaceeStamp(result);
115115
}
116116

@@ -119,7 +119,7 @@ private static Word encodeAsObjectHeader(DynamicHub hub, boolean rememberedSet,
119119
}
120120

121121
@Fold
122-
static SubstrateAllocationSnippets base() {
122+
static SubstrateAllocationSnippets alloc() {
123123
return ImageSingletons.lookup(SubstrateAllocationSnippets.class);
124124
}
125125

substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/graal/GenScavengeAllocationSupport.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727
import com.oracle.svm.core.genscavenge.HeapParameters;
2828
import com.oracle.svm.core.genscavenge.ThreadLocalAllocation;
2929
import com.oracle.svm.core.graal.meta.SubstrateForeignCallsProvider;
30-
import com.oracle.svm.core.graal.snippets.SubstrateAllocationSupport;
30+
import com.oracle.svm.core.graal.snippets.GCAllocationSupport;
3131
import com.oracle.svm.core.snippets.SnippetRuntime;
3232
import org.graalvm.compiler.core.common.spi.ForeignCallDescriptor;
3333
import org.graalvm.compiler.word.Word;
3434
import org.graalvm.word.UnsignedWord;
3535

36-
public class GenScavengeAllocationSupport implements SubstrateAllocationSupport {
36+
public class GenScavengeAllocationSupport implements GCAllocationSupport {
3737
private static final SnippetRuntime.SubstrateForeignCallDescriptor SLOW_NEW_INSTANCE = SnippetRuntime.findForeignCall(ThreadLocalAllocation.class, "slowPathNewInstance", true);
3838
private static final SnippetRuntime.SubstrateForeignCallDescriptor SLOW_NEW_ARRAY = SnippetRuntime.findForeignCall(ThreadLocalAllocation.class, "slowPathNewArray", true);
3939
private static final SnippetRuntime.SubstrateForeignCallDescriptor[] FOREIGN_CALLS = new SnippetRuntime.SubstrateForeignCallDescriptor[]{SLOW_NEW_INSTANCE, SLOW_NEW_ARRAY};

substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/graal/SerialGCFeature.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
import com.oracle.svm.core.graal.meta.RuntimeConfiguration;
5252
import com.oracle.svm.core.graal.meta.SubstrateForeignCallsProvider;
5353
import com.oracle.svm.core.graal.snippets.NodeLoweringProvider;
54-
import com.oracle.svm.core.graal.snippets.SubstrateAllocationSupport;
54+
import com.oracle.svm.core.graal.snippets.GCAllocationSupport;
5555
import com.oracle.svm.core.heap.Heap;
5656
import com.oracle.svm.core.heap.HeapFeature;
5757
import com.oracle.svm.core.image.ImageHeapLayouter;
@@ -76,7 +76,7 @@ public void afterRegistration(AfterRegistrationAccess access) {
7676
HeapImpl heap = new HeapImpl(SubstrateOptions.getPageSize());
7777
ImageSingletons.add(Heap.class, heap);
7878
ImageSingletons.add(RememberedSet.class, createRememberedSet());
79-
ImageSingletons.add(SubstrateAllocationSupport.class, new GenScavengeAllocationSupport());
79+
ImageSingletons.add(GCAllocationSupport.class, new GenScavengeAllocationSupport());
8080

8181
ManagementSupport managementSupport = ManagementSupport.getSingleton();
8282
managementSupport.addPlatformManagedObjectSingleton(java.lang.management.MemoryMXBean.class, new HeapImplMemoryMXBean());
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@
2828
import org.graalvm.compiler.word.Word;
2929
import org.graalvm.word.UnsignedWord;
3030

31-
public interface SubstrateAllocationSupport {
31+
/**
32+
* Used to abstract the GC-specific part of the allocation functionality, e.g., how does the TLAB
33+
* look like in detail.
34+
*/
35+
public interface GCAllocationSupport {
3236
ForeignCallDescriptor getSlowNewInstanceStub();
3337

3438
ForeignCallDescriptor getSlowNewArrayStub();

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/snippets/SubstrateAllocationSnippets.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -335,12 +335,12 @@ public static Word encodeAsTLABObjectHeader(DynamicHub hub) {
335335

336336
@Override
337337
protected final Object callNewInstanceStub(Word objectHeader) {
338-
return callSlowNewInstance(config().getSlowNewInstanceStub(), objectHeader);
338+
return callSlowNewInstance(gcAllocationSupport().getSlowNewInstanceStub(), objectHeader);
339339
}
340340

341341
@Override
342342
protected final Object callNewArrayStub(Word objectHeader, int length, int fillStartOffset) {
343-
return callSlowNewArray(config().getSlowNewArrayStub(), objectHeader, length, fillStartOffset);
343+
return callSlowNewArray(gcAllocationSupport().getSlowNewArrayStub(), objectHeader, length, fillStartOffset);
344344
}
345345

346346
@Override
@@ -364,37 +364,37 @@ public void initializeObjectHeader(Word memory, Word objectHeader, boolean isArr
364364

365365
@Override
366366
public boolean useTLAB() {
367-
return config().useTLAB();
367+
return gcAllocationSupport().useTLAB();
368368
}
369369

370370
@Override
371371
protected boolean shouldAllocateInTLAB(UnsignedWord size, boolean isArray) {
372-
return config().shouldAllocateInTLAB(size, isArray);
372+
return gcAllocationSupport().shouldAllocateInTLAB(size, isArray);
373373
}
374374

375375
@Override
376376
public Word getTLABInfo() {
377-
return config().getTLABInfo();
377+
return gcAllocationSupport().getTLABInfo();
378378
}
379379

380380
@Override
381381
public Word readTlabTop(Word tlabInfo) {
382-
return tlabInfo.readWord(config().tlabTopOffset(), TLAB_TOP_IDENTITY);
382+
return tlabInfo.readWord(gcAllocationSupport().tlabTopOffset(), TLAB_TOP_IDENTITY);
383383
}
384384

385385
@Override
386386
public Word readTlabEnd(Word tlabInfo) {
387-
return tlabInfo.readWord(config().tlabEndOffset(), TLAB_END_IDENTITY);
387+
return tlabInfo.readWord(gcAllocationSupport().tlabEndOffset(), TLAB_END_IDENTITY);
388388
}
389389

390390
@Override
391391
public void writeTlabTop(Word tlabInfo, Word newTop) {
392-
tlabInfo.writeWord(config().tlabTopOffset(), newTop, TLAB_TOP_IDENTITY);
392+
tlabInfo.writeWord(gcAllocationSupport().tlabTopOffset(), newTop, TLAB_TOP_IDENTITY);
393393
}
394394

395395
@Fold
396-
static SubstrateAllocationSupport config() {
397-
return ImageSingletons.lookup(SubstrateAllocationSupport.class);
396+
static GCAllocationSupport gcAllocationSupport() {
397+
return ImageSingletons.lookup(GCAllocationSupport.class);
398398
}
399399

400400
public static class SubstrateAllocationProfilingData extends AllocationProfilingData {

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -709,17 +709,20 @@ private static boolean hasClassPath() {
709709

710710
/** Dummy class to have a class with the file's name. */
711711
public final class JavaLangSubstitutions {
712-
/**
713-
* Returns a character from a string at {@code index} position based on the encoding format.
714-
*/
715-
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
716-
public static char charAt(String string, int index) {
717-
Target_java_lang_String str = SubstrateUtil.cast(string, Target_java_lang_String.class);
718-
byte[] value = str.value;
719-
if (str.isLatin1()) {
720-
return (char) (value[index] & 0xFF);
721-
} else {
722-
return Target_java_lang_StringUTF16.getChar(value, index);
712+
713+
public static final class StringUtil {
714+
/**
715+
* Returns a character from a string at {@code index} position based on the encoding format.
716+
*/
717+
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
718+
public static char charAt(String string, int index) {
719+
Target_java_lang_String str = SubstrateUtil.cast(string, Target_java_lang_String.class);
720+
byte[] value = str.value;
721+
if (str.isLatin1()) {
722+
return (char) (value[index] & 0xFF);
723+
} else {
724+
return Target_java_lang_StringUTF16.getChar(value, index);
725+
}
723726
}
724727
}
725728

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
*/
2525
package com.oracle.svm.core.jdk;
2626

27+
import com.oracle.svm.core.jdk.JavaLangSubstitutions.StringUtil;
2728
import org.graalvm.word.Pointer;
2829
import org.graalvm.word.PointerBase;
2930
import org.graalvm.word.UnsignedWord;
@@ -511,7 +512,7 @@ private static Pointer writeModifiedUTF8(Pointer buffer, char c) {
511512
public static int modifiedUTF8Length(java.lang.String string, boolean addNullTerminator) {
512513
int result = 0;
513514
for (int index = 0; index < string.length(); index++) {
514-
char ch = JavaLangSubstitutions.charAt(string, index);
515+
char ch = StringUtil.charAt(string, index);
515516
result += modifiedUTF8Length(ch);
516517
}
517518

@@ -529,7 +530,7 @@ public static int modifiedUTF8Length(java.lang.String string, boolean addNullTer
529530
public static Pointer toModifiedUTF8(java.lang.String string, Pointer buffer, Pointer bufferEnd, boolean addNullTerminator) {
530531
Pointer pos = buffer;
531532
for (int index = 0; index < string.length(); index++) {
532-
pos = writeModifiedUTF8(pos, JavaLangSubstitutions.charAt(string, index));
533+
pos = writeModifiedUTF8(pos, StringUtil.charAt(string, index));
533534
}
534535

535536
if (addNullTerminator) {

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/FactoryMethodSupport.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@ protected AbstractNewObjectNode createNewInstance(HostedGraphKit kit, ResolvedJa
109109
final class FactoryMethodFeature implements Feature {
110110
@Override
111111
public void beforeAnalysis(BeforeAnalysisAccess arg) {
112-
if (!ImageSingletons.contains(FactoryMethodSupport.class)) {
113-
ImageSingletons.add(FactoryMethodSupport.class, new FactoryMethodSupport());
114-
}
112+
ImageSingletons.add(FactoryMethodSupport.class, new FactoryMethodSupport());
115113
}
116114
}

0 commit comments

Comments
 (0)