Package org.vmmagic.unboxed

Examples of org.vmmagic.unboxed.Address


     * @param object
     * @param on
     */
    @Inline
    protected final void setAllocationBit(Object object, boolean on) {
        final Address addr = ObjectReference.fromObject(object).toAddress();
        if (addr.LT(start) || addr.GE(end)) {
            return;
        }

        final int offset = addr.toWord().sub(start.toWord()).toInt();
        final int bit = offset / ObjectLayout.OBJECT_ALIGN;
        final Offset idx = Offset.fromIntZeroExtend(bit / 8);
        final int mask = 1 << (bit & 7);
        final Address bitmapPtr = this.allocationBitmapPtr;
        int value = bitmapPtr.loadByte(idx);
        if (on) {
            value |= mask;
        } else {
            value &= ~mask;
        }
        bitmapPtr.store((byte) value, idx);
    }
View Full Code Here


     *
     * @param instrPtr
     * @return The index, or -1 is not found.
     */
    public final int getAddressMapIndex(Address instrPtr) {
        final Address codeAddr = Address.fromAddress(nativeCode);
        final int offset = instrPtr.toWord().sub(codeAddr.toWord()).toInt();
        return addressTable.getIndexForOffset(offset);
    }
View Full Code Here

     *
     * @param codePtr
     * @return boolean
     */
    public boolean contains(Address codePtr) {
        final Address start = Address.fromAddress(nativeCode);
        final Address end = start.add(nativeCodeSize1);

        return codePtr.GE(start) && codePtr.LT(end);
    }
