示例#1
0
文件: Stable.c 项目: alexbiehl/ghc
StgStablePtr
getStablePtr(StgPtr p)
{
  StgWord sp;

  stableLock();
  if (!stable_ptr_free) enlargeStablePtrTable();
  sp = stable_ptr_free - stable_ptr_table;
  stable_ptr_free  = (spEntry*)(stable_ptr_free->addr);
  stable_ptr_table[sp].addr = p;
  stableUnlock();
  return (StgStablePtr)(sp);
}
示例#2
0
文件: Stable.c 项目: Eufavn/ghc
static StgWord
lookupStableName_(StgPtr p)
{
  StgWord sn;
  void* sn_tmp;

  if (stable_ptr_free == NULL) {
    enlargeStablePtrTable();
  }

  /* 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_ptr_table[sn].addr == p);
    debugTrace(DEBUG_stable, "cached stable name %ld at %p",sn,p);
    return sn;
  } else {
    sn = stable_ptr_free - stable_ptr_table;
    stable_ptr_free  = (snEntry*)(stable_ptr_free->addr);
    stable_ptr_table[sn].ref = 0;
    stable_ptr_table[sn].addr = p;
    stable_ptr_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);

    return sn;
  }
}