src/share/vm/gc_implementation/parallelScavenge/psPromotionManager.hpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 1
2d8a650513c2
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPROMOTIONMANAGER_HPP
aoqi@0 26 #define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPROMOTIONMANAGER_HPP
aoqi@0 27
aoqi@0 28 #include "gc_implementation/parallelScavenge/psPromotionLAB.hpp"
aoqi@0 29 #include "gc_implementation/shared/gcTrace.hpp"
aoqi@0 30 #include "gc_implementation/shared/copyFailedInfo.hpp"
aoqi@0 31 #include "memory/allocation.hpp"
aoqi@0 32 #include "memory/padded.hpp"
aoqi@0 33 #include "utilities/globalDefinitions.hpp"
aoqi@0 34 #include "utilities/taskqueue.hpp"
aoqi@0 35
aoqi@0 36 //
aoqi@0 37 // psPromotionManager is used by a single thread to manage object survival
aoqi@0 38 // during a scavenge. The promotion manager contains thread local data only.
aoqi@0 39 //
aoqi@0 40 // NOTE! Be careful when allocating the stacks on cheap. If you are going
aoqi@0 41 // to use a promotion manager in more than one thread, the stacks MUST be
aoqi@0 42 // on cheap. This can lead to memory leaks, though, as they are not auto
aoqi@0 43 // deallocated.
aoqi@0 44 //
aoqi@0 45 // FIX ME FIX ME Add a destructor, and don't rely on the user to drain/flush/deallocate!
aoqi@0 46 //
aoqi@0 47
aoqi@0 48 // Move to some global location
aoqi@0 49 #define HAS_BEEN_MOVED 0x1501d01d
aoqi@0 50 // End move to some global location
aoqi@0 51
aoqi@0 52 class MutableSpace;
aoqi@0 53 class PSOldGen;
aoqi@0 54 class ParCompactionManager;
aoqi@0 55
aoqi@0 56 class PSPromotionManager VALUE_OBJ_CLASS_SPEC {
aoqi@0 57 friend class PSScavenge;
aoqi@0 58 friend class PSRefProcTaskExecutor;
aoqi@0 59 private:
aoqi@0 60 static PaddedEnd<PSPromotionManager>* _manager_array;
aoqi@0 61 static OopStarTaskQueueSet* _stack_array_depth;
aoqi@0 62 static PSOldGen* _old_gen;
aoqi@0 63 static MutableSpace* _young_space;
aoqi@0 64
aoqi@0 65 #if TASKQUEUE_STATS
aoqi@0 66 size_t _masked_pushes;
aoqi@0 67 size_t _masked_steals;
aoqi@0 68 size_t _arrays_chunked;
aoqi@0 69 size_t _array_chunks_processed;
aoqi@0 70
aoqi@0 71 void print_taskqueue_stats(uint i) const;
aoqi@0 72 void print_local_stats(uint i) const;
aoqi@0 73 static void print_stats();
aoqi@0 74
aoqi@0 75 void reset_stats();
aoqi@0 76 #endif // TASKQUEUE_STATS
aoqi@0 77
aoqi@0 78 PSYoungPromotionLAB _young_lab;
aoqi@0 79 PSOldPromotionLAB _old_lab;
aoqi@0 80 bool _young_gen_is_full;
aoqi@0 81 bool _old_gen_is_full;
aoqi@0 82
aoqi@0 83 OopStarTaskQueue _claimed_stack_depth;
aoqi@0 84 OverflowTaskQueue<oop, mtGC> _claimed_stack_breadth;
aoqi@0 85
aoqi@0 86 bool _totally_drain;
aoqi@0 87 uint _target_stack_size;
aoqi@0 88
aoqi@0 89 uint _array_chunk_size;
aoqi@0 90 uint _min_array_size_for_chunking;
aoqi@0 91
aoqi@0 92 PromotionFailedInfo _promotion_failed_info;
aoqi@0 93
aoqi@0 94 // Accessors
aoqi@0 95 static PSOldGen* old_gen() { return _old_gen; }
aoqi@0 96 static MutableSpace* young_space() { return _young_space; }
aoqi@0 97
aoqi@0 98 inline static PSPromotionManager* manager_array(int index);
aoqi@0 99 template <class T> inline void claim_or_forward_internal_depth(T* p);
aoqi@0 100
aoqi@0 101 // On the task queues we push reference locations as well as
aoqi@0 102 // partially-scanned arrays (in the latter case, we push an oop to
aoqi@0 103 // the from-space image of the array and the length on the
aoqi@0 104 // from-space image indicates how many entries on the array we still
aoqi@0 105 // need to scan; this is basically how ParNew does partial array
aoqi@0 106 // scanning too). To be able to distinguish between reference
aoqi@0 107 // locations and partially-scanned array oops we simply mask the
aoqi@0 108 // latter oops with 0x01. The next three methods do the masking,
aoqi@0 109 // unmasking, and checking whether the oop is masked or not. Notice
aoqi@0 110 // that the signature of the mask and unmask methods looks a bit
aoqi@0 111 // strange, as they accept and return different types (oop and
aoqi@0 112 // oop*). This is because of the difference in types between what
aoqi@0 113 // the task queue holds (oop*) and oops to partially-scanned arrays
aoqi@0 114 // (oop). We do all the necessary casting in the mask / unmask
aoqi@0 115 // methods to avoid sprinkling the rest of the code with more casts.
aoqi@0 116
aoqi@0 117 // These are added to the taskqueue so PS_CHUNKED_ARRAY_OOP_MASK (or any
aoqi@0 118 // future masks) can't conflict with COMPRESSED_OOP_MASK
aoqi@0 119 #define PS_CHUNKED_ARRAY_OOP_MASK 0x2
aoqi@0 120
aoqi@0 121 bool is_oop_masked(StarTask p) {
aoqi@0 122 // If something is marked chunked it's always treated like wide oop*
aoqi@0 123 return (((intptr_t)(oop*)p) & PS_CHUNKED_ARRAY_OOP_MASK) ==
aoqi@0 124 PS_CHUNKED_ARRAY_OOP_MASK;
aoqi@0 125 }
aoqi@0 126
aoqi@0 127 oop* mask_chunked_array_oop(oop obj) {
aoqi@0 128 assert(!is_oop_masked((oop*) obj), "invariant");
aoqi@0 129 oop* ret = (oop*) (cast_from_oop<uintptr_t>(obj) | PS_CHUNKED_ARRAY_OOP_MASK);
aoqi@0 130 assert(is_oop_masked(ret), "invariant");
aoqi@0 131 return ret;
aoqi@0 132 }
aoqi@0 133
aoqi@0 134 oop unmask_chunked_array_oop(StarTask p) {
aoqi@0 135 assert(is_oop_masked(p), "invariant");
aoqi@0 136 assert(!p.is_narrow(), "chunked array oops cannot be narrow");
aoqi@0 137 oop *chunk = (oop*)p; // cast p to oop (uses conversion operator)
aoqi@0 138 oop ret = oop((oop*)((uintptr_t)chunk & ~PS_CHUNKED_ARRAY_OOP_MASK));
aoqi@0 139 assert(!is_oop_masked((oop*) ret), "invariant");
aoqi@0 140 return ret;
aoqi@0 141 }
aoqi@0 142
aoqi@0 143 template <class T> void process_array_chunk_work(oop obj,
aoqi@0 144 int start, int end);
aoqi@0 145 void process_array_chunk(oop old);
aoqi@0 146
aoqi@0 147 template <class T> void push_depth(T* p) {
aoqi@0 148 claimed_stack_depth()->push(p);
aoqi@0 149 }
aoqi@0 150
aoqi@0 151 protected:
aoqi@0 152 static OopStarTaskQueueSet* stack_array_depth() { return _stack_array_depth; }
aoqi@0 153 public:
aoqi@0 154 // Static
aoqi@0 155 static void initialize();
aoqi@0 156
aoqi@0 157 static void pre_scavenge();
aoqi@0 158 static bool post_scavenge(YoungGCTracer& gc_tracer);
aoqi@0 159
aoqi@0 160 static PSPromotionManager* gc_thread_promotion_manager(int index);
aoqi@0 161 static PSPromotionManager* vm_thread_promotion_manager();
aoqi@0 162
aoqi@0 163 static bool steal_depth(int queue_num, int* seed, StarTask& t) {
aoqi@0 164 return stack_array_depth()->steal(queue_num, seed, t);
aoqi@0 165 }
aoqi@0 166
aoqi@0 167 PSPromotionManager();
aoqi@0 168
aoqi@0 169 // Accessors
aoqi@0 170 OopStarTaskQueue* claimed_stack_depth() {
aoqi@0 171 return &_claimed_stack_depth;
aoqi@0 172 }
aoqi@0 173
aoqi@0 174 bool young_gen_is_full() { return _young_gen_is_full; }
aoqi@0 175
aoqi@0 176 bool old_gen_is_full() { return _old_gen_is_full; }
aoqi@0 177 void set_old_gen_is_full(bool state) { _old_gen_is_full = state; }
aoqi@0 178
aoqi@0 179 // Promotion methods
aoqi@0 180 template<bool promote_immediately> oop copy_to_survivor_space(oop o);
aoqi@0 181 oop oop_promotion_failed(oop obj, markOop obj_mark);
aoqi@0 182
aoqi@0 183 void reset();
aoqi@0 184
aoqi@0 185 void flush_labs();
aoqi@0 186 void drain_stacks(bool totally_drain) {
aoqi@0 187 drain_stacks_depth(totally_drain);
aoqi@0 188 }
aoqi@0 189 public:
aoqi@0 190 void drain_stacks_cond_depth() {
aoqi@0 191 if (claimed_stack_depth()->size() > _target_stack_size) {
aoqi@0 192 drain_stacks_depth(false);
aoqi@0 193 }
aoqi@0 194 }
aoqi@0 195 void drain_stacks_depth(bool totally_drain);
aoqi@0 196
aoqi@0 197 bool stacks_empty() {
aoqi@0 198 return claimed_stack_depth()->is_empty();
aoqi@0 199 }
aoqi@0 200
aoqi@0 201 inline void process_popped_location_depth(StarTask p);
aoqi@0 202
aoqi@0 203 template <class T> inline void claim_or_forward_depth(T* p);
aoqi@0 204
aoqi@0 205 TASKQUEUE_STATS_ONLY(inline void record_steal(StarTask& p);)
aoqi@0 206 };
aoqi@0 207
aoqi@0 208 #endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPROMOTIONMANAGER_HPP

mercurial