Search in sources :

Example 31 with Unpreemptible

use of org.vmmagic.pragma.Unpreemptible in project JikesRVM by JikesRVM.

the class RVMThread method hardHandshakeResume.

@NoCheckStore
@Unpreemptible
public static void hardHandshakeResume(BlockAdapter ba, HardHandshakeVisitor hhv) {
    long before = sysCall.sysNanoTime();
    handshakeLock.lockWithHandshake();
    RVMThread current = getCurrentThread();
    acctLock.lockNoHandshake();
    int numToHandshake = 0;
    for (int i = 0; i < numThreads; ++i) {
        RVMThread t = threads[i];
        if (t != current && !t.ignoreHandshakesAndGC() && hhv.includeThread(t)) {
            handshakeThreads[numToHandshake++] = t;
        }
    }
    acctLock.unlock();
    for (int i = 0; i < numToHandshake; ++i) {
        handshakeThreads[i].unblock(ba);
        // help GC
        handshakeThreads[i] = null;
    }
    handshakeLock.unlock();
    if (false) {
        long after = sysCall.sysNanoTime();
        totalResumeTime += after - before;
        VM.sysWriteln("Resuming the world took ", (after - before), " ns (", totalResumeTime, " ns total)");
    }
}
Also used : Entrypoint(org.vmmagic.pragma.Entrypoint) Unpreemptible(org.vmmagic.pragma.Unpreemptible) NoCheckStore(org.vmmagic.pragma.NoCheckStore)

Example 32 with Unpreemptible

use of org.vmmagic.pragma.Unpreemptible in project JikesRVM by JikesRVM.

the class RVMThread method yieldpoint.

/**
 * Process a taken yieldpoint.
 *
 * @param whereFrom source of the yieldpoint (e.g. backedge)
 * @param yieldpointServiceMethodFP the frame pointer of the service
 *  method that called this method
 */
@Unpreemptible("May block if the thread was asked to do so but otherwise does not perform actions that may lead to blocking")
public static void yieldpoint(int whereFrom, Address yieldpointServiceMethodFP) {
    RVMThread t = getCurrentThread();
    boolean wasAtYieldpoint = t.atYieldpoint;
    t.atYieldpoint = true;
    t.yieldpointsTaken++;
    // just come back here and reset it to 0 again.
    if (!t.yieldpointsEnabled()) {
        if (VM.VerifyAssertions)
            VM._assert(!t.yieldToOSRRequested);
        if (traceBlock && !wasAtYieldpoint) {
            VM.sysWriteln("Thread #", t.threadSlot, " deferring yield!");
            dumpStack();
        }
        t.yieldpointRequestPending = true;
        t.takeYieldpoint = 0;
        t.atYieldpoint = false;
        return;
    }
    t.yieldpointsTakenFully++;
    Throwable throwThis = null;
    t.monitor().lockNoHandshake();
    int takeYieldpointVal = t.takeYieldpoint;
    if (takeYieldpointVal != 0) {
        t.takeYieldpoint = 0;
        // do two things: check if we should be blocking, and act upon
        // handshake requests. This also has the effect of reasserting that
        // we are in fact IN_JAVA (as opposed to IN_JAVA_TO_BLOCK).
        t.checkBlock();
        // Process timer interrupt event
        if (t.timeSliceExpired != 0) {
            t.timeSliceExpired = 0;
            if (t.yieldForCBSCall || t.yieldForCBSMethod) {
            /*
           * CBS Sampling is still active from previous quantum. Note that fact,
           * but leave all the other CBS parameters alone.
           */
            } else {
                if (VM.CBSCallSamplesPerTick > 0) {
                    t.yieldForCBSCall = true;
                    t.takeYieldpoint = -1;
                    t.firstCBSCallSample++;
                    t.firstCBSCallSample = t.firstCBSCallSample % VM.CBSCallSampleStride;
                    t.countdownCBSCall = t.firstCBSCallSample;
                    t.numCBSCallSamples = VM.CBSCallSamplesPerTick;
                }
                if (VM.CBSMethodSamplesPerTick > 0) {
                    t.yieldForCBSMethod = true;
                    t.takeYieldpoint = -1;
                    t.firstCBSMethodSample++;
                    t.firstCBSMethodSample = t.firstCBSMethodSample % VM.CBSMethodSampleStride;
                    t.countdownCBSMethod = t.firstCBSMethodSample;
                    t.numCBSMethodSamples = VM.CBSMethodSamplesPerTick;
                }
            }
            if (VM.BuildForAdaptiveSystem) {
                RuntimeMeasurements.takeTimerSample(whereFrom, yieldpointServiceMethodFP);
            }
            if (VM.BuildForAdaptiveSystem) {
                OSRListener.checkForOSRPromotion(whereFrom, yieldpointServiceMethodFP);
            }
        }
        if (t.yieldForCBSCall) {
            if (!(whereFrom == BACKEDGE || whereFrom == OSROPT)) {
                if (--t.countdownCBSCall <= 0) {
                    if (VM.BuildForAdaptiveSystem) {
                        // take CBS sample
                        RuntimeMeasurements.takeCBSCallSample(whereFrom, yieldpointServiceMethodFP);
                    }
                    t.countdownCBSCall = VM.CBSCallSampleStride;
                    t.numCBSCallSamples--;
                    if (t.numCBSCallSamples <= 0) {
                        t.yieldForCBSCall = false;
                    }
                }
            }
            if (t.yieldForCBSCall) {
                t.takeYieldpoint = -1;
            }
        }
        if (t.yieldForCBSMethod) {
            if (--t.countdownCBSMethod <= 0) {
                if (VM.BuildForAdaptiveSystem) {
                    // take CBS sample
                    RuntimeMeasurements.takeCBSMethodSample(whereFrom, yieldpointServiceMethodFP);
                }
                t.countdownCBSMethod = VM.CBSMethodSampleStride;
                t.numCBSMethodSamples--;
                if (t.numCBSMethodSamples <= 0) {
                    t.yieldForCBSMethod = false;
                }
            }
            if (t.yieldForCBSMethod) {
                t.takeYieldpoint = 1;
            }
        }
        if (VM.BuildForAdaptiveSystem && t.yieldToOSRRequested) {
            t.yieldToOSRRequested = false;
            OSRListener.handleOSRFromOpt(yieldpointServiceMethodFP);
        }
        // switch then there would be the possibility of interleaved GC.
        if (VM.BuildForAdaptiveSystem && t.isWaitingForOsr) {
            if (VM.BuildForIA32) {
                org.jikesrvm.osr.ia32.PostThreadSwitch.postProcess(t);
            } else {
                if (VM.VerifyAssertions)
                    VM._assert(VM.BuildForPowerPC);
                org.jikesrvm.osr.ppc.PostThreadSwitch.postProcess(t);
            }
        }
        if (t.asyncThrowable != null) {
            throwThis = t.asyncThrowable;
            t.asyncThrowable = null;
        }
    }
    t.monitor().unlock();
    t.atYieldpoint = false;
    if (throwThis != null) {
        throwFromUninterruptible(throwThis);
    }
}
Also used : Entrypoint(org.vmmagic.pragma.Entrypoint) Unpreemptible(org.vmmagic.pragma.Unpreemptible)

