Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ public byte[] allocateByteArray(int length) {
return allocator.allocateByteArray(length);
}

@Override
public int[] allocateIntArray(int length) {
return allocator.allocateIntArray(length);
}

@Override
public void walkObjects(ObjectVisitor visitor) {
assert VMOperation.isInProgress() : "prevent other threads from manipulating the metaspace";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ public byte[] allocateByteArray(int length) {
return (byte[]) allocateArrayLikeObject(hub, length);
}

public int[] allocateIntArray(int length) {
DynamicHub hub = DynamicHub.fromClass(int[].class);
return (int[]) allocateArrayLikeObject(hub, length);
}

@Uninterruptible(reason = "Holds uninitialized memory.")
private Object allocateArrayLikeObject(DynamicHub hub, int arrayLength) {
UnsignedWord size = LayoutEncoding.getArrayAllocationSize(hub.getLayoutEncoding(), arrayLength);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.oracle.svm.core.config.ConfigurationValues;
import com.oracle.svm.core.heap.InstanceReferenceMapDecoder.InstanceReferenceMap;
import com.oracle.svm.core.snippets.KnownIntrinsics;
import com.oracle.svm.core.util.DuplicatedInNativeCode;
import com.oracle.svm.core.util.VMError;

import jdk.graal.compiler.core.common.NumUtil;
Expand All @@ -56,6 +57,7 @@
* </ul>
*/
public class InstanceReferenceMapEncoder extends ReferenceMapEncoder {
@DuplicatedInNativeCode //
public static final int REFERENCE_MAP_COMPRESSED_OFFSET_SHIFT = 2;

public static final int MAP_HEADER_SIZE = 4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ public final class DynamicHub implements AnnotatedElement, java.lang.reflect.Typ

/**
* Array containing this type's type check id information. During a type check, these slots are
* searched for a matching typeID.
* searched for a matching typeID. This array may be used by the garbage collector and therefore
* needs to live in the image heap or {@link Metaspace}.
*/
@UnknownObjectField(availability = AfterHostedUniverse.class)//
private int[] openTypeWorldTypeCheckSlots;
Expand All @@ -306,7 +307,8 @@ public final class DynamicHub implements AnnotatedElement, java.lang.reflect.Typ
/**
* HashTable used for interface hashing under open type world if
* {@link SubstrateOptions#useInterfaceHashing()} is enabled. See TypeCheckBuilder for a general
* documentation.
* documentation. This array may be used by the garbage collector and therefore needs to live in
* the image heap or {@link Metaspace}.
*/
@UnknownObjectField(availability = AfterHostedUniverse.class)//
private int[] openTypeWorldInterfaceHashTable;
Expand Down Expand Up @@ -480,8 +482,8 @@ public static DynamicHub allocate(String name, DynamicHub superHub, Object inter
short numClassTypes,
short typeIDDepth,
short numIterableInterfaceTypes,
int[] openTypeWorldTypeCheckSlots,
int[] openTypeWorldInterfaceHashTable,
int[] typeCheckSlotsHeapArray,
int[] interfaceHashTableHeapArray,
int openTypeWorldInterfaceHashParam,
int vTableEntries,
int afterFieldsOffset, boolean valueBased) {
Expand Down Expand Up @@ -585,16 +587,18 @@ public static DynamicHub allocate(String name, DynamicHub superHub, Object inter
// GR-61330: only write if the field exists according to analysis
// companion.metaType = null;

int referenceMapCompressedOffset = RuntimeInstanceReferenceMapSupport.singleton().getOrCreateReferenceMap(superHub);

// GR-57813
companion.hubMetadata = null;
companion.reflectionMetadata = null;

/* Allocate memory in the metaspace and copy data from the Java heap to the metaspace. */
DynamicHub hub = Metaspace.singleton().allocateDynamicHub(vTableEntries);
int[] openTypeWorldTypeCheckSlots = Metaspace.singleton().copyToMetaspace(typeCheckSlotsHeapArray);
int[] openTypeWorldInterfaceHashTable = Metaspace.singleton().copyToMetaspace(interfaceHashTableHeapArray);
int referenceMapCompressedOffset = RuntimeInstanceReferenceMapSupport.singleton().getOrCreateReferenceMap(superHub);

DynamicHubOffsets dynamicHubOffsets = DynamicHubOffsets.singleton();
/* Write fields in defining order. */
DynamicHubOffsets dynamicHubOffsets = DynamicHubOffsets.singleton();
writeObject(hub, dynamicHubOffsets.getNameOffset(), name);
writeByte(hub, dynamicHubOffsets.getHubTypeOffset(), hubType);
writeByte(hub, dynamicHubOffsets.getReferenceTypeOffset(), referenceType.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,8 @@ private synchronized int putIfAbsent(byte[] newHeapMap) {
return toCompressedOffset(existingMetaspaceMapHolder.refMap);
}

/* Copy the data to the metaspace. */
byte[] newMetaspaceMap = Metaspace.singleton().allocateByteArray(newHeapMap.length);
System.arraycopy(newHeapMap, 0, newMetaspaceMap, 0, newHeapMap.length);

/* Store the new reference map in the hash map. */
/* Copy the data to the metaspace and store the new reference map in the hash map. */
byte[] newMetaspaceMap = Metaspace.singleton().copyToMetaspace(newHeapMap);
ReferenceMapHolder newMetaspaceMapHolder = new ReferenceMapHolder(newMetaspaceMap);
refMaps.put(newMetaspaceMapHolder, newMetaspaceMapHolder);
return toCompressedOffset(newMetaspaceMapHolder.refMap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,21 @@ static boolean isSupported() {
/** Allocates a byte array. */
byte[] allocateByteArray(int length);

/** Allocates an int array. */
int[] allocateIntArray(int length);

default byte[] copyToMetaspace(byte[] heapArray) {
byte[] result = Metaspace.singleton().allocateByteArray(heapArray.length);
System.arraycopy(heapArray, 0, result, 0, heapArray.length);
return result;
}

default int[] copyToMetaspace(int[] heapArray) {
int[] result = Metaspace.singleton().allocateIntArray(heapArray.length);
System.arraycopy(heapArray, 0, result, 0, heapArray.length);
return result;
}

/** Walks all metaspace objects. May only be called at a safepoint. */
void walkObjects(ObjectVisitor visitor);
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ public byte[] allocateByteArray(int length) {
throw VMError.shouldNotReachHere("Must not be called if metaspace support is not available.");
}

@Override
public int[] allocateIntArray(int length) {
throw VMError.shouldNotReachHere("Must not be called if metaspace support is not available.");
}

@Override
public void walkObjects(ObjectVisitor visitor) {
/* Nothing to do. */
Expand Down