2007-12-01 00:00:00 +00:00
|
|
|
/*
|
2019-01-08 10:54:00 +01:00
|
|
|
* Copyright (c) 2001, 2019, 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
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-01-10 15:13:51 -05:00
|
|
|
#ifndef SHARE_GC_SHARED_COLLECTEDHEAP_INLINE_HPP
|
|
|
|
#define SHARE_GC_SHARED_COLLECTEDHEAP_INLINE_HPP
|
2010-11-23 13:22:55 -08:00
|
|
|
|
2015-05-13 15:16:06 +02:00
|
|
|
#include "gc/shared/collectedHeap.hpp"
|
2019-01-08 10:54:00 +01:00
|
|
|
#include "gc/shared/memAllocator.hpp"
|
2016-01-18 10:25:41 +01:00
|
|
|
#include "oops/oop.inline.hpp"
|
2017-07-05 11:33:17 +02:00
|
|
|
#include "utilities/align.hpp"
|
2011-09-26 10:24:05 -07:00
|
|
|
|
2014-08-01 15:40:12 -07:00
|
|
|
inline HeapWord* CollectedHeap::align_allocation_or_fail(HeapWord* addr,
|
|
|
|
HeapWord* end,
|
|
|
|
unsigned short alignment_in_bytes) {
|
|
|
|
if (alignment_in_bytes <= ObjectAlignmentInBytes) {
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
2017-07-04 15:58:10 +02:00
|
|
|
assert(is_aligned(addr, HeapWordSize),
|
2015-09-29 11:02:08 +02:00
|
|
|
"Address " PTR_FORMAT " is not properly aligned.", p2i(addr));
|
2017-07-04 15:58:10 +02:00
|
|
|
assert(is_aligned(alignment_in_bytes, HeapWordSize),
|
2015-09-29 11:02:08 +02:00
|
|
|
"Alignment size %u is incorrect.", alignment_in_bytes);
|
2014-08-01 15:40:12 -07:00
|
|
|
|
2017-07-04 15:58:10 +02:00
|
|
|
HeapWord* new_addr = align_up(addr, alignment_in_bytes);
|
2014-08-01 15:40:12 -07:00
|
|
|
size_t padding = pointer_delta(new_addr, addr);
|
|
|
|
|
|
|
|
if (padding == 0) {
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (padding < CollectedHeap::min_fill_size()) {
|
|
|
|
padding += alignment_in_bytes / HeapWordSize;
|
|
|
|
assert(padding >= CollectedHeap::min_fill_size(),
|
2015-09-29 11:02:08 +02:00
|
|
|
"alignment_in_bytes %u is expect to be larger "
|
|
|
|
"than the minimum object size", alignment_in_bytes);
|
2014-08-01 15:40:12 -07:00
|
|
|
new_addr = addr + padding;
|
|
|
|
}
|
|
|
|
|
2015-09-29 11:02:08 +02:00
|
|
|
assert(new_addr > addr, "Unexpected arithmetic overflow "
|
|
|
|
PTR_FORMAT " not greater than " PTR_FORMAT, p2i(new_addr), p2i(addr));
|
2014-08-01 15:40:12 -07:00
|
|
|
if(new_addr < end) {
|
|
|
|
CollectedHeap::fill_with_object(addr, padding);
|
|
|
|
return new_addr;
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-08 10:54:00 +01:00
|
|
|
inline oop CollectedHeap::obj_allocate(Klass* klass, int size, TRAPS) {
|
|
|
|
ObjAllocator allocator(klass, size, THREAD);
|
|
|
|
return allocator.allocate();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline oop CollectedHeap::array_allocate(Klass* klass, int size, int length, bool do_zero, TRAPS) {
|
|
|
|
ObjArrayAllocator allocator(klass, size, length, do_zero, THREAD);
|
|
|
|
return allocator.allocate();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline oop CollectedHeap::class_allocate(Klass* klass, int size, TRAPS) {
|
|
|
|
ClassAllocator allocator(klass, size, THREAD);
|
|
|
|
return allocator.allocate();
|
|
|
|
}
|
|
|
|
|
2019-01-10 15:13:51 -05:00
|
|
|
#endif // SHARE_GC_SHARED_COLLECTEDHEAP_INLINE_HPP
|