Skip to content

Commit

Permalink
Archive various pieces of test code.
Browse files Browse the repository at this point in the history
  • Loading branch information
perlfu committed Jul 27, 2016
1 parent 7d2190a commit 968d4cc
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 16 deletions.
10 changes: 9 additions & 1 deletion MMTk/src/org/mmtk/plan/Plan.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public abstract class Plan implements Constants {
public static final LargeObjectSpace largeCodeSpace = USE_CODE_SPACE ? new LargeObjectSpace("lg-code", VMRequest.discontiguous()) : null;

public static int pretenureThreshold = Integer.MAX_VALUE;
public static int stwTrigger = 0;

/* Space descriptors */
public static final int IMMORTAL = immortalSpace.getDescriptor();
Expand Down Expand Up @@ -174,6 +175,7 @@ public Plan() {
Options.variableSizeHeap = new VariableSizeHeap();
Options.eagerMmapSpaces = new EagerMmapSpaces();
Options.sanityCheck = new SanityCheck();
Options.stwTrigger = new STWTrigger();
Options.debugAddress = new DebugAddress();
Options.perfEvents = new PerfEvents();
Options.useReturnBarrier = new UseReturnBarrier();
Expand Down Expand Up @@ -232,6 +234,7 @@ public void processOptions() {
if (Options.verbose.getValue() > 0) Stats.startAll();
if (Options.eagerMmapSpaces.getValue()) Space.eagerlyMmapMMTkSpaces();
pretenureThreshold = (int) ((Options.nurserySize.getMaxNursery()<<LOG_BYTES_IN_PAGE) * Options.pretenureThresholdFraction.getValue());
stwTrigger = Options.stwTrigger.getValue();
}

/**
Expand Down Expand Up @@ -940,7 +943,12 @@ protected void logPoll(Space space, String message) {
*/
protected boolean collectionRequired(boolean spaceFull, Space space) {
boolean stressForceGC = stressTestGCRequired();
boolean heapFull = getPagesReserved() > getTotalPages();
boolean heapFull;
if (stwTrigger > 0) {
heapFull = getPagesReserved() > stwTrigger;
} else {
heapFull = getPagesReserved() > getTotalPages();
}

return spaceFull || stressForceGC || heapFull;
}
Expand Down
17 changes: 16 additions & 1 deletion MMTk/src/org/mmtk/plan/otfsapphire/OTFSapphire.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.mmtk.policy.Space;
import org.mmtk.plan.*;
import org.mmtk.plan.onthefly.OnTheFly;
import org.mmtk.utility.Conversions;
import org.mmtk.utility.Log;
import org.mmtk.utility.alloc.Allocator;
import org.mmtk.utility.alloc.BumpPointer;
Expand Down Expand Up @@ -487,6 +488,7 @@ public void scan(ObjectReference object, boolean live, Address cellAddress, Exte
public OTFSapphireCopyScan copyScan;
private int concurrentTriggerMethod;
private int concurrentTrigger;
private int stwTrigger = 0;
private int lastCollectionUsedPages = 0;
private long lastCollectionStartTime = 0;
private long lastCollectionCompleteTime = 0;
Expand Down Expand Up @@ -724,6 +726,7 @@ public void collectionPhase(short phaseId) {

if (phaseId == RELEASE_FLIP) {
if (VM.VERIFY_ASSERTIONS) assert_TO_SPLACE_LOCAL_IS_EMPTY = true;
printHeapUsage();
low = !low; // flip the semi-spaces
toSpace().release();
OTFSapphire.tackOnLock.acquire();
Expand Down Expand Up @@ -754,6 +757,13 @@ public void collectionPhase(short phaseId) {
super.collectionPhase(phaseId);
}

protected void printHeapUsage() {
Log.write("->"); Log.write(Conversions.pagesToKBytes(getPagesUsed())); Log.write(" KB");
Log.write(" (From = "); Log.write(Conversions.pagesToKBytes(fromSpace().reservedPages()));
Log.write(" KB To = "); Log.write(Conversions.pagesToKBytes(toSpace().reservedPages()));
Log.write(" KB Other = "); Log.write(Conversions.pagesToKBytes(super.getPagesUsed())); Log.write(" KB) ");
}

@Override
@Inline
protected boolean collectorHasWork() {
Expand Down Expand Up @@ -789,7 +799,11 @@ protected int getWeakReferenceTerminationLoopPhase() {
*/
public final int getCollectionReserve() {
// our copy reserve is the size of fromSpace less any copying we have done so far
return fromSpace().reservedPages() + super.getCollectionReserve();
if (stwTrigger == 0) {
return (fromSpace().reservedPages() - toSpace().reservedPages()) + super.getCollectionReserve();
} else {
return super.getCollectionReserve();
}
}

/**
Expand Down Expand Up @@ -1013,6 +1027,7 @@ public void processOptions() {
copyScanSTW = new OTFSapphireCopyScan.CopyScanUnsafe2(flipRootTrace);
concurrentTriggerMethod = Options.concurrentTriggerMethod.method();
concurrentTrigger = Options.concurrentTrigger.getValueForMethod(concurrentTriggerMethod);
stwTrigger = Options.stwTrigger.getValue();

if (MERGE_REPLICATE_PHASE) Log.writeln("Option: MERGE_REPLICATE_PHASE");
if (REPLICATE_WITH_CAS) Log.writeln("Option: REPLICATE_WITH_CAS");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public int gcHeaderWords() {
public int numSpecializedScans() { return 0; }

@Override
public int maxNonLOSDefaultAllocBytes() { return !OTFSapphire.NO_LOS ? BYTES_IN_PAGE : org.mmtk.utility.Constants.MAX_INT; }
public int maxNonLOSDefaultAllocBytes() { return !OTFSapphire.NO_LOS ? BYTES_IN_PAGE * 32: org.mmtk.utility.Constants.MAX_INT; }

// LPJH: later implement bulkCopy support

Expand Down
12 changes: 12 additions & 0 deletions MMTk/src/org/mmtk/plan/otfsapphire/OTFSapphireMutator.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ final void setupBarrier() {
protected ReplicatingSpace fromSpace;
private Address fromSpaceReplica = Address.zero();

private boolean inGC = false;
private int allocInGC = 0;

/****************************************************************************
*
* Initialization
Expand Down Expand Up @@ -239,6 +242,8 @@ public int checkAllocator(int bytes, int align, int allocator) {
@Inline
public Address alloc(int bytes, int align, int offset, int allocator, int site) {
Address addy;
if (inGC)
allocInGC += bytes;
if (VM.VERIFY_ASSERTIONS) VM.assertions._assert(fromSpaceReplica.isZero());
if (allocator == OTFSapphire.ALLOC_REPLICATING) {
addy = fromSpaceLocal.alloc(bytes, align, offset); // may cause GC
Expand Down Expand Up @@ -427,6 +432,8 @@ public void collectionPhase(short phaseId, boolean primary) {
if (!prepared)
super.collectionPhase(Simple.PREPARE, primary);
prepared = false;
allocInGC = 0;
inGC = true;
return;
}

Expand Down Expand Up @@ -578,6 +585,11 @@ public void collectionPhase(short phaseId, boolean primary) {
setupBarrier();
if (VM.VERIFY_ASSERTIONS) VM.assertions._assert(!barrierEnable());
super.collectionPhase(Simple.RELEASE, primary);
inGC = false;
if (allocInGC > 0) {
Log.writeln("allocInGC ", allocInGC);
allocInGC = 0;
}
return;
}

Expand Down
1 change: 1 addition & 0 deletions MMTk/src/org/mmtk/utility/options/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public final class Options {
public static SanityCheck sanityCheck;
public static SapphireSTWPhase sapphireSTWPhase;
public static StressFactor stressFactor;
public static STWTrigger stwTrigger;
public static Threads threads;
public static TraceRate traceRate;
public static UseReturnBarrier useReturnBarrier;
Expand Down
41 changes: 28 additions & 13 deletions tools/bootImageRunner/sys.C
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ extern "C" void sysMonitorTimedWait(Word, long long);
extern "C" void sysMonitorWait(Word);
extern "C" void sysMonitorBroadcast(Word);

static void* checkMalloc(int);
static void checkFree(void*);

// #define DEBUG_SYS
// #define DEBUG_THREAD

Expand Down Expand Up @@ -1026,7 +1029,7 @@ sysThreadCreate(Address tr, Address ip, Address fp)

// create arguments
//
sysThreadArguments = new Address[3];
sysThreadArguments = (Address*) checkMalloc(sizeof(Address) * 3);
sysThreadArguments[0] = tr;
sysThreadArguments[1] = ip;
sysThreadArguments[2] = fp;
Expand Down Expand Up @@ -1134,7 +1137,7 @@ sysThreadStartup(void *args)
char *stackBuf;

memset (&stack, 0, sizeof stack);
stack.ss_sp = stackBuf = new char[SIGSTKSZ];
stack.ss_sp = stackBuf = (char*) checkMalloc(sizeof(char) * SIGSTKSZ);
stack.ss_flags = 0;
stack.ss_size = SIGSTKSZ;
if (sigaltstack (&stack, 0)) {
Expand All @@ -1144,18 +1147,18 @@ sysThreadStartup(void *args)

Address tr = ((Address *)args)[0];

jmp_buf *jb = (jmp_buf*)malloc(sizeof(jmp_buf));
jmp_buf *jb = (jmp_buf*)checkMalloc(sizeof(jmp_buf));
if (setjmp(*jb)) {
// this is where we come to terminate the thread
#ifdef RVM_FOR_HARMONY
hythread_detach(NULL);
#endif
free(jb);
checkFree(jb);
*(int*)(tr + RVMThread_execStatus_offset) = RVMThread_TERMINATED;

stack.ss_flags = SS_DISABLE;
sigaltstack(&stack, 0);
delete[] stackBuf;
checkFree(stackBuf);
} else {
setThreadLocal(TerminateJmpBufKey, (void*)jb);

Expand Down Expand Up @@ -1242,7 +1245,7 @@ sysSetupHardwareTrapHandler()
stack_t stack;

memset (&stack, 0, sizeof stack);
stack.ss_sp = new char[SIGSTKSZ];
stack.ss_sp = (char*) checkMalloc(sizeof(char) * SIGSTKSZ);

stack.ss_size = SIGSTKSZ;
if (sigaltstack (&stack, 0)) {
Expand Down Expand Up @@ -1417,7 +1420,7 @@ sysMonitorCreate()
hythread_monitor_t monitor;
hythread_monitor_init_with_name(&monitor, 0, NULL);
#else
vmmonitor_t *monitor = new vmmonitor_t;
vmmonitor_t *monitor = (vmmonitor_t*) checkMalloc(sizeof(vmmonitor_t));
pthread_mutex_init(&monitor->mutex, NULL);
pthread_cond_init(&monitor->cond, NULL);
#endif
Expand All @@ -1433,7 +1436,7 @@ sysMonitorDestroy(Word _monitor)
vmmonitor_t *monitor = (vmmonitor_t*)_monitor;
pthread_mutex_destroy(&monitor->mutex);
pthread_cond_destroy(&monitor->cond);
delete monitor;
checkFree(monitor);
#endif
}

Expand Down Expand Up @@ -1732,10 +1735,8 @@ sysMemmove(void *dst, const void *src, Extent cnt)

int inRVMAddressSpace(Address a);

// Allocate memory.
//
extern "C" void *
sysMalloc(int length)
static void*
checkMalloc(int length)
{
void *result=malloc(length);
if (inRVMAddressSpace((Address)result)) {
Expand All @@ -1744,6 +1745,20 @@ sysMalloc(int length)
return result;
}

static void
checkFree(void* mem)
{
free(mem);
}

// Allocate memory.
//
extern "C" void *
sysMalloc(int length)
{
return checkMalloc(length);
}

extern "C" void *
sysCalloc(int length)
{
Expand All @@ -1755,7 +1770,7 @@ sysCalloc(int length)
extern "C" void
sysFree(void *location)
{
free(location);
checkFree(location);
}

// Zero a range of memory with non-temporal instructions on x86
Expand Down

0 comments on commit 968d4cc

Please sign in to comment.