src/share/vm/memory/defNewGeneration.hpp

Sat, 01 Dec 2007 00:00:00 +0000

author
duke
date
Sat, 01 Dec 2007 00:00:00 +0000
changeset 435
a61af66fc99e
child 548
ba764ed4b6f2
permissions
-rw-r--r--

Initial load

     1 /*
     2  * Copyright 2001-2007 Sun Microsystems, Inc.  All Rights Reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
    21  * have any questions.
    22  *
    23  */
    25 class EdenSpace;
    26 class ContiguousSpace;
    28 // DefNewGeneration is a young generation containing eden, from- and
    29 // to-space.
    31 class DefNewGeneration: public Generation {
    32   friend class VMStructs;
    34 protected:
    35   Generation* _next_gen;
    36   int         _tenuring_threshold;   // Tenuring threshold for next collection.
    37   ageTable    _age_table;
    38   // Size of object to pretenure in words; command line provides bytes
    39   size_t        _pretenure_size_threshold_words;
    41   ageTable*   age_table() { return &_age_table; }
    42   // Initialize state to optimistically assume no promotion failure will
    43   // happen.
    44   void   init_assuming_no_promotion_failure();
    45   // True iff a promotion has failed in the current collection.
    46   bool   _promotion_failed;
    47   bool   promotion_failed() { return _promotion_failed; }
    49   // Handling promotion failure.  A young generation collection
    50   // can fail if a live object cannot be copied out of its
    51   // location in eden or from-space during the collection.  If
    52   // a collection fails, the young generation is left in a
    53   // consistent state such that it can be collected by a
    54   // full collection.
    55   //   Before the collection
    56   //     Objects are in eden or from-space
    57   //     All roots into the young generation point into eden or from-space.
    58   //
    59   //   After a failed collection
    60   //     Objects may be in eden, from-space, or to-space
    61   //     An object A in eden or from-space may have a copy B
    62   //       in to-space.  If B exists, all roots that once pointed
    63   //       to A must now point to B.
    64   //     All objects in the young generation are unmarked.
    65   //     Eden, from-space, and to-space will all be collected by
    66   //       the full collection.
    67   void handle_promotion_failure(oop);
    69   // In the absence of promotion failure, we wouldn't look at "from-space"
    70   // objects after a young-gen collection.  When promotion fails, however,
    71   // the subsequent full collection will look at from-space objects:
    72   // therefore we must remove their forwarding pointers.
    73   void remove_forwarding_pointers();
    75   // Preserve the mark of "obj", if necessary, in preparation for its mark
    76   // word being overwritten with a self-forwarding-pointer.
    77   void   preserve_mark_if_necessary(oop obj, markOop m);
    79   // When one is non-null, so is the other.  Together, they each pair is
    80   // an object with a preserved mark, and its mark value.
    81   GrowableArray<oop>*     _objs_with_preserved_marks;
    82   GrowableArray<markOop>* _preserved_marks_of_objs;
    84   // Returns true if the collection can be safely attempted.
    85   // If this method returns false, a collection is not
    86   // guaranteed to fail but the system may not be able
    87   // to recover from the failure.
    88   bool collection_attempt_is_safe();
    90   // Promotion failure handling
    91   OopClosure *_promo_failure_scan_stack_closure;
    92   void set_promo_failure_scan_stack_closure(OopClosure *scan_stack_closure) {
    93     _promo_failure_scan_stack_closure = scan_stack_closure;
    94   }
    96   GrowableArray<oop>* _promo_failure_scan_stack;
    97   GrowableArray<oop>* promo_failure_scan_stack() const {
    98     return _promo_failure_scan_stack;
    99   }
   100   void push_on_promo_failure_scan_stack(oop);
   101   void drain_promo_failure_scan_stack(void);
   102   bool _promo_failure_drain_in_progress;
   104   // Performance Counters
   105   GenerationCounters*  _gen_counters;
   106   CSpaceCounters*      _eden_counters;
   107   CSpaceCounters*      _from_counters;
   108   CSpaceCounters*      _to_counters;
   110   // sizing information
   111   size_t               _max_eden_size;
   112   size_t               _max_survivor_size;
   114   // Allocation support
   115   bool _should_allocate_from_space;
   116   bool should_allocate_from_space() const {
   117     return _should_allocate_from_space;
   118   }
   119   void clear_should_allocate_from_space() {
   120     _should_allocate_from_space = false;
   121   }
   122   void set_should_allocate_from_space() {
   123     _should_allocate_from_space = true;
   124   }
   126  protected:
   127   // Spaces
   128   EdenSpace*       _eden_space;
   129   ContiguousSpace* _from_space;
   130   ContiguousSpace* _to_space;
   132   enum SomeProtectedConstants {
   133     // Generations are GenGrain-aligned and have size that are multiples of
   134     // GenGrain.
   135     MinFreeScratchWords = 100
   136   };
   138   // Return the size of a survivor space if this generation were of size
   139   // gen_size.
   140   size_t compute_survivor_size(size_t gen_size, size_t alignment) const {
   141     size_t n = gen_size / (SurvivorRatio + 2);
   142     return n > alignment ? align_size_down(n, alignment) : alignment;
   143   }
   145  public:  // was "protected" but caused compile error on win32
   146   class IsAliveClosure: public BoolObjectClosure {
   147     Generation* _g;
   148   public:
   149     IsAliveClosure(Generation* g);
   150     void do_object(oop p);
   151     bool do_object_b(oop p);
   152   };
   154   class KeepAliveClosure: public OopClosure {
   155   protected:
   156     ScanWeakRefClosure* _cl;
   157     CardTableRS* _rs;
   158   public:
   159     KeepAliveClosure(ScanWeakRefClosure* cl);
   160     void do_oop(oop* p);
   161   };
   163   class FastKeepAliveClosure: public KeepAliveClosure {
   164   protected:
   165     HeapWord* _boundary;
   166   public:
   167     FastKeepAliveClosure(DefNewGeneration* g, ScanWeakRefClosure* cl);
   168     void do_oop(oop* p);
   169   };
   171   class EvacuateFollowersClosure: public VoidClosure {
   172     GenCollectedHeap* _gch;
   173     int _level;
   174     ScanClosure* _scan_cur_or_nonheap;
   175     ScanClosure* _scan_older;
   176   public:
   177     EvacuateFollowersClosure(GenCollectedHeap* gch, int level,
   178                              ScanClosure* cur, ScanClosure* older);
   179     void do_void();
   180   };
   182   class FastEvacuateFollowersClosure;
   183   friend class FastEvacuateFollowersClosure;
   184   class FastEvacuateFollowersClosure: public VoidClosure {
   185     GenCollectedHeap* _gch;
   186     int _level;
   187     DefNewGeneration* _gen;
   188     FastScanClosure* _scan_cur_or_nonheap;
   189     FastScanClosure* _scan_older;
   190   public:
   191     FastEvacuateFollowersClosure(GenCollectedHeap* gch, int level,
   192                                  DefNewGeneration* gen,
   193                                  FastScanClosure* cur,
   194                                  FastScanClosure* older);
   195     void do_void();
   196   };
   198  public:
   199   DefNewGeneration(ReservedSpace rs, size_t initial_byte_size, int level,
   200                    const char* policy="Copy");
   202   virtual Generation::Name kind() { return Generation::DefNew; }
   204   // Accessing spaces
   205   EdenSpace*       eden() const           { return _eden_space; }
   206   ContiguousSpace* from() const           { return _from_space;  }
   207   ContiguousSpace* to()   const           { return _to_space;    }
   209   inline CompactibleSpace* first_compaction_space() const;
   211   // Space enquiries
   212   size_t capacity() const;
   213   size_t used() const;
   214   size_t free() const;
   215   size_t max_capacity() const;
   216   size_t capacity_before_gc() const;
   217   size_t unsafe_max_alloc_nogc() const;
   218   size_t contiguous_available() const;
   220   size_t max_eden_size() const              { return _max_eden_size; }
   221   size_t max_survivor_size() const          { return _max_survivor_size; }
   223   bool supports_inline_contig_alloc() const { return true; }
   224   HeapWord** top_addr() const;
   225   HeapWord** end_addr() const;
   227   // Thread-local allocation buffers
   228   bool supports_tlab_allocation() const { return true; }
   229   inline size_t tlab_capacity() const;
   230   inline size_t unsafe_max_tlab_alloc() const;
   232   // Grow the generation by the specified number of bytes.
   233   // The size of bytes is assumed to be properly aligned.
   234   // Return true if the expansion was successful.
   235   bool expand(size_t bytes);
   237   // DefNewGeneration cannot currently expand except at
   238   // a GC.
   239   virtual bool is_maximal_no_gc() const { return true; }
   241   // Iteration
   242   void object_iterate(ObjectClosure* blk);
   243   void object_iterate_since_last_GC(ObjectClosure* cl);
   245   void younger_refs_iterate(OopsInGenClosure* cl);
   247   void space_iterate(SpaceClosure* blk, bool usedOnly = false);
   249   // Allocation support
   250   virtual bool should_allocate(size_t word_size, bool is_tlab) {
   251     assert(UseTLAB || !is_tlab, "Should not allocate tlab");
   253     size_t overflow_limit    = (size_t)1 << (BitsPerSize_t - LogHeapWordSize);
   255     const bool non_zero      = word_size > 0;
   256     const bool overflows     = word_size >= overflow_limit;
   257     const bool check_too_big = _pretenure_size_threshold_words > 0;
   258     const bool not_too_big   = word_size < _pretenure_size_threshold_words;
   259     const bool size_ok       = is_tlab || !check_too_big || not_too_big;
   261     bool result = !overflows &&
   262                   non_zero   &&
   263                   size_ok;
   265     return result;
   266   }
   268   inline HeapWord* allocate(size_t word_size, bool is_tlab);
   269   HeapWord* allocate_from_space(size_t word_size);
   271   inline HeapWord* par_allocate(size_t word_size, bool is_tlab);
   273   // Prologue & Epilogue
   274   inline virtual void gc_prologue(bool full);
   275   virtual void gc_epilogue(bool full);
   277   // Doesn't require additional work during GC prologue and epilogue
   278   virtual bool performs_in_place_marking() const { return false; }
   280   // Accessing marks
   281   void save_marks();
   282   void reset_saved_marks();
   283   bool no_allocs_since_save_marks();
   285   // Need to declare the full complement of closures, whether we'll
   286   // override them or not, or get message from the compiler:
   287   //   oop_since_save_marks_iterate_nv hides virtual function...
   288 #define DefNew_SINCE_SAVE_MARKS_DECL(OopClosureType, nv_suffix) \
   289   void oop_since_save_marks_iterate##nv_suffix(OopClosureType* cl);
   291   ALL_SINCE_SAVE_MARKS_CLOSURES(DefNew_SINCE_SAVE_MARKS_DECL)
   293 #undef DefNew_SINCE_SAVE_MARKS_DECL
   295   // For non-youngest collection, the DefNewGeneration can contribute
   296   // "to-space".
   297   void contribute_scratch(ScratchBlock*& list, Generation* requestor,
   298                           size_t max_alloc_words);
   300   // GC support
   301   virtual void compute_new_size();
   302   virtual void collect(bool   full,
   303                        bool   clear_all_soft_refs,
   304                        size_t size,
   305                        bool   is_tlab);
   306   HeapWord* expand_and_allocate(size_t size,
   307                                 bool is_tlab,
   308                                 bool parallel = false);
   310   oop copy_to_survivor_space(oop old, oop* from);
   311   int tenuring_threshold() { return _tenuring_threshold; }
   313   // Performance Counter support
   314   void update_counters();
   316   // Printing
   317   virtual const char* name() const;
   318   virtual const char* short_name() const { return "DefNew"; }
   320   bool must_be_youngest() const { return true; }
   321   bool must_be_oldest() const { return false; }
   323   // PrintHeapAtGC support.
   324   void print_on(outputStream* st) const;
   326   void verify(bool allow_dirty);
   328  protected:
   329   void compute_space_boundaries(uintx minimum_eden_size);
   330   // Scavenge support
   331   void swap_spaces();
   332 };

mercurial