< 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 +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_field && field_holder->is_inlinetype() && peek()->is_InlineTypeBase()) {
+     assert(is_get, "inline type field store not supported");
+     InlineTypeBaseNode* vt = peek()->as_InlineTypeBase();
+     if (vt->is_InlineTypePtr()) {
+       null_check(vt);
+     }
+     pop();
+     Node* value = vt->field_value_by_offset(field->offset());
+     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,
                    NULL, "put to call site target field");
      return;
    }

@@ -86,32 +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, 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_flattened() &&
        // 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 +139,63 @@
        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;
+   Node* ld = NULL;
+   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_flattened()) {
+     // Loading from a flattened inline type field.
+     ld = InlineTypeNode::make_from_flattened(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 != NULL, "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 != NULL, "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);

@@ -186,47 +214,55 @@
      if (PrintOpto && (Verbose || WizardMode)) {
        method()->print_name(); tty->print_cr(" asserting nullness of field at bci: %d", bci());
      }
      if (C->log() != NULL) {
        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
    }
  }
  
  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;
+   assert(!field->is_null_free() || val->is_InlineType() || !gvn().type(val)->maybe_null(), "Null store to inline type field");
+   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_flattened()) {
+     // Storing to a flattened inline type field.
+     if (!val->is_InlineType()) {
+       val = InlineTypeNode::make_from_oop(this, val, field->type()->as_inline_klass());
+     }
+     val->as_InlineType()->store_flattened(this, obj, obj, field->holder(), offset);
    } 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.

@@ -254,27 +290,37 @@
      }
    }
  }
  
  //=============================================================================
- void Parse::do_anewarray() {
+ 
+ void Parse::do_newarray() {
    bool will_link;
    ciKlass* klass = iter().get_klass(will_link);
+   bool null_free = iter().has_Q_signature();
  
    // 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, null_free);
  
-   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() != NULL &&
+              array_klass->element_klass()->is_inlinetype() &&
+              !array_klass->element_klass()->as_inline_klass()->is_initialized()) {
+     uncommon_trap(Deoptimization::Reason_uninitialized,
+                   Deoptimization::Action_reinterpret,
+                   NULL);
+     return;
    }
  
    kill_dead_locals();
  
    const TypeKlassPtr* array_klass_type = TypeKlassPtr::make(array_klass);

@@ -331,11 +377,22 @@
  
    // get the lengths from the stack (first dimension is on top)
    Node** length = NEW_RESOURCE_ARRAY(Node*, ndimensions + 1);
    length[ndimensions] = NULL;  // 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 != NULL && elem_klass->is_inlinetype() && !elem_klass->as_inline_klass()->is_initialized()) {
+     inc_sp(ndimensions);
+     uncommon_trap(Deoptimization::Reason_uninitialized,
+                   Deoptimization::Action_reinterpret,
+                   NULL);
+     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 >