Skip to content

Commit

Permalink
Rename scheduler methods from awful previous nicely, dangerously... n…
Browse files Browse the repository at this point in the history
…ames. Bring up-to-date with RVM 15658.
  • Loading branch information
Ian Rogers committed Apr 20, 2009
1 parent c71eae1 commit 8d72057
Show file tree
Hide file tree
Showing 20 changed files with 206 additions and 156 deletions.
4 changes: 2 additions & 2 deletions MMTk/ext/vm/jikesrvm/org/jikesrvm/mm/mmtk/Collection.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private static void checkForOutOfMemoryError(boolean afterCollection) {
*/
public int maximumCollectionAttempt() {
int max = 1;
RVMThread.acctLock.lock();
RVMThread.acctLock.lockNoHandshake();
for(int t=0; t < RVMThread.numThreads; t++) {
RVMThread thread = RVMThread.threads[t];
int current = thread.getCollectionAttempt();
Expand Down Expand Up @@ -228,7 +228,7 @@ public final void prepareMutator(MutatorContext m) {
* off in JNI-land cannot run.
*/
RVMThread t = ((Selected.Mutator) m).getThread();
t.monitor().lock();
t.monitor().lockNoHandshake();
// are these the only unexpected states?
t.assertUnacceptableStates(RVMThread.IN_JNI,RVMThread.IN_NATIVE);
int execStatus = t.getExecStatus();
Expand Down
6 changes: 3 additions & 3 deletions MMTk/ext/vm/jikesrvm/org/jikesrvm/mm/mmtk/Lock.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ public void acquire() {
queue.enqueue(me);
Magic.sync();
state=LOCKED_QUEUED;
me.monitor().lock();
me.monitor().lockNoHandshake();
while (queue.isQueued(me)) {
// use await instead of waitNicely because this is NOT a GC point!
me.monitor().await();
me.monitor().waitNoHandshake();
}
me.monitor().unlock();
}
Expand Down Expand Up @@ -162,7 +162,7 @@ public void release() {
} else {
state=CLEAR_QUEUED;
}
toAwaken.monitor().lockedBroadcast();
toAwaken.monitor().lockedBroadcastNoHandshake();
break;
}
}
Expand Down
18 changes: 14 additions & 4 deletions rvm/src/org/jikesrvm/VM.java
Original file line number Diff line number Diff line change
Expand Up @@ -1399,6 +1399,17 @@ public static void sysWriteln(String s, long i) {
swUnlock();
}

@NoInline
public static void sysWriteln(String s1, long i1,String s2, long i2) {
swLock();
write(s1);
write(i1);
write(s2);
write(i2);
writeln();
swUnlock();
}

@NoInline
public static void sysWrite(int i, String s) {
swLock();
Expand Down Expand Up @@ -2532,12 +2543,11 @@ public static void disableGC(boolean recursiveOK) {
}

// 1.
//
//
if (!VM.AutomaticStackGrowth) {
if (Magic.getFramePointer().minus(ArchitectureSpecific.StackframeLayoutConstants.STACK_SIZE_GCDISABLED)
.LT(myThread.stackLimit) && !myThread.hasNativeStackFrame()) {
RVMThread.resizeCurrentStack(myThread.getStackLength()+
ArchitectureSpecific.StackframeLayoutConstants.STACK_SIZE_GCDISABLED, null);
.LT(myThread.stackLimit) && !myThread.hasNativeStackFrame()) {
RVMThread.resizeCurrentStack(myThread.getStackLength() + ArchitectureSpecific.StackframeLayoutConstants.STACK_SIZE_GCDISABLED, null);
}
}

Expand Down
8 changes: 4 additions & 4 deletions rvm/src/org/jikesrvm/adaptive/OSROrganizerThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public OSROrganizerThread() {
@Override
public void run() {
while (true) {
monitor().lock();
monitor().lockNoHandshake();
if (!this.osr_flag) {
monitor().waitNicely();
monitor().waitWithHandshake();
}
this.osr_flag=false; /* if we get another activation after here
then we should rescan the threads array */
Expand All @@ -55,7 +55,7 @@ public void run() {
*/
@Uninterruptible
public void activate() {
monitor().lock();
monitor().lockNoHandshake();
osr_flag=true;
monitor().broadcast();
monitor().unlock();
Expand All @@ -69,7 +69,7 @@ private void processOsrRequest() {
RVMThread t=RVMThread.threads[i];
if (t!=null) {
boolean go=false;
t.monitor().lock();
t.monitor().lockNoHandshake();
// NOTE: if threads are being removed, we may see a thread twice
if (t.requesting_osr) {
t.requesting_osr=false;
Expand Down
2 changes: 1 addition & 1 deletion rvm/src/org/jikesrvm/adaptive/OnStackReplacementPlan.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public void execute() {
}
}

suspendedThread.monitor().lock();
suspendedThread.monitor().lockNoHandshake();
suspendedThread.osr_done=true;
suspendedThread.monitor().broadcast();
suspendedThread.monitor().unlock();
Expand Down
6 changes: 3 additions & 3 deletions rvm/src/org/jikesrvm/adaptive/OnStackReplacementTrigger.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ public static void trigger(int ypTakenInCMID, Offset tsFromFPoff, Offset ypTaken
event.tsFromFPoff = tsFromFPoff;
event.ypTakenFPoff = ypTakenFPoff;

thread.monitor().lock();
thread.monitor().lockNoHandshake();
thread.requesting_osr = true;
thread.monitor().unlock();

Controller.osrOrganizer.activate();
// PNT: Assumes that OSR doesn't need access to our context regs
thread.monitor().lock();
thread.monitor().lockNoHandshake();
while (!thread.osr_done) {
thread.monitor().waitNicely();
thread.monitor().waitWithHandshake();
}
thread.osr_done=false;
thread.monitor().unlock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public synchronized void update(int cmid, double numCounts) {
* To get a sorted list, pipe the output through sort -n -r.
*/
public synchronized void report() {
RVMThread.dumpLock.lock();
RVMThread.dumpLock.lockNoHandshake();
VM.sysWrite("Method counts: A total of " + totalCountsTaken + " samples\n");
for (int i = 1; i < nextIndex; i++) {
double percent = 100 * countsToHotness(counts[i]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public AsyncReporter() {
}
public void run() {
for (;;) {
RVMThread.doProfileReport.waitAndClose();
RVMThread.doProfileReport.waitAndCloseWithHandshake();
report();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private void passivate() {
if (VM.VerifyAssertions) VM._assert(!listener.isActive());
listener.activate();
}
latch.waitAndClose();
latch.waitAndCloseWithHandshake();
}

/**
Expand All @@ -101,6 +101,6 @@ public void activate() {
if (VM.VerifyAssertions) VM._assert(listener.isActive());
listener.passivate();
}
latch.openDangerously();
latch.openNoHandshake();
}
}
2 changes: 1 addition & 1 deletion rvm/src/org/jikesrvm/classloader/NativeMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private String getMangledArgs() {
String result = (char)getReturnType().getName().parseForTypeCode() + "PL";
// encode the arguments
for (TypeReference arg : getParameterTypes()) {
result += (char)arg.getName().parseForTypeCode();
result += (char)arg.getName().parseForTypeCode();
}
return result;
}
Expand Down
4 changes: 2 additions & 2 deletions rvm/src/org/jikesrvm/mm/mminterface/Barrier.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public boolean arrive(int mode) {
" entered ",RVMThread.getCurrentThread().barriersEntered++,
" barriers");
}
lock.lock();
lock.lockNoHandshake();
int myCountIdx=countIdx;
boolean result;
if (VM.VerifyAssertions) {
Expand Down Expand Up @@ -75,7 +75,7 @@ public boolean arrive(int mode) {
result=true;
} else {
while (counters[myCountIdx]!=0) {
lock.await();
lock.waitNoHandshake();
}
result=false;
}
Expand Down
10 changes: 5 additions & 5 deletions rvm/src/org/jikesrvm/mm/mminterface/CollectorThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,12 @@ public void run() {
themselves (if they had made their own GC requests). */
if (gcOrdinal == GC_ORDINAL_BASE) {
if (verbose>=2) VM.sysWriteln("Thread #",getThreadSlot()," is about to block a bunch of threads.");
RVMThread.handshakeLock.lock();
RVMThread.handshakeLock.lockNoHandshake();
// fixpoint until there are no threads that we haven't blocked.
// fixpoint is needed in case some thread spawns another thread
// while we're waiting. that is unlikely but possible.
for (;;) {
RVMThread.acctLock.lock();
RVMThread.acctLock.lockNoHandshake();
int numToHandshake=0;
for (int i=0;i<RVMThread.numThreads;++i) {
RVMThread t=threads[i];
Expand All @@ -364,7 +364,7 @@ public void run() {

for (int i=0;i<numToHandshake;++i) {
RVMThread t=RVMThread.handshakeThreads[i];
t.monitor().lock();
t.monitor().lockNoHandshake();
if (t.blockedFor(RVMThread.gcBlockAdapter) ||
RVMThread.notRunning(t.asyncBlock(RVMThread.gcBlockAdapter))) {
// already blocked or not running, remove
Expand Down Expand Up @@ -501,8 +501,8 @@ public void run() {

if (verbose>=2) VM.sysWriteln("Thread #",getThreadSlot()," is unblocking a bunch of threads.");
// and now unblock all threads
RVMThread.handshakeLock.lock();
RVMThread.acctLock.lock();
RVMThread.handshakeLock.lockNoHandshake();
RVMThread.acctLock.lockNoHandshake();
int numToHandshake=0;
for (int i=0;i<RVMThread.numThreads;++i) {
RVMThread t=threads[i];
Expand Down
8 changes: 4 additions & 4 deletions rvm/src/org/jikesrvm/mm/mminterface/Handshake.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void requestAndContinue(int why) {
@Unpreemptible
public void reset() {
if (lock!=null) {
lock.lock();
lock.lockNoHandshake();
}
gcTrigger = Collection.UNKNOWN_GC_TRIGGER;
requestFlag = false;
Expand All @@ -113,13 +113,13 @@ public void reset() {
}
@Unpreemptible
void parkCollectorThread() {
lock.lock();
lock.lockNoHandshake();
collectorThreadsParked++;
lock.broadcast();
if (verbose>=1) VM.sysWriteln("GC Thread #",RVMThread.getCurrentThreadSlot()," parked.");
while (!requestFlag) {
if (verbose>=1) VM.sysWriteln("GC Thread #",RVMThread.getCurrentThreadSlot()," waiting for request.");
lock.waitNicely();
lock.waitWithHandshake();
}
if (verbose>=1) VM.sysWriteln("GC Thread #",RVMThread.getCurrentThreadSlot()," got request, unparking.");
collectorThreadsParked--;
Expand All @@ -134,7 +134,7 @@ void parkCollectorThread() {
@Unpreemptible("Becoming another thread interrupts the current thread, avoid preemption in the process")
private boolean request(int why) {
if (verbose>=1) VM.sysWriteln("Thread #",RVMThread.getCurrentThreadSlot()," is trying to make a GC request");
lock.lock();
lock.lockNoHandshake();
if (verbose>=1) VM.sysWriteln("Thread #",RVMThread.getCurrentThreadSlot()," acquired the lock for making a GC request");
if (why > gcTrigger) gcTrigger = why;
if (requestFlag) {
Expand Down
6 changes: 3 additions & 3 deletions rvm/src/org/jikesrvm/scheduler/FinalizerThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static void boot() {
}
@Uninterruptible
public static void schedule() {
schedLock.lock();
schedLock.lockNoHandshake();
shouldRun=true;
schedLock.broadcast();
schedLock.unlock();
Expand All @@ -67,12 +67,12 @@ public void run() {

// suspend this thread: it will resume when the garbage collector
// places objects on the finalizer queue and notifies.
schedLock.lock();
schedLock.lockNoHandshake();
if (!shouldRun) {
if (verbose>=1) {
VM.sysWriteln("finalizer thread sleeping.");
}
schedLock.waitNicely();
schedLock.waitWithHandshake();
}
shouldRun=false;
schedLock.unlock();
Expand Down
24 changes: 12 additions & 12 deletions rvm/src/org/jikesrvm/scheduler/Latch.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public Latch(boolean open) {
* But - if any of the threads is using waitAndClose(), then as soon
* as that thread awakes further threads will be blocked.
*/
public void open() {
schedLock.lockNicely();
public void openWithHandshake() {
schedLock.lockWithHandshake();
open=true;
schedLock.broadcast();
schedLock.unlock();
Expand All @@ -53,8 +53,8 @@ public void open() {
* interrupt handlers.
*/
@Uninterruptible
public void openDangerously() {
schedLock.lock();
public void openNoHandshake() {
schedLock.lockNoHandshake();
open=true;
schedLock.broadcast();
schedLock.unlock();
Expand All @@ -63,19 +63,19 @@ public void openDangerously() {
* Close the latch, causing future calls to wait() or waitAndClose()
* to block.
*/
public void close() {
schedLock.lockNicely();
public void closeWithHandshake() {
schedLock.lockWithHandshake();
open=false;
schedLock.unlock();
}
/**
* Wait for the latch to become open. If it is already open, don't
* wait at all.
*/
public void await() {
schedLock.lockNicely();
public void waitWithHandshake() {
schedLock.lockWithHandshake();
while (!open) {
schedLock.waitNicely();
schedLock.waitWithHandshake();
}
schedLock.unlock();
}
Expand All @@ -84,10 +84,10 @@ public void await() {
* If the latch is already open, don't wait at all, just close it
* immediately and return.
*/
public void waitAndClose() {
schedLock.lockNicely();
public void waitAndCloseWithHandshake() {
schedLock.lockWithHandshake();
while (!open) {
schedLock.waitNicely();
schedLock.waitWithHandshake();
}
open=false;
schedLock.unlock();
Expand Down
6 changes: 3 additions & 3 deletions rvm/src/org/jikesrvm/scheduler/Lock.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ public boolean lockHeavyLocked(Object o) {
} else {
entering.enqueue(me);
mutex.unlock();
me.monitor().lock();
me.monitor().lockNoHandshake();
while (entering.isQueued(me)) {
me.monitor().waitNicely(); // this may spuriously return
me.monitor().waitWithHandshake(); // this may spuriously return
}
me.monitor().unlock();
return false;
Expand Down Expand Up @@ -292,7 +292,7 @@ public void unlockHeavy(Object o) {
}
mutex.unlock(); // does a Magic.sync(); (thread-switching benign)
if (toAwaken != null) {
toAwaken.monitor().lockedBroadcast();
toAwaken.monitor().lockedBroadcastNoHandshake();
}
}

Expand Down
Loading

0 comments on commit 8d72057

Please sign in to comment.