generation.hpp

Go to the documentation of this file.
00001 /* Copyright 1994, 1995 LongView Technologies L.L.C. $Revision: 1.20 $ */
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 // A generation is a bunch of spaces of similarly-aged objects
00025 
00026 class generation: ValueObj {
00027   friend class rSet;
00028   friend class Universe;
00029   friend class MarkSweep;
00030   friend class memOopDesc;
00031   friend class byteArrayOopDesc;
00032   friend class oldGeneration;
00033 
00034  protected:
00035   // Minimum and maximum addresses, used by card marking code.
00036   // Must not overlap with address ranges of other generation(s).
00037   char *low_boundary;
00038   char *high_boundary;
00039   VirtualSpace virtual_space;
00040 
00041  public:
00042   // space enquiries
00043   virtual int capacity() = 0;
00044   virtual int used() = 0;
00045   virtual int free() = 0;
00046 
00047   void print();
00048 };
00049 
00050 
00051 class newGeneration: public generation {
00052   friend class rSet;
00053   friend class Universe;
00054   friend class MarkSweep;
00055   friend class OopNCode;
00056 
00057  private:
00058   edenSpace eden_space;
00059   survivorSpace* from_space;
00060   survivorSpace* to_space;
00061 
00062  public:
00063   edenSpace*      eden() { return &eden_space; }
00064   survivorSpace*  from() { return from_space;  }
00065   survivorSpace*  to()   { return to_space;    }
00066 
00067   // space enquiries
00068   int capacity();
00069   int used();
00070   int free();
00071 
00072   void print();
00073 
00074   void object_iterate(ObjectClosure* blk);
00075 
00076   void verify();
00077   bool would_fit(int size) { return to_space->would_fit(size); }
00078 
00079   void swap_spaces();
00080 
00081   bool contains(void* p) {
00082     return (char*)p >= low_boundary && (char*)p < high_boundary; }
00083 
00084   oop* object_start(oop* p);
00085 
00086   oop* allocate(int size) { return eden()->allocate(size); }
00087   oop* allocate_in_survivor_space(int size) {
00088     return to_space->allocate(size); }
00089 
00090   char *boundary() { return high_boundary; }
00091  protected:
00092   inline bool is_new(memOop p, char *boundary); // inlined in generation.dcl.h
00093   inline bool is_new(oop p,    char *boundary); // ditto
00094 
00095  private:
00096   // called by Universe
00097   void initialize(ReservedSpace rs, int eden_size, int surv_size);
00098 
00099   // phase2 of mark sweep
00100   void prepare_for_compaction(OldWaterMark* mark);
00101   // phase3 of mark sweep
00102   void compact(OldWaterMark* mark);
00103 
00104   void switch_pointers(oop from, oop to);
00105 };
00106 
00107 
00108 class oldGeneration: public generation {
00109   friend class rSet;
00110   friend class Universe;
00111   friend class MarkSweep;
00112   friend class oldSpace;
00113   friend class symbolKlass;
00114 
00115   oop* allocate_in_next_space(int size);
00116 
00117  private:
00118   // OldGeneration consists of a linked lists of spaces.
00119   // [ ] -> [ ] -> [ ] -> [ ] -> [ ] 
00120   //  ^             ^             ^
00121   // first         current       last
00122 
00123   oldSpace *first_space;
00124   oldSpace *current_space;
00125   oldSpace *last_space;
00126 
00127  public:
00128   int expand(int size);
00129 
00130   oop* allocate(int size) {
00131     return current_space->allocate(size);
00132   }
00133 
00134   // called by Universe
00135   void initialize(ReservedSpace rs, int initial_size);
00136 
00137  public:
00138   // space enquiries
00139   int capacity();
00140   int used();
00141   int free();
00142 
00143   void print();
00144   void print_remembered_set();
00145 
00146   // Returns the number of dirty pages in old space.
00147   // ie. # of pages marked as dirty
00148   int number_of_dirty_pages();
00149 
00150   // Returns the number of pages with dirty objects
00151   // ie. # of pages with object pointing to new objects.
00152   int number_of_pages_with_dirty_objects();
00153 
00154   void object_iterate(ObjectClosure* blk);
00155   void object_iterate_from(OldWaterMark* mark, ObjectClosure* blk);
00156 
00157   void verify();
00158 
00159   bool contains(void* p);
00160   oop* object_start(oop* p);
00161 
00162   OldWaterMark top_mark()    { return current_space->top_mark(); }
00163   OldWaterMark bottom_mark() { return first_space->bottom_mark(); }
00164 
00165  private:
00166   void scavenge_contents_from(OldWaterMark* mark);
00167 
00168   void switch_pointers(oop from, oop to);
00169   void switch_pointers_by_card(oop from, oop to);
00170 
00171   void sorted_space_list(oldSpace *sp[], int (*cmp)(oldSpace**, oldSpace**));
00172 
00173   // phase2 of mark sweep
00174   void prepare_for_compaction(OldWaterMark* mark);
00175   // phase3 of mark sweep
00176   void compact(OldWaterMark* mark);
00177 
00178   void append_space(oldSpace *last);
00179 };
00180 
00181 // ensure that you surround the call with {} to prevent s leaking out!
00182 #define FOR_EACH_OLD_SPACE(s) \
00183   for (oldSpace *s= Universe::old_gen.first_space;               \
00184        s != NULL;                                               \
00185        s= s->next_space)
00186 
00187 
00188 

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