Example 33 with Unpreemptible

use of org.vmmagic.pragma.Unpreemptible in project JikesRVM by JikesRVM.

the class Collection method blockForGC.

@Override
@Unpreemptible
public void blockForGC() {
    RVMThread t = RVMThread.getCurrentThread();
    t.assertAcceptableStates(RVMThread.IN_JAVA, RVMThread.IN_JAVA_TO_BLOCK);
    RVMThread.observeExecStatusAtSTW(t.getExecStatus());
    RVMThread.getCurrentThread().block(RVMThread.gcBlockAdapter);
}
Also used : RVMThread(org.jikesrvm.scheduler.RVMThread) Unpreemptible(org.vmmagic.pragma.Unpreemptible)

Example 34 with Unpreemptible

use of org.vmmagic.pragma.Unpreemptible in project JikesRVM by JikesRVM.

the class RuntimeEntrypoints method deliverException.

/**
 * Deliver an exception to current java thread.
 * <STRONG> Precondition: </STRONG> VM.disableGC has already been called.
 *  <ol>
 *   <li> exceptionRegisters may not match any reasonable stack
 *          frame at this point.
 *   <li> we're going to be playing with raw addresses (fp, ip).
 *  </ol>
 * <p>
 * Does not return:
 * <ul>
 *  <li> stack is unwound and execution resumes in a catch block
 *  <li> <em> or </em> current thread is terminated if no catch block is found
 * </ul>
 *
 * @param exceptionObject exception object to deliver
 * @param exceptionRegisters register state corresponding to exception site
 */
