Skip to content

Commit

Permalink
Disable fast path allocation for types which must be slow path allocated
Browse files Browse the repository at this point in the history
(cherry picked from commit 6cbcc1a)
  • Loading branch information
tkrodriguez authored and marwan-hallaoui committed Oct 3, 2023
1 parent 33bde2c commit 7e2bd5c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,11 @@ public HotSpotAllocationSnippets(GraalHotSpotVMConfig config, HotSpotRegistersPr
@Snippet
protected Object allocateInstance(KlassPointer hub,
@ConstantParameter long size,
@ConstantParameter boolean forceSlowPath,
@ConstantParameter FillContent fillContents,
@ConstantParameter boolean emitMemoryBarrier,
@ConstantParameter HotSpotAllocationProfilingData profilingData) {
Object result = allocateInstanceImpl(hub.asWord(), WordFactory.unsigned(size), fillContents, emitMemoryBarrier, true, profilingData);
Object result = allocateInstanceImpl(hub.asWord(), WordFactory.unsigned(size), forceSlowPath, fillContents, emitMemoryBarrier, true, profilingData);
return piCastToSnippetReplaceeStamp(result);
}

Expand Down Expand Up @@ -194,7 +195,7 @@ public Object allocateInstanceDynamic(@NonNullParameter Class<?> type,
* binding of parameters is not yet supported by the GraphBuilderPlugin system.
*/
UnsignedWord size = WordFactory.unsigned(layoutHelper);
return allocateInstanceImpl(nonNullHub.asWord(), size, fillContents, emitMemoryBarrier, false, profilingData);
return allocateInstanceImpl(nonNullHub.asWord(), size, false, fillContents, emitMemoryBarrier, false, profilingData);
}
} else {
DeoptimizeNode.deopt(None, RuntimeConstraint);
Expand Down Expand Up @@ -657,12 +658,14 @@ public void lower(NewInstanceNode node, LoweringTool tool) {
HotSpotResolvedObjectType type = (HotSpotResolvedObjectType) node.instanceClass();
assert !type.isArray();
ConstantNode hub = ConstantNode.forConstant(KlassPointerStamp.klassNonNull(), type.klass(), tool.getMetaAccess(), graph);
long size = instanceSize(type);
long size = type.instanceSize();

OptionValues localOptions = graph.getOptions();
Arguments args = new Arguments(allocateInstance, graph.getGuardsStage(), tool.getLoweringStage());
args.add("hub", hub);
args.addConst("size", size);
// instanceSize returns a negative number for types which should be slow path allocated
args.addConst("size", Math.abs(size));
args.addConst("forceSlowPath", size < 0);
args.addConst("fillContents", FillContent.fromBoolean(node.fillContents()));
args.addConst("emitMemoryBarrier", node.emitMemoryBarrier());
args.addConst("profilingData", getProfilingData(localOptions, "instance", type));
Expand Down Expand Up @@ -794,11 +797,6 @@ private static HotSpotResolvedObjectType lookupArrayClass(LoweringTool tool, Jav
return HotSpotAllocationSnippets.lookupArrayClass(tool.getMetaAccess(), kind);
}

private static long instanceSize(HotSpotResolvedObjectType type) {
long size = type.instanceSize();
assert size >= 0;
return size;
}
}

private static class HotSpotAllocationProfilingData extends AllocationProfilingData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
public abstract class AllocationSnippets implements Snippets {
protected Object allocateInstanceImpl(Word hub,
UnsignedWord size,
boolean forceSlowPath,
FillContent fillContents,
boolean emitMemoryBarrier,
boolean constantSize,
Expand All @@ -58,7 +59,7 @@ protected Object allocateInstanceImpl(Word hub,
Word top = readTlabTop(tlabInfo);
Word end = readTlabEnd(tlabInfo);
Word newTop = top.add(size);
if (useTLAB() && probability(FAST_PATH_PROBABILITY, shouldAllocateInTLAB(size, false)) && probability(FAST_PATH_PROBABILITY, newTop.belowOrEqual(end))) {
if (!forceSlowPath && useTLAB() && probability(FAST_PATH_PROBABILITY, shouldAllocateInTLAB(size, false)) && probability(FAST_PATH_PROBABILITY, newTop.belowOrEqual(end))) {
writeTlabTop(tlabInfo, newTop);
emitPrefetchAllocate(newTop, false);
result = formatObject(hub, size, top, fillContents, emitMemoryBarrier, constantSize, profilingData.snippetCounters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ protected int getBaseInstanceSize(Class<?> type) {

HotSpotMetaAccessProvider meta = (HotSpotMetaAccessProvider) getMetaAccess();
HotSpotResolvedObjectType resolvedType = (HotSpotResolvedObjectType) meta.lookupJavaType(type);
return resolvedType.instanceSize();
return Math.abs(resolvedType.instanceSize());
}

private static boolean fieldIsNotEligible(Class<?> clazz, ResolvedJavaField f) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ protected Object allocateInstance(@NonNullParameter DynamicHub hub,
@ConstantParameter FillContent fillContents,
@ConstantParameter boolean emitMemoryBarrier,
@ConstantParameter AllocationProfilingData profilingData) {
Object result = allocateInstanceImpl(encodeAsTLABObjectHeader(hub), WordFactory.unsigned(size), fillContents, emitMemoryBarrier, true, profilingData);
Object result = allocateInstanceImpl(encodeAsTLABObjectHeader(hub), WordFactory.unsigned(size), false, fillContents, emitMemoryBarrier, true, profilingData);
return piCastToSnippetReplaceeStamp(result);
}

Expand Down Expand Up @@ -230,7 +230,7 @@ protected Object allocateInstanceDynamicImpl(DynamicHub hub, FillContent fillCon
@SuppressWarnings("unused") boolean supportsOptimizedFilling, AllocationProfilingData profilingData) {
// The hub was already verified by a ValidateNewInstanceClassNode.
UnsignedWord size = LayoutEncoding.getPureInstanceAllocationSize(hub.getLayoutEncoding());
Object result = allocateInstanceImpl(encodeAsTLABObjectHeader(hub), size, fillContents, emitMemoryBarrier, false, profilingData);
Object result = allocateInstanceImpl(encodeAsTLABObjectHeader(hub), size, false, fillContents, emitMemoryBarrier, false, profilingData);
return piCastToSnippetReplaceeStamp(result);
}

Expand Down

0 comments on commit 7e2bd5c

Please sign in to comment.