Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Friends
morkZone Class Reference

#include <morkZone.h>

Inheritance diagram for morkZone:
Inheritance graph
[legend]
Collaboration diagram for morkZone:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_IMETHOD Alloc (nsIMdbEnv *ev, mdb_size inSize, void **outBlock)
NS_IMETHOD Free (nsIMdbEnv *ev, void *inBlock)
NS_IMETHOD HeapAddStrongRef (nsIMdbEnv *ev)
NS_IMETHOD HeapCutStrongRef (nsIMdbEnv *ev)
virtual void CloseMorkNode (morkEnv *ev)
virtual ~morkZone ()
 morkZone (morkEnv *ev, const morkUsage &inUsage, nsIMdbHeap *ioNodeHeap, nsIMdbHeap *ioZoneHeap)
void CloseZone (morkEnv *ev)
mork_bool IsZone () const
voidZoneNewChip (morkEnv *ev, mdb_size inSize)
voidZoneNewRun (morkEnv *ev, mdb_size inSize)
void ZoneZapRun (morkEnv *ev, void *ioRunBody)
voidZoneGrowRun (morkEnv *ev, void *ioRunBody, mdb_size inSize)
void SetFrozen ()
void SetMutable ()
void SetAsleep ()
mork_bool IsFrozen () const
mork_bool IsMutable () const
mork_bool IsAsleep () const
void SetNodeClean ()
void SetNodeDirty ()
mork_bool IsNodeClean () const
mork_bool IsNodeDirty () const
void ZapOld (morkEnv *ev, nsIMdbHeap *ioHeap)
voidoperator new (size_t inSize, nsIMdbHeap &ioHeap, morkEnv *ev) CPP_THROW_NEW
void CloseNode (morkEnv *ev)
mdb_err CloseMdbObject (morkEnv *ev)
NS_IMETHOD CloseMdbObject (nsIMdbEnv *ev)
mork_bool IsNode () const
void RefsUnderUsesWarning (morkEnv *ev) const
void NonNodeError (morkEnv *ev) const
void NilHeapError (morkEnv *ev) const
void NonOpenNodeError (morkEnv *ev) const
void NonMutableNodeError (morkEnv *ev) const
void RefsOverflowWarning (morkEnv *ev) const
void UsesOverflowWarning (morkEnv *ev) const
void RefsUnderflowWarning (morkEnv *ev) const
void UsesUnderflowWarning (morkEnv *ev) const
mork_bool GoodRefs () const
mork_bool BadRefs () const
mork_uses StrongRefsOnly () const
mork_refs WeakRefsOnly () const
virtual mork_refs AddStrongRef (morkEnv *ev)
virtual mork_refs CutStrongRef (morkEnv *ev)
mork_refs AddWeakRef (morkEnv *ev)
mork_refs CutWeakRef (morkEnv *ev)
const char * GetNodeAccessAsString () const
const char * GetNodeUsageAsString () const
mork_usage NodeUsage () const
mork_bool IsHeapNode () const
mork_bool IsOpenNode () const
mork_bool IsShutNode () const
mork_bool IsDeadNode () const
mork_bool IsClosingNode () const
mork_bool IsOpenOrClosingNode () const
mork_bool HasNodeAccess () const
void MarkShut ()
void MarkClosing ()
void MarkDead ()

Static Public Member Functions

static void NonZoneTypeError (morkEnv *ev)
static void NilZoneHeapError (morkEnv *ev)
static void BadZoneTagError (morkEnv *ev)
static voidMakeNew (size_t inSize, nsIMdbHeap &ioHeap, morkEnv *ev)
static void SlotWeakNode (morkNode *me, morkEnv *ev, morkNode **ioSlot)
static void SlotStrongNode (morkNode *me, morkEnv *ev, morkNode **ioSlot)

Public Attributes

nsIMdbHeapmZone_Heap
mork_size mZone_HeapVolume
mork_size mZone_BlockVolume
mork_size mZone_RunVolume
mork_size mZone_ChipVolume
mork_size mZone_FreeOldRunVolume
mork_count mZone_HunkCount
mork_count mZone_FreeOldRunCount
morkHunkmZone_HunkList
morkRunmZone_FreeOldRunList
mork_u1mZone_At
mork_size mZone_AtSize
morkRunmZone_FreeRuns [morkZone_kBuckets+1]
nsIMdbHeapmNode_Heap
mork_base mNode_Base
mork_derived mNode_Derived
mork_access mNode_Access
mork_usage mNode_Usage
mork_able mNode_Mutable
mork_load mNode_Load
mork_uses mNode_Uses
mork_refs mNode_Refs

Protected Member Functions

mork_size zone_grow_at (morkEnv *ev, mork_size inNeededSize)
voidzone_new_chip (morkEnv *ev, mdb_size inSize)
morkHunkzone_new_hunk (morkEnv *ev, mdb_size inRunSize)

Friends

class morkHandleFrame

Detailed Description

