< prev index next >
src/share/vm/opto/valuetypenode.cpp
Print this page
*** 28,37 ****
--- 28,201 ----
#include "opto/graphKit.hpp"
#include "opto/rootnode.hpp"
#include "opto/valuetypenode.hpp"
#include "opto/phaseX.hpp"
+ // Clones the values type to handle control flow merges involving multiple value types.
+ // The inputs are replaced by PhiNodes to represent the merged values for the given region.
+ ValueTypeBaseNode* ValueTypeBaseNode::clone_with_phis(PhaseGVN* gvn, Node* region) {
+ assert(!has_phi_inputs(region), "already cloned with phis");
+ ValueTypeBaseNode* vt = clone()->as_ValueTypeBase();
+
+ // Create a PhiNode for merging the oop values
+ const TypeValueTypePtr* vtptr = value_type_ptr();
+ PhiNode* oop = PhiNode::make(region, vt->get_oop(), vtptr);
+ gvn->set_type(oop, vtptr);
+ vt->set_oop(oop);
+
+ // Create a PhiNode each for merging the field values
+ for (uint i = 0; i < vt->field_count(); ++i) {
+ ciType* type = vt->field_type(i);
+ Node* value = vt->field_value(i);
+ if (type->is_valuetype()) {
+ // Handle flattened value type fields recursively
+ value = value->as_ValueType()->clone_with_phis(gvn, region);
+ } else {
+ const Type* phi_type = Type::get_const_type(type);
+ value = PhiNode::make(region, value, phi_type);
+ gvn->set_type(value, phi_type);
+ }
+ vt->set_field_value(i, value);
+ }
+ gvn->set_type(vt, vt->bottom_type());
+ return vt;
+ }
+
+ // Checks if the inputs of the ValueBaseTypeNode were replaced by PhiNodes
+ // for the given region (see ValueBaseTypeNode::clone_with_phis).
+ bool ValueTypeBaseNode::has_phi_inputs(Node* region) {
+ // Check oop input
+ bool result = get_oop()->is_Phi() && get_oop()->as_Phi()->region() == region;
+ #ifdef ASSERT
+ if (result) {
+ // Check all field value inputs for consistency
+ for (uint i = Oop; i < field_count(); ++i) {
+ Node* n = in(i);
+ if (n->is_ValueTypeBase()) {
+ assert(n->as_ValueTypeBase()->has_phi_inputs(region), "inconsistent phi inputs");
+ } else {
+ assert(n->is_Phi() && n->as_Phi()->region() == region, "inconsistent phi inputs");
+ }
+ }
+ }
+ #endif
+ return result;
+ }
+
+ // Merges 'this' with 'other' by updating the input PhiNodes added by 'clone_with_phis'
+ ValueTypeBaseNode* ValueTypeBaseNode::merge_with(PhaseGVN* gvn, const ValueTypeBaseNode* other, int pnum, bool transform) {
+ // Merge oop inputs
+ PhiNode* phi = get_oop()->as_Phi();
+ phi->set_req(pnum, other->get_oop());
+ if (transform) {
+ set_oop(gvn->transform(phi));
+ gvn->record_for_igvn(phi);
+ }
+ // Merge field values
+ for (uint i = 0; i < field_count(); ++i) {
+ Node* val1 = field_value(i);
+ Node* val2 = other->field_value(i);
+ if (val1->isa_ValueType()) {
+ val1->as_ValueType()->merge_with(gvn, val2->as_ValueType(), pnum, transform);
+ } else {
+ assert(val1->is_Phi(), "must be a phi node");
+ assert(!val2->is_ValueType(), "inconsistent merge values");
+ val1->set_req(pnum, val2);
+ }
+ if (transform) {
+ set_field_value(i, gvn->transform(val1));
+ gvn->record_for_igvn(val1);
+ }
+ }
+ return this;
+ }
+
+ Node* ValueTypeBaseNode::field_value(uint index) const {
+ assert(index < field_count(), "index out of bounds");
+ return in(Values + index);
+ }
+
+ // Get the value of the field at the given offset.
+ // If 'recursive' is true, flattened value type fields will be resolved recursively.
+ Node* ValueTypeBaseNode::field_value_by_offset(int offset, bool recursive) const {
+ // If the field at 'offset' belongs to a flattened value type field, 'index' refers to the
+ // corresponding ValueTypeNode input and 'sub_offset' is the offset in flattened value type.
+ int index = value_klass()->field_index_by_offset(offset);
+ int sub_offset = offset - field_offset(index);
+ Node* value = field_value(index);
+ if (recursive && value->is_ValueType()) {
+ // Flattened value type field
+ ValueTypeNode* vt = value->as_ValueType();
+ sub_offset += vt->value_klass()->first_field_offset(); // Add header size
+ return vt->field_value_by_offset(sub_offset);
+ }
+ assert(!(recursive && value->is_ValueType()), "should not be a value type");
+ assert(sub_offset == 0, "offset mismatch");
+ return value;
+ }
+
+ void ValueTypeBaseNode::set_field_value(uint index, Node* value) {
+ assert(index < field_count(), "index out of bounds");
+ set_req(Values + index, value);
+ }
+
+ int ValueTypeBaseNode::field_offset(uint index) const {
+ assert(index < field_count(), "index out of bounds");
+ return value_klass()->field_offset_by_index(index);
+ }
+
+ ciType* ValueTypeBaseNode::field_type(uint index) const {
+ assert(index < field_count(), "index out of bounds");
+ return value_klass()->field_type_by_index(index);
+ }
+
+ int ValueTypeBaseNode::make_scalar_in_safepoint(SafePointNode* sfpt, Node* root, PhaseGVN* gvn) {
+ ciValueKlass* vk = value_klass();
+ uint nfields = vk->flattened_field_count();
+ JVMState* jvms = sfpt->jvms();
+ int start = jvms->debug_start();
+ int end = jvms->debug_end();
+ // Replace safepoint edge by SafePointScalarObjectNode and add field values
+ assert(jvms != NULL, "missing JVMS");
+ uint first_ind = (sfpt->req() - jvms->scloff());
+ const TypeValueTypePtr* res_type = value_type_ptr();
+ SafePointScalarObjectNode* sobj = new SafePointScalarObjectNode(res_type,
+ #ifdef ASSERT
+ NULL,
+ #endif
+ first_ind, nfields);
+ sobj->init_req(0, root);
+ // Iterate over the value type fields in order of increasing
+ // offset and add the field values to the safepoint.
+ for (uint j = 0; j < nfields; ++j) {
+ int offset = vk->nonstatic_field_at(j)->offset();
+ Node* value = field_value_by_offset(offset, true /* include flattened value type fields */);
+ assert(value != NULL, "");
+ sfpt->add_req(value);
+ }
+ jvms->set_endoff(sfpt->req());
+ if (gvn != NULL) {
+ sobj = gvn->transform(sobj)->as_SafePointScalarObject();
+ gvn->igvn_rehash_node_delayed(sfpt);
+ }
+ return sfpt->replace_edges_in_range(this, sobj, start, end);
+ }
+
+ void ValueTypeBaseNode::make_scalar_in_safepoints(Node* root, PhaseGVN* gvn) {
+ for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {
+ Node* u = fast_out(i);
+ if (u->is_SafePoint() && (!u->is_Call() || u->as_Call()->has_debug_use(this))) {
+ SafePointNode* sfpt = u->as_SafePoint();
+ Node* in_oop = get_oop();
+ const Type* oop_type = in_oop->bottom_type();
+ assert(Opcode() == Op_ValueTypePtr || TypePtr::NULL_PTR->higher_equal(oop_type), "already heap allocated value type should be linked directly");
+ int nb = make_scalar_in_safepoint(sfpt, root, gvn);
+ --i; imax -= nb;
+ }
+ }
+ }
+
ValueTypeNode* ValueTypeNode::make(PhaseGVN& gvn, ciValueKlass* klass) {
// Create a new ValueTypeNode with uninitialized values and NULL oop
const TypeValueType* type = TypeValueType::make(klass);
return new ValueTypeNode(type, gvn.zerocon(T_VALUETYPE));
}
*** 58,68 ****
// values from a heap-allocated version and also save the oop.
const TypeValueType* type = gvn.type(oop)->is_valuetypeptr()->value_type();
ValueTypeNode* vt = new ValueTypeNode(type, oop);
vt->load(gvn, mem, oop, oop, type->value_klass());
assert(vt->is_allocated(&gvn), "value type should be allocated");
! assert(oop->is_Con() || oop->is_CheckCastPP() || vt->is_loaded(&gvn, type) == oop, "value type should be loaded");
return gvn.transform(vt);
}
Node* ValueTypeNode::make(PhaseGVN& gvn, ciValueKlass* vk, Node* mem, Node* obj, Node* ptr, ciInstanceKlass* holder, int holder_offset) {
// Create and initialize a ValueTypeNode by loading all field values from
--- 222,232 ----
// values from a heap-allocated version and also save the oop.
const TypeValueType* type = gvn.type(oop)->is_valuetypeptr()->value_type();
ValueTypeNode* vt = new ValueTypeNode(type, oop);
vt->load(gvn, mem, oop, oop, type->value_klass());
assert(vt->is_allocated(&gvn), "value type should be allocated");
! assert(oop->is_Con() || oop->is_CheckCastPP() || oop->Opcode() == Op_ValueTypePtr || vt->is_loaded(&gvn, type) == oop, "value type should be loaded");
return gvn.transform(vt);
}
Node* ValueTypeNode::make(PhaseGVN& gvn, ciValueKlass* vk, Node* mem, Node* obj, Node* ptr, ciInstanceKlass* holder, int holder_offset) {
// Create and initialize a ValueTypeNode by loading all field values from
*** 260,424 ****
bool ValueTypeNode::is_allocated(PhaseGVN* phase) const {
const Type* oop_type = phase->type(get_oop());
return oop_type->meet(TypePtr::NULL_PTR) != oop_type;
}
- // Clones the values type to handle control flow merges involving multiple value types.
- // The inputs are replaced by PhiNodes to represent the merged values for the given region.
- ValueTypeNode* ValueTypeNode::clone_with_phis(PhaseGVN* gvn, Node* region) {
- assert(!has_phi_inputs(region), "already cloned with phis");
- ValueTypeNode* vt = clone()->as_ValueType();
-
- // Create a PhiNode for merging the oop values
- const TypeValueTypePtr* vtptr = TypeValueTypePtr::make(vt->bottom_type()->isa_valuetype());
- PhiNode* oop = PhiNode::make(region, vt->get_oop(), vtptr);
- gvn->set_type(oop, vtptr);
- vt->set_oop(oop);
-
- // Create a PhiNode each for merging the field values
- for (uint i = 0; i < vt->field_count(); ++i) {
- ciType* type = vt->field_type(i);
- Node* value = vt->field_value(i);
- if (type->is_valuetype()) {
- // Handle flattened value type fields recursively
- value = value->as_ValueType()->clone_with_phis(gvn, region);
- } else {
- const Type* phi_type = Type::get_const_type(type);
- value = PhiNode::make(region, value, phi_type);
- gvn->set_type(value, phi_type);
- }
- vt->set_field_value(i, value);
- }
- gvn->set_type(vt, vt->bottom_type());
- return vt;
- }
-
- // Checks if the inputs of the ValueTypeNode were replaced by PhiNodes
- // for the given region (see ValueTypeNode::clone_with_phis).
- bool ValueTypeNode::has_phi_inputs(Node* region) {
- // Check oop input
- bool result = get_oop()->is_Phi() && get_oop()->as_Phi()->region() == region;
- #ifdef ASSERT
- if (result) {
- // Check all field value inputs for consistency
- for (uint i = Oop; i < field_count(); ++i) {
- Node* n = in(i);
- if (n->is_ValueType()) {
- assert(n->as_ValueType()->has_phi_inputs(region), "inconsistent phi inputs");
- } else {
- assert(n->is_Phi() && n->as_Phi()->region() == region, "inconsistent phi inputs");
- }
- }
- }
- #endif
- return result;
- }
-
- // Merges 'this' with 'other' by updating the input PhiNodes added by 'clone_with_phis'
- ValueTypeNode* ValueTypeNode::merge_with(PhaseGVN* gvn, const ValueTypeNode* other, int pnum, bool transform) {
- // Merge oop inputs
- PhiNode* phi = get_oop()->as_Phi();
- phi->set_req(pnum, other->get_oop());
- if (transform) {
- set_oop(gvn->transform(phi));
- gvn->record_for_igvn(phi);
- }
- // Merge field values
- for (uint i = 0; i < field_count(); ++i) {
- Node* val1 = field_value(i);
- Node* val2 = other->field_value(i);
- if (val1->isa_ValueType()) {
- val1->as_ValueType()->merge_with(gvn, val2->as_ValueType(), pnum, transform);
- } else {
- assert(val1->is_Phi(), "must be a phi node");
- assert(!val2->is_ValueType(), "inconsistent merge values");
- val1->set_req(pnum, val2);
- }
- if (transform) {
- set_field_value(i, gvn->transform(val1));
- gvn->record_for_igvn(val1);
- }
- }
- return this;
- }
-
- Node* ValueTypeNode::field_value(uint index) const {
- assert(index < field_count(), "index out of bounds");
- return in(Values + index);
- }
-
- // Get the value of the field at the given offset.
- // If 'recursive' is true, flattened value type fields will be resolved recursively.
- Node* ValueTypeNode::field_value_by_offset(int offset, bool recursive) const {
- // If the field at 'offset' belongs to a flattened value type field, 'index' refers to the
- // corresponding ValueTypeNode input and 'sub_offset' is the offset in flattened value type.
- int index = value_klass()->field_index_by_offset(offset);
- int sub_offset = offset - field_offset(index);
- Node* value = field_value(index);
- if (recursive && value->is_ValueType()) {
- // Flattened value type field
- ValueTypeNode* vt = value->as_ValueType();
- sub_offset += vt->value_klass()->first_field_offset(); // Add header size
- return vt->field_value_by_offset(sub_offset);
- }
- assert(!(recursive && value->is_ValueType()), "should not be a value type");
- assert(sub_offset == 0, "offset mismatch");
- return value;
- }
-
- void ValueTypeNode::set_field_value(uint index, Node* value) {
- assert(index < field_count(), "index out of bounds");
- set_req(Values + index, value);
- }
-
- int ValueTypeNode::field_offset(uint index) const {
- assert(index < field_count(), "index out of bounds");
- return value_klass()->field_offset_by_index(index);
- }
-
- ciType* ValueTypeNode::field_type(uint index) const {
- assert(index < field_count(), "index out of bounds");
- return value_klass()->field_type_by_index(index);
- }
-
- void ValueTypeNode::make_scalar_in_safepoints(Compile* C) {
- const TypeValueTypePtr* res_type = TypeValueTypePtr::make(bottom_type()->isa_valuetype(), TypePtr::NotNull);
- ciValueKlass* vk = value_klass();
- uint nfields = vk->flattened_field_count();
- for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {
- Node* u = fast_out(i);
- if (u->is_SafePoint() && (!u->is_Call() || u->as_Call()->has_debug_use(this))) {
- Node* in_oop = get_oop();
- const Type* oop_type = in_oop->bottom_type();
- SafePointNode* sfpt = u->as_SafePoint();
- JVMState* jvms = sfpt->jvms();
- int start = jvms->debug_start();
- int end = jvms->debug_end();
- assert(TypePtr::NULL_PTR->higher_equal(oop_type), "already heap allocated value type should be linked directly");
- // Replace safepoint edge by SafePointScalarObjectNode and add field values
- assert(jvms != NULL, "missing JVMS");
- uint first_ind = (sfpt->req() - jvms->scloff());
- SafePointScalarObjectNode* sobj = new SafePointScalarObjectNode(res_type,
- #ifdef ASSERT
- NULL,
- #endif
- first_ind, nfields);
- sobj->init_req(0, C->root());
- // Iterate over the value type fields in order of increasing
- // offset and add the field values to the safepoint.
- for (uint j = 0; j < nfields; ++j) {
- int offset = vk->nonstatic_field_at(j)->offset();
- Node* value = field_value_by_offset(offset, true /* include flattened value type fields */);
- sfpt->add_req(value);
- }
- jvms->set_endoff(sfpt->req());
- int nb = sfpt->replace_edges_in_range(this, sobj, start, end);
- --i; imax -= nb;
- }
- }
- }
-
void ValueTypeNode::pass_klass(Node* n, uint pos, const GraphKit& kit) {
ciValueKlass* vk = value_klass();
const TypeKlassPtr* tk = TypeKlassPtr::make(vk);
intptr_t bits = tk->get_con();
set_nth_bit(bits, 0);
--- 424,433 ----
< prev index next >