Skip to content

Commit

Permalink
Remove signatureOffset from DynamicHubOffsets
Browse files Browse the repository at this point in the history
The offset was left at 0 and caused the hub to be overwritten.

Added some checks to verify that all offsets correspond to existing
fields.
  • Loading branch information
gilles-duboscq committed Jan 23, 2025
1 parent f6e5249 commit 024a51e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.lang.reflect.Field;
import java.util.Arrays;

import jdk.graal.compiler.word.BarrieredAccess;
import org.graalvm.nativeimage.AnnotationAccess;
import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.Platform;
Expand All @@ -41,54 +40,53 @@
import com.oracle.svm.util.ReflectionUtil;

import jdk.graal.compiler.api.replacements.Fold;
import jdk.graal.compiler.word.BarrieredAccess;
import jdk.vm.ci.meta.MetaAccessProvider;
import jdk.vm.ci.meta.ResolvedJavaField;

public class DynamicHubOffsets {
private static final int UNINITIALIZED = -1;
/* defining order in DynamicHub */

@UnknownPrimitiveField(availability = BuildPhaseProvider.ReadyForCompilation.class) //
private int nameOffset;
private int nameOffset = UNINITIALIZED;
@UnknownPrimitiveField(availability = BuildPhaseProvider.ReadyForCompilation.class) //
private int hubTypeOffset;
private int hubTypeOffset = UNINITIALIZED;
@UnknownPrimitiveField(availability = BuildPhaseProvider.ReadyForCompilation.class) //
private int referenceTypeOffset;
private int referenceTypeOffset = UNINITIALIZED;

@UnknownPrimitiveField(availability = BuildPhaseProvider.ReadyForCompilation.class) //
private int layoutEncodingOffset;
private int layoutEncodingOffset = UNINITIALIZED;
@UnknownPrimitiveField(availability = BuildPhaseProvider.ReadyForCompilation.class) //
private int typeIDOffset;
private int typeIDOffset = UNINITIALIZED;
@UnknownPrimitiveField(availability = BuildPhaseProvider.ReadyForCompilation.class) //
private int typeIDDepthOffset;
private int typeIDDepthOffset = UNINITIALIZED;
@UnknownPrimitiveField(availability = BuildPhaseProvider.ReadyForCompilation.class) //
private int numClassTypesOffset;
private int numClassTypesOffset = UNINITIALIZED;

@UnknownPrimitiveField(availability = BuildPhaseProvider.ReadyForCompilation.class) //
private int numInterfaceTypesOffset;
private int numInterfaceTypesOffset = UNINITIALIZED;
@UnknownPrimitiveField(availability = BuildPhaseProvider.ReadyForCompilation.class) //
private int openTypeWorldTypeCheckSlotsOffset;
private int openTypeWorldTypeCheckSlotsOffset = UNINITIALIZED;

@UnknownPrimitiveField(availability = BuildPhaseProvider.ReadyForCompilation.class) //
private int monitorOffsetOffset;
private int monitorOffsetOffset = UNINITIALIZED;
@UnknownPrimitiveField(availability = BuildPhaseProvider.ReadyForCompilation.class) //
private int identityHashOffsetOffset;
private int identityHashOffsetOffset = UNINITIALIZED;

@UnknownPrimitiveField(availability = BuildPhaseProvider.ReadyForCompilation.class) //
private int flagsOffset;
private int flagsOffset = UNINITIALIZED;

@UnknownPrimitiveField(availability = BuildPhaseProvider.ReadyForCompilation.class) //
private int componentTypeOffset;
private int componentTypeOffset = UNINITIALIZED;

@UnknownPrimitiveField(availability = BuildPhaseProvider.ReadyForCompilation.class) //
private int referenceMapIndexOffset;
@UnknownPrimitiveField(availability = BuildPhaseProvider.ReadyForCompilation.class) //
private int layerIdOffset;

private int referenceMapIndexOffset = UNINITIALIZED;
@UnknownPrimitiveField(availability = BuildPhaseProvider.ReadyForCompilation.class) //
private int companionOffset;
private int layerIdOffset = UNINITIALIZED;

@UnknownPrimitiveField(availability = BuildPhaseProvider.ReadyForCompilation.class) //
private int signatureOffset;
private int companionOffset = UNINITIALIZED;

@Fold
public static DynamicHubOffsets singleton() {
Expand Down Expand Up @@ -121,6 +119,18 @@ public void initializeOffsets(MetaAccessProvider metaAccess) {
throw VMError.shouldNotReachHere(e);
}
}
// Ensure the expected fields exist
for (Field field : DynamicHubOffsets.class.getDeclaredFields()) {
String name = field.getName();
if (!name.endsWith("Offset")) {
continue;
}
try {
DynamicHub.class.getDeclaredField(name.substring(0, name.length() - "Offset".length()));
} catch (NoSuchFieldException e) {
throw VMError.shouldNotReachHere(e);
}
}
}

public int getNameOffset() {
Expand Down Expand Up @@ -187,10 +197,6 @@ public int getCompanionOffset() {
return companionOffset;
}

public int getSignatureOffset() {
return signatureOffset;
}

public static void writeObject(DynamicHub hub, int offset, Object value) {
if (offset < 0) {
/* field removed by analysis */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,6 @@ public static DynamicHub allocate(String name, DynamicHub superHub, DynamicHub c

writeObject(hub, dynamicHubOffsets.getCompanionOffset(), companion);

writeObject(hub, dynamicHubOffsets.getSignatureOffset(), signature);

FinalFieldBarrierNode.finalFieldBarrier(hub);

return hub;
Expand Down

0 comments on commit 024a51e

Please sign in to comment.