Polaris: Zombie.cc Source File

Zombie.cc

Go to the documentation of this file.
00001 ///
00002 ///
00003 ///
00004 #ifdef POLARIS_GNU_PRAGMAS
00005 #pragma implementation
00006 #endif
00007 ///
00008 #include "Collection/Zombie.h"
00009 
00010 #include "GC_TRACE_MACS.h"
00011 #ifdef ZOMBIE_STATS
00012 int  max_zombies = 0;
00013 int  cur_zombies = 0;
00014 #endif
00015 
00016 Listable *
00017 Zombie::listable_clone() const
00018 {
00019     return new Zombie;
00020 }
00021 
00022 void
00023 Zombie::print(ostream & out) const
00024 {
00025     out << "ZOMBIE!";
00026 }
00027 
00028 Zombie::~Zombie()
00029 {
00030     #ifdef CLASS_INSTANCE_REGISTRY
00031     unregister_instance(ZOMBIE_CLASS, this);
00032     #endif
00033 
00034 #ifdef ZOMBIE_STATS
00035     --cur_zombies;
00036 #endif
00037     #ifdef GC_TRACE_ZOMBIES
00038       cout<<__FILE__<<":~Zombie:"<<this<<endl;
00039     #endif
00040 
00041     /// ...  Nothin' to do
00042 }
00043 #define DEF_GRAVEYARD
00044 #ifdef DEF_GRAVEYARD
00045 //98-05-20 evansl@cs.tamu.edu(Larry Evans): graveyard is no longer
00046 //used; so, eventually, everything in this #ifdef...#endif clause
00047 //should be removed from here and the header file.
00048 int  graveyard_size = 0;
00049 
00050 coffin graveyard[DELETE_MAX] = {0, 0};
00051 
00052 void 
00053 add_zombie_list(Listable *)
00054 {
00055   p_assert(0,"no longer valid");
00056 }
00057 
00058 int
00059 check_zombie_list(void *)
00060 {
00061   p_assert(0,"no longer valid");
00062 
00063         return 0;
00064 }
00065 #endif
00066 void 
00067 dump_zombie_stats()
00068 {
00069     cout << "current number of Zombies: " << cur_zombies << endl;
00070     cout << "Max number of Zombies: " << max_zombies << endl;
00071 }
00072 
00073 void 
00074 dec_refs_delete_or_zombie( Listable *ptr)
00075   //Modification History:
00076 ///  98-05-20 evansl@cs.tamu.edu(Larry Evans)
00077 ///    WHAT:
00078 ///      1.Replaced Zombie conversion with delete
00079 ///      2.Added p_assert(count>0)
00080 ///    WHY:
00081 ///      1.This change, in combination with changes in Listable::
00082 ///        operator delete, solve the cyclic reference count
00083 ///        problem([BOB80,p. 270],[MIL96])
00084 ///      2.Prevent possibility of infinite calls to this method
00085 ///        because of cycles in LiveWrappers.
00086 ///                
00087   //------------------ Bibliography ----------------
00088   //[BOB80] Daniel G. Bobrow
00089 ///        "Managing reentrant structures using reference counts"
00090 ///        _TOPLAS_, 2(3):269-273, July 1980
00091   //[MIL96] Justin Miller
00092 ///        "Clean up:C++ garbage collection"
00093 ///        _Byte_, 21(1):157(2)
00094   {
00095   ; const char* context="dec_refs_delete_or_zombie:"
00096   ; int count=ptr->count();
00097   #ifdef GC_TRACE_DRDOZ
00098   ; cout<<context<<"ptr="<<ptr<<" count="<<count<<endl
00099   #endif
00100 ///   ; p_assert(count>0,"possible cycle in LiveWrapper pointer graph")
00101 ///    ; p_warning("possible cycle in LiveWrapper pointer graph")
00102   ; if (count == 1)
00103     {
00104     ; ptr->ref_dec()   /// ...  only one ref -- it will be deleted
00105     ;}
00106     else 
00107     {
00108     #ifdef GC_TRACE_DELETES
00109       cout<<context<<":deleting "<<ptr<<endl
00110     #endif
00111     ; ptr->ref_dec() /// ... remove count due to containing LiveWrapper.
00112     ; delete ptr /// ... will call DTOR and convert to Zombie if there's any
00113       /// ... outstanding references left.
00114     #ifdef GC_TRACE_DRDOZ
00115     ; cout<<context<<"else-part"<<endl
00116     #endif
00117     ;}
00118   ;}
 © 1995-2005 University of Illinois, Urbana-Champaign. All rights reserved.  Fri Mar 25 23:06:17 2005