8183923: Get rid of FreeBlockDictionary and dithering

Reviewed-by: ehelin, kbarrett
This commit is contained in:
Mikael Gerdin 2017-07-17 09:30:00 +02:00
parent c1af106f51
commit 6be7a36028
13 changed files with 52 additions and 214 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -26,7 +26,6 @@
#include "gc/cms/adaptiveFreeList.hpp"
#include "gc/cms/freeChunk.hpp"
#include "gc/shared/collectedHeap.hpp"
#include "memory/freeBlockDictionary.hpp"
#include "runtime/globals.hpp"
#include "runtime/mutex.hpp"
#include "runtime/orderAccess.inline.hpp"

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -1533,8 +1533,7 @@ CompactibleFreeListSpace::getChunkFromIndexedFreeListHelper(size_t size,
FreeChunk*
CompactibleFreeListSpace::getChunkFromDictionary(size_t size) {
assert_locked();
FreeChunk* fc = _dictionary->get_chunk(size,
FreeBlockDictionary<FreeChunk>::atLeast);
FreeChunk* fc = _dictionary->get_chunk(size);
if (fc == NULL) {
return NULL;
}
@ -1551,8 +1550,7 @@ CompactibleFreeListSpace::getChunkFromDictionary(size_t size) {
FreeChunk*
CompactibleFreeListSpace::getChunkFromDictionaryExact(size_t size) {
assert_locked();
FreeChunk* fc = _dictionary->get_chunk(size,
FreeBlockDictionary<FreeChunk>::atLeast);
FreeChunk* fc = _dictionary->get_chunk(size);
if (fc == NULL) {
return fc;
}
@ -1565,8 +1563,7 @@ CompactibleFreeListSpace::getChunkFromDictionaryExact(size_t size) {
if (fc->size() < size + MinChunkSize) {
// Return the chunk to the dictionary and go get a bigger one.
returnChunkToDictionary(fc);
fc = _dictionary->get_chunk(size + MinChunkSize,
FreeBlockDictionary<FreeChunk>::atLeast);
fc = _dictionary->get_chunk(size + MinChunkSize);
if (fc == NULL) {
return NULL;
}
@ -2679,8 +2676,7 @@ FreeChunk* CompactibleFreeListSpace::get_n_way_chunk_to_split(size_t word_sz, si
MutexLockerEx x(parDictionaryAllocLock(),
Mutex::_no_safepoint_check_flag);
while (n > 0) {
fc = dictionary()->get_chunk(MAX2(n * word_sz, _dictionary->min_size()),
FreeBlockDictionary<FreeChunk>::atLeast);
fc = dictionary()->get_chunk(MAX2(n * word_sz, _dictionary->min_size()));
if (fc != NULL) {
break;
} else {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -331,7 +331,7 @@ class CompactibleFreeListSpace: public CompactibleSpace {
CompactibleFreeListSpace(BlockOffsetSharedArray* bs, MemRegion mr);
// Accessors
bool bestFitFirst() { return _fitStrategy == FreeBlockBestFitFirst; }
FreeBlockDictionary<FreeChunk>* dictionary() const { return _dictionary; }
AFLBinaryTreeDictionary* dictionary() const { return _dictionary; }
HeapWord* nearLargestChunk() const { return _nearLargestChunk; }
void set_nearLargestChunk(HeapWord* v) { _nearLargestChunk = v; }

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -36,7 +36,6 @@
#include "gc/shared/space.hpp"
#include "gc/shared/taskqueue.hpp"
#include "logging/log.hpp"
#include "memory/freeBlockDictionary.hpp"
#include "memory/iterator.hpp"
#include "memory/virtualspace.hpp"
#include "runtime/mutexLocker.hpp"

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,7 +24,6 @@
#include "precompiled.hpp"
#include "gc/cms/freeChunk.hpp"
#include "memory/freeBlockDictionary.hpp"
#include "utilities/copy.hpp"
#ifndef PRODUCT

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -60,8 +60,7 @@
declare_toplevel_type(CompactibleFreeListSpace*) \
declare_toplevel_type(CMSCollector*) \
declare_toplevel_type(AFLBinaryTreeDictionary) \
declare_toplevel_type(LinearAllocBlock) \
declare_toplevel_type(FreeBlockDictionary<FreeChunk>)
declare_toplevel_type(LinearAllocBlock)
#define VM_INT_CONSTANTS_CMS(declare_constant) \
declare_constant(Generation::ConcurrentMarkSweep) \

View File

@ -27,7 +27,6 @@
#include "gc/shared/spaceDecorator.hpp"
#include "logging/logStream.inline.hpp"
#include "memory/binaryTreeDictionary.hpp"
#include "memory/freeBlockDictionary.hpp"
#include "memory/freeList.hpp"
#include "memory/metachunk.hpp"
#include "memory/resourceArea.hpp"
@ -423,9 +422,7 @@ void BinaryTreeDictionary<Chunk_t, FreeList_t>::reset() {
// Get a free block of size at least size from tree, or NULL.
template <class Chunk_t, class FreeList_t>
TreeChunk<Chunk_t, FreeList_t>*
BinaryTreeDictionary<Chunk_t, FreeList_t>::get_chunk_from_tree(
size_t size,
enum FreeBlockDictionary<Chunk_t>::Dither dither)
BinaryTreeDictionary<Chunk_t, FreeList_t>::get_chunk_from_tree(size_t size)
{
TreeList<Chunk_t, FreeList_t> *curTL, *prevTL;
TreeChunk<Chunk_t, FreeList_t>* retTC = NULL;
@ -450,8 +447,6 @@ BinaryTreeDictionary<Chunk_t, FreeList_t>::get_chunk_from_tree(
}
if (curTL == NULL) { // couldn't find exact match
if (dither == FreeBlockDictionary<Chunk_t>::exactly) return NULL;
// try and find the next larger size by walking back up the search path
for (curTL = prevTL; curTL != NULL;) {
if (curTL->size() >= size) break;
@ -769,7 +764,7 @@ void BinaryTreeDictionary<Chunk_t, FreeList_t>::insert_chunk_in_tree(Chunk_t* fc
template <class Chunk_t, class FreeList_t>
size_t BinaryTreeDictionary<Chunk_t, FreeList_t>::max_chunk_size() const {
FreeBlockDictionary<Chunk_t>::verify_par_locked();
verify_par_locked();
TreeList<Chunk_t, FreeList_t>* tc = root();
if (tc == NULL) return 0;
for (; tc->right() != NULL; tc = tc->right());
@ -1109,6 +1104,27 @@ size_t BinaryTreeDictionary<Chunk_t, FreeList_t>::total_count() {
ctc.do_tree(root());
return ctc.count;
}
template <class Chunk_t, class FreeList_t>
Mutex* BinaryTreeDictionary<Chunk_t, FreeList_t>::par_lock() const {
return _lock;
}
template <class Chunk_t, class FreeList_t>
void BinaryTreeDictionary<Chunk_t, FreeList_t>::set_par_lock(Mutex* lock) {
_lock = lock;
}
template <class Chunk_t, class FreeList_t>
void BinaryTreeDictionary<Chunk_t, FreeList_t>::verify_par_locked() const {
#ifdef ASSERT
Thread* my_thread = Thread::current();
if (my_thread->is_GC_task_thread()) {
assert(par_lock() != NULL, "Should be using locking?");
assert_lock_strong(par_lock());
}
#endif // ASSERT
}
#endif // PRODUCT
// Calculate surpluses for the lists in the tree.
@ -1199,7 +1215,7 @@ void BinaryTreeDictionary<Chunk_t, FreeList_t>::end_sweep_dict_census(double spl
// Print summary statistics
template <class Chunk_t, class FreeList_t>
void BinaryTreeDictionary<Chunk_t, FreeList_t>::report_statistics(outputStream* st) const {
FreeBlockDictionary<Chunk_t>::verify_par_locked();
verify_par_locked();
st->print_cr("Statistics for BinaryTreeDictionary:");
st->print_cr("------------------------------------");
size_t total_size = total_chunk_size(debug_only(NULL));

View File

@ -25,7 +25,6 @@
#ifndef SHARE_VM_MEMORY_BINARYTREEDICTIONARY_HPP
#define SHARE_VM_MEMORY_BINARYTREEDICTIONARY_HPP
#include "memory/freeBlockDictionary.hpp"
#include "memory/freeList.hpp"
/*
@ -176,7 +175,7 @@ template <class Chunk_t, class FreeList_t>
size_t TreeChunk<Chunk_t, FreeList_t>::min_size() { return _min_tree_chunk_size; }
template <class Chunk_t, class FreeList_t>
class BinaryTreeDictionary: public FreeBlockDictionary<Chunk_t> {
class BinaryTreeDictionary: public CHeapObj<mtGC> {
friend class VMStructs;
size_t _total_size;
size_t _total_free_blocks;
@ -184,8 +183,8 @@ class BinaryTreeDictionary: public FreeBlockDictionary<Chunk_t> {
// private accessors
void set_total_size(size_t v) { _total_size = v; }
virtual void inc_total_size(size_t v);
virtual void dec_total_size(size_t v);
void inc_total_size(size_t v);
void dec_total_size(size_t v);
void set_total_free_blocks(size_t v) { _total_free_blocks = v; }
TreeList<Chunk_t, FreeList_t>* root() const { return _root; }
void set_root(TreeList<Chunk_t, FreeList_t>* v) { _root = v; }
@ -200,7 +199,7 @@ class BinaryTreeDictionary: public FreeBlockDictionary<Chunk_t> {
// return it. If the chunk
// is the last chunk of that size, remove the node for that size
// from the tree.
TreeChunk<Chunk_t, FreeList_t>* get_chunk_from_tree(size_t size, enum FreeBlockDictionary<Chunk_t>::Dither dither);
TreeChunk<Chunk_t, FreeList_t>* get_chunk_from_tree(size_t size);
// Remove this chunk from the tree. If the removal results
// in an empty list in the tree, remove the empty list.
TreeChunk<Chunk_t, FreeList_t>* remove_chunk_from_tree(TreeChunk<Chunk_t, FreeList_t>* tc);
@ -259,23 +258,21 @@ class BinaryTreeDictionary: public FreeBlockDictionary<Chunk_t> {
// Return a chunk of size "size" or greater from
// the tree.
Chunk_t* get_chunk(size_t size, enum FreeBlockDictionary<Chunk_t>::Dither dither) {
FreeBlockDictionary<Chunk_t>::verify_par_locked();
Chunk_t* res = get_chunk_from_tree(size, dither);
Chunk_t* get_chunk(size_t size) {
verify_par_locked();
Chunk_t* res = get_chunk_from_tree(size);
assert(res == NULL || res->is_free(),
"Should be returning a free chunk");
assert(dither != FreeBlockDictionary<Chunk_t>::exactly ||
res == NULL || res->size() == size, "Not correct size");
return res;
}
void return_chunk(Chunk_t* chunk) {
FreeBlockDictionary<Chunk_t>::verify_par_locked();
verify_par_locked();
insert_chunk_in_tree(chunk);
}
void remove_chunk(Chunk_t* chunk) {
FreeBlockDictionary<Chunk_t>::verify_par_locked();
verify_par_locked();
remove_chunk_from_tree((TreeChunk<Chunk_t, FreeList_t>*)chunk);
assert(chunk->is_free(), "Should still be a free chunk");
}
@ -340,6 +337,10 @@ class BinaryTreeDictionary: public FreeBlockDictionary<Chunk_t> {
void report_statistics(outputStream* st) const;
void verify() const;
Mutex* par_lock() const PRODUCT_RETURN0;
void set_par_lock(Mutex* lock) PRODUCT_RETURN;
void verify_par_locked() const PRODUCT_RETURN;
};
#endif // SHARE_VM_MEMORY_BINARYTREEDICTIONARY_HPP

View File

@ -1,60 +0,0 @@
/*
* Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "precompiled.hpp"
#include "memory/freeBlockDictionary.hpp"
#include "memory/metachunk.hpp"
#include "runtime/thread.inline.hpp"
#include "utilities/macros.hpp"
#if INCLUDE_ALL_GCS
#include "gc/cms/freeChunk.hpp"
#endif // INCLUDE_ALL_GCS
#ifndef PRODUCT
template <class Chunk> Mutex* FreeBlockDictionary<Chunk>::par_lock() const {
return _lock;
}
template <class Chunk> void FreeBlockDictionary<Chunk>::set_par_lock(Mutex* lock) {
_lock = lock;
}
template <class Chunk> void FreeBlockDictionary<Chunk>::verify_par_locked() const {
#ifdef ASSERT
Thread* my_thread = Thread::current();
if (my_thread->is_GC_task_thread()) {
assert(par_lock() != NULL, "Should be using locking?");
assert_lock_strong(par_lock());
}
#endif // ASSERT
}
#endif
template class FreeBlockDictionary<Metablock>;
template class FreeBlockDictionary<Metachunk>;
#if INCLUDE_ALL_GCS
// Explicitly instantiate for FreeChunk
template class FreeBlockDictionary<FreeChunk>;
#endif // INCLUDE_ALL_GCS

View File

@ -1,106 +0,0 @@
/*
* Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#ifndef SHARE_VM_MEMORY_FREEBLOCKDICTIONARY_HPP
#define SHARE_VM_MEMORY_FREEBLOCKDICTIONARY_HPP
#include "memory/allocation.hpp"
#include "runtime/mutex.hpp"
#include "utilities/debug.hpp"
#include "utilities/globalDefinitions.hpp"
#include "utilities/ostream.hpp"
// A FreeBlockDictionary is an abstract superclass that will allow
// a number of alternative implementations in the future.
template <class Chunk>
class FreeBlockDictionary: public CHeapObj<mtGC> {
public:
enum Dither {
atLeast,
exactly,
roughly
};
enum DictionaryChoice {
dictionaryBinaryTree = 0,
dictionarySplayTree = 1,
dictionarySkipList = 2
};
private:
// This field is added and can be set to point to the
// the Mutex used to synchronize access to the
// dictionary so that assertion checking can be done.
// For example it is set to point to _parDictionaryAllocLock.
NOT_PRODUCT(Mutex* _lock;)
public:
virtual void remove_chunk(Chunk* fc) = 0;
virtual Chunk* get_chunk(size_t size, Dither dither = atLeast) = 0;
virtual void return_chunk(Chunk* chunk) = 0;
virtual size_t total_chunk_size(debug_only(const Mutex* lock)) const = 0;
virtual size_t max_chunk_size() const = 0;
virtual size_t min_size() const = 0;
// Reset the dictionary to the initial conditions for a single
// block.
virtual void reset(HeapWord* addr, size_t size) = 0;
virtual void reset() = 0;
virtual void dict_census_update(size_t size, bool split, bool birth) = 0;
virtual bool coal_dict_over_populated(size_t size) = 0;
virtual void begin_sweep_dict_census(double coalSurplusPercent,
float inter_sweep_current, float inter_sweep_estimate,
float intra__sweep_current) = 0;
virtual void end_sweep_dict_census(double splitSurplusPercent) = 0;
virtual Chunk* find_largest_dict() const = 0;
// verify that the given chunk is in the dictionary.
virtual bool verify_chunk_in_free_list(Chunk* tc) const = 0;
// Sigma_{all_free_blocks} (block_size^2)
virtual double sum_of_squared_block_sizes() const = 0;
virtual Chunk* find_chunk_ends_at(HeapWord* target) const = 0;
virtual void inc_total_size(size_t v) = 0;
virtual void dec_total_size(size_t v) = 0;
NOT_PRODUCT (
virtual size_t sum_dict_returned_bytes() = 0;
virtual void initialize_dict_returned_bytes() = 0;
virtual size_t total_count() = 0;
)
virtual void report_statistics(outputStream* st) const {
st->print_cr("No statistics available");
}
virtual void print_dict_census(outputStream* st) const = 0;
virtual void print_free_lists(outputStream* st) const = 0;
virtual void verify() const = 0;
Mutex* par_lock() const PRODUCT_RETURN0;
void set_par_lock(Mutex* lock) PRODUCT_RETURN;
void verify_par_locked() const PRODUCT_RETURN;
};
#endif // SHARE_VM_MEMORY_FREEBLOCKDICTIONARY_HPP

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,7 +24,6 @@
#include "precompiled.hpp"
#include "gc/shared/collectedHeap.hpp"
#include "memory/freeBlockDictionary.hpp"
#include "memory/freeList.hpp"
#include "memory/metachunk.hpp"
#include "runtime/globals.hpp"

View File

@ -940,8 +940,7 @@ MetaWord* BlockFreelist::get_block(size_t word_size) {
return NULL;
}
Metablock* free_block =
dictionary()->get_chunk(word_size, FreeBlockDictionary<Metablock>::atLeast);
Metablock* free_block = dictionary()->get_chunk(word_size);
if (free_block == NULL) {
return NULL;
}
@ -1912,9 +1911,7 @@ Metachunk* ChunkManager::free_chunks_get(size_t word_size) {
log_trace(gc, metaspace, freelist)("ChunkManager::free_chunks_get: free_list " PTR_FORMAT " head " PTR_FORMAT " size " SIZE_FORMAT,
p2i(free_list), p2i(chunk), chunk->word_size());
} else {
chunk = humongous_dictionary()->get_chunk(
word_size,
FreeBlockDictionary<Metachunk>::atLeast);
chunk = humongous_dictionary()->get_chunk(word_size);
if (chunk == NULL) {
return NULL;

View File

@ -60,7 +60,6 @@
#include "interpreter/interpreter.hpp"
#include "memory/allocation.hpp"
#include "memory/allocation.inline.hpp"
#include "memory/freeBlockDictionary.hpp"
#include "memory/heap.hpp"
#include "memory/metachunk.hpp"
#include "memory/referenceType.hpp"