Skip to content

Commit

Permalink
[GR-49219] Backport 23.0 : Properly handle negative instance sizes on…
Browse files Browse the repository at this point in the history
… HotSpot.

PullRequest: graal/15706
  • Loading branch information
marwan-hallaoui committed Oct 4, 2023
2 parents fcb8daf + 59857a6 commit 66b451d
Show file tree
Hide file tree
Showing 6 changed files with 404 additions and 14 deletions.
5 changes: 5 additions & 0 deletions compiler/mx.compiler/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -1526,6 +1526,11 @@
"requires" : [
"jdk.unsupported",
],
"requiresConcealed" : {
"java.base" : [
"jdk.internal.vm.annotation",
]
},
"checkstyle" : "org.graalvm.compiler.graph",
"javaCompliance" : "17+",
"workingSets" : "Graal,Test",
Expand Down
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
Loading

0 comments on commit 66b451d

Please sign in to comment.