30 31 class GraphKit; 32 33 class ValueTypeBaseNode : public TypeNode { 34 protected: 35 ValueTypeBaseNode(const Type* t, int nb_fields) 36 : TypeNode(t, nb_fields) { 37 init_class_id(Class_ValueTypeBase); 38 } 39 40 enum { Control, // Control input 41 Oop, // Oop of TypeValueTypePtr 42 Values // Nodes corresponding to values of the value type's fields. 43 // Nodes are connected in increasing order of the index of the field 44 // they correspond to. Field indeces are defined in ciValueKlass::_field_index_map. 45 }; 46 47 virtual const TypeValueTypePtr* value_type_ptr() const = 0; 48 // Get the klass defining the field layout of the value type 49 virtual ciValueKlass* value_klass() const = 0; 50 int make_scalar_in_safepoint(SafePointNode* sfpt, Node* root, PhaseGVN* gvn); 51 52 static void make(PhaseGVN* gvn, Node* n, ValueTypeBaseNode* vt, ciValueKlass* base_vk, int base_offset, int base_input, bool in); 53 54 public: 55 // Support for control flow merges 56 bool has_phi_inputs(Node* region); 57 ValueTypeBaseNode* clone_with_phis(PhaseGVN* gvn, Node* region); 58 ValueTypeBaseNode* merge_with(PhaseGVN* gvn, const ValueTypeBaseNode* other, int pnum, bool transform); 59 60 // Get oop for heap allocated value type (may be TypePtr::NULL_PTR) 61 Node* get_oop() const { return in(Oop); } 62 void set_oop(Node* oop) { set_req(Oop, oop); } 63 64 // Value type fields 65 uint field_count() const { return req() - Values; } 66 Node* field_value(uint index) const; 67 Node* field_value_by_offset(int offset, bool recursive = false) const; 68 void set_field_value(uint index, Node* value); 69 int field_offset(uint index) const; 70 ciType* field_type(uint index) const; 71 72 // Replace ValueTypeNodes in debug info at safepoints with SafePointScalarObjectNodes 73 void make_scalar_in_safepoints(Node* root, PhaseGVN* gvn); 74 75 void store_flattened(PhaseGVN* gvn, Node* ctl, MergeMemNode* mem, Node* base, ciValueKlass* holder, int holder_offset) const; 76 void store(PhaseGVN* gvn, Node* ctl, MergeMemNode* mem, Node* base, ciValueKlass* holder = NULL, int holder_offset = 0) const; 77 78 // Initialize the value type by loading its field values from memory 79 void load(PhaseGVN& gvn, Node* mem, Node* base, Node* ptr, ciInstanceKlass* holder, int holder_offset = 0); 80 81 void replace_call_results(Node* call, Compile* C); 82 83 static Node* allocate(const Type* type, 84 Node*& ctl, Node*& mem, Node*& io, 85 Node* frameptr, 86 Node*& ex_ctl, Node*& ex_mem, Node*& ex_io, 87 JVMState* jvms, PhaseIterGVN *igvn); 88 }; 89 90 //------------------------------ValueTypeNode------------------------------------- 91 // Node representing a value type in C2 IR 92 class ValueTypeNode : public ValueTypeBaseNode { 93 friend class ValueTypeBaseNode; 94 private: 95 ValueTypeNode(const TypeValueType* t, Node* oop) 96 : ValueTypeBaseNode(t, Values + t->value_klass()->nof_declared_nonstatic_fields()) { 97 init_class_id(Class_ValueType); 98 init_req(Oop, oop); 99 } 100 101 ValueTypeNode(const TypeValueType* t, Node* oop, int field_count) 102 : ValueTypeBaseNode(t, Values + field_count) { 103 init_class_id(Class_ValueType); 104 init_req(Oop, oop); 105 } 106 107 // Checks if the value type is loaded from memory and if so returns the oop 108 Node* is_loaded(PhaseGVN* phase, const TypeValueType* t, Node* base = NULL, int holder_offset = 0); 109 110 const TypeValueTypePtr* value_type_ptr() const { return TypeValueTypePtr::make(bottom_type()->isa_valuetype()); } 111 // Get the klass defining the field layout of the value type 112 ciValueKlass* value_klass() const { return type()->is_valuetype()->value_klass(); } 113 114 public: 115 // Create a new ValueTypeNode with uninitialized values 116 static ValueTypeNode* make(PhaseGVN& gvn, ciValueKlass* klass); 117 // Create a new ValueTypeNode with default values 118 static Node* make_default(PhaseGVN& gvn, ciValueKlass* vk); 119 // Create a new ValueTypeNode and load its values from an oop 120 static Node* make(PhaseGVN& gvn, Node* mem, Node* oop); 121 // Create a new ValueTypeNode and load its values from a flattened value type field or array 122 static Node* make(PhaseGVN& gvn, ciValueKlass* vk, Node* mem, Node* obj, Node* ptr, ciInstanceKlass* holder = NULL, int holder_offset = 0); 123 // Create value type node from arguments at method entry and calls 124 static Node* make(PhaseGVN& gvn, Node* n, ciValueKlass* vk, int base_input, bool in); 125 126 // Store the value type as a flattened (headerless) representation 127 void store_flattened(GraphKit* kit, Node* base, Node* ptr, ciInstanceKlass* holder = NULL, int holder_offset = 0) const; 128 // Store the field values to memory 129 void store(GraphKit* kit, Node* base, Node* ptr, ciInstanceKlass* holder, int holder_offset = 0) const; 130 131 // Allocates the value type (if not yet allocated) and returns the oop 132 Node* allocate(GraphKit* kit); 133 bool is_allocated(PhaseGVN* phase) const; 134 135 Node* tagged_klass(PhaseGVN& gvn); 136 void pass_klass(Node* n, uint pos, const GraphKit& kit); 137 uint pass_fields(Node* call, int base_input, const GraphKit& kit, ciValueKlass* base_vk = NULL, int base_offset = 0); 138 139 // Allocation optimizations 140 void remove_redundant_allocations(PhaseIterGVN* igvn, PhaseIdealLoop* phase); 141 142 virtual Node* Ideal(PhaseGVN* phase, bool can_reshape); 143 virtual int Opcode() const; 144 145 #ifndef PRODUCT 146 virtual void dump_spec(outputStream* st) const; 147 #endif 148 }; 149 150 //------------------------------ValueTypePtrNode------------------------------------- 151 // Node representing a value type as a pointer in C2 IR 152 class ValueTypePtrNode : public ValueTypeBaseNode { 153 private: 154 ciValueKlass* value_klass() const { return type()->is_valuetypeptr()->value_type()->value_klass(); } 155 const TypeValueTypePtr* value_type_ptr() const { return bottom_type()->isa_valuetypeptr(); } 156 157 ValueTypePtrNode(ciValueKlass* vk, Compile* C) 158 : ValueTypeBaseNode(TypeValueTypePtr::make(TypePtr::NotNull, vk), Values + vk->nof_declared_nonstatic_fields()) { 159 init_class_id(Class_ValueTypePtr); 160 C->add_value_type_ptr(this); 161 } 162 public: 163 164 ValueTypePtrNode(ValueTypeNode* vt, Node* oop, Compile* C) 165 : ValueTypeBaseNode(TypeValueTypePtr::make(vt->type()->is_valuetype())->cast_to_ptr_type(TypePtr::NotNull), vt->req()) { 166 init_class_id(Class_ValueTypePtr); 167 for (uint i = Oop+1; i < vt->req(); i++) { 168 init_req(i, vt->in(i)); 169 } 170 init_req(Oop, oop); 171 C->add_value_type_ptr(this); 172 } 173 174 static ValueTypePtrNode* make(PhaseGVN* gvn, CheckCastPPNode* cast); 175 static ValueTypePtrNode* make(PhaseGVN& gvn, Node* mem, Node* oop); 176 virtual int Opcode() const; 177 }; 178 179 #endif // SHARE_VM_OPTO_VALUETYPENODE_HPP | 30 31 class GraphKit; 32 33 class ValueTypeBaseNode : public TypeNode { 34 protected: 35 ValueTypeBaseNode(const Type* t, int nb_fields) 36 : TypeNode(t, nb_fields) { 37 init_class_id(Class_ValueTypeBase); 38 } 39 40 enum { Control, // Control input 41 Oop, // Oop of TypeValueTypePtr 42 Values // Nodes corresponding to values of the value type's fields. 43 // Nodes are connected in increasing order of the index of the field 44 // they correspond to. Field indeces are defined in ciValueKlass::_field_index_map. 45 }; 46 47 virtual const TypeValueTypePtr* value_type_ptr() const = 0; 48 // Get the klass defining the field layout of the value type 49 virtual ciValueKlass* value_klass() const = 0; 50 int make_scalar_in_safepoint(Unique_Node_List& worklist, SafePointNode* sfpt, Node* root, PhaseGVN* gvn); 51 52 static void make(PhaseGVN* gvn, Node*& ctl, Node* mem, Node* n, ValueTypeBaseNode* vt, ciValueKlass* base_vk, int base_offset, int base_input, bool in); 53 54 public: 55 // Support for control flow merges 56 bool has_phi_inputs(Node* region); 57 ValueTypeBaseNode* clone_with_phis(PhaseGVN* gvn, Node* region); 58 ValueTypeBaseNode* merge_with(PhaseGVN* gvn, const ValueTypeBaseNode* other, int pnum, bool transform); 59 60 // Get oop for heap allocated value type (may be TypePtr::NULL_PTR) 61 Node* get_oop() const { return in(Oop); } 62 void set_oop(Node* oop) { set_req(Oop, oop); } 63 64 // Value type fields 65 uint field_count() const { return req() - Values; } 66 Node* field_value(uint index) const; 67 Node* field_value_by_offset(int offset, bool recursive = false) const; 68 void set_field_value(uint index, Node* value); 69 int field_offset(uint index) const; 70 ciType* field_type(uint index) const; 71 bool field_is_flattened(uint index) const; 72 73 // Replace ValueTypeNodes in debug info at safepoints with SafePointScalarObjectNodes 74 void make_scalar_in_safepoints(Node* root, PhaseGVN* gvn); 75 76 // Store the value type as a flattened (headerless) representation 77 void store_flattened(GraphKit* kit, Node* base, Node* ptr, ciInstanceKlass* holder = NULL, int holder_offset = 0) const; 78 // Store the field values to memory 79 void store(GraphKit* kit, Node* base, Node* ptr, ciInstanceKlass* holder, int holder_offset = 0) const; 80 81 // Initialize the value type by loading its field values from memory 82 void load(PhaseGVN& gvn, Node*& ctl, Node* mem, Node* base, Node* ptr, ciInstanceKlass* holder, int holder_offset = 0); 83 84 // Allocates the value type (if not yet allocated) and returns the oop 85 ValueTypeBaseNode* allocate(GraphKit* kit); 86 bool is_allocated(PhaseGVN* phase) const; 87 88 void replace_call_results(GraphKit* kit, Node* call, Compile* C); 89 }; 90 91 //------------------------------ValueTypeNode------------------------------------- 92 // Node representing a value type in C2 IR 93 class ValueTypeNode : public ValueTypeBaseNode { 94 friend class ValueTypeBaseNode; 95 private: 96 ValueTypeNode(const TypeValueType* t, Node* oop) 97 : ValueTypeBaseNode(t, Values + t->value_klass()->nof_declared_nonstatic_fields()) { 98 init_class_id(Class_ValueType); 99 init_req(Oop, oop); 100 } 101 102 // Checks if the value type is loaded from memory and if so returns the oop 103 Node* is_loaded(PhaseGVN* phase, const TypeValueType* t, Node* base = NULL, int holder_offset = 0); 104 105 const TypeValueTypePtr* value_type_ptr() const { return TypeValueTypePtr::make(bottom_type()->isa_valuetype()); } 106 // Get the klass defining the field layout of the value type 107 ciValueKlass* value_klass() const { return type()->is_valuetype()->value_klass(); } 108 109 public: 110 // Create a new ValueTypeNode with uninitialized values 111 static ValueTypeNode* make(PhaseGVN& gvn, ciValueKlass* klass); 112 // Create a new ValueTypeNode with default values 113 static Node* make_default(PhaseGVN& gvn, ciValueKlass* vk); 114 // Create a new ValueTypeNode and load its values from an oop 115 static Node* make(GraphKit* kit, Node* oop, bool null_check = false); 116 static Node* make(PhaseGVN& gvn, Node*& ctl, Node* mem, Node* oop, bool null_check = false); 117 // Create a new ValueTypeNode and load its values from a flattened value type field or array 118 static Node* make(GraphKit* kit, ciValueKlass* vk, Node* obj, Node* ptr, ciInstanceKlass* holder = NULL, int holder_offset = 0); 119 static Node* make(PhaseGVN& gvn, ciValueKlass* vk, Node*& ctl, Node* mem, Node* obj, Node* ptr, ciInstanceKlass* holder = NULL, int holder_offset = 0); 120 // Create value type node from arguments at method entry and calls 121 static Node* make(PhaseGVN& gvn, Node*& ctl, Node* mem, Node* n, ciValueKlass* vk, int base_input, bool in); 122 123 // Allocate all non-flattened value type fields 124 Node* allocate_fields(GraphKit* kit); 125 126 Node* tagged_klass(PhaseGVN& gvn); 127 void pass_klass(Node* n, uint pos, const GraphKit& kit); 128 uint pass_fields(Node* call, int base_input, GraphKit& kit, bool assert_allocated = false, ciValueKlass* base_vk = NULL, int base_offset = 0); 129 130 // Allocation optimizations 131 void remove_redundant_allocations(PhaseIterGVN* igvn, PhaseIdealLoop* phase); 132 133 virtual Node* Ideal(PhaseGVN* phase, bool can_reshape); 134 virtual int Opcode() const; 135 136 #ifndef PRODUCT 137 virtual void dump_spec(outputStream* st) const; 138 #endif 139 }; 140 141 //------------------------------ValueTypePtrNode------------------------------------- 142 // Node representing a value type as a pointer in C2 IR 143 class ValueTypePtrNode : public ValueTypeBaseNode { 144 private: 145 ciValueKlass* value_klass() const { return type()->is_valuetypeptr()->value_type()->value_klass(); } 146 const TypeValueTypePtr* value_type_ptr() const { return bottom_type()->isa_valuetypeptr(); } 147 148 ValueTypePtrNode(ciValueKlass* vk, Node* oop, Compile* C) 149 : ValueTypeBaseNode(TypeValueTypePtr::make(TypePtr::NotNull, vk), Values + vk->nof_declared_nonstatic_fields()) { 150 init_class_id(Class_ValueTypePtr); 151 init_req(Oop, oop); 152 C->add_value_type_ptr(this); 153 } 154 public: 155 156 ValueTypePtrNode(ValueTypeNode* vt, Node* oop, Compile* C) 157 : ValueTypeBaseNode(TypeValueTypePtr::make(vt->type()->is_valuetype())->cast_to_ptr_type(TypePtr::NotNull), vt->req()) { 158 init_class_id(Class_ValueTypePtr); 159 for (uint i = Oop+1; i < vt->req(); i++) { 160 init_req(i, vt->in(i)); 161 } 162 init_req(Oop, oop); 163 C->add_value_type_ptr(this); 164 } 165 166 static ValueTypePtrNode* make(GraphKit* kit, ciValueKlass* vk, CallNode* call); 167 static ValueTypePtrNode* make(PhaseGVN& gvn, Node*& ctl, Node* mem, Node* oop); 168 virtual int Opcode() const; 169 }; 170 171 #endif // SHARE_VM_OPTO_VALUETYPENODE_HPP |