< prev index next >

src/share/vm/gc/parallel/psParallelCompact.hpp

Print this page
rev 9846 : [mq]: par-scav-patch
rev 9847 : 8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
Summary: A large part of time in the parallel scavenge collector is spent finding out the amount of live words within memory ranges to find out where to move an object to. Try to incrementally calculate this value.
Reviewed-by: tschatzl, mgerdin
Contributed-by: ray alex <sky1young@gmail.com>
   1 /*
   2  * Copyright (c) 2005, 2015, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 434   inline bool       is_region_aligned(HeapWord* addr) const;
 435 
 436   // Analogous to region_offset() for blocks.
 437   size_t     block_offset(const HeapWord* addr) const;
 438   size_t     addr_to_block_idx(const HeapWord* addr) const;
 439   size_t     addr_to_block_idx(const oop obj) const {
 440     return addr_to_block_idx((HeapWord*) obj);
 441   }
 442   inline BlockData* addr_to_block_ptr(const HeapWord* addr) const;
 443   inline HeapWord*  block_to_addr(size_t block) const;
 444   inline size_t     region_to_block_idx(size_t region) const;
 445 
 446   inline HeapWord*  block_align_down(HeapWord* addr) const;
 447   inline HeapWord*  block_align_up(HeapWord* addr) const;
 448   inline bool       is_block_aligned(HeapWord* addr) const;
 449 
 450   // Return the address one past the end of the partial object.
 451   HeapWord* partial_obj_end(size_t region_idx) const;
 452 
 453   // Return the location of the object after compaction.
 454   HeapWord* calc_new_pointer(HeapWord* addr);
 455 
 456   HeapWord* calc_new_pointer(oop p) {
 457     return calc_new_pointer((HeapWord*) p);
 458   }
 459 
 460 #ifdef  ASSERT
 461   void verify_clear(const PSVirtualSpace* vspace);
 462   void verify_clear();
 463 #endif  // #ifdef ASSERT
 464 
 465 private:
 466   bool initialize_block_data();
 467   bool initialize_region_data(size_t region_size);
 468   PSVirtualSpace* create_vspace(size_t count, size_t element_size);
 469 
 470 private:
 471   HeapWord*       _region_start;
 472 #ifdef  ASSERT
 473   HeapWord*       _region_end;
 474 #endif  // #ifdef ASSERT
 475 
 476   PSVirtualSpace* _region_vspace;
 477   size_t          _reserved_byte_size;


 920   // Convenient access to type names.
 921   typedef ParMarkBitMap::idx_t idx_t;
 922   typedef ParallelCompactData::RegionData RegionData;
 923   typedef ParallelCompactData::BlockData BlockData;
 924 
 925   typedef enum {
 926     old_space_id, eden_space_id,
 927     from_space_id, to_space_id, last_space_id
 928   } SpaceId;
 929 
 930  public:
 931   // Inline closure decls
 932   //
 933   class IsAliveClosure: public BoolObjectClosure {
 934    public:
 935     virtual bool do_object_b(oop p);
 936   };
 937 
 938   class AdjustPointerClosure: public ExtendedOopClosure {
 939    public:




 940     template <typename T> void do_oop_nv(T* p);
 941     virtual void do_oop(oop* p);
 942     virtual void do_oop(narrowOop* p);
 943 
 944     // This closure provides its own oop verification code.
 945     debug_only(virtual bool should_verify_oops() { return false; })


 946   };
 947 
 948   class AdjustKlassClosure : public KlassClosure {
 949    public:




 950     void do_klass(Klass* klass);


 951   };
 952 
 953   friend class AdjustPointerClosure;
 954   friend class AdjustKlassClosure;
 955   friend class RefProcTaskProxy;
 956 
 957  private:
 958   static STWGCTimer           _gc_timer;
 959   static ParallelOldTracer    _gc_tracer;
 960   static elapsedTimer         _accumulated_time;
 961   static unsigned int         _total_invocations;
 962   static unsigned int         _maximum_compaction_gc_num;
 963   static jlong                _time_of_last_gc;   // ms
 964   static CollectorCounters*   _counters;
 965   static ParMarkBitMap        _mark_bitmap;
 966   static ParallelCompactData  _summary_data;
 967   static IsAliveClosure       _is_alive_closure;
 968   static SpaceInfo            _space_info[last_space_id];
 969   static AdjustPointerClosure _adjust_pointer_closure;
 970   static AdjustKlassClosure   _adjust_klass_closure;
 971 
 972   // Reference processing (used in ...follow_contents)
 973   static ReferenceProcessor*  _ref_processor;
 974 
 975   // Values computed at initialization and used by dead_wood_limiter().
 976   static double _dwl_mean;
 977   static double _dwl_std_dev;
 978   static double _dwl_first_term;
 979   static double _dwl_adjustment;
 980 #ifdef  ASSERT
 981   static bool   _dwl_initialized;
 982 #endif  // #ifdef ASSERT
 983 
 984  public:
 985   static ParallelOldTracer* gc_tracer() { return &_gc_tracer; }
 986 
 987  private:
 988 
 989   static void initialize_space_info();
 990 


1046                                         bool maximum_compaction);
1047 
1048   // Return true if dead space crosses onto the specified Region; bit must be
1049   // the bit index corresponding to the first word of the Region.
1050   static inline bool dead_space_crosses_boundary(const RegionData* region,
1051                                                  idx_t bit);
1052 
1053   // Summary phase utility routine to fill dead space (if any) at the dense
1054   // prefix boundary.  Should only be called if the the dense prefix is
1055   // non-empty.
1056   static void fill_dense_prefix_end(SpaceId id);
1057 
1058   // Clear the summary data source_region field for the specified addresses.
1059   static void clear_source_region(HeapWord* beg_addr, HeapWord* end_addr);
1060 
1061   static void summarize_spaces_quick();
1062   static void summarize_space(SpaceId id, bool maximum_compaction);
1063   static void summary_phase(ParCompactionManager* cm, bool maximum_compaction);
1064 
1065   // Adjust addresses in roots.  Does not adjust addresses in heap.
1066   static void adjust_roots();
1067 
1068   DEBUG_ONLY(static void write_block_fill_histogram();)
1069 
1070   // Move objects to new locations.
1071   static void compact_perm(ParCompactionManager* cm);
1072   static void compact();
1073 
1074   // Add available regions to the stack and draining tasks to the task queue.
1075   static void enqueue_region_draining_tasks(GCTaskQueue* q,
1076                                             uint parallel_gc_threads);
1077 
1078   // Add dense prefix update tasks to the task queue.
1079   static void enqueue_dense_prefix_tasks(GCTaskQueue* q,
1080                                          uint parallel_gc_threads);
1081 
1082   // Add region stealing tasks to the task queue.
1083   static void enqueue_region_stealing_tasks(
1084                                        GCTaskQueue* q,
1085                                        ParallelTaskTerminator* terminator_ptr,
1086                                        uint parallel_gc_threads);


1092                                          PSOldGen* old_gen);
1093 
1094   // Reset time since last full gc
1095   static void reset_millis_since_last_gc();
1096 
1097  public:
1098 
1099   PSParallelCompact();
1100 
1101   static void invoke(bool maximum_heap_compaction);
1102   static bool invoke_no_policy(bool maximum_heap_compaction);
1103 
1104   static void post_initialize();
1105   // Perform initialization for PSParallelCompact that requires
1106   // allocations.  This should be called during the VM initialization
1107   // at a pointer where it would be appropriate to return a JNI_ENOMEM
1108   // in the event of a failure.
1109   static bool initialize();
1110 
1111   // Closure accessors
1112   static PSParallelCompact::AdjustPointerClosure* adjust_pointer_closure() {
1113     return &_adjust_pointer_closure;
1114   }
1115   static KlassClosure* adjust_klass_closure()      { return (KlassClosure*)&_adjust_klass_closure; }
1116   static BoolObjectClosure* is_alive_closure()     { return (BoolObjectClosure*)&_is_alive_closure; }
1117 
1118   // Public accessors
1119   static elapsedTimer* accumulated_time() { return &_accumulated_time; }
1120   static unsigned int total_invocations() { return _total_invocations; }
1121   static CollectorCounters* counters()    { return _counters; }
1122 
1123   // Used to add tasks
1124   static GCTaskManager* const gc_task_manager();
1125 
1126   // Marking support
1127   static inline bool mark_obj(oop obj);
1128   static inline bool is_marked(oop obj);
1129 
1130   template <class T> static inline void adjust_pointer(T* p);
1131 
1132   // Compaction support.
1133   // Return true if p is in the range [beg_addr, end_addr).
1134   static inline bool is_in(HeapWord* p, HeapWord* beg_addr, HeapWord* end_addr);
1135   static inline bool is_in(oop* p, HeapWord* beg_addr, HeapWord* end_addr);
1136 
1137   // Convenience wrappers for per-space data kept in _space_info.
1138   static inline MutableSpace*     space(SpaceId space_id);
1139   static inline HeapWord*         new_top(SpaceId space_id);
1140   static inline HeapWord*         dense_prefix(SpaceId space_id);
1141   static inline ObjectStartArray* start_array(SpaceId space_id);
1142 
1143   // Move and update the live objects in the specified space.
1144   static void move_and_update(ParCompactionManager* cm, SpaceId space_id);
1145 
1146   // Process the end of the given region range in the dense prefix.
1147   // This includes saving any object not updated.
1148   static void dense_prefix_regions_epilogue(ParCompactionManager* cm,
1149                                             size_t region_start_index,
1150                                             size_t region_end_index,


   1 /*
   2  * Copyright (c) 2005, 2016, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 434   inline bool       is_region_aligned(HeapWord* addr) const;
 435 
 436   // Analogous to region_offset() for blocks.
 437   size_t     block_offset(const HeapWord* addr) const;
 438   size_t     addr_to_block_idx(const HeapWord* addr) const;
 439   size_t     addr_to_block_idx(const oop obj) const {
 440     return addr_to_block_idx((HeapWord*) obj);
 441   }
 442   inline BlockData* addr_to_block_ptr(const HeapWord* addr) const;
 443   inline HeapWord*  block_to_addr(size_t block) const;
 444   inline size_t     region_to_block_idx(size_t region) const;
 445 
 446   inline HeapWord*  block_align_down(HeapWord* addr) const;
 447   inline HeapWord*  block_align_up(HeapWord* addr) const;
 448   inline bool       is_block_aligned(HeapWord* addr) const;
 449 
 450   // Return the address one past the end of the partial object.
 451   HeapWord* partial_obj_end(size_t region_idx) const;
 452 
 453   // Return the location of the object after compaction.
 454   HeapWord* calc_new_pointer(HeapWord* addr, ParCompactionManager* cm);
 455 
 456   HeapWord* calc_new_pointer(oop p, ParCompactionManager* cm) {
 457     return calc_new_pointer((HeapWord*) p, cm);
 458   }
 459 
 460 #ifdef  ASSERT
 461   void verify_clear(const PSVirtualSpace* vspace);
 462   void verify_clear();
 463 #endif  // #ifdef ASSERT
 464 
 465 private:
 466   bool initialize_block_data();
 467   bool initialize_region_data(size_t region_size);
 468   PSVirtualSpace* create_vspace(size_t count, size_t element_size);
 469 
 470 private:
 471   HeapWord*       _region_start;
 472 #ifdef  ASSERT
 473   HeapWord*       _region_end;
 474 #endif  // #ifdef ASSERT
 475 
 476   PSVirtualSpace* _region_vspace;
 477   size_t          _reserved_byte_size;


 920   // Convenient access to type names.
 921   typedef ParMarkBitMap::idx_t idx_t;
 922   typedef ParallelCompactData::RegionData RegionData;
 923   typedef ParallelCompactData::BlockData BlockData;
 924 
 925   typedef enum {
 926     old_space_id, eden_space_id,
 927     from_space_id, to_space_id, last_space_id
 928   } SpaceId;
 929 
 930  public:
 931   // Inline closure decls
 932   //
 933   class IsAliveClosure: public BoolObjectClosure {
 934    public:
 935     virtual bool do_object_b(oop p);
 936   };
 937 
 938   class AdjustPointerClosure: public ExtendedOopClosure {
 939    public:
 940     AdjustPointerClosure(ParCompactionManager* cm) { 
 941       assert(cm != NULL, "associate ParCompactionManage should not be NULL");
 942       _cm = cm;   
 943     }
 944     template <typename T> void do_oop_nv(T* p);
 945     virtual void do_oop(oop* p);
 946     virtual void do_oop(narrowOop* p);
 947 
 948     // This closure provides its own oop verification code.
 949     debug_only(virtual bool should_verify_oops() { return false; })
 950    private:
 951     ParCompactionManager* _cm;
 952   };
 953 
 954   class AdjustKlassClosure : public KlassClosure {
 955    public:
 956     AdjustKlassClosure(ParCompactionManager* cm) {
 957       assert(cm != NULL, "associate ParCompactionManage should not be NULL");
 958       _cm = cm;   
 959     }
 960     void do_klass(Klass* klass);
 961    private:
 962     ParCompactionManager* _cm;
 963   };
 964 
 965   friend class AdjustPointerClosure;
 966   friend class AdjustKlassClosure;
 967   friend class RefProcTaskProxy;
 968 
 969  private:
 970   static STWGCTimer           _gc_timer;
 971   static ParallelOldTracer    _gc_tracer;
 972   static elapsedTimer         _accumulated_time;
 973   static unsigned int         _total_invocations;
 974   static unsigned int         _maximum_compaction_gc_num;
 975   static jlong                _time_of_last_gc;   // ms
 976   static CollectorCounters*   _counters;
 977   static ParMarkBitMap        _mark_bitmap;
 978   static ParallelCompactData  _summary_data;
 979   static IsAliveClosure       _is_alive_closure;
 980   static SpaceInfo            _space_info[last_space_id];


 981 
 982   // Reference processing (used in ...follow_contents)
 983   static ReferenceProcessor*  _ref_processor;
 984 
 985   // Values computed at initialization and used by dead_wood_limiter().
 986   static double _dwl_mean;
 987   static double _dwl_std_dev;
 988   static double _dwl_first_term;
 989   static double _dwl_adjustment;
 990 #ifdef  ASSERT
 991   static bool   _dwl_initialized;
 992 #endif  // #ifdef ASSERT
 993 
 994  public:
 995   static ParallelOldTracer* gc_tracer() { return &_gc_tracer; }
 996 
 997  private:
 998 
 999   static void initialize_space_info();
1000 


1056                                         bool maximum_compaction);
1057 
1058   // Return true if dead space crosses onto the specified Region; bit must be
1059   // the bit index corresponding to the first word of the Region.
1060   static inline bool dead_space_crosses_boundary(const RegionData* region,
1061                                                  idx_t bit);
1062 
1063   // Summary phase utility routine to fill dead space (if any) at the dense
1064   // prefix boundary.  Should only be called if the the dense prefix is
1065   // non-empty.
1066   static void fill_dense_prefix_end(SpaceId id);
1067 
1068   // Clear the summary data source_region field for the specified addresses.
1069   static void clear_source_region(HeapWord* beg_addr, HeapWord* end_addr);
1070 
1071   static void summarize_spaces_quick();
1072   static void summarize_space(SpaceId id, bool maximum_compaction);
1073   static void summary_phase(ParCompactionManager* cm, bool maximum_compaction);
1074 
1075   // Adjust addresses in roots.  Does not adjust addresses in heap.
1076   static void adjust_roots(ParCompactionManager* cm);
1077 
1078   DEBUG_ONLY(static void write_block_fill_histogram();)
1079 
1080   // Move objects to new locations.
1081   static void compact_perm(ParCompactionManager* cm);
1082   static void compact();
1083 
1084   // Add available regions to the stack and draining tasks to the task queue.
1085   static void enqueue_region_draining_tasks(GCTaskQueue* q,
1086                                             uint parallel_gc_threads);
1087 
1088   // Add dense prefix update tasks to the task queue.
1089   static void enqueue_dense_prefix_tasks(GCTaskQueue* q,
1090                                          uint parallel_gc_threads);
1091 
1092   // Add region stealing tasks to the task queue.
1093   static void enqueue_region_stealing_tasks(
1094                                        GCTaskQueue* q,
1095                                        ParallelTaskTerminator* terminator_ptr,
1096                                        uint parallel_gc_threads);


1102                                          PSOldGen* old_gen);
1103 
1104   // Reset time since last full gc
1105   static void reset_millis_since_last_gc();
1106 
1107  public:
1108 
1109   PSParallelCompact();
1110 
1111   static void invoke(bool maximum_heap_compaction);
1112   static bool invoke_no_policy(bool maximum_heap_compaction);
1113 
1114   static void post_initialize();
1115   // Perform initialization for PSParallelCompact that requires
1116   // allocations.  This should be called during the VM initialization
1117   // at a pointer where it would be appropriate to return a JNI_ENOMEM
1118   // in the event of a failure.
1119   static bool initialize();
1120 
1121   // Closure accessors




1122   static BoolObjectClosure* is_alive_closure()     { return (BoolObjectClosure*)&_is_alive_closure; }
1123 
1124   // Public accessors
1125   static elapsedTimer* accumulated_time() { return &_accumulated_time; }
1126   static unsigned int total_invocations() { return _total_invocations; }
1127   static CollectorCounters* counters()    { return _counters; }
1128 
1129   // Used to add tasks
1130   static GCTaskManager* const gc_task_manager();
1131 
1132   // Marking support
1133   static inline bool mark_obj(oop obj);
1134   static inline bool is_marked(oop obj);
1135 
1136   template <class T> static inline void adjust_pointer(T* p, ParCompactionManager* cm);
1137 
1138   // Compaction support.
1139   // Return true if p is in the range [beg_addr, end_addr).
1140   static inline bool is_in(HeapWord* p, HeapWord* beg_addr, HeapWord* end_addr);
1141   static inline bool is_in(oop* p, HeapWord* beg_addr, HeapWord* end_addr);
1142 
1143   // Convenience wrappers for per-space data kept in _space_info.
1144   static inline MutableSpace*     space(SpaceId space_id);
1145   static inline HeapWord*         new_top(SpaceId space_id);
1146   static inline HeapWord*         dense_prefix(SpaceId space_id);
1147   static inline ObjectStartArray* start_array(SpaceId space_id);
1148 
1149   // Move and update the live objects in the specified space.
1150   static void move_and_update(ParCompactionManager* cm, SpaceId space_id);
1151 
1152   // Process the end of the given region range in the dense prefix.
1153   // This includes saving any object not updated.
1154   static void dense_prefix_regions_epilogue(ParCompactionManager* cm,
1155                                             size_t region_start_index,
1156                                             size_t region_end_index,


< prev index next >