* The main C method packs up the arguments into a string array
* and passes it to the java main method. */
- private void outputMainMethod(PrintWriter outmethod) {
+ protected void outputMainMethod(PrintWriter outmethod) {
outmethod.println("int main(int argc, const char *argv[]) {");
outmethod.println(" int i;");
outmethod.println("#include \"localobjects.h\"");
}
if(state.MULTICORE) {
- outmethod.println("#include \"task.h\"");
+ if(state.TASK) {
+ outmethod.println("#include \"task.h\"");
+ }
outmethod.println("#include \"multicoreruntime.h\"");
outmethod.println("#include \"runtime_arch.h\"");
}
outclassdefs.println(" void * lockentry;");
outclassdefs.println(" int lockcount;");
}
+ if(state.MGC) {
+ outclassdefs.println(" int mutex;");
+ outclassdefs.println(" int objlock;");
+ if(state.MULTICOREGC) {
+ outclassdefs.println(" int marked;");
+ }
+ }
if (state.TASK) {
outclassdefs.println(" int flag;");
if(!state.MULTICORE) {
classdefout.println(" void * lockentry;");
classdefout.println(" int lockcount;");
}
-
+ if(state.MGC) {
+ classdefout.println(" int mutex;");
+ classdefout.println(" int objlock;");
+ if(state.MULTICOREGC) {
+ classdefout.println(" int marked;");
+ }
+ }
if (state.TASK) {
classdefout.println(" int flag;");
if((!state.MULTICORE) || (cn.getSymbol().equals("TagDescriptor"))) {
--- /dev/null
+package IR.Flat;
+
+import java.io.FileOutputStream;
+import java.io.PrintWriter;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.Queue;
+import java.util.Set;
+import java.util.Vector;
+
+import Analysis.Locality.LocalityBinding;
+import Analysis.Scheduling.Schedule;
+import Analysis.TaskStateAnalysis.FEdge;
+import Analysis.TaskStateAnalysis.FlagState;
+import Analysis.TaskStateAnalysis.SafetyAnalysis;
+import Analysis.OwnershipAnalysis.AllocationSite;
+import Analysis.OwnershipAnalysis.OwnershipAnalysis;
+import Analysis.OwnershipAnalysis.HeapRegionNode;
+import Analysis.Prefetch.*;
+import IR.ClassDescriptor;
+import IR.Descriptor;
+import IR.FlagDescriptor;
+import IR.MethodDescriptor;
+import IR.State;
+import IR.TagVarDescriptor;
+import IR.TaskDescriptor;
+import IR.TypeDescriptor;
+import IR.TypeUtil;
+import IR.VarDescriptor;
+import IR.Tree.DNFFlag;
+import IR.Tree.DNFFlagAtom;
+import IR.Tree.FlagExpressionNode;
+import IR.Tree.TagExpressionList;
+
+public class BuildCodeMGC extends BuildCode {
+ int coreNum;
+ int tcoreNum;
+ int gcoreNum;
+ int startupcorenum; // record the core containing startup task, s
+ // uppose only one core can have startup object
+
+ public BuildCodeMGC(State st,
+ Hashtable temptovar,
+ TypeUtil typeutil,
+ SafetyAnalysis sa,
+ int coreNum,
+ int tcoreNum,
+ int gcoreNum,
+ PrefetchAnalysis pa) {
+ super(st, temptovar, typeutil, sa, pa);
+ this.coreNum = coreNum; // # of the active cores
+ this.tcoreNum = tcoreNum; // # of the total number of cores
+ this.gcoreNum = gcoreNum; // # of the cores for gc if any
+ this.startupcorenum = 0;
+ }
+
+ public void buildCode() {
+ /* Create output streams to write to */
+ PrintWriter outclassdefs=null;
+ PrintWriter outstructs=null;
+ PrintWriter outmethodheader=null;
+ PrintWriter outmethod=null;
+ PrintWriter outvirtual=null;
+
+ try {
+ outstructs=new PrintWriter(new FileOutputStream(PREFIX+"structdefs.h"), true);
+ outmethodheader=new PrintWriter(new FileOutputStream(PREFIX+"methodheaders.h"), true);
+ outclassdefs=new PrintWriter(new FileOutputStream(PREFIX+"classdefs.h"), true);
+ outvirtual=new PrintWriter(new FileOutputStream(PREFIX+"virtualtable.h"), true);
+ outmethod=new PrintWriter(new FileOutputStream(PREFIX+"methods.c"), true);
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.exit(-1);
+ }
+
+ /* Build the virtual dispatch tables */
+ super.buildVirtualTables(outvirtual);
+
+ /* Output includes */
+ outmethodheader.println("#ifndef METHODHEADERS_H");
+ outmethodheader.println("#define METHODHEADERS_H");
+ outmethodheader.println("#include \"structdefs.h\"");
+
+ /* Output Structures */
+ super.outputStructs(outstructs);
+
+ // Output the C class declarations
+ // These could mutually reference each other
+ super.outputClassDeclarations(outclassdefs);
+
+ // Output function prototypes and structures for parameters
+ Iterator it=state.getClassSymbolTable().getDescriptorsIterator();
+ int numclasses = this.state.numClasses();
+ while(it.hasNext()) {
+ ClassDescriptor cn=(ClassDescriptor)it.next();
+ super.generateCallStructs(cn, outclassdefs, outstructs, outmethodheader);
+ }
+ outclassdefs.close();
+
+ /* Build the actual methods */
+ super.outputMethods(outmethod);
+
+ /* Record maximum number of task parameters */
+ //outstructs.println("#define MAXTASKPARAMS "+maxtaskparams);
+ /* Record maximum number of all types, i.e. length of classsize[] */
+ outstructs.println("#define NUMTYPES "+(state.numClasses() + state.numArrays()));
+ /* Record number of total cores */
+ outstructs.println("#define NUMCORES "+this.tcoreNum);
+ /* Record number of active cores */
+ outstructs.println("#define NUMCORESACTIVE "+this.coreNum); // this.coreNum
+ // can be reset by the scheduling analysis
+ /* Record number of garbage collection cores */
+ outstructs.println("#ifdef MULTICORE_GC");
+ outstructs.println("#define NUMCORES4GC "+this.gcoreNum);
+ outstructs.println("#endif");
+ /* Record number of core containing startup task */
+ outstructs.println("#define STARTUPCORE "+this.startupcorenum);
+
+ if (state.main!=null) {
+ /* Generate main method */
+ outputMainMethod(outmethod);
+ }
+
+ /* Close files */
+ outmethodheader.println("#endif");
+ outmethodheader.close();
+ outmethod.close();
+ outstructs.println("#endif");
+ outstructs.close();
+ }
+
+ protected void outputMainMethod(PrintWriter outmethod) {
+ outmethod.println("int mgc_main(int argc, const char *argv[]) {");
+ outmethod.println(" int i;");
+
+ if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
+ outmethod.println(" struct ArrayObject * stringarray=allocate_newarray(NULL, STRINGARRAYTYPE, argc-1);");
+ } else {
+ outmethod.println(" struct ArrayObject * stringarray=allocate_newarray(STRINGARRAYTYPE, argc-1);");
+ }
+ outmethod.println(" for(i=1;i<argc;i++) {");
+ outmethod.println(" int length=strlen(argv[i]);");
+ if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
+ outmethod.println(" struct ___String___ *newstring=NewString(NULL, argv[i], length);");
+ } else {
+ outmethod.println(" struct ___String___ *newstring=NewString(argv[i], length);");
+ }
+ outmethod.println(" ((void **)(((char *)& stringarray->___length___)+sizeof(int)))[i-1]=newstring;");
+ outmethod.println(" }");
+
+ MethodDescriptor md=typeutil.getMain();
+ ClassDescriptor cd=typeutil.getMainClass();
+
+ outmethod.println(" {");
+ if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
+ outmethod.print(" struct "+cd.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params __parameterlist__={");
+ outmethod.println("1, NULL,"+"stringarray};");
+ outmethod.println(" "+cd.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"(& __parameterlist__);");
+ } else {
+ outmethod.println(" "+cd.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"(stringarray);");
+ }
+ outmethod.println(" }");
+
+ outmethod.println("}");
+ }
+}
outstructs.println("#define NUMCORESACTIVE "+this.coreNum); // this.coreNum
// can be reset by the scheduling analysis
/* Record number of garbage collection cores */
- outtask.println("#ifdef MULTICORE_GC");
+ outstructs.println("#ifdef MULTICORE_GC");
outstructs.println("#define NUMCORES4GC "+this.gcoreNum);
- outtask.println("#endif");
+ outstructs.println("#endif");
/* Record number of core containing startup task */
outstructs.println("#define STARTUPCORE "+this.startupcorenum);
} //else if (state.main!=null) {
public int CORENUM4GC = 0;
public String profilename = null;
public String outputdir = "/scratch/";
+ // MGC options
+ public boolean MGC=false;
+
//Other options
public String structfile;
public String main;
import IR.Tree.BuildIR;
import IR.Tree.SemanticCheck;
import IR.Flat.BuildCodeMultiCore;
+import IR.Flat.BuildCodeMGC;
import IR.Flat.BuildFlat;
import IR.Flat.BuildCode;
import IR.Flat.Inliner;
state.MULTICORE=true;
else if (option.equals("-multicoregc"))
state.MULTICOREGC=true;
+ else if (option.equals("-mgc"))
+ state.MGC = true;
else if (option.equals("-ownership"))
state.OWNERSHIP=true;
else if (option.equals("-ownallocdepth")) {
CallGraph callGraph = new CallGraph(state);
Liveness liveness = new Liveness();
ArrayReferencees ar = new ArrayReferencees(state);
- OwnershipAnalysis oa = new OwnershipAnalysis(state,
+ OwnershipAnalysis oa = null;/*new OwnershipAnalysis(state,
tu,
callGraph,
liveness,
state.OWNERSHIPALLOCDEPTH,
state.OWNERSHIPWRITEDOTS,
state.OWNERSHIPWRITEALL,
- state.OWNERSHIPALIASFILE);
+ state.OWNERSHIPALIASFILE);*/
// synthesis a layout according to target multicore processor
MCImplSynthesis mcImplSynthesis = new MCImplSynthesis(state,
}
}
}
+
+ if (state.MGC) {
+ // generate multicore codes
+ if(state.MULTICORE) {
+ BuildCodeMGC bcmgc=new BuildCodeMGC(state,
+ bf.getMap(),
+ tu,
+ sa,
+ state.CORENUM,
+ state.CORENUM,
+ state.CORENUM4GC,
+ pa);
+ bcmgc.buildCode();
+ }
+ }
+
if(!state.MULTICORE) {
if (state.DSM||state.SINGLETM) {
CallGraph callgraph=new CallGraph(state);
#ifndef MULTICORE_MEM_H
#define MULTICORE_MEM_H
+#include "Queue.h"
+#include "SimpleHash.h"
#ifndef INTPTR
#ifdef BIT64
#ifdef MULTICORE_GC
volatile bool gc_localheap_s;
-#endif
-
-#ifdef MULTICORE_GC
#include "multicoregarbage.h"
typedef enum {
//volatile mspace bamboo_free_msp;
INTPTR bamboo_free_smemp;
int bamboo_free_smem_size;
-#endif
+#endif // MULTICORE_GC
volatile bool smemflag;
volatile INTPTR bamboo_cur_msp;
volatile int bamboo_smem_size;
#ifndef RAW
#include <stdio.h>
#endif
-#ifdef MGC
-#include "thread.h"
-#endif
#ifndef INLINE
#define INLINE inline __attribute__((always_inline))
#endif // MULTICORE_GC
int debugtask=0;
+#ifdef MGC
+int corenum = 0;
+#endif
int instanceof(struct ___Object___ *ptr, int type) {
int i=ptr->type;
}
void CALL01(___System______printString____L___String___,struct ___String___ * ___s___) {
+#ifdef MGC
+#ifdef TILERA_BME
+ struct ArrayObject * chararray=VAR(___s___)->___value___;
+ int i;
+ int offset=VAR(___s___)->___offset___;
+ tprintf("");
+ for(i=0; i<VAR(___s___)->___count___; i++) {
+ short sc=
+ ((short *)(((char *)&chararray->___length___)+sizeof(int)))[i+offset];
+ printf("%c", sc);
+ }
+ printf("\n");
+#endif // TILERA_BME
+#endif // MGC
}
/* Object allocation function */
struct ___Object___ * v=
(struct ___Object___*)FREEMALLOC((struct garbagelist*) ptr,classsize[type]);
v->type=type;
+#ifdef TASK
v->version = 0;
v->lock = NULL;
v->lockcount = 0;
+#endif
initlock(v);
#ifdef GC_PROFILE
extern unsigned int gc_num_obj;
FREEMALLOC((struct garbagelist*)ptr,
sizeof(struct ArrayObject)+length*classsize[type]);
v->type=type;
+#ifdef TASK
v->version = 0;
v->lock = NULL;
+#endif
if (length<0) {
return NULL;
}
void * allocate_new(int type) {
struct ___Object___ * v=FREEMALLOC(classsize[type]);
v->type=type;
+#ifdef TASK
v->version = 0;
v->lock = NULL;
+#endif
initlock(v);
return v;
}
struct ArrayObject * v=
FREEMALLOC(sizeof(struct ArrayObject)+length*classsize[type]);
v->type=type;
+#ifdef TASK
v->version = 0;
v->lock = NULL;
+#endif
v->___length___=length;
initlock(v);
return v;
#endif
#ifdef MGC
- // TODO
- threadlocks = 0;
-#endif
+ initializethreads();
+ bamboo_current_thread = NULL;
+#endif // MGC
#ifdef TASK
inittaskdata();
}
// main function for each core
-inline void run(void * arg) {
+inline void run(int argc, char** argv) {
int i = 0;
- int argc = 1;
- char ** argv = NULL;
bool sendStall = false;
bool isfirst = true;
bool tocontinue = false;
BAMBOO_DEBUGPRINT(0xee00);
#endif
+#ifdef MGC
+ if(STARTUPCORE == BAMBOO_NUM_OF_CORE) {
+ // run the main method in the specified mainclass
+ mgc_main(argc, argv);
+ }
+#endif
+
while(true) {
#ifdef MULTICORE_GC
// if yes, enqueue them and executetasks again
tocontinue = checkObjQueue();
#elif defined MGC
- // TODO
+ trystartthread();
+ tocontinue = false;
#endif
if(!tocontinue) {
#ifndef MULTICORE_RUNTIME
#define MULTICORE_RUNTIME
#include "structdefs.h"
-#include "Queue.h"
#ifndef INLINE
#define INLINE inline __attribute__((always_inline))
bool reside;
#endif
+#ifdef MGC
+// shared memory pointer for global thread queue
+// In MGC version, this block of memory is located at the very bottom of the
+// shared memory with the base address as BAMBOO_BASE_VA.
+// The bottom of the shared memory = global thread queue + sbstart tbl
+// + smemtbl + NUMCORES4GC bamboo_rmsp
+// This queue is always reside at the bottom of the shared memory. It is
+// considered as runtime structure, during gc, it is scanned for mark and flush
+// phase but never been compacted.
+//
+// This is a loop array and the first 4 int fields of the queue are:
+// mutex + thread counter + start pointer + end pointer
+#ifdef GC_SMALLPAGESIZE
+#define BAMBOO_THREAD_QUEUE_SIZE (1024 * 1024)
+#else
+#define BAMBOO_THREAD_QUEUE_SIZE (BAMBOO_SMEM_SIZE) // (45 * 16 * 1024)
+#endif
+// data structures for threads
+INTPTR * bamboo_thread_queue;
+unsigned int bamboo_max_thread_num_mask;
+INTPTR bamboo_current_thread;
+
+extern int corenum;
+#endif // MGC
+
// data structures for msgs
#define BAMBOO_OUT_BUF_LENGTH 2048
#define BAMBOO_OUT_BUF_MASK (0x7FF)
unsigned long n3,
unsigned long n4,
unsigned long n5);
-INLINE int receiveMsg(uint32_t send_port_pending);
+INLINE int receiveMsg(unsigned int send_port_pending);
#ifdef MULTICORE_GC
INLINE void transferMarkResults();
// BAMBOO_DIE(x): error exit routine with error msg //
// BAMBOO_GET_EXE_TIME(): rountine to get current clock cycle number //
// BAMBOO_MSG_AVAIL(): checking if there are msgs coming in //
-// BAMBOO_GCMSG_AVAIL(): checking if there are gcmsgs coming in //
// BAMBOO_ENTER_RUNTIME_MODE_FROM_CLIENT(): change to runtime mode from //
// client mode //
// BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME(): change to client mode from //
#define CALL35(name, rest, rest2, rest3, alt1, alt2, alt3, alt4, alt5) name(alt1, alt2, alt3, alt4, alt5)
#endif
-#ifdef TASK
+#ifdef MULTICORE
#include "SimpleHash.h"
+inline void run(int argc, char** argv);
+int receiveObject(int send_port_pending);
+void * smemalloc_I(int coren, int size, int * allocsize);
+#ifdef MULTICORE_GC
+inline void setupsmemmode(void);
+#endif
+#endif
+
+#ifdef TASK
#ifndef MULTICORE
#include "chash.h"
#include "ObjectHash.h"
#endif
#ifdef MULTICORE
-inline void run(void * arg);
-#ifdef MULTICORE_GC
-inline void setupsmemmode(void);
-#endif
-int receiveObject(int send_port_pending);
void flagorand(void * ptr, int ormask, int andmask, struct parameterwrapper ** queues, int length);
void flagorandinit(void * ptr, int ormask, int andmask);
void enqueueObject(void * ptr, struct parameterwrapper ** queues,int length);
#endif
int * getAliasLock(void ** ptrs, int length, struct RuntimeHash * tbl);
void addAliasLock(void * ptr, int lock);
-void * smemalloc_I(int coren, int size, int * allocsize);
#else
void flagorand(void * ptr, int ormask, int andmask);
void flagorandinit(void * ptr, int ormask, int andmask);
elif [[ $1 = '-mgc' ]]
then
MGCFLAG=true
+JAVAOPTS="$JAVAOPTS -mgc"
elif [[ $1 = '-dmalloc' ]]
then
USEDMALLOC=true
then
#threading java stuff
JAVAOPTS="$JAVAOPTS -classlibrary $ROBUSTROOT/ClassLibrary/JavaThread"
+elif $MGCFLAG
+then
+#base multicore gc files
+JAVAOPTS="$JAVAOPTS -classlibrary $ROBUSTROOT/ClassLibrary/MGC"
fi
#base java stuff
JAVAOPTS="$JAVAOPTS -classlibrary $ROBUSTROOT/ClassLibrary/Java"
make clean
rm ./*
+if $MGCFLAG
+then
+export TILERACFLAGS="-DMULTICORE -DCLOSE_PRINT -DTILERA"
+else
export TILERACFLAGS="-DTASK -DMULTICORE -DCLOSE_PRINT -DTILERA"
+fi
if $TILERAMEMPROFFLAG
then # not only with 1 core
TILERACFLAGS="${TILERACFLAGS} -DGC_CACHE_SAMPLING"
fi
+if $MGCFLAG
+then
+cp $ROBUSTROOT/Tilera/Runtime/MGC/$MAKEFILE ./Makefile
+else
cp $ROBUSTROOT/Tilera/Runtime/$TILERA_INDIR/$MAKEFILE ./Makefile
+fi
if $TILERABMEFLAG
then # TILERABMEFLAG
cp $ROBUSTROOT/Tilera/Runtime/$TILERA_INDIR/$SIMHVC ./sim.hvc
cp ../Runtime/Queue.c ./
cp ../Runtime/file.c ./
cp ../Runtime/math.c ./
+if [ !$MGCFLAG ]
+then
cp ../Runtime/object.c ./
+fi
cp ../Runtime/GenericHashtable.c ./
cp ../Runtime/SimpleHash.c ./
cp ../Runtime/ObjectHash.c ./
cp ../Runtime/mem.c ./
cp ../Runtime/GenericHashtable.h ./
cp ../Runtime/mem.h ./
+if [ !$MGCFLAG ]
+then
cp ../Runtime/object.h ./
+fi
cp ../Runtime/ObjectHash.h ./
cp ../Runtime/Queue.h ./
cp ../Runtime/runtime.h ./
#then # TILERAMEMPROFFLAG
cp ../Tilera/Runtime/$TILERA_INDIR/linux_client.c ./
#fi
+if $MGCFLAG
+then
+cp ../Tilera/Runtime/MGC/*.c ./
+cp ../Tilera/Runtime/MGC/*.h ./
+fi
cp ../Tilera/lib/* ./
cp ../$tmpbuilddirectory/*.c ./
cp ../$tmpbuilddirectory/*.h ./