Package org.vmmagic.unboxed

Examples of org.vmmagic.unboxed.Word


        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


        if (nextFreePtr.EQ(Address.zero())) { /* This heap is full */
            return null;
        }

        final Offset tibOffset = this.tibOffset;
        final Word headerSize = Word.fromIntZeroExtend(this.headerSize);
        final Offset flagsOffset = this.flagsOffset;
        final Offset sizeOffset = this.sizeOffset;

        Word alignedSizeW = Word.fromIntZeroExtend(alignedSize);
        final Word totalSize = alignedSizeW.add(headerSize);
        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);
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

     * Join all adjacent free spaces.
     *
     * @throws UninterruptiblePragma
     */
    protected final void defragment() throws UninterruptiblePragma {
        final Word size = Word.fromIntZeroExtend(getSize());
        final Word headerSize = Word.fromIntZeroExtend(this.headerSize);
        Word offset = headerSize;
        final Offset sizeOffset = this.sizeOffset;
        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.
                    } else {
View Full Code Here

     * @param locking If true, use lock/unlock while proceeding to the next object.
     */
    protected final void walk(ObjectVisitor visitor, boolean locking,
                              Word flagsMask, Word flagsValue) {
        // Go through the heap and call visit on each object
        final Word headerSize = Word.fromIntZeroExtend(this.headerSize);
        final Offset sizeOffset = this.sizeOffset;
        final Offset tibOffset = this.tibOffset;
        final Object FREE = this.FREE;
        Word offset = headerSize;
        final Word size = Word.fromIntZeroExtend(getSize());

        if (locking) {
            while (offset.LT(size)) {
                final Object tib;
                final Object object;
                final Word objSize;
                final Word flags;

                lock();
                try {
                    final Address ptr = start.add(offset);
                    object = ptr.toObjectReference().toObject();
                    tib = ptr.loadObjectReference(tibOffset);
                    objSize = ptr.loadWord(sizeOffset);
                    flags = (flagsMask.isZero()) ? Word.zero() : VmMagic.getObjectFlags(object).and(flagsMask);
                } finally {
                    unlock();
                }
                if (tib != FREE) {
                    if (flags.EQ(flagsValue)) {
                        if (!visitor.visit(object)) {
                            // Stop
                            return;
                        }
                    }
                }
                offset = offset.add(objSize).add(headerSize);
            }
        } else {
            while (offset.LT(size)) {
                final Address ptr = start.add(offset);
                final Object object = ptr.toObjectReference().toObject();
                final Object tib = ptr.loadObjectReference(tibOffset);
                final Word objSize = ptr.loadWord(sizeOffset);
                final Word flags = flagsMask.isZero() ? Word.zero() : VmMagic.getObjectFlags(object).and(flagsMask);
                if (tib != FREE) {
                    if (flags.EQ(flagsValue)) {
                        if (!visitor.visit(object)) {
                            // Stop
                            return;
                        }
                    }
View Full Code Here

        //allocationBitmapPtr = MemoryBlockManager.allocateBlock(bitmapSize);

        // Initialize the allocation bitmap
        helper.clear(allocationBitmapPtr, bitmapSize);
        // Go through the heap and mark all objects in the allocation bitmap.
        final Word heapSizeW = Word.fromIntZeroExtend(heapSize);
        final Word headerSize = Word.fromIntZeroExtend(this.headerSize);
        Word offset = headerSize;
        while (offset.LT(heapSizeW)) {
            final Address ptr = start.add(offset);
            setAllocationBit(ptr, true);
            final Word objSize = ptr.loadWord(sizeOffset);
            offset = offset.add(objSize).add(headerSize);
        }
        //Unsafe.debug("end of bootheap.initialize");
    }
View Full Code Here

     *                This parameter is irrelevant here, since the structure of
     *                this heap never changes.
     */
    protected void walk(ObjectVisitor visitor, boolean locking, Word flagsMask, Word flagsValue) {
        // Go through the heap and mark all objects in the allocation bitmap.
        final Word headerSize = Word.fromIntZeroExtend(this.headerSize);
        final Offset sizeOffset = this.sizeOffset;
        final Word size = Word.fromIntZeroExtend(getSize());
        Word offset = headerSize;
        while (offset.LT(size)) {
            final Address ptr = start.add(offset);
            final Object object = ptr.toObjectReference().toObject();
            final Word flags = VmMagic.getObjectFlags(object).and(flagsMask);
            if (!flags.EQ(flagsValue) || visitor.visit(object)) {
                // Continue
                final Word objSize = ptr.loadWord(sizeOffset);
                offset = offset.add(objSize).add(headerSize);
            } else {
                // Stop
                offset = size;
            }
View Full Code Here

     * @param bootHeap
     * @param firstHeap
     */
    private void verify(VmBootHeap bootHeap, VmDefaultHeap firstHeap) {
        final long startTime = VmSystem.currentKernelMillis();
        final Word zero = Word.zero();
        verifyVisitor.reset();
        bootHeap.walk(verifyVisitor, true, zero, zero);
        VmDefaultHeap heap = firstHeap;
        while (heap != null) {
            heap.walk(verifyVisitor, true, zero, zero);
View Full Code Here

        return heapStatistics;
    }
   
    private void accept(ObjectVisitor visitor, boolean locking) {
        VmDefaultHeap heap = firstNormalHeap;
        final Word zero = Word.zero();

        while (heap != null) {
            heap.walk(visitor, locking, zero, zero);
            heap = heap.getNext();
        }
View Full Code Here

        Address start = acpiStart;
        for (MemoryMapEntry e : mmap) {
            if (e.isAcpi() || e.isAcpiNVS()) {
                // Calculate page aligned boundaries & sizes
                final Address alignedPhysStart = arch.pageAlign(ACPI, e.getStart(), false);
                final Word diff = e.getStart().toWord().sub(alignedPhysStart.toWord());
                final Extent size = e.getSize().add(diff);

                // Check for adjacent memory blocks
                if (lastAcpiEntry != null) {
                    Address expected = lastAcpiEntry.getStart().add(lastAcpiEntry.getSize());
View Full Code Here

TOP

Related Classes of org.vmmagic.unboxed.Word

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.