Skip to content

Commit 117a113

Browse files
committed
Distinguish arrays and hybrids in layout encoding.
1 parent a76eff1 commit 117a113

File tree

14 files changed

+106
-67
lines changed

14 files changed

+106
-67
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public void printDiagnostics(Log log, ErrorContext context, int maxDiagnosticLev
166166
DynamicHub hub = (DynamicHub) headerHub.toObject();
167167
log.string(" class: ").string(hub.getName());
168168
Object entryAsObject = objectEntry.toObject();
169-
if (LayoutEncoding.isArray(entryAsObject)) {
169+
if (LayoutEncoding.isArrayLike(entryAsObject)) {
170170
int length = ArrayLengthNode.arrayLength(entryAsObject);
171171
log.string(" length: ").signed(length);
172172
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ private static Object slowPathNewArrayWithoutAllocating(DynamicHub hub, int leng
294294

295295
@Uninterruptible(reason = "Holds uninitialized memory.")
296296
private static Object allocateInstanceInNewTlab(DynamicHub hub, AlignedHeader newTlabChunk) {
297-
UnsignedWord size = LayoutEncoding.getInstanceSize(hub.getLayoutEncoding());
297+
UnsignedWord size = LayoutEncoding.getPureInstanceSize(hub.getLayoutEncoding());
298298
Pointer memory = allocateRawMemoryInNewTlab(size, newTlabChunk);
299299
return FormatObjectNode.formatObject(memory, DynamicHub.toClass(hub), false, FillContent.WITH_ZEROES, true);
300300
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public Object formatObjectSnippet(Word memory, DynamicHub hub, boolean remembere
102102
@ConstantParameter AllocationSnippetCounters snippetCounters) {
103103
DynamicHub hubNonNull = (DynamicHub) PiNode.piCastNonNull(hub, SnippetAnchorNode.anchor());
104104
int layoutEncoding = hubNonNull.getLayoutEncoding();
105-
UnsignedWord size = LayoutEncoding.getInstanceSize(layoutEncoding);
105+
UnsignedWord size = LayoutEncoding.getPureInstanceSize(layoutEncoding);
106106
Word objectHeader = encodeAsObjectHeader(hubNonNull, rememberedSet, false);
107107
return formatObject(objectHeader, size, memory, fillContents, emitMemoryBarrier, false, snippetCounters);
108108
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ private static boolean isObjectArray(DynamicHub hub) {
315315

316316
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
317317
private static boolean isInstance(DynamicHub hub) {
318-
return LayoutEncoding.isInstance(hub.getLayoutEncoding());
318+
return LayoutEncoding.isPureInstance(hub.getLayoutEncoding());
319319
}
320320

321321
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/annotate/Hybrid.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,10 @@
5959
*
6060
* <p>
6161
* Hybrid objects have {@link HubType#Instance} but a {@link LayoutEncoding} like an array. This is
62-
* important to keep in mind because methods such as {@link Class#isArray()} will return
63-
* {@code false}, while methods such as {@link LayoutEncoding#isArray} will return {@code true} for
64-
* hybrid objects.
62+
* important to keep in mind because methods such as {@link Class#isInstance} will return
63+
* {@code true} and {@link Class#isArray()} will return {@code false}, while
64+
* {@link LayoutEncoding#isPureInstance} will return {@code false} and
65+
* {@link LayoutEncoding#isArrayLike} will return {@code true} and for hybrid objects.
6566
*/
6667
@Retention(RetentionPolicy.RUNTIME)
6768
@Target(ElementType.TYPE)

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/code/CodeInfoEncoder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ private static ValueInfo findActualArrayElement(ValueInfo[] actualObject, Unsign
646646
private static ValueInfo findActualField(ValueInfo[] actualObject, UnsignedWord expectedOffset) {
647647
DynamicHub hub = (DynamicHub) SubstrateObjectConstant.asObject(actualObject[0].getValue());
648648
ObjectLayout objectLayout = ConfigurationValues.getObjectLayout();
649-
assert LayoutEncoding.isInstance(hub.getLayoutEncoding());
649+
assert LayoutEncoding.isPureInstance(hub.getLayoutEncoding());
650650
return findActualValue(actualObject, expectedOffset, objectLayout, WordFactory.unsigned(objectLayout.getFirstFieldOffset()), 1);
651651
}
652652

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/deopt/Deoptimizer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,7 @@ private Object materializeObject(int virtualObjectId, FrameInfoQueryResult sourc
990990
curOffset = LayoutEncoding.getArrayBaseOffset(hub.getLayoutEncoding());
991991
curIdx = 2;
992992
} else {
993+
assert LayoutEncoding.isPureInstance(hub.getLayoutEncoding());
993994
try {
994995
obj = Unsafe.getUnsafe().allocateInstance(DynamicHub.toClass(hub));
995996
} catch (InstantiationException ex) {

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/jdk/SubstrateObjectCloneSnippets.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ private static Object doClone(Object original) throws CloneNotSupportedException
9696

9797
DynamicHub hub = KnownIntrinsics.readHub(original);
9898
int layoutEncoding = hub.getLayoutEncoding();
99-
boolean hasArray = LayoutEncoding.isArray(layoutEncoding);
99+
boolean isArrayLike = LayoutEncoding.isArrayLike(layoutEncoding);
100100

101101
Object result;
102-
if (hasArray) {
103-
// Hybrids like pods have an array encoding, but a non-array hub type.
102+
if (isArrayLike) {
103+
// Hybrids like pods have an array-like encoding, but a non-array hub type.
104104
if (BranchProbabilityNode.probability(FAST_PATH_PROBABILITY, hub.isArray())) {
105105
int length = ArrayLengthNode.arrayLength(original);
106106
Object newArray = java.lang.reflect.Array.newInstance(DynamicHub.toClass(hub.getComponentHub()), length);
@@ -153,8 +153,8 @@ private static Object doClone(Object original) throws CloneNotSupportedException
153153
}
154154

155155
// copy remaining non-object data
156-
if (!hasArray) {
157-
int objectSize = UnsignedUtils.safeToInt(LayoutEncoding.getInstanceSize(layoutEncoding));
156+
if (!isArrayLike) {
157+
int objectSize = UnsignedUtils.safeToInt(LayoutEncoding.getPureInstanceSize(layoutEncoding));
158158
int primitiveDataSize = objectSize - curOffset;
159159
assert primitiveDataSize >= 0;
160160
assert curOffset >= 0;
@@ -182,9 +182,9 @@ static boolean canVirtualize(ObjectClone node, VirtualizerTool tool) {
182182
return false;
183183
}
184184
if (!type.isArray() && type instanceof SharedType) {
185-
// Hybrids are instances with array encoding; cloning them virtually is not implemented.
185+
// Hybrids are instances with array-like encoding; cloning virtually is unimplemented.
186186
int encoding = ((SharedType) type).getHub().getLayoutEncoding();
187-
return !LayoutEncoding.isArray(encoding);
187+
return !LayoutEncoding.isArrayLike(encoding);
188188
}
189189
return true;
190190
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public Object allocateArray(@NonNullParameter DynamicHub hub,
140140
public Object allocateInstanceDynamic(@NonNullParameter DynamicHub hub, @ConstantParameter FillContent fillContents, @ConstantParameter boolean emitMemoryBarrier,
141141
@ConstantParameter AllocationProfilingData profilingData) {
142142
// The hub was already verified by a ValidateNewInstanceClassNode.
143-
UnsignedWord size = LayoutEncoding.getInstanceSize(hub.getLayoutEncoding());
143+
UnsignedWord size = LayoutEncoding.getPureInstanceSize(hub.getLayoutEncoding());
144144
Object result = allocateInstanceImpl(encodeAsTLABObjectHeader(hub), size, fillContents, emitMemoryBarrier, false, profilingData);
145145
return piCastToSnippetReplaceeStamp(result);
146146
}
@@ -168,7 +168,7 @@ protected Object newmultiarray(DynamicHub hub, @ConstantParameter int rank, @Var
168168
private static DynamicHub validateNewInstanceClass(DynamicHub hub) {
169169
if (probability(EXTREMELY_FAST_PATH_PROBABILITY, hub != null)) {
170170
DynamicHub nonNullHub = (DynamicHub) PiNode.piCastNonNull(hub, SnippetAnchorNode.anchor());
171-
if (probability(EXTREMELY_FAST_PATH_PROBABILITY, LayoutEncoding.isInstance(nonNullHub.getLayoutEncoding())) &&
171+
if (probability(EXTREMELY_FAST_PATH_PROBABILITY, LayoutEncoding.isPureInstance(nonNullHub.getLayoutEncoding())) &&
172172
probability(EXTREMELY_FAST_PATH_PROBABILITY, nonNullHub.isInstantiated())) {
173173
return nonNullHub;
174174
}
@@ -212,7 +212,7 @@ private static Object newMultiArrayRecursion(DynamicHub hub, int rank, Word dime
212212
private static void instanceHubErrorStub(DynamicHub hub) throws InstantiationException {
213213
if (hub == null) {
214214
throw new NullPointerException("Allocation type is null.");
215-
} else if (!LayoutEncoding.isInstance(hub.getLayoutEncoding())) {
215+
} else if (!LayoutEncoding.isPureInstance(hub.getLayoutEncoding())) {
216216
throw new InstantiationException("Cannot allocate instance.");
217217
} else if (!hub.isInstantiated()) {
218218
throw new IllegalArgumentException("Type " + DynamicHub.toClass(hub).getTypeName() + " is instantiated reflectively but was never registered." +
@@ -443,7 +443,7 @@ public void lower(NewInstanceNode node, LoweringTool tool) {
443443
DynamicHub hub = ensureMarkedAsInstantiated(type.getHub());
444444

445445
ConstantNode hubConstant = ConstantNode.forConstant(SubstrateObjectConstant.forObject(hub), providers.getMetaAccess(), graph);
446-
long size = LayoutEncoding.getInstanceSize(hub.getLayoutEncoding()).rawValue();
446+
long size = LayoutEncoding.getPureInstanceSize(hub.getLayoutEncoding()).rawValue();
447447

448448
Arguments args = new Arguments(allocateInstance, graph.getGuardsStage(), tool.getLoweringStage());
449449
args.add("hub", hubConstant);

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/InteriorObjRefWalker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public static boolean walkObjectInline(final Object obj, final ObjectReferenceVi
6666
final Pointer objPointer = Word.objectToUntrackedPointer(obj);
6767

6868
// Visit each Object reference in the array part of the Object.
69-
if (LayoutEncoding.isObjectArray(layoutEncoding)) {
69+
if (LayoutEncoding.isArrayLikeWithObjectElements(layoutEncoding)) {
7070
int length = ArrayLengthNode.arrayLength(obj);
7171
int referenceSize = ConfigurationValues.getObjectLayout().getReferenceSize();
7272
boolean isCompressed = ReferenceAccess.singleton().haveCompressedReferences();

0 commit comments

Comments
 (0)