space.hpp

Go to the documentation of this file.
00001 /* Copyright 1994, 1995 LongView Technologies L.L.C. $Revision: 1.23 $ */
00002 /* Copyright (c) 2006, Sun Microsystems, Inc.
00003 All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the 
00006 following conditions are met:
00007 
00008     * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
00009     * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following 
00010           disclaimer in the documentation and/or other materials provided with the distribution.
00011     * Neither the name of Sun Microsystems nor the names of its contributors may be used to endorse or promote products derived 
00012           from this software without specific prior written permission.
00013 
00014 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 
00015 NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 
00016 THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
00017 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
00018 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
00019 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
00020 
00021 
00022 */
00023 
00024 
00025 // A Water mark points into a space and is used during scavenge to 
00026 // keep track of progress.
00027 class NewWaterMark : ValueObj {
00028  public:
00029   oop* _point;
00030 
00031 };
00032 
00033 inline bool operator==(const NewWaterMark& x, const NewWaterMark& y) {
00034   return x._point == y._point; 
00035 }
00036 
00037 inline bool operator!=(const NewWaterMark& x, const NewWaterMark& y) {
00038   return !(x == y);
00039 }
00040 
00041 class OldWaterMark : ValueObj {
00042  public:
00043   oldSpace* _space;
00044   oop*      _point;
00045   oop* pseudo_allocate(int size);
00046 };
00047 
00048 inline bool operator==(const OldWaterMark& x, const OldWaterMark& y) {
00049   return (x._space == y._space) && (x._point == y._point); 
00050 }
00051 inline bool operator!=(const OldWaterMark& x, const OldWaterMark& y) {
00052   return !(x == y); 
00053 }
00054 
00055 class space: public CHeapObj {
00056  private:
00057   // instance variable
00058   char* _name;
00059 
00060  public:
00061   // invariant: bottom() and end() are on page_size boundaries
00062   // and:       bottom() <= top() <= end()
00063   virtual oop* bottom() = 0;
00064   virtual oop* top()    = 0;
00065   virtual oop* end()    = 0;
00066 
00067   char* name() const        { return _name; }
00068   void set_name(char* name) { _name = name; }
00069 
00070  protected:
00071   virtual void set_bottom(oop* value) = 0;
00072   virtual void set_top(oop* value)    = 0;
00073   virtual void set_end(oop* value)    = 0;
00074 
00075  public:
00076   void initialize(char* name, oop* bottom, oop* end);
00077   void clear();
00078 
00079  public:
00080   bool is_empty()     { return used() == 0; }
00081   int  capacity()     { return byte_size(bottom(), end()); }
00082   int  used()         { return byte_size(bottom(), top()); }
00083   int  free()         { return byte_size(top(),    end()); }
00084     
00085   // MarkSweep support
00086   // phase2
00087   void prepare_for_compaction(OldWaterMark* mark);
00088   // phase3
00089   void compact(OldWaterMark* mark);
00090 
00091  protected:
00092   // operations
00093   virtual void verify() = 0;
00094 
00095   // for debugging & fun
00096   void oops_do(oopsDoFn f);
00097      
00098  public:
00099   void switch_pointers(oop from, oop to);
00100   void print();
00101   void object_iterate(ObjectClosure* blk);
00102 };
00103 
00104 class newSpace: public space {
00105  public:
00106   newSpace* next_space;
00107 
00108  public:
00109   oop* object_start(oop* p);
00110   void verify();
00111 
00112   void object_iterate_from(NewWaterMark* mark, ObjectClosure* blk);
00113 
00114   NewWaterMark top_mark() {
00115     NewWaterMark m;
00116     m._point = top();
00117     return m;
00118   }
00119 };
00120 
00121 extern "C" oop* eden_bottom;
00122 extern "C" oop* eden_top;
00123 extern "C" oop* eden_end;
00124 
00125 class edenSpace : public newSpace {
00126  public:
00127   oop* bottom() { return eden_bottom; }
00128   oop* top()    { return eden_top; }
00129   oop* end()    { return eden_end; }
00130 
00131   bool contains(void* p) { return (oop*) p >= eden_bottom && (oop*) p < eden_top; }
00132 
00133  protected:
00134   void set_bottom(oop* value) { eden_bottom = value; }
00135   void set_top(oop* value)    { eden_top    = value; }
00136   void set_end(oop* value)    { eden_end    = value; }
00137 
00138  public:
00139   // constructor
00140   edenSpace();
00141 
00142   // allocation
00143   oop* allocate(int size) {
00144     oop* oops     = eden_top;
00145     oop* oops_end = oops + size;
00146     if (oops_end <= eden_end) {
00147       eden_top = oops_end;
00148       return oops;
00149     } else {
00150       return NULL;
00151     }
00152   }
00153 };
00154 
00155 class survivorSpace : public newSpace {
00156  private:
00157   oop* _bottom;
00158   oop* _top;
00159   oop* _end;
00160 
00161  public:
00162   oop* bottom() { return _bottom; }
00163   oop* top()   { return _top; }
00164   oop* end()   { return _end; }
00165 
00166   bool contains(void* p) { return (oop*) p >= _bottom && (oop*) p < _top; }
00167 
00168  protected:
00169   void set_bottom(oop* value) { _bottom = value; }
00170   void set_top(oop* value)    { _top    = value; }
00171   void set_end(oop* value)    { _end    = value; }
00172 
00173  public:
00174   // constructor
00175   survivorSpace();
00176 
00177   // allocation
00178   oop* allocate(int size) {
00179     oop* oops     = _top;
00180     oop* oops_end = oops + size;
00181     if (oops_end <= _end) {
00182       _top = oops_end;
00183       return oops;
00184     } else {
00185       return NULL;
00186     }
00187   }
00188 
00189   // allocation test
00190   bool would_fit(int size) { return _top + size < _end; }
00191 
00192   // Scavenge support
00193   void scavenge_contents_from(NewWaterMark* mark);
00194 };
00195 
00196 class oldSpace: public space {
00197  friend class space;
00198  private:
00199   oop* _bottom;
00200   oop* _top;
00201   oop* _end;
00202  public:
00203   oop* bottom() { return _bottom; }
00204   oop* top()    { return _top; }
00205   oop* end()    { return _end; }
00206 
00207   bool contains(void* p) { return (oop*) p >= _bottom && (oop*) p < _top; }
00208 
00209  protected:
00210   void set_bottom(oop* value) { _bottom = value; }
00211   void set_top(oop* value)    { _top    = value; }
00212   void set_end(oop* value)    { _end    = value; }
00213 
00214  public: 
00215   void initialize_threshold();
00216   inline void update_offsets(oop* begin, oop* end) {
00217     if (end >= next_offset_treshold) update_offset_array(begin, end);
00218   }
00219   public: 
00220   oldSpace* next_space;
00221 
00222   oop* object_start(oop* p);
00223 
00224   void update_offset_array(oop* p, oop* p_end);
00225 
00226   oop* expand_and_allocate(int size);
00227 
00228   // Keeps offset for retrieving object start given a card_page
00229   u_char* offset_array;
00230   oop*    next_offset_treshold;
00231   int     next_offset_index;
00232 
00233   oop* allocate(int size) {
00234     oop* p  = _top;
00235     oop* p1 = p + size;
00236     if (p1 < _end) {
00237       _top = p1;
00238       update_offsets(p, p1);
00239       return p;
00240     } else {
00241       return expand_and_allocate(size);
00242     }
00243   }
00244 
00245   // constructors
00246   // allocates object space too; sets size to amount allocated, 0 if none
00247   oldSpace(char* nm, int &size);
00248 
00249   void scavenge_contents_from(OldWaterMark* mark);
00250   void object_iterate_from(OldWaterMark* mark, ObjectClosure* blk);
00251 
00252   void scavenge_recorded_stores();
00253 
00254   void verify();
00255 
00256   OldWaterMark top_mark() {
00257     OldWaterMark m;
00258     m._space = this;
00259     m._point = _top;
00260     return m;
00261   }
00262 
00263   OldWaterMark bottom_mark() {
00264     OldWaterMark m;
00265     m._space = this;
00266     m._point = _bottom;
00267     return m;
00268   }
00269 };
00270 

Generated on Mon Oct 9 13:37:27 2006 for Strongtalk VM by  doxygen 1.4.7