/* * Copyright (c) 1997, 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. *
*/
void* MetaspaceObj::operatornew(size_t size, ClassLoaderData* loader_data,
size_t word_size,
MetaspaceObj::Type type, TRAPS) throw() { // Klass has its own operator new return Metaspace::allocate(loader_data, word_size, type, THREAD);
}
// This whole business of passing information from AnyObj::operator new // to the AnyObj constructor via fields in the "object" is technically UB. // But it seems to work within the limitations of HotSpot usage (such as no // multiple inheritance) with the compilers and compiler options we're using. // And it gives some possibly useful checking for misuse of AnyObj. void AnyObj::initialize_allocation_info() { if (~(_allocation_t[0] | allocation_mask) != (uintptr_t)this) { // Operator new() is not called for allocations // on stack and for embedded objects.
set_allocation_type((address)this, STACK_OR_EMBEDDED);
} elseif (allocated_on_stack_or_embedded()) { // STACK_OR_EMBEDDED // For some reason we got a value which resembles // an embedded or stack object (operator new() does not // set such type). Keep it since it is valid value // (even if it was garbage). // Ignore garbage in other fields.
} elseif (is_type_set()) { // Operator new() was called and type was set.
assert(!allocated_on_stack_or_embedded(), "not embedded or stack, this(" PTR_FORMAT ") type %d a[0]=(" PTR_FORMAT ") a[1]=(" PTR_FORMAT ")",
p2i(this), get_allocation_type(), _allocation_t[0], _allocation_t[1]);
} else { // Operator new() was not called. // Assume that it is embedded or stack object.
set_allocation_type((address)this, STACK_OR_EMBEDDED);
}
_allocation_t[1] = 0; // Zap verification value
}
AnyObj::AnyObj(const AnyObj&) { // Initialize _allocation_t as a new object, ignoring object being copied.
initialize_allocation_info();
}
AnyObj& AnyObj::operator=(const AnyObj& r) {
assert(allocated_on_stack_or_embedded(), "copy only into local, this(" PTR_FORMAT ") type %d a[0]=(" PTR_FORMAT ") a[1]=(" PTR_FORMAT ")",
p2i(this), get_allocation_type(), _allocation_t[0], _allocation_t[1]); // Keep current _allocation_t value; return *this;
}
AnyObj::~AnyObj() { // allocated_on_C_heap() also checks that encoded (in _allocation) address == this. if (!allocated_on_C_heap()) { // AnyObj::delete() will zap _allocation for C_heap.
_allocation_t[0] = (uintptr_t)badHeapOopVal; // zap type
}
} #endif// ASSERT
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.