use of jdk.vm.ci.meta.JavaKind in project graal by oracle.
the class GraalCompilerTest method checkArgs.
protected void checkArgs(ResolvedJavaMethod method, Object[] args) {
JavaType[] sig = method.toParameterTypes();
Assert.assertEquals(sig.length, args.length);
for (int i = 0; i < args.length; i++) {
JavaType javaType = sig[i];
JavaKind kind = javaType.getJavaKind();
Object arg = args[i];
if (kind == JavaKind.Object) {
if (arg != null && javaType instanceof ResolvedJavaType) {
ResolvedJavaType resolvedJavaType = (ResolvedJavaType) javaType;
Assert.assertTrue(resolvedJavaType + " from " + getMetaAccess().lookupJavaType(arg.getClass()), resolvedJavaType.isAssignableFrom(getMetaAccess().lookupJavaType(arg.getClass())));
}
} else {
Assert.assertNotNull(arg);
Assert.assertEquals(kind.toBoxedJavaClass(), arg.getClass());
}
}
}
use of jdk.vm.ci.meta.JavaKind in project graal by oracle.
the class PEReadEliminationClosure method processStoreIndexed.
private boolean processStoreIndexed(StoreIndexedNode store, PEReadEliminationBlockState state, GraphEffectList effects) {
int index = store.index().isConstant() ? ((JavaConstant) store.index().asConstant()).asInt() : -1;
// BASTORE (with elementKind being Byte) can be used to store values in boolean arrays.
JavaKind elementKind = store.elementKind();
if (elementKind == JavaKind.Byte) {
elementKind = getElementKindFromStamp(store.array());
if (elementKind == JavaKind.Illegal) {
// Could not determine the actual access kind from stamp. Hence kill both.
state.killReadCache(NamedLocationIdentity.getArrayLocation(JavaKind.Boolean), index);
state.killReadCache(NamedLocationIdentity.getArrayLocation(JavaKind.Byte), index);
return false;
}
}
LocationIdentity arrayLocation = NamedLocationIdentity.getArrayLocation(elementKind);
if (index != -1) {
return processStore(store, store.array(), arrayLocation, index, elementKind, false, store.value(), state, effects);
} else {
state.killReadCache(arrayLocation, -1);
}
return false;
}
use of jdk.vm.ci.meta.JavaKind in project graal by oracle.
the class PEReadEliminationClosure method processUnsafeLoad.
private boolean processUnsafeLoad(RawLoadNode load, PEReadEliminationBlockState state, GraphEffectList effects) {
if (load.offset().isConstant()) {
ResolvedJavaType type = StampTool.typeOrNull(load.object());
if (type != null && type.isArray()) {
JavaKind accessKind = load.accessKind();
JavaKind componentKind = type.getComponentType().getJavaKind();
long offset = load.offset().asJavaConstant().asLong();
int index = VirtualArrayNode.entryIndexForOffset(tool.getArrayOffsetProvider(), offset, accessKind, type.getComponentType(), Integer.MAX_VALUE);
ValueNode object = GraphUtil.unproxify(load.object());
LocationIdentity location = NamedLocationIdentity.getArrayLocation(componentKind);
ValueNode cachedValue = state.getReadCache(object, location, index, accessKind, this);
assert cachedValue == null || load.stamp(NodeView.DEFAULT).isCompatible(cachedValue.stamp(NodeView.DEFAULT)) : "The RawLoadNode's stamp is not compatible with the cached value.";
if (cachedValue != null) {
effects.replaceAtUsages(load, cachedValue, load);
addScalarAlias(load, cachedValue);
return true;
} else {
state.addReadCache(object, location, index, accessKind, isOverflowAccess(accessKind, componentKind), load, this);
}
}
}
return false;
}
use of jdk.vm.ci.meta.JavaKind in project graal by oracle.
the class NativeImageHeap method writeObject.
private void writeObject(ObjectInfo info, final RelocatableBuffer roBuffer, final RelocatableBuffer rwBuffer) {
/*
* Write a reference from the object to its hub. This lives at layout.getHubOffset() from
* the object base.
*/
final RelocatableBuffer buffer = bufferForPartition(info, roBuffer, rwBuffer);
final int indexInSection = info.getIntIndexInSection(layout.getHubOffset());
assert layout.isReferenceAligned(info.getOffsetInPartition());
assert layout.isReferenceAligned(indexInSection);
final HostedClass clazz = info.getClazz();
final DynamicHub hub = clazz.getHub();
final long objectHeaderBits = Heap.getHeap().getObjectHeader().setBootImageOnLong(0L);
writeDynamicHub(buffer, indexInSection, hub, objectHeaderBits);
if (clazz.isInstanceClass()) {
JavaConstant con = SubstrateObjectConstant.forObject(info.getObject());
HybridLayout<?> hybridLayout = hybridLayouts.get(clazz);
HostedField hybridArrayField = null;
HostedField hybridBitsetField = null;
int maxBitIndex = -1;
Object hybridArray = null;
if (hybridLayout != null) {
hybridArrayField = hybridLayout.getArrayField();
hybridArray = SubstrateObjectConstant.asObject(hybridArrayField.readStorageValue(con));
hybridBitsetField = hybridLayout.getBitsetField();
if (hybridBitsetField != null) {
BitSet bitSet = (BitSet) SubstrateObjectConstant.asObject(hybridBitsetField.readStorageValue(con));
if (bitSet != null) {
/*
* Write the bits of the hybrid bit field. The bits are located between the
* array length and the instance fields.
*/
int bitsPerByte = Byte.SIZE;
for (int bit = bitSet.nextSetBit(0); bit >= 0; bit = bitSet.nextSetBit(bit + 1)) {
final int index = info.getIntIndexInSection(hybridLayout.getBitFieldOffset()) + bit / bitsPerByte;
if (index > maxBitIndex) {
maxBitIndex = index;
}
int mask = 1 << (bit % bitsPerByte);
assert mask < (1 << bitsPerByte);
buffer.putByte(index, (byte) (buffer.getByte(index) | mask));
}
}
}
}
/*
* Write the regular instance fields.
*/
for (HostedField field : clazz.getInstanceFields(true)) {
if (!field.equals(hybridArrayField) && !field.equals(hybridBitsetField) && field.isAccessed()) {
assert field.getLocation() >= 0;
assert info.getIntIndexInSection(field.getLocation()) > maxBitIndex;
writeField(buffer, info, field, con, info);
}
}
if (hub.getHashCodeOffset() != 0) {
buffer.putInt(info.getIntIndexInSection(hub.getHashCodeOffset()), info.getIdentityHashCode());
}
if (hybridArray != null) {
/*
* Write the hybrid array length and the array elements.
*/
int length = Array.getLength(hybridArray);
buffer.putInt(info.getIntIndexInSection(layout.getArrayLengthOffset()), length);
for (int i = 0; i < length; i++) {
final int elementIndex = info.getIntIndexInSection(hybridLayout.getArrayElementOffset(i));
final JavaKind elementKind = hybridLayout.getArrayElementKind();
final Object array = Array.get(hybridArray, i);
writeConstant(buffer, elementIndex, elementKind, array, info);
}
}
} else if (clazz.isArray()) {
JavaKind kind = clazz.getComponentType().getJavaKind();
Object array = info.getObject();
int length = Array.getLength(array);
buffer.putInt(info.getIntIndexInSection(layout.getArrayLengthOffset()), length);
buffer.putInt(info.getIntIndexInSection(layout.getArrayHashCodeOffset()), info.getIdentityHashCode());
if (array instanceof Object[]) {
Object[] oarray = (Object[]) array;
assert oarray.length == length;
for (int i = 0; i < length; i++) {
final int elementIndex = info.getIntIndexInSection(layout.getArrayElementOffset(kind, i));
final Object element = aUniverse.replaceObject(oarray[i]);
writeConstant(buffer, elementIndex, kind, element, info);
}
} else {
for (int i = 0; i < length; i++) {
final int elementIndex = info.getIntIndexInSection(layout.getArrayElementOffset(kind, i));
final Object element = Array.get(array, i);
writeConstant(buffer, elementIndex, kind, element, info);
}
}
} else {
throw shouldNotReachHere();
}
}
use of jdk.vm.ci.meta.JavaKind in project graal by oracle.
the class NativeImageHeap method addObjectToBootImageHeap.
/**
* It has been determined that an object should be added to the model of the native image heap.
* This is the mechanics of recursively adding the object and all its fields and array elements
* to the model of the native image heap.
*/
private void addObjectToBootImageHeap(final Object original, final Object canonicalObj, final boolean canonicalizable, boolean immutableFromParent, final int identityHashCode, final Object reason) {
final Optional<HostedType> optionalType = getMetaAccess().optionalLookupJavaType(canonicalObj.getClass());
if (!optionalType.isPresent() || !optionalType.get().isInstantiated()) {
throw UserError.abort("Image heap writing found an object whose class was not seen as instantiated during static analysis. " + "Did a static field or an object referenced from a static field changed during native image generation? " + "For example, a lazily initialized cache could have been initialized during image generation, " + "in which case you need to force eager initialization of the cache before static analysis or reset the cache using a field value recomputation.\n" + " object: " + original + " of class: " + original.getClass().getTypeName() + "\n" + " reachable through:\n" + fillReasonStack(new StringBuilder(), reason));
}
final HostedType type = optionalType.get();
if (type.isInstanceClass()) {
final HostedInstanceClass clazz = (HostedInstanceClass) type;
final JavaConstant con = SubstrateObjectConstant.forObject(canonicalObj);
final Object hybridArray;
final long size;
if (HybridLayout.isHybrid(clazz)) {
HybridLayout<?> hybridLayout = hybridLayouts.get(clazz);
if (hybridLayout == null) {
hybridLayout = new HybridLayout<>(clazz, layout);
hybridLayouts.put(clazz, hybridLayout);
}
/*
* The hybrid array and bit set are written within the hybrid object. So they may
* not be written as separate objects. We use the blacklist to check that.
*/
HostedField bitsetField = hybridLayout.getBitsetField();
if (bitsetField != null) {
BitSet bitSet = (BitSet) SubstrateObjectConstant.asObject(bitsetField.readStorageValue(con));
if (bitSet != null) {
blacklist.put(bitSet, Boolean.TRUE);
}
}
hybridArray = SubstrateObjectConstant.asObject(hybridLayout.getArrayField().readStorageValue(con));
blacklist.put(hybridArray, Boolean.TRUE);
size = hybridLayout.getTotalSize(Array.getLength(hybridArray));
} else {
hybridArray = null;
size = LayoutEncoding.getInstanceSize(clazz.getHub().getLayoutEncoding()).rawValue();
}
// All canonicalizable objects are immutable,
// as are instances of known immutable classes.
final ObjectInfo info = addToHeapPartition(original, canonicalObj, clazz, size, identityHashCode, canonicalizable, immutableFromParent, reason);
recursiveAddObject(clazz.getHub(), canonicalizable, false, info);
// Recursively add all the fields of the object.
// Even if the parent is not canonicalizable, the fields may be canonicalizable.
final boolean fieldsAreImmutable = canonicalObj instanceof String;
for (HostedField field : clazz.getInstanceFields(true)) {
if (field.getType().getStorageKind() == JavaKind.Object && !HybridLayout.isHybridField(field) && field.isAccessed()) {
assert field.getLocation() >= 0;
recursiveAddObject(SubstrateObjectConstant.asObject(field.readStorageValue(con)), canonicalizable, fieldsAreImmutable, info);
}
}
if (hybridArray instanceof Object[]) {
addArrayElements((Object[]) hybridArray, canonicalizable, info);
}
} else if (type.isArray()) {
HostedArrayClass clazz = (HostedArrayClass) type;
int length = Array.getLength(canonicalObj);
JavaKind kind = type.getComponentType().getJavaKind();
final long size = layout.getArraySize(kind, length);
final ObjectInfo info = addToHeapPartition(original, canonicalObj, clazz, size, identityHashCode, canonicalizable, immutableFromParent, reason);
recursiveAddObject(clazz.getHub(), canonicalizable, false, info);
if (kind == JavaKind.Object) {
addArrayElements((Object[]) canonicalObj, canonicalizable, info);
}
} else {
throw shouldNotReachHere();
}
}
Aggregations