Examples of Word


Examples of org.vmmagic.unboxed.Word

     */
    public final Word allocateBits(Word noBits) {
        lock();
        try {
            // Find a large enough series of bits
            final Word nr = findFreeBits(noBits);
            if (nr.isMax()) {
                return nr;
            }
            // Mark all blocks as in use
            for (Word i = Word.zero(); i.LT(noBits); i = i.add(1)) {
                set(nr.add(i), true);
            }
            // Return the address of block "nr".
            allocatedBits = allocatedBits.add(noBits);
            nextBitNr = nr.add(noBits);
            return nr;
        } finally {
            unlock();
        }
    }
View Full Code Here

Examples of org.vmmagic.unboxed.Word

     *
     * @param freeBits
     * @return The bit number of the first block, or Word.max() if not found.
     */
    private final Word findFreeBits(Word freeBits) {
        final Word max = bits;
        Word nr = nextBitNr;
        while (nr.LT(max)) {
            boolean inUse = false;
            Word i;
            for (i = Word.zero(); i.LT(freeBits) && (!inUse); i = i.add(1)) {
                inUse |= isSet(nr.add(i));
            }
            if (!inUse) {
                // We found it
                return nr;
View Full Code Here

Examples of org.vmmagic.unboxed.Word

     *
     * @param bit the bit to be tested
     * @return {@link true} if the bit is set, {@code false} otherwise.
     */
    private final boolean isSet(Word bit) {
        final Word offset = bit.rshl(3); // we still need a byte offset
        final int mask = (1 << bit.and(Word.fromIntZeroExtend(7)).toInt());
        final Address ptr = bitmap.add(offset);
        final int v = ptr.loadByte() & 0xFF;
        return ((v & mask) == mask);
    }
View Full Code Here

Examples of org.vmmagic.unboxed.Word

     *
     * @param bit the bit to be set or reset
     * @param value the new value for the bit
     */
    private final void set(Word bit, boolean value) {
        final Word offset = bit.rshl(3); // we still need a byte offset
        final int mask = (1 << bit.and(Word.fromIntZeroExtend(7)).toInt());
        // final int mask = (1 << blockNr);
        final Address ptr = bitmap.add(offset);
        int v = ptr.loadByte();
        if (value) {
View Full Code Here

Examples of org.vmmagic.unboxed.Word

    public boolean atomicChangeObjectColor(Object dst, int oldColor,
                                           int newColor) {
        final Address addr = ObjectReference.fromObject(dst).toAddress().add(
            flagsOffset);
        for (;;) {
            Word oldValue = addr.prepareWord();
            if (oldValue
                .and(Word.fromIntZeroExtend(ObjectFlags.GC_COLOUR_MASK))
                .NE(Word.fromIntZeroExtend(oldColor))) {
                return false;
            }
            Word newValue = oldValue.and(
                Word.fromIntZeroExtend(ObjectFlags.GC_COLOUR_MASK).not())
                .or(Word.fromIntZeroExtend(newColor));
            if (addr.attempt(oldValue, newValue)) {
                return true;
            }
View Full Code Here

Examples of org.vmmagic.unboxed.Word

    /**
     * @see org.jnode.vm.memmgr.HeapHelper#getHeapSize()
     */
    public Extent getHeapSize() {
        final Word end = Unsafe.getMemoryEnd().toWord();
        final Word start = Unsafe.getMemoryStart().toWord();
        return end.sub(start).toExtent();
    }
View Full Code Here

Examples of org.vmmagic.unboxed.Word

     * Go through all heaps and run the finalize method of all objects that
     * are unreachable and still need finalization.
     */
    private final void runFinalization() {
        VmDefaultHeap heap = heapManager.getHeapList();
        final Word colorMask = Word.fromIntZeroExtend(ObjectFlags.GC_COLOUR_MASK);
        final Word yellow = Word.fromIntZeroExtend(ObjectFlags.GC_YELLOW);
        while (heap != null) {
            visitor.setCurrentHeap(heap);
            heap.walk(visitor, true, colorMask, yellow);
            heap = heap.getNext();
        }
View Full Code Here

Examples of org.vmmagic.unboxed.Word

                    Unsafe.debug(objAddr);
                    Unsafe.debug(", tib is ");
                    Object[] tib = VmMagic.getTIB(object);
                    Unsafe.debug(ObjectReference.fromObject(tib).toAddress());
                    Unsafe.debug(", flags word is ");
                    Word flags = VmMagic.getObjectFlags(object);
                    Unsafe.debug(flags);
                    Unsafe.debug(", markedObjects is ");
                    Unsafe.debug(markedObjects);
                    Unsafe.debug('\n');
                    helper.die("GCMarkError: NPE");
View Full Code Here

Examples of org.vmmagic.unboxed.Word

        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());

View Full Code Here

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
TOP
Copyright © 2018 www.massapi.com. 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.