Package org.vmmagic.unboxed

Examples of org.vmmagic.unboxed.Address


    private final Object newArray0(VmClassType vmClass, int elemSize,
                                   int elements, int slotSize) {
        final int size = (VmArray.DATA_OFFSET * slotSize)
            + (elemSize * elements);
        final Object array = allocObject(vmClass, size);
        final Address arrayPtr = ObjectReference.fromObject(array).toAddress();
        arrayPtr.store(elements, Offset.fromIntSignExtend(VmArray.LENGTH_OFFSET
            * slotSize));
        return array;
    }
View Full Code Here


        throws DMAException, IllegalArgumentException {

        if (length > memory.getSize().toWord().toLong()) {
            throw new IllegalArgumentException("Length > memory.size");
        }
        final Address addr = memory.getAddress();
        dma.test(dmanr, addr, length);

        // Mask the channel
        dma.disable(dmanr);
        // Clear any datatransfers that are currently executing
View Full Code Here

        final MemoryScanner scanner = (MemoryScanner) AccessController.doPrivileged(new PrivilegedAction() {
            public Object run() {
                return rm.getMemoryScanner();
            }
        });
        final Address tablePtr =
            scanner.findInt8Array(Address.fromIntZeroExtend(0xe0000), 0x1ffff, match, 0, match.length, 1);
        if (tablePtr != null) {
            final int version = getRSDTVersion(rm, tablePtr);
            return new AcpiRSDPInfo(tablePtr, version);
        } else {
View Full Code Here

            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)) {
                        return;
                    }
                }
            } else {
                // Another thread owns the lock
                // thin lock owned by another thread.
                int ownerId = oldlockword.and(Word.fromIntZeroExtend(ObjectFlags.THREAD_ID_MASK)).toInt();
                VmThread thread = VmMagic.currentProcessor().getScheduler().getThreadById(ownerId);
                if (thread == null) {
                    //the owner of the lock was destroyed              
                    //aquire the lock in fast fashion
                    statusPtr.store(statusFlags.or(tid));
                    return;
                } else {
                    // install an inflated lock.
                    installInflatedLock(object, thread).enter();
                }
View Full Code Here

            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
                    newlockword = oldlockword.sub(Word.fromIntSignExtend(ObjectFlags.LOCK_COUNT_INC));
                }
                if (statusPtr.attempt(oldlockword, newlockword)) {
                    return;
                }
            } else {
                // lock not owned by us!
                String exMsg = "Lock not owned by us:";
                Unsafe.debug(exMsg);
                Unsafe.debug(object.getClass().getName());
                // Extra debug info
                Unsafe.debug("\n");
                Unsafe.debug(oldlockword);
                Unsafe.debug(objectPtr);
                Unsafe.debug(statusPtr);
                Unsafe.debug(oldlockword.and(Word.fromIntZeroExtend(ObjectFlags.LOCK_COUNT_MASK)));
                Unsafe.debug(tid);
                Unsafe.debug(statusPtr.prepareWord());
                VmMagic.currentProcessor().getArchitecture().getStackReader().debugStackTrace();
                Unsafe.die("Please report this problem with the above values to epr@jnode.org");
                throw new IllegalMonitorStateException(exMsg);
            }
        }
View Full Code Here

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

     *
     * @param lockword
     * @return The monitor
     */
    private static Monitor getMonitor(Word lockword) {
        final Address address = lockword.and(Word.fromIntZeroExtend(
            ~(ObjectFlags.LOCK_EXPANDED | ObjectFlags.STATUS_FLAGS_MASK))).toAddress();

        if (address.isZero()) {
            String exMsg = "Inflated monitor is null????";
            Unsafe.debug(exMsg);
            throw new IllegalMonitorStateException(exMsg);
        }
        return (Monitor) address.toObjectReference().toObject();
    }
View Full Code Here

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

     */
    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) {
            v |= mask;
        } else {
            v &= ~mask;
        }
        ptr.store((byte) v);
    }
View Full Code Here

    private VmAddress start;
    private VmAddress end;

    protected final void setAllocationBit(Object object, boolean on) {
        Address addr = ObjectReference.fromObject(object).toAddress();
        final Address start = Address.fromAddress(this.start);
        final Address end = Address.fromAddress(this.end);
        final boolean q1 = (addr.LT(start) || addr.GE(end));

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