Examples of Word


Examples of org.vmmagic.unboxed.Word

     * Is a block identified by it blockNr [0..blockCount-1] already used.
     *
     * @param blockNr
     */
    private static final void setInUse(Word blockNr, boolean inUse) {
        final Word offset = blockNr.rshl(3); // we still need a byte offset
        final int mask = (1 << blockNr.and(Word.fromIntZeroExtend(7)).toInt());
        // final int mask = (1 << blockNr);
        final Address ptr = bitmapPtr.add(offset);
        int v = ptr.loadByte();
        if (inUse) {
View Full Code Here

Examples of org.vmmagic.unboxed.Word

     * @param ptr
     * @param roundup
     * @return The aligned address as long
     */
    private static Word blockAlign(Word ptr, boolean roundup) {
        final Word blockSizeM1 = Word.fromIntSignExtend(BLOCK_SIZEa - 1);
        if (roundup) {
            ptr = ptr.add(blockSizeM1);
        }
        return ptr.and(blockSizeM1.not());
    }
View Full Code Here

Examples of org.vmmagic.unboxed.Word

    protected final void testMemPtr(int memPtr, int size) {
        if (released) {
            throw new IndexOutOfBoundsException("MemoryResource is released");
        }
        final Word end = Word.fromIntZeroExtend(memPtr + size);
        if ((memPtr < 0) || end.GT(this.size.toWord())) {
            throw new IndexOutOfBoundsException("At " + memPtr + ", this.size=" + this.size.toLong());
        }
    }
View Full Code Here

Examples of org.vmmagic.unboxed.Word

        if (align <= 0) {
            throw new IllegalArgumentException("Align must be >= 1");
        }

        Offset offset = Offset.zero();
        final Word alignMask = Word.fromIntZeroExtend(align - 1);
        while (true) {
            final Address addr = this.start.add(offset);
            final MemoryResourceImpl child = new MemoryResourceImpl(this, getOwner(), addr, size);
            final MemoryResourceImpl existingChild = (MemoryResourceImpl) get(this.children, child);
            if (existingChild == null) {
                // We found a free region
                this.children = (MemoryResourceImpl) add(this.children, child);
                return child;
            }
            // We found an existing child, skip over that.
            offset = existingChild.getOffset().add(existingChild.getSize());

            // Align the new offset
            if (!offset.toWord().and(alignMask).isZero()) {
                offset = offset.toWord().add(alignMask).and(alignMask.not()).toOffset();
            }

            // Do we have space left?
            if (offset.toWord().add(size).GT(this.size.toWord())) {
                throw new ResourceNotFreeException();
View Full Code Here

Examples of org.vmmagic.unboxed.Word

* @author Ewout Prangsma (epr@users.sourceforge.net)
*/
public class MagicWordTest {

    public static void main(String[] args) {
        Word w = Word.fromInt(0x54);
        Word w2 = Word.zero();
        Word w3 = w.add(w2);
        System.out.println(w3.toInt());
    }
View Full Code Here

Examples of org.vmmagic.unboxed.Word

        if (object == null) {
            throw new NullPointerException();
        }

        // Prepare
        final Word tid = Word.fromIntZeroExtend(VmMagic.currentProcessor().getCurrentThread().getId());
        final Address objectPtr = ObjectReference.fromObject(object).toAddress();
        final Address statusPtr = objectPtr.add(ObjectLayout.FLAGS_SLOT * Address.size());

        for (;;) {
            // attempt fast path: object is not locked.
            final Word oldlockword = statusPtr.prepareWord();

            final Word statusFlags = oldlockword.and(Word.fromIntZeroExtend(ObjectFlags.STATUS_FLAGS_MASK));
            if (statusPtr.attempt(statusFlags, statusFlags.or(tid))) {
                // fast path succeeded, the object was not locked and
                // has been locked by the current thread.
                return;
            }

            // object is locked or has an inflated lock.
            if (!oldlockword.and(Word.fromIntZeroExtend(ObjectFlags.LOCK_EXPANDED)).isZero()) {
                // slow path 2: high bit of lock word is set --> inflated lock
                final Monitor m = getMonitor(oldlockword);
                m.enter();
                return;
            } else if (oldlockword.and(Word.fromIntZeroExtend(ObjectFlags.THREAD_ID_MASK)).EQ(tid)) {
                // Current thread owns the thinlock
                final Word counter = oldlockword.and(Word.fromIntZeroExtend(ObjectFlags.LOCK_COUNT_MASK));
                if (counter.EQ(Word.fromIntZeroExtend(ObjectFlags.LOCK_COUNT_MASK))) {
                    // thin lock entry counter == max, so we need to inflate
                    // ourselves.
                    installInflatedLock(object, null).enter();
                    return;
                } else {
                    // not-quite-so-fast path: locked by current thread.
                    // increment counter.
                    // Try to update lock, it may be inflated by some other
                    // thread, so
                    // be cautious
                    final Word newlockword;
                    newlockword = oldlockword.add(Word.fromIntZeroExtend(ObjectFlags.LOCK_COUNT_INC));
                    // Try to update lock, it may be inflated by some other
                    // thread, so
                    // be cautious
                    if (statusPtr.attempt(oldlockword, newlockword)) {
View Full Code Here

Examples of org.vmmagic.unboxed.Word

        if (object == null) {
            throw new NullPointerException();
        }

        // Prepare
        final Word tid = Word.fromIntZeroExtend(VmMagic.currentProcessor().getCurrentThread().getId());
        final Address objectPtr = ObjectReference.fromObject(object).toAddress();
        final Address statusPtr = objectPtr.add(ObjectLayout.FLAGS_SLOT * Address.size());

        for (;;) {
            final Word oldlockword = statusPtr.prepareWord();

            // Unsafe.debug(" exit:");
            // proc.getArchitecture().getStackReader().debugStackTrace();
            // Unsafe.debug(oldlockword); Unsafe.debug(tid); Unsafe.debug('}');

            // if not inflated and tid matches, this contains status flags and
            // counter
            if (!oldlockword.and(Word.fromIntZeroExtend(ObjectFlags.LOCK_EXPANDED)).isZero()) {
                // inflated lock
                final Monitor m = getMonitor(oldlockword);
                m.exit();
                return;
            } else if (oldlockword.and(Word.fromIntZeroExtend(ObjectFlags.THREAD_ID_MASK)).EQ(tid)) {
                // owned by current thread
                final Word counter = oldlockword.and(Word.fromIntZeroExtend(ObjectFlags.LOCK_COUNT_MASK));
                final Word newlockword;
                if (counter.isZero()) {
                    // Count is zero, clear tid field
                    newlockword = oldlockword.and(Word.fromIntZeroExtend(ObjectFlags.STATUS_FLAGS_MASK));
                } else {
                    // count is non-zero, decrement count
View Full Code Here

Examples of org.vmmagic.unboxed.Word

     * @param thread
     * @return the Monitor object representing the lock
     */
    private static Monitor installInflatedLock(Object k, VmThread thread) {
        Monitor m = null;
        Word monAddr = null;

        final Address kPtr = ObjectReference.fromObject(k).toAddress();
        final Address statusPtr = kPtr.add(ObjectLayout.FLAGS_SLOT * Address.size());

        for (;;) {
            final Word oldlockword = statusPtr.prepareWord();
            if (!oldlockword.and(Word.fromIntZeroExtend(ObjectFlags.LOCK_EXPANDED)).isZero()) {
                // inflated by another thread, use that one.
                return getMonitor(oldlockword);
            }

            if (m == null) {
                m = new Monitor(VmMagic.currentProcessor().getCurrentThread(), 1);
                monAddr = ObjectReference.fromObject(m).toAddress().toWord();
                if (!monAddr.and(Word.fromIntZeroExtend(ObjectFlags.LOCK_EXPANDED
                    | ObjectFlags.STATUS_FLAGS_MASK)).isZero()) {
                    throw new InternalError("Monitor object has address that conflicts with header flags 0x"
                        + NumberUtils.hex(monAddr.toInt()));
                }
            }

            // Put entry count & owner in monitor
            int lockcount = 1 + oldlockword.and(Word.fromIntZeroExtend(ObjectFlags.LOCK_COUNT_MASK)).
                rshl(ObjectFlags.LOCK_COUNT_SHIFT).toInt();
            int ownerId = oldlockword.and(Word.fromIntZeroExtend(ObjectFlags.THREAD_ID_MASK)).toInt();
            if (thread == null) {
                thread = VmMagic.currentProcessor().getScheduler().getThreadById(ownerId);
            }
            m.initialize(thread, lockcount);

            final Word statusFlags = oldlockword.and(Word.fromIntZeroExtend(ObjectFlags.STATUS_FLAGS_MASK));
            final Word newlockword = monAddr.or(statusFlags).or(Word.fromIntZeroExtend(ObjectFlags.LOCK_EXPANDED));
            if (statusPtr.attempt(oldlockword, newlockword)) {
                // successfully obtained inflated lock.
                return m;
            }
        }
View Full Code Here

Examples of org.vmmagic.unboxed.Word

     * @return The inflated monitor of the given object, or null if the given
     *         object has no inflated monitor.
     */
    @Internal
    public static Monitor getInflatedMonitor(Object object) {
        final Word oldlockword = ObjectReference.fromObject(object).toAddress().
            add(ObjectLayout.FLAGS_SLOT * Address.size()).loadWord();

        if (!oldlockword.and(Word.fromIntZeroExtend(ObjectFlags.LOCK_EXPANDED)).isZero()) {
            return getMonitor(oldlockword);
        } else {
            return null;
        }
    }
View Full Code Here

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
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.