void LDV_recordDead( StgClosure *c, nat size ) { void *id; nat t; counter *ctr; if (era > 0 && closureSatisfiesConstraints(c)) { size -= sizeofW(StgProfHeader); ASSERT(LDVW(c) != 0); if ((LDVW((c)) & LDV_STATE_MASK) == LDV_STATE_CREATE) { t = (LDVW((c)) & LDV_CREATE_MASK) >> LDV_SHIFT; if (t < era) { if (RtsFlags.ProfFlags.bioSelector == NULL) { censuses[t].void_total += (long)size; censuses[era].void_total -= (long)size; ASSERT(censuses[t].void_total < censuses[t].not_used); } else { id = closureIdentity(c); ctr = lookupHashTable(censuses[t].hash, (StgWord)id); ASSERT( ctr != NULL ); ctr->c.ldv.void_total += (long)size; ctr = lookupHashTable(censuses[era].hash, (StgWord)id); if (ctr == NULL) { ctr = arenaAlloc(censuses[era].arena, sizeof(counter)); initLDVCtr(ctr); insertHashTable(censuses[era].hash, (StgWord)id, ctr); ctr->identity = id; ctr->next = censuses[era].ctrs; censuses[era].ctrs = ctr; } ctr->c.ldv.void_total -= (long)size; } } } else {
const char *lookupGHCName( void *addr ) { if (add_to_fname_table == NULL) return NULL; return lookupHashTable(add_to_fname_table, (StgWord)addr); }
void hs_hpc_module(char *modName, StgWord32 modCount, StgWord32 modHashNo, StgWord64 *tixArr) { HpcModuleInfo *tmpModule; uint32_t i; if (moduleHash == NULL) { moduleHash = allocStrHashTable(); } tmpModule = lookupHashTable(moduleHash, (StgWord)modName); if (tmpModule == NULL) { // Did not find entry so add one on. tmpModule = (HpcModuleInfo *)stgMallocBytes(sizeof(HpcModuleInfo), "Hpc.hs_hpc_module"); tmpModule->modName = modName; tmpModule->tickCount = modCount; tmpModule->hashNo = modHashNo; tmpModule->tixArr = tixArr; for(i=0;i < modCount;i++) { tixArr[i] = 0; } tmpModule->next = modules; tmpModule->from_file = false; modules = tmpModule; insertHashTable(moduleHash, (StgWord)modName, tmpModule); } else { if (tmpModule->tickCount != modCount) { failure("inconsistent number of tick boxes"); } ASSERT(tmpModule->tixArr != 0); if (tmpModule->hashNo != modHashNo) { fprintf(stderr,"in module '%s'\n",tmpModule->modName); failure("module mismatch with .tix/.mix file hash number"); if (tixFilename != NULL) { fprintf(stderr,"(perhaps remove %s ?)\n",tixFilename); } stg_exit(EXIT_FAILURE); } // The existing tixArr was made up when we read the .tix file, // whereas this is the real tixArr, so copy the data from the // .tix into the real tixArr. for(i=0;i < modCount;i++) { tixArr[i] = tmpModule->tixArr[i]; } if (tmpModule->from_file) { stgFree(tmpModule->modName); stgFree(tmpModule->tixArr); } tmpModule->from_file = false; } }
int unlockFile(int fd) { Lock *lock; lock = lookupHashTable(fd_hash, fd); if (lock == NULL) { // errorBelch("unlockFile: fd %d not found", fd); // This is normal: we didn't know when calling unlockFile // whether this FD referred to a locked file or not. return 1; } if (lock->readers < 0) { lock->readers++; } else { lock->readers--; } if (lock->readers == 0) { removeHashTable(obj_hash, (StgWord)lock, NULL); stgFree(lock); } removeHashTable(fd_hash, fd, NULL); return 0; }
int lockFile(int fd, dev_t dev, ino_t ino, int for_writing) { Lock key, *lock; key.device = dev; key.inode = ino; lock = lookupHashTable(obj_hash, (StgWord)&key); if (lock == NULL) { lock = stgMallocBytes(sizeof(Lock), "lockFile"); lock->device = dev; lock->inode = ino; lock->readers = for_writing ? -1 : 1; insertHashTable(obj_hash, (StgWord)lock, (void *)lock); insertHashTable(fd_hash, fd, lock); return 0; } else { // single-writer/multi-reader locking: if (for_writing || lock->readers < 0) { return -1; } lock->readers++; return 0; } }
void removeThreadLabel(StgWord key) { void * old = NULL; if ((old = lookupHashTable(threadLabels,key))) { removeHashTable(threadLabels,key,old); stgFree(old); } }
StgPtr hs_spt_lookup(StgWord64 key[2]) { if (spt) { ACQUIRE_LOCK(&spt_lock); const StgStablePtr * entry = lookupHashTable(spt, (StgWord)key); RELEASE_LOCK(&spt_lock); const StgPtr ret = entry ? deRefStablePtr(*entry) : NULL; return ret; } else return NULL; }
AdjustorWritable execToWritable(AdjustorExecutable exec) { AdjustorWritable writ; ACQUIRE_SM_LOCK; if (allocatedExecs == NULL || (writ = lookupHashTable(allocatedExecs, (StgWord)exec)) == NULL) { RELEASE_SM_LOCK; barf("execToWritable: not found"); } RELEASE_SM_LOCK; return writ; }
void * lookupThreadLabel(StgWord key) { void * result; ACQUIRE_LOCK(&threadLabels_mutex); result = lookupHashTable(threadLabels,key); RELEASE_LOCK(&threadLabels_mutex); return result; }
void removeThreadLabel(StgWord key) { ACQUIRE_LOCK(&threadLabels_mutex); void * old = NULL; if ((old = lookupHashTable(threadLabels,key))) { removeHashTable(threadLabels,key,old); stgFree(old); } RELEASE_LOCK(&threadLabels_mutex); }
static void checkAddress (HashTable *addrs, void *addr) { ObjectCode *oc; if (!lookupHashTable(addrs, (W_)addr)) { insertHashTable(addrs, (W_)addr, addr); for (oc = unloaded_objects; oc; oc = oc->next) { if ((W_)addr >= (W_)oc->image && (W_)addr < (W_)oc->image + oc->fileSize) { oc->referenced = 1; break; } } } }
StgWord lookupStableName (StgPtr p) { StgWord sn; const void* sn_tmp; stableLock(); if (stable_name_free == NULL) { enlargeStableNameTable(); } /* removing indirections increases the likelihood * of finding a match in the stable name hash table. */ p = (StgPtr)removeIndirections((StgClosure*)p); // register the untagged pointer. This just makes things simpler. p = (StgPtr)UNTAG_CLOSURE((StgClosure*)p); sn_tmp = lookupHashTable(addrToStableHash,(W_)p); sn = (StgWord)sn_tmp; if (sn != 0) { ASSERT(stable_name_table[sn].addr == p); debugTrace(DEBUG_stable, "cached stable name %ld at %p",sn,p); stableUnlock(); return sn; } sn = stable_name_free - stable_name_table; stable_name_free = (snEntry*)(stable_name_free->addr); stable_name_table[sn].addr = p; stable_name_table[sn].sn_obj = NULL; /* debugTrace(DEBUG_stable, "new stable name %d at %p\n",sn,p); */ /* add the new stable name to the hash table */ insertHashTable(addrToStableHash, (W_)p, (void *)sn); stableUnlock(); return sn; }
static void checkAddress (HashTable *addrs, void *addr) { ObjectCode *oc; int i; if (!lookupHashTable(addrs, (W_)addr)) { insertHashTable(addrs, (W_)addr, addr); for (oc = unloaded_objects; oc; oc = oc->next) { for (i = 0; i < oc->n_sections; i++) { if (oc->sections[i].kind != SECTIONKIND_OTHER) { if ((W_)addr >= (W_)oc->sections[i].start && (W_)addr < (W_)oc->sections[i].start + oc->sections[i].size) { oc->referenced = 1; return; } } } } } }
void * lookupThreadLabel(StgWord key) { return lookupHashTable(threadLabels,key); }
static void readTix(void) { unsigned int i; HpcModuleInfo *tmpModule; const HpcModuleInfo *lookup; ws(); expect('T'); expect('i'); expect('x'); ws(); expect('['); ws(); while(tix_ch != ']') { tmpModule = (HpcModuleInfo *)stgMallocBytes(sizeof(HpcModuleInfo), "Hpc.readTix"); tmpModule->from_file = true; expect('T'); expect('i'); expect('x'); expect('M'); expect('o'); expect('d'); expect('u'); expect('l'); expect('e'); ws(); tmpModule -> modName = expectString(); ws(); tmpModule -> hashNo = (unsigned int)expectWord64(); ws(); tmpModule -> tickCount = (int)expectWord64(); tmpModule -> tixArr = (StgWord64 *)calloc(tmpModule->tickCount,sizeof(StgWord64)); ws(); expect('['); ws(); for(i = 0;i < tmpModule->tickCount;i++) { tmpModule->tixArr[i] = expectWord64(); ws(); if (tix_ch == ',') { expect(','); ws(); } } expect(']'); ws(); lookup = lookupHashTable(moduleHash, (StgWord)tmpModule->modName); if (lookup == NULL) { debugTrace(DEBUG_hpc,"readTix: new HpcModuleInfo for %s", tmpModule->modName); insertHashTable(moduleHash, (StgWord)tmpModule->modName, tmpModule); } else { ASSERT(lookup->tixArr != 0); ASSERT(!strcmp(tmpModule->modName, lookup->modName)); debugTrace(DEBUG_hpc,"readTix: existing HpcModuleInfo for %s", tmpModule->modName); if (tmpModule->hashNo != lookup->hashNo) { fprintf(stderr,"in module '%s'\n",tmpModule->modName); failure("module mismatch with .tix/.mix file hash number"); if (tixFilename != NULL) { fprintf(stderr,"(perhaps remove %s ?)\n",tixFilename); } stg_exit(EXIT_FAILURE); } for (i=0; i < tmpModule->tickCount; i++) { lookup->tixArr[i] = tmpModule->tixArr[i]; } stgFree(tmpModule->tixArr); stgFree(tmpModule->modName); stgFree(tmpModule); } if (tix_ch == ',') { expect(','); ws(); } } expect(']'); fclose(tixFile); }