@Unpreemptible("Deliver exception trying to avoid preemption")
private static void deliverException(Throwable exceptionObject, AbstractRegisters exceptionRegisters) {
    if (VM.TraceExceptionDelivery) {
        VM.sysWriteln("RuntimeEntrypoints.deliverException() entered; just got an exception object.");
    }
    // 
    if (VM.TraceExceptionDelivery) {
        VM.sysWrite("Hunting for a catch block...");
    }
    RVMType exceptionType = Magic.getObjectType(exceptionObject);
    Address fp = exceptionRegisters.getInnermostFramePointer();
    Address hijackedCalleeFp = RVMThread.getCurrentThread().getHijackedReturnCalleeFp();
    boolean leapfroggedReturnBarrier = false;
    if (VM.VerifyAssertions)
        VM._assert(hijackedCalleeFp.isZero() || hijackedCalleeFp.GE(fp));
    while (Magic.getCallerFramePointer(fp).NE(StackFrameLayout.getStackFrameSentinelFP())) {
        if (!hijackedCalleeFp.isZero() && hijackedCalleeFp.LE(fp)) {
            leapfroggedReturnBarrier = true;
        }
        int compiledMethodId = Magic.getCompiledMethodID(fp);
        if (compiledMethodId != StackFrameLayout.getInvisibleMethodID()) {
            CompiledMethod compiledMethod = CompiledMethods.getCompiledMethod(compiledMethodId);
            ExceptionDeliverer exceptionDeliverer = compiledMethod.getExceptionDeliverer();
            Address ip = exceptionRegisters.getInnermostInstructionAddress();
            Offset ipOffset = compiledMethod.getInstructionOffset(ip);
            int catchBlockOffset = compiledMethod.findCatchBlockForInstruction(ipOffset, exceptionType);
            if (catchBlockOffset >= 0) {
                // found an appropriate catch block
                if (VM.TraceExceptionDelivery) {
                    VM.sysWriteln("found one; delivering.");
                }
                if (leapfroggedReturnBarrier) {
                    RVMThread t = RVMThread.getCurrentThread();
                    if (RVMThread.DEBUG_STACK_TRAMPOLINE)
                        VM.sysWriteln("leapfrogged...");
                    t.deInstallStackTrampoline();
                }
                Address catchBlockStart = compiledMethod.getInstructionAddress(Offset.fromIntSignExtend(catchBlockOffset));
                exceptionDeliverer.deliverException(compiledMethod, catchBlockStart, exceptionObject, exceptionRegisters);
                if (VM.VerifyAssertions)
                    VM._assert(NOT_REACHED);
            }
            exceptionDeliverer.unwindStackFrame(compiledMethod, exceptionRegisters);
        } else {
            unwindInvisibleStackFrame(exceptionRegisters);
        }
        fp = exceptionRegisters.getInnermostFramePointer();
    }
    if (VM.TraceExceptionDelivery) {
        VM.sysWriteln("Nope.");
        VM.sysWriteln("RuntimeEntrypoints.deliverException() found no catch block.");
    }
    /* No appropriate catch block found. */
    if (RVMThread.DEBUG_STACK_TRAMPOLINE && leapfroggedReturnBarrier)
        VM.sysWriteln("Leapfrogged, and unhandled!");
    handleUncaughtException(exceptionObject);
}
Also used : Address(org.vmmagic.unboxed.Address) RVMThread(org.jikesrvm.scheduler.RVMThread) RVMType(org.jikesrvm.classloader.RVMType) Entrypoint(org.vmmagic.pragma.Entrypoint) CompiledMethod(org.jikesrvm.compilers.common.CompiledMethod) Offset(org.vmmagic.unboxed.Offset) Unpreemptible(org.vmmagic.pragma.Unpreemptible)

Aggregations

Unpreemptible (org.vmmagic.pragma.Unpreemptible)34 Entrypoint (org.vmmagic.pragma.Entrypoint)23 NoInline (org.vmmagic.pragma.NoInline)14 Address (org.vmmagic.unboxed.Address)12 RVMThread (org.jikesrvm.scheduler.RVMThread)7 Offset (org.vmmagic.unboxed.Offset)6 Word (org.vmmagic.unboxed.Word)6 NoCheckStore (org.vmmagic.pragma.NoCheckStore)5 NoNullCheck (org.vmmagic.pragma.NoNullCheck)5 OptCompiledMethod (org.jikesrvm.compilers.opt.runtimesupport.OptCompiledMethod)4 Inline (org.vmmagic.pragma.Inline)4 BaselineSaveLSRegisters (org.vmmagic.pragma.BaselineSaveLSRegisters)3 NoOptCompile (org.vmmagic.pragma.NoOptCompile)3 NormalMethod (org.jikesrvm.classloader.NormalMethod)2 CompiledMethod (org.jikesrvm.compilers.common.CompiledMethod)2 GPR (org.jikesrvm.ia32.RegisterConstants.GPR)2 AbstractRegisters (org.jikesrvm.architecture.AbstractRegisters)1 RVMArray (org.jikesrvm.classloader.RVMArray)1 RVMMethod (org.jikesrvm.classloader.RVMMethod)1 RVMType (org.jikesrvm.classloader.RVMType)1