Skip to content

Re-work of arrays meta-data #1452

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: lworld
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/hotspot/cpu/aarch64/c1_Runtime1_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -747,16 +747,16 @@ OopMapSet* Runtime1::generate_code_for(C1StubId id, StubAssembler* sasm) {
__ stop("assert(is a type array klass)");
break;
case C1StubId::new_object_array_id:
__ cmpw(t0, Klass::_lh_array_tag_obj_value); // new "[Ljava/lang/Object;"
__ cmpw(t0, Klass::_lh_array_tag_ref_value); // new "[Ljava/lang/Object;"
__ br(Assembler::EQ, ok);
__ cmpw(t0, Klass::_lh_array_tag_vt_value); // new "[LVT;"
__ cmpw(t0, Klass::_lh_array_tag_flat_value); // new "[LVT;"
__ br(Assembler::EQ, ok);
__ stop("assert(is an object or inline type array klass)");
break;
case C1StubId::new_null_free_array_id:
__ cmpw(t0, Klass::_lh_array_tag_vt_value); // the array can be a flat array.
__ cmpw(t0, Klass::_lh_array_tag_flat_value); // the array can be a flat array.
__ br(Assembler::EQ, ok);
__ cmpw(t0, Klass::_lh_array_tag_obj_value); // the array cannot be a flat array (due to InlineArrayElementMaxFlatSize, etc)
__ cmpw(t0, Klass::_lh_array_tag_ref_value); // the array cannot be a flat array (due to the InlineArrayElementMaxFlatSize, etc.)
__ br(Assembler::EQ, ok);
__ stop("assert(is an object or inline type array klass)");
break;
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/ppc/c1_Runtime1_ppc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ OopMapSet* Runtime1::generate_code_for(C1StubId id, StubAssembler* sasm) {
#ifdef ASSERT
// Assert object type is really an array of the proper kind.
{
int tag = (id == C1StubId::new_type_array_id) ? Klass::_lh_array_tag_type_value : Klass::_lh_array_tag_obj_value;
int tag = (id == C1StubId::new_type_array_id) ? Klass::_lh_array_tag_type_value : Klass::_lh_array_tag_ref_value;
Label ok;
__ lwz(R0, in_bytes(Klass::layout_helper_offset()), R4_ARG2);
__ srawi(R0, R0, Klass::_lh_array_tag_shift);
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/riscv/c1_Runtime1_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ OopMapSet* Runtime1::generate_code_for(C1StubId id, StubAssembler* sasm) {
Register tmp = obj;
__ lwu(tmp, Address(klass, Klass::layout_helper_offset()));
__ sraiw(tmp, tmp, Klass::_lh_array_tag_shift);
int tag = ((id == C1StubId::new_type_array_id) ? Klass::_lh_array_tag_type_value : Klass::_lh_array_tag_obj_value);
int tag = ((id == C1StubId::new_type_array_id) ? Klass::_lh_array_tag_type_value : Klass::_lh_array_tag_ref_value);
__ mv(t0, tag);
__ beq(t0, tmp, ok);
__ stop("assert(is an array klass)");
Expand Down
3 changes: 1 addition & 2 deletions src/hotspot/cpu/s390/c1_Runtime1_s390.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,7 @@ OopMapSet* Runtime1::generate_code_for(C1StubId id, StubAssembler* sasm) {
__ mem2reg_opt(t0, Address(klass, Klass::layout_helper_offset()), false);
__ z_sra(t0, Klass::_lh_array_tag_shift);
int tag = ((id == C1StubId::new_type_array_id)
? Klass::_lh_array_tag_type_value
: Klass::_lh_array_tag_obj_value);
? Klass::_lh_array_tag_type_value : Klass::_lh_array_tag_ref_value);
__ compare32_and_branch(t0, tag, Assembler::bcondEqual, ok);
__ stop("assert(is an array klass)");
__ should_not_reach_here();
Expand Down
8 changes: 4 additions & 4 deletions src/hotspot/cpu/x86/c1_Runtime1_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -911,16 +911,16 @@ OopMapSet* Runtime1::generate_code_for(C1StubId id, StubAssembler* sasm) {
__ stop("assert(is a type array klass)");
break;
case C1StubId::new_object_array_id:
__ cmpl(t0, Klass::_lh_array_tag_obj_value); // new "[Ljava/lang/Object;"
__ cmpl(t0, (Klass::_lh_array_tag_ref_value)); // new "[Ljava/lang/Object;"
__ jcc(Assembler::equal, ok);
__ cmpl(t0, Klass::_lh_array_tag_vt_value); // new "[LVT;"
__ cmpl(t0, Klass::_lh_array_tag_flat_value); // new "[LVT;"
__ jcc(Assembler::equal, ok);
__ stop("assert(is an object or inline type array klass)");
break;
case C1StubId::new_null_free_array_id:
__ cmpl(t0, Klass::_lh_array_tag_vt_value); // the array can be a flat array.
__ cmpl(t0, Klass::_lh_array_tag_flat_value); // the array can be a flat array.
__ jcc(Assembler::equal, ok);
__ cmpl(t0, Klass::_lh_array_tag_obj_value); // the array cannot be a flat array (due to InlineArrayElementMaxFlatSize, etc)
__ cmpl(t0, (Klass::_lh_array_tag_ref_value)); // the array cannot be a flat array (due to InlineArrayElementMaxFlatSize, etc)
__ jcc(Assembler::equal, ok);
__ stop("assert(is an object or inline type array klass)");
break;
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/c1/c1_Runtime1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ JRT_ENTRY(void, Runtime1::load_flat_array(JavaThread* current, flatArrayOopDesc*
NOT_PRODUCT(_load_flat_array_slowcase_cnt++;)
assert(array->length() > 0 && index < array->length(), "already checked");
flatArrayHandle vah(current, array);
oop obj = array->read_value_from_flat_array(index, CHECK);
oop obj = array->obj_at(index, CHECK);
current->set_vm_result_oop(obj);
JRT_END

Expand All @@ -531,7 +531,7 @@ JRT_ENTRY(void, Runtime1::store_flat_array(JavaThread* current, flatArrayOopDesc
SharedRuntime::throw_and_post_jvmti_exception(current, vmSymbols::java_lang_NullPointerException());
} else {
assert(array->klass()->is_flatArray_klass(), "should not be called");
array->write_value_to_flat_array(value, index, CHECK);
array->obj_at_put(index, value, CHECK);
}
JRT_END

Expand Down
6 changes: 3 additions & 3 deletions src/hotspot/share/cds/archiveHeapWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ void ArchiveHeapWriter::ensure_buffer_space(size_t min_bytes) {

objArrayOop ArchiveHeapWriter::allocate_root_segment(size_t offset, int element_count) {
HeapWord* mem = offset_to_buffered_address<HeapWord *>(offset);
memset(mem, 0, objArrayOopDesc::object_size(element_count));
memset(mem, 0, refArrayOopDesc::object_size(element_count));

// The initialization code is copied from MemAllocator::finish and ObjArrayAllocator::initialize.
if (UseCompactObjectHeaders) {
Expand Down Expand Up @@ -220,7 +220,7 @@ void ArchiveHeapWriter::copy_roots_to_buffer(GrowableArrayCHeap<oop, mtClassShar
"Pre-condition: Roots start at aligned boundary: %zu", _buffer_used);

int max_elem_count = ((MIN_GC_REGION_ALIGNMENT - arrayOopDesc::header_size_in_bytes()) / heapOopSize);
assert(objArrayOopDesc::object_size(max_elem_count)*HeapWordSize == MIN_GC_REGION_ALIGNMENT,
assert(refArrayOopDesc::object_size(max_elem_count)*HeapWordSize == MIN_GC_REGION_ALIGNMENT,
"Should match exactly");

HeapRootSegments segments(_buffer_used,
Expand Down Expand Up @@ -334,7 +334,7 @@ void ArchiveHeapWriter::copy_source_objs_to_buffer(GrowableArrayCHeap<oop, mtCla
}

size_t ArchiveHeapWriter::filler_array_byte_size(int length) {
size_t byte_size = objArrayOopDesc::object_size(length) * HeapWordSize;
size_t byte_size = refArrayOopDesc::object_size(length) * HeapWordSize;
return byte_size;
}

Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/cds/archiveUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ bool ArchiveUtils::has_aot_initialized_mirror(InstanceKlass* src_ik) {

size_t HeapRootSegments::size_in_bytes(size_t seg_idx) {
assert(seg_idx < _count, "In range");
return objArrayOopDesc::object_size(size_in_elems(seg_idx)) * HeapWordSize;
return refArrayOopDesc::object_size(size_in_elems(seg_idx)) * HeapWordSize;
}

int HeapRootSegments::size_in_elems(size_t seg_idx) {
Expand Down
4 changes: 3 additions & 1 deletion src/hotspot/share/cds/cdsProtectionDomain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "memory/resourceArea.hpp"
#include "memory/universe.hpp"
#include "oops/instanceKlass.hpp"
#include "oops/refArrayOop.hpp"
#include "oops/symbol.hpp"
#include "runtime/javaCalls.hpp"

Expand Down Expand Up @@ -296,7 +297,8 @@ void CDSProtectionDomain::atomic_set_array_index(OopHandle array, int index, oop
// The important thing here is that all threads pick up the same result.
// It doesn't matter which racing thread wins, as long as only one
// result is used by all threads, and all future queries.
((objArrayOop)array.resolve())->replace_if_null(index, o);
// ((objArrayOop)array.resolve())->replace_if_null(index, o);
refArrayOopDesc::cast(array.resolve())->replace_if_null(index, o);
}

oop CDSProtectionDomain::shared_protection_domain(int index) {
Expand Down
4 changes: 3 additions & 1 deletion src/hotspot/share/cds/cppVtables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "oops/instanceStackChunkKlass.hpp"
#include "oops/methodData.hpp"
#include "oops/objArrayKlass.hpp"
#include "oops/refArrayKlass.hpp"
#include "oops/typeArrayKlass.hpp"
#include "runtime/arguments.hpp"
#include "utilities/globalDefinitions.hpp"
Expand Down Expand Up @@ -67,7 +68,8 @@
f(ObjArrayKlass) \
f(TypeArrayKlass) \
f(FlatArrayKlass) \
f(InlineKlass)
f(InlineKlass) \
f(RefArrayKlass)

class CppVtableInfo {
intptr_t _vtable_size;
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/cds/metaspaceShared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ void MetaspaceShared::serialize(SerializeClosure* soc) {
soc->do_tag(arrayOopDesc::base_offset_in_bytes(T_BYTE));
soc->do_tag(sizeof(ConstantPool));
soc->do_tag(sizeof(ConstantPoolCache));
soc->do_tag(objArrayOopDesc::base_offset_in_bytes());
soc->do_tag(refArrayOopDesc::base_offset_in_bytes());
soc->do_tag(typeArrayOopDesc::base_offset_in_bytes(T_BYTE));
soc->do_tag(sizeof(Symbol));

Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/classfile/javaClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,7 @@ void java_lang_Class::allocate_mirror(Klass* k, bool is_scratch, Handle protecti
comp_mirror = Handle(THREAD, Universe::java_mirror(type));
}
} else {
assert(k->is_objArray_klass(), "Must be");
assert(k->is_refArray_klass(), "Must be");
Klass* element_klass = ObjArrayKlass::cast(k)->element_klass();
assert(element_klass != nullptr, "Must have an element klass");
oop comp_oop = element_klass->java_mirror();
Expand Down
8 changes: 4 additions & 4 deletions src/hotspot/share/classfile/stringTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ void StringTable::allocate_shared_strings_array(TRAPS) {
}

int total = (int)_items_count;
size_t single_array_size = objArrayOopDesc::object_size(total);
size_t single_array_size = refArrayOopDesc::object_size(total);

log_info(cds)("allocated string table for %d strings", total);

Expand All @@ -963,8 +963,8 @@ void StringTable::allocate_shared_strings_array(TRAPS) {
} else {
// Split the table in two levels of arrays.
int primary_array_length = (total + _secondary_array_max_length - 1) / _secondary_array_max_length;
size_t primary_array_size = objArrayOopDesc::object_size(primary_array_length);
size_t secondary_array_size = objArrayOopDesc::object_size(_secondary_array_max_length);
size_t primary_array_size = refArrayOopDesc::object_size(primary_array_length);
size_t secondary_array_size = refArrayOopDesc::object_size(_secondary_array_max_length);

if (ArchiveHeapWriter::is_too_large_to_archive(secondary_array_size)) {
// This can only happen if you have an extremely large number of classes that
Expand Down Expand Up @@ -1004,7 +1004,7 @@ void StringTable::allocate_shared_strings_array(TRAPS) {
void StringTable::verify_secondary_array_index_bits() {
int max;
for (max = 1; ; max++) {
size_t next_size = objArrayOopDesc::object_size(1 << (max + 1));
size_t next_size = refArrayOopDesc::object_size(1 << (max + 1));
if (ArchiveHeapWriter::is_too_large_to_archive(next_size)) {
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/gc/shared/memAllocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "utilities/globalDefinitions.hpp"
#include "utilities/macros.hpp"

// These fascilities are used for allocating, and initializing newly allocated objects.
// These facilities are used for allocating, and initializing newly allocated objects.

class MemAllocator: StackObj {
protected:
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/gc/z/zIterator.inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ inline bool ZIterator::is_invisible_object(oop obj) {
}

inline bool ZIterator::is_invisible_object_array(oop obj) {
return obj->klass()->is_objArray_klass() && is_invisible_object(obj);
return obj->klass()->is_refArray_klass() && is_invisible_object(obj);
}

// This iterator skips invisible object arrays
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/interpreter/interpreterRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,14 +298,14 @@ JRT_END
JRT_ENTRY(void, InterpreterRuntime::flat_array_load(JavaThread* current, arrayOopDesc* array, int index))
assert(array->is_flatArray(), "Must be");
flatArrayOop farray = (flatArrayOop)array;
oop res = farray->read_value_from_flat_array(index, CHECK);
oop res = farray->obj_at(index, CHECK);
current->set_vm_result_oop(res);
JRT_END

JRT_ENTRY(void, InterpreterRuntime::flat_array_store(JavaThread* current, oopDesc* val, arrayOopDesc* array, int index))
assert(array->is_flatArray(), "Must be");
flatArrayOop farray = (flatArrayOop)array;
farray->write_value_to_flat_array(val, index, CHECK);
farray->obj_at_put(index, val, CHECK);
JRT_END

JRT_ENTRY(void, InterpreterRuntime::multianewarray(JavaThread* current, jint* first_size_address))
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/share/jvmci/vmStructs_jvmci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,7 @@
declare_constant(Klass::_lh_array_tag_shift) \
declare_constant(Klass::_lh_array_tag_type_value) \
declare_constant(Klass::_lh_array_tag_obj_value) \
declare_constant(Klass::_lh_array_tag_ref_value) \
\
declare_constant(markWord::no_hash) \
\
Expand Down
4 changes: 4 additions & 0 deletions src/hotspot/share/memory/iterator.inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "oops/instanceStackChunkKlass.inline.hpp"
#include "oops/objArrayKlass.inline.hpp"
#include "oops/typeArrayKlass.inline.hpp"
#include "oops/refArrayKlass.inline.hpp"
#include "utilities/debug.hpp"

// Defaults to strong claiming.
Expand Down Expand Up @@ -157,6 +158,7 @@ class OopOopIterateDispatch : public AllStatic {
set_init_function<ObjArrayKlass>();
set_init_function<TypeArrayKlass>();
set_init_function<FlatArrayKlass>();
set_init_function<RefArrayKlass>();
}
};

Expand Down Expand Up @@ -222,6 +224,7 @@ class OopOopIterateBoundedDispatch {
set_init_function<ObjArrayKlass>();
set_init_function<TypeArrayKlass>();
set_init_function<FlatArrayKlass>();
set_init_function<RefArrayKlass>();
}
};

Expand Down Expand Up @@ -287,6 +290,7 @@ class OopOopIterateBackwardsDispatch {
set_init_function<ObjArrayKlass>();
set_init_function<TypeArrayKlass>();
set_init_function<FlatArrayKlass>();
set_init_function<RefArrayKlass>();
}
};

Expand Down
35 changes: 34 additions & 1 deletion src/hotspot/share/memory/oopFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,39 @@ typeArrayOop oopFactory::new_typeArray_nozero(BasicType type, int length, TRAPS)
return klass->allocate_common(length, false, THREAD);
}

objArrayOop oopFactory::new_objArray2(Klass* klass, int length, ArrayKlass::Properties properties, TRAPS) {
assert(klass->is_klass(), "must be instance class");
if (klass->is_array_klass()) {
assert(properties == ArrayKlass::Properties::DEFAULT, "properties only apply to single dimension arrays");
return ArrayKlass::cast(klass)->allocate_arrayArray(1, length, THREAD);
}
if (klass->is_identity_class() || klass->is_abstract()) {
return InstanceKlass::cast(klass)->allocate_objArray(1, length, THREAD);
} else {
assert(!klass->is_identity_class() && !klass->is_abstract(), "Monomorphism required below");
InlineKlass* vk = InlineKlass::cast(klass);
objArrayOop array = nullptr;
ArrayDescription ad = ObjArrayKlass::array_layout_selection(klass, properties);
switch (ad._kind) {
case Klass::RefArrayKlassKind: {
if (ArrayKlass::is_null_restricted(properties)) {
ObjArrayKlass* array_klass = vk->null_free_reference_array(CHECK_NULL);
array = array_klass->allocate(length, CHECK_NULL);
} else {
array = InstanceKlass::cast(klass)->allocate_objArray(1, length, THREAD);
}
break;
}
case Klass::FlatArrayKlassKind: {
array = oopFactory::new_flatArray(vk, length, ad._layout_kind, CHECK_NULL);
break;
}
default:
ShouldNotReachHere();
}
return array;
}
}

objArrayOop oopFactory::new_objArray(Klass* klass, int length, TRAPS) {
assert(klass->is_klass(), "must be instance class");
Expand All @@ -123,7 +156,7 @@ objArrayOop oopFactory::new_null_free_objArray(Klass* k, int length, TRAPS) {
InlineKlass* klass = InlineKlass::cast(k);
ObjArrayKlass* array_klass = klass->null_free_reference_array(CHECK_NULL);

assert(array_klass->is_objArray_klass(), "Must be");
assert(array_klass->is_refArray_klass(), "Must be");
assert(array_klass->is_null_free_array_klass(), "Must be");

objArrayOop oop = array_klass->allocate(length, CHECK_NULL);
Expand Down
2 changes: 2 additions & 0 deletions src/hotspot/share/memory/oopFactory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#define SHARE_MEMORY_OOPFACTORY_HPP

#include "memory/referenceType.hpp"
#include "oops/arrayKlass.hpp"
#include "oops/oopsHierarchy.hpp"
#include "runtime/handles.hpp"
#include "utilities/exceptions.hpp"
Expand Down Expand Up @@ -55,6 +56,7 @@ class oopFactory: AllStatic {

// Regular object arrays
static objArrayOop new_objArray(Klass* klass, int length, TRAPS);
static objArrayOop new_objArray2(Klass* klass, int length, ArrayKlass::Properties properties, TRAPS);

// Value arrays...
// LWorld:
Expand Down
7 changes: 4 additions & 3 deletions src/hotspot/share/oops/arrayKlass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "oops/objArrayKlass.hpp"
#include "oops/objArrayOop.hpp"
#include "oops/oop.inline.hpp"
#include "oops/refArrayKlass.hpp"
#include "runtime/handles.inline.hpp"

void* ArrayKlass::operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPS) throw() {
Expand Down Expand Up @@ -159,8 +160,8 @@ ArrayKlass* ArrayKlass::array_klass(int n, TRAPS) {

if (higher_dimension() == nullptr) {
// Create multi-dim klass object and link them together
ObjArrayKlass* ak =
ObjArrayKlass::allocate_objArray_klass(class_loader_data(), dim + 1, this, false, CHECK_NULL);
ObjArrayKlass* ak = nullptr;
ak = RefArrayKlass::allocate_refArray_klass(class_loader_data(), dim + 1, this, false, CHECK_NULL);
// use 'release' to pair with lock-free load
release_set_higher_dimension(ak);
assert(ak->lower_dimension() == this, "lower dimension mismatch");
Expand Down Expand Up @@ -210,7 +211,7 @@ GrowableArray<Klass*>* ArrayKlass::compute_secondary_supers(int num_extra_slots,

objArrayOop ArrayKlass::allocate_arrayArray(int n, int length, TRAPS) {
check_array_allocation_length(length, arrayOopDesc::max_array_length(T_ARRAY), CHECK_NULL);
size_t size = objArrayOopDesc::object_size(length);
size_t size = refArrayOopDesc::object_size(length);
ArrayKlass* ak = array_klass(n + dimension(), CHECK_NULL);
objArrayOop o = (objArrayOop)Universe::heap()->array_allocate(ak, size, length,
/* do_zero */ true, CHECK_NULL);
Expand Down
Loading