// associate locks with parameters
int lockindex = 0;
for(int i = 0; i < this.m_aliasSets.size(); i++) {
- Vector<Integer> toadd = this.m_aliasSets.elementAt(i);
-
- output.print("int tmplen_" + lockindex + " = 0;");
- output.println("void * tmpptrs_" + lockindex + "[] = {");
- for(int j = 0; j < toadd.size(); j++) {
- int para = toadd.elementAt(j).intValue();
- output.print(super.generateTemp(fm, fm.getParameter(para), lb));
- if(j < toadd.size() - 1) {
- output.print(", ");
- } else {
- output.println("};");
- }
- }
- output.println("aliaslocks[tmpi++] = getAliasLock(tmpptrs_" + lockindex + ", tmplen_" + lockindex + ", lockRedirectTbl);");
-
- for(int j = 0; j < toadd.size(); j++) {
- int para = toadd.elementAt(j).intValue();
- output.println("addAliasLock(" + super.generateTemp(fm, fm.getParameter(para), lb) + ", aliaslocks[" + i + "]);");
- }
- // check if this lock is also associated with any FlatNew nodes
- if(this.m_aliasFNTbl4Para.containsKey(toadd.elementAt(0))) {
- if(this.m_aliaslocksTbl4FN == null) {
- this.m_aliaslocksTbl4FN = new Hashtable<FlatNew, Vector<Integer>>();
- }
- Vector<FlatNew> tmpv = this.m_aliasFNTbl4Para.get(toadd.elementAt(0));
- for(int j = 0; j < tmpv.size(); j++) {
- FlatNew fn = tmpv.elementAt(j);
- if(!this.m_aliaslocksTbl4FN.containsKey(fn)) {
- this.m_aliaslocksTbl4FN.put(fn, new Vector<Integer>());
- }
- this.m_aliaslocksTbl4FN.get(fn).add(i);
- }
- this.m_aliasFNTbl4Para.remove(toadd.elementAt(0));
- }
- lockindex++;
+ Vector<Integer> toadd = this.m_aliasSets.elementAt(i);
+
+ output.println("int tmplen_" + lockindex + " = " + toadd.size());
+ output.println("void * tmpptrs_" + lockindex + "[] = {");
+ for(int j = 0; j < toadd.size(); j++) {
+ int para = toadd.elementAt(j).intValue();
+ output.print(super.generateTemp(fm, fm.getParameter(para), lb));
+ if(j < toadd.size() - 1) {
+ output.print(", ");
+ } else {
+ output.println("};");
+ }
+ }
+ output.println("aliaslocks[tmpi++] = getAliasLock(tmpptrs_" + lockindex + ", tmplen_" + lockindex + ", lockRedirectTbl);");
+
+ for(int j = 0; j < toadd.size(); j++) {
+ int para = toadd.elementAt(j).intValue();
+ output.println("addAliasLock(" + super.generateTemp(fm, fm.getParameter(para), lb) + ", aliaslocks[" + i + "]);");
+ }
+ // check if this lock is also associated with any FlatNew nodes
+ if(this.m_aliasFNTbl4Para.containsKey(toadd.elementAt(0))) {
+ if(this.m_aliaslocksTbl4FN == null) {
+ this.m_aliaslocksTbl4FN = new Hashtable<FlatNew, Vector<Integer>>();
+ }
+ Vector<FlatNew> tmpv = this.m_aliasFNTbl4Para.get(toadd.elementAt(0));
+ for(int j = 0; j < tmpv.size(); j++) {
+ FlatNew fn = tmpv.elementAt(j);
+ if(!this.m_aliaslocksTbl4FN.containsKey(fn)) {
+ this.m_aliaslocksTbl4FN.put(fn, new Vector<Integer>());
+ }
+ this.m_aliaslocksTbl4FN.get(fn).add(i);
+ }
+ this.m_aliasFNTbl4Para.remove(toadd.elementAt(0));
+ }
+ lockindex++;
}
Object[] key = this.m_aliasFNTbl4Para.keySet().toArray();
BAMBOO_DEBUGPRINT_REG((int)obj);
// grab lock and flush the obj
grount = 0;
- getwritelock_I(obj);
+ struct ___Object___ * tmpobj = (struct ___Object___ *)obj;
+ while(tmpobj->lock != NULL) {
+ tmpobj = (struct ___Object___ *)(tmpobj->lock);
+ }
+ getwritelock_I(tmpobj);
while(!lockflag) {
BAMBOO_WAITING_FOR_LOCK(0);
} // while(!lockflag)
enqueueObject_I(obj, queues, 1);
BAMBOO_DEBUGPRINT_REG(hashsize(activetasks));
} // for(k = 0; k < objInfo->length; ++k)
- releasewritelock_I(obj);
+ releasewritelock_I(tmpobj);
RUNFREE(objInfo->queues);
RUNFREE(objInfo);
} else {
int * getAliasLock(void ** ptrs,
int length,
struct RuntimeHash * tbl) {
+#ifdef TILERA_BME
+ int i = 0;
+ int locks[length];
+ int locklen = 0;
+ // sort all the locks required by the objs in the aliased set
+ for(; i < length; i++) {
+ struct ___Object___ * ptr = (struct ___Object___ *)(ptrs[i]);
+ int lock = 0;
+ int j = 0;
+ if(ptr->lock == NULL) {
+ lock = (int)(ptr);
+ } else {
+ lock = (int)(ptr->lock);
+ }
+ bool insert = true;
+ for(j = 0; j < locklen; j++) {
+ if(locks[j] == lock) {
+ insert = false;
+ break;
+ } else if(locks[j] > lock) {
+ break;
+ }
+ }
+ if(insert) {
+ int h = locklen;
+ for(; h > j; h--) {
+ locks[h] = locks[h-1];
+ }
+ locks[j] = lock;
+ locklen++;
+ }
+ }
+ // use the smallest lock as the shared lock for the whole set
+ return (int *)(locks[0]);
+#else // TILERA_BME
+ // TODO possible bug here!!!
if(length == 0) {
return (int*)(RUNMALLOC(sizeof(int)));
} else {
if(redirect) {
return (int *)redirectlock;
} else {
+ // use the first lock as the shared lock
+ for(j = 1; j < locklen; j++) {
+ if(locks[j] != locks[0]) {
+ RuntimeHashadd(tbl, locks[j], locks[0]);
+ }
+ }
return (int *)(locks[0]);
}
}
+#endif // TILERA_BME
}
void addAliasLock(void * ptr,
if(((int)ptr != lock) && (obj->lock != (int*)lock)) {
// originally no alias lock associated or have a different alias lock
// flush it as the new one
+#ifdef TILERA_BME
+ while(obj->lock != NULL) {
+ // previously have alias lock, trace the 'root' obj and redirect it
+ obj = (struct ___Object___ *)(obj->lock);
+ }
+#endif // TILERA_BME
obj->lock = (int *)lock;
}
}
taskpointerarray[i+OFFSET]=param;
goto execute;
}
- if(((struct ___Object___ *)param)->lock == NULL) {
+ /*if(((struct ___Object___ *)param)->lock == NULL) {
tmplock = (int)param;
} else {
- tmplock = (int)(((struct ___Object___ *)param)->lock);
- }
+ struct ___Object___ * obj = (struct ___Object___ *)param;
+ while(obj->lock != NULL) {
+ obj = (struct ___Object___ *)(obj->lock);
+ }
+ tmplock = (int)(obj);
+ }*/
+ struct ___Object___ * obj = (struct ___Object___ *)param;
+ while(obj->lock != NULL) {
+ obj = (struct ___Object___ *)(obj->lock);
+ }
+ tmplock = (int)(obj);
// insert into the locks array
for(j = 0; j < runtime_locklen; j++) {
if(runtime_locks[j].value == tmplock) {
BAMBOO_DEBUGPRINT(0xe991);
for(i = 0; i < runtime_locklen; i++) {
- int * lock = (int *)(runtime_locks[i].redirectlock);
+ int * lock = (int *)(runtime_locks[i].value);//(runtime_locks[i].redirectlock);
islock = true;
// require locks for this parameter if it is not a startup object
BAMBOO_DEBUGPRINT_REG((int)lock);
// can not get the lock, try later
// release all grabbed locks for previous parameters
for(j = 0; j < i; ++j) {
- lock = (int*)(runtime_locks[j].redirectlock);
+ lock = (int*)(runtime_locks[j].value/*redirectlock*/);
releasewritelock(lock);
}
genputtable(activetasks, currtpd, currtpd);
BAMBOO_DEBUGPRINT_REG(parameter);
// release grabbed locks
for(j = 0; j < runtime_locklen; ++j) {
- int * lock = (int *)(runtime_locks[j].redirectlock);
+ int * lock = (int *)(runtime_locks[j].value/*redirectlock*/);
releasewritelock(lock);
}
RUNFREE(currtpd->parameterArray);
RUNFREE(enterflags);
// release grabbed locks
for(j = 0; j < runtime_locklen; ++j) {
- int * lock = (int *)(runtime_locks[j].redirectlock);
+ int * lock = (int *)(runtime_locks[j].value/*redirectlock*/);
releasewritelock(lock);
}
RUNFREE(currtpd->parameterArray);
// release grabbed locks
int tmpj = 0;
for(tmpj = 0; tmpj < runtime_locklen; ++tmpj) {
- int * lock = (int *)(runtime_locks[tmpj].redirectlock);
+ int * lock = (int *)(runtime_locks[tmpj].value/*redirectlock*/);
releasewritelock(lock);
}
}
if(islock) {
BAMBOO_DEBUGPRINT(0xe999);
- for(i = 0; i < runtime_locklen; ++i) {
- void * ptr = (void *)(runtime_locks[i].redirectlock);
- int * lock = (int *)(runtime_locks[i].value);
+ for(i = runtime_locklen; i>0; i--) {
+ void * ptr = (void *)(runtime_locks[i-1].redirectlock);
+ int * lock = (int *)(runtime_locks[i-1].value);
BAMBOO_DEBUGPRINT_REG((int)ptr);
BAMBOO_DEBUGPRINT_REG((int)lock);
BAMBOO_DEBUGPRINT_REG(*((int*)lock+5));
#ifndef MULTICORE_GC
+#ifndef TILERA_BME
if(RuntimeHashcontainskey(lockRedirectTbl, (int)lock)) {
int redirectlock;
RuntimeHashget(lockRedirectTbl, (int)lock, &redirectlock);
RuntimeHashremovekey(lockRedirectTbl, (int)lock);
releasewritelock_r(lock, (int *)redirectlock);
- } else {
+ } else -1{
+#else
+ {
+#endif
#else
{
#endif
- releasewritelock(ptr);
+ releasewritelock(lock); // ptr
}
}
} // line 3015: if(islock)