src/share/vm/memory/defNewGeneration.hpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/memory/defNewGeneration.hpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,369 @@
     1.4 +/*
     1.5 + * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#ifndef SHARE_VM_MEMORY_DEFNEWGENERATION_HPP
    1.29 +#define SHARE_VM_MEMORY_DEFNEWGENERATION_HPP
    1.30 +
    1.31 +#include "gc_implementation/shared/ageTable.hpp"
    1.32 +#include "gc_implementation/shared/cSpaceCounters.hpp"
    1.33 +#include "gc_implementation/shared/generationCounters.hpp"
    1.34 +#include "gc_implementation/shared/copyFailedInfo.hpp"
    1.35 +#include "memory/generation.inline.hpp"
    1.36 +#include "utilities/stack.hpp"
    1.37 +
    1.38 +class EdenSpace;
    1.39 +class ContiguousSpace;
    1.40 +class ScanClosure;
    1.41 +class STWGCTimer;
    1.42 +
    1.43 +// DefNewGeneration is a young generation containing eden, from- and
    1.44 +// to-space.
    1.45 +
    1.46 +class DefNewGeneration: public Generation {
    1.47 +  friend class VMStructs;
    1.48 +
    1.49 +protected:
    1.50 +  Generation* _next_gen;
    1.51 +  uint        _tenuring_threshold;   // Tenuring threshold for next collection.
    1.52 +  ageTable    _age_table;
    1.53 +  // Size of object to pretenure in words; command line provides bytes
    1.54 +  size_t      _pretenure_size_threshold_words;
    1.55 +
    1.56 +  ageTable*   age_table() { return &_age_table; }
    1.57 +
    1.58 +  // Initialize state to optimistically assume no promotion failure will
    1.59 +  // happen.
    1.60 +  void   init_assuming_no_promotion_failure();
    1.61 +  // True iff a promotion has failed in the current collection.
    1.62 +  bool   _promotion_failed;
    1.63 +  bool   promotion_failed() { return _promotion_failed; }
    1.64 +  PromotionFailedInfo _promotion_failed_info;
    1.65 +
    1.66 +  // Handling promotion failure.  A young generation collection
    1.67 +  // can fail if a live object cannot be copied out of its
    1.68 +  // location in eden or from-space during the collection.  If
    1.69 +  // a collection fails, the young generation is left in a
    1.70 +  // consistent state such that it can be collected by a
    1.71 +  // full collection.
    1.72 +  //   Before the collection
    1.73 +  //     Objects are in eden or from-space
    1.74 +  //     All roots into the young generation point into eden or from-space.
    1.75 +  //
    1.76 +  //   After a failed collection
    1.77 +  //     Objects may be in eden, from-space, or to-space
    1.78 +  //     An object A in eden or from-space may have a copy B
    1.79 +  //       in to-space.  If B exists, all roots that once pointed
    1.80 +  //       to A must now point to B.
    1.81 +  //     All objects in the young generation are unmarked.
    1.82 +  //     Eden, from-space, and to-space will all be collected by
    1.83 +  //       the full collection.
    1.84 +  void handle_promotion_failure(oop);
    1.85 +
    1.86 +  // In the absence of promotion failure, we wouldn't look at "from-space"
    1.87 +  // objects after a young-gen collection.  When promotion fails, however,
    1.88 +  // the subsequent full collection will look at from-space objects:
    1.89 +  // therefore we must remove their forwarding pointers.
    1.90 +  void remove_forwarding_pointers();
    1.91 +
    1.92 +  // Preserve the mark of "obj", if necessary, in preparation for its mark
    1.93 +  // word being overwritten with a self-forwarding-pointer.
    1.94 +  void   preserve_mark_if_necessary(oop obj, markOop m);
    1.95 +  void   preserve_mark(oop obj, markOop m);    // work routine used by the above
    1.96 +
    1.97 +  // Together, these keep <object with a preserved mark, mark value> pairs.
    1.98 +  // They should always contain the same number of elements.
    1.99 +  Stack<oop, mtGC>     _objs_with_preserved_marks;
   1.100 +  Stack<markOop, mtGC> _preserved_marks_of_objs;
   1.101 +
   1.102 +  // Promotion failure handling
   1.103 +  ExtendedOopClosure *_promo_failure_scan_stack_closure;
   1.104 +  void set_promo_failure_scan_stack_closure(ExtendedOopClosure *scan_stack_closure) {
   1.105 +    _promo_failure_scan_stack_closure = scan_stack_closure;
   1.106 +  }
   1.107 +
   1.108 +  Stack<oop, mtGC> _promo_failure_scan_stack;
   1.109 +  void drain_promo_failure_scan_stack(void);
   1.110 +  bool _promo_failure_drain_in_progress;
   1.111 +
   1.112 +  // Performance Counters
   1.113 +  GenerationCounters*  _gen_counters;
   1.114 +  CSpaceCounters*      _eden_counters;
   1.115 +  CSpaceCounters*      _from_counters;
   1.116 +  CSpaceCounters*      _to_counters;
   1.117 +
   1.118 +  // sizing information
   1.119 +  size_t               _max_eden_size;
   1.120 +  size_t               _max_survivor_size;
   1.121 +
   1.122 +  // Allocation support
   1.123 +  bool _should_allocate_from_space;
   1.124 +  bool should_allocate_from_space() const {
   1.125 +    return _should_allocate_from_space;
   1.126 +  }
   1.127 +  void clear_should_allocate_from_space() {
   1.128 +    _should_allocate_from_space = false;
   1.129 +  }
   1.130 +  void set_should_allocate_from_space() {
   1.131 +    _should_allocate_from_space = true;
   1.132 +  }
   1.133 +
   1.134 +  // Tenuring
   1.135 +  void adjust_desired_tenuring_threshold();
   1.136 +
   1.137 +  // Spaces
   1.138 +  EdenSpace*       _eden_space;
   1.139 +  ContiguousSpace* _from_space;
   1.140 +  ContiguousSpace* _to_space;
   1.141 +
   1.142 +  STWGCTimer* _gc_timer;
   1.143 +
   1.144 +  enum SomeProtectedConstants {
   1.145 +    // Generations are GenGrain-aligned and have size that are multiples of
   1.146 +    // GenGrain.
   1.147 +    MinFreeScratchWords = 100
   1.148 +  };
   1.149 +
   1.150 +  // Return the size of a survivor space if this generation were of size
   1.151 +  // gen_size.
   1.152 +  size_t compute_survivor_size(size_t gen_size, size_t alignment) const {
   1.153 +    size_t n = gen_size / (SurvivorRatio + 2);
   1.154 +    return n > alignment ? align_size_down(n, alignment) : alignment;
   1.155 +  }
   1.156 +
   1.157 + public:  // was "protected" but caused compile error on win32
   1.158 +  class IsAliveClosure: public BoolObjectClosure {
   1.159 +    Generation* _g;
   1.160 +  public:
   1.161 +    IsAliveClosure(Generation* g);
   1.162 +    bool do_object_b(oop p);
   1.163 +  };
   1.164 +
   1.165 +  class KeepAliveClosure: public OopClosure {
   1.166 +  protected:
   1.167 +    ScanWeakRefClosure* _cl;
   1.168 +    CardTableRS* _rs;
   1.169 +    template <class T> void do_oop_work(T* p);
   1.170 +  public:
   1.171 +    KeepAliveClosure(ScanWeakRefClosure* cl);
   1.172 +    virtual void do_oop(oop* p);
   1.173 +    virtual void do_oop(narrowOop* p);
   1.174 +  };
   1.175 +
   1.176 +  class FastKeepAliveClosure: public KeepAliveClosure {
   1.177 +  protected:
   1.178 +    HeapWord* _boundary;
   1.179 +    template <class T> void do_oop_work(T* p);
   1.180 +  public:
   1.181 +    FastKeepAliveClosure(DefNewGeneration* g, ScanWeakRefClosure* cl);
   1.182 +    virtual void do_oop(oop* p);
   1.183 +    virtual void do_oop(narrowOop* p);
   1.184 +  };
   1.185 +
   1.186 +  class EvacuateFollowersClosure: public VoidClosure {
   1.187 +    GenCollectedHeap* _gch;
   1.188 +    int _level;
   1.189 +    ScanClosure* _scan_cur_or_nonheap;
   1.190 +    ScanClosure* _scan_older;
   1.191 +  public:
   1.192 +    EvacuateFollowersClosure(GenCollectedHeap* gch, int level,
   1.193 +                             ScanClosure* cur, ScanClosure* older);
   1.194 +    void do_void();
   1.195 +  };
   1.196 +
   1.197 +  class FastEvacuateFollowersClosure: public VoidClosure {
   1.198 +    GenCollectedHeap* _gch;
   1.199 +    int _level;
   1.200 +    DefNewGeneration* _gen;
   1.201 +    FastScanClosure* _scan_cur_or_nonheap;
   1.202 +    FastScanClosure* _scan_older;
   1.203 +  public:
   1.204 +    FastEvacuateFollowersClosure(GenCollectedHeap* gch, int level,
   1.205 +                                 DefNewGeneration* gen,
   1.206 +                                 FastScanClosure* cur,
   1.207 +                                 FastScanClosure* older);
   1.208 +    void do_void();
   1.209 +  };
   1.210 +
   1.211 + public:
   1.212 +  DefNewGeneration(ReservedSpace rs, size_t initial_byte_size, int level,
   1.213 +                   const char* policy="Copy");
   1.214 +
   1.215 +  virtual void ref_processor_init();
   1.216 +
   1.217 +  virtual Generation::Name kind() { return Generation::DefNew; }
   1.218 +
   1.219 +  // Accessing spaces
   1.220 +  EdenSpace*       eden() const           { return _eden_space; }
   1.221 +  ContiguousSpace* from() const           { return _from_space;  }
   1.222 +  ContiguousSpace* to()   const           { return _to_space;    }
   1.223 +
   1.224 +  virtual CompactibleSpace* first_compaction_space() const;
   1.225 +
   1.226 +  // Space enquiries
   1.227 +  size_t capacity() const;
   1.228 +  size_t used() const;
   1.229 +  size_t free() const;
   1.230 +  size_t max_capacity() const;
   1.231 +  size_t capacity_before_gc() const;
   1.232 +  size_t unsafe_max_alloc_nogc() const;
   1.233 +  size_t contiguous_available() const;
   1.234 +
   1.235 +  size_t max_eden_size() const              { return _max_eden_size; }
   1.236 +  size_t max_survivor_size() const          { return _max_survivor_size; }
   1.237 +
   1.238 +  bool supports_inline_contig_alloc() const { return true; }
   1.239 +  HeapWord** top_addr() const;
   1.240 +  HeapWord** end_addr() const;
   1.241 +
   1.242 +  // Thread-local allocation buffers
   1.243 +  bool supports_tlab_allocation() const { return true; }
   1.244 +  size_t tlab_capacity() const;
   1.245 +  size_t tlab_used() const;
   1.246 +  size_t unsafe_max_tlab_alloc() const;
   1.247 +
   1.248 +  // Grow the generation by the specified number of bytes.
   1.249 +  // The size of bytes is assumed to be properly aligned.
   1.250 +  // Return true if the expansion was successful.
   1.251 +  bool expand(size_t bytes);
   1.252 +
   1.253 +  // DefNewGeneration cannot currently expand except at
   1.254 +  // a GC.
   1.255 +  virtual bool is_maximal_no_gc() const { return true; }
   1.256 +
   1.257 +  // Iteration
   1.258 +  void object_iterate(ObjectClosure* blk);
   1.259 +
   1.260 +  void younger_refs_iterate(OopsInGenClosure* cl);
   1.261 +
   1.262 +  void space_iterate(SpaceClosure* blk, bool usedOnly = false);
   1.263 +
   1.264 +  // Allocation support
   1.265 +  virtual bool should_allocate(size_t word_size, bool is_tlab) {
   1.266 +    assert(UseTLAB || !is_tlab, "Should not allocate tlab");
   1.267 +
   1.268 +    size_t overflow_limit    = (size_t)1 << (BitsPerSize_t - LogHeapWordSize);
   1.269 +
   1.270 +    const bool non_zero      = word_size > 0;
   1.271 +    const bool overflows     = word_size >= overflow_limit;
   1.272 +    const bool check_too_big = _pretenure_size_threshold_words > 0;
   1.273 +    const bool not_too_big   = word_size < _pretenure_size_threshold_words;
   1.274 +    const bool size_ok       = is_tlab || !check_too_big || not_too_big;
   1.275 +
   1.276 +    bool result = !overflows &&
   1.277 +                  non_zero   &&
   1.278 +                  size_ok;
   1.279 +
   1.280 +    return result;
   1.281 +  }
   1.282 +
   1.283 +  HeapWord* allocate(size_t word_size, bool is_tlab);
   1.284 +  HeapWord* allocate_from_space(size_t word_size);
   1.285 +
   1.286 +  HeapWord* par_allocate(size_t word_size, bool is_tlab);
   1.287 +
   1.288 +  // Prologue & Epilogue
   1.289 +  virtual void gc_prologue(bool full);
   1.290 +  virtual void gc_epilogue(bool full);
   1.291 +
   1.292 +  // Save the tops for eden, from, and to
   1.293 +  virtual void record_spaces_top();
   1.294 +
   1.295 +  // Doesn't require additional work during GC prologue and epilogue
   1.296 +  virtual bool performs_in_place_marking() const { return false; }
   1.297 +
   1.298 +  // Accessing marks
   1.299 +  void save_marks();
   1.300 +  void reset_saved_marks();
   1.301 +  bool no_allocs_since_save_marks();
   1.302 +
   1.303 +  // Need to declare the full complement of closures, whether we'll
   1.304 +  // override them or not, or get message from the compiler:
   1.305 +  //   oop_since_save_marks_iterate_nv hides virtual function...
   1.306 +#define DefNew_SINCE_SAVE_MARKS_DECL(OopClosureType, nv_suffix) \
   1.307 +  void oop_since_save_marks_iterate##nv_suffix(OopClosureType* cl);
   1.308 +
   1.309 +  ALL_SINCE_SAVE_MARKS_CLOSURES(DefNew_SINCE_SAVE_MARKS_DECL)
   1.310 +
   1.311 +#undef DefNew_SINCE_SAVE_MARKS_DECL
   1.312 +
   1.313 +  // For non-youngest collection, the DefNewGeneration can contribute
   1.314 +  // "to-space".
   1.315 +  virtual void contribute_scratch(ScratchBlock*& list, Generation* requestor,
   1.316 +                          size_t max_alloc_words);
   1.317 +
   1.318 +  // Reset for contribution of "to-space".
   1.319 +  virtual void reset_scratch();
   1.320 +
   1.321 +  // GC support
   1.322 +  virtual void compute_new_size();
   1.323 +
   1.324 +  // Returns true if the collection is likely to be safely
   1.325 +  // completed. Even if this method returns true, a collection
   1.326 +  // may not be guaranteed to succeed, and the system should be
   1.327 +  // able to safely unwind and recover from that failure, albeit
   1.328 +  // at some additional cost. Override superclass's implementation.
   1.329 +  virtual bool collection_attempt_is_safe();
   1.330 +
   1.331 +  virtual void collect(bool   full,
   1.332 +                       bool   clear_all_soft_refs,
   1.333 +                       size_t size,
   1.334 +                       bool   is_tlab);
   1.335 +  HeapWord* expand_and_allocate(size_t size,
   1.336 +                                bool is_tlab,
   1.337 +                                bool parallel = false);
   1.338 +
   1.339 +  oop copy_to_survivor_space(oop old);
   1.340 +  uint tenuring_threshold() { return _tenuring_threshold; }
   1.341 +
   1.342 +  // Performance Counter support
   1.343 +  void update_counters();
   1.344 +
   1.345 +  // Printing
   1.346 +  virtual const char* name() const;
   1.347 +  virtual const char* short_name() const { return "DefNew"; }
   1.348 +
   1.349 +  bool must_be_youngest() const { return true; }
   1.350 +  bool must_be_oldest() const { return false; }
   1.351 +
   1.352 +  // PrintHeapAtGC support.
   1.353 +  void print_on(outputStream* st) const;
   1.354 +
   1.355 +  void verify();
   1.356 +
   1.357 +  bool promo_failure_scan_is_complete() const {
   1.358 +    return _promo_failure_scan_stack.is_empty();
   1.359 +  }
   1.360 +
   1.361 + protected:
   1.362 +  // If clear_space is true, clear the survivor spaces.  Eden is
   1.363 +  // cleared if the minimum size of eden is 0.  If mangle_space
   1.364 +  // is true, also mangle the space in debug mode.
   1.365 +  void compute_space_boundaries(uintx minimum_eden_size,
   1.366 +                                bool clear_space,
   1.367 +                                bool mangle_space);
   1.368 +  // Scavenge support
   1.369 +  void swap_spaces();
   1.370 +};
   1.371 +
   1.372 +#endif // SHARE_VM_MEMORY_DEFNEWGENERATION_HPP

mercurial