use of org.graalvm.compiler.api.replacements.Snippet in project graal by oracle.
the class CFunctionSnippets method prologueSnippet.
@Snippet
private static void prologueSnippet() {
// Push a Java frame anchor.
JavaFrameAnchor anchor = (JavaFrameAnchor) StackValueNode.stackValue(1, SizeOf.get(JavaFrameAnchor.class), frameAnchorIdentity);
anchor.setLastJavaSP(KnownIntrinsics.readStackPointer());
JavaFrameAnchors.pushFrameAnchor(anchor);
if (SubstrateOptions.MultiThreaded.getValue()) {
// Change the VMThread status from Java to native.
VMThreads.StatusSupport.setStatusNative();
}
}
use of org.graalvm.compiler.api.replacements.Snippet in project graal by oracle.
the class NewArrayStub method newArray.
/**
* Re-attempts allocation after an initial TLAB allocation failed or was skipped (e.g., due to
* -XX:-UseTLAB).
*
* @param hub the hub of the object to be allocated
* @param length the length of the array
* @param fillContents Should the array be filled with zeroes?
* @param intArrayHub the hub for {@code int[].class}
*/
@Snippet
private static Object newArray(KlassPointer hub, int length, boolean fillContents, @ConstantParameter KlassPointer intArrayHub, @ConstantParameter Register threadRegister, @ConstantParameter OptionValues options) {
int layoutHelper = readLayoutHelper(hub);
int log2ElementSize = (layoutHelper >> layoutHelperLog2ElementSizeShift(INJECTED_VMCONFIG)) & layoutHelperLog2ElementSizeMask(INJECTED_VMCONFIG);
int headerSize = (layoutHelper >> layoutHelperHeaderSizeShift(INJECTED_VMCONFIG)) & layoutHelperHeaderSizeMask(INJECTED_VMCONFIG);
int elementKind = (layoutHelper >> layoutHelperElementTypeShift(INJECTED_VMCONFIG)) & layoutHelperElementTypeMask(INJECTED_VMCONFIG);
int sizeInBytes = arrayAllocationSize(length, headerSize, log2ElementSize);
if (logging(options)) {
printf("newArray: element kind %d\n", elementKind);
printf("newArray: array length %d\n", length);
printf("newArray: array size %d\n", sizeInBytes);
printf("newArray: hub=%p\n", hub.asWord().rawValue());
}
// check that array length is small enough for fast path.
Word thread = registerAsWord(threadRegister);
boolean inlineContiguousAllocationSupported = GraalHotSpotVMConfigNode.inlineContiguousAllocationSupported();
if (inlineContiguousAllocationSupported && !useCMSIncrementalMode(INJECTED_VMCONFIG) && length >= 0 && length <= MAX_ARRAY_FAST_PATH_ALLOCATION_LENGTH) {
Word memory = refillAllocate(thread, intArrayHub, sizeInBytes, logging(options));
if (memory.notEqual(0)) {
if (logging(options)) {
printf("newArray: allocated new array at %p\n", memory.rawValue());
}
return verifyObject(formatArray(hub, sizeInBytes, length, headerSize, memory, WordFactory.unsigned(arrayPrototypeMarkWord(INJECTED_VMCONFIG)), fillContents, false, null));
}
}
if (logging(options)) {
printf("newArray: calling new_array_c\n");
}
newArrayC(NEW_ARRAY_C, thread, hub, length);
handlePendingException(thread, true);
return verifyObject(getAndClearObjectResult(thread));
}
use of org.graalvm.compiler.api.replacements.Snippet in project graal by oracle.
the class AllocationSnippets method newPinnedArraySnippet.
@Snippet
public static Object newPinnedArraySnippet(PinnedAllocatorImpl pinnedAllocator, DynamicHub hub, int length, @ConstantParameter int layoutEncoding, @ConstantParameter boolean fillContents, AllocationCounter counter) {
pinnedAllocator.ensureOpen();
UnsignedWord size = LayoutEncoding.getArraySize(layoutEncoding, length);
profileAllocation(size, counter);
Pointer memory = WordFactory.nullPointer();
if (size.belowOrEqual(HeapPolicy.getLargeArrayThreshold()) && length >= 0) {
memory = ThreadLocalAllocation.allocateMemory(ThreadLocalAllocation.pinnedTLAB.getAddress(), size);
}
Object result = null;
if (BranchProbabilityNode.probability(BranchProbabilityNode.FAST_PATH_PROBABILITY, memory.isNonNull())) {
result = formatArrayImpl(memory, hub, length, layoutEncoding, size, fillContents, false, false);
} else {
result = callSlowNewPinnedArray(SLOW_NEW_PINNED_ARRAY, pinnedAllocator, hub.asClass(), length);
}
return PiArrayNode.piArrayCastToSnippetReplaceeStamp(result, length);
}
use of org.graalvm.compiler.api.replacements.Snippet in project graal by oracle.
the class AllocationSnippets method arraysCopyOfSnippet.
@Snippet
public static Object arraysCopyOfSnippet(DynamicHub hub, Object original, int originalLength, int newLength, AllocationCounter counter) {
int layoutEncoding = hub.getLayoutEncoding();
// allocate new array without initializing the new array
Object copy = newArraySnippet(hub, newLength, layoutEncoding, false, counter);
// copy elements from original
// The length of the copied section
int length = originalLength < newLength ? originalLength : newLength;
// The size of the copied section(obtained from the length of the copied section)
UnsignedWord size = LayoutEncoding.getArraySize(layoutEncoding, length);
// The size of the new array (obtained from the length of the new array)
UnsignedWord newSize = LayoutEncoding.getArraySize(layoutEncoding, newLength);
// We know that the offset is always word aligned
UnsignedWord offset = LayoutEncoding.getArrayBaseOffset(layoutEncoding);
while (offset.belowThan(size)) {
Object val = ObjectAccess.readObject(original, offset);
ObjectAccess.writeObject(copy, offset, val, LocationIdentity.INIT_LOCATION);
offset = offset.add(ConfigurationValues.getTarget().wordSize);
}
while (offset.belowThan(newSize)) {
ObjectAccess.writeObject(copy, offset, null, LocationIdentity.INIT_LOCATION);
offset = offset.add(ConfigurationValues.getTarget().wordSize);
}
return FixedValueAnchorNode.getObject(copy);
}
use of org.graalvm.compiler.api.replacements.Snippet in project graal by oracle.
the class AllocationSnippets method formatArraySnippet.
@Snippet
public static Object formatArraySnippet(Word memory, DynamicHub hub, int length, boolean rememberedSet, boolean unaligned) {
DynamicHub hubNonNull = (DynamicHub) PiNode.piCastNonNull(hub, SnippetAnchorNode.anchor());
int layoutEncoding = hubNonNull.getLayoutEncoding();
UnsignedWord size = LayoutEncoding.getArraySize(layoutEncoding, length);
emitPrefetchAllocate(memory, true);
return formatArrayImpl(memory, hubNonNull, length, layoutEncoding, size, true, rememberedSet, unaligned);
}
Aggregations