Definition at line 251 of file morkZone.h.


Constructor & Destructor Documentation

morkZone::~morkZone ( ) [virtual]

Definition at line 72 of file morkZone.cpp.

{
  MORK_ASSERT(this->IsShutNode());
}

Here is the call graph for this function:

morkZone::morkZone ( morkEnv ev,
const morkUsage inUsage,
nsIMdbHeap ioNodeHeap,
nsIMdbHeap ioZoneHeap 
)

Definition at line 78 of file morkZone.cpp.

: morkNode(ev, inUsage, ioNodeHeap)
, mZone_Heap( 0 )
, mZone_HeapVolume( 0 )
, mZone_BlockVolume( 0 )
, mZone_RunVolume( 0 )
, mZone_ChipVolume( 0 )
  
, mZone_FreeOldRunVolume( 0 )
  
, mZone_HunkCount( 0 )
, mZone_FreeOldRunCount( 0 )

, mZone_HunkList( 0 )
, mZone_FreeOldRunList( 0 )
  
, mZone_At( 0 )
, mZone_AtSize( 0 )
    
  // morkRun*     mZone_FreeRuns[ morkZone_kBuckets + 1 ];
{

  morkRun** runs = mZone_FreeRuns;
  morkRun** end = runs + (morkZone_kBuckets + 1); // one past last slot
  --runs; // prepare for preincrement
  while ( ++runs < end ) // another slot in array?
    *runs = 0; // clear all the slots
  
  if ( ev->Good() )
  {
    if ( ioZoneHeap )
    {
      nsIMdbHeap_SlotStrongHeap(ioZoneHeap, ev, &mZone_Heap);
      if ( ev->Good() )
        mNode_Derived = morkDerived_kZone;
    }
    else
      ev->NilPointerError();
  }
}

Here is the call graph for this function:


Member Function Documentation

mork_uses morkNode::AddStrongRef ( morkEnv ev) [virtual, inherited]

Reimplemented in morkTable.

Definition at line 510 of file morkNode.cpp.

{
  mork_uses outUses = 0;
  if ( this )
  {
    if ( this->IsNode() )
    {
      mork_uses uses = mNode_Uses;
      mork_refs refs = mNode_Refs;
      if ( refs < uses ) // need to fix broken refs/uses relation?
      { 
        this->RefsUnderUsesWarning(ev);
        mNode_Refs = mNode_Uses = refs = uses;
      }
      if ( refs < morkNode_kMaxRefCount ) // not too great?
      {
        mNode_Refs = ++refs;
        mNode_Uses = ++uses;
      }
      else
        this->RefsOverflowWarning(ev);

      outUses = uses;
    }
    else
      this->NonNodeError(ev);
  }
  else
    ev->NilPointerError();
  return outUses;
}

Here is the call graph for this function:

Here is the caller graph for this function:

mork_refs morkNode::AddWeakRef ( morkEnv ev) [inherited]

Definition at line 599 of file morkNode.cpp.

{
  mork_refs outRefs = 0;
  if ( this )
  {
    if ( this->IsNode() )
    {
      mork_refs refs = mNode_Refs;
      if ( refs < morkNode_kMaxRefCount ) // not too great?
        mNode_Refs = ++refs;
      else
        this->RefsOverflowWarning(ev);
        
      outRefs = refs;
    }
    else
      this->NonNodeError(ev);
  }
  else
    ev->NilPointerError();
  return outRefs;
}

Here is the call graph for this function:

Here is the caller graph for this function:

mdb_err morkZone::Alloc ( nsIMdbEnv ev,
mdb_size  inSize,
void **  outBlock 
) [virtual]

Implements nsIMdbHeap.

Definition at line 521 of file morkZone.cpp.

{
  mdb_err outErr = 0;
  void* block = 0;
  morkEnv* ev = morkEnv::FromMdbEnv(mev);
  if ( ev )
  {
    block = this->ZoneNewRun(ev, inSize);
    outErr = ev->AsErr();
  }
  else
    outErr = 1;
    
  if ( outBlock )
    *outBlock = block;
    
  return outErr;
}

Here is the call graph for this function:

mork_bool morkNode::BadRefs ( ) const [inline, inherited]

Definition at line 217 of file morkNode.h.

{ return mNode_Refs < mNode_Uses; }
static void morkZone::BadZoneTagError ( morkEnv ev) [static]
mdb_err morkNode::CloseMdbObject ( morkEnv ev) [inherited]

Definition at line 243 of file morkNode.cpp.

