use of org.graalvm.compiler.word.Word in project graal by oracle.
the class PosixIsolates method create.
@Uninterruptible(reason = "Thread state not yet set up.")
public static int create(WordPointer isolatePointer, @SuppressWarnings("unused") CEntryPointCreateIsolateParameters parameters) {
if (!SubstrateOptions.SpawnIsolates.getValue()) {
isolatePointer.write(CEntryPointSetup.SINGLE_ISOLATE_SENTINEL);
return Errors.NO_ERROR;
}
Word begin = IMAGE_HEAP_BEGIN.get();
Word size = IMAGE_HEAP_END.get().subtract(begin);
/*
* Request an anonymous memory mapping for this isolate's clone of the image heap. The start
* address of that mapping becomes the isolate's heap base address. We want extra heap
* chunks that we allocate later to be at a higher address than the heap base so that we can
* safely consider the base-relative offsets to be unsigned. Therefore, we request the
* lowest non-zero multiple of the page size as this mapping's address. However, that
* request is only a hint unless we use MAP_FIXED, which makes things much more complex on
* our end. Observations:
*
* - Without a hint to mmap(), anonymous mappings on Linux 4.4 (openSUSE) on x86_64 are
* created just before the mapped shared objects, and subsequent mappings are assigned
* decreasing addresses. However, specifying sysconf(_SC_PAGE_SIZE) as a hint for the first
* mapping reproducingly places it at a very low address, even before the loaded executable.
* Therefore, it seems that a number of isolates can be reliably created with their image
* heap clones at low addresses and with allocated heap chunks at higher addresses.
*
* - On Darwin 13.4, anonymous mappings are created after the mapped executable (and some
* malloc regions in between). Subsequent mappings are assigned increasing addresses that
* are close to each other. Specifying hints does not have a noticeable effect. Unmapping a
* mapping makes its address space immediately reusable. Due to the increasing addresses, a
* single isolate's heap can be safely created. However, because of the address space reuse,
* a heap chunk of an isolate can be allocated at a lower address than its heap base when
* another isolate unmaps a chunk at that location.
*/
long pageSize = Unistd.NoTransitions.sysconf(Unistd._SC_PAGE_SIZE());
Pointer heap = Mman.NoTransitions.mmap(Word.pointer(pageSize), size, PROT_READ() | PROT_WRITE(), MAP_ANON() | MAP_PRIVATE(), -1, 0);
if (heap.equal(MAP_FAILED())) {
return Errors.HEAP_CLONE_FAILED;
}
LibC.memcpy(heap, begin, size);
isolatePointer.write(heap);
return Errors.NO_ERROR;
}
use of org.graalvm.compiler.word.Word in project graal by oracle.
the class PosixIsolates method tearDownCurrent.
@Uninterruptible(reason = "Tear-down in progress.")
public static int tearDownCurrent() {
if (SubstrateOptions.SpawnIsolates.getValue()) {
PointerBase heapBase = getHeapBase(CEntryPointContext.getCurrentIsolate());
Word size = IMAGE_HEAP_END.get().subtract(IMAGE_HEAP_BEGIN.get());
if (Mman.NoTransitions.munmap(heapBase, size) != 0) {
return Errors.UNSPECIFIED;
}
}
return Errors.NO_ERROR;
}
use of org.graalvm.compiler.word.Word in project graal by oracle.
the class HotSpotUnsafeSubstitutions method copyMemory.
@SuppressWarnings("unused")
@MethodSubstitution(isStatic = false)
static void copyMemory(Object receiver, Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes) {
Word srcAddr = WordFactory.unsigned(ComputeObjectAddressNode.get(srcBase, srcOffset));
Word dstAddr = WordFactory.unsigned(ComputeObjectAddressNode.get(destBase, destOffset));
Word size = Word.signed(bytes);
HotSpotBackend.unsafeArraycopy(srcAddr, dstAddr, size);
}
use of org.graalvm.compiler.word.Word in project graal by oracle.
the class Deoptimizer method readConstant.
private static JavaConstant readConstant(Pointer addr, SignedWord offset, JavaKind kind, boolean compressed) {
switch(kind) {
case Boolean:
return JavaConstant.forBoolean(addr.readByte(offset) != 0);
case Byte:
return JavaConstant.forByte(addr.readByte(offset));
case Char:
return JavaConstant.forChar(addr.readChar(offset));
case Short:
return JavaConstant.forShort(addr.readShort(offset));
case Int:
return JavaConstant.forInt(addr.readInt(offset));
case Long:
return JavaConstant.forLong(addr.readLong(offset));
case Float:
return JavaConstant.forFloat(addr.readFloat(offset));
case Double:
return JavaConstant.forDouble(addr.readDouble(offset));
case Object:
Word p = ((Word) addr).add(offset);
Object obj = ReferenceAccess.singleton().readObjectAt(p, compressed);
return SubstrateObjectConstant.forObject(obj, compressed);
default:
throw VMError.shouldNotReachHere();
}
}
use of org.graalvm.compiler.word.Word 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));
}
Aggregations