< prev index next >

src/share/vm/opto/valuetypenode.cpp

Print this page

        

@@ -33,43 +33,79 @@
   // Create a new ValueTypeNode with uninitialized values and NULL oop
   const TypeValueType* type = TypeValueType::make(klass);
   return new ValueTypeNode(type, gvn.zerocon(T_VALUETYPE));
 }
 
+Node* ValueTypeNode::make_default(PhaseGVN& gvn, ciValueKlass* vk) {
+  // TODO re-use constant oop of pre-allocated default value type here?
+  // Create a new ValueTypeNode with default values
+  ValueTypeNode* vt = ValueTypeNode::make(gvn, vk);
+  for (uint i = 0; i < vt->field_count(); ++i) {
+    ciType* field_type = vt->field_type(i);
+    Node* value = NULL;
+    if (field_type->is_primitive_type()) {
+      value = gvn.zerocon(field_type->basic_type());
+    } else {
+      value = ValueTypeNode::make_default(gvn, field_type->as_value_klass());
+    }
+    vt->set_field_value(i, value);
+  }
+  return gvn.transform(vt);
+}
+
 Node* ValueTypeNode::make(PhaseGVN& gvn, Node* mem, Node* oop) {
   // Create and initialize a ValueTypeNode by loading all field
   // values from a heap-allocated version and also save the oop.
   const TypeValueTypePtr* vtptr = gvn.type(oop)->is_valuetypeptr();
   ValueTypeNode* vt = new ValueTypeNode(vtptr->value_type(), oop);
-  vt->load_values(gvn, mem, vt->value_klass(), oop);
+  vt->load_values(gvn, mem, oop, oop);
   return gvn.transform(vt);
 }
 
