From 968d4cca4194b4e499211b76e69d8796f9131c3e Mon Sep 17 00:00:00 2001 From: Carl Ritson Date: Wed, 27 Jul 2016 16:01:14 +0100 Subject: [PATCH] Archive various pieces of test code. --- MMTk/src/org/mmtk/plan/Plan.java | 10 ++++- .../mmtk/plan/otfsapphire/OTFSapphire.java | 17 +++++++- .../otfsapphire/OTFSapphireConstraints.java | 2 +- .../plan/otfsapphire/OTFSapphireMutator.java | 12 ++++++ .../src/org/mmtk/utility/options/Options.java | 1 + tools/bootImageRunner/sys.C | 41 +++++++++++++------ 6 files changed, 67 insertions(+), 16 deletions(-) diff --git a/MMTk/src/org/mmtk/plan/Plan.java b/MMTk/src/org/mmtk/plan/Plan.java index fa5ed387c..a9f556242 100644 --- a/MMTk/src/org/mmtk/plan/Plan.java +++ b/MMTk/src/org/mmtk/plan/Plan.java @@ -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(); @@ -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(); @@ -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()< getTotalPages(); + boolean heapFull; + if (stwTrigger > 0) { + heapFull = getPagesReserved() > stwTrigger; + } else { + heapFull = getPagesReserved() > getTotalPages(); + } return spaceFull || stressForceGC || heapFull; } diff --git a/MMTk/src/org/mmtk/plan/otfsapphire/OTFSapphire.java b/MMTk/src/org/mmtk/plan/otfsapphire/OTFSapphire.java index 3d4131129..8e6040cd2 100644 --- a/MMTk/src/org/mmtk/plan/otfsapphire/OTFSapphire.java +++ b/MMTk/src/org/mmtk/plan/otfsapphire/OTFSapphire.java @@ -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; @@ -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; @@ -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(); @@ -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() { @@ -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(); + } } /** @@ -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"); diff --git a/MMTk/src/org/mmtk/plan/otfsapphire/OTFSapphireConstraints.java b/MMTk/src/org/mmtk/plan/otfsapphire/OTFSapphireConstraints.java index b06e7c0ad..e04b9745b 100644 --- a/MMTk/src/org/mmtk/plan/otfsapphire/OTFSapphireConstraints.java +++ b/MMTk/src/org/mmtk/plan/otfsapphire/OTFSapphireConstraints.java @@ -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 diff --git a/MMTk/src/org/mmtk/plan/otfsapphire/OTFSapphireMutator.java b/MMTk/src/org/mmtk/plan/otfsapphire/OTFSapphireMutator.java index 4365936a0..553c76369 100644 --- a/MMTk/src/org/mmtk/plan/otfsapphire/OTFSapphireMutator.java +++ b/MMTk/src/org/mmtk/plan/otfsapphire/OTFSapphireMutator.java @@ -117,6 +117,9 @@ final void setupBarrier() { protected ReplicatingSpace fromSpace; private Address fromSpaceReplica = Address.zero(); + private boolean inGC = false; + private int allocInGC = 0; + /**************************************************************************** * * Initialization @@ -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 @@ -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; } @@ -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; } diff --git a/MMTk/src/org/mmtk/utility/options/Options.java b/MMTk/src/org/mmtk/utility/options/Options.java index e6349d0cc..997dda134 100644 --- a/MMTk/src/org/mmtk/utility/options/Options.java +++ b/MMTk/src/org/mmtk/utility/options/Options.java @@ -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; diff --git a/tools/bootImageRunner/sys.C b/tools/bootImageRunner/sys.C index 7e1bd11ff..493077d4c 100644 --- a/tools/bootImageRunner/sys.C +++ b/tools/bootImageRunner/sys.C @@ -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 @@ -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; @@ -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)) { @@ -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); @@ -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)) { @@ -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 @@ -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 } @@ -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)) { @@ -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) { @@ -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