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.