{
  // if only one ref, Handle_CutStrongRef will clean up better.
  if (mNode_Uses == 1)
    return CutStrongRef(ev);

  mdb_err outErr = 0;
  
  if ( IsNode() && IsOpenNode() )
  {
    if ( ev )
    {
      CloseMorkNode(ev);
      outErr = ev->AsErr();
    }
  }
  return outErr;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Reimplemented in orkinFactory, orkinPortTableCursor, orkinRowCellCursor, orkinRow, orkinTableRowCursor, orkinThumb, morkStore, orkinCell, orkinEnv, orkinFile, orkinSorting, orkinStore, orkinTable, morkObject, and morkCursor.

Definition at line 238 of file morkNode.cpp.

{
  return morkNode::CloseMdbObject((morkEnv *) mev);
}

Here is the call graph for this function:

void morkZone::CloseMorkNode ( morkEnv ev) [virtual]

Reimplemented from morkNode.

Definition at line 62 of file morkZone.cpp.

{
  if ( this->IsOpenNode() )
  {
    this->MarkClosing();
    this->CloseZone(ev);
    this->MarkShut();
  }
}

Here is the call graph for this function:

void morkNode::CloseNode ( morkEnv ev) [inherited]

Definition at line 384 of file morkNode.cpp.

{
  if ( this )
  {
    if ( this->IsNode() )
      this->MarkShut();
    else
      this->NonNodeError(ev);
  }
  else
    ev->NilPointerError();
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 120 of file morkZone.cpp.

{
  if ( this )
  {
    if ( this->IsNode() )
    {
      nsIMdbHeap* heap = mZone_Heap;
      if ( heap )
      {
        morkHunk* hunk = 0;
        nsIMdbEnv* mev = ev->AsMdbEnv();
        
        morkHunk* next = mZone_HunkList;
        while ( ( hunk = next ) != 0 )
        {
#ifdef morkHunk_USE_TAG_SLOT
          if ( !hunk->HunkGoodTag()  )
            hunk->BadHunkTagWarning(ev);
#endif /* morkHunk_USE_TAG_SLOT */

          next = hunk->HunkNext();
          heap->Free(mev, hunk);
        }
      }
      nsIMdbHeap_SlotStrongHeap((nsIMdbHeap*) 0, ev, &mZone_Heap);
      this->MarkShut();
    }
    else
      this->NonNodeError(ev);
  }
  else
    ev->NilPointerError();
}

Here is the call graph for this function:

Here is the caller graph for this function:

mork_uses morkNode::CutStrongRef ( morkEnv ev) [virtual, inherited]

Reimplemented in morkTable.

Definition at line 580 of file morkNode.cpp.

{
  mork_refs outRefs = 0;
  if ( this )
  {
    if ( this->IsNode() )
    {
      if ( this->cut_use_count(ev) )
        outRefs = this->CutWeakRef(ev);
    }
    else
      this->NonNodeError(ev);
  }
  else
    ev->NilPointerError();
  return outRefs;
}

Here is the call graph for this function:

Here is the caller graph for this function:

mork_refs morkNode::CutWeakRef ( morkEnv ev) [inherited]

Definition at line 623 of file morkNode.cpp.

{
  mork_refs outRefs = 0;
  if ( this )
  {
    if ( this->IsNode() )
    {
      mork_uses uses = mNode_Uses;
      mork_refs refs = mNode_Refs;
      if ( refs ) // not yet zero?
        mNode_Refs = --refs;
      else
        this->RefsUnderflowWarning(ev);

      if ( refs < uses ) // need to fix broken refs/uses relation?
      { 
        this->RefsUnderUsesWarning(ev);
        mNode_Refs = mNode_Uses = refs = uses;
      }
        
      outRefs = refs;
      if ( !refs ) // last reference gone? time to destroy node?
        this->ZapOld(ev, mNode_Heap); // self destroy, use this no longer
    }
    else
      this->NonNodeError(ev);
  }
  else
    ev->NilPointerError();
  return outRefs;
}

Here is the call graph for this function:

Here is the caller graph for this function:

mdb_err morkZone::Free ( nsIMdbEnv ev,
void inBlock 
) [virtual]

Implements nsIMdbHeap.

Definition at line 543 of file morkZone.cpp.

{
  mdb_err outErr = 0;
  if ( inBlock )
  {
    morkEnv* ev = morkEnv::FromMdbEnv(mev);
    if ( ev )
    {
      this->ZoneZapRun(ev, inBlock);
      outErr = ev->AsErr();
    }
    else
      outErr = 1;
  }
    
  return outErr;
}

Here is the call graph for this function:

const char * morkNode::GetNodeAccessAsString ( ) const [inherited]

Definition at line 658 of file morkNode.cpp.

{
  const char* outString = morkNode_kBroken;
  switch( mNode_Access )
  {
    case morkAccess_kOpen: outString = "open"; break;
    case morkAccess_kClosing: outString = "closing"; break;
    case morkAccess_kShut: outString = "shut"; break;
    case morkAccess_kDead: outString = "dead"; break;
  }
  return outString;
}
const char * morkNode::GetNodeUsageAsString ( ) const [inherited]

Definition at line 672 of file morkNode.cpp.

{
  const char* outString = morkNode_kBroken;
  switch( mNode_Usage )
  {
    case morkUsage_kHeap: outString = "heap"; break;
    case morkUsage_kStack: outString = "stack"; break;
    case morkUsage_kMember: outString = "member"; break;
    case morkUsage_kGlobal: outString = "global"; break;
    case morkUsage_kPool: outString = "pool"; break;
    case morkUsage_kNone: outString = "none"; break;
  }
  return outString;
}
mork_bool morkNode::GoodRefs ( ) const [inline, inherited]

Definition at line 216 of file morkNode.h.

{ return mNode_Refs >= mNode_Uses; }
mork_bool morkNode::HasNodeAccess ( ) const [inline, inherited]

Definition at line 251 of file morkNode.h.

  { return ( IsOpenNode() || IsShutNode() || IsClosingNode() ); }

Here is the call graph for this function:

Implements nsIMdbHeap.

Definition at line 563 of file morkZone.cpp.

{
  MORK_USED_1(mev);
  return 0;
}

Implements nsIMdbHeap.

Definition at line 570 of file morkZone.cpp.

{
  MORK_USED_1(mev);
  return 0;
}
mork_bool morkNode::IsAsleep ( ) const [inline, inherited]

Definition at line 142 of file morkNode.h.

mork_bool morkNode::IsClosingNode ( ) const [inline, inherited]

Definition at line 245 of file morkNode.h.

Here is the caller graph for this function:

mork_bool morkNode::IsDeadNode ( ) const [inline, inherited]

Definition at line 242 of file morkNode.h.

Here is the caller graph for this function:

mork_bool morkNode::IsFrozen ( ) const [inline, inherited]

Definition at line 140 of file morkNode.h.

Here is the caller graph for this function:

mork_bool morkNode::IsHeapNode ( ) const [inline, inherited]

Definition at line 233 of file morkNode.h.

  { return mNode_Usage == morkUsage_kHeap; }
mork_bool morkNode::IsMutable ( ) const [inline, inherited]

Definition at line 141 of file morkNode.h.

Here is the caller graph for this function:

mork_bool morkNode::IsNode ( ) const [inline, inherited]

Definition at line 193 of file morkNode.h.

  { return mNode_Base == morkBase_kNode; }
mork_bool morkNode::IsNodeClean ( ) const [inline, inherited]

Definition at line 147 of file morkNode.h.

{ return mNode_Load == morkLoad_kClean; }

Here is the caller graph for this function:

mork_bool morkNode::IsNodeDirty ( ) const [inline, inherited]

Definition at line 148 of file morkNode.h.

{ return mNode_Load == morkLoad_kDirty; }

Here is the caller graph for this function:

mork_bool morkNode::IsOpenNode ( ) const [inline, inherited]

Definition at line 236 of file morkNode.h.

mork_bool morkNode::IsOpenOrClosingNode ( ) const [inline, inherited]

Definition at line 248 of file morkNode.h.

  { return IsOpenNode() || IsClosingNode(); }

Here is the call graph for this function:

Here is the caller graph for this function:

mork_bool morkNode::IsShutNode ( ) const [inline, inherited]

Definition at line 239 of file morkNode.h.

Here is the caller graph for this function:

mork_bool morkZone::IsZone ( ) const [inline]

Definition at line 331 of file morkZone.h.

  { return IsNode() && mNode_Derived == morkDerived_kZone; }

Here is the call graph for this function:

Here is the caller graph for this function:

void * morkNode::MakeNew ( size_t  inSize,
nsIMdbHeap ioHeap,
morkEnv ev 
) [static, inherited]

Definition at line 177 of file morkNode.cpp.

{
  void* node = 0;
  if ( &ioHeap )
  {
    ioHeap.Alloc(ev->AsMdbEnv(), inSize, (void **) &node);
    if ( !node )
      ev->OutOfMemoryError();
  }
  else
    ev->NilPointerError();
  
  return node;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void morkNode::MarkClosing ( ) [inline, inherited]

Definition at line 255 of file morkNode.h.

void morkNode::MarkDead ( ) [inline, inherited]

Definition at line 256 of file morkNode.h.

void morkNode::MarkShut ( ) [inline, inherited]

Definition at line 254 of file morkNode.h.

void morkNode::NilHeapError ( morkEnv ev) const [inherited]

Definition at line 354 of file morkNode.cpp.

{
  ev->NewError("nil mNode_Heap");
}

Here is the caller graph for this function:

Definition at line 163 of file morkZone.cpp.

{
  ev->NewError("nil mZone_Heap");
}

Here is the call graph for this function:

Here is the caller graph for this function:

mork_usage morkNode::NodeUsage ( ) const [inline, inherited]

Definition at line 231 of file morkNode.h.

{ return mNode_Usage; }
void morkNode::NonMutableNodeError ( morkEnv ev) const [inherited]

Definition at line 348 of file morkNode.cpp.

{
  ev->NewError("non-mutable-morkNode");
}

Here is the caller graph for this function:

void morkNode::NonNodeError ( morkEnv ev) const [inherited]

Definition at line 336 of file morkNode.cpp.

{
  ev->NewError("non-morkNode");
}
void morkNode::NonOpenNodeError ( morkEnv ev) const [inherited]

Definition at line 342 of file morkNode.cpp.

{
  ev->NewError("non-open-morkNode");
}

Here is the caller graph for this function:

Definition at line 157 of file morkZone.cpp.

{
  ev->NewError("non morkZone");
}

Here is the call graph for this function:

Here is the caller graph for this function:

void* morkNode::operator new ( size_t  inSize,
nsIMdbHeap ioHeap,
morkEnv ev 
) [inline, inherited]

Reimplemented in morkTable, morkFactory, morkPool, and morkSorting.

Definition at line 159 of file morkNode.h.

  { return morkNode::MakeNew(inSize, ioHeap, ev); }

Here is the call graph for this function:

void morkNode::RefsOverflowWarning ( morkEnv ev) const [inherited]

Definition at line 360 of file morkNode.cpp.

{
  ev->NewWarning("mNode_Refs overflow");
}

Here is the caller graph for this function:

void morkNode::RefsUnderflowWarning ( morkEnv ev) const [inherited]

Definition at line 372 of file morkNode.cpp.

{
  ev->NewWarning("mNode_Refs underflow");
}

Here is the caller graph for this function:

void morkNode::RefsUnderUsesWarning ( morkEnv ev) const [inherited]

Definition at line 330 of file morkNode.cpp.

{
  ev->NewError("mNode_Refs < mNode_Uses");
}

Here is the call graph for this function:

Here is the caller graph for this function:

void morkNode::SetAsleep ( ) [inline, inherited]

Definition at line 138 of file morkNode.h.

void morkNode::SetFrozen ( ) [inline, inherited]

Definition at line 136 of file morkNode.h.

void morkNode::SetMutable ( ) [inline, inherited]

Definition at line 137 of file morkNode.h.

void morkNode::SetNodeClean ( ) [inline, inherited]

Definition at line 144 of file morkNode.h.

Here is the caller graph for this function:

void morkNode::SetNodeDirty ( ) [inline, inherited]

Definition at line 145 of file morkNode.h.

Here is the caller graph for this function:

void morkNode::SlotStrongNode ( morkNode me,
morkEnv ev,
morkNode **  ioSlot 
) [static, inherited]

Definition at line 466 of file morkNode.cpp.

{
  morkNode* node = *ioSlot;
  if ( me != node )
  {
    if ( node )
    {
      // what if this nulls out the ev and causes asserts?
      // can we move this after the CutStrongRef()?
      *ioSlot = 0;
      node->CutStrongRef(ev);
    }
    if ( me && me->AddStrongRef(ev) )
      *ioSlot = me;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void morkNode::SlotWeakNode ( morkNode me,
morkEnv ev,
morkNode **  ioSlot 
) [static, inherited]

Definition at line 489 of file morkNode.cpp.

{
  morkNode* node = *ioSlot;
  if ( me != node )
  {
    if ( node )
    {
      *ioSlot = 0;
      node->CutWeakRef(ev);
    }
    if ( me && me->AddWeakRef(ev) )
      *ioSlot = me;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

mork_uses morkNode::StrongRefsOnly ( ) const [inline, inherited]

Definition at line 219 of file morkNode.h.

{ return mNode_Uses; }

Here is the caller graph for this function:

void morkNode::UsesOverflowWarning ( morkEnv ev) const [inherited]

Definition at line 366 of file morkNode.cpp.

{
  ev->NewWarning("mNode_Uses overflow");
}
void morkNode::UsesUnderflowWarning ( morkEnv ev) const [inherited]

Definition at line 378 of file morkNode.cpp.

{
  ev->NewWarning("mNode_Uses underflow");
}

Here is the caller graph for this function:

mork_refs morkNode::WeakRefsOnly ( ) const [inline, inherited]

Definition at line 220 of file morkNode.h.

{ return (mork_refs) ( mNode_Refs - mNode_Uses ); }

Here is the caller graph for this function:

void morkNode::ZapOld ( morkEnv ev,
nsIMdbHeap ioHeap 
) [inherited]

Definition at line 193 of file morkNode.cpp.

{
  if ( this )
  {
    if ( this->IsNode() )
    {
      mork_usage usage = mNode_Usage; // mNode_Usage before ~morkNode
      this->morkNode::~morkNode(); // first call polymorphic destructor
      if ( ioHeap ) // was this node heap allocated?
        ioHeap->Free(ev->AsMdbEnv(), this);
      else if ( usage == morkUsage_kPool ) // mNode_Usage before ~morkNode
      {
        morkHandle* h = (morkHandle*) this;
        if ( h->IsHandle() && h->GoodHandleTag() )
        {
          if ( h->mHandle_Face )
          {
            if (ev->mEnv_HandlePool)
              ev->mEnv_HandlePool->ZapHandle(ev, h->mHandle_Face);
            else if (h->mHandle_Env && h->mHandle_Env->mEnv_HandlePool)
              h->mHandle_Env->mEnv_HandlePool->ZapHandle(ev, h->mHandle_Face);
          }
          else
            ev->NilPointerError();
        }
      }
    }
    else
      this->NonNodeError(ev);
  }
  else
    ev->NilPointerError();
}

Here is the call graph for this function:

Here is the caller graph for this function:

mork_size morkZone::zone_grow_at ( morkEnv ev,
mork_size  inNeededSize 
) [protected]

Definition at line 189 of file morkZone.cpp.

{
  mZone_At = 0;       // remove any ref to current hunk
  mZone_AtSize = 0;   // zero available bytes in current hunk
  
  mork_size runSize = 0; // actual size of a particular run
  
  // try to find a run in old run list with at least inNeededSize bytes:
  morkRun* run = mZone_FreeOldRunList; // cursor in list scan
  morkRun* prev = 0; // the node before run in the list scan
 
  while ( run ) // another run in list to check?
  {
    morkOldRun* oldRun = (morkOldRun*) run;
    mork_size oldSize = oldRun->OldSize();
    if ( oldSize >= inNeededSize ) // found one big enough?
    {
      runSize = oldSize;
      break; // end while loop early
    }
    prev = run; // remember last position in singly linked list
    run = run->RunNext(); // advance cursor to next node in list
  }
  if ( runSize && run ) // found a usable old run?
  {
    morkRun* next = run->RunNext();
    if ( prev ) // another node in free list precedes run?
      prev->RunSetNext(next); // unlink run
    else
      mZone_FreeOldRunList = next; // unlink run from head of list
      
    morkOldRun *oldRun = (morkOldRun *) run;
    oldRun->OldSetSize(runSize);
    mZone_At = (mork_u1*) run;
    mZone_AtSize = runSize;

#ifdef morkZone_CONFIG_DEBUG
#ifdef morkZone_CONFIG_ALIGN_8
    mork_ip lowThree = ((mork_ip) mZone_At) & 7;
    if ( lowThree ) // not 8 byte aligned?
#else /*morkZone_CONFIG_ALIGN_8*/
    mork_ip lowTwo = ((mork_ip) mZone_At) & 3;
    if ( lowTwo ) // not 4 byte aligned?
#endif /*morkZone_CONFIG_ALIGN_8*/
      ev->NewWarning("mZone_At not aligned");
#endif /*morkZone_CONFIG_DEBUG*/
  }
  else // need to allocate a brand new run
  {
    inNeededSize += 7; // allow for possible alignment padding
    mork_size newSize = ( inNeededSize > morkZone_kNewHunkSize )?
      inNeededSize : morkZone_kNewHunkSize;
      
    morkHunk* hunk = this->zone_new_hunk(ev, newSize);
    if ( hunk )
    {
      morkRun* hunkRun = hunk->HunkRun();
      mork_u1* at = (mork_u1*) hunkRun->RunAsBlock();
      mork_ip lowBits = ((mork_ip) at) & 7;
      if ( lowBits ) // not 8 byte aligned?
      {
        mork_ip skip = (8 - lowBits); // skip the complement to align
        at += skip;
        newSize -= skip;
      }
      mZone_At = at;
      mZone_AtSize = newSize;
    }
  }
  
  return mZone_AtSize;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void * morkZone::zone_new_chip ( morkEnv ev,
mdb_size  inSize 
) [protected]

Definition at line 295 of file morkZone.cpp.

{
#ifdef morkZone_CONFIG_VOL_STATS
  mZone_BlockVolume += inSize; // sum sizes of both chips and runs
#endif /* morkZone_CONFIG_VOL_STATS */
  
  mork_u1* at = mZone_At;
  mork_size atSize = mZone_AtSize; // available bytes in current hunk
  if ( atSize >= inSize ) // current hunk can satisfy request?
  {
    mZone_At = at + inSize;
    mZone_AtSize = atSize - inSize;
    return at;
  }
  else if ( atSize > morkZone_kMaxHunkWaste ) // over max waste allowed?
  {
    morkHunk* hunk = this->zone_new_hunk(ev, inSize);
    if ( hunk )
      return hunk->HunkRun();
      
    return (void*) 0; // show allocation has failed
  }
  else // get ourselves a new hunk for suballocation:
  {
    atSize = this->zone_grow_at(ev, inSize); // get a new hunk
  }

  if ( atSize >= inSize ) // current hunk can satisfy request?
  {
    at = mZone_At;
    mZone_At = at + inSize;
    mZone_AtSize = atSize - inSize;
    return at;
  }
  
  if ( ev->Good() ) // got this far without any error reported yet?
    ev->OutOfMemoryError();
    
  return (void*) 0; // show allocation has failed
}

Here is the call graph for this function:

Here is the caller graph for this function:

morkHunk * morkZone::zone_new_hunk ( morkEnv ev,
mdb_size  inRunSize 
) [protected]

Definition at line 262 of file morkZone.cpp.

{
  mdb_size hunkSize = inSize + sizeof(morkHunk);
  void* outBlock = 0; // we are going straight to the heap:
  mZone_Heap->Alloc(ev->AsMdbEnv(), hunkSize, &outBlock);
  if ( outBlock )
  {
#ifdef morkZone_CONFIG_VOL_STATS
    mZone_HeapVolume += hunkSize; // track all heap allocations
#endif /* morkZone_CONFIG_VOL_STATS */
  
    morkHunk* hunk = (morkHunk*) outBlock;
#ifdef morkHunk_USE_TAG_SLOT
    hunk->HunkInitTag();
#endif /* morkHunk_USE_TAG_SLOT */
  
    hunk->HunkSetNext(mZone_HunkList);
    mZone_HunkList = hunk;
    ++mZone_HunkCount;
    
    morkRun* run = hunk->HunkRun();
    run->RunSetSize(inSize);
#ifdef morkRun_USE_TAG_SLOT
    run->RunInitTag();
#endif /* morkRun_USE_TAG_SLOT */
    
    return hunk;
  }
  if ( ev->Good() ) // got this far without any error reported yet?
    ev->OutOfMemoryError();
  return (morkHunk*) 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void * morkZone::ZoneGrowRun ( morkEnv ev,
void ioRunBody,
mdb_size  inSize 
)

Definition at line 469 of file morkZone.cpp.

{
#ifdef morkZone_CONFIG_ARENA

  morkRun* run = morkRun::BlockAsRun(ioRunBlock);
  mdb_size runSize = run->RunSize();

#ifdef morkZone_CONFIG_DEBUG
  if ( !this->IsZone() )
    this->NonZoneTypeError(ev);
  else if ( !mZone_Heap )
    this->NilZoneHeapError(ev);
#endif /*morkZone_CONFIG_DEBUG*/

#ifdef morkZone_CONFIG_ALIGN_8
  inSize += 7;
  inSize &= ~((mork_ip) 7); // force to multiple of 8 bytes
#else /*morkZone_CONFIG_ALIGN_8*/
  inSize += 3;
  inSize &= ~((mork_ip) 3); // force to multiple of 4 bytes
#endif /*morkZone_CONFIG_ALIGN_8*/

  if ( inSize > runSize )
  {
    void* newBuf = this->ZoneNewRun(ev, inSize);
    if ( newBuf )
    {
      MORK_MEMCPY(newBuf, ioRunBlock, runSize);
      this->ZoneZapRun(ev, ioRunBlock);
      
      return newBuf;
    }
  }
  else
    return ioRunBlock; // old size is big enough
  
  if ( ev->Good() ) // got this far without any error reported yet?
    ev->OutOfMemoryError();
  
  return (void*) 0; // indicate failed allocation

#else /*morkZone_CONFIG_ARENA*/
  void* outBlock = 0;
  mZone_Heap->Free(ev->AsMdbEnv(), ioRunBlock);
  return outBlock;
#endif /*morkZone_CONFIG_ARENA*/
}

Here is the call graph for this function:

void * morkZone::ZoneNewChip ( morkEnv ev,
mdb_size  inSize 
)

Definition at line 336 of file morkZone.cpp.

{
#ifdef morkZone_CONFIG_ARENA

#ifdef morkZone_CONFIG_DEBUG
  if ( !this->IsZone() )
    this->NonZoneTypeError(ev);
  else if ( !mZone_Heap )
    this->NilZoneHeapError(ev);
#endif /*morkZone_CONFIG_DEBUG*/

#ifdef morkZone_CONFIG_ALIGN_8
  inSize += 7;
  inSize &= ~((mork_ip) 7); // force to multiple of 8 bytes
#else /*morkZone_CONFIG_ALIGN_8*/
  inSize += 3;
  inSize &= ~((mork_ip) 3); // force to multiple of 4 bytes
#endif /*morkZone_CONFIG_ALIGN_8*/

#ifdef morkZone_CONFIG_VOL_STATS
  mZone_ChipVolume += inSize; // sum sizes of chips only
#endif /* morkZone_CONFIG_VOL_STATS */

  return this->zone_new_chip(ev, inSize);

#else /*morkZone_CONFIG_ARENA*/
  void* outBlock = 0;
  mZone_Heap->Alloc(ev->AsMdbEnv(), inSize, &outBlock);
  return outBlock;
#endif /*morkZone_CONFIG_ARENA*/
  
}

Here is the call graph for this function:

Here is the caller graph for this function:

void * morkZone::ZoneNewRun ( morkEnv ev,
mdb_size  inSize 
)

Definition at line 370 of file morkZone.cpp.

{
#ifdef morkZone_CONFIG_ARENA

#ifdef morkZone_CONFIG_DEBUG
  if ( !this->IsZone() )
    this->NonZoneTypeError(ev);
  else if ( !mZone_Heap )
    this->NilZoneHeapError(ev);
#endif /*morkZone_CONFIG_DEBUG*/

  inSize += morkZone_kRoundAdd;
  inSize &= morkZone_kRoundMask;
  if ( inSize <= morkZone_kMaxCachedRun )
  {
    morkRun** bucket = mZone_FreeRuns + (inSize >> morkZone_kRoundBits);
    morkRun* hit = *bucket;
    if ( hit ) // cache hit?
    {
      *bucket = hit->RunNext();
      hit->RunSetSize(inSize);
      return hit->RunAsBlock();
    }
  }
  mdb_size blockSize = inSize + sizeof(morkRun); // plus run overhead
#ifdef morkZone_CONFIG_VOL_STATS
  mZone_RunVolume += blockSize; // sum sizes of runs only
#endif /* morkZone_CONFIG_VOL_STATS */
  morkRun* run = (morkRun*) this->zone_new_chip(ev, blockSize);
  if ( run )
  {
    run->RunSetSize(inSize);
#ifdef morkRun_USE_TAG_SLOT
    run->RunInitTag();
#endif /* morkRun_USE_TAG_SLOT */
    return run->RunAsBlock();
  }
  
  if ( ev->Good() ) // got this far without any error reported yet?
    ev->OutOfMemoryError();
  
  return (void*) 0; // indicate failed allocation

#else /*morkZone_CONFIG_ARENA*/
  void* outBlock = 0;
  mZone_Heap->Alloc(ev->AsMdbEnv(), inSize, &outBlock);
  return outBlock;
#endif /*morkZone_CONFIG_ARENA*/
}

Here is the call graph for this function:

Here is the caller graph for this function:

void morkZone::ZoneZapRun ( morkEnv ev,
void ioRunBody 
)

Definition at line 420 of file morkZone.cpp.

{
#ifdef morkZone_CONFIG_ARENA

  morkRun* run = morkRun::BlockAsRun(ioRunBlock);
  mdb_size runSize = run->RunSize();
#ifdef morkZone_CONFIG_VOL_STATS
  mZone_BlockVolume -= runSize; // tracking sizes of both chips and runs
#endif /* morkZone_CONFIG_VOL_STATS */

#ifdef morkZone_CONFIG_DEBUG
  if ( !this->IsZone() )
    this->NonZoneTypeError(ev);
  else if ( !mZone_Heap )
    this->NilZoneHeapError(ev);
  else if ( !ioRunBlock )
    ev->NilPointerError();
  else if ( runSize & morkZone_kRoundAdd )
    run->RunSizeAlignError(ev);
#ifdef morkRun_USE_TAG_SLOT
  else if ( !run->RunGoodTag() )
    run->BadRunTagError(ev);
#endif /* morkRun_USE_TAG_SLOT */
#endif /*morkZone_CONFIG_DEBUG*/

  if ( runSize <= morkZone_kMaxCachedRun ) // goes into free run list?
  {
    morkRun** bucket = mZone_FreeRuns + (runSize >> morkZone_kRoundBits);
    run->RunSetNext(*bucket); // push onto free run list
    *bucket = run;
  }
  else // free old run list
  {
    run->RunSetNext(mZone_FreeOldRunList); // push onto free old run list
    mZone_FreeOldRunList = run;
    ++mZone_FreeOldRunCount;
#ifdef morkZone_CONFIG_VOL_STATS
    mZone_FreeOldRunVolume += runSize;
#endif /* morkZone_CONFIG_VOL_STATS */

    morkOldRun* oldRun = (morkOldRun*) run; // to access extra size slot
    oldRun->OldSetSize(runSize); // so we know how big this is later
  }

#else /*morkZone_CONFIG_ARENA*/
  mZone_Heap->Free(ev->AsMdbEnv(), ioRunBlock);
#endif /*morkZone_CONFIG_ARENA*/
}

Here is the call graph for this function:

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class morkHandleFrame [friend, inherited]

Reimplemented in morkHandle.

Definition at line 131 of file morkNode.h.


Member Data Documentation

Definition at line 122 of file morkNode.h.

Definition at line 119 of file morkNode.h.

Definition at line 120 of file morkNode.h.

Definition at line 117 of file morkNode.h.

Definition at line 125 of file morkNode.h.

Definition at line 124 of file morkNode.h.

Definition at line 128 of file morkNode.h.

Definition at line 123 of file morkNode.h.

Definition at line 127 of file morkNode.h.

Definition at line 285 of file morkZone.h.

Definition at line 286 of file morkZone.h.

Definition at line 272 of file morkZone.h.

Definition at line 274 of file morkZone.h.

Definition at line 279 of file morkZone.h.

Definition at line 282 of file morkZone.h.

Definition at line 276 of file morkZone.h.

Definition at line 290 of file morkZone.h.

Definition at line 269 of file morkZone.h.

Definition at line 271 of file morkZone.h.

Definition at line 278 of file morkZone.h.

Definition at line 281 of file morkZone.h.

Definition at line 273 of file morkZone.h.


The documentation for this class was generated from the following files: