< prev index next >

src/hotspot/share/opto/parse3.cpp

Print this page
*** 24,13 ***
--- 24,15 ---
  
  #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"

*** 38,28 ***
  #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_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())) {
      uncommon_trap(Deoptimization::Reason_unhandled,
                    Deoptimization::Action_reinterpret,
                    nullptr, "put to call site target field");
      return;
    }
--- 40,41 ---
  #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_constructor())) {
      uncommon_trap(Deoptimization::Reason_unhandled,
                    Deoptimization::Action_reinterpret,
                    nullptr, "put to call site target field");
      return;
    }

*** 86,32 ***
      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);
      } else {
        do_put_xxx(obj, field, is_field);
        (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);
      } else {
        do_put_xxx(obj, field, is_field);
      }
    }
  }
  
! 
- void Parse::do_get_xxx(Node* obj, ciField* field, bool is_field) {
    BasicType bt = field->layout_type();
- 
    // Does this field have a constant value?  If so, just push the value.
!   if (field->is_constant() &&
        // 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.
--- 101,33 ---
      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);
      } 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);
      } else {
        do_put_xxx(obj, field, 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() && !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.

*** 123,51 ***
        return;
      }
    }
  
    ciType* field_klass = field->type();
!   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);
- 
-   // 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;
        } else {
!         type = TypeOopPtr::make_from_constant(con)->isa_oopptr();
        }
-       assert(type != nullptr, "field singleton type must be consistent");
      } else {
!       type = TypeOopPtr::make_from_klass(field_klass->as_klass());
      }
-   } 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);
--- 139,64 ---
        return;
      }
    }
  
    ciType* field_klass = field->type();
!   field_klass = improve_abstract_inline_type_klass(field_klass);
    int offset = field->offset_in_bytes();
    bool must_assert_null = false;
  
!   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_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);
+           }
+         }
        }
      } else {
!       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());
      }
    }
  
    // Adjust Java stack
    if (type2size[bt] == 1)
      push(ld);
    else
      push_pair(ld);

*** 186,47 ***
      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()));
      }
      // 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
    }
  }
  
  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;
    } else {
!     if (is_obj) {
!       field_type = TypeOopPtr::make_from_klass(field->type()->as_klass());
      } else {
!       field_type = Type::BOTTOM;
      }
    }
-   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.
--- 215,146 ---
      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_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();
    int offset = field->offset_in_bytes();
    BasicType bt = field->layout_type();
    Node* val = type2size[bt] == 1 ? pop() : pop_pair();
  
!   if (obj->is_InlineType()) {
!     // TODO 8325106 Factor into own method
+     // TODO 8325106 Assert that we only do this in the constructor and align with checks in ::do_call
+     //if (_method->is_object_constructor() && _method->holder()->is_inlinetype()) {
+     assert(obj->as_InlineType()->is_larval(), "must be larval");
+ 
+     // TODO 8325106 Assert that holder is null-free
+     /*
+     int holder_depth = field->type()->size();
+     null_check(peek(holder_depth));
+     if (stopped()) {
+       return;
+     }
+     */
+ 
+     if (field->is_null_free()) {
+       PreserveReexecuteState preexecs(this);
+       jvms()->set_should_reexecute(true);
+       inc_sp(1);
+       val = null_check(val);
+       if (stopped()) {
+         return;
+       }
+     }
+     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 an oop.
+       // Re-execute if buffering triggers deoptimization.
+       PreserveReexecuteState preexecs(this);
+       jvms()->set_should_reexecute(true);
+       inc_sp(1);
+       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);
+     {
+       PreserveReexecuteState preexecs(this);
+       jvms()->set_should_reexecute(true);
+       inc_sp(1);
+       new_vt = new_vt->adjust_scalarization_depth(this);
+     }
  
!     // TODO 8325106 Double check and explain these checks
+     if ((!_caller->has_method() || C->inlining_incrementally() || _caller->method()->is_object_constructor()) && new_vt->is_allocated(&gvn())) {
+       assert(new_vt->as_InlineType()->is_allocated(&gvn()), "must be buffered");
+       // We need to store to the buffer
+       // TODO 8325106 looks like G1BarrierSetC2::g1_can_remove_pre_barrier is not strong enough to remove the pre barrier
+       // TODO is it really guaranteed that the preval is null?
+       new_vt->store(this, new_vt->get_oop(), new_vt->get_oop(), new_vt->bottom_type()->inline_klass(), 0, C2_TIGHTLY_COUPLED_ALLOC | IN_HEAP | MO_UNORDERED, 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(new_vt->get_oop());
+       }
+       set_wrote_final(true);
+     }
+ 
+     replace_in_map(obj, _gvn.transform(new_vt));
+     return;
+   }
  
!   if (field->is_null_free()) {
!     PreserveReexecuteState preexecs(this);
!     inc_sp(1);
!     jvms()->set_should_reexecute(true);
+     val = null_check(val);
+   }
+   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);
+     dec_sp(1);
    } else {
!     // Store the value.
!     const Type* field_type;
+     if (!field->type()->is_loaded()) {
+       field_type = TypeInstPtr::BOTTOM;
      } else {
!       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);
    }
  
    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.

*** 254,27 ***
      }
    }
  }
  
  //=============================================================================
! void Parse::do_anewarray() {
    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");
  
-   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;
    }
  
    kill_dead_locals();
  
    const TypeKlassPtr* array_klass_type = TypeKlassPtr::make(array_klass, Type::trust_interfaces);
--- 382,36 ---
      }
    }
  }
  
  //=============================================================================
! 
+ 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, "newarray: typeflow responsibility");
+ 
+   ciArrayKlass* array_klass = ciArrayKlass::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);

*** 331,11 ***
  
    // 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();
  
    // 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);
--- 468,22 ---
  
    // 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;
!   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 >