Package org.vmmagic.unboxed

Examples of org.vmmagic.unboxed.Word


     * @since 1.4
     */
    public static boolean holdsLock(Object obj) {
        final VmThread current = VmThread.currentThread();

        final Word lockword = ObjectReference.fromObject(obj).toAddress().
            add(ObjectLayout.FLAGS_SLOT * Address.size()).prepareWord();

        if (!lockword.and(Word.fromIntZeroExtend(ObjectFlags.LOCK_EXPANDED)).isZero()) {
            return getMonitor(lockword).isOwner(current);
        } else {
            final Word tid = Word.fromIntZeroExtend(current.getId());
            return lockword.and(Word.fromIntZeroExtend(ObjectFlags.THREAD_ID_MASK)).EQ(tid);
        }
    }
View Full Code Here


     */
    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

     *
     * @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

     *
     * @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

     *
     * @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

    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

    /**
     * @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

     * 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

                    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

        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

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.