Fri, 29 Apr 2016 00:06:10 +0800
Added MIPS 64-bit port.
1 /*
2 * Copyright (c) 2001, 2013, 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 *
23 */
25 /*
26 * This file has been modified by Loongson Technology in 2015. These
27 * modifications are Copyright (c) 2015 Loongson Technology, and are made
28 * available on the same license terms set forth above.
29 */
31 #ifndef SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSOLDGEN_HPP
32 #define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSOLDGEN_HPP
34 #include "gc_implementation/parallelScavenge/objectStartArray.hpp"
35 #include "gc_implementation/parallelScavenge/psGenerationCounters.hpp"
36 #include "gc_implementation/parallelScavenge/psVirtualspace.hpp"
37 #include "gc_implementation/shared/mutableSpace.hpp"
38 #include "gc_implementation/shared/mutableNUMASpace.hpp"
39 #include "gc_implementation/shared/spaceCounters.hpp"
40 #include "runtime/safepoint.hpp"
42 class PSMarkSweepDecorator;
44 class PSOldGen : public CHeapObj<mtGC> {
45 friend class VMStructs;
46 friend class PSPromotionManager; // Uses the cas_allocate methods
47 friend class ParallelScavengeHeap;
48 friend class AdjoiningGenerations;
50 protected:
51 MemRegion _reserved; // Used for simple containment tests
52 PSVirtualSpace* _virtual_space; // Controls mapping and unmapping of virtual mem
53 ObjectStartArray _start_array; // Keeps track of where objects start in a 512b block
54 MutableSpace* _object_space; // Where all the objects live
55 PSMarkSweepDecorator* _object_mark_sweep; // The mark sweep view of _object_space
56 const char* const _name; // Name of this generation.
58 // Performance Counters
59 PSGenerationCounters* _gen_counters;
60 SpaceCounters* _space_counters;
62 // Sizing information, in bytes, set in constructor
63 const size_t _init_gen_size;
64 const size_t _min_gen_size;
65 const size_t _max_gen_size;
67 // Used when initializing the _name field.
68 static inline const char* select_name();
70 HeapWord* allocate_noexpand(size_t word_size) {
71 // We assume the heap lock is held here.
72 assert_locked_or_safepoint(Heap_lock);
73 HeapWord* res = object_space()->allocate(word_size);
74 if (res != NULL) {
75 _start_array.allocate_block(res);
76 }
77 return res;
78 }
80 // Support for MT garbage collection. CAS allocation is lower overhead than grabbing
81 // and releasing the heap lock, which is held during gc's anyway. This method is not
82 // safe for use at the same time as allocate_noexpand()!
83 HeapWord* cas_allocate_noexpand(size_t word_size, int node) {
84 assert(SafepointSynchronize::is_at_safepoint(), "Must only be called at safepoint");
85 HeapWord* res;
86 if(UseOldNUMA) {
87 res = object_space()->cas_allocate_oldnuma(word_size, node);
88 }
89 else {
90 res = object_space()->cas_allocate(word_size);
91 }
92 if (res != NULL) {
93 _start_array.allocate_block(res);
94 }
95 return res;
96 }
98 // Support for MT garbage collection. See above comment.
99 HeapWord* cas_allocate(size_t word_size, int node) {
100 HeapWord* res = cas_allocate_noexpand(word_size, node);
101 return (res == NULL) ? expand_and_cas_allocate(word_size, node) : res;
102 }
104 HeapWord* expand_and_allocate(size_t word_size);
105 HeapWord* expand_and_cas_allocate(size_t word_size, int node);
106 void expand(size_t bytes);
107 bool expand_by(size_t bytes);
108 bool expand_to_reserved();
110 void shrink(size_t bytes);
112 void post_resize();
114 public:
115 // Initialize the generation.
116 PSOldGen(ReservedSpace rs, size_t alignment,
117 size_t initial_size, size_t min_size, size_t max_size,
118 const char* perf_data_name, int level);
120 PSOldGen(size_t initial_size, size_t min_size, size_t max_size,
121 const char* perf_data_name, int level);
123 virtual void initialize(ReservedSpace rs, size_t alignment,
124 const char* perf_data_name, int level);
125 void initialize_virtual_space(ReservedSpace rs, size_t alignment);
126 virtual void initialize_work(const char* perf_data_name, int level);
127 virtual void initialize_performance_counters(const char* perf_data_name, int level);
129 MemRegion reserved() const { return _reserved; }
130 virtual size_t max_gen_size() { return _max_gen_size; }
131 size_t min_gen_size() { return _min_gen_size; }
133 // Returns limit on the maximum size of the generation. This
134 // is the same as _max_gen_size for PSOldGen but need not be
135 // for a derived class.
136 virtual size_t gen_size_limit();
138 bool is_in(const void* p) const {
139 return _virtual_space->contains((void *)p);
140 }
142 bool is_in_reserved(const void* p) const {
143 return reserved().contains(p);
144 }
146 MutableSpace* object_space() const { return _object_space; }
147 PSMarkSweepDecorator* object_mark_sweep() const { return _object_mark_sweep; }
148 ObjectStartArray* start_array() { return &_start_array; }
149 PSVirtualSpace* virtual_space() const { return _virtual_space;}
151 // Has the generation been successfully allocated?
152 bool is_allocated();
154 // MarkSweep methods
155 virtual void precompact();
156 void adjust_pointers();
157 void compact();
159 // Size info
160 size_t capacity_in_bytes() const { return object_space()->capacity_in_bytes(); }
161 size_t used_in_bytes() const { return object_space()->used_in_bytes(); }
162 size_t free_in_bytes() const { return object_space()->free_in_bytes(); }
163 size_t free_in_bytes_numa() const {
164 size_t min_size, free_bytes;
165 MutableNUMASpace* s = (MutableNUMASpace*) object_space();
166 int i = s->lgrp_spaces()->length();
167 int j;
168 MutableNUMASpace::LGRPSpace *ls;
169 MutableSpace* sp;
170 for(j = 0; j < i; j++) {
171 ls = s->lgrp_spaces()->at(j);
172 sp = ls->space();
173 free_bytes = sp->free_in_bytes();
174 if(j == 0) min_size = free_bytes;
175 if(free_bytes < min_size) min_size = free_bytes;
176 }
177 return min_size;
178 }
180 size_t capacity_in_words() const { return object_space()->capacity_in_words(); }
181 size_t used_in_words() const { return object_space()->used_in_words(); }
182 size_t free_in_words() const { return object_space()->free_in_words(); }
184 // Includes uncommitted memory
185 size_t contiguous_available() const;
187 bool is_maximal_no_gc() const {
188 return virtual_space()->uncommitted_size() == 0;
189 }
191 // Calculating new sizes
192 void resize(size_t desired_free_space);
194 // Allocation. We report all successful allocations to the size policy
195 // Note that the perm gen does not use this method, and should not!
196 HeapWord* allocate(size_t word_size);
198 // Iteration.
199 void oop_iterate_no_header(OopClosure* cl) { object_space()->oop_iterate_no_header(cl); }
200 void object_iterate(ObjectClosure* cl) { object_space()->object_iterate(cl); }
202 // Debugging - do not use for time critical operations
203 virtual void print() const;
204 virtual void print_on(outputStream* st) const;
205 void print_used_change(size_t prev_used) const;
207 void verify();
208 void verify_object_start_array();
210 // These should not used
211 virtual void reset_after_change();
213 // These should not used
214 virtual size_t available_for_expansion();
215 virtual size_t available_for_contraction();
217 void space_invariants() PRODUCT_RETURN;
219 // Performace Counter support
220 void update_counters();
222 // Printing support
223 virtual const char* name() const { return _name; }
225 // Debugging support
226 // Save the tops of all spaces for later use during mangling.
227 void record_spaces_top() PRODUCT_RETURN;
228 };
230 #endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSOLDGEN_HPP