View Full Code Here

            } catch (NullPointerException ex) {
                // This is a symptom of heap corruption
                if (object == null) {
                    helper.die("GCMarkError: null object");
                } else {
                    final Address objAddr = ObjectReference.fromObject(object).toAddress();
                    Unsafe.debug("Object address is ");
                    Unsafe.debug(objAddr);
                    Unsafe.debug(", tib is ");
                    Object[] tib = VmMagic.getTIB(object);
                    Unsafe.debug(ObjectReference.fromObject(tib).toAddress());
View Full Code Here

        if (cnt == 0) {
            return;
        }

        final int size = vmClass.getObjectSize();
        final Address objAddr = ObjectReference.fromObject(object).toAddress();

        for (int i = 0; i < cnt; i++) {
            final int offset = referenceOffsets[i];
            if ((offset < 0) || (offset >= size)) {
                Unsafe.debug("reference offset out of range!");
                Unsafe.debug(vmClass.getName());
                helper.die("Class internal error");
            } else {
                final ObjectReference child = objAddr.loadObjectReference(Offset.fromIntZeroExtend(offset));
                if (child != null) {
                    // Enable the following in the case of heap corruption
                    if (false) {
                        verifyChild(child, object, "object child", i, offset);
                    }
View Full Code Here

        final Offset vmtOffset = Offset.fromIntSignExtend(ObjectLayout.TIB_SLOT * slotSize);
        final Offset sizeOffset = Offset.fromIntSignExtend(-((ObjectLayout.HEADER_SLOTS + 1) * slotSize));
        final Offset flagsOffset = Offset.fromIntSignExtend(ObjectLayout.FLAGS_SLOT * slotSize);

        // Setup a heap object, so the heap can initialize itself.
        final Address heapPtr = start.add(headerSize);
        final Word heapObjSize = Word.fromIntZeroExtend(ObjectLayout.objectAlign(heapClass
            .getObjectSize()));
        final Word flags = Word.fromIntZeroExtend(ObjectFlags.GC_DEFAULT_COLOR);
        heapPtr.store(heapObjSize, sizeOffset);
        heapPtr.store(flags, flagsOffset);
        heapPtr.store(ObjectReference.fromObject(heapClass.getTIB()), vmtOffset);
        helper.clear(heapPtr, heapObjSize.toInt());

        VmDefaultHeap heap = (VmDefaultHeap) heapPtr.toObjectReference().toObject();
        heap.helper = helper;
        return heap;
    }
View Full Code Here

        initializeAbstract(slotSize);
        this.sizeOffset = Offset.fromIntSignExtend(-((ObjectLayout.HEADER_SLOTS + 1) * slotSize));
        this.headerSize = ObjectLayout.objectAlign(this.headerSize + slotSize);
        final int size = getSize();

        final Address myAddr = ObjectReference.fromObject(this).toAddress();
        final Word mySize = myAddr.loadWord(sizeOffset);
        Address firstObject;
        if (inHeap(myAddr)) {
            firstObject = myAddr.add(mySize).add(headerSize);
        } else {
            firstObject = start.add(headerSize);
        }

        // Initialize an allocation bitmap
        final int allocationBits = size / ObjectLayout.OBJECT_ALIGN;
        final int allocationBitmapSize = ObjectLayout
            .objectAlign((allocationBits + 7) / 8);
        this.allocationBitmapPtr = firstObject;
        final Address bitmapPtr = this.allocationBitmapPtr;
        // Make the bitmap an object, so it is easy to manipulate.
        bitmapPtr.store(Word.fromIntZeroExtend(allocationBitmapSize), sizeOffset);
        bitmapPtr.store(Word.fromIntZeroExtend(GC_DEFAULT_COLOR), flagsOffset);
        bitmapPtr.store(ObjectReference.fromObject(VmType.getObjectClass().getTIB()), tibOffset);
        firstObject = firstObject.add(allocationBitmapSize + headerSize);
        helper.clear(allocationBitmapPtr, allocationBitmapSize);
        this.allocationBitmap = allocationBitmapPtr.toObjectReference().toObject();

        // Mark this heap in the allocation bitmap
        setAllocationBit(this, true);
        // Mark the allocation bitmap in the allocation bitmap
        setAllocationBit(allocationBitmap, true);

        // Initialize the remaining space as free object.
        final Word remainingSize = end.toWord().sub(firstObject.toWord());
        final Address ptr = firstObject;
        ptr.store(remainingSize, sizeOffset);
        ptr.store(ObjectReference.fromObject(FREE), tibOffset);
        this.nextFreePtr = ptr;
        this.freeSize = remainingSize.toExtent();
    }
View Full Code Here

        final Object tib = vmClass.getTIB();
        if (tib == null) {
            throw new IllegalArgumentException("vmClass.TIB is null");
        }
        //final int size = getSize();
        Address objectPtr = Address.zero();
        lock();
        try {
            // Search for the first free block that is large enough
            //Screen.debug("a");
            while (objectPtr == null) {
                final Address ptr = nextFreePtr;
                final Word objSize = ptr.loadWord(sizeOffset);
                final Object objVmt = ptr.loadObjectReference(tibOffset);
                final Address nextPtr = ptr.add(objSize.add(headerSize));
                if ((objVmt == FREE) && alignedSizeW.LE(objSize)) {
                    objectPtr = ptr;
                } else {
                    if (!inHeap(nextPtr)) {
                        // No large enough free space has been found
                        // A collect may recover smaller free spaces in this
                        // heap, but we leave that to a GC iteration.
                        nextFreePtr = Address.zero();
                        //Screen.debug("B");
                        return null;
                    } else {
                        this.nextFreePtr = nextPtr;
                    }
                }
            }
            //Screen.debug("A");

            final Word curFreeSize = objectPtr.loadWord(sizeOffset);
            if (curFreeSize.GT(totalSize)) {
                // Block is larger then we need, split it up.
                final Word newFreeSize = curFreeSize.sub(totalSize);
                /*if (newFreeSize <= headerSize) {
                    Unsafe.debug("Block splitup failed");
                    Unsafe.debug("\ncurFreeSize "); Unsafe.debug(curFreeSize);
                    Unsafe.debug("\ntotalSize   "); Unsafe.debug(totalSize);
                    Unsafe.debug("\nnewFreeSize "); Unsafe.debug(newFreeSize);
                    Unsafe.debug("\nheaderSize  "); Unsafe.debug(headerSize);
                    throw new Error("Block splitup failed");
                }*/
                final Address newFreePtr = objectPtr.add(totalSize);
                // Set the header for the remaining free block
                newFreePtr.store(newFreeSize, sizeOffset);
                newFreePtr.store(0, flagsOffset);
                newFreePtr.store(ObjectReference.fromObject(FREE), tibOffset);
                // Set the next free offset
                nextFreePtr = newFreePtr;
            } else {
                // The block is not large enough to split up, make the
                // new object the size of the free block.
View Full Code Here

     *
     * @param object
     */
    @Inline
    final void free(Object object) {
        final Address ptr = ObjectReference.fromObject(object).toAddress();
        final Word objSize = ptr.loadWord(sizeOffset);
        ptr.store(ObjectReference.fromObject(FREE), tibOffset);
        setAllocationBit(object, false);
        freeSize = freeSize.add(objSize);
    }
View Full Code Here

        final Offset tibOffset = this.tibOffset;


        lock();
        try {
            Address firstFreePtr = Address.zero();
            while (offset.LT(size)) {
                final Address ptr = start.add(offset);
                final Word objSize = ptr.loadWord(sizeOffset);
                final Word nextOffset = offset.add(objSize).add(headerSize);
                final Object vmt = ptr.loadObjectReference(tibOffset);
                if ((firstFreePtr == null) && (vmt == FREE)) {
                    firstFreePtr = ptr;
                }
                if ((vmt == FREE) && (nextOffset.LT(size))) {
                    final Object nextVmt;
                    final Address nextObjectPtr = start.add(nextOffset);
                    nextVmt = nextObjectPtr.loadObjectReference(tibOffset);
                    if (nextVmt == FREE) {
                        // Combine two free spaces
                        Word nextObjSize = nextObjectPtr.loadWord(sizeOffset);
                        Word newObjSize = objSize.add(headerSize).add(nextObjSize);
                        ptr.store(newObjSize, sizeOffset);
                        // Do not increment offset here, because there may be
                        // another next free object, which we will combine
                        // in the next loop.
View Full Code Here

TOP

Related Classes of org.vmmagic.unboxed.Address

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.