Skip to content

Commit

Permalink
[GR-49879] Backport to 23.0: Add an option to artificially increase t…
Browse files Browse the repository at this point in the history
…he header size.

PullRequest: graal/16103
  • Loading branch information
medoussboug committed Dec 5, 2023
2 parents ed0e1de + 2abe819 commit 7edc294
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,16 @@ protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, Boolean o
@Option(help = "How many bytes to pad fields and classes marked @Contended with.") //
public static final HostedOptionKey<Integer> ContendedPaddingWidth = new HostedOptionKey<>(128);

@Option(help = "Add additional header bytes to each object, for diagnostic purposes.", type = OptionType.Debug) //
public static final HostedOptionKey<Integer> AdditionalHeaderBytes = new HostedOptionKey<>(0, SubstrateOptions::validateAdditionalHeaderBytes);

private static void validateAdditionalHeaderBytes(HostedOptionKey<Integer> optionKey) {
int value = optionKey.getValue();
if (value < 0 || value % 4 != 0) {
throw UserError.abort("The option '%s' must be 0 or a multiple of 4.", optionKey.getName());
}
}

/*
* Isolate tear down options.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ public final class ObjectLayout {

public ObjectLayout(SubstrateTargetDescription target, int referenceSize, int objectAlignment, int hubOffset,
int firstFieldOffset, int arrayLengthOffset, int arrayBaseOffset, int fixedIdentityHashOffset) {
assert CodeUtil.isPowerOf2(referenceSize);
assert CodeUtil.isPowerOf2(objectAlignment);
assert hubOffset < firstFieldOffset && hubOffset < arrayLengthOffset;
assert fixedIdentityHashOffset == -1 || (fixedIdentityHashOffset > 0 && fixedIdentityHashOffset < arrayLengthOffset);
assert CodeUtil.isPowerOf2(referenceSize) : referenceSize;
assert CodeUtil.isPowerOf2(objectAlignment) : objectAlignment;
assert arrayLengthOffset % Integer.BYTES == 0;
assert hubOffset < firstFieldOffset && hubOffset < arrayLengthOffset : hubOffset;
assert fixedIdentityHashOffset == -1 || (fixedIdentityHashOffset > 0 && fixedIdentityHashOffset < arrayLengthOffset) : fixedIdentityHashOffset;

this.target = target;
this.referenceSize = referenceSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,13 @@ public static ObjectLayout createObjectLayout() {
public static ObjectLayout createObjectLayout(JavaKind referenceKind, boolean disableOptionalIdentityHash) {
SubstrateTargetDescription target = ConfigurationValues.getTarget();
int referenceSize = target.arch.getPlatformKind(referenceKind).getSizeInBytes();
int headerSize = referenceSize;
int intSize = target.arch.getPlatformKind(JavaKind.Int).getSizeInBytes();
int objectAlignment = 8;

int headerOffset = 0;
int hubOffset = 0;
int headerSize = hubOffset + referenceSize;

int identityHashCodeOffset;
int firstFieldOffset;
if (!disableOptionalIdentityHash && SubstrateOptions.SpawnIsolates.getValue() && headerSize + referenceSize <= objectAlignment) {
/*
* References are relative to the heap base, so we should be able to use fewer bits in
Expand All @@ -158,15 +158,18 @@ public static ObjectLayout createObjectLayout(JavaKind referenceKind, boolean di
* individual object was assigned an identity hash code after allocation.
*/
identityHashCodeOffset = -1;
firstFieldOffset = headerOffset + headerSize;
} else { // need all object header bits except for lowest-order bits freed up by alignment
identityHashCodeOffset = headerOffset + referenceSize;
firstFieldOffset = identityHashCodeOffset + intSize;
identityHashCodeOffset = headerSize;
headerSize += intSize;
}
int arrayLengthOffset = firstFieldOffset;

headerSize += SubstrateOptions.AdditionalHeaderBytes.getValue();

int firstFieldOffset = headerSize;
int arrayLengthOffset = headerSize;
int arrayBaseOffset = arrayLengthOffset + intSize;

return new ObjectLayout(target, referenceSize, objectAlignment, headerOffset, firstFieldOffset, arrayLengthOffset, arrayBaseOffset, identityHashCodeOffset);
return new ObjectLayout(target, referenceSize, objectAlignment, hubOffset, firstFieldOffset, arrayLengthOffset, arrayBaseOffset, identityHashCodeOffset);
}

public SVMHost createHostVM(OptionValues options, ClassLoader classLoader, ClassInitializationSupport classInitializationSupport,
Expand Down

0 comments on commit 7edc294

Please sign in to comment.