src/share/vm/memory/sharedHeap.cpp

Mon, 23 Mar 2020 17:57:13 +0000

author
poonam
date
Mon, 23 Mar 2020 17:57:13 +0000
changeset 9965
c39172598323
parent 7659
38d6febe66af
child 7994
04ff2f6cd0eb
permissions
-rw-r--r--

8231779: crash HeapWord*ParallelScavengeHeap::failed_mem_allocate
Reviewed-by: dlong, tschatzl, pliden

duke@435 1 /*
drchase@6680 2 * Copyright (c) 2000, 2014, 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 "code/codeCache.hpp"
stefank@2314 29 #include "gc_interface/collectedHeap.inline.hpp"
stefank@2314 30 #include "memory/sharedHeap.hpp"
stefank@2314 31 #include "oops/oop.inline.hpp"
stefank@6992 32 #include "runtime/atomic.inline.hpp"
stefank@2314 33 #include "runtime/fprofiler.hpp"
stefank@2314 34 #include "runtime/java.hpp"
stefank@2314 35 #include "utilities/copy.hpp"
stefank@2314 36 #include "utilities/workgroup.hpp"
duke@435 37
drchase@6680 38 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
drchase@6680 39
duke@435 40 SharedHeap* SharedHeap::_sh;
duke@435 41
duke@435 42 SharedHeap::SharedHeap(CollectorPolicy* policy_) :
duke@435 43 CollectedHeap(),
duke@435 44 _collector_policy(policy_),
coleenp@4037 45 _rem_set(NULL),
duke@435 46 _strong_roots_parity(0),
jmasa@2188 47 _workers(NULL)
duke@435 48 {
duke@435 49 _sh = this; // ch is static, should be set only once.
duke@435 50 if ((UseParNewGC ||
jmasa@5461 51 (UseConcMarkSweepGC && (CMSParallelInitialMarkEnabled ||
jmasa@5461 52 CMSParallelRemarkEnabled)) ||
ysr@777 53 UseG1GC) &&
duke@435 54 ParallelGCThreads > 0) {
jmasa@2188 55 _workers = new FlexibleWorkGang("Parallel GC Threads", ParallelGCThreads,
ysr@777 56 /* are_GC_task_threads */true,
ysr@777 57 /* are_ConcurrentGC_threads */false);
duke@435 58 if (_workers == NULL) {
duke@435 59 vm_exit_during_initialization("Failed necessary allocation.");
jmasa@2188 60 } else {
jmasa@2188 61 _workers->initialize_workers();
duke@435 62 }
duke@435 63 }
duke@435 64 }
duke@435 65
ysr@777 66 bool SharedHeap::heap_lock_held_for_gc() {
ysr@777 67 Thread* t = Thread::current();
ysr@777 68 return Heap_lock->owned_by_self()
ysr@777 69 || ( (t->is_GC_task_thread() || t->is_VM_thread())
ysr@777 70 && _thread_holds_heap_lock_for_gc);
ysr@777 71 }
duke@435 72
jmasa@3357 73 void SharedHeap::set_par_threads(uint t) {
jmasa@2188 74 assert(t == 0 || !UseSerialGC, "Cannot have parallel threads");
duke@435 75 _n_par_threads = t;
stefank@6992 76 }
stefank@6992 77
duke@435 78 void SharedHeap::change_strong_roots_parity() {
duke@435 79 // Also set the new collection parity.
duke@435 80 assert(_strong_roots_parity >= 0 && _strong_roots_parity <= 2,
duke@435 81 "Not in range.");
duke@435 82 _strong_roots_parity++;
duke@435 83 if (_strong_roots_parity == 3) _strong_roots_parity = 1;
duke@435 84 assert(_strong_roots_parity >= 1 && _strong_roots_parity <= 2,
duke@435 85 "Not in range.");
duke@435 86 }
duke@435 87
stefank@6992 88 SharedHeap::StrongRootsScope::StrongRootsScope(SharedHeap* heap, bool activate)
mgerdin@7659 89 : MarkScope(activate), _sh(heap)
jrose@1424 90 {
jrose@1424 91 if (_active) {
stefank@6992 92 _sh->change_strong_roots_parity();
johnc@5277 93 // Zero the claimed high water mark in the StringTable
johnc@5277 94 StringTable::clear_parallel_claimed_index();
jrose@1424 95 }
jrose@1424 96 }
jrose@1424 97
duke@435 98 void SharedHeap::set_barrier_set(BarrierSet* bs) {
duke@435 99 _barrier_set = bs;
duke@435 100 // Cached barrier set for fast access in oops
duke@435 101 oopDesc::set_bs(bs);
duke@435 102 }
duke@435 103
duke@435 104 void SharedHeap::post_initialize() {
jwilhelm@6085 105 CollectedHeap::post_initialize();
duke@435 106 ref_processing_init();
duke@435 107 }
duke@435 108
coleenp@4037 109 void SharedHeap::ref_processing_init() {}
duke@435 110
duke@435 111 // Some utilities.
ysr@777 112 void SharedHeap::print_size_transition(outputStream* out,
ysr@777 113 size_t bytes_before,
duke@435 114 size_t bytes_after,
duke@435 115 size_t capacity) {
ysr@777 116 out->print(" %d%s->%d%s(%d%s)",
duke@435 117 byte_size_in_proper_unit(bytes_before),
duke@435 118 proper_unit_for_byte_size(bytes_before),
duke@435 119 byte_size_in_proper_unit(bytes_after),
duke@435 120 proper_unit_for_byte_size(bytes_after),
duke@435 121 byte_size_in_proper_unit(capacity),
duke@435 122 proper_unit_for_byte_size(capacity));
duke@435 123 }

mercurial