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

Sat, 19 Jul 2008 17:38:22 -0400

author
coleenp
date
Sat, 19 Jul 2008 17:38:22 -0400
changeset 672
1fdb98a17101
parent 631
d1605aabd0a1
child 704
850fdf70db2b
permissions
-rw-r--r--

6716785: implicit null checks not triggering with CompressedOops
Summary: allocate alignment-sized page(s) below java heap so that memory accesses at heap_base+1page give signal and cause an implicit null check
Reviewed-by: kvn, jmasa, phh, jcoomes

duke@435 1 /*
xdono@631 2 * Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 class AdjoiningGenerations;
duke@435 26 class GCTaskManager;
duke@435 27 class PSAdaptiveSizePolicy;
duke@435 28
duke@435 29 class ParallelScavengeHeap : public CollectedHeap {
duke@435 30 friend class VMStructs;
duke@435 31 private:
duke@435 32 static PSYoungGen* _young_gen;
duke@435 33 static PSOldGen* _old_gen;
duke@435 34 static PSPermGen* _perm_gen;
duke@435 35
duke@435 36 // Sizing policy for entire heap
duke@435 37 static PSAdaptiveSizePolicy* _size_policy;
duke@435 38 static PSGCAdaptivePolicyCounters* _gc_policy_counters;
duke@435 39
duke@435 40 static ParallelScavengeHeap* _psh;
duke@435 41
duke@435 42 size_t _perm_gen_alignment;
duke@435 43 size_t _young_gen_alignment;
duke@435 44 size_t _old_gen_alignment;
duke@435 45
duke@435 46 inline size_t set_alignment(size_t& var, size_t val);
duke@435 47
duke@435 48 // Collection of generations that are adjacent in the
duke@435 49 // space reserved for the heap.
duke@435 50 AdjoiningGenerations* _gens;
duke@435 51
duke@435 52 static GCTaskManager* _gc_task_manager; // The task manager.
duke@435 53
duke@435 54 protected:
duke@435 55 static inline size_t total_invocations();
duke@435 56 HeapWord* allocate_new_tlab(size_t size);
duke@435 57 void fill_all_tlabs(bool retire);
duke@435 58
duke@435 59 public:
duke@435 60 ParallelScavengeHeap() : CollectedHeap() {
jmasa@448 61 set_alignment(_perm_gen_alignment, intra_heap_alignment());
jmasa@448 62 set_alignment(_young_gen_alignment, intra_heap_alignment());
jmasa@448 63 set_alignment(_old_gen_alignment, intra_heap_alignment());
duke@435 64 }
duke@435 65
duke@435 66 // For use by VM operations
duke@435 67 enum CollectionType {
duke@435 68 Scavenge,
duke@435 69 MarkSweep
duke@435 70 };
duke@435 71
duke@435 72 ParallelScavengeHeap::Name kind() const {
duke@435 73 return CollectedHeap::ParallelScavengeHeap;
duke@435 74 }
duke@435 75
duke@435 76 static PSYoungGen* young_gen() { return _young_gen; }
duke@435 77 static PSOldGen* old_gen() { return _old_gen; }
duke@435 78 static PSPermGen* perm_gen() { return _perm_gen; }
duke@435 79
duke@435 80 virtual PSAdaptiveSizePolicy* size_policy() { return _size_policy; }
duke@435 81
duke@435 82 static PSGCAdaptivePolicyCounters* gc_policy_counters() { return _gc_policy_counters; }
duke@435 83
duke@435 84 static ParallelScavengeHeap* heap();
duke@435 85
duke@435 86 static GCTaskManager* const gc_task_manager() { return _gc_task_manager; }
duke@435 87
duke@435 88 AdjoiningGenerations* gens() { return _gens; }
duke@435 89
duke@435 90 // Returns JNI_OK on success
duke@435 91 virtual jint initialize();
duke@435 92
duke@435 93 void post_initialize();
duke@435 94 void update_counters();
duke@435 95 // The alignment used for the various generations.
duke@435 96 size_t perm_gen_alignment() const { return _perm_gen_alignment; }
duke@435 97 size_t young_gen_alignment() const { return _young_gen_alignment; }
duke@435 98 size_t old_gen_alignment() const { return _old_gen_alignment; }
duke@435 99
jmasa@448 100 // The alignment used for eden and survivors within the young gen
jmasa@448 101 // and for boundary between young gen and old gen.
jmasa@448 102 size_t intra_heap_alignment() const { return 64 * K; }
duke@435 103
duke@435 104 size_t capacity() const;
duke@435 105 size_t used() const;
duke@435 106
duke@435 107 // Return "true" if all generations (but perm) have reached the
duke@435 108 // maximal committed limit that they can reach, without a garbage
duke@435 109 // collection.
duke@435 110 virtual bool is_maximal_no_gc() const;
duke@435 111
duke@435 112 // Does this heap support heap inspection? (+PrintClassHistogram)
duke@435 113 bool supports_heap_inspection() const { return true; }
duke@435 114
duke@435 115 size_t permanent_capacity() const;
duke@435 116 size_t permanent_used() const;
duke@435 117
duke@435 118 size_t max_capacity() const;
duke@435 119
duke@435 120 // Whether p is in the allocated part of the heap
duke@435 121 bool is_in(const void* p) const;
duke@435 122
duke@435 123 bool is_in_reserved(const void* p) const;
duke@435 124 bool is_in_permanent(const void *p) const { // reserved part
duke@435 125 return perm_gen()->reserved().contains(p);
duke@435 126 }
duke@435 127
duke@435 128 bool is_permanent(const void *p) const { // committed part
duke@435 129 return perm_gen()->is_in(p);
duke@435 130 }
duke@435 131
duke@435 132 static bool is_in_young(oop *p); // reserved part
duke@435 133 static bool is_in_old_or_perm(oop *p); // reserved part
duke@435 134
duke@435 135 // Memory allocation. "gc_time_limit_was_exceeded" will
duke@435 136 // be set to true if the adaptive size policy determine that
duke@435 137 // an excessive amount of time is being spent doing collections
duke@435 138 // and caused a NULL to be returned. If a NULL is not returned,
duke@435 139 // "gc_time_limit_was_exceeded" has an undefined meaning.
duke@435 140
duke@435 141 HeapWord* mem_allocate(size_t size,
duke@435 142 bool is_noref,
duke@435 143 bool is_tlab,
duke@435 144 bool* gc_overhead_limit_was_exceeded);
duke@435 145 HeapWord* failed_mem_allocate(size_t size, bool is_tlab);
duke@435 146
duke@435 147 HeapWord* permanent_mem_allocate(size_t size);
duke@435 148 HeapWord* failed_permanent_mem_allocate(size_t size);
duke@435 149
duke@435 150 // Support for System.gc()
duke@435 151 void collect(GCCause::Cause cause);
duke@435 152
duke@435 153 // This interface assumes that it's being called by the
duke@435 154 // vm thread. It collects the heap assuming that the
duke@435 155 // heap lock is already held and that we are executing in
duke@435 156 // the context of the vm thread.
duke@435 157 void collect_as_vm_thread(GCCause::Cause cause);
duke@435 158
duke@435 159 // These also should be called by the vm thread at a safepoint (e.g., from a
duke@435 160 // VM operation).
duke@435 161 //
duke@435 162 // The first collects the young generation only, unless the scavenge fails; it
duke@435 163 // will then attempt a full gc. The second collects the entire heap; if
duke@435 164 // maximum_compaction is true, it will compact everything and clear all soft
duke@435 165 // references.
duke@435 166 inline void invoke_scavenge();
duke@435 167 inline void invoke_full_gc(bool maximum_compaction);
duke@435 168
duke@435 169 size_t large_typearray_limit() { return FastAllocateSizeLimit; }
duke@435 170
duke@435 171 bool supports_inline_contig_alloc() const { return !UseNUMA; }
iveresov@576 172
iveresov@576 173 HeapWord** top_addr() const { return !UseNUMA ? young_gen()->top_addr() : (HeapWord**)-1; }
iveresov@576 174 HeapWord** end_addr() const { return !UseNUMA ? young_gen()->end_addr() : (HeapWord**)-1; }
duke@435 175
duke@435 176 void ensure_parsability(bool retire_tlabs);
duke@435 177 void accumulate_statistics_all_tlabs();
duke@435 178 void resize_all_tlabs();
duke@435 179
duke@435 180 size_t unsafe_max_alloc();
duke@435 181
duke@435 182 bool supports_tlab_allocation() const { return true; }
duke@435 183
duke@435 184 size_t tlab_capacity(Thread* thr) const;
duke@435 185 size_t unsafe_max_tlab_alloc(Thread* thr) const;
duke@435 186
duke@435 187 void oop_iterate(OopClosure* cl);
duke@435 188 void object_iterate(ObjectClosure* cl);
duke@435 189 void permanent_oop_iterate(OopClosure* cl);
duke@435 190 void permanent_object_iterate(ObjectClosure* cl);
duke@435 191
duke@435 192 HeapWord* block_start(const void* addr) const;
duke@435 193 size_t block_size(const HeapWord* addr) const;
duke@435 194 bool block_is_obj(const HeapWord* addr) const;
duke@435 195
duke@435 196 jlong millis_since_last_gc();
duke@435 197
duke@435 198 void prepare_for_verify();
duke@435 199 void print() const;
duke@435 200 void print_on(outputStream* st) const;
duke@435 201 virtual void print_gc_threads_on(outputStream* st) const;
duke@435 202 virtual void gc_threads_do(ThreadClosure* tc) const;
duke@435 203 virtual void print_tracing_info() const;
duke@435 204
duke@435 205 void verify(bool allow_dirty, bool silent);
duke@435 206
duke@435 207 void print_heap_change(size_t prev_used);
duke@435 208
duke@435 209 // Resize the young generation. The reserved space for the
duke@435 210 // generation may be expanded in preparation for the resize.
duke@435 211 void resize_young_gen(size_t eden_size, size_t survivor_size);
duke@435 212
duke@435 213 // Resize the old generation. The reserved space for the
duke@435 214 // generation may be expanded in preparation for the resize.
duke@435 215 void resize_old_gen(size_t desired_free_space);
duke@435 216 };
duke@435 217
duke@435 218 inline size_t ParallelScavengeHeap::set_alignment(size_t& var, size_t val)
duke@435 219 {
duke@435 220 assert(is_power_of_2((intptr_t)val), "must be a power of 2");
jmasa@448 221 var = round_to(val, intra_heap_alignment());
duke@435 222 return var;
duke@435 223 }

mercurial