Fri, 19 Apr 2013 11:08:52 -0700
8010992: Remove calls to global ::operator new[] and new
Summary: disable use of global operator new and new[] which could cause unexpected exception and escape from NMT tracking.
Reviewed-by: coleenp, dholmes, zgu
Contributed-by: yumin.qi@oracle.com
duke@435 | 1 | /* |
never@3499 | 2 | * Copyright (c) 2000, 2012, Oracle and/or its affiliates. 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 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #include "precompiled.hpp" |
stefank@2314 | 26 | #include "classfile/symbolTable.hpp" |
stefank@2314 | 27 | #include "classfile/systemDictionary.hpp" |
stefank@2314 | 28 | #include "classfile/vmSymbols.hpp" |
stefank@2314 | 29 | #include "code/icBuffer.hpp" |
stefank@2314 | 30 | #include "gc_implementation/shared/collectorCounters.hpp" |
stefank@2314 | 31 | #include "gc_implementation/shared/vmGCOperations.hpp" |
stefank@2314 | 32 | #include "gc_interface/collectedHeap.inline.hpp" |
stefank@2314 | 33 | #include "memory/filemap.hpp" |
stefank@2314 | 34 | #include "memory/gcLocker.inline.hpp" |
stefank@2314 | 35 | #include "memory/genCollectedHeap.hpp" |
stefank@2314 | 36 | #include "memory/genOopClosures.inline.hpp" |
stefank@2314 | 37 | #include "memory/generation.inline.hpp" |
stefank@2314 | 38 | #include "memory/generationSpec.hpp" |
stefank@2314 | 39 | #include "memory/resourceArea.hpp" |
stefank@2314 | 40 | #include "memory/sharedHeap.hpp" |
stefank@2314 | 41 | #include "memory/space.hpp" |
stefank@2314 | 42 | #include "oops/oop.inline.hpp" |
stefank@2314 | 43 | #include "oops/oop.inline2.hpp" |
stefank@2314 | 44 | #include "runtime/aprofiler.hpp" |
stefank@2314 | 45 | #include "runtime/biasedLocking.hpp" |
stefank@2314 | 46 | #include "runtime/fprofiler.hpp" |
stefank@2314 | 47 | #include "runtime/handles.hpp" |
stefank@2314 | 48 | #include "runtime/handles.inline.hpp" |
stefank@2314 | 49 | #include "runtime/java.hpp" |
stefank@2314 | 50 | #include "runtime/vmThread.hpp" |
stefank@2314 | 51 | #include "services/memoryService.hpp" |
stefank@2314 | 52 | #include "utilities/vmError.hpp" |
stefank@2314 | 53 | #include "utilities/workgroup.hpp" |
jprovino@4542 | 54 | #include "utilities/macros.hpp" |
jprovino@4542 | 55 | #if INCLUDE_ALL_GCS |
stefank@2314 | 56 | #include "gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.hpp" |
stefank@2314 | 57 | #include "gc_implementation/concurrentMarkSweep/vmCMSOperations.hpp" |
jprovino@4542 | 58 | #endif // INCLUDE_ALL_GCS |
duke@435 | 59 | |
duke@435 | 60 | GenCollectedHeap* GenCollectedHeap::_gch; |
duke@435 | 61 | NOT_PRODUCT(size_t GenCollectedHeap::_skip_header_HeapWords = 0;) |
duke@435 | 62 | |
duke@435 | 63 | // The set of potentially parallel tasks in strong root scanning. |
duke@435 | 64 | enum GCH_process_strong_roots_tasks { |
duke@435 | 65 | // We probably want to parallelize both of these internally, but for now... |
duke@435 | 66 | GCH_PS_younger_gens, |
duke@435 | 67 | // Leave this one last. |
duke@435 | 68 | GCH_PS_NumElements |
duke@435 | 69 | }; |
duke@435 | 70 | |
duke@435 | 71 | GenCollectedHeap::GenCollectedHeap(GenCollectorPolicy *policy) : |
duke@435 | 72 | SharedHeap(policy), |
duke@435 | 73 | _gen_policy(policy), |
duke@435 | 74 | _gen_process_strong_tasks(new SubTasksDone(GCH_PS_NumElements)), |
duke@435 | 75 | _full_collections_completed(0) |
duke@435 | 76 | { |
duke@435 | 77 | if (_gen_process_strong_tasks == NULL || |
duke@435 | 78 | !_gen_process_strong_tasks->valid()) { |
duke@435 | 79 | vm_exit_during_initialization("Failed necessary allocation."); |
duke@435 | 80 | } |
duke@435 | 81 | assert(policy != NULL, "Sanity check"); |
duke@435 | 82 | } |
duke@435 | 83 | |
duke@435 | 84 | jint GenCollectedHeap::initialize() { |
ysr@1601 | 85 | CollectedHeap::pre_initialize(); |
ysr@1601 | 86 | |
duke@435 | 87 | int i; |
duke@435 | 88 | _n_gens = gen_policy()->number_of_generations(); |
duke@435 | 89 | |
duke@435 | 90 | // While there are no constraints in the GC code that HeapWordSize |
duke@435 | 91 | // be any particular value, there are multiple other areas in the |
duke@435 | 92 | // system which believe this to be true (e.g. oop->object_size in some |
duke@435 | 93 | // cases incorrectly returns the size in wordSize units rather than |
duke@435 | 94 | // HeapWordSize). |
duke@435 | 95 | guarantee(HeapWordSize == wordSize, "HeapWordSize must equal wordSize"); |
duke@435 | 96 | |
duke@435 | 97 | // The heap must be at least as aligned as generations. |
duke@435 | 98 | size_t alignment = Generation::GenGrain; |
duke@435 | 99 | |
duke@435 | 100 | _gen_specs = gen_policy()->generations(); |
duke@435 | 101 | |
duke@435 | 102 | // Make sure the sizes are all aligned. |
duke@435 | 103 | for (i = 0; i < _n_gens; i++) { |
duke@435 | 104 | _gen_specs[i]->align(alignment); |
duke@435 | 105 | } |
duke@435 | 106 | |
duke@435 | 107 | // Allocate space for the heap. |
duke@435 | 108 | |
duke@435 | 109 | char* heap_address; |
duke@435 | 110 | size_t total_reserved = 0; |
duke@435 | 111 | int n_covered_regions = 0; |
duke@435 | 112 | ReservedSpace heap_rs(0); |
duke@435 | 113 | |
coleenp@4037 | 114 | heap_address = allocate(alignment, &total_reserved, |
duke@435 | 115 | &n_covered_regions, &heap_rs); |
duke@435 | 116 | |
duke@435 | 117 | if (!heap_rs.is_reserved()) { |
duke@435 | 118 | vm_shutdown_during_initialization( |
duke@435 | 119 | "Could not reserve enough space for object heap"); |
duke@435 | 120 | return JNI_ENOMEM; |
duke@435 | 121 | } |
duke@435 | 122 | |
duke@435 | 123 | _reserved = MemRegion((HeapWord*)heap_rs.base(), |
duke@435 | 124 | (HeapWord*)(heap_rs.base() + heap_rs.size())); |
duke@435 | 125 | |
duke@435 | 126 | // It is important to do this in a way such that concurrent readers can't |
duke@435 | 127 | // temporarily think somethings in the heap. (Seen this happen in asserts.) |
duke@435 | 128 | _reserved.set_word_size(0); |
duke@435 | 129 | _reserved.set_start((HeapWord*)heap_rs.base()); |
coleenp@4037 | 130 | size_t actual_heap_size = heap_rs.size(); |
duke@435 | 131 | _reserved.set_end((HeapWord*)(heap_rs.base() + actual_heap_size)); |
duke@435 | 132 | |
duke@435 | 133 | _rem_set = collector_policy()->create_rem_set(_reserved, n_covered_regions); |
duke@435 | 134 | set_barrier_set(rem_set()->bs()); |
ysr@1601 | 135 | |
duke@435 | 136 | _gch = this; |
duke@435 | 137 | |
duke@435 | 138 | for (i = 0; i < _n_gens; i++) { |
coleenp@4037 | 139 | ReservedSpace this_rs = heap_rs.first_part(_gen_specs[i]->max_size(), false, false); |
duke@435 | 140 | _gens[i] = _gen_specs[i]->init(this_rs, i, rem_set()); |
duke@435 | 141 | heap_rs = heap_rs.last_part(_gen_specs[i]->max_size()); |
duke@435 | 142 | } |
ysr@2243 | 143 | clear_incremental_collection_failed(); |
duke@435 | 144 | |
jprovino@4542 | 145 | #if INCLUDE_ALL_GCS |
duke@435 | 146 | // If we are running CMS, create the collector responsible |
duke@435 | 147 | // for collecting the CMS generations. |
duke@435 | 148 | if (collector_policy()->is_concurrent_mark_sweep_policy()) { |
duke@435 | 149 | bool success = create_cms_collector(); |
duke@435 | 150 | if (!success) return JNI_ENOMEM; |
duke@435 | 151 | } |
jprovino@4542 | 152 | #endif // INCLUDE_ALL_GCS |
duke@435 | 153 | |
duke@435 | 154 | return JNI_OK; |
duke@435 | 155 | } |
duke@435 | 156 | |
duke@435 | 157 | |
duke@435 | 158 | char* GenCollectedHeap::allocate(size_t alignment, |
duke@435 | 159 | size_t* _total_reserved, |
duke@435 | 160 | int* _n_covered_regions, |
duke@435 | 161 | ReservedSpace* heap_rs){ |
duke@435 | 162 | const char overflow_msg[] = "The size of the object heap + VM data exceeds " |
duke@435 | 163 | "the maximum representable size"; |
duke@435 | 164 | |
duke@435 | 165 | // Now figure out the total size. |
duke@435 | 166 | size_t total_reserved = 0; |
duke@435 | 167 | int n_covered_regions = 0; |
duke@435 | 168 | const size_t pageSize = UseLargePages ? |
duke@435 | 169 | os::large_page_size() : os::vm_page_size(); |
duke@435 | 170 | |
duke@435 | 171 | for (int i = 0; i < _n_gens; i++) { |
duke@435 | 172 | total_reserved += _gen_specs[i]->max_size(); |
duke@435 | 173 | if (total_reserved < _gen_specs[i]->max_size()) { |
duke@435 | 174 | vm_exit_during_initialization(overflow_msg); |
duke@435 | 175 | } |
duke@435 | 176 | n_covered_regions += _gen_specs[i]->n_covered_regions(); |
duke@435 | 177 | } |
jcoomes@1981 | 178 | assert(total_reserved % pageSize == 0, |
jcoomes@1981 | 179 | err_msg("Gen size; total_reserved=" SIZE_FORMAT ", pageSize=" |
jcoomes@1981 | 180 | SIZE_FORMAT, total_reserved, pageSize)); |
duke@435 | 181 | |
coleenp@4037 | 182 | // Needed until the cardtable is fixed to have the right number |
coleenp@4037 | 183 | // of covered regions. |
coleenp@4037 | 184 | n_covered_regions += 2; |
duke@435 | 185 | |
duke@435 | 186 | if (UseLargePages) { |
duke@435 | 187 | assert(total_reserved != 0, "total_reserved cannot be 0"); |
duke@435 | 188 | total_reserved = round_to(total_reserved, os::large_page_size()); |
duke@435 | 189 | if (total_reserved < os::large_page_size()) { |
duke@435 | 190 | vm_exit_during_initialization(overflow_msg); |
duke@435 | 191 | } |
duke@435 | 192 | } |
duke@435 | 193 | |
kvn@1077 | 194 | *_total_reserved = total_reserved; |
kvn@1077 | 195 | *_n_covered_regions = n_covered_regions; |
coleenp@4037 | 196 | *heap_rs = Universe::reserve_heap(total_reserved, alignment); |
coleenp@4037 | 197 | return heap_rs->base(); |
duke@435 | 198 | } |
duke@435 | 199 | |
duke@435 | 200 | |
duke@435 | 201 | void GenCollectedHeap::post_initialize() { |
duke@435 | 202 | SharedHeap::post_initialize(); |
duke@435 | 203 | TwoGenerationCollectorPolicy *policy = |
duke@435 | 204 | (TwoGenerationCollectorPolicy *)collector_policy(); |
duke@435 | 205 | guarantee(policy->is_two_generation_policy(), "Illegal policy type"); |
duke@435 | 206 | DefNewGeneration* def_new_gen = (DefNewGeneration*) get_gen(0); |
duke@435 | 207 | assert(def_new_gen->kind() == Generation::DefNew || |
duke@435 | 208 | def_new_gen->kind() == Generation::ParNew || |
duke@435 | 209 | def_new_gen->kind() == Generation::ASParNew, |
duke@435 | 210 | "Wrong generation kind"); |
duke@435 | 211 | |
duke@435 | 212 | Generation* old_gen = get_gen(1); |
duke@435 | 213 | assert(old_gen->kind() == Generation::ConcurrentMarkSweep || |
duke@435 | 214 | old_gen->kind() == Generation::ASConcurrentMarkSweep || |
duke@435 | 215 | old_gen->kind() == Generation::MarkSweepCompact, |
duke@435 | 216 | "Wrong generation kind"); |
duke@435 | 217 | |
duke@435 | 218 | policy->initialize_size_policy(def_new_gen->eden()->capacity(), |
duke@435 | 219 | old_gen->capacity(), |
duke@435 | 220 | def_new_gen->from()->capacity()); |
duke@435 | 221 | policy->initialize_gc_policy_counters(); |
duke@435 | 222 | } |
duke@435 | 223 | |
duke@435 | 224 | void GenCollectedHeap::ref_processing_init() { |
duke@435 | 225 | SharedHeap::ref_processing_init(); |
duke@435 | 226 | for (int i = 0; i < _n_gens; i++) { |
duke@435 | 227 | _gens[i]->ref_processor_init(); |
duke@435 | 228 | } |
duke@435 | 229 | } |
duke@435 | 230 | |
duke@435 | 231 | size_t GenCollectedHeap::capacity() const { |
duke@435 | 232 | size_t res = 0; |
duke@435 | 233 | for (int i = 0; i < _n_gens; i++) { |
duke@435 | 234 | res += _gens[i]->capacity(); |
duke@435 | 235 | } |
duke@435 | 236 | return res; |
duke@435 | 237 | } |
duke@435 | 238 | |
duke@435 | 239 | size_t GenCollectedHeap::used() const { |
duke@435 | 240 | size_t res = 0; |
duke@435 | 241 | for (int i = 0; i < _n_gens; i++) { |
duke@435 | 242 | res += _gens[i]->used(); |
duke@435 | 243 | } |
duke@435 | 244 | return res; |
duke@435 | 245 | } |
duke@435 | 246 | |
coleenp@4037 | 247 | // Save the "used_region" for generations level and lower. |
coleenp@4037 | 248 | void GenCollectedHeap::save_used_regions(int level) { |
duke@435 | 249 | assert(level < _n_gens, "Illegal level parameter"); |
duke@435 | 250 | for (int i = level; i >= 0; i--) { |
duke@435 | 251 | _gens[i]->save_used_region(); |
duke@435 | 252 | } |
duke@435 | 253 | } |
duke@435 | 254 | |
duke@435 | 255 | size_t GenCollectedHeap::max_capacity() const { |
duke@435 | 256 | size_t res = 0; |
duke@435 | 257 | for (int i = 0; i < _n_gens; i++) { |
duke@435 | 258 | res += _gens[i]->max_capacity(); |
duke@435 | 259 | } |
duke@435 | 260 | return res; |
duke@435 | 261 | } |
duke@435 | 262 | |
duke@435 | 263 | // Update the _full_collections_completed counter |
duke@435 | 264 | // at the end of a stop-world full GC. |
duke@435 | 265 | unsigned int GenCollectedHeap::update_full_collections_completed() { |
duke@435 | 266 | MonitorLockerEx ml(FullGCCount_lock, Mutex::_no_safepoint_check_flag); |
duke@435 | 267 | assert(_full_collections_completed <= _total_full_collections, |
duke@435 | 268 | "Can't complete more collections than were started"); |
duke@435 | 269 | _full_collections_completed = _total_full_collections; |
duke@435 | 270 | ml.notify_all(); |
duke@435 | 271 | return _full_collections_completed; |
duke@435 | 272 | } |
duke@435 | 273 | |
duke@435 | 274 | // Update the _full_collections_completed counter, as appropriate, |
duke@435 | 275 | // at the end of a concurrent GC cycle. Note the conditional update |
duke@435 | 276 | // below to allow this method to be called by a concurrent collector |
duke@435 | 277 | // without synchronizing in any manner with the VM thread (which |
duke@435 | 278 | // may already have initiated a STW full collection "concurrently"). |
duke@435 | 279 | unsigned int GenCollectedHeap::update_full_collections_completed(unsigned int count) { |
duke@435 | 280 | MonitorLockerEx ml(FullGCCount_lock, Mutex::_no_safepoint_check_flag); |
duke@435 | 281 | assert((_full_collections_completed <= _total_full_collections) && |
duke@435 | 282 | (count <= _total_full_collections), |
duke@435 | 283 | "Can't complete more collections than were started"); |
duke@435 | 284 | if (count > _full_collections_completed) { |
duke@435 | 285 | _full_collections_completed = count; |
duke@435 | 286 | ml.notify_all(); |
duke@435 | 287 | } |
duke@435 | 288 | return _full_collections_completed; |
duke@435 | 289 | } |
duke@435 | 290 | |
duke@435 | 291 | |
duke@435 | 292 | #ifndef PRODUCT |
duke@435 | 293 | // Override of memory state checking method in CollectedHeap: |
duke@435 | 294 | // Some collectors (CMS for example) can't have badHeapWordVal written |
duke@435 | 295 | // in the first two words of an object. (For instance , in the case of |
duke@435 | 296 | // CMS these words hold state used to synchronize between certain |
duke@435 | 297 | // (concurrent) GC steps and direct allocating mutators.) |
duke@435 | 298 | // The skip_header_HeapWords() method below, allows us to skip |
duke@435 | 299 | // over the requisite number of HeapWord's. Note that (for |
duke@435 | 300 | // generational collectors) this means that those many words are |
duke@435 | 301 | // skipped in each object, irrespective of the generation in which |
duke@435 | 302 | // that object lives. The resultant loss of precision seems to be |
duke@435 | 303 | // harmless and the pain of avoiding that imprecision appears somewhat |
duke@435 | 304 | // higher than we are prepared to pay for such rudimentary debugging |
duke@435 | 305 | // support. |
duke@435 | 306 | void GenCollectedHeap::check_for_non_bad_heap_word_value(HeapWord* addr, |
duke@435 | 307 | size_t size) { |
duke@435 | 308 | if (CheckMemoryInitialization && ZapUnusedHeapArea) { |
duke@435 | 309 | // We are asked to check a size in HeapWords, |
duke@435 | 310 | // but the memory is mangled in juint words. |
duke@435 | 311 | juint* start = (juint*) (addr + skip_header_HeapWords()); |
duke@435 | 312 | juint* end = (juint*) (addr + size); |
duke@435 | 313 | for (juint* slot = start; slot < end; slot += 1) { |
duke@435 | 314 | assert(*slot == badHeapWordVal, |
duke@435 | 315 | "Found non badHeapWordValue in pre-allocation check"); |
duke@435 | 316 | } |
duke@435 | 317 | } |
duke@435 | 318 | } |
duke@435 | 319 | #endif |
duke@435 | 320 | |
duke@435 | 321 | HeapWord* GenCollectedHeap::attempt_allocation(size_t size, |
duke@435 | 322 | bool is_tlab, |
duke@435 | 323 | bool first_only) { |
duke@435 | 324 | HeapWord* res; |
duke@435 | 325 | for (int i = 0; i < _n_gens; i++) { |
duke@435 | 326 | if (_gens[i]->should_allocate(size, is_tlab)) { |
duke@435 | 327 | res = _gens[i]->allocate(size, is_tlab); |
duke@435 | 328 | if (res != NULL) return res; |
duke@435 | 329 | else if (first_only) break; |
duke@435 | 330 | } |
duke@435 | 331 | } |
duke@435 | 332 | // Otherwise... |
duke@435 | 333 | return NULL; |
duke@435 | 334 | } |
duke@435 | 335 | |
duke@435 | 336 | HeapWord* GenCollectedHeap::mem_allocate(size_t size, |
duke@435 | 337 | bool* gc_overhead_limit_was_exceeded) { |
duke@435 | 338 | return collector_policy()->mem_allocate_work(size, |
tonyp@2971 | 339 | false /* is_tlab */, |
duke@435 | 340 | gc_overhead_limit_was_exceeded); |
duke@435 | 341 | } |
duke@435 | 342 | |
duke@435 | 343 | bool GenCollectedHeap::must_clear_all_soft_refs() { |
duke@435 | 344 | return _gc_cause == GCCause::_last_ditch_collection; |
duke@435 | 345 | } |
duke@435 | 346 | |
duke@435 | 347 | bool GenCollectedHeap::should_do_concurrent_full_gc(GCCause::Cause cause) { |
ysr@1875 | 348 | return UseConcMarkSweepGC && |
ysr@1875 | 349 | ((cause == GCCause::_gc_locker && GCLockerInvokesConcurrent) || |
ysr@1875 | 350 | (cause == GCCause::_java_lang_system_gc && ExplicitGCInvokesConcurrent)); |
duke@435 | 351 | } |
duke@435 | 352 | |
duke@435 | 353 | void GenCollectedHeap::do_collection(bool full, |
duke@435 | 354 | bool clear_all_soft_refs, |
duke@435 | 355 | size_t size, |
duke@435 | 356 | bool is_tlab, |
duke@435 | 357 | int max_level) { |
duke@435 | 358 | bool prepared_for_verification = false; |
duke@435 | 359 | ResourceMark rm; |
duke@435 | 360 | DEBUG_ONLY(Thread* my_thread = Thread::current();) |
duke@435 | 361 | |
duke@435 | 362 | assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint"); |
duke@435 | 363 | assert(my_thread->is_VM_thread() || |
duke@435 | 364 | my_thread->is_ConcurrentGC_thread(), |
duke@435 | 365 | "incorrect thread type capability"); |
jmasa@1822 | 366 | assert(Heap_lock->is_locked(), |
jmasa@1822 | 367 | "the requesting thread should have the Heap_lock"); |
duke@435 | 368 | guarantee(!is_gc_active(), "collection is not reentrant"); |
duke@435 | 369 | assert(max_level < n_gens(), "sanity check"); |
duke@435 | 370 | |
duke@435 | 371 | if (GC_locker::check_active_before_gc()) { |
duke@435 | 372 | return; // GC is disabled (e.g. JNI GetXXXCritical operation) |
duke@435 | 373 | } |
duke@435 | 374 | |
jmasa@1822 | 375 | const bool do_clear_all_soft_refs = clear_all_soft_refs || |
jmasa@1822 | 376 | collector_policy()->should_clear_all_soft_refs(); |
jmasa@1822 | 377 | |
jmasa@1822 | 378 | ClearedAllSoftRefs casr(do_clear_all_soft_refs, collector_policy()); |
jmasa@1822 | 379 | |
coleenp@4037 | 380 | const size_t metadata_prev_used = MetaspaceAux::used_in_bytes(); |
duke@435 | 381 | |
never@3499 | 382 | print_heap_before_gc(); |
duke@435 | 383 | |
duke@435 | 384 | { |
duke@435 | 385 | FlagSetting fl(_is_gc_active, true); |
duke@435 | 386 | |
duke@435 | 387 | bool complete = full && (max_level == (n_gens()-1)); |
brutisso@3767 | 388 | const char* gc_cause_prefix = complete ? "Full GC" : "GC"; |
duke@435 | 389 | gclog_or_tty->date_stamp(PrintGC && PrintGCDateStamps); |
duke@435 | 390 | TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty); |
brutisso@3767 | 391 | TraceTime t(GCCauseString(gc_cause_prefix, gc_cause()), PrintGCDetails, false, gclog_or_tty); |
duke@435 | 392 | |
duke@435 | 393 | gc_prologue(complete); |
duke@435 | 394 | increment_total_collections(complete); |
duke@435 | 395 | |
duke@435 | 396 | size_t gch_prev_used = used(); |
duke@435 | 397 | |
duke@435 | 398 | int starting_level = 0; |
duke@435 | 399 | if (full) { |
duke@435 | 400 | // Search for the oldest generation which will collect all younger |
duke@435 | 401 | // generations, and start collection loop there. |
duke@435 | 402 | for (int i = max_level; i >= 0; i--) { |
duke@435 | 403 | if (_gens[i]->full_collects_younger_generations()) { |
duke@435 | 404 | starting_level = i; |
duke@435 | 405 | break; |
duke@435 | 406 | } |
duke@435 | 407 | } |
duke@435 | 408 | } |
duke@435 | 409 | |
duke@435 | 410 | bool must_restore_marks_for_biased_locking = false; |
duke@435 | 411 | |
duke@435 | 412 | int max_level_collected = starting_level; |
duke@435 | 413 | for (int i = starting_level; i <= max_level; i++) { |
duke@435 | 414 | if (_gens[i]->should_collect(full, size, is_tlab)) { |
dcubed@1315 | 415 | if (i == n_gens() - 1) { // a major collection is to happen |
dcubed@1315 | 416 | if (!complete) { |
dcubed@1315 | 417 | // The full_collections increment was missed above. |
dcubed@1315 | 418 | increment_total_full_collections(); |
dcubed@1315 | 419 | } |
ysr@1050 | 420 | pre_full_gc_dump(); // do any pre full gc dumps |
dcubed@1315 | 421 | } |
duke@435 | 422 | // Timer for individual generations. Last argument is false: no CR |
duke@435 | 423 | TraceTime t1(_gens[i]->short_name(), PrintGCDetails, false, gclog_or_tty); |
duke@435 | 424 | TraceCollectorStats tcs(_gens[i]->counters()); |
fparain@2888 | 425 | TraceMemoryManagerStats tmms(_gens[i]->kind(),gc_cause()); |
duke@435 | 426 | |
duke@435 | 427 | size_t prev_used = _gens[i]->used(); |
duke@435 | 428 | _gens[i]->stat_record()->invocations++; |
duke@435 | 429 | _gens[i]->stat_record()->accumulated_time.start(); |
duke@435 | 430 | |
jmasa@698 | 431 | // Must be done anew before each collection because |
jmasa@698 | 432 | // a previous collection will do mangling and will |
jmasa@698 | 433 | // change top of some spaces. |
jmasa@698 | 434 | record_gen_tops_before_GC(); |
jmasa@698 | 435 | |
duke@435 | 436 | if (PrintGC && Verbose) { |
duke@435 | 437 | gclog_or_tty->print("level=%d invoke=%d size=" SIZE_FORMAT, |
duke@435 | 438 | i, |
duke@435 | 439 | _gens[i]->stat_record()->invocations, |
duke@435 | 440 | size*HeapWordSize); |
duke@435 | 441 | } |
duke@435 | 442 | |
duke@435 | 443 | if (VerifyBeforeGC && i >= VerifyGCLevel && |
duke@435 | 444 | total_collections() >= VerifyGCStartAt) { |
duke@435 | 445 | HandleMark hm; // Discard invalid handles created during verification |
duke@435 | 446 | if (!prepared_for_verification) { |
duke@435 | 447 | prepare_for_verify(); |
duke@435 | 448 | prepared_for_verification = true; |
duke@435 | 449 | } |
duke@435 | 450 | gclog_or_tty->print(" VerifyBeforeGC:"); |
johnc@4176 | 451 | Universe::verify(); |
duke@435 | 452 | } |
duke@435 | 453 | COMPILER2_PRESENT(DerivedPointerTable::clear()); |
duke@435 | 454 | |
duke@435 | 455 | if (!must_restore_marks_for_biased_locking && |
duke@435 | 456 | _gens[i]->performs_in_place_marking()) { |
duke@435 | 457 | // We perform this mark word preservation work lazily |
duke@435 | 458 | // because it's only at this point that we know whether we |
duke@435 | 459 | // absolutely have to do it; we want to avoid doing it for |
duke@435 | 460 | // scavenge-only collections where it's unnecessary |
duke@435 | 461 | must_restore_marks_for_biased_locking = true; |
duke@435 | 462 | BiasedLocking::preserve_marks(); |
duke@435 | 463 | } |
duke@435 | 464 | |
duke@435 | 465 | // Do collection work |
duke@435 | 466 | { |
duke@435 | 467 | // Note on ref discovery: For what appear to be historical reasons, |
duke@435 | 468 | // GCH enables and disabled (by enqueing) refs discovery. |
duke@435 | 469 | // In the future this should be moved into the generation's |
duke@435 | 470 | // collect method so that ref discovery and enqueueing concerns |
duke@435 | 471 | // are local to a generation. The collect method could return |
duke@435 | 472 | // an appropriate indication in the case that notification on |
duke@435 | 473 | // the ref lock was needed. This will make the treatment of |
duke@435 | 474 | // weak refs more uniform (and indeed remove such concerns |
duke@435 | 475 | // from GCH). XXX |
duke@435 | 476 | |
duke@435 | 477 | HandleMark hm; // Discard invalid handles created during gc |
duke@435 | 478 | save_marks(); // save marks for all gens |
duke@435 | 479 | // We want to discover references, but not process them yet. |
duke@435 | 480 | // This mode is disabled in process_discovered_references if the |
duke@435 | 481 | // generation does some collection work, or in |
duke@435 | 482 | // enqueue_discovered_references if the generation returns |
duke@435 | 483 | // without doing any work. |
duke@435 | 484 | ReferenceProcessor* rp = _gens[i]->ref_processor(); |
duke@435 | 485 | // If the discovery of ("weak") refs in this generation is |
duke@435 | 486 | // atomic wrt other collectors in this configuration, we |
duke@435 | 487 | // are guaranteed to have empty discovered ref lists. |
duke@435 | 488 | if (rp->discovery_is_atomic()) { |
johnc@3175 | 489 | rp->enable_discovery(true /*verify_disabled*/, true /*verify_no_refs*/); |
jmasa@1822 | 490 | rp->setup_policy(do_clear_all_soft_refs); |
duke@435 | 491 | } else { |
ysr@888 | 492 | // collect() below will enable discovery as appropriate |
duke@435 | 493 | } |
jmasa@1822 | 494 | _gens[i]->collect(full, do_clear_all_soft_refs, size, is_tlab); |
duke@435 | 495 | if (!rp->enqueuing_is_done()) { |
duke@435 | 496 | rp->enqueue_discovered_references(); |
duke@435 | 497 | } else { |
duke@435 | 498 | rp->set_enqueuing_is_done(false); |
duke@435 | 499 | } |
duke@435 | 500 | rp->verify_no_references_recorded(); |
duke@435 | 501 | } |
duke@435 | 502 | max_level_collected = i; |
duke@435 | 503 | |
duke@435 | 504 | // Determine if allocation request was met. |
duke@435 | 505 | if (size > 0) { |
duke@435 | 506 | if (!is_tlab || _gens[i]->supports_tlab_allocation()) { |
duke@435 | 507 | if (size*HeapWordSize <= _gens[i]->unsafe_max_alloc_nogc()) { |
duke@435 | 508 | size = 0; |
duke@435 | 509 | } |
duke@435 | 510 | } |
duke@435 | 511 | } |
duke@435 | 512 | |
duke@435 | 513 | COMPILER2_PRESENT(DerivedPointerTable::update_pointers()); |
duke@435 | 514 | |
duke@435 | 515 | _gens[i]->stat_record()->accumulated_time.stop(); |
duke@435 | 516 | |
duke@435 | 517 | update_gc_stats(i, full); |
duke@435 | 518 | |
duke@435 | 519 | if (VerifyAfterGC && i >= VerifyGCLevel && |
duke@435 | 520 | total_collections() >= VerifyGCStartAt) { |
duke@435 | 521 | HandleMark hm; // Discard invalid handles created during verification |
duke@435 | 522 | gclog_or_tty->print(" VerifyAfterGC:"); |
johnc@4176 | 523 | Universe::verify(); |
duke@435 | 524 | } |
duke@435 | 525 | |
duke@435 | 526 | if (PrintGCDetails) { |
duke@435 | 527 | gclog_or_tty->print(":"); |
duke@435 | 528 | _gens[i]->print_heap_change(prev_used); |
duke@435 | 529 | } |
duke@435 | 530 | } |
duke@435 | 531 | } |
duke@435 | 532 | |
duke@435 | 533 | // Update "complete" boolean wrt what actually transpired -- |
duke@435 | 534 | // for instance, a promotion failure could have led to |
duke@435 | 535 | // a whole heap collection. |
duke@435 | 536 | complete = complete || (max_level_collected == n_gens() - 1); |
duke@435 | 537 | |
ysr@1050 | 538 | if (complete) { // We did a "major" collection |
ysr@1050 | 539 | post_full_gc_dump(); // do any post full gc dumps |
ysr@1050 | 540 | } |
ysr@1050 | 541 | |
duke@435 | 542 | if (PrintGCDetails) { |
duke@435 | 543 | print_heap_change(gch_prev_used); |
duke@435 | 544 | |
coleenp@4037 | 545 | // Print metaspace info for full GC with PrintGCDetails flag. |
duke@435 | 546 | if (complete) { |
coleenp@4037 | 547 | MetaspaceAux::print_metaspace_change(metadata_prev_used); |
duke@435 | 548 | } |
duke@435 | 549 | } |
duke@435 | 550 | |
duke@435 | 551 | for (int j = max_level_collected; j >= 0; j -= 1) { |
duke@435 | 552 | // Adjust generation sizes. |
duke@435 | 553 | _gens[j]->compute_new_size(); |
duke@435 | 554 | } |
duke@435 | 555 | |
duke@435 | 556 | if (complete) { |
mgerdin@4784 | 557 | // Delete metaspaces for unloaded class loaders and clean up loader_data graph |
mgerdin@4784 | 558 | ClassLoaderDataGraph::purge(); |
coleenp@4037 | 559 | // Resize the metaspace capacity after full collections |
coleenp@4037 | 560 | MetaspaceGC::compute_new_size(); |
duke@435 | 561 | update_full_collections_completed(); |
duke@435 | 562 | } |
duke@435 | 563 | |
duke@435 | 564 | // Track memory usage and detect low memory after GC finishes |
duke@435 | 565 | MemoryService::track_memory_usage(); |
duke@435 | 566 | |
duke@435 | 567 | gc_epilogue(complete); |
duke@435 | 568 | |
duke@435 | 569 | if (must_restore_marks_for_biased_locking) { |
duke@435 | 570 | BiasedLocking::restore_marks(); |
duke@435 | 571 | } |
duke@435 | 572 | } |
duke@435 | 573 | |
duke@435 | 574 | AdaptiveSizePolicy* sp = gen_policy()->size_policy(); |
duke@435 | 575 | AdaptiveSizePolicyOutput(sp, total_collections()); |
duke@435 | 576 | |
never@3499 | 577 | print_heap_after_gc(); |
duke@435 | 578 | |
jmasa@981 | 579 | #ifdef TRACESPINNING |
jmasa@981 | 580 | ParallelTaskTerminator::print_termination_counts(); |
jmasa@981 | 581 | #endif |
duke@435 | 582 | } |
duke@435 | 583 | |
duke@435 | 584 | HeapWord* GenCollectedHeap::satisfy_failed_allocation(size_t size, bool is_tlab) { |
duke@435 | 585 | return collector_policy()->satisfy_failed_allocation(size, is_tlab); |
duke@435 | 586 | } |
duke@435 | 587 | |
jmasa@3357 | 588 | void GenCollectedHeap::set_par_threads(uint t) { |
duke@435 | 589 | SharedHeap::set_par_threads(t); |
jmasa@2188 | 590 | _gen_process_strong_tasks->set_n_threads(t); |
duke@435 | 591 | } |
duke@435 | 592 | |
duke@435 | 593 | void GenCollectedHeap:: |
duke@435 | 594 | gen_process_strong_roots(int level, |
duke@435 | 595 | bool younger_gens_as_roots, |
jrose@1424 | 596 | bool activate_scope, |
coleenp@4037 | 597 | bool is_scavenging, |
duke@435 | 598 | SharedHeap::ScanningOption so, |
jrose@1424 | 599 | OopsInGenClosure* not_older_gens, |
jrose@1424 | 600 | bool do_code_roots, |
coleenp@4037 | 601 | OopsInGenClosure* older_gens, |
coleenp@4037 | 602 | KlassClosure* klass_closure) { |
duke@435 | 603 | // General strong roots. |
jrose@1424 | 604 | |
jrose@1424 | 605 | if (!do_code_roots) { |
coleenp@4037 | 606 | SharedHeap::process_strong_roots(activate_scope, is_scavenging, so, |
coleenp@4037 | 607 | not_older_gens, NULL, klass_closure); |
jrose@1424 | 608 | } else { |
jrose@1424 | 609 | bool do_code_marking = (activate_scope || nmethod::oops_do_marking_is_active()); |
jrose@1424 | 610 | CodeBlobToOopClosure code_roots(not_older_gens, /*do_marking=*/ do_code_marking); |
coleenp@4037 | 611 | SharedHeap::process_strong_roots(activate_scope, is_scavenging, so, |
coleenp@4037 | 612 | not_older_gens, &code_roots, klass_closure); |
jrose@1424 | 613 | } |
duke@435 | 614 | |
duke@435 | 615 | if (younger_gens_as_roots) { |
duke@435 | 616 | if (!_gen_process_strong_tasks->is_task_claimed(GCH_PS_younger_gens)) { |
duke@435 | 617 | for (int i = 0; i < level; i++) { |
duke@435 | 618 | not_older_gens->set_generation(_gens[i]); |
duke@435 | 619 | _gens[i]->oop_iterate(not_older_gens); |
duke@435 | 620 | } |
duke@435 | 621 | not_older_gens->reset_generation(); |
duke@435 | 622 | } |
duke@435 | 623 | } |
duke@435 | 624 | // When collection is parallel, all threads get to cooperate to do |
duke@435 | 625 | // older-gen scanning. |
duke@435 | 626 | for (int i = level+1; i < _n_gens; i++) { |
duke@435 | 627 | older_gens->set_generation(_gens[i]); |
duke@435 | 628 | rem_set()->younger_refs_iterate(_gens[i], older_gens); |
duke@435 | 629 | older_gens->reset_generation(); |
duke@435 | 630 | } |
duke@435 | 631 | |
duke@435 | 632 | _gen_process_strong_tasks->all_tasks_completed(); |
duke@435 | 633 | } |
duke@435 | 634 | |
duke@435 | 635 | void GenCollectedHeap::gen_process_weak_roots(OopClosure* root_closure, |
jrose@1424 | 636 | CodeBlobClosure* code_roots, |
duke@435 | 637 | OopClosure* non_root_closure) { |
jrose@1424 | 638 | SharedHeap::process_weak_roots(root_closure, code_roots, non_root_closure); |
duke@435 | 639 | // "Local" "weak" refs |
duke@435 | 640 | for (int i = 0; i < _n_gens; i++) { |
duke@435 | 641 | _gens[i]->ref_processor()->weak_oops_do(root_closure); |
duke@435 | 642 | } |
duke@435 | 643 | } |
duke@435 | 644 | |
duke@435 | 645 | #define GCH_SINCE_SAVE_MARKS_ITERATE_DEFN(OopClosureType, nv_suffix) \ |
duke@435 | 646 | void GenCollectedHeap:: \ |
duke@435 | 647 | oop_since_save_marks_iterate(int level, \ |
duke@435 | 648 | OopClosureType* cur, \ |
duke@435 | 649 | OopClosureType* older) { \ |
duke@435 | 650 | _gens[level]->oop_since_save_marks_iterate##nv_suffix(cur); \ |
duke@435 | 651 | for (int i = level+1; i < n_gens(); i++) { \ |
duke@435 | 652 | _gens[i]->oop_since_save_marks_iterate##nv_suffix(older); \ |
duke@435 | 653 | } \ |
duke@435 | 654 | } |
duke@435 | 655 | |
duke@435 | 656 | ALL_SINCE_SAVE_MARKS_CLOSURES(GCH_SINCE_SAVE_MARKS_ITERATE_DEFN) |
duke@435 | 657 | |
duke@435 | 658 | #undef GCH_SINCE_SAVE_MARKS_ITERATE_DEFN |
duke@435 | 659 | |
duke@435 | 660 | bool GenCollectedHeap::no_allocs_since_save_marks(int level) { |
duke@435 | 661 | for (int i = level; i < _n_gens; i++) { |
duke@435 | 662 | if (!_gens[i]->no_allocs_since_save_marks()) return false; |
duke@435 | 663 | } |
coleenp@4037 | 664 | return true; |
duke@435 | 665 | } |
duke@435 | 666 | |
duke@435 | 667 | bool GenCollectedHeap::supports_inline_contig_alloc() const { |
duke@435 | 668 | return _gens[0]->supports_inline_contig_alloc(); |
duke@435 | 669 | } |
duke@435 | 670 | |
duke@435 | 671 | HeapWord** GenCollectedHeap::top_addr() const { |
duke@435 | 672 | return _gens[0]->top_addr(); |
duke@435 | 673 | } |
duke@435 | 674 | |
duke@435 | 675 | HeapWord** GenCollectedHeap::end_addr() const { |
duke@435 | 676 | return _gens[0]->end_addr(); |
duke@435 | 677 | } |
duke@435 | 678 | |
duke@435 | 679 | size_t GenCollectedHeap::unsafe_max_alloc() { |
duke@435 | 680 | return _gens[0]->unsafe_max_alloc_nogc(); |
duke@435 | 681 | } |
duke@435 | 682 | |
duke@435 | 683 | // public collection interfaces |
duke@435 | 684 | |
duke@435 | 685 | void GenCollectedHeap::collect(GCCause::Cause cause) { |
duke@435 | 686 | if (should_do_concurrent_full_gc(cause)) { |
jprovino@4542 | 687 | #if INCLUDE_ALL_GCS |
duke@435 | 688 | // mostly concurrent full collection |
duke@435 | 689 | collect_mostly_concurrent(cause); |
jprovino@4542 | 690 | #else // INCLUDE_ALL_GCS |
duke@435 | 691 | ShouldNotReachHere(); |
jprovino@4542 | 692 | #endif // INCLUDE_ALL_GCS |
duke@435 | 693 | } else { |
duke@435 | 694 | #ifdef ASSERT |
duke@435 | 695 | if (cause == GCCause::_scavenge_alot) { |
duke@435 | 696 | // minor collection only |
duke@435 | 697 | collect(cause, 0); |
duke@435 | 698 | } else { |
duke@435 | 699 | // Stop-the-world full collection |
duke@435 | 700 | collect(cause, n_gens() - 1); |
duke@435 | 701 | } |
duke@435 | 702 | #else |
duke@435 | 703 | // Stop-the-world full collection |
duke@435 | 704 | collect(cause, n_gens() - 1); |
duke@435 | 705 | #endif |
duke@435 | 706 | } |
duke@435 | 707 | } |
duke@435 | 708 | |
duke@435 | 709 | void GenCollectedHeap::collect(GCCause::Cause cause, int max_level) { |
duke@435 | 710 | // The caller doesn't have the Heap_lock |
duke@435 | 711 | assert(!Heap_lock->owned_by_self(), "this thread should not own the Heap_lock"); |
duke@435 | 712 | MutexLocker ml(Heap_lock); |
duke@435 | 713 | collect_locked(cause, max_level); |
duke@435 | 714 | } |
duke@435 | 715 | |
duke@435 | 716 | void GenCollectedHeap::collect_locked(GCCause::Cause cause) { |
duke@435 | 717 | // The caller has the Heap_lock |
duke@435 | 718 | assert(Heap_lock->owned_by_self(), "this thread should own the Heap_lock"); |
duke@435 | 719 | collect_locked(cause, n_gens() - 1); |
duke@435 | 720 | } |
duke@435 | 721 | |
duke@435 | 722 | // this is the private collection interface |
duke@435 | 723 | // The Heap_lock is expected to be held on entry. |
duke@435 | 724 | |
duke@435 | 725 | void GenCollectedHeap::collect_locked(GCCause::Cause cause, int max_level) { |
duke@435 | 726 | // Read the GC count while holding the Heap_lock |
duke@435 | 727 | unsigned int gc_count_before = total_collections(); |
duke@435 | 728 | unsigned int full_gc_count_before = total_full_collections(); |
duke@435 | 729 | { |
duke@435 | 730 | MutexUnlocker mu(Heap_lock); // give up heap lock, execute gets it back |
duke@435 | 731 | VM_GenCollectFull op(gc_count_before, full_gc_count_before, |
duke@435 | 732 | cause, max_level); |
duke@435 | 733 | VMThread::execute(&op); |
duke@435 | 734 | } |
duke@435 | 735 | } |
duke@435 | 736 | |
jprovino@4542 | 737 | #if INCLUDE_ALL_GCS |
duke@435 | 738 | bool GenCollectedHeap::create_cms_collector() { |
duke@435 | 739 | |
duke@435 | 740 | assert(((_gens[1]->kind() == Generation::ConcurrentMarkSweep) || |
coleenp@4037 | 741 | (_gens[1]->kind() == Generation::ASConcurrentMarkSweep)), |
duke@435 | 742 | "Unexpected generation kinds"); |
duke@435 | 743 | // Skip two header words in the block content verification |
duke@435 | 744 | NOT_PRODUCT(_skip_header_HeapWords = CMSCollector::skip_header_HeapWords();) |
duke@435 | 745 | CMSCollector* collector = new CMSCollector( |
duke@435 | 746 | (ConcurrentMarkSweepGeneration*)_gens[1], |
duke@435 | 747 | _rem_set->as_CardTableRS(), |
duke@435 | 748 | (ConcurrentMarkSweepPolicy*) collector_policy()); |
duke@435 | 749 | |
duke@435 | 750 | if (collector == NULL || !collector->completed_initialization()) { |
duke@435 | 751 | if (collector) { |
duke@435 | 752 | delete collector; // Be nice in embedded situation |
duke@435 | 753 | } |
duke@435 | 754 | vm_shutdown_during_initialization("Could not create CMS collector"); |
duke@435 | 755 | return false; |
duke@435 | 756 | } |
duke@435 | 757 | return true; // success |
duke@435 | 758 | } |
duke@435 | 759 | |
duke@435 | 760 | void GenCollectedHeap::collect_mostly_concurrent(GCCause::Cause cause) { |
duke@435 | 761 | assert(!Heap_lock->owned_by_self(), "Should not own Heap_lock"); |
duke@435 | 762 | |
duke@435 | 763 | MutexLocker ml(Heap_lock); |
duke@435 | 764 | // Read the GC counts while holding the Heap_lock |
duke@435 | 765 | unsigned int full_gc_count_before = total_full_collections(); |
duke@435 | 766 | unsigned int gc_count_before = total_collections(); |
duke@435 | 767 | { |
duke@435 | 768 | MutexUnlocker mu(Heap_lock); |
duke@435 | 769 | VM_GenCollectFullConcurrent op(gc_count_before, full_gc_count_before, cause); |
duke@435 | 770 | VMThread::execute(&op); |
duke@435 | 771 | } |
duke@435 | 772 | } |
jprovino@4542 | 773 | #endif // INCLUDE_ALL_GCS |
duke@435 | 774 | |
coleenp@4037 | 775 | void GenCollectedHeap::do_full_collection(bool clear_all_soft_refs) { |
coleenp@4037 | 776 | do_full_collection(clear_all_soft_refs, _n_gens - 1); |
coleenp@4037 | 777 | } |
duke@435 | 778 | |
duke@435 | 779 | void GenCollectedHeap::do_full_collection(bool clear_all_soft_refs, |
duke@435 | 780 | int max_level) { |
duke@435 | 781 | int local_max_level; |
ysr@2336 | 782 | if (!incremental_collection_will_fail(false /* don't consult_young */) && |
duke@435 | 783 | gc_cause() == GCCause::_gc_locker) { |
duke@435 | 784 | local_max_level = 0; |
duke@435 | 785 | } else { |
duke@435 | 786 | local_max_level = max_level; |
duke@435 | 787 | } |
duke@435 | 788 | |
duke@435 | 789 | do_collection(true /* full */, |
duke@435 | 790 | clear_all_soft_refs /* clear_all_soft_refs */, |
duke@435 | 791 | 0 /* size */, |
duke@435 | 792 | false /* is_tlab */, |
duke@435 | 793 | local_max_level /* max_level */); |
duke@435 | 794 | // Hack XXX FIX ME !!! |
duke@435 | 795 | // A scavenge may not have been attempted, or may have |
duke@435 | 796 | // been attempted and failed, because the old gen was too full |
duke@435 | 797 | if (local_max_level == 0 && gc_cause() == GCCause::_gc_locker && |
ysr@2336 | 798 | incremental_collection_will_fail(false /* don't consult_young */)) { |
duke@435 | 799 | if (PrintGCDetails) { |
duke@435 | 800 | gclog_or_tty->print_cr("GC locker: Trying a full collection " |
duke@435 | 801 | "because scavenge failed"); |
duke@435 | 802 | } |
duke@435 | 803 | // This time allow the old gen to be collected as well |
duke@435 | 804 | do_collection(true /* full */, |
duke@435 | 805 | clear_all_soft_refs /* clear_all_soft_refs */, |
duke@435 | 806 | 0 /* size */, |
duke@435 | 807 | false /* is_tlab */, |
duke@435 | 808 | n_gens() - 1 /* max_level */); |
duke@435 | 809 | } |
duke@435 | 810 | } |
duke@435 | 811 | |
jmasa@2909 | 812 | bool GenCollectedHeap::is_in_young(oop p) { |
jmasa@2909 | 813 | bool result = ((HeapWord*)p) < _gens[_n_gens - 1]->reserved().start(); |
jmasa@2909 | 814 | assert(result == _gens[0]->is_in_reserved(p), |
jmasa@2909 | 815 | err_msg("incorrect test - result=%d, p=" PTR_FORMAT, result, (void*)p)); |
jmasa@2909 | 816 | return result; |
jmasa@2909 | 817 | } |
jmasa@2909 | 818 | |
stefank@3335 | 819 | // Returns "TRUE" iff "p" points into the committed areas of the heap. |
duke@435 | 820 | bool GenCollectedHeap::is_in(const void* p) const { |
duke@435 | 821 | #ifndef ASSERT |
johnc@4899 | 822 | guarantee(VerifyBeforeGC || |
johnc@4899 | 823 | VerifyDuringGC || |
johnc@4899 | 824 | VerifyBeforeExit || |
johnc@4899 | 825 | VerifyDuringStartup || |
johnc@4899 | 826 | PrintAssembly || |
johnc@4899 | 827 | tty->count() != 0 || // already printing |
johnc@4899 | 828 | VerifyAfterGC || |
bobv@2036 | 829 | VMError::fatal_error_in_progress(), "too expensive"); |
bobv@2036 | 830 | |
duke@435 | 831 | #endif |
duke@435 | 832 | // This might be sped up with a cache of the last generation that |
duke@435 | 833 | // answered yes. |
duke@435 | 834 | for (int i = 0; i < _n_gens; i++) { |
duke@435 | 835 | if (_gens[i]->is_in(p)) return true; |
duke@435 | 836 | } |
duke@435 | 837 | // Otherwise... |
duke@435 | 838 | return false; |
duke@435 | 839 | } |
duke@435 | 840 | |
jmasa@2909 | 841 | #ifdef ASSERT |
jmasa@2909 | 842 | // Don't implement this by using is_in_young(). This method is used |
jmasa@2909 | 843 | // in some cases to check that is_in_young() is correct. |
jmasa@2909 | 844 | bool GenCollectedHeap::is_in_partial_collection(const void* p) { |
jmasa@2909 | 845 | assert(is_in_reserved(p) || p == NULL, |
jmasa@2909 | 846 | "Does not work if address is non-null and outside of the heap"); |
jmasa@2909 | 847 | return p < _gens[_n_gens - 2]->reserved().end() && p != NULL; |
duke@435 | 848 | } |
jmasa@2909 | 849 | #endif |
duke@435 | 850 | |
coleenp@4037 | 851 | void GenCollectedHeap::oop_iterate(ExtendedOopClosure* cl) { |
duke@435 | 852 | for (int i = 0; i < _n_gens; i++) { |
duke@435 | 853 | _gens[i]->oop_iterate(cl); |
duke@435 | 854 | } |
duke@435 | 855 | } |
duke@435 | 856 | |
coleenp@4037 | 857 | void GenCollectedHeap::oop_iterate(MemRegion mr, ExtendedOopClosure* cl) { |
duke@435 | 858 | for (int i = 0; i < _n_gens; i++) { |
duke@435 | 859 | _gens[i]->oop_iterate(mr, cl); |
duke@435 | 860 | } |
duke@435 | 861 | } |
duke@435 | 862 | |
duke@435 | 863 | void GenCollectedHeap::object_iterate(ObjectClosure* cl) { |
duke@435 | 864 | for (int i = 0; i < _n_gens; i++) { |
duke@435 | 865 | _gens[i]->object_iterate(cl); |
duke@435 | 866 | } |
duke@435 | 867 | } |
duke@435 | 868 | |
jmasa@952 | 869 | void GenCollectedHeap::safe_object_iterate(ObjectClosure* cl) { |
jmasa@952 | 870 | for (int i = 0; i < _n_gens; i++) { |
jmasa@952 | 871 | _gens[i]->safe_object_iterate(cl); |
jmasa@952 | 872 | } |
jmasa@952 | 873 | } |
jmasa@952 | 874 | |
duke@435 | 875 | void GenCollectedHeap::object_iterate_since_last_GC(ObjectClosure* cl) { |
duke@435 | 876 | for (int i = 0; i < _n_gens; i++) { |
duke@435 | 877 | _gens[i]->object_iterate_since_last_GC(cl); |
duke@435 | 878 | } |
duke@435 | 879 | } |
duke@435 | 880 | |
duke@435 | 881 | Space* GenCollectedHeap::space_containing(const void* addr) const { |
duke@435 | 882 | for (int i = 0; i < _n_gens; i++) { |
duke@435 | 883 | Space* res = _gens[i]->space_containing(addr); |
duke@435 | 884 | if (res != NULL) return res; |
duke@435 | 885 | } |
duke@435 | 886 | // Otherwise... |
duke@435 | 887 | assert(false, "Could not find containing space"); |
duke@435 | 888 | return NULL; |
duke@435 | 889 | } |
duke@435 | 890 | |
duke@435 | 891 | |
duke@435 | 892 | HeapWord* GenCollectedHeap::block_start(const void* addr) const { |
duke@435 | 893 | assert(is_in_reserved(addr), "block_start of address outside of heap"); |
duke@435 | 894 | for (int i = 0; i < _n_gens; i++) { |
duke@435 | 895 | if (_gens[i]->is_in_reserved(addr)) { |
duke@435 | 896 | assert(_gens[i]->is_in(addr), |
duke@435 | 897 | "addr should be in allocated part of generation"); |
duke@435 | 898 | return _gens[i]->block_start(addr); |
duke@435 | 899 | } |
duke@435 | 900 | } |
duke@435 | 901 | assert(false, "Some generation should contain the address"); |
duke@435 | 902 | return NULL; |
duke@435 | 903 | } |
duke@435 | 904 | |
duke@435 | 905 | size_t GenCollectedHeap::block_size(const HeapWord* addr) const { |
duke@435 | 906 | assert(is_in_reserved(addr), "block_size of address outside of heap"); |
duke@435 | 907 | for (int i = 0; i < _n_gens; i++) { |
duke@435 | 908 | if (_gens[i]->is_in_reserved(addr)) { |
duke@435 | 909 | assert(_gens[i]->is_in(addr), |
duke@435 | 910 | "addr should be in allocated part of generation"); |
duke@435 | 911 | return _gens[i]->block_size(addr); |
duke@435 | 912 | } |
duke@435 | 913 | } |
duke@435 | 914 | assert(false, "Some generation should contain the address"); |
duke@435 | 915 | return 0; |
duke@435 | 916 | } |
duke@435 | 917 | |
duke@435 | 918 | bool GenCollectedHeap::block_is_obj(const HeapWord* addr) const { |
duke@435 | 919 | assert(is_in_reserved(addr), "block_is_obj of address outside of heap"); |
duke@435 | 920 | assert(block_start(addr) == addr, "addr must be a block start"); |
duke@435 | 921 | for (int i = 0; i < _n_gens; i++) { |
duke@435 | 922 | if (_gens[i]->is_in_reserved(addr)) { |
duke@435 | 923 | return _gens[i]->block_is_obj(addr); |
duke@435 | 924 | } |
duke@435 | 925 | } |
duke@435 | 926 | assert(false, "Some generation should contain the address"); |
duke@435 | 927 | return false; |
duke@435 | 928 | } |
duke@435 | 929 | |
duke@435 | 930 | bool GenCollectedHeap::supports_tlab_allocation() const { |
duke@435 | 931 | for (int i = 0; i < _n_gens; i += 1) { |
duke@435 | 932 | if (_gens[i]->supports_tlab_allocation()) { |
duke@435 | 933 | return true; |
duke@435 | 934 | } |
duke@435 | 935 | } |
duke@435 | 936 | return false; |
duke@435 | 937 | } |
duke@435 | 938 | |
duke@435 | 939 | size_t GenCollectedHeap::tlab_capacity(Thread* thr) const { |
duke@435 | 940 | size_t result = 0; |
duke@435 | 941 | for (int i = 0; i < _n_gens; i += 1) { |
duke@435 | 942 | if (_gens[i]->supports_tlab_allocation()) { |
duke@435 | 943 | result += _gens[i]->tlab_capacity(); |
duke@435 | 944 | } |
duke@435 | 945 | } |
duke@435 | 946 | return result; |
duke@435 | 947 | } |
duke@435 | 948 | |
duke@435 | 949 | size_t GenCollectedHeap::unsafe_max_tlab_alloc(Thread* thr) const { |
duke@435 | 950 | size_t result = 0; |
duke@435 | 951 | for (int i = 0; i < _n_gens; i += 1) { |
duke@435 | 952 | if (_gens[i]->supports_tlab_allocation()) { |
duke@435 | 953 | result += _gens[i]->unsafe_max_tlab_alloc(); |
duke@435 | 954 | } |
duke@435 | 955 | } |
duke@435 | 956 | return result; |
duke@435 | 957 | } |
duke@435 | 958 | |
duke@435 | 959 | HeapWord* GenCollectedHeap::allocate_new_tlab(size_t size) { |
duke@435 | 960 | bool gc_overhead_limit_was_exceeded; |
tonyp@2971 | 961 | return collector_policy()->mem_allocate_work(size /* size */, |
tonyp@2971 | 962 | true /* is_tlab */, |
tonyp@2971 | 963 | &gc_overhead_limit_was_exceeded); |
duke@435 | 964 | } |
duke@435 | 965 | |
duke@435 | 966 | // Requires "*prev_ptr" to be non-NULL. Deletes and a block of minimal size |
duke@435 | 967 | // from the list headed by "*prev_ptr". |
duke@435 | 968 | static ScratchBlock *removeSmallestScratch(ScratchBlock **prev_ptr) { |
duke@435 | 969 | bool first = true; |
duke@435 | 970 | size_t min_size = 0; // "first" makes this conceptually infinite. |
duke@435 | 971 | ScratchBlock **smallest_ptr, *smallest; |
duke@435 | 972 | ScratchBlock *cur = *prev_ptr; |
duke@435 | 973 | while (cur) { |
duke@435 | 974 | assert(*prev_ptr == cur, "just checking"); |
duke@435 | 975 | if (first || cur->num_words < min_size) { |
duke@435 | 976 | smallest_ptr = prev_ptr; |
duke@435 | 977 | smallest = cur; |
duke@435 | 978 | min_size = smallest->num_words; |
duke@435 | 979 | first = false; |
duke@435 | 980 | } |
duke@435 | 981 | prev_ptr = &cur->next; |
duke@435 | 982 | cur = cur->next; |
duke@435 | 983 | } |
duke@435 | 984 | smallest = *smallest_ptr; |
duke@435 | 985 | *smallest_ptr = smallest->next; |
duke@435 | 986 | return smallest; |
duke@435 | 987 | } |
duke@435 | 988 | |
duke@435 | 989 | // Sort the scratch block list headed by res into decreasing size order, |
duke@435 | 990 | // and set "res" to the result. |
duke@435 | 991 | static void sort_scratch_list(ScratchBlock*& list) { |
duke@435 | 992 | ScratchBlock* sorted = NULL; |
duke@435 | 993 | ScratchBlock* unsorted = list; |
duke@435 | 994 | while (unsorted) { |
duke@435 | 995 | ScratchBlock *smallest = removeSmallestScratch(&unsorted); |
duke@435 | 996 | smallest->next = sorted; |
duke@435 | 997 | sorted = smallest; |
duke@435 | 998 | } |
duke@435 | 999 | list = sorted; |
duke@435 | 1000 | } |
duke@435 | 1001 | |
duke@435 | 1002 | ScratchBlock* GenCollectedHeap::gather_scratch(Generation* requestor, |
duke@435 | 1003 | size_t max_alloc_words) { |
duke@435 | 1004 | ScratchBlock* res = NULL; |
duke@435 | 1005 | for (int i = 0; i < _n_gens; i++) { |
duke@435 | 1006 | _gens[i]->contribute_scratch(res, requestor, max_alloc_words); |
duke@435 | 1007 | } |
duke@435 | 1008 | sort_scratch_list(res); |
duke@435 | 1009 | return res; |
duke@435 | 1010 | } |
duke@435 | 1011 | |
jmasa@698 | 1012 | void GenCollectedHeap::release_scratch() { |
jmasa@698 | 1013 | for (int i = 0; i < _n_gens; i++) { |
jmasa@698 | 1014 | _gens[i]->reset_scratch(); |
jmasa@698 | 1015 | } |
jmasa@698 | 1016 | } |
jmasa@698 | 1017 | |
duke@435 | 1018 | class GenPrepareForVerifyClosure: public GenCollectedHeap::GenClosure { |
duke@435 | 1019 | void do_generation(Generation* gen) { |
duke@435 | 1020 | gen->prepare_for_verify(); |
duke@435 | 1021 | } |
duke@435 | 1022 | }; |
duke@435 | 1023 | |
duke@435 | 1024 | void GenCollectedHeap::prepare_for_verify() { |
duke@435 | 1025 | ensure_parsability(false); // no need to retire TLABs |
duke@435 | 1026 | GenPrepareForVerifyClosure blk; |
duke@435 | 1027 | generation_iterate(&blk, false); |
duke@435 | 1028 | } |
duke@435 | 1029 | |
duke@435 | 1030 | |
duke@435 | 1031 | void GenCollectedHeap::generation_iterate(GenClosure* cl, |
duke@435 | 1032 | bool old_to_young) { |
duke@435 | 1033 | if (old_to_young) { |
duke@435 | 1034 | for (int i = _n_gens-1; i >= 0; i--) { |
duke@435 | 1035 | cl->do_generation(_gens[i]); |
duke@435 | 1036 | } |
duke@435 | 1037 | } else { |
duke@435 | 1038 | for (int i = 0; i < _n_gens; i++) { |
duke@435 | 1039 | cl->do_generation(_gens[i]); |
duke@435 | 1040 | } |
duke@435 | 1041 | } |
duke@435 | 1042 | } |
duke@435 | 1043 | |
duke@435 | 1044 | void GenCollectedHeap::space_iterate(SpaceClosure* cl) { |
duke@435 | 1045 | for (int i = 0; i < _n_gens; i++) { |
duke@435 | 1046 | _gens[i]->space_iterate(cl, true); |
duke@435 | 1047 | } |
duke@435 | 1048 | } |
duke@435 | 1049 | |
duke@435 | 1050 | bool GenCollectedHeap::is_maximal_no_gc() const { |
coleenp@4037 | 1051 | for (int i = 0; i < _n_gens; i++) { |
duke@435 | 1052 | if (!_gens[i]->is_maximal_no_gc()) { |
duke@435 | 1053 | return false; |
duke@435 | 1054 | } |
duke@435 | 1055 | } |
duke@435 | 1056 | return true; |
duke@435 | 1057 | } |
duke@435 | 1058 | |
duke@435 | 1059 | void GenCollectedHeap::save_marks() { |
duke@435 | 1060 | for (int i = 0; i < _n_gens; i++) { |
duke@435 | 1061 | _gens[i]->save_marks(); |
duke@435 | 1062 | } |
duke@435 | 1063 | } |
duke@435 | 1064 | |
duke@435 | 1065 | void GenCollectedHeap::compute_new_generation_sizes(int collectedGen) { |
duke@435 | 1066 | for (int i = 0; i <= collectedGen; i++) { |
duke@435 | 1067 | _gens[i]->compute_new_size(); |
duke@435 | 1068 | } |
duke@435 | 1069 | } |
duke@435 | 1070 | |
duke@435 | 1071 | GenCollectedHeap* GenCollectedHeap::heap() { |
duke@435 | 1072 | assert(_gch != NULL, "Uninitialized access to GenCollectedHeap::heap()"); |
duke@435 | 1073 | assert(_gch->kind() == CollectedHeap::GenCollectedHeap, "not a generational heap"); |
duke@435 | 1074 | return _gch; |
duke@435 | 1075 | } |
duke@435 | 1076 | |
duke@435 | 1077 | |
duke@435 | 1078 | void GenCollectedHeap::prepare_for_compaction() { |
duke@435 | 1079 | Generation* scanning_gen = _gens[_n_gens-1]; |
duke@435 | 1080 | // Start by compacting into same gen. |
duke@435 | 1081 | CompactPoint cp(scanning_gen, NULL, NULL); |
duke@435 | 1082 | while (scanning_gen != NULL) { |
duke@435 | 1083 | scanning_gen->prepare_for_compaction(&cp); |
duke@435 | 1084 | scanning_gen = prev_gen(scanning_gen); |
duke@435 | 1085 | } |
duke@435 | 1086 | } |
duke@435 | 1087 | |
duke@435 | 1088 | GCStats* GenCollectedHeap::gc_stats(int level) const { |
duke@435 | 1089 | return _gens[level]->gc_stats(); |
duke@435 | 1090 | } |
duke@435 | 1091 | |
brutisso@3711 | 1092 | void GenCollectedHeap::verify(bool silent, VerifyOption option /* ignored */) { |
duke@435 | 1093 | for (int i = _n_gens-1; i >= 0; i--) { |
duke@435 | 1094 | Generation* g = _gens[i]; |
duke@435 | 1095 | if (!silent) { |
duke@435 | 1096 | gclog_or_tty->print(g->name()); |
duke@435 | 1097 | gclog_or_tty->print(" "); |
duke@435 | 1098 | } |
brutisso@3711 | 1099 | g->verify(); |
duke@435 | 1100 | } |
duke@435 | 1101 | if (!silent) { |
duke@435 | 1102 | gclog_or_tty->print("remset "); |
duke@435 | 1103 | } |
duke@435 | 1104 | rem_set()->verify(); |
duke@435 | 1105 | } |
duke@435 | 1106 | |
duke@435 | 1107 | void GenCollectedHeap::print_on(outputStream* st) const { |
duke@435 | 1108 | for (int i = 0; i < _n_gens; i++) { |
duke@435 | 1109 | _gens[i]->print_on(st); |
duke@435 | 1110 | } |
coleenp@4037 | 1111 | MetaspaceAux::print_on(st); |
duke@435 | 1112 | } |
duke@435 | 1113 | |
duke@435 | 1114 | void GenCollectedHeap::gc_threads_do(ThreadClosure* tc) const { |
duke@435 | 1115 | if (workers() != NULL) { |
duke@435 | 1116 | workers()->threads_do(tc); |
duke@435 | 1117 | } |
jprovino@4542 | 1118 | #if INCLUDE_ALL_GCS |
duke@435 | 1119 | if (UseConcMarkSweepGC) { |
duke@435 | 1120 | ConcurrentMarkSweepThread::threads_do(tc); |
duke@435 | 1121 | } |
jprovino@4542 | 1122 | #endif // INCLUDE_ALL_GCS |
duke@435 | 1123 | } |
duke@435 | 1124 | |
duke@435 | 1125 | void GenCollectedHeap::print_gc_threads_on(outputStream* st) const { |
jprovino@4542 | 1126 | #if INCLUDE_ALL_GCS |
duke@435 | 1127 | if (UseParNewGC) { |
duke@435 | 1128 | workers()->print_worker_threads_on(st); |
duke@435 | 1129 | } |
duke@435 | 1130 | if (UseConcMarkSweepGC) { |
duke@435 | 1131 | ConcurrentMarkSweepThread::print_all_on(st); |
duke@435 | 1132 | } |
jprovino@4542 | 1133 | #endif // INCLUDE_ALL_GCS |
duke@435 | 1134 | } |
duke@435 | 1135 | |
stefank@4904 | 1136 | void GenCollectedHeap::print_on_error(outputStream* st) const { |
stefank@4904 | 1137 | this->CollectedHeap::print_on_error(st); |
stefank@4904 | 1138 | |
stefank@4904 | 1139 | #if INCLUDE_ALL_GCS |
stefank@4904 | 1140 | if (UseConcMarkSweepGC) { |
stefank@4904 | 1141 | st->cr(); |
stefank@4904 | 1142 | CMSCollector::print_on_error(st); |
stefank@4904 | 1143 | } |
stefank@4904 | 1144 | #endif // INCLUDE_ALL_GCS |
stefank@4904 | 1145 | } |
stefank@4904 | 1146 | |
duke@435 | 1147 | void GenCollectedHeap::print_tracing_info() const { |
duke@435 | 1148 | if (TraceGen0Time) { |
duke@435 | 1149 | get_gen(0)->print_summary_info(); |
duke@435 | 1150 | } |
duke@435 | 1151 | if (TraceGen1Time) { |
duke@435 | 1152 | get_gen(1)->print_summary_info(); |
duke@435 | 1153 | } |
duke@435 | 1154 | } |
duke@435 | 1155 | |
duke@435 | 1156 | void GenCollectedHeap::print_heap_change(size_t prev_used) const { |
duke@435 | 1157 | if (PrintGCDetails && Verbose) { |
duke@435 | 1158 | gclog_or_tty->print(" " SIZE_FORMAT |
duke@435 | 1159 | "->" SIZE_FORMAT |
duke@435 | 1160 | "(" SIZE_FORMAT ")", |
duke@435 | 1161 | prev_used, used(), capacity()); |
duke@435 | 1162 | } else { |
duke@435 | 1163 | gclog_or_tty->print(" " SIZE_FORMAT "K" |
duke@435 | 1164 | "->" SIZE_FORMAT "K" |
duke@435 | 1165 | "(" SIZE_FORMAT "K)", |
duke@435 | 1166 | prev_used / K, used() / K, capacity() / K); |
duke@435 | 1167 | } |
duke@435 | 1168 | } |
duke@435 | 1169 | |
duke@435 | 1170 | class GenGCPrologueClosure: public GenCollectedHeap::GenClosure { |
duke@435 | 1171 | private: |
duke@435 | 1172 | bool _full; |
duke@435 | 1173 | public: |
duke@435 | 1174 | void do_generation(Generation* gen) { |
duke@435 | 1175 | gen->gc_prologue(_full); |
duke@435 | 1176 | } |
duke@435 | 1177 | GenGCPrologueClosure(bool full) : _full(full) {}; |
duke@435 | 1178 | }; |
duke@435 | 1179 | |
duke@435 | 1180 | void GenCollectedHeap::gc_prologue(bool full) { |
duke@435 | 1181 | assert(InlineCacheBuffer::is_empty(), "should have cleaned up ICBuffer"); |
duke@435 | 1182 | |
duke@435 | 1183 | always_do_update_barrier = false; |
duke@435 | 1184 | // Fill TLAB's and such |
duke@435 | 1185 | CollectedHeap::accumulate_statistics_all_tlabs(); |
duke@435 | 1186 | ensure_parsability(true); // retire TLABs |
duke@435 | 1187 | |
duke@435 | 1188 | // Call allocation profiler |
duke@435 | 1189 | AllocationProfiler::iterate_since_last_gc(); |
duke@435 | 1190 | // Walk generations |
duke@435 | 1191 | GenGCPrologueClosure blk(full); |
duke@435 | 1192 | generation_iterate(&blk, false); // not old-to-young. |
duke@435 | 1193 | }; |
duke@435 | 1194 | |
duke@435 | 1195 | class GenGCEpilogueClosure: public GenCollectedHeap::GenClosure { |
duke@435 | 1196 | private: |
duke@435 | 1197 | bool _full; |
duke@435 | 1198 | public: |
duke@435 | 1199 | void do_generation(Generation* gen) { |
duke@435 | 1200 | gen->gc_epilogue(_full); |
duke@435 | 1201 | } |
duke@435 | 1202 | GenGCEpilogueClosure(bool full) : _full(full) {}; |
duke@435 | 1203 | }; |
duke@435 | 1204 | |
duke@435 | 1205 | void GenCollectedHeap::gc_epilogue(bool full) { |
duke@435 | 1206 | #ifdef COMPILER2 |
duke@435 | 1207 | assert(DerivedPointerTable::is_empty(), "derived pointer present"); |
duke@435 | 1208 | size_t actual_gap = pointer_delta((HeapWord*) (max_uintx-3), *(end_addr())); |
duke@435 | 1209 | guarantee(actual_gap > (size_t)FastAllocateSizeLimit, "inline allocation wraps"); |
duke@435 | 1210 | #endif /* COMPILER2 */ |
duke@435 | 1211 | |
duke@435 | 1212 | resize_all_tlabs(); |
duke@435 | 1213 | |
duke@435 | 1214 | GenGCEpilogueClosure blk(full); |
duke@435 | 1215 | generation_iterate(&blk, false); // not old-to-young. |
duke@435 | 1216 | |
jcoomes@2996 | 1217 | if (!CleanChunkPoolAsync) { |
jcoomes@2996 | 1218 | Chunk::clean_chunk_pool(); |
jcoomes@2996 | 1219 | } |
jcoomes@2996 | 1220 | |
coleenp@4037 | 1221 | MetaspaceCounters::update_performance_counters(); |
coleenp@4037 | 1222 | |
duke@435 | 1223 | always_do_update_barrier = UseConcMarkSweepGC; |
duke@435 | 1224 | }; |
duke@435 | 1225 | |
jmasa@698 | 1226 | #ifndef PRODUCT |
jmasa@698 | 1227 | class GenGCSaveTopsBeforeGCClosure: public GenCollectedHeap::GenClosure { |
jmasa@698 | 1228 | private: |
jmasa@698 | 1229 | public: |
jmasa@698 | 1230 | void do_generation(Generation* gen) { |
jmasa@698 | 1231 | gen->record_spaces_top(); |
jmasa@698 | 1232 | } |
jmasa@698 | 1233 | }; |
jmasa@698 | 1234 | |
jmasa@698 | 1235 | void GenCollectedHeap::record_gen_tops_before_GC() { |
jmasa@698 | 1236 | if (ZapUnusedHeapArea) { |
jmasa@698 | 1237 | GenGCSaveTopsBeforeGCClosure blk; |
jmasa@698 | 1238 | generation_iterate(&blk, false); // not old-to-young. |
jmasa@698 | 1239 | } |
jmasa@698 | 1240 | } |
jmasa@698 | 1241 | #endif // not PRODUCT |
jmasa@698 | 1242 | |
duke@435 | 1243 | class GenEnsureParsabilityClosure: public GenCollectedHeap::GenClosure { |
duke@435 | 1244 | public: |
duke@435 | 1245 | void do_generation(Generation* gen) { |
duke@435 | 1246 | gen->ensure_parsability(); |
duke@435 | 1247 | } |
duke@435 | 1248 | }; |
duke@435 | 1249 | |
duke@435 | 1250 | void GenCollectedHeap::ensure_parsability(bool retire_tlabs) { |
duke@435 | 1251 | CollectedHeap::ensure_parsability(retire_tlabs); |
duke@435 | 1252 | GenEnsureParsabilityClosure ep_cl; |
duke@435 | 1253 | generation_iterate(&ep_cl, false); |
duke@435 | 1254 | } |
duke@435 | 1255 | |
duke@435 | 1256 | oop GenCollectedHeap::handle_failed_promotion(Generation* gen, |
duke@435 | 1257 | oop obj, |
coleenp@548 | 1258 | size_t obj_size) { |
duke@435 | 1259 | assert(obj_size == (size_t)obj->size(), "bad obj_size passed in"); |
duke@435 | 1260 | HeapWord* result = NULL; |
duke@435 | 1261 | |
duke@435 | 1262 | // First give each higher generation a chance to allocate the promoted object. |
duke@435 | 1263 | Generation* allocator = next_gen(gen); |
duke@435 | 1264 | if (allocator != NULL) { |
duke@435 | 1265 | do { |
duke@435 | 1266 | result = allocator->allocate(obj_size, false); |
duke@435 | 1267 | } while (result == NULL && (allocator = next_gen(allocator)) != NULL); |
duke@435 | 1268 | } |
duke@435 | 1269 | |
duke@435 | 1270 | if (result == NULL) { |
duke@435 | 1271 | // Then give gen and higher generations a chance to expand and allocate the |
duke@435 | 1272 | // object. |
duke@435 | 1273 | do { |
duke@435 | 1274 | result = gen->expand_and_allocate(obj_size, false); |
duke@435 | 1275 | } while (result == NULL && (gen = next_gen(gen)) != NULL); |
duke@435 | 1276 | } |
duke@435 | 1277 | |
duke@435 | 1278 | if (result != NULL) { |
duke@435 | 1279 | Copy::aligned_disjoint_words((HeapWord*)obj, result, obj_size); |
duke@435 | 1280 | } |
duke@435 | 1281 | return oop(result); |
duke@435 | 1282 | } |
duke@435 | 1283 | |
duke@435 | 1284 | class GenTimeOfLastGCClosure: public GenCollectedHeap::GenClosure { |
duke@435 | 1285 | jlong _time; // in ms |
duke@435 | 1286 | jlong _now; // in ms |
duke@435 | 1287 | |
duke@435 | 1288 | public: |
duke@435 | 1289 | GenTimeOfLastGCClosure(jlong now) : _time(now), _now(now) { } |
duke@435 | 1290 | |
duke@435 | 1291 | jlong time() { return _time; } |
duke@435 | 1292 | |
duke@435 | 1293 | void do_generation(Generation* gen) { |
duke@435 | 1294 | _time = MIN2(_time, gen->time_of_last_gc(_now)); |
duke@435 | 1295 | } |
duke@435 | 1296 | }; |
duke@435 | 1297 | |
duke@435 | 1298 | jlong GenCollectedHeap::millis_since_last_gc() { |
johnc@3339 | 1299 | // We need a monotonically non-deccreasing time in ms but |
johnc@3339 | 1300 | // os::javaTimeMillis() does not guarantee monotonicity. |
johnc@3339 | 1301 | jlong now = os::javaTimeNanos() / NANOSECS_PER_MILLISEC; |
duke@435 | 1302 | GenTimeOfLastGCClosure tolgc_cl(now); |
duke@435 | 1303 | // iterate over generations getting the oldest |
duke@435 | 1304 | // time that a generation was collected |
duke@435 | 1305 | generation_iterate(&tolgc_cl, false); |
johnc@3339 | 1306 | |
johnc@3339 | 1307 | // javaTimeNanos() is guaranteed to be monotonically non-decreasing |
johnc@3339 | 1308 | // provided the underlying platform provides such a time source |
johnc@3339 | 1309 | // (and it is bug free). So we still have to guard against getting |
johnc@3339 | 1310 | // back a time later than 'now'. |
duke@435 | 1311 | jlong retVal = now - tolgc_cl.time(); |
duke@435 | 1312 | if (retVal < 0) { |
johnc@3339 | 1313 | NOT_PRODUCT(warning("time warp: "INT64_FORMAT, retVal);) |
duke@435 | 1314 | return 0; |
duke@435 | 1315 | } |
duke@435 | 1316 | return retVal; |
duke@435 | 1317 | } |