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

Wed, 22 Jan 2014 17:42:23 -0800

author
kvn
date
Wed, 22 Jan 2014 17:42:23 -0800
changeset 6503
a9becfeecd1b
parent 6461
bdd155477289
parent 6198
55fb97c4c58d
child 6680
78bbf4d43a14
permissions
-rw-r--r--

Merge

jmasa@4196 1 /*
mikael@6198 2 * Copyright (c) 2012, 2013, 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 void AdaptiveFreeList<Chunk>::initialize() {
jmasa@4196 55 FreeList<Chunk>::initialize();
jmasa@4196 56 set_hint(0);
jmasa@4196 57 init_statistics(true /* split_birth */);
jmasa@4196 58 }
jmasa@4196 59
jmasa@4196 60 template <class Chunk>
jmasa@4196 61 void AdaptiveFreeList<Chunk>::reset(size_t hint) {
jmasa@4196 62 FreeList<Chunk>::reset();
jmasa@4196 63 set_hint(hint);
jmasa@4196 64 }
jmasa@4196 65
jmasa@4196 66 #ifndef PRODUCT
jmasa@4196 67 template <class Chunk>
jmasa@4196 68 void AdaptiveFreeList<Chunk>::assert_proper_lock_protection_work() const {
jmasa@4196 69 assert(protecting_lock() != NULL, "Don't call this directly");
jmasa@4196 70 assert(ParallelGCThreads > 0, "Don't call this directly");
jmasa@4196 71 Thread* thr = Thread::current();
jmasa@4196 72 if (thr->is_VM_thread() || thr->is_ConcurrentGC_thread()) {
jmasa@4196 73 // assert that we are holding the freelist lock
jmasa@4196 74 } else if (thr->is_GC_task_thread()) {
jmasa@4196 75 assert(protecting_lock()->owned_by_self(), "FreeList RACE DETECTED");
jmasa@4196 76 } else if (thr->is_Java_thread()) {
jmasa@4196 77 assert(!SafepointSynchronize::is_at_safepoint(), "Should not be executing");
jmasa@4196 78 } else {
jmasa@4196 79 ShouldNotReachHere(); // unaccounted thread type?
jmasa@4196 80 }
jmasa@4196 81 }
jmasa@4196 82 #endif
jmasa@4196 83 template <class Chunk>
jmasa@4196 84 void AdaptiveFreeList<Chunk>::init_statistics(bool split_birth) {
jmasa@4196 85 _allocation_stats.initialize(split_birth);
jmasa@4196 86 }
jmasa@4196 87
jmasa@4196 88 template <class Chunk>
jmasa@4196 89 size_t AdaptiveFreeList<Chunk>::get_better_size() {
jmasa@4196 90
jmasa@4196 91 // A candidate chunk has been found. If it is already under
jmasa@4196 92 // populated and there is a hinT, REturn the hint(). Else
jmasa@4196 93 // return the size of this chunk.
jmasa@4196 94 if (surplus() <= 0) {
jmasa@4196 95 if (hint() != 0) {
jmasa@4196 96 return hint();
jmasa@4196 97 } else {
jmasa@4196 98 return size();
jmasa@4196 99 }
jmasa@4196 100 } else {
jmasa@4196 101 // This list has a surplus so use it.
jmasa@4196 102 return size();
jmasa@4196 103 }
jmasa@4196 104 }
jmasa@4196 105
jmasa@4196 106
jmasa@4196 107 template <class Chunk>
jmasa@4196 108 void AdaptiveFreeList<Chunk>::return_chunk_at_head(Chunk* chunk) {
jmasa@4196 109 assert_proper_lock_protection();
jmasa@4196 110 return_chunk_at_head(chunk, true);
jmasa@4196 111 }
jmasa@4196 112
jmasa@4196 113 template <class Chunk>
jmasa@4196 114 void AdaptiveFreeList<Chunk>::return_chunk_at_head(Chunk* chunk, bool record_return) {
jmasa@4196 115 FreeList<Chunk>::return_chunk_at_head(chunk, record_return);
jmasa@4196 116 #ifdef ASSERT
jmasa@4196 117 if (record_return) {
jmasa@4196 118 increment_returned_bytes_by(size()*HeapWordSize);
jmasa@4196 119 }
jmasa@4196 120 #endif
jmasa@4196 121 }
jmasa@4196 122
jmasa@4196 123 template <class Chunk>
jmasa@4196 124 void AdaptiveFreeList<Chunk>::return_chunk_at_tail(Chunk* chunk) {
goetz@6461 125 AdaptiveFreeList<Chunk>::return_chunk_at_tail(chunk, true);
jmasa@4196 126 }
jmasa@4196 127
jmasa@4196 128 template <class Chunk>
jmasa@4196 129 void AdaptiveFreeList<Chunk>::return_chunk_at_tail(Chunk* chunk, bool record_return) {
jmasa@4196 130 FreeList<Chunk>::return_chunk_at_tail(chunk, record_return);
jmasa@4196 131 #ifdef ASSERT
jmasa@4196 132 if (record_return) {
jmasa@4196 133 increment_returned_bytes_by(size()*HeapWordSize);
jmasa@4196 134 }
jmasa@4196 135 #endif
jmasa@4196 136 }
jmasa@4196 137
jmasa@4196 138 #ifndef PRODUCT
jmasa@4196 139 template <class Chunk>
jmasa@4196 140 void AdaptiveFreeList<Chunk>::verify_stats() const {
jmasa@4196 141 // The +1 of the LH comparand is to allow some "looseness" in
jmasa@4196 142 // checking: we usually call this interface when adding a block
jmasa@4196 143 // and we'll subsequently update the stats; we cannot update the
jmasa@4196 144 // stats beforehand because in the case of the large-block BT
jmasa@4196 145 // dictionary for example, this might be the first block and
jmasa@4196 146 // in that case there would be no place that we could record
jmasa@4196 147 // the stats (which are kept in the block itself).
jmasa@4196 148 assert((_allocation_stats.prev_sweep() + _allocation_stats.split_births()
jmasa@4196 149 + _allocation_stats.coal_births() + 1) // Total Production Stock + 1
jmasa@4196 150 >= (_allocation_stats.split_deaths() + _allocation_stats.coal_deaths()
jmasa@4196 151 + (ssize_t)count()), // Total Current Stock + depletion
jmasa@4196 152 err_msg("FreeList " PTR_FORMAT " of size " SIZE_FORMAT
jmasa@4196 153 " violates Conservation Principle: "
jmasa@4196 154 "prev_sweep(" SIZE_FORMAT ")"
jmasa@4196 155 " + split_births(" SIZE_FORMAT ")"
jmasa@4196 156 " + coal_births(" SIZE_FORMAT ") + 1 >= "
jmasa@4196 157 " split_deaths(" SIZE_FORMAT ")"
jmasa@4196 158 " coal_deaths(" SIZE_FORMAT ")"
jmasa@4196 159 " + count(" SSIZE_FORMAT ")",
jmasa@4196 160 this, size(), _allocation_stats.prev_sweep(), _allocation_stats.split_births(),
jmasa@4196 161 _allocation_stats.split_births(), _allocation_stats.split_deaths(),
jmasa@4196 162 _allocation_stats.coal_deaths(), count()));
jmasa@4196 163 }
jmasa@4196 164 #endif
jmasa@4196 165
jmasa@4196 166 // Needs to be after the definitions have been seen.
jmasa@4196 167 template class AdaptiveFreeList<FreeChunk>;

mercurial