src/share/vm/gc_implementation/concurrentMarkSweep/adaptiveFreeList.cpp

Tue, 27 Nov 2012 07:57:57 -0800

author
mikael
date
Tue, 27 Nov 2012 07:57:57 -0800
changeset 4290
7c15faa95ce7
parent 4196
685df3c6f84b
child 5166
7c5a1b62f53d
permissions
-rw-r--r--

8003879: Duplicate definitions in vmStructs
Summary: Removed duplicate entries
Reviewed-by: dholmes, sspitsyn

jmasa@4196 1 /*
jmasa@4196 2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
jmasa@4196 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jmasa@4196 4 *
jmasa@4196 5 * This code is free software; you can redistribute it and/or modify it
jmasa@4196 6 * under the terms of the GNU General Public License version 2 only, as
jmasa@4196 7 * published by the Free Software Foundation.
jmasa@4196 8 *
jmasa@4196 9 * This code is distributed in the hope that it will be useful, but WITHOUT
jmasa@4196 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jmasa@4196 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jmasa@4196 12 * version 2 for more details (a copy is included in the LICENSE file that
jmasa@4196 13 * accompanied this code).
jmasa@4196 14 *
jmasa@4196 15 * You should have received a copy of the GNU General Public License version
jmasa@4196 16 * 2 along with this work; if not, write to the Free Software Foundation,
jmasa@4196 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jmasa@4196 18 *
jmasa@4196 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jmasa@4196 20 * or visit www.oracle.com if you need additional information or have any
jmasa@4196 21 * questions.
jmasa@4196 22 *
jmasa@4196 23 */
jmasa@4196 24
jmasa@4196 25 #include "precompiled.hpp"
jmasa@4196 26 #include "gc_implementation/concurrentMarkSweep/adaptiveFreeList.hpp"
jmasa@4196 27 #include "gc_implementation/concurrentMarkSweep/freeChunk.hpp"
jmasa@4196 28 #include "memory/freeBlockDictionary.hpp"
jmasa@4196 29 #include "memory/sharedHeap.hpp"
jmasa@4196 30 #include "runtime/globals.hpp"
jmasa@4196 31 #include "runtime/mutex.hpp"
jmasa@4196 32 #include "runtime/vmThread.hpp"
jmasa@4196 33
jmasa@4196 34 template <>
jmasa@4196 35 void AdaptiveFreeList<FreeChunk>::print_on(outputStream* st, const char* c) const {
jmasa@4196 36 if (c != NULL) {
jmasa@4196 37 st->print("%16s", c);
jmasa@4196 38 } else {
jmasa@4196 39 st->print(SIZE_FORMAT_W(16), size());
jmasa@4196 40 }
jmasa@4196 41 st->print("\t"
jmasa@4196 42 SSIZE_FORMAT_W(14) "\t" SSIZE_FORMAT_W(14) "\t" SSIZE_FORMAT_W(14) "\t" SSIZE_FORMAT_W(14) "\t" SSIZE_FORMAT_W(14) "\t"
jmasa@4196 43 SSIZE_FORMAT_W(14) "\t" SSIZE_FORMAT_W(14) "\t" SSIZE_FORMAT_W(14) "\t" SSIZE_FORMAT_W(14) "\t" SSIZE_FORMAT_W(14) "\n",
jmasa@4196 44 bfr_surp(), surplus(), desired(), prev_sweep(), before_sweep(),
jmasa@4196 45 count(), coal_births(), coal_deaths(), split_births(), split_deaths());
jmasa@4196 46 }
jmasa@4196 47
jmasa@4196 48 template <class Chunk>
jmasa@4196 49 AdaptiveFreeList<Chunk>::AdaptiveFreeList() : FreeList<Chunk>(), _hint(0) {
jmasa@4196 50 init_statistics();
jmasa@4196 51 }
jmasa@4196 52
jmasa@4196 53 template <class Chunk>
jmasa@4196 54 AdaptiveFreeList<Chunk>::AdaptiveFreeList(Chunk* fc) : FreeList<Chunk>(fc), _hint(0) {
jmasa@4196 55 init_statistics();
jmasa@4196 56 #ifndef PRODUCT
jmasa@4196 57 _allocation_stats.set_returned_bytes(size() * HeapWordSize);
jmasa@4196 58 #endif
jmasa@4196 59 }
jmasa@4196 60
jmasa@4196 61 template <class Chunk>
jmasa@4196 62 void AdaptiveFreeList<Chunk>::initialize() {
jmasa@4196 63 FreeList<Chunk>::initialize();
jmasa@4196 64 set_hint(0);
jmasa@4196 65 init_statistics(true /* split_birth */);
jmasa@4196 66 }
jmasa@4196 67
jmasa@4196 68 template <class Chunk>
jmasa@4196 69 void AdaptiveFreeList<Chunk>::reset(size_t hint) {
jmasa@4196 70 FreeList<Chunk>::reset();
jmasa@4196 71 set_hint(hint);
jmasa@4196 72 }
jmasa@4196 73
jmasa@4196 74 #ifndef PRODUCT
jmasa@4196 75 template <class Chunk>
jmasa@4196 76 void AdaptiveFreeList<Chunk>::assert_proper_lock_protection_work() const {
jmasa@4196 77 assert(protecting_lock() != NULL, "Don't call this directly");
jmasa@4196 78 assert(ParallelGCThreads > 0, "Don't call this directly");
jmasa@4196 79 Thread* thr = Thread::current();
jmasa@4196 80 if (thr->is_VM_thread() || thr->is_ConcurrentGC_thread()) {
jmasa@4196 81 // assert that we are holding the freelist lock
jmasa@4196 82 } else if (thr->is_GC_task_thread()) {
jmasa@4196 83 assert(protecting_lock()->owned_by_self(), "FreeList RACE DETECTED");
jmasa@4196 84 } else if (thr->is_Java_thread()) {
jmasa@4196 85 assert(!SafepointSynchronize::is_at_safepoint(), "Should not be executing");
jmasa@4196 86 } else {
jmasa@4196 87 ShouldNotReachHere(); // unaccounted thread type?
jmasa@4196 88 }
jmasa@4196 89 }
jmasa@4196 90 #endif
jmasa@4196 91 template <class Chunk>
jmasa@4196 92 void AdaptiveFreeList<Chunk>::init_statistics(bool split_birth) {
jmasa@4196 93 _allocation_stats.initialize(split_birth);
jmasa@4196 94 }
jmasa@4196 95
jmasa@4196 96 template <class Chunk>
jmasa@4196 97 size_t AdaptiveFreeList<Chunk>::get_better_size() {
jmasa@4196 98
jmasa@4196 99 // A candidate chunk has been found. If it is already under
jmasa@4196 100 // populated and there is a hinT, REturn the hint(). Else
jmasa@4196 101 // return the size of this chunk.
jmasa@4196 102 if (surplus() <= 0) {
jmasa@4196 103 if (hint() != 0) {
jmasa@4196 104 return hint();
jmasa@4196 105 } else {
jmasa@4196 106 return size();
jmasa@4196 107 }
jmasa@4196 108 } else {
jmasa@4196 109 // This list has a surplus so use it.
jmasa@4196 110 return size();
jmasa@4196 111 }
jmasa@4196 112 }
jmasa@4196 113
jmasa@4196 114
jmasa@4196 115 template <class Chunk>
jmasa@4196 116 void AdaptiveFreeList<Chunk>::return_chunk_at_head(Chunk* chunk) {
jmasa@4196 117 assert_proper_lock_protection();
jmasa@4196 118 return_chunk_at_head(chunk, true);
jmasa@4196 119 }
jmasa@4196 120
jmasa@4196 121 template <class Chunk>
jmasa@4196 122 void AdaptiveFreeList<Chunk>::return_chunk_at_head(Chunk* chunk, bool record_return) {
jmasa@4196 123 FreeList<Chunk>::return_chunk_at_head(chunk, record_return);
jmasa@4196 124 #ifdef ASSERT
jmasa@4196 125 if (record_return) {
jmasa@4196 126 increment_returned_bytes_by(size()*HeapWordSize);
jmasa@4196 127 }
jmasa@4196 128 #endif
jmasa@4196 129 }
jmasa@4196 130
jmasa@4196 131 template <class Chunk>
jmasa@4196 132 void AdaptiveFreeList<Chunk>::return_chunk_at_tail(Chunk* chunk) {
jmasa@4196 133 return_chunk_at_tail(chunk, true);
jmasa@4196 134 }
jmasa@4196 135
jmasa@4196 136 template <class Chunk>
jmasa@4196 137 void AdaptiveFreeList<Chunk>::return_chunk_at_tail(Chunk* chunk, bool record_return) {
jmasa@4196 138 FreeList<Chunk>::return_chunk_at_tail(chunk, record_return);
jmasa@4196 139 #ifdef ASSERT
jmasa@4196 140 if (record_return) {
jmasa@4196 141 increment_returned_bytes_by(size()*HeapWordSize);
jmasa@4196 142 }
jmasa@4196 143 #endif
jmasa@4196 144 }
jmasa@4196 145
jmasa@4196 146 #ifndef PRODUCT
jmasa@4196 147 template <class Chunk>
jmasa@4196 148 void AdaptiveFreeList<Chunk>::verify_stats() const {
jmasa@4196 149 // The +1 of the LH comparand is to allow some "looseness" in
jmasa@4196 150 // checking: we usually call this interface when adding a block
jmasa@4196 151 // and we'll subsequently update the stats; we cannot update the
jmasa@4196 152 // stats beforehand because in the case of the large-block BT
jmasa@4196 153 // dictionary for example, this might be the first block and
jmasa@4196 154 // in that case there would be no place that we could record
jmasa@4196 155 // the stats (which are kept in the block itself).
jmasa@4196 156 assert((_allocation_stats.prev_sweep() + _allocation_stats.split_births()
jmasa@4196 157 + _allocation_stats.coal_births() + 1) // Total Production Stock + 1
jmasa@4196 158 >= (_allocation_stats.split_deaths() + _allocation_stats.coal_deaths()
jmasa@4196 159 + (ssize_t)count()), // Total Current Stock + depletion
jmasa@4196 160 err_msg("FreeList " PTR_FORMAT " of size " SIZE_FORMAT
jmasa@4196 161 " violates Conservation Principle: "
jmasa@4196 162 "prev_sweep(" SIZE_FORMAT ")"
jmasa@4196 163 " + split_births(" SIZE_FORMAT ")"
jmasa@4196 164 " + coal_births(" SIZE_FORMAT ") + 1 >= "
jmasa@4196 165 " split_deaths(" SIZE_FORMAT ")"
jmasa@4196 166 " coal_deaths(" SIZE_FORMAT ")"
jmasa@4196 167 " + count(" SSIZE_FORMAT ")",
jmasa@4196 168 this, size(), _allocation_stats.prev_sweep(), _allocation_stats.split_births(),
jmasa@4196 169 _allocation_stats.split_births(), _allocation_stats.split_deaths(),
jmasa@4196 170 _allocation_stats.coal_deaths(), count()));
jmasa@4196 171 }
jmasa@4196 172 #endif
jmasa@4196 173
jmasa@4196 174 // Needs to be after the definitions have been seen.
jmasa@4196 175 template class AdaptiveFreeList<FreeChunk>;

mercurial