Skip to content

Commit

Permalink
8319967: [lworld] TypeAryPtr::cast_to_not_null_free hits assert(\!not…
Browse files Browse the repository at this point in the history
…_null_free || \!is_flat()) failed: inconsistency
  • Loading branch information
TobiHartmann committed Nov 14, 2023
1 parent 6e31ad2 commit debc20d
Show file tree
Hide file tree
Showing 13 changed files with 110 additions and 100 deletions.
2 changes: 1 addition & 1 deletion src/hotspot/share/c1/c1_Instruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ bool Instruction::maybe_flat_array() {
if (type->is_obj_array_klass() && !type->as_obj_array_klass()->is_elem_null_free()) {
// The runtime type of [LMyValue might be [QMyValue due to [QMyValue <: [LMyValue.
ciKlass* element_klass = type->as_obj_array_klass()->element_klass();
if (element_klass->can_be_inline_klass() && (!element_klass->is_inlinetype() || element_klass->as_inline_klass()->flat_array())) {
if (element_klass->can_be_inline_klass() && (!element_klass->is_inlinetype() || element_klass->as_inline_klass()->flat_in_array())) {
return true;
}
} else if (type->is_flat_array_klass()) {
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/c1/c1_LIRGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1867,7 +1867,7 @@ bool LIRGenerator::needs_flat_array_store_check(StoreIndexed* x) {
ciType* type = x->value()->declared_type();
if (type != nullptr && type->is_klass()) {
ciKlass* klass = type->as_klass();
if (!klass->can_be_inline_klass() || (klass->is_inlinetype() && !klass->as_inline_klass()->flat_array())) {
if (!klass->can_be_inline_klass() || (klass->is_inlinetype() && !klass->as_inline_klass()->flat_in_array())) {
// This is known to be a non-flat object. If the array is a flat array,
// it will be caught by the code generated by array_store_check().
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/ci/ciInlineKlass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ int ciInlineKlass::field_index_by_offset(int offset) {
}

// Are arrays containing this inline type flat arrays?
bool ciInlineKlass::flat_array() const {
bool ciInlineKlass::flat_in_array() const {
GUARDED_VM_ENTRY(return to_InlineKlass()->flat_array();)
}

Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/ci/ciInlineKlass.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class ciInlineKlass : public ciInstanceKlass {
int first_field_offset() const;
int field_index_by_offset(int offset);

bool flat_array() const;
bool flat_in_array() const;
bool can_be_passed_as_fields() const;
bool can_be_returned_as_fields() const;
bool is_empty();
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/ci/ciMetadata.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class ciMetadata: public ciBaseObject {
virtual bool is_obj_array_klass() const { return false; }
virtual bool is_type_array_klass() const { return false; }
virtual bool is_wrapper() const { return false; }
virtual bool flat_array() const { return false; }
virtual bool flat_in_array() const { return false; }
virtual void dump_replay_data(outputStream* st) { /* do nothing */ }

ciMethod* as_method() {
Expand Down
8 changes: 4 additions & 4 deletions src/hotspot/share/opto/graphKit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3566,8 +3566,8 @@ Node* GraphKit::gen_checkcast(Node *obj, Node* superklass, Node* *failure_contro
record_for_igvn(region);

bool not_inline = !toop->can_be_inline_type();
bool not_flat = !UseFlatArray || not_inline || (toop->is_inlinetypeptr() && !toop->inline_klass()->flat_array());
if (EnableValhalla && not_flat) {
bool not_flat_in_array = !UseFlatArray || not_inline || (toop->is_inlinetypeptr() && !toop->inline_klass()->flat_in_array());
if (EnableValhalla && not_flat_in_array) {
// Check if obj has been loaded from an array
obj = obj->isa_DecodeN() ? obj->in(1) : obj;
Node* array = nullptr;
Expand All @@ -3588,7 +3588,7 @@ Node* GraphKit::gen_checkcast(Node *obj, Node* superklass, Node* *failure_contro
}
if (array != nullptr) {
const TypeAryPtr* ary_t = _gvn.type(array)->isa_aryptr();
if (ary_t != nullptr) {
if (ary_t != nullptr && !ary_t->is_flat()) {
if (!ary_t->is_not_null_free() && not_inline) {
// Casting array element to a non-inline-type, mark array as not null-free.
Node* cast = _gvn.transform(new CheckCastPPNode(control(), array, ary_t->cast_to_not_null_free()));
Expand Down Expand Up @@ -3869,7 +3869,7 @@ Node* GraphKit::get_layout_helper(Node* klass_node, jint& constant_value) {
if (UseFlatArray && !xklass && ary_type != nullptr && !ary_type->is_null_free()) {
// The runtime type of [LMyValue might be [QMyValue due to [QMyValue <: [LMyValue. Don't constant fold.
const TypeOopPtr* elem = ary_type->elem()->make_oopptr();
can_be_flat = ary_type->can_be_inline_array() && (!elem->is_inlinetypeptr() || elem->inline_klass()->flat_array());
can_be_flat = ary_type->can_be_inline_array() && (!elem->is_inlinetypeptr() || elem->inline_klass()->flat_in_array());
}
if (!can_be_flat && (xklass || (klass_t->isa_aryklassptr() && klass_t->is_aryklassptr()->elem() != Type::BOTTOM))) {
jint lhelper;
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/opto/macro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ SafePointScalarObjectNode* PhaseMacroExpand::create_scalarized_object_descriptio
const TypeOopPtr* field_addr_type = res_type->add_offset(offset)->isa_oopptr();
if (res_type->is_flat()) {
ciInlineKlass* vk = res_type->is_aryptr()->elem()->inline_klass();
assert(vk->flat_array(), "must be flat");
assert(vk->flat_in_array(), "must be flat in array");
field_val = inline_type_from_mem(sfpt->memory(), sfpt->control(), vk, field_addr_type->isa_aryptr(), 0, alloc);
} else {
field_val = value_from_mem(sfpt->memory(), sfpt->control(), basic_elem_type, field_type, field_addr_type, alloc);
Expand Down
10 changes: 5 additions & 5 deletions src/hotspot/share/opto/parse2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void Parse::array_load(BasicType bt) {
} else if (!ary_t->is_not_flat()) {
// Cannot statically determine if array is a flat array, emit runtime check
assert(UseFlatArray && is_reference_type(bt) && elemptr->can_be_inline_type() && !ary_t->klass_is_exact() && !ary_t->is_not_null_free() &&
(!elemptr->is_inlinetypeptr() || elemptr->inline_klass()->flat_array()), "array can't be flat");
(!elemptr->is_inlinetypeptr() || elemptr->inline_klass()->flat_in_array()), "array can't be flat");
IdealKit ideal(this);
IdealVariable res(ideal);
ideal.declarations_done();
Expand All @@ -116,7 +116,7 @@ void Parse::array_load(BasicType bt) {
if (elemptr->is_inlinetypeptr()) {
// Element type is known, cast and load from flat representation
ciInlineKlass* vk = elemptr->inline_klass();
assert(vk->flat_array() && elemptr->maybe_null(), "never/always flat - should be optimized");
assert(vk->flat_in_array() && elemptr->maybe_null(), "never/always flat - should be optimized");
ciArrayKlass* array_klass = ciArrayKlass::make(vk, /* null_free */ true);
const TypeAryPtr* arytype = TypeOopPtr::make_from_klass(array_klass)->isa_aryptr();
Node* cast = _gvn.transform(new CheckCastPPNode(control(), ary, arytype));
Expand Down Expand Up @@ -155,7 +155,7 @@ void Parse::array_load(BasicType bt) {
insert_mem_bar_volatile(Op_MemBarCPUOrder, C->get_alias_index(TypeAryPtr::INLINES));

// Keep track of the information that the inline type is in flat arrays
const Type* unknown_value = elemptr->is_instptr()->cast_to_flat_array();
const Type* unknown_value = elemptr->is_instptr()->cast_to_flat_in_array();
buffer = _gvn.transform(new CheckCastPPNode(control(), buffer, unknown_value));

ideal.sync_kit(this);
Expand Down Expand Up @@ -211,7 +211,7 @@ void Parse::array_store(BasicType bt) {
// This is only legal for non-null stores because the array_store_check always passes for null, even
// if the array is null-free. Null stores are handled in GraphKit::gen_inline_array_null_guard().
bool not_null_free = !tval->maybe_null() && !tval->is_oopptr()->can_be_inline_type();
bool not_flat = not_null_free || (tval->is_inlinetypeptr() && !tval->inline_klass()->flat_array());
bool not_flat = not_null_free || (tval->is_inlinetypeptr() && !tval->inline_klass()->flat_in_array());
if (!ary_t->is_not_null_free() && not_null_free) {
// Storing a non-inline type, mark array as not null-free (-> not flat).
ary_t = ary_t->cast_to_not_null_free();
Expand Down Expand Up @@ -278,7 +278,7 @@ void Parse::array_store(BasicType bt) {
Node* casted_ary = ary;
if (vk != nullptr && !stopped()) {
// Element type is known, cast and store to flat representation
assert(vk->flat_array() && elemtype->maybe_null(), "never/always flat - should be optimized");
assert(vk->flat_in_array() && elemtype->maybe_null(), "never/always flat - should be optimized");
ciArrayKlass* array_klass = ciArrayKlass::make(vk, /* null_free */ true);
const TypeAryPtr* arytype = TypeOopPtr::make_from_klass(array_klass)->isa_aryptr();
casted_ary = _gvn.transform(new CheckCastPPNode(control(), casted_ary, arytype));
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/opto/subnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1045,8 +1045,8 @@ const Type *CmpPNode::sub( const Type *t1, const Type *t2 ) const {
}
if (!unrelated_classes) {
// Handle inline type arrays
if ((r0->flat_array() && r1->not_flat_array()) ||
(r1->flat_array() && r0->not_flat_array())) {
if ((r0->flat_in_array() && r1->not_flat_in_array()) ||
(r1->flat_in_array() && r0->not_flat_in_array())) {
// One type is in flat arrays but the other type is not. Must be unrelated.
unrelated_classes = true;
} else if ((r0->is_not_flat() && r1->is_flat()) ||
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/opto/subtypenode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const Type* SubTypeCheckNode::sub(const Type* sub_t, const Type* super_t) const
// Similar to logic in CmpPNode::sub()
bool unrelated_classes = false;
// Handle inline type arrays
if (subk->flat_array() && superk->not_flat_array()) {
if (subk->flat_in_array() && superk->not_flat_in_array()) {
// The subtype is in flat arrays and the supertype is not in flat arrays. Must be unrelated.
unrelated_classes = true;
} else if (subk->is_not_flat() && superk->is_flat()) {
Expand Down
Loading

0 comments on commit debc20d

Please sign in to comment.