Skip to content

Commit 1792cb5

Browse files
author
Maxime Kjaer
committed
[GR-24922] [GR-24575] [GR-24574] [GR-24924] Array and hybrid object-related refactorings.
PullRequest: graal/6977
2 parents 362bb7f + 4b6c70f commit 1792cb5

File tree

87 files changed

+1710
-556
lines changed

Some content is hidden

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

87 files changed

+1710
-556
lines changed

compiler/src/org.graalvm.compiler.core.aarch64/src/org/graalvm/compiler/core/aarch64/AArch64LIRGenerator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -534,24 +534,24 @@ public Variable emitByteSwap(Value input) {
534534
}
535535

536536
@Override
537-
public Variable emitArrayCompareTo(JavaKind kind1, JavaKind kind2, Value array1, Value array2, Value length1, Value length2) {
537+
public Variable emitArrayCompareTo(JavaKind kind1, JavaKind kind2, int array1BaseOffset, int array2BaseOffset, Value array1, Value array2, Value length1, Value length2) {
538538
LIRKind resultKind = LIRKind.value(AArch64Kind.DWORD);
539539
// DMS TODO: check calling conversion and registers used
540540
RegisterValue res = AArch64.r0.asValue(resultKind);
541541
RegisterValue cnt1 = AArch64.r1.asValue(length1.getValueKind());
542542
RegisterValue cnt2 = AArch64.r2.asValue(length2.getValueKind());
543543
emitMove(cnt1, length1);
544544
emitMove(cnt2, length2);
545-
append(new AArch64ArrayCompareToOp(this, kind1, kind2, res, array1, array2, cnt1, cnt2));
545+
append(new AArch64ArrayCompareToOp(this, kind1, kind2, array1BaseOffset, array2BaseOffset, res, array1, array2, cnt1, cnt2));
546546
Variable result = newVariable(resultKind);
547547
emitMove(result, res);
548548
return result;
549549
}
550550

551551
@Override
552-
public Variable emitArrayEquals(JavaKind kind, Value array1, Value array2, Value length, boolean directPointers) {
552+
public Variable emitArrayEquals(JavaKind kind, int array1BaseOffset, int array2BaseOffset, Value array1, Value array2, Value length, boolean directPointers) {
553553
Variable result = newVariable(LIRKind.value(AArch64Kind.DWORD));
554-
append(new AArch64ArrayEqualsOp(this, kind, result, array1, array2, asAllocatable(length), directPointers));
554+
append(new AArch64ArrayEqualsOp(this, kind, array1BaseOffset, array2BaseOffset, result, array1, array2, asAllocatable(length), directPointers));
555555
return result;
556556
}
557557

compiler/src/org.graalvm.compiler.core.amd64/src/org/graalvm/compiler/core/amd64/AMD64LIRGenerator.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -582,30 +582,30 @@ public Variable emitByteSwap(Value input) {
582582
}
583583

584584
@Override
585-
public Variable emitArrayCompareTo(JavaKind kind1, JavaKind kind2, Value array1, Value array2, Value length1, Value length2) {
585+
public Variable emitArrayCompareTo(JavaKind kind1, JavaKind kind2, int array1BaseOffset, int array2BaseOffset, Value array1, Value array2, Value length1, Value length2) {
586586
LIRKind resultKind = LIRKind.value(AMD64Kind.DWORD);
587587
RegisterValue raxRes = AMD64.rax.asValue(resultKind);
588588
RegisterValue cnt1 = AMD64.rcx.asValue(length1.getValueKind());
589589
RegisterValue cnt2 = AMD64.rdx.asValue(length2.getValueKind());
590590
emitMove(cnt1, length1);
591591
emitMove(cnt2, length2);
592-
append(new AMD64ArrayCompareToOp(this, getAVX3Threshold(), kind1, kind2, raxRes, array1, array2, cnt1, cnt2));
592+
append(new AMD64ArrayCompareToOp(this, getAVX3Threshold(), kind1, kind2, array1BaseOffset, array2BaseOffset, raxRes, array1, array2, cnt1, cnt2));
593593
Variable result = newVariable(resultKind);
594594
emitMove(result, raxRes);
595595
return result;
596596
}
597597

598598
@Override
599-
public Variable emitArrayEquals(JavaKind kind, Value array1, Value array2, Value length, boolean directPointers) {
599+
public Variable emitArrayEquals(JavaKind kind, int array1BaseOffset, int array2BaseOffset, Value array1, Value array2, Value length, boolean directPointers) {
600600
Variable result = newVariable(LIRKind.value(AMD64Kind.DWORD));
601-
append(new AMD64ArrayEqualsOp(this, kind, kind, result, array1, array2, length, directPointers, getMaxVectorSize()));
601+
append(new AMD64ArrayEqualsOp(this, kind, kind, array1BaseOffset, array2BaseOffset, result, array1, array2, length, directPointers, getMaxVectorSize()));
602602
return result;
603603
}
604604

605605
@Override
606-
public Variable emitArrayEquals(JavaKind kind1, JavaKind kind2, Value array1, Value array2, Value length, boolean directPointers) {
606+
public Variable emitArrayEquals(JavaKind kind1, JavaKind kind2, int array1BaseOffset, int array2BaseOffset, Value array1, Value array2, Value length, boolean directPointers) {
607607
Variable result = newVariable(LIRKind.value(AMD64Kind.DWORD));
608-
append(new AMD64ArrayEqualsOp(this, kind1, kind2, result, array1, array2, length, directPointers, getMaxVectorSize()));
608+
append(new AMD64ArrayEqualsOp(this, kind1, kind2, array1BaseOffset, array2BaseOffset, result, array1, array2, length, directPointers, getMaxVectorSize()));
609609
return result;
610610
}
611611

@@ -625,9 +625,9 @@ protected int getAVX3Threshold() {
625625
}
626626

627627
@Override
628-
public Variable emitArrayIndexOf(JavaKind arrayKind, JavaKind valueKind, boolean findTwoConsecutive, Value arrayPointer, Value arrayLength, Value fromIndex, Value... searchValues) {
628+
public Variable emitArrayIndexOf(int arrayBaseOffset, JavaKind valueKind, boolean findTwoConsecutive, Value arrayPointer, Value arrayLength, Value fromIndex, Value... searchValues) {
629629
Variable result = newVariable(LIRKind.value(AMD64Kind.DWORD));
630-
append(new AMD64ArrayIndexOfOp(arrayKind, valueKind, findTwoConsecutive, getMaxVectorSize(), this, result,
630+
append(new AMD64ArrayIndexOfOp(arrayBaseOffset, valueKind, findTwoConsecutive, getMaxVectorSize(), this, result,
631631
asAllocatable(arrayPointer), asAllocatable(arrayLength), asAllocatable(fromIndex), searchValues));
632632
return result;
633633
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,4 +282,7 @@ public final class GraalOptions {
282282

283283
@Option(help = "String.indexOf invocations will be evaluated at compile time if the receiver is a constant and its length is lower than this value.", type = OptionType.Expert)
284284
public static final OptionKey<Integer> StringIndexOfLimit = new OptionKey<>(4096);
285+
286+
@Option(help = "Emit substitutions for String methods", type = OptionType.Debug)//
287+
public static final OptionKey<Boolean> EmitStringSubstitutions = new OptionKey<>(true);
285288
}

compiler/src/org.graalvm.compiler.core.sparc/src/org/graalvm/compiler/core/sparc/SPARCLIRGenerator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,9 +420,9 @@ public Variable emitByteSwap(Value input) {
420420
}
421421

422422
@Override
423-
public Variable emitArrayEquals(JavaKind kind, Value array1, Value array2, Value length, boolean directPointers) {
423+
public Variable emitArrayEquals(JavaKind kind, int array1BaseOffset, int array2BaseOffset, Value array1, Value array2, Value length, boolean directPointers) {
424424
Variable result = newVariable(LIRKind.value(SPARCKind.WORD));
425-
append(new SPARCArrayEqualsOp(this, kind, result, load(array1), load(array2), asAllocatable(length), directPointers));
425+
append(new SPARCArrayEqualsOp(this, kind, array1BaseOffset, array2BaseOffset, result, load(array1), load(array2), asAllocatable(length), directPointers));
426426
return result;
427427
}
428428

compiler/src/org.graalvm.compiler.graph/src/org/graalvm/compiler/graph/NodeClass.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,7 +1388,7 @@ public void registerAtInputsAsUsage(Node node) {
13881388
if ((myMask & LIST_MASK) == 0) {
13891389
Node curNode = Edges.getNodeUnsafe(node, offset);
13901390
if (curNode != null) {
1391-
assert curNode.isAlive() : "Input not alive " + curNode;
1391+
assert curNode.isAlive() : "Input " + curNode + " of node " + node + " is not alive";
13921392
curNode.addUsage(node);
13931393
}
13941394
} else {
@@ -1404,7 +1404,7 @@ private static void registerAtInputsAsUsageHelper(Node node, long offset) {
14041404
for (int i = 0; i < list.size(); ++i) {
14051405
Node curNode = list.get(i);
14061406
if (curNode != null) {
1407-
assert curNode.isAlive() : "Input not alive";
1407+
assert curNode.isAlive() : "Input not alive " + curNode;
14081408
curNode.addUsage(node);
14091409
}
14101410
}

compiler/src/org.graalvm.compiler.graph/src/org/graalvm/compiler/graph/NodeList.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.Iterator;
3131
import java.util.List;
3232
import java.util.RandomAccess;
33+
import java.util.stream.Stream;
3334

3435
import org.graalvm.compiler.core.common.PermanentBailoutException;
3536
import org.graalvm.compiler.graph.iterators.NodeIterable;
@@ -264,6 +265,11 @@ public boolean equals(Object other) {
264265
return false;
265266
}
266267

268+
@Override
269+
public Stream<T> stream() {
270+
return super.stream();
271+
}
272+
267273
@SuppressWarnings("unchecked")
268274
@Override
269275
public void clear() {
@@ -489,6 +495,11 @@ public SubList<R> subList(int startIndex) {
489495
public Iterator<R> iterator() {
490496
return new NodeListIterator<>(list, offset);
491497
}
498+
499+
@Override
500+
public Stream<R> stream() {
501+
return super.stream();
502+
}
492503
}
493504

494505
private static final class NodeListIterator<R extends Node> implements Iterator<R> {

compiler/src/org.graalvm.compiler.graph/src/org/graalvm/compiler/graph/iterators/NodeIterable.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import java.util.Collection;
2929
import java.util.Iterator;
3030
import java.util.List;
31+
import java.util.stream.Stream;
32+
import java.util.stream.StreamSupport;
3133

3234
import org.graalvm.compiler.graph.Node;
3335

@@ -88,4 +90,8 @@ default boolean contains(T node) {
8890
}
8991
return false;
9092
}
93+
94+
default Stream<T> stream() {
95+
return StreamSupport.stream(spliterator(), false);
96+
}
9197
}

compiler/src/org.graalvm.compiler.hotspot.aarch64/src/org/graalvm/compiler/hotspot/aarch64/AArch64HotSpotBackendFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ protected Plugins createGraphBuilderPlugins(HotSpotGraalRuntimeProvider graalRun
100100
options,
101101
target);
102102
AArch64GraphBuilderPlugins.register(plugins, replacements, false, //
103-
/* registerForeignCallMath */true, /* emitJDK9StringSubstitutions */true, config.useFMAIntrinsics);
103+
/* registerForeignCallMath */true, config.useFMAIntrinsics, options);
104104
return plugins;
105105
}
106106

compiler/src/org.graalvm.compiler.hotspot.amd64/src/org/graalvm/compiler/hotspot/amd64/AMD64HotSpotBackendFactory.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
import org.graalvm.compiler.phases.common.AddressLoweringPhase;
4949
import org.graalvm.compiler.phases.tiers.CompilerConfiguration;
5050
import org.graalvm.compiler.replacements.amd64.AMD64GraphBuilderPlugins;
51-
import org.graalvm.compiler.serviceprovider.JavaVersionUtil;
5251
import org.graalvm.compiler.serviceprovider.ServiceProvider;
5352

5453
import jdk.vm.ci.amd64.AMD64;
@@ -91,7 +90,7 @@ protected Plugins createGraphBuilderPlugins(HotSpotGraalRuntimeProvider graalRun
9190
replacements,
9291
options,
9392
target);
94-
AMD64GraphBuilderPlugins.register(plugins, replacements, (AMD64) target.arch, false, JavaVersionUtil.JAVA_SPEC >= 9, config.useFMAIntrinsics);
93+
AMD64GraphBuilderPlugins.register(plugins, replacements, (AMD64) target.arch, false, config.useFMAIntrinsics, options);
9594
return plugins;
9695
}
9796

compiler/src/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/replacements/HotSpotAllocationSnippets.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,13 @@ public Object allocateArray(KlassPointer hub,
165165
@ConstantParameter int arrayBaseOffset,
166166
@ConstantParameter int log2ElementSize,
167167
@ConstantParameter boolean fillContents,
168+
@ConstantParameter int fillStartOffset,
168169
@ConstantParameter boolean emitMemoryBarrier,
169170
@ConstantParameter boolean maybeUnroll,
170171
@ConstantParameter boolean supportsBulkZeroing,
171172
@ConstantParameter boolean supportsOptimizedFilling,
172173
@ConstantParameter HotSpotAllocationProfilingData profilingData) {
173-
Object result = allocateArrayImpl(hub.asWord(), prototypeMarkWord, length, arrayBaseOffset, log2ElementSize, fillContents, emitMemoryBarrier, maybeUnroll, supportsBulkZeroing,
174+
Object result = allocateArrayImpl(hub.asWord(), prototypeMarkWord, length, arrayBaseOffset, log2ElementSize, fillContents, fillStartOffset, emitMemoryBarrier, maybeUnroll, supportsBulkZeroing,
174175
supportsOptimizedFilling, profilingData);
175176
return piArrayCastToSnippetReplaceeStamp(result, length);
176177
}
@@ -244,14 +245,15 @@ public Object allocatePrimitiveArrayPIC(KlassPointer hub,
244245
@ConstantParameter int arrayBaseOffset,
245246
@ConstantParameter int log2ElementSize,
246247
@ConstantParameter boolean fillContents,
248+
@ConstantParameter int fillStartOffset,
247249
@ConstantParameter boolean emitMemoryBarrier,
248250
@ConstantParameter boolean maybeUnroll,
249251
@ConstantParameter boolean supportsBulkZeroing,
250252
@ConstantParameter boolean supportsOptimizedFilling,
251253
@ConstantParameter HotSpotAllocationProfilingData profilingData) {
252254
// Primitive array types are eagerly pre-resolved. We can use a floating load.
253255
KlassPointer picHub = LoadConstantIndirectlyNode.loadKlass(hub);
254-
return allocateArrayImpl(picHub.asWord(), prototypeMarkWord, length, arrayBaseOffset, log2ElementSize, fillContents, emitMemoryBarrier, maybeUnroll, supportsBulkZeroing,
256+
return allocateArrayImpl(picHub.asWord(), prototypeMarkWord, length, arrayBaseOffset, log2ElementSize, fillContents, fillStartOffset, emitMemoryBarrier, maybeUnroll, supportsBulkZeroing,
255257
supportsOptimizedFilling, profilingData);
256258
}
257259

@@ -262,14 +264,15 @@ public Object allocateArrayPIC(KlassPointer hub,
262264
@ConstantParameter int arrayBaseOffset,
263265
@ConstantParameter int log2ElementSize,
264266
@ConstantParameter boolean fillContents,
267+
@ConstantParameter int fillStartOffset,
265268
@ConstantParameter boolean emitMemoryBarrier,
266269
@ConstantParameter boolean maybeUnroll,
267270
@ConstantParameter boolean supportsBulkZeroing,
268271
@ConstantParameter boolean supportsOptimizedFilling,
269272
@ConstantParameter HotSpotAllocationProfilingData profilingData) {
270273
// Array type would be resolved by dominating resolution.
271274
KlassPointer picHub = LoadConstantIndirectlyFixedNode.loadKlass(hub);
272-
return allocateArrayImpl(picHub.asWord(), prototypeMarkWord, length, arrayBaseOffset, log2ElementSize, fillContents, emitMemoryBarrier, maybeUnroll, supportsBulkZeroing,
275+
return allocateArrayImpl(picHub.asWord(), prototypeMarkWord, length, arrayBaseOffset, log2ElementSize, fillContents, fillStartOffset, emitMemoryBarrier, maybeUnroll, supportsBulkZeroing,
273276
supportsOptimizedFilling, profilingData);
274277
}
275278

@@ -325,9 +328,8 @@ public Object allocateArrayDynamic(Class<?> elementType,
325328

326329
int arrayBaseOffset = (layoutHelper >> layoutHelperHeaderSizeShift(INJECTED_VMCONFIG)) & layoutHelperHeaderSizeMask(INJECTED_VMCONFIG);
327330
int log2ElementSize = (layoutHelper >> layoutHelperLog2ElementSizeShift(INJECTED_VMCONFIG)) & layoutHelperLog2ElementSizeMask(INJECTED_VMCONFIG);
328-
329-
Object result = allocateArrayImpl(nonNullKlass.asWord(), prototypeMarkWord, length, arrayBaseOffset, log2ElementSize, fillContents, emitMemoryBarrier, false, supportsBulkZeroing,
330-
supportsOptimizedFilling, profilingData);
331+
Object result = allocateArrayImpl(nonNullKlass.asWord(), prototypeMarkWord, length, arrayBaseOffset, log2ElementSize, fillContents, arrayBaseOffset, emitMemoryBarrier, false,
332+
supportsBulkZeroing, supportsOptimizedFilling, profilingData);
331333
return piArrayCastToSnippetReplaceeStamp(result, length);
332334
}
333335

@@ -418,7 +420,7 @@ static boolean useNullAllocationStubs(@InjectedParameter GraalHotSpotVMConfig co
418420
}
419421

420422
@Override
421-
protected final Object callNewArrayStub(Word hub, int length) {
423+
protected final Object callNewArrayStub(Word hub, int length, int fillStartOffset) {
422424
KlassPointer klassPtr = KlassPointer.fromWord(hub);
423425
if (useNullAllocationStubs(INJECTED_VMCONFIG)) {
424426
return nonNullOrDeopt(newArrayOrNull(NEW_ARRAY_OR_NULL, klassPtr, length));
@@ -722,6 +724,7 @@ public void lower(NewArrayNode node, LoweringTool tool) {
722724
args.addConst("arrayBaseOffset", arrayBaseOffset);
723725
args.addConst("log2ElementSize", log2ElementSize);
724726
args.addConst("fillContents", node.fillContents());
727+
args.addConst("fillStartOffset", arrayBaseOffset);
725728
args.addConst("emitMemoryBarrier", node.emitMemoryBarrier());
726729
args.addConst("maybeUnroll", length.isConstant());
727730
args.addConst("supportsBulkZeroing", tool.getLowerer().supportsBulkZeroing());

0 commit comments

Comments
 (0)