< prev index next > src/hotspot/share/opto/parse3.cpp
Print this page
#include "precompiled.hpp"
#include "compiler/compileLog.hpp"
#include "interpreter/linkResolver.hpp"
#include "memory/universe.hpp"
+ #include "oops/flatArrayKlass.hpp"
#include "oops/objArrayKlass.hpp"
#include "opto/addnode.hpp"
#include "opto/castnode.hpp"
+ #include "opto/inlinetypenode.hpp"
#include "opto/memnode.hpp"
#include "opto/parse.hpp"
#include "opto/rootnode.hpp"
#include "opto/runtime.hpp"
#include "opto/subnode.hpp"
#include "runtime/handles.inline.hpp"
//=============================================================================
// Helper methods for _get* and _put* bytecodes
//=============================================================================
+
void Parse::do_field_access(bool is_get, bool is_field) {
bool will_link;
ciField* field = iter().get_field(will_link);
assert(will_link, "getfield: typeflow responsibility");
ciInstanceKlass* field_holder = field->holder();
+ if (is_get && is_field && field_holder->is_inlinetype() && peek()->is_InlineType()) {
+ InlineTypeNode* vt = peek()->as_InlineType();
+ null_check(vt);
+ Node* value = vt->field_value_by_offset(field->offset_in_bytes());
+ if (value->is_InlineType()) {
+ value = value->as_InlineType()->adjust_scalarization_depth(this);
+ }
+ pop();
+ push_node(field->layout_type(), value);
+ return;
+ }
+
if (is_field == field->is_static()) {
// Interpreter will throw java_lang_IncompatibleClassChangeError
// Check this before allowing <clinit> methods to access static fields
uncommon_trap(Deoptimization::Reason_unhandled,
Deoptimization::Action_none);
return;
}
// Deoptimize on putfield writes to call site target field outside of CallSite ctor.
if (!is_get && field->is_call_site_target() &&
- !(method()->holder() == field_holder && method()->is_object_initializer())) {
+ !(method()->holder() == field_holder && method()->is_object_constructor())) {
uncommon_trap(Deoptimization::Reason_unhandled,
Deoptimization::Action_reinterpret,
nullptr, "put to call site target field");
return;
}
assert(_gvn.type(obj)->higher_equal(tjp), "cast_up is no longer needed");
#endif
if (is_get) {
(void) pop(); // pop receiver before getting
- do_get_xxx(obj, field, is_field);
+ do_get_xxx(obj, field);
} else {
do_put_xxx(obj, field, is_field);
+ if (stopped()) {
+ return;
+ }
(void) pop(); // pop receiver after putting
}
} else {
const TypeInstPtr* tip = TypeInstPtr::make(field_holder->java_mirror());
obj = _gvn.makecon(tip);
if (is_get) {
- do_get_xxx(obj, field, is_field);
+ do_get_xxx(obj, field);
} else {
do_put_xxx(obj, field, is_field);
}
}
}
-
- void Parse::do_get_xxx(Node* obj, ciField* field, bool is_field) {
+ void Parse::do_get_xxx(Node* obj, ciField* field) {
BasicType bt = field->layout_type();
-
// Does this field have a constant value? If so, just push the value.
- if (field->is_constant() &&
+ if (field->is_constant() && !field->is_flat() &&
// Keep consistent with types found by ciTypeFlow: for an
// unloaded field type, ciTypeFlow::StateVector::do_getstatic()
// speculates the field is null. The code in the rest of this
// method does the same. We must not bypass it and use a non
// null constant here.
return;
}
}
ciType* field_klass = field->type();
- bool is_vol = field->is_volatile();
-
- // Compute address and memory type.
+ field_klass = improve_abstract_inline_type_klass(field_klass);
int offset = field->offset_in_bytes();
- const TypePtr* adr_type = C->alias_type(field)->adr_type();
- Node *adr = basic_plus_adr(obj, obj, offset);
-
- // Build the resultant type of the load
- const Type *type;
-
bool must_assert_null = false;
- DecoratorSet decorators = IN_HEAP;
- decorators |= is_vol ? MO_SEQ_CST : MO_UNORDERED;
-
- bool is_obj = is_reference_type(bt);
-
- if (is_obj) {
- if (!field->type()->is_loaded()) {
- type = TypeInstPtr::BOTTOM;
- must_assert_null = true;
- } else if (field->is_static_constant()) {
- // This can happen if the constant oop is non-perm.
- ciObject* con = field->constant_value().as_object();
- // Do not "join" in the previous type; it doesn't add value,
- // and may yield a vacuous result if the field is of interface type.
- if (con->is_null_object()) {
- type = TypePtr::NULL_PTR;
+ Node* ld = nullptr;
+ if (field->is_null_free() && field_klass->as_inline_klass()->is_empty()) {
+ // Loading from a field of an empty inline type. Just return the default instance.
+ ld = InlineTypeNode::make_default(_gvn, field_klass->as_inline_klass());
+ } else if (field->is_flat()) {
+ // Loading from a flat inline type field.
+ ld = InlineTypeNode::make_from_flat(this, field_klass->as_inline_klass(), obj, obj, field->holder(), offset);
+ } else {
+ // Build the resultant type of the load
+ const Type* type;
+ if (is_reference_type(bt)) {
+ if (!field_klass->is_loaded()) {
+ type = TypeInstPtr::BOTTOM;
+ must_assert_null = true;
+ } else if (field->is_static_constant()) {
+ // This can happen if the constant oop is non-perm.
+ ciObject* con = field->constant_value().as_object();
+ // Do not "join" in the previous type; it doesn't add value,
+ // and may yield a vacuous result if the field is of interface type.
+ if (con->is_null_object()) {
+ type = TypePtr::NULL_PTR;
+ } else {
+ type = TypeOopPtr::make_from_constant(con)->isa_oopptr();
+ }
+ assert(type != nullptr, "field singleton type must be consistent");
} else {
- type = TypeOopPtr::make_from_constant(con)->isa_oopptr();
+ type = TypeOopPtr::make_from_klass(field_klass->as_klass());
+ if (field->is_null_free() && field->is_static()) {
+ // Check if static inline type field is already initialized
+ ciInstance* mirror = field->holder()->java_mirror();
+ ciObject* val = mirror->field_value(field).as_object();
+ if (!val->is_null_object()) {
+ type = type->join_speculative(TypePtr::NOTNULL);
+ }
+ }
}
- assert(type != nullptr, "field singleton type must be consistent");
} else {
- type = TypeOopPtr::make_from_klass(field_klass->as_klass());
+ type = Type::get_const_basic_type(bt);
+ }
+ Node* adr = basic_plus_adr(obj, obj, offset);
+ const TypePtr* adr_type = C->alias_type(field)->adr_type();
+ DecoratorSet decorators = IN_HEAP;
+ decorators |= field->is_volatile() ? MO_SEQ_CST : MO_UNORDERED;
+ ld = access_load_at(obj, adr, adr_type, type, bt, decorators);
+ if (field_klass->is_inlinetype()) {
+ // Load a non-flattened inline type from memory
+ ld = InlineTypeNode::make_from_oop(this, ld, field_klass->as_inline_klass(), field->is_null_free());
}
- } else {
- type = Type::get_const_basic_type(bt);
}
- Node* ld = access_load_at(obj, adr, adr_type, type, bt, decorators);
-
// Adjust Java stack
if (type2size[bt] == 1)
push(ld);
else
push_pair(ld);
if (PrintOpto && (Verbose || WizardMode)) {
method()->print_name(); tty->print_cr(" asserting nullness of field at bci: %d", bci());
}
if (C->log() != nullptr) {
C->log()->elem("assert_null reason='field' klass='%d'",
- C->log()->identify(field->type()));
+ C->log()->identify(field_klass));
}
// If there is going to be a trap, put it at the next bytecode:
set_bci(iter().next_bci());
null_assert(peek());
set_bci(iter().cur_bci()); // put it back
}
}
+ // If the field klass is an abstract value klass (for which we do not know the layout, yet), it could have a unique
+ // concrete sub klass for which we have a fixed layout. This allows us to use InlineTypeNodes instead.
+ ciType* Parse::improve_abstract_inline_type_klass(ciType* field_klass) {
+ Dependencies* dependencies = C->dependencies();
+ if (UseUniqueSubclasses && dependencies != nullptr && field_klass->is_instance_klass()) {
+ ciInstanceKlass* instance_klass = field_klass->as_instance_klass();
+ if (instance_klass->is_loaded() && instance_klass->is_abstract_value_klass()) {
+ ciInstanceKlass* sub_klass = instance_klass->unique_concrete_subklass();
+ if (sub_klass != nullptr && sub_klass != field_klass) {
+ field_klass = sub_klass;
+ dependencies->assert_abstract_with_unique_concrete_subtype(instance_klass, sub_klass);
+ }
+ }
+ }
+ return field_klass;
+ }
+
void Parse::do_put_xxx(Node* obj, ciField* field, bool is_field) {
bool is_vol = field->is_volatile();
-
- // Compute address and memory type.
int offset = field->offset_in_bytes();
- const TypePtr* adr_type = C->alias_type(field)->adr_type();
- Node* adr = basic_plus_adr(obj, obj, offset);
BasicType bt = field->layout_type();
- // Value to be stored
Node* val = type2size[bt] == 1 ? pop() : pop_pair();
- DecoratorSet decorators = IN_HEAP;
- decorators |= is_vol ? MO_SEQ_CST : MO_UNORDERED;
-
- bool is_obj = is_reference_type(bt);
-
- // Store the value.
- const Type* field_type;
- if (!field->type()->is_loaded()) {
- field_type = TypeInstPtr::BOTTOM;
+ if (field->is_null_free()) {
+ PreserveReexecuteState preexecs(this);
+ jvms()->set_should_reexecute(true);
+ inc_sp(1);
+ val = null_check(val);
+ if (stopped()) {
+ return;
+ }
+ }
+ if (obj->is_InlineType()) {
+ set_inline_type_field(obj, field, val);
+ return;
+ }
+ if (field->is_null_free() && field->type()->as_inline_klass()->is_empty()) {
+ // Storing to a field of an empty inline type. Ignore.
+ return;
+ } else if (field->is_flat()) {
+ // Storing to a flat inline type field.
+ if (!val->is_InlineType()) {
+ val = InlineTypeNode::make_from_oop(this, val, field->type()->as_inline_klass());
+ }
+ inc_sp(1);
+ val->as_InlineType()->store_flat(this, obj, obj, field->holder(), offset, IN_HEAP | MO_UNORDERED);
+ dec_sp(1);
} else {
- if (is_obj) {
- field_type = TypeOopPtr::make_from_klass(field->type()->as_klass());
+ // Store the value.
+ const Type* field_type;
+ if (!field->type()->is_loaded()) {
+ field_type = TypeInstPtr::BOTTOM;
} else {
- field_type = Type::BOTTOM;
+ if (is_reference_type(bt)) {
+ field_type = TypeOopPtr::make_from_klass(field->type()->as_klass());
+ } else {
+ field_type = Type::BOTTOM;
+ }
}
+ Node* adr = basic_plus_adr(obj, obj, offset);
+ const TypePtr* adr_type = C->alias_type(field)->adr_type();
+ DecoratorSet decorators = IN_HEAP;
+ decorators |= is_vol ? MO_SEQ_CST : MO_UNORDERED;
+ inc_sp(1);
+ access_store_at(obj, adr, adr_type, val, field_type, bt, decorators);
+ dec_sp(1);
}
- access_store_at(obj, adr, adr_type, val, field_type, bt, decorators);
if (is_field) {
// Remember we wrote a volatile field.
// For not multiple copy atomic cpu (ppc64) a barrier should be issued
// in constructors which have such stores. See do_exits() in parse1.cpp.
}
}
}
}
+ void Parse::set_inline_type_field(Node* obj, ciField* field, Node* val) {
+ assert(_method->is_object_constructor(), "inline type is initialized outside of constructor");
+ assert(obj->as_InlineType()->is_larval(), "must be larval");
+ assert(!_gvn.type(obj)->maybe_null(), "should never be null");
+
+ // Re-execute if buffering in below code triggers deoptimization.
+ PreserveReexecuteState preexecs(this);
+ jvms()->set_should_reexecute(true);
+ inc_sp(1);
+
+ if (!val->is_InlineType() && field->type()->is_inlinetype()) {
+ // Scalarize inline type field value
+ val = InlineTypeNode::make_from_oop(this, val, field->type()->as_inline_klass(), field->is_null_free());
+ } else if (val->is_InlineType() && !field->is_flat()) {
+ // Field value needs to be allocated because it can be merged with a non-inline type.
+ val = val->as_InlineType()->buffer(this);
+ }
+
+ // Clone the inline type node and set the new field value
+ InlineTypeNode* new_vt = obj->as_InlineType()->clone_if_required(&_gvn, _map);
+ new_vt->set_field_value_by_offset(field->offset_in_bytes(), val);
+ new_vt = new_vt->adjust_scalarization_depth(this);
+
+ // If the inline type is buffered and the caller might use the buffer, update it.
+ if (new_vt->is_allocated(&gvn()) && (!_caller->has_method() || C->inlining_incrementally() || _caller->method()->is_object_constructor())) {
+ new_vt->store(this, new_vt->get_oop(), new_vt->get_oop(), new_vt->bottom_type()->inline_klass(), 0, field->offset_in_bytes());
+
+ // Preserve allocation ptr to create precedent edge to it in membar
+ // generated on exit from constructor.
+ AllocateNode* alloc = AllocateNode::Ideal_allocation(new_vt->get_oop());
+ if (alloc != nullptr) {
+ set_alloc_with_final_or_stable(new_vt->get_oop());
+ }
+ set_wrote_final(true);
+ }
+
+ replace_in_map(obj, _gvn.transform(new_vt));
+ return;
+ }
+
//=============================================================================
- void Parse::do_anewarray() {
+
+ void Parse::do_newarray() {
bool will_link;
ciKlass* klass = iter().get_klass(will_link);
// Uncommon Trap when class that array contains is not loaded
// we need the loaded class for the rest of graph; do not
// initialize the container class (see Java spec)!!!
- assert(will_link, "anewarray: typeflow responsibility");
+ assert(will_link, "newarray: typeflow responsibility");
+
+ ciArrayKlass* array_klass = ciArrayKlass::make(klass);
- ciObjArrayKlass* array_klass = ciObjArrayKlass::make(klass);
// Check that array_klass object is loaded
if (!array_klass->is_loaded()) {
// Generate uncommon_trap for unloaded array_class
uncommon_trap(Deoptimization::Reason_unloaded,
Deoptimization::Action_reinterpret,
array_klass);
return;
+ } else if (array_klass->element_klass() != nullptr &&
+ array_klass->element_klass()->is_inlinetype() &&
+ !array_klass->element_klass()->as_inline_klass()->is_initialized()) {
+ uncommon_trap(Deoptimization::Reason_uninitialized,
+ Deoptimization::Action_reinterpret,
+ nullptr);
+ return;
}
kill_dead_locals();
const TypeKlassPtr* array_klass_type = TypeKlassPtr::make(array_klass, Type::trust_interfaces);
// get the lengths from the stack (first dimension is on top)
Node** length = NEW_RESOURCE_ARRAY(Node*, ndimensions + 1);
length[ndimensions] = nullptr; // terminating null for make_runtime_call
int j;
- for (j = ndimensions-1; j >= 0 ; j--) length[j] = pop();
+ ciKlass* elem_klass = array_klass;
+ for (j = ndimensions-1; j >= 0; j--) {
+ length[j] = pop();
+ elem_klass = elem_klass->as_array_klass()->element_klass();
+ }
+ if (elem_klass != nullptr && elem_klass->is_inlinetype() && !elem_klass->as_inline_klass()->is_initialized()) {
+ inc_sp(ndimensions);
+ uncommon_trap(Deoptimization::Reason_uninitialized,
+ Deoptimization::Action_reinterpret,
+ nullptr);
+ return;
+ }
// The original expression was of this form: new T[length0][length1]...
// It is often the case that the lengths are small (except the last).
// If that happens, use the fast 1-d creator a constant number of times.
const int expand_limit = MIN2((int)MultiArrayExpandLimit, 100);
< prev index next >