2007-12-01 00:00:00 +00:00
|
|
|
/*
|
2015-02-16 14:07:36 +01:00
|
|
|
* Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
|
2007-12-01 00:00:00 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2010-05-27 19:08:38 -07:00
|
|
|
* 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.
|
2007-12-01 00:00:00 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "precompiled.hpp"
|
2015-05-13 15:16:06 +02:00
|
|
|
#include "gc/parallel/mutableSpace.hpp"
|
|
|
|
#include "gc/shared/spaceDecorator.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "oops/oop.inline.hpp"
|
2015-05-13 15:16:06 +02:00
|
|
|
#include "runtime/atomic.inline.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "runtime/safepoint.hpp"
|
|
|
|
#include "runtime/thread.hpp"
|
2015-05-13 15:16:06 +02:00
|
|
|
#include "utilities/macros.hpp"
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2009-01-27 18:13:59 -08:00
|
|
|
MutableSpace::MutableSpace(size_t alignment): ImmutableSpace(), _top(NULL), _alignment(alignment) {
|
2015-02-16 14:07:36 +01:00
|
|
|
assert(MutableSpace::alignment() % os::vm_page_size() == 0,
|
2009-01-27 18:13:59 -08:00
|
|
|
"Space should be aligned");
|
2008-07-09 15:08:55 -07:00
|
|
|
_mangler = new MutableSpaceMangler(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
MutableSpace::~MutableSpace() {
|
|
|
|
delete _mangler;
|
|
|
|
}
|
|
|
|
|
2009-01-27 18:13:59 -08:00
|
|
|
void MutableSpace::numa_setup_pages(MemRegion mr, bool clear_space) {
|
|
|
|
if (!mr.is_empty()) {
|
|
|
|
size_t page_size = UseLargePages ? alignment() : os::vm_page_size();
|
|
|
|
HeapWord *start = (HeapWord*)round_to((intptr_t) mr.start(), page_size);
|
|
|
|
HeapWord *end = (HeapWord*)round_down((intptr_t) mr.end(), page_size);
|
|
|
|
if (end > start) {
|
|
|
|
size_t size = pointer_delta(end, start, sizeof(char));
|
|
|
|
if (clear_space) {
|
|
|
|
// Prefer page reallocation to migration.
|
2011-12-27 16:43:49 -08:00
|
|
|
os::free_memory((char*)start, size, page_size);
|
2009-01-27 18:13:59 -08:00
|
|
|
}
|
|
|
|
os::numa_make_global((char*)start, size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MutableSpace::pretouch_pages(MemRegion mr) {
|
2014-12-18 09:37:02 +01:00
|
|
|
os::pretouch_memory((char*)mr.start(), (char*)mr.end());
|
2009-01-27 18:13:59 -08:00
|
|
|
}
|
|
|
|
|
2008-07-09 15:08:55 -07:00
|
|
|
void MutableSpace::initialize(MemRegion mr,
|
|
|
|
bool clear_space,
|
2009-01-27 18:13:59 -08:00
|
|
|
bool mangle_space,
|
|
|
|
bool setup_pages) {
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2009-01-27 18:13:59 -08:00
|
|
|
assert(Universe::on_page_boundary(mr.start()) && Universe::on_page_boundary(mr.end()),
|
2007-12-01 00:00:00 +00:00
|
|
|
"invalid space boundaries");
|
2009-01-27 18:13:59 -08:00
|
|
|
|
|
|
|
if (setup_pages && (UseNUMA || AlwaysPreTouch)) {
|
|
|
|
// The space may move left and right or expand/shrink.
|
|
|
|
// We'd like to enforce the desired page placement.
|
|
|
|
MemRegion head, tail;
|
|
|
|
if (last_setup_region().is_empty()) {
|
|
|
|
// If it's the first initialization don't limit the amount of work.
|
|
|
|
head = mr;
|
|
|
|
tail = MemRegion(mr.end(), mr.end());
|
|
|
|
} else {
|
|
|
|
// Is there an intersection with the address space?
|
|
|
|
MemRegion intersection = last_setup_region().intersection(mr);
|
|
|
|
if (intersection.is_empty()) {
|
|
|
|
intersection = MemRegion(mr.end(), mr.end());
|
|
|
|
}
|
|
|
|
// All the sizes below are in words.
|
|
|
|
size_t head_size = 0, tail_size = 0;
|
|
|
|
if (mr.start() <= intersection.start()) {
|
|
|
|
head_size = pointer_delta(intersection.start(), mr.start());
|
|
|
|
}
|
|
|
|
if(intersection.end() <= mr.end()) {
|
|
|
|
tail_size = pointer_delta(mr.end(), intersection.end());
|
|
|
|
}
|
|
|
|
// Limit the amount of page manipulation if necessary.
|
|
|
|
if (NUMASpaceResizeRate > 0 && !AlwaysPreTouch) {
|
|
|
|
const size_t change_size = head_size + tail_size;
|
|
|
|
const float setup_rate_words = NUMASpaceResizeRate >> LogBytesPerWord;
|
|
|
|
head_size = MIN2((size_t)(setup_rate_words * head_size / change_size),
|
|
|
|
head_size);
|
|
|
|
tail_size = MIN2((size_t)(setup_rate_words * tail_size / change_size),
|
|
|
|
tail_size);
|
|
|
|
}
|
|
|
|
head = MemRegion(intersection.start() - head_size, intersection.start());
|
|
|
|
tail = MemRegion(intersection.end(), intersection.end() + tail_size);
|
|
|
|
}
|
|
|
|
assert(mr.contains(head) && mr.contains(tail), "Sanity");
|
|
|
|
|
|
|
|
if (UseNUMA) {
|
|
|
|
numa_setup_pages(head, clear_space);
|
|
|
|
numa_setup_pages(tail, clear_space);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (AlwaysPreTouch) {
|
|
|
|
pretouch_pages(head);
|
|
|
|
pretouch_pages(tail);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remember where we stopped so that we can continue later.
|
|
|
|
set_last_setup_region(MemRegion(head.start(), tail.end()));
|
|
|
|
}
|
|
|
|
|
|
|
|
set_bottom(mr.start());
|
|
|
|
set_end(mr.end());
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2008-07-09 15:08:55 -07:00
|
|
|
if (clear_space) {
|
|
|
|
clear(mangle_space);
|
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2008-07-09 15:08:55 -07:00
|
|
|
void MutableSpace::clear(bool mangle_space) {
|
2007-12-01 00:00:00 +00:00
|
|
|
set_top(bottom());
|
2008-07-09 15:08:55 -07:00
|
|
|
if (ZapUnusedHeapArea && mangle_space) {
|
|
|
|
mangle_unused_area();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef PRODUCT
|
|
|
|
void MutableSpace::check_mangled_unused_area(HeapWord* limit) {
|
|
|
|
mangler()->check_mangled_unused_area(limit);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MutableSpace::check_mangled_unused_area_complete() {
|
|
|
|
mangler()->check_mangled_unused_area_complete();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mangle only the unused space that has not previously
|
|
|
|
// been mangled and that has not been allocated since being
|
|
|
|
// mangled.
|
|
|
|
void MutableSpace::mangle_unused_area() {
|
|
|
|
mangler()->mangle_unused_area();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MutableSpace::mangle_unused_area_complete() {
|
|
|
|
mangler()->mangle_unused_area_complete();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MutableSpace::mangle_region(MemRegion mr) {
|
|
|
|
SpaceMangler::mangle_region(mr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MutableSpace::set_top_for_allocations(HeapWord* v) {
|
|
|
|
mangler()->set_top_for_allocations(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MutableSpace::set_top_for_allocations() {
|
|
|
|
mangler()->set_top_for_allocations(top());
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
2008-07-09 15:08:55 -07:00
|
|
|
#endif
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// This version requires locking. */
|
|
|
|
HeapWord* MutableSpace::allocate(size_t size) {
|
|
|
|
assert(Heap_lock->owned_by_self() ||
|
|
|
|
(SafepointSynchronize::is_at_safepoint() &&
|
|
|
|
Thread::current()->is_VM_thread()),
|
|
|
|
"not locked");
|
|
|
|
HeapWord* obj = top();
|
|
|
|
if (pointer_delta(end(), obj) >= size) {
|
|
|
|
HeapWord* new_top = obj + size;
|
|
|
|
set_top(new_top);
|
|
|
|
assert(is_object_aligned((intptr_t)obj) && is_object_aligned((intptr_t)new_top),
|
|
|
|
"checking alignment");
|
|
|
|
return obj;
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This version is lock-free.
|
|
|
|
HeapWord* MutableSpace::cas_allocate(size_t size) {
|
|
|
|
do {
|
|
|
|
HeapWord* obj = top();
|
|
|
|
if (pointer_delta(end(), obj) >= size) {
|
|
|
|
HeapWord* new_top = obj + size;
|
|
|
|
HeapWord* result = (HeapWord*)Atomic::cmpxchg_ptr(new_top, top_addr(), obj);
|
|
|
|
// result can be one of two:
|
|
|
|
// the old top value: the exchange succeeded
|
|
|
|
// otherwise: the new value of the top is returned.
|
|
|
|
if (result != obj) {
|
|
|
|
continue; // another thread beat us to the allocation, try again
|
|
|
|
}
|
|
|
|
assert(is_object_aligned((intptr_t)obj) && is_object_aligned((intptr_t)new_top),
|
|
|
|
"checking alignment");
|
|
|
|
return obj;
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
} while (true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try to deallocate previous allocation. Returns true upon success.
|
|
|
|
bool MutableSpace::cas_deallocate(HeapWord *obj, size_t size) {
|
|
|
|
HeapWord* expected_top = obj + size;
|
|
|
|
return (HeapWord*)Atomic::cmpxchg_ptr(obj, top_addr(), expected_top) == expected_top;
|
|
|
|
}
|
|
|
|
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
void MutableSpace::oop_iterate_no_header(OopClosure* cl) {
|
|
|
|
HeapWord* obj_addr = bottom();
|
|
|
|
HeapWord* t = top();
|
|
|
|
// Could call objects iterate, but this is easier.
|
|
|
|
while (obj_addr < t) {
|
|
|
|
obj_addr += oop(obj_addr)->oop_iterate_no_header(cl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
void MutableSpace::object_iterate(ObjectClosure* cl) {
|
|
|
|
HeapWord* p = bottom();
|
|
|
|
while (p < top()) {
|
|
|
|
cl->do_object(oop(p));
|
|
|
|
p += oop(p)->size();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MutableSpace::print_short() const { print_short_on(tty); }
|
|
|
|
void MutableSpace::print_short_on( outputStream* st) const {
|
|
|
|
st->print(" space " SIZE_FORMAT "K, %d%% used", capacity_in_bytes() / K,
|
|
|
|
(int) ((double) used_in_bytes() * 100 / capacity_in_bytes()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void MutableSpace::print() const { print_on(tty); }
|
|
|
|
void MutableSpace::print_on(outputStream* st) const {
|
|
|
|
MutableSpace::print_short_on(st);
|
|
|
|
st->print_cr(" [" INTPTR_FORMAT "," INTPTR_FORMAT "," INTPTR_FORMAT ")",
|
2015-03-27 15:29:19 +01:00
|
|
|
p2i(bottom()), p2i(top()), p2i(end()));
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2012-04-16 08:57:18 +02:00
|
|
|
void MutableSpace::verify() {
|
2007-12-01 00:00:00 +00:00
|
|
|
HeapWord* p = bottom();
|
|
|
|
HeapWord* t = top();
|
|
|
|
HeapWord* prev_p = NULL;
|
|
|
|
while (p < t) {
|
|
|
|
oop(p)->verify();
|
|
|
|
prev_p = p;
|
|
|
|
p += oop(p)->size();
|
|
|
|
}
|
|
|
|
guarantee(p == top(), "end of last object must match end of space");
|
|
|
|
}
|