/* * Copyright (c) 2018, 2022, 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. *
*/
bool MemAllocator::Allocation::check_out_of_memory() {
JavaThread* THREAD = _thread; // For exception macros.
assert(!HAS_PENDING_EXCEPTION, "Unexpected exception, will result in uninitialized storage");
if (obj() != NULL) { returnfalse;
}
constchar* message = _overhead_limit_exceeded ? "GC overhead limit exceeded" : "Java heap space"; if (!_thread->in_retryable_allocation()) { // -XX:+HeapDumpOnOutOfMemoryError and -XX:OnOutOfMemoryError support
report_java_out_of_memory(message);
void MemAllocator::Allocation::verify_before() { // Clear unhandled oops for memory allocation. Memory allocation might // not take out a lock if from tlab, so clear here.
JavaThread* THREAD = _thread; // For exception macros.
assert(!HAS_PENDING_EXCEPTION, "Should not allocate with exception pending");
debug_only(check_for_valid_allocation_state());
assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed");
}
#ifdef ASSERT void MemAllocator::Allocation::check_for_valid_allocation_state() const { // How to choose between a pending exception and a potential // OutOfMemoryError? Don't allow pending exceptions. // This is a VM policy failure, so how do we exhaustively test it?
assert(!_thread->has_pending_exception(), "shouldn't be allocating with pending exception"); // Allocation of an oop can always invoke a safepoint.
JavaThread::cast(_thread)->check_for_valid_safepoint_state();
} #endif
void MemAllocator::Allocation::notify_allocation_jvmti_sampler() { // support for JVMTI VMObjectAlloc event (no-op if not enabled)
JvmtiExport::vm_object_alloc_event_collector(obj());
if (!JvmtiExport::should_post_sampled_object_alloc()) { // Sampling disabled return;
}
if (!_allocated_outside_tlab && _allocated_tlab_size == 0 && !_tlab_end_reset_for_sample) { // Sample if it's a non-TLAB allocation, or a TLAB allocation that either refills the TLAB // or expands it due to taking a sampler induced slow path. return;
}
// If we want to be sampling, protect the allocated object with a Handle // before doing the callback. The callback is done in the destructor of // the JvmtiSampledObjectAllocEventCollector.
size_t bytes_since_last = 0;
if (_tlab_end_reset_for_sample || _allocated_tlab_size != 0) { // Tell tlab to forget bytes_since_last if we passed it to the heap sampler.
_thread->tlab().set_sample_end(bytes_since_last != 0);
}
}
void MemAllocator::Allocation::notify_allocation_low_memory_detector() { // support low memory notifications (no-op if not enabled)
LowMemoryDetector::detect_low_memory_for_collected_pools();
}
if (JvmtiExport::should_post_sampled_object_alloc()) {
tlab.set_back_allocation_end();
mem = tlab.allocate(_word_size);
// We set back the allocation sample point to try to allocate this, reset it // when done.
allocation._tlab_end_reset_for_sample = true;
if (mem != NULL) { return mem;
}
}
// Retain tlab and allocate object in shared space if // the amount free in the tlab is too large to discard. if (tlab.free() > tlab.refill_waste_limit()) {
tlab.record_slow_allocation(_word_size); return NULL;
}
// Discard tlab and allocate a new one. // To minimize fragmentation, the last TLAB may be smaller than the rest.
size_t new_tlab_size = tlab.compute_size(_word_size);
tlab.retire_before_allocation();
if (new_tlab_size == 0) { return NULL;
}
// Allocate a new TLAB requesting new_tlab_size. Any size // between minimal and new_tlab_size is accepted.
size_t min_tlab_size = ThreadLocalAllocBuffer::compute_min_size(_word_size);
mem = Universe::heap()->allocate_new_tlab(min_tlab_size, new_tlab_size, &allocation._allocated_tlab_size); if (mem == NULL) {
assert(allocation._allocated_tlab_size == 0, "Allocation failed, but actual size was updated. min: " SIZE_FORMAT ", desired: " SIZE_FORMAT ", actual: " SIZE_FORMAT,
min_tlab_size, new_tlab_size, allocation._allocated_tlab_size); return NULL;
}
assert(allocation._allocated_tlab_size != 0, "Allocation succeeded but actual size not updated. mem at: "
PTR_FORMAT " min: " SIZE_FORMAT ", desired: " SIZE_FORMAT,
p2i(mem), min_tlab_size, new_tlab_size);
if (ZeroTLAB) { // ..and clear it.
Copy::zero_to_words(mem, allocation._allocated_tlab_size);
} else { // ...and zap just allocated object. #ifdef ASSERT // Skip mangling the space corresponding to the object header to // ensure that the returned space is not considered parsable by // any concurrent GC thread.
size_t hdr_size = oopDesc::header_size();
Copy::fill_to_words(mem + hdr_size, allocation._allocated_tlab_size - hdr_size, badHeapWordVal); #endif// ASSERT
}
tlab.fill(mem, mem + _word_size, allocation._allocated_tlab_size); return mem;
}
HeapWord* MemAllocator::mem_allocate_slow(Allocation& allocation) const { // Allocation of an oop can always invoke a safepoint.
debug_only(JavaThread::cast(_thread)->check_for_valid_safepoint_state());
if (UseTLAB) { // Try refilling the TLAB and allocating the object in it.
HeapWord* mem = mem_allocate_inside_tlab_slow(allocation); if (mem != NULL) { return mem;
}
}
return mem_allocate_outside_tlab(allocation);
}
HeapWord* MemAllocator::mem_allocate(Allocation& allocation) const { if (UseTLAB) { // Try allocating from an existing TLAB.
HeapWord* mem = mem_allocate_inside_tlab_fast(); if (mem != NULL) { return mem;
}
}
return mem_allocate_slow(allocation);
}
oop MemAllocator::allocate() const {
oop obj = NULL;
{
Allocation allocation(*this, &obj);
HeapWord* mem = mem_allocate(allocation); if (mem != NULL) {
obj = initialize(mem);
} else { // The unhandled oop detector will poison local variable obj, // so reset it to NULL if mem is NULL.
obj = NULL;
}
} return obj;
}
oop MemAllocator::finish(HeapWord* mem) const {
assert(mem != NULL, "NULL object pointer"); // May be bootstrapping
oopDesc::set_mark(mem, markWord::prototype()); // Need a release store to ensure array/class length, mark word, and // object zeroing are visible before setting the klass non-NULL, for // concurrent collectors.
oopDesc::release_set_klass(mem, _klass); return cast_to_oop(mem);
}
oop ObjArrayAllocator::initialize(HeapWord* mem) const { // Set array length before setting the _klass field because a // non-NULL klass field indicates that the object is parsable by // concurrent GC.
assert(_length >= 0, "length should be non-negative"); if (_do_zero) {
mem_clear(mem);
}
arrayOopDesc::set_length(mem, _length); return finish(mem);
}
oop ClassAllocator::initialize(HeapWord* mem) const { // Set oop_size field before setting the _klass field because a // non-NULL _klass field indicates that the object is parsable by // concurrent GC.
assert(_word_size > 0, "oop_size must be positive.");
mem_clear(mem);
java_lang_Class::set_oop_size(mem, _word_size); return finish(mem);
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.26 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.