-Node* ValueTypeNode::make(PhaseGVN& gvn, ciValueKlass* klass, Node* mem, ciInstanceKlass* holder, Node* obj, int field_offset) {
-  // Create and initialize a ValueTypeNode by loading all field
-  // values from a flattened value type field at 'field_offset' in 'obj'.
-  ValueTypeNode* vt = make(gvn, klass)->as_ValueType();
+Node* ValueTypeNode::make(PhaseGVN& gvn, ciValueKlass* vk, Node* mem, Node* obj, Node* ptr, ciKlass* holder, int field_offset) {
+  // Create and initialize a ValueTypeNode by loading all field values from
+  // a flattened value type field at 'field_offset' or from a value type array.
+  ValueTypeNode* vt = make(gvn, vk);
+  int base_offset = 0;
+  if (holder->is_value_array_klass()) {
+    assert(field_offset == 0, "field offset not supported for arrays");
+  } else {
   // The value type is flattened into the object without an oop header. Subtract the
   // offset of the first field to account for the missing header when loading the values.
-  int base_offset = field_offset - klass->first_field_offset();
-  vt->load_values(gvn, mem, holder, obj, base_offset);
+    base_offset = field_offset - vk->first_field_offset();
+  }
+  vt->load_values(gvn, mem, obj, ptr, holder, base_offset);
   return gvn.transform(vt);
 }
 
-void ValueTypeNode::load_values(PhaseGVN& gvn, Node* mem, ciInstanceKlass* holder, Node* base, int base_offset) {
+void ValueTypeNode::load_values(PhaseGVN& gvn, Node* mem, Node* base, Node* ptr, ciKlass* holder, int f_offset) {
+  ciInstanceKlass* lookup;
+  if (holder) {
+    // Flattened
+    if (holder->is_value_array_klass()) {
+      lookup = value_klass();
+    } else {
+      lookup = holder->as_instance_klass();
+    }
+  } else {
+    // Not flattened
+    assert(f_offset == 0, "must be");
+    lookup = value_klass();
+  }
   // Initialize the value type by loading its field values from
   // memory and adding the values as input edges to the node.
   for (uint i = 0; i < field_count(); ++i) {
-    int offset = base_offset + field_offset(i);
-    Node* adr = gvn.transform(new AddPNode(base, base, gvn.longcon(offset)));
-    ciField* field = holder->get_field_by_offset(offset, false);
-    const TypePtr* adr_type = gvn.C->alias_type(field)->adr_type();
-    Node* value = NULL;
+    int offset = f_offset + field_offset(i);
+    ciField* field = lookup->get_field_by_offset(offset, false);
     ciType* f_type = field_type(i);
+    Node* value = NULL;
     if (f_type->is_valuetype()) {
+      if (holder && holder->is_value_array_klass()) {
+        offset -= value_klass()->first_field_offset();
+      }
       // Recursively load the flattened value type field
-      value = ValueTypeNode::make(gvn, f_type->as_value_klass(), mem, holder, base, offset);
+      value = ValueTypeNode::make(gvn, f_type->as_value_klass(), mem, base, ptr, lookup, offset);
     } else {
       const Type* con_type = NULL;
       if (base->is_Con()) {
         // If the oop to the value type is constant (static final field), we can
         // also treat the fields as constants because the value type is immutable.

@@ -81,36 +117,73 @@
       if (con_type != NULL) {
         // Found a constant field value
         value = gvn.makecon(con_type);
       } else {
         // Load field value from memory
+        const Type* base_type = gvn.type(base);
+        const TypePtr* adr_type = NULL;
+        if (base_type->isa_aryptr()) {
+          adr_type = base_type->is_aryptr()->add_offset(Type::OffsetBot);
+        } else {
+          adr_type = gvn.C->alias_type(field)->adr_type();
+        }
+        if (holder && holder->is_value_array_klass()) {
+          offset -= value_klass()->first_field_offset();
+        }
+        Node* adr = gvn.transform(new AddPNode(base, ptr, gvn.MakeConX(offset)));
         value = LoadNode::make(gvn, NULL, mem, adr, adr_type, Type::get_const_type(f_type), f_type->basic_type(), MemNode::unordered);
       }
     }
     set_field_value(i, gvn.transform(value));
   }
 }
 
-void ValueTypeNode::store_to_field(GraphKit* kit, ciInstanceKlass* holder, Node* obj, int field_offset) const {
+void ValueTypeNode::store_to_field(GraphKit* kit, Node* obj, Node* ptr, ciInstanceKlass* instance_type, int field_offset) const {
   // The value type is embedded into the object without an oop header. Subtract the
   // offset of the first field to account for the missing header when storing the values.
   int base_offset = field_offset - value_klass()->first_field_offset();
-  store_values(kit, holder, obj, base_offset);
+  store_values(kit, obj, ptr, instance_type, base_offset);
 }
 
-void ValueTypeNode::store_values(GraphKit* kit, ciInstanceKlass* holder, Node* base, int base_offset) const {
+void ValueTypeNode::store_values(GraphKit* kit, Node* base, Node* ptr, ciKlass* holder, int holder_offset) const {
+  ciInstanceKlass* lookup;
+  if (holder) {
+    // flattened
+    if (holder->is_value_array_klass()) {
+      assert(holder_offset == 0, "must be");
+      lookup = value_klass();
+    } else {
+      lookup = holder->as_instance_klass();
+    }
+  } else {
+    // not flattened
+    assert(holder_offset == 0, "must be");
+    lookup = value_klass();
+  }
   // Write field values to memory
   for (uint i = 0; i < field_count(); ++i) {
-    int offset = base_offset + field_offset(i);
-    Node* adr = kit->basic_plus_adr(base, base, offset);
-    ciField* field = holder->get_field_by_offset(offset, false);
-    const TypePtr* adr_type = kit->C->alias_type(field)->adr_type();
+    int offset = holder_offset + field_offset(i);
     Node* value = field_value(i);
     if (value->is_ValueType()) {
       // Recursively store the flattened value type field
-      value->isa_ValueType()->store_to_field(kit, holder, base, offset);
+      if (holder && holder->is_value_array_klass()) {
+        offset -= value_klass()->first_field_offset();
+      }
+      value->isa_ValueType()->store_to_field(kit, base, ptr, lookup, offset);
     } else {
+      const Type* base_type = kit->gvn().type(base);
+      const TypePtr* adr_type = NULL;
+      if (base_type->isa_aryptr()) {
+        adr_type = base_type->is_aryptr()->add_offset(Type::OffsetBot);
+      } else {
+        ciField* field = lookup->get_field_by_offset(offset, false);
+        adr_type = kit->gvn().C->alias_type(field)->adr_type();
+      }
+      if (holder && holder->is_value_array_klass()) {
+        offset -= value_klass()->first_field_offset();
+      }
+      Node* adr = kit->basic_plus_adr(base, ptr, offset);
       kit->store_to_memory(kit->control(), adr, value, field_type(i)->basic_type(), adr_type, MemNode::unordered);
     }
   }
 }
 

@@ -146,12 +219,15 @@
   // Oop is NULL, allocate value type
   kit->set_control(null_ctl);
   kit->kill_dead_locals();
   Node* klass_node = kit->makecon(TypeKlassPtr::make(value_klass()));
   Node* alloc_oop  = kit->new_instance(klass_node);
+  AllocateNode* alloc = AllocateNode::Ideal_allocation(alloc_oop, &kit->gvn());
+  // TODO enable/fix this
+  // alloc->initialization()->set_complete_with_arraycopy();
   // Write field values to memory
-  store_values(kit, value_klass(), alloc_oop);
+  store_values(kit, alloc_oop, alloc_oop);
   region->init_req(2, kit->control());
   oop   ->init_req(2, alloc_oop);
   io    ->init_req(2, kit->i_o());
   mem   ->init_req(2, kit->merged_memory());
 
< prev index next >