< prev index next >

src/share/vm/opto/valuetypenode.cpp

Print this page




  26 #include "ci/ciValueKlass.hpp"
  27 #include "opto/addnode.hpp"
  28 #include "opto/graphKit.hpp"
  29 #include "opto/rootnode.hpp"
  30 #include "opto/valuetypenode.hpp"
  31 #include "opto/phaseX.hpp"
  32 
  33 ValueTypeNode* ValueTypeNode::make(PhaseGVN& gvn, ciValueKlass* klass) {
  34   // Create a new ValueTypeNode with uninitialized values and NULL oop
  35   const TypeValueType* type = TypeValueType::make(klass);
  36   return new ValueTypeNode(type, gvn.zerocon(T_VALUETYPE));
  37 }
  38 
  39 Node* ValueTypeNode::make_default(PhaseGVN& gvn, ciValueKlass* vk) {
  40   // TODO re-use constant oop of pre-allocated default value type here?
  41   // Create a new ValueTypeNode with default values
  42   ValueTypeNode* vt = ValueTypeNode::make(gvn, vk);
  43   for (uint i = 0; i < vt->field_count(); ++i) {
  44     ciType* field_type = vt->field_type(i);
  45     Node* value = NULL;
  46     if (field_type->is_primitive_type()) {
  47       value = gvn.zerocon(field_type->basic_type());
  48     } else {
  49       value = ValueTypeNode::make_default(gvn, field_type->as_value_klass());


  50     }
  51     vt->set_field_value(i, value);
  52   }
  53   return gvn.transform(vt);
  54 }
  55 
  56 Node* ValueTypeNode::make(PhaseGVN& gvn, Node* mem, Node* oop) {
  57   // Create and initialize a ValueTypeNode by loading all field
  58   // values from a heap-allocated version and also save the oop.
  59   const TypeValueType* type = gvn.type(oop)->is_valuetypeptr()->value_type();
  60   ValueTypeNode* vt = new ValueTypeNode(type, oop);
  61   vt->load_values(gvn, mem, oop, oop, type->value_klass());
  62   return gvn.transform(vt);
  63 }
  64 
  65 Node* ValueTypeNode::make(PhaseGVN& gvn, ciValueKlass* vk, Node* mem, Node* obj, Node* ptr, ciInstanceKlass* holder, int holder_offset) {
  66   // Create and initialize a ValueTypeNode by loading all field values from
  67   // a flattened value type field at 'holder_offset' or from a value type array.
  68   ValueTypeNode* vt = make(gvn, vk);
  69   // The value type is flattened into the object without an oop header. Subtract the


  93         ciField* field = holder->get_field_by_offset(offset, false);
  94         ciConstant constant = constant_oop->as_instance()->field_value(field);
  95         con_type = Type::make_from_constant(constant, /*require_const=*/ true);
  96       }
  97       if (con_type != NULL) {
  98         // Found a constant field value
  99         value = gvn.makecon(con_type);
 100       } else {
 101         // Load field value from memory
 102         const Type* base_type = gvn.type(base);
 103         const TypePtr* adr_type = NULL;
 104         if (base_type->isa_aryptr()) {
 105           // In the case of a flattened value type array, each field
 106           // has its own slice
 107           adr_type = base_type->is_aryptr()->with_field_offset(offset)->add_offset(Type::OffsetBot);
 108         } else {
 109           ciField* field = holder->get_field_by_offset(offset, false);
 110           adr_type = gvn.C->alias_type(field)->adr_type();
 111         }
 112         Node* adr = gvn.transform(new AddPNode(base, ptr, gvn.MakeConX(offset)));
 113         value = LoadNode::make(gvn, NULL, mem, adr, adr_type, Type::get_const_type(ftype), ftype->basic_type(), MemNode::unordered);

 114       }
 115     }
 116     set_field_value(i, gvn.transform(value));
 117   }
 118 }
 119 
 120 void ValueTypeNode::store(GraphKit* kit, Node* obj, Node* ptr, ciInstanceKlass* holder, int holder_offset) const {
 121   // The value type is embedded into the object without an oop header. Subtract the
 122   // offset of the first field to account for the missing header when storing the values.
 123   holder_offset -= value_klass()->first_field_offset();
 124   store_values(kit, obj, ptr, holder, holder_offset);
 125 }
 126 
 127 void ValueTypeNode::store_values(GraphKit* kit, Node* base, Node* ptr, ciInstanceKlass* holder, int holder_offset) const {
 128   // Write field values to memory
 129   for (uint i = 0; i < field_count(); ++i) {
 130     int offset = holder_offset + field_offset(i);
 131     Node* value = field_value(i);
 132     if (value->is_ValueType()) {
 133       // Recursively store the flattened value type field
 134       value->isa_ValueType()->store(kit, base, ptr, holder, offset);
 135     } else {
 136       const Type* base_type = kit->gvn().type(base);
 137       const TypePtr* adr_type = NULL;
 138       if (base_type->isa_aryptr()) {
 139         // In the case of a flattened value type array, each field has its own slice
 140         adr_type = base_type->is_aryptr()->with_field_offset(offset)->add_offset(Type::OffsetBot);
 141       } else {
 142         ciField* field = holder->get_field_by_offset(offset, false);
 143         adr_type = kit->C->alias_type(field)->adr_type();
 144       }
 145       Node* adr = kit->basic_plus_adr(base, ptr, offset);
 146       kit->store_to_memory(kit->control(), adr, value, field_type(i)->basic_type(), adr_type, MemNode::unordered);









 147     }
 148   }
 149 }
 150 
 151 Node* ValueTypeNode::store_to_memory(GraphKit* kit) {
 152   Node* in_oop = get_oop();
 153   Node* null_ctl = kit->top();
 154   // Check if value type is already allocated
 155   Node* not_null_oop = kit->null_check_oop(in_oop, &null_ctl);
 156   if (null_ctl->is_top()) {
 157     // Value type is allocated
 158     return not_null_oop;
 159   }
 160   // Not able to prove that value type is allocated.
 161   // Emit runtime check that may be folded later.
 162   const Type* oop_type = kit->gvn().type(in_oop);
 163   assert(TypePtr::NULL_PTR->higher_equal(oop_type), "should not be allocated");
 164 
 165   const TypeValueTypePtr* vtptr_type = TypeValueTypePtr::make(bottom_type()->isa_valuetype(), TypePtr::NotNull);
 166   RegionNode* region = new RegionNode(3);
 167   PhiNode* oop = new PhiNode(region, vtptr_type);
 168   PhiNode* io  = new PhiNode(region, Type::ABIO);
 169   PhiNode* mem = new PhiNode(region, Type::MEMORY, TypePtr::BOTTOM);
 170 
 171   // Oop is non-NULL, use it
 172   region->init_req(1, kit->control());
 173   // Fixme if we cast oop to not null we fail if the control path is not folded
 174   // castnode.cpp:69: #  assert(ft == Type::TOP) failed: special case #3
 175   //oop   ->init_req(1, not_null_oop);
 176   oop   ->init_req(1, in_oop);
 177   io    ->init_req(1, kit->i_o());
 178   mem   ->init_req(1, kit->merged_memory());
 179 
 180   // Oop is NULL, allocate value type
 181   kit->set_control(null_ctl);
 182   kit->kill_dead_locals();
 183   ciValueKlass* vk = value_klass();
 184   Node* klass_node = kit->makecon(TypeKlassPtr::make(vk));
 185   Node* alloc_oop  = kit->new_instance(klass_node);
 186   AllocateNode* alloc = AllocateNode::Ideal_allocation(alloc_oop, &kit->gvn());
 187   // TODO enable/fix this
 188   // alloc->initialization()->set_complete_with_arraycopy();
 189   // Write field values to memory
 190   store_values(kit, alloc_oop, alloc_oop, vk);
 191   region->init_req(2, kit->control());
 192   oop   ->init_req(2, alloc_oop);
 193   io    ->init_req(2, kit->i_o());
 194   mem   ->init_req(2, kit->merged_memory());
 195 
 196   // Update GraphKit
 197   kit->set_control(kit->gvn().transform(region));
 198   kit->set_i_o(kit->gvn().transform(io));
 199   kit->set_all_memory(kit->gvn().transform(mem));
 200   kit->record_for_igvn(region);
 201   kit->record_for_igvn(oop);
 202   kit->record_for_igvn(io);
 203   kit->record_for_igvn(mem);
 204 
 205   // Use cloned ValueTypeNode to propagate oop from now on
 206   Node* res_oop = kit->gvn().transform(oop);
 207   ValueTypeNode* vt = clone()->as_ValueType();
 208   vt->set_oop(res_oop);




  26 #include "ci/ciValueKlass.hpp"
  27 #include "opto/addnode.hpp"
  28 #include "opto/graphKit.hpp"
  29 #include "opto/rootnode.hpp"
  30 #include "opto/valuetypenode.hpp"
  31 #include "opto/phaseX.hpp"
  32 
  33 ValueTypeNode* ValueTypeNode::make(PhaseGVN& gvn, ciValueKlass* klass) {
  34   // Create a new ValueTypeNode with uninitialized values and NULL oop
  35   const TypeValueType* type = TypeValueType::make(klass);
  36   return new ValueTypeNode(type, gvn.zerocon(T_VALUETYPE));
  37 }
  38 
  39 Node* ValueTypeNode::make_default(PhaseGVN& gvn, ciValueKlass* vk) {
  40   // TODO re-use constant oop of pre-allocated default value type here?
  41   // Create a new ValueTypeNode with default values
  42   ValueTypeNode* vt = ValueTypeNode::make(gvn, vk);
  43   for (uint i = 0; i < vt->field_count(); ++i) {
  44     ciType* field_type = vt->field_type(i);
  45     Node* value = NULL;
  46     if (field_type->is_valuetype()) {


  47       value = ValueTypeNode::make_default(gvn, field_type->as_value_klass());
  48     } else {
  49       value = gvn.zerocon(field_type->basic_type());
  50     }
  51     vt->set_field_value(i, value);
  52   }
  53   return gvn.transform(vt);
  54 }
  55 
  56 Node* ValueTypeNode::make(PhaseGVN& gvn, Node* mem, Node* oop) {
  57   // Create and initialize a ValueTypeNode by loading all field
  58   // values from a heap-allocated version and also save the oop.
  59   const TypeValueType* type = gvn.type(oop)->is_valuetypeptr()->value_type();
  60   ValueTypeNode* vt = new ValueTypeNode(type, oop);
  61   vt->load_values(gvn, mem, oop, oop, type->value_klass());
  62   return gvn.transform(vt);
  63 }
  64 
  65 Node* ValueTypeNode::make(PhaseGVN& gvn, ciValueKlass* vk, Node* mem, Node* obj, Node* ptr, ciInstanceKlass* holder, int holder_offset) {
  66   // Create and initialize a ValueTypeNode by loading all field values from
  67   // a flattened value type field at 'holder_offset' or from a value type array.
  68   ValueTypeNode* vt = make(gvn, vk);
  69   // The value type is flattened into the object without an oop header. Subtract the


  93         ciField* field = holder->get_field_by_offset(offset, false);
  94         ciConstant constant = constant_oop->as_instance()->field_value(field);
  95         con_type = Type::make_from_constant(constant, /*require_const=*/ true);
  96       }
  97       if (con_type != NULL) {
  98         // Found a constant field value
  99         value = gvn.makecon(con_type);
 100       } else {
 101         // Load field value from memory
 102         const Type* base_type = gvn.type(base);
 103         const TypePtr* adr_type = NULL;
 104         if (base_type->isa_aryptr()) {
 105           // In the case of a flattened value type array, each field
 106           // has its own slice
 107           adr_type = base_type->is_aryptr()->with_field_offset(offset)->add_offset(Type::OffsetBot);
 108         } else {
 109           ciField* field = holder->get_field_by_offset(offset, false);
 110           adr_type = gvn.C->alias_type(field)->adr_type();
 111         }
 112         Node* adr = gvn.transform(new AddPNode(base, ptr, gvn.MakeConX(offset)));
 113         BasicType bt = type2field[ftype->basic_type()];
 114         value = LoadNode::make(gvn, NULL, mem, adr, adr_type, Type::get_const_type(ftype), bt, MemNode::unordered);
 115       }
 116     }
 117     set_field_value(i, gvn.transform(value));
 118   }
 119 }
 120 
 121 void ValueTypeNode::store(GraphKit* kit, Node* obj, Node* ptr, ciInstanceKlass* holder, int holder_offset) const {
 122   // The value type is embedded into the object without an oop header. Subtract the
 123   // offset of the first field to account for the missing header when storing the values.
 124   holder_offset -= value_klass()->first_field_offset();
 125   store_values(kit, obj, ptr, holder, holder_offset);
 126 }
 127 
 128 void ValueTypeNode::store_values(GraphKit* kit, Node* base, Node* ptr, ciInstanceKlass* holder, int holder_offset) const {
 129   // Write field values to memory
 130   for (uint i = 0; i < field_count(); ++i) {
 131     int offset = holder_offset + field_offset(i);
 132     Node* value = field_value(i);
 133     if (value->is_ValueType()) {
 134       // Recursively store the flattened value type field
 135       value->isa_ValueType()->store(kit, base, ptr, holder, offset);
 136     } else {
 137       const Type* base_type = kit->gvn().type(base);
 138       const TypePtr* adr_type = NULL;
 139       if (base_type->isa_aryptr()) {
 140         // In the case of a flattened value type array, each field has its own slice
 141         adr_type = base_type->is_aryptr()->with_field_offset(offset)->add_offset(Type::OffsetBot);
 142       } else {
 143         ciField* field = holder->get_field_by_offset(offset, false);
 144         adr_type = kit->C->alias_type(field)->adr_type();
 145       }
 146       Node* adr = kit->basic_plus_adr(base, ptr, offset);
 147       BasicType bt = type2field[field_type(i)->basic_type()];
 148       if (is_java_primitive(bt)) {
 149         kit->store_to_memory(kit->control(), adr, value, bt, adr_type, MemNode::unordered);
 150       } else {
 151         const TypeOopPtr* ft = TypeOopPtr::make_from_klass(field_type(i)->as_klass());
 152         assert(adr->bottom_type()->is_ptr_to_narrowoop() == UseCompressedOops, "inconsistent");
 153         // TODO What about "use_precise"?
 154         kit->store_oop(kit->control(), base, adr, adr_type, value, ft, bt, false, MemNode::unordered);
 155       }
 156 
 157     }
 158   }
 159 }
 160 
 161 Node* ValueTypeNode::store_to_memory(GraphKit* kit) {
 162   Node* in_oop = get_oop();
 163   Node* null_ctl = kit->top();
 164   // Check if value type is already allocated
 165   Node* not_null_oop = kit->null_check_oop(in_oop, &null_ctl);
 166   if (null_ctl->is_top()) {
 167     // Value type is allocated
 168     return not_null_oop;
 169   }
 170   // Not able to prove that value type is allocated.
 171   // Emit runtime check that may be folded later.
 172   const Type* oop_type = kit->gvn().type(in_oop);
 173   assert(TypePtr::NULL_PTR->higher_equal(oop_type), "should not be allocated");
 174 
 175   const TypeValueTypePtr* vtptr_type = TypeValueTypePtr::make(bottom_type()->isa_valuetype(), TypePtr::NotNull);
 176   RegionNode* region = new RegionNode(3);
 177   PhiNode* oop = new PhiNode(region, vtptr_type);
 178   PhiNode* io  = new PhiNode(region, Type::ABIO);
 179   PhiNode* mem = new PhiNode(region, Type::MEMORY, TypePtr::BOTTOM);
 180 
 181   // Oop is non-NULL, use it
 182   region->init_req(1, kit->control());
 183   oop   ->init_req(1, not_null_oop);



 184   io    ->init_req(1, kit->i_o());
 185   mem   ->init_req(1, kit->merged_memory());
 186 
 187   // Oop is NULL, allocate value type
 188   kit->set_control(null_ctl);
 189   kit->kill_dead_locals();
 190   ciValueKlass* vk = value_klass();
 191   Node* klass_node = kit->makecon(TypeKlassPtr::make(vk));
 192   Node* alloc_oop  = kit->new_instance(klass_node);



 193   // Write field values to memory
 194   store_values(kit, alloc_oop, alloc_oop, vk);
 195   region->init_req(2, kit->control());
 196   oop   ->init_req(2, alloc_oop);
 197   io    ->init_req(2, kit->i_o());
 198   mem   ->init_req(2, kit->merged_memory());
 199 
 200   // Update GraphKit
 201   kit->set_control(kit->gvn().transform(region));
 202   kit->set_i_o(kit->gvn().transform(io));
 203   kit->set_all_memory(kit->gvn().transform(mem));
 204   kit->record_for_igvn(region);
 205   kit->record_for_igvn(oop);
 206   kit->record_for_igvn(io);
 207   kit->record_for_igvn(mem);
 208 
 209   // Use cloned ValueTypeNode to propagate oop from now on
 210   Node* res_oop = kit->gvn().transform(oop);
 211   ValueTypeNode* vt = clone()->as_ValueType();
 212   vt->set_oop(res_oop);


< prev index next >