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