use of org.graalvm.compiler.api.replacements.Snippet in project graal by oracle.
the class InstanceOfSnippets method instanceofDynamic.
/**
* Type test used when the type being tested against is not known at compile time.
*/
@Snippet
public static Object instanceofDynamic(KlassPointer hub, Object object, Object trueValue, Object falseValue, @ConstantParameter boolean allowNull, @ConstantParameter Counters counters) {
if (probability(NOT_FREQUENT_PROBABILITY, object == null)) {
counters.isNull.inc();
if (allowNull) {
return trueValue;
} else {
return falseValue;
}
}
GuardingNode anchorNode = SnippetAnchorNode.anchor();
KlassPointer nonNullObjectHub = loadHubIntrinsic(PiNode.piCastNonNull(object, anchorNode));
// The hub of a primitive type can be null => always return false in this case.
if (BranchProbabilityNode.probability(BranchProbabilityNode.FAST_PATH_PROBABILITY, !hub.isNull())) {
if (checkUnknownSubType(hub, nonNullObjectHub, counters)) {
return trueValue;
}
}
return falseValue;
}
use of org.graalvm.compiler.api.replacements.Snippet in project graal by oracle.
the class InstanceOfSnippets method instanceofPrimary.
/**
* A test against a primary type.
*/
@Snippet
public static Object instanceofPrimary(KlassPointer hub, Object object, @ConstantParameter int superCheckOffset, Object trueValue, Object falseValue, @ConstantParameter Counters counters) {
if (probability(NOT_FREQUENT_PROBABILITY, object == null)) {
counters.isNull.inc();
return falseValue;
}
GuardingNode anchorNode = SnippetAnchorNode.anchor();
KlassPointer objectHub = loadHubIntrinsic(PiNode.piCastNonNull(object, anchorNode));
if (probability(NOT_LIKELY_PROBABILITY, objectHub.readKlassPointer(superCheckOffset, PRIMARY_SUPERS_LOCATION).notEqual(hub))) {
counters.displayMiss.inc();
return falseValue;
}
counters.displayHit.inc();
return trueValue;
}
use of org.graalvm.compiler.api.replacements.Snippet in project graal by oracle.
the class AllocationSnippets method newPinnedInstanceSnippet.
@Snippet
public static Object newPinnedInstanceSnippet(PinnedAllocatorImpl pinnedAllocator, DynamicHub hub, @ConstantParameter int encoding, @ConstantParameter boolean fillContents, AllocationCounter counter) {
pinnedAllocator.ensureOpen();
UnsignedWord size = LayoutEncoding.getInstanceSize(encoding);
profileAllocation(size, counter);
Pointer memory = ThreadLocalAllocation.allocateMemory(ThreadLocalAllocation.pinnedTLAB.getAddress(), size);
Object result;
if (BranchProbabilityNode.probability(BranchProbabilityNode.FAST_PATH_PROBABILITY, memory.isNonNull())) {
result = formatObjectImpl(memory, hub, size, true, fillContents, false);
} else {
result = callSlowNewPinnedInstance(SLOW_NEW_PINNED_INSTANCE, pinnedAllocator, hub.asClass());
}
return PiNode.piCastToSnippetReplaceeStamp(result);
}
use of org.graalvm.compiler.api.replacements.Snippet in project graal by oracle.
the class AllocationSnippets method newMultiArraySnippet.
@Snippet
public static Object newMultiArraySnippet(DynamicHub hub, @ConstantParameter int rank, @VarargsParameter int[] dimensions, AllocationCounter counter) {
Pointer dims = DimensionsNode.allocaDimsArray(rank);
ExplodeLoopNode.explodeLoop();
for (int i = 0; i < rank; i++) {
dims.writeInt(i * sizeOfDimensionElement, dimensions[i], LocationIdentity.INIT_LOCATION);
}
return callNewMultiArray(NEW_MULTI_ARRAY, hub.asClass(), rank, dims, counter);
}
use of org.graalvm.compiler.api.replacements.Snippet in project graal by oracle.
the class AllocationSnippets method doCloneSnippet.
/**
* The actual implementation of {@link Object#clone}.
*/
@Snippet
private static Object doCloneSnippet(Object thisObj, AllocationCounter counter) throws CloneNotSupportedException {
if (!(thisObj instanceof Cloneable)) {
throw CLONE_NOT_SUPPORTED_EXCEPTION;
}
DynamicHub hub = KnownIntrinsics.readHub(thisObj);
int layoutEncoding = hub.getLayoutEncoding();
UnsignedWord size = LayoutEncoding.getSizeFromObject(thisObj);
profileAllocation(size, counter);
/*
* The size of the clone is the same as the size of the original object. On the fast path we
* try to allocate aligned memory, i.e., a block inside an aligned chunks, for the clone and
* don't need to distinguish instance objects from arrays. If we fail, i.e., the returned
* memory is null, then either the instance object or small array didn't fit in the
* available space or it is a large array. In either case we go on the slow path.
*/
Pointer memory = ThreadLocalAllocation.allocateMemory(ThreadLocalAllocation.regularTLAB.getAddress(), size);
Object thatObject = null;
if (BranchProbabilityNode.probability(BranchProbabilityNode.FAST_PATH_PROBABILITY, memory.isNonNull())) {
WordBase header = ObjectHeaderImpl.getObjectHeaderImpl().formatHub(hub, false, false);
memory.writeWord(ConfigurationValues.getObjectLayout().getHubOffset(), header, LocationIdentity.INIT_LOCATION);
/*
* For arrays the length initialization is handled by doCloneUninterruptibly since the
* array length offset is the same as the first field offset.
*/
thatObject = memory.toObjectNonNull();
} else {
if (LayoutEncoding.isArray(layoutEncoding)) {
int length = KnownIntrinsics.readArrayLength(thisObj);
thatObject = callSlowNewArray(SLOW_NEW_ARRAY, hub.asClass(), length);
} else {
thatObject = callSlowNewInstance(SLOW_NEW_INSTANCE, hub.asClass());
}
}
if (LayoutEncoding.isArray(layoutEncoding)) {
int length = KnownIntrinsics.readArrayLength(thisObj);
thatObject = PiArrayNode.piArrayCastToSnippetReplaceeStamp(thatObject, length);
} else {
thatObject = PiNode.piCastToSnippetReplaceeStamp(thatObject);
}
UnsignedWord firstFieldOffset = WordFactory.signed(ConfigurationValues.getObjectLayout().getFirstFieldOffset());
return doCloneUninterruptibly(thisObj, thatObject, firstFieldOffset, size);
}
Aggregations