Example #1
0
/*
 * Exercise several of the atomic ops.
 */
static void doAtomicTest(int num) {
    int addVal = (num & 0x01) + 1;

    int i;
    for (i = 0; i < ITERATION_COUNT; i++) {
        if (USE_ATOMIC) {
            android_atomic_inc(&incTest);
            android_atomic_dec(&decTest);
            android_atomic_add(addVal, &addTest);

            int val;
            do {
                val = casTest;
            } while (android_atomic_release_cas(val, val + 3, &casTest) != 0);
            do {
                val = casTest;
            } while (android_atomic_acquire_cas(val, val - 1, &casTest) != 0);

            int64_t wval;
            do {
                wval = dvmQuasiAtomicRead64(&wideCasTest);
            } while (dvmQuasiAtomicCas64(wval,
                                         wval + 0x0000002000000001LL, &wideCasTest) != 0);
            do {
                wval = dvmQuasiAtomicRead64(&wideCasTest);
            } while (dvmQuasiAtomicCas64(wval,
                                         wval - 0x0000002000000001LL, &wideCasTest) != 0);
        } else {
            incr();
            decr();
            add(addVal);

            int val;
            do {
                val = casTest;
            } while (compareAndSwap(val, val + 3, &casTest) != 0);
            do {
                val = casTest;
            } while (compareAndSwap(val, val - 1, &casTest) != 0);

            int64_t wval;
            do {
                wval = wideCasTest;
            } while (compareAndSwapWide(wval,
                                        wval + 0x0000002000000001LL, &wideCasTest) != 0);
            do {
                wval = wideCasTest;
            } while (compareAndSwapWide(wval,
                                        wval - 0x0000002000000001LL, &wideCasTest) != 0);
        }
    }
}
Example #2
0
/*
 * public native long getLongVolatile(Object obj, long offset);
 */
static void Dalvik_sun_misc_Unsafe_getLongVolatile(const u4 *args,
                                                   JValue *pResult) {
    // We ignore the this pointer in args[0].
    Object *obj = (Object *) args[1];
    s8 offset = GET_ARG_LONG(args, 2);
    volatile int64_t *address = (volatile int64_t *) (((u1 *) obj) + offset);

    assert((offset & 7) == 0);
    RETURN_LONG(dvmQuasiAtomicRead64(address));
}
Example #3
0
/*
 * Return the time, in milliseconds, since the last debugger activity.
 *
 * Returns -1 if no debugger is attached, or 0 if we're in the middle of
 * processing a debugger request.
 */
s8 dvmJdwpLastDebuggerActivity(JdwpState* state)
{
    if (!gDvm.debuggerActive) {
        LOGD("dvmJdwpLastDebuggerActivity: no active debugger\n");
        return -1;
    }

    s8 last = dvmQuasiAtomicRead64(&state->lastActivityWhen);

    /* initializing or in the middle of something? */
    if (last == 0) {
        LOGV("+++ last=busy\n");
        return 0;
    }

    /* now get the current time */
    s8 now = dvmJdwpGetNowMsec();
    assert(now > last);

    LOGV("+++ debugger interval=%lld\n", now - last);
    return now - last;
}