Commit 77a0726c authored by Yi Lin's avatar Yi Lin

count each single yieldpoint

parent 892fb628
......@@ -100,6 +100,10 @@ public final class YieldpointCounterData extends StringEventCounterData implemen
return collectData("TRAP");
}
public double reportYieldpointOfID(int id) {
return collectData("ID=" + Integer.toString(id) + ")");
}
private double collectData(String keyword) {
Instrumentation.disableInstrumentation();
......
......@@ -110,16 +110,18 @@ public class InsertYieldpointCounters extends CompilerPhase {
int compileType = ir.compiledMethod.getCompilerType();
if (compileType == CompiledMethod.BASELINE)
prefix += "(BASE) ";
prefix += "(BASE,";
else if (compileType == CompiledMethod.OPT) {
prefix += "(OPT) ";
prefix += "(OPT,";
}
else if (compileType == CompiledMethod.JNI) {
prefix += "(JNI) ";
prefix += "(JNI,";
}
else if (compileType == CompiledMethod.TRAP) {
prefix += "(TRAP) ";
prefix += "(TRAP,";
}
prefix += "ID=" + i.yieldpointID + ")";
// Create an instruction to increment the counter for this
// method. By appending the prefix and method name, it
......
......@@ -28,6 +28,7 @@ import org.jikesrvm.compilers.opt.runtimesupport.OptCompiledMethod;
import org.jikesrvm.jni.JNICompiledMethod;
import org.jikesrvm.runtime.Magic;
import org.jikesrvm.runtime.Memory;
import org.jikesrvm.runtime.Time;
import org.jikesrvm.scheduler.NoYieldpointsMonitor;
import org.jikesrvm.scheduler.YieldpointStatistics;
import org.vmmagic.pragma.Uninterruptible;
......@@ -357,7 +358,7 @@ public class CompiledMethods {
@Uninterruptible
public static void setNOP2CALL() {
VM.sysWriteln("-----Start patching code-----");
// VM.sysWriteln("-----Start patching code-----");
int patched = 0;
long start = Magic.getTimeBase();
......@@ -394,15 +395,15 @@ public class CompiledMethods {
long time = Magic.getTimeBase() - start;
YieldpointStatistics.methodsPatched(patched);
VM.sysWriteln("patched ", patched, " YPs ");
VM.sysWriteln(" in ", time, " cycles. ");
YieldpointStatistics.yieldpointsPatched(patched);
// VM.sysWriteln("patched ", patched, " YPs ");
// VM.sysWriteln(" in ", time, " cycles. ");
}
@Uninterruptible
public static void setCALL2NOP() {
int patched = 0;
long start = Magic.getTimeBase();
long start = Time.currentTimeMillis();
// for (int i = 0, n = numCompiledMethods(); i < n; i ++) {
// CompiledMethod cm = getCompiledMethodUnchecked(i);
......@@ -435,7 +436,10 @@ public class CompiledMethods {
patched++;
}
long time = Magic.getTimeBase() - start;
long time = Time.currentTimeMillis() - start;
YieldpointStatistics.timeUsedOnPatching(time);
YieldpointStatistics.yieldpointsPatched(patched);
// VM.sysWriteln("patched ", patched, " methods ");
// VM.sysWriteln(" in ", time, " cycles. ");
......@@ -446,7 +450,7 @@ public class CompiledMethods {
// VM.sysWriteln("-----Start patching code-----");
int patched = 0;
long start = Magic.getTimeBase();
long start = Time.currentTimeMillis();
for (int i = 0, n = numCompiledMethods(); i < n; i ++) {
CompiledMethod cm = getCompiledMethodUnchecked(i);
......@@ -459,9 +463,10 @@ public class CompiledMethods {
patched ++;
}
long time = Magic.getTimeBase() - start;
long time = Time.currentTimeMillis() - start;
YieldpointStatistics.methodsPatched(patched);
YieldpointStatistics.timeUsedOnPatching(time);
YieldpointStatistics.yieldpointsPatched(patched);
// VM.sysWriteln("patched ", patched, " methods ");
// VM.sysWriteln(" in ", time, " cycles. ");
}
......
......@@ -22,6 +22,8 @@ import static org.jikesrvm.compilers.opt.ir.Operators.YIELDPOINT_PROLOGUE;
import java.util.Enumeration;
import org.jikesrvm.VM;
import org.jikesrvm.adaptive.database.AOSDatabase;
import org.jikesrvm.compilers.common.CompiledMethods;
import org.jikesrvm.compilers.opt.driver.CompilerPhase;
import org.jikesrvm.compilers.opt.inlining.InlineSequence;
import org.jikesrvm.compilers.opt.ir.BasicBlock;
......@@ -67,7 +69,7 @@ public class YieldPoints extends CompilerPhase {
public final CompilerPhase newExecution(IR ir) {
return this;
}
/**
* Insert yield points in method prologues, loop heads, and method exits
*
......@@ -82,14 +84,14 @@ public class YieldPoints extends CompilerPhase {
// As part of prologue/epilogue insertion we'll remove
// the yieldpoints in trivial methods that otherwise wouldn't need
// a stackframe.
prependYield(ir.cfg.entry(), YIELDPOINT_PROLOGUE, 0, ir.gc.getInlineSequence());
prependYield(ir, ir.cfg.entry(), YIELDPOINT_PROLOGUE, 0, ir.gc.getInlineSequence());
// (2) If using epilogue yieldpoints scan basic blocks, looking for returns or throws
if (VM.UseEpilogueYieldPoints) {
for (Enumeration<BasicBlock> e = ir.getBasicBlocks(); e.hasMoreElements();) {
BasicBlock block = e.nextElement();
if (block.hasReturn() || block.hasAthrowInst()) {
prependYield(block, YIELDPOINT_EPILOGUE, INSTRUMENTATION_BCI, ir.gc.getInlineSequence());
prependYield(ir, block, YIELDPOINT_EPILOGUE, INSTRUMENTATION_BCI, ir.gc.getInlineSequence());
}
}
}
......@@ -98,7 +100,7 @@ public class YieldPoints extends CompilerPhase {
LSTGraph lst = ir.HIRInfo.loopStructureTree;
if (lst != null) {
for (java.util.Enumeration<LSTNode> e = lst.getRoot().getChildren(); e.hasMoreElements();) {
processLoopNest(e.nextElement());
processLoopNest(ir, e.nextElement());
}
}
}
......@@ -108,13 +110,13 @@ public class YieldPoints extends CompilerPhase {
*
* @param n a loop node
*/
private void processLoopNest(LSTNode n) {
private void processLoopNest(IR ir, LSTNode n) {
for (java.util.Enumeration<LSTNode> e = n.getChildren(); e.hasMoreElements();) {
processLoopNest(e.nextElement());
processLoopNest(ir, e.nextElement());
}
Instruction dest = n.header.firstInstruction();
if (dest.position.getMethod().isInterruptible()) {
prependYield(n.header, YIELDPOINT_BACKEDGE, dest.bcIndex, dest.position);
prependYield(ir, n.header, YIELDPOINT_BACKEDGE, dest.bcIndex, dest.position);
}
}
......@@ -127,7 +129,7 @@ public class YieldPoints extends CompilerPhase {
* @param bcIndex the bcIndex of the yieldpoint
* @param position the source position of the yieldpoint
*/
private void prependYield(BasicBlock bb, Operator yp, int bcIndex, InlineSequence position) {
private void prependYield(IR ir, BasicBlock bb, Operator yp, int bcIndex, InlineSequence position) {
Instruction insertionPoint = null;
if (bb.isEmpty()) {
......@@ -148,10 +150,15 @@ public class YieldPoints extends CompilerPhase {
}
Instruction s = Empty.create(yp);
int id = yieldpointCount;
s.yieldpointID = id;
yieldpointCount++;
insertionPoint.insertBefore(s);
s.position = position;
s.bcIndex = bcIndex;
}
public static int yieldpointCount = 0;
}
......
......@@ -140,6 +140,7 @@ import org.vmmagic.pragma.NoInline;
* @see BasicBlock
*/
public final class Instruction {
public int yieldpointID;
/**
* BITFIELD used to encode {@link #operatorInfo}.
......
......@@ -452,11 +452,15 @@ public class FinalMIRExpansion extends IRTools {
expandCodePatchingYieldpointNOP6(p, ir);
}
else if (org.mmtk.vm.VM.config.YIELDPOINT_IMPL == org.mmtk.vm.Config.USE_CODE_PATCHING_CALL_LOCAL_YP) {
expandCodePatchingYieldpointNOP6(p, ir);
// expandCodePatchingYieldpointNOP6(p, ir);
expandYieldpoint(p, ir, Entrypoints.optThreadSwitchFromPrologueMethod, IA32ConditionOperand.NE());
}
break;
case YIELDPOINT_EPILOGUE_opcode:
if (YieldpointStatistics.ENABLE_YP_COUNT)
YieldpointStatistics.yieldpointOptInsertedForEpilogue++;
if (org.mmtk.vm.VM.config.YIELDPOINT_IMPL == org.mmtk.vm.Config.USE_CHECKING_YP)
expandYieldpoint(p, ir, Entrypoints.optThreadSwitchFromEpilogueMethod, IA32ConditionOperand.NE());
else if (org.mmtk.vm.VM.config.YIELDPOINT_IMPL == org.mmtk.vm.Config.USE_GLOBAL_CHECKING_YP) {
......@@ -492,7 +496,8 @@ public class FinalMIRExpansion extends IRTools {
expandCodePatchingYieldpointNOP6(p, ir);
}
else if (org.mmtk.vm.VM.config.YIELDPOINT_IMPL == org.mmtk.vm.Config.USE_CODE_PATCHING_CALL_LOCAL_YP) {
expandCodePatchingYieldpointNOP6(p, ir);
// expandCodePatchingYieldpointNOP6(p, ir);
expandYieldpoint(p, ir, Entrypoints.optThreadSwitchFromPrologueMethod, IA32ConditionOperand.NE());
}
break;
......@@ -795,4 +800,10 @@ private static void expandPageProtectionReadYieldpoint(Instruction p, IR ir) {
// make a jump to yield block
thisBlock.appendInstruction(MIR_Branch.create(IA32_JMP, yieldpoint.makeJumpTarget()));
}
static int id = 0;
private static void genYieldpointExecutedCounter(Instruction yp, IR ir) {
}
}
......@@ -16,6 +16,7 @@ import org.jikesrvm.VM;
import org.jikesrvm.compilers.common.CompiledMethods;
import org.jikesrvm.runtime.Magic;
import org.jikesrvm.scheduler.RVMThread;
import org.jikesrvm.scheduler.YieldpointStatistics;
import org.vmmagic.pragma.Entrypoint;
import org.vmmagic.pragma.Interruptible;
import org.vmmagic.pragma.SaveVolatile;
......@@ -123,7 +124,7 @@ public class OptSaveVolatile {
RVMThread.getCurrentThread().takeYieldpoint = 1;
RVMThread.yieldpoint(RVMThread.OSROPT, fp);
}
/**
* Wrapper to save/restore volatile registers when a class needs to be
* dynamically loaded/resolved/etc.
......
......@@ -47,62 +47,62 @@ public class TimerThread extends SystemThread {
// TODO: consider allowing GC to be sampled to enable profile-directed optimization of MMTk.
@Override
public void run() {
// VM.disableYieldpoints();
// if (verbose>=1) VM.sysWriteln("TimerThread run routine entered");
// try {
// for (;;) {
// sysCall.sysNanoSleep(1000L*1000L*VM.interruptQuantum);
//
//// int total = 0;
//// int base = 0;
//// int o0 = 0, o1 = 0, o2 = 0;
////
//// for (int i = 0; i < CompiledMethods.numCompiledMethods(); i++) {
//// CompiledMethod cm = CompiledMethods.getCompiledMethod(i);
//// if (cm == null || !cm.isCompiled())
//// continue;
////
//// total ++;
////
//// if (cm.getCompilerType() == CompiledMethod.BASELINE)
//// base ++;
//// else if (cm.getCompilerType() == CompiledMethod.OPT) {
//// int olvl = ((OptCompiledMethod)cm).getOptLevel();
//// if (olvl == 0)
//// o0++;
//// else if (olvl == 1)
//// o1++;
//// else if (olvl == 2)
//// o2++;
//// }
//// }
////
//// VM.sysWriteln("Total: ", total);
//// VM.sysWriteln(" Base: ", base);
//// VM.sysWriteln(" O0: ", o0);
//// VM.sysWriteln(" O1: ", o1);
//// VM.sysWriteln(" O2: ", o2);
//
// if (VM.BuildForAdaptiveSystem) {
// // grab the lock to prevent threads from getting GC'd while we are
// // iterating (since this thread doesn't stop for GC)
// RVMThread.acctLock.lockNoHandshake();
// RVMThread.timerTicks++;
// for (int i=0;i<RVMThread.numThreads;++i) {
// RVMThread candidate=RVMThread.threads[i];
// if (candidate!=null && candidate.shouldBeSampled() && candidate.eligibleForTimerThread()) {
// candidate.timeSliceExpired++;
// candidate.turnOnLocalYieldpoints();
// }
// }
// RVMThread.acctLock.unlock();
VM.disableYieldpoints();
if (verbose>=1) VM.sysWriteln("TimerThread run routine entered");
try {
for (;;) {
sysCall.sysNanoSleep(1000L*1000L*VM.interruptQuantum);
// int total = 0;
// int base = 0;
// int o0 = 0, o1 = 0, o2 = 0;
//
// for (int i = 0; i < CompiledMethods.numCompiledMethods(); i++) {
// CompiledMethod cm = CompiledMethods.getCompiledMethod(i);
// if (cm == null || !cm.isCompiled())
// continue;
//
// total ++;
//
// if (cm.getCompilerType() == CompiledMethod.BASELINE)
// base ++;
// else if (cm.getCompilerType() == CompiledMethod.OPT) {
// int olvl = ((OptCompiledMethod)cm).getOptLevel();
// if (olvl == 0)
// o0++;
// else if (olvl == 1)
// o1++;
// else if (olvl == 2)
// o2++;
// }
// }
//
// RVMThread.checkDebugRequest();
// }
// } catch (Throwable e) {
// printExceptionAndDie(e);
// }
//
// VM.sysWriteln("Total: ", total);
// VM.sysWriteln(" Base: ", base);
// VM.sysWriteln(" O0: ", o0);
// VM.sysWriteln(" O1: ", o1);
// VM.sysWriteln(" O2: ", o2);
if (VM.BuildForAdaptiveSystem) {
// grab the lock to prevent threads from getting GC'd while we are
// iterating (since this thread doesn't stop for GC)
RVMThread.acctLock.lockNoHandshake();
RVMThread.timerTicks++;
for (int i=0;i<RVMThread.numThreads;++i) {
RVMThread candidate=RVMThread.threads[i];
if (candidate!=null && candidate.shouldBeSampled() && candidate.eligibleForTimerThread()) {
candidate.timeSliceExpired++;
candidate.turnOnLocalYieldpoints();
}
}
RVMThread.acctLock.unlock();
}
RVMThread.checkDebugRequest();
}
} catch (Throwable e) {
printExceptionAndDie(e);
}
}
@UninterruptibleNoWarn
private static void printExceptionAndDie(Throwable e) {
......
......@@ -4,6 +4,8 @@ import org.jikesrvm.VM;
import org.jikesrvm.adaptive.controller.Controller;
import org.jikesrvm.adaptive.database.AOSDatabase;
import org.jikesrvm.adaptive.measurements.instrumentation.Instrumentation;
import org.jikesrvm.compilers.common.CompiledMethods;
import org.jikesrvm.compilers.opt.controlflow.YieldPoints;
import org.jikesrvm.mm.mmtk.SynchronizedCounter;
import org.jikesrvm.runtime.SysCall;
import org.mmtk.utility.statistics.LongCounter;
......@@ -17,6 +19,9 @@ import org.vmmagic.pragma.Uninterruptible;
public class YieldpointStatistics {
// use -X:aos:insert_yieldpoint_counters with this flag
public static final boolean ENABLE_YP_COUNT = true;
// how much time patching takes
public static double patchingCost = 0;
// how many yieldpoint are executed in baseline code
public static SynchronizedCounter baselineYieldpointExecuted = new SynchronizedCounter();
......@@ -25,6 +30,7 @@ public class YieldpointStatistics {
public static SynchronizedCounter yieldpointTaken = new SynchronizedCounter();
public static long yieldpointOptInsertedForPrologue = 0;
public static long yieldpointOptInsertedForEpilogue = 0;
public static long yieldpointOptInsertedForBackedge = 0;
public static long yieldpointBaselineInserted = 0;
......@@ -38,14 +44,14 @@ public class YieldpointStatistics {
public static long mutatorStartTimeMillis;
public static long mutatorTimeWithoutBlockingCost = 0;
public static int maxMethodsPatched = 0;
public static int maxYieldpointsPatched = 0;
@Interruptible
public static void reset() {
if (ENABLE_YP_COUNT) {
yieldpointTaken.reset();
baselineYieldpointExecuted.reset();
// yieldpointOptInsertedForPrologue.reset();
// yieldpointOptInsertedForBackedge.reset();
......@@ -60,7 +66,8 @@ public class YieldpointStatistics {
mutatorTimeWithoutBlockingCost = 0;
mutatorStartTimeMillis = SysCall.sysCall.sysCurrentTimeMillis();
maxMethodsPatched = 0;
maxYieldpointsPatched = 0;
patchingCost = 0;
}
@Interruptible
......@@ -71,9 +78,13 @@ public class YieldpointStatistics {
Instrumentation.disableInstrumentation();
}
public static void methodsPatched(int patched) {
if (patched > maxMethodsPatched)
maxMethodsPatched = patched;
public static void yieldpointsPatched(int patched) {
if (patched > maxYieldpointsPatched)
maxYieldpointsPatched = patched;
}
public static void timeUsedOnPatching(long time) {
patchingCost += time;
}
public static void executeBaselineYP() {
......@@ -101,7 +112,8 @@ public class YieldpointStatistics {
printColumn("yieldpointTurnedOnLatencySum");
printColumn("allThreadsBlockedLatencySum");
printColumn("mutatorTimeWithoutBlockingCost");
printColumn("maxMethodsPatched");
printColumn("maxYieldpointsPatched");
printColumn("patchingCost");
if (ENABLE_YP_COUNT) {
printColumn("yieldpointTaken");
printColumn("yieldpointExecutedFromPrologue");
......@@ -112,6 +124,7 @@ public class YieldpointStatistics {
printColumn("yieldpointExecutedFromJNI");
printColumn("yieldpointExecutedFromTrap");
printColumn("yieldpointInsertedForPrologue");
printColumn("yieldpointInsertedForEpilogue");
printColumn("yieldpointInsertedForBackedge");
printColumn("yieldpointInsertedForBaseline");
}
......@@ -119,7 +132,8 @@ public class YieldpointStatistics {
printColumn(yieldpointTurnedOnLatency);
printColumn(allThreadBlockedLatency);
printColumn(mutatorTimeWithoutBlockingCost);
printColumn(maxMethodsPatched);
printColumn(maxYieldpointsPatched);
printColumn(patchingCost);
if (ENABLE_YP_COUNT) {
printColumn(yieldpointTaken.peek());
printColumn(AOSDatabase.yieldpointCounterData.reportPrologueYieldpoints());
......@@ -130,6 +144,7 @@ public class YieldpointStatistics {
printColumn(AOSDatabase.yieldpointCounterData.reportJNIYieldpoints());
printColumn(AOSDatabase.yieldpointCounterData.reportTrapYieldpoints());
printColumn((double)yieldpointOptInsertedForPrologue);
printColumn((double)yieldpointOptInsertedForEpilogue);
printColumn((double)yieldpointOptInsertedForBackedge);
printColumn((double)yieldpointBaselineInserted);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment