851 klass = res_type->klass();
852 // Value types are only allocated on demand
853 if (res_type->isa_instptr() || res_type->isa_valuetypeptr()) {
854 // find the fields of the class which will be needed for safepoint debug information
855 assert(klass->is_instance_klass(), "must be an instance klass.");
856 iklass = klass->as_instance_klass();
857 nfields = iklass->nof_nonstatic_fields();
858 } else {
859 // find the array's elements which will be needed for safepoint debug information
860 nfields = alloc->in(AllocateNode::ALength)->find_int_con(-1);
861 assert(klass->is_array_klass() && nfields >= 0, "must be an array klass.");
862 elem_type = klass->as_array_klass()->element_type();
863 basic_elem_type = elem_type->basic_type();
864 array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
865 element_size = type2aelembytes(basic_elem_type);
866 }
867 }
868 //
869 // Process the safepoint uses
870 //
871 while (safepoints.length() > 0) {
872 SafePointNode* sfpt = safepoints.pop();
873 Node* mem = sfpt->memory();
874 Node* ctl = sfpt->control();
875 assert(sfpt->jvms() != NULL, "missed JVMS");
876 // Fields of scalar objs are referenced only at the end
877 // of regular debuginfo at the last (youngest) JVMS.
878 // Record relative start index.
879 uint first_ind = (sfpt->req() - sfpt->jvms()->scloff());
880 SafePointScalarObjectNode* sobj = new SafePointScalarObjectNode(res_type,
881 #ifdef ASSERT
882 alloc,
883 #endif
884 first_ind, nfields);
885 sobj->init_req(0, C->root());
886 transform_later(sobj);
887
888 // Scan object's fields adding an input to the safepoint for each field.
889 for (int j = 0; j < nfields; j++) {
890 intptr_t offset;
979 tty->print("=== At SafePoint node %d can't find value of array element [%d]",
980 sfpt->_idx, j);
981 }
982 tty->print(", which prevents elimination of: ");
983 if (res == NULL)
984 alloc->dump();
985 else
986 res->dump();
987 }
988 #endif
989 return false;
990 }
991 if (UseCompressedOops && field_type->isa_narrowoop()) {
992 // Enable "DecodeN(EncodeP(Allocate)) --> Allocate" transformation
993 // to be able scalar replace the allocation.
994 if (field_val->is_EncodeP()) {
995 field_val = field_val->in(1);
996 } else {
997 field_val = transform_later(new DecodeNNode(field_val, field_val->get_ptr_type()));
998 }
999 }
1000 sfpt->add_req(field_val);
1001 }
1002 JVMState *jvms = sfpt->jvms();
1003 jvms->set_endoff(sfpt->req());
1004 // Now make a pass over the debug information replacing any references
1005 // to the allocated object with "sobj"
1006 int start = jvms->debug_start();
1007 int end = jvms->debug_end();
1008 sfpt->replace_edges_in_range(res, sobj, start, end);
1009 _igvn._worklist.push(sfpt);
1010 safepoints_done.append_if_missing(sfpt); // keep it for rollback
1011 }
1012 return true;
1013 }
1014
1015 static void disconnect_projections(MultiNode* n, PhaseIterGVN& igvn) {
1016 Node* ctl_proj = n->proj_out(TypeFunc::Control);
1017 Node* mem_proj = n->proj_out(TypeFunc::Memory);
1018 if (ctl_proj != NULL) {
1019 igvn.replace_node(ctl_proj, n->in(0));
1020 }
1021 if (mem_proj != NULL) {
1022 igvn.replace_node(mem_proj, n->in(TypeFunc::Memory));
1023 }
1024 }
1025
1026 // Process users of eliminated allocation.
1027 void PhaseMacroExpand::process_users_of_allocation(CallNode *alloc) {
1028 Node* res = alloc->result_cast();
1029 if (res != NULL) {
1030 for (DUIterator_Last jmin, j = res->last_outs(jmin); j >= jmin; ) {
|
851 klass = res_type->klass();
852 // Value types are only allocated on demand
853 if (res_type->isa_instptr() || res_type->isa_valuetypeptr()) {
854 // find the fields of the class which will be needed for safepoint debug information
855 assert(klass->is_instance_klass(), "must be an instance klass.");
856 iklass = klass->as_instance_klass();
857 nfields = iklass->nof_nonstatic_fields();
858 } else {
859 // find the array's elements which will be needed for safepoint debug information
860 nfields = alloc->in(AllocateNode::ALength)->find_int_con(-1);
861 assert(klass->is_array_klass() && nfields >= 0, "must be an array klass.");
862 elem_type = klass->as_array_klass()->element_type();
863 basic_elem_type = elem_type->basic_type();
864 array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
865 element_size = type2aelembytes(basic_elem_type);
866 }
867 }
868 //
869 // Process the safepoint uses
870 //
871 Unique_Node_List value_worklist;
872 while (safepoints.length() > 0) {
873 SafePointNode* sfpt = safepoints.pop();
874 Node* mem = sfpt->memory();
875 Node* ctl = sfpt->control();
876 assert(sfpt->jvms() != NULL, "missed JVMS");
877 // Fields of scalar objs are referenced only at the end
878 // of regular debuginfo at the last (youngest) JVMS.
879 // Record relative start index.
880 uint first_ind = (sfpt->req() - sfpt->jvms()->scloff());
881 SafePointScalarObjectNode* sobj = new SafePointScalarObjectNode(res_type,
882 #ifdef ASSERT
883 alloc,
884 #endif
885 first_ind, nfields);
886 sobj->init_req(0, C->root());
887 transform_later(sobj);
888
889 // Scan object's fields adding an input to the safepoint for each field.
890 for (int j = 0; j < nfields; j++) {
891 intptr_t offset;
980 tty->print("=== At SafePoint node %d can't find value of array element [%d]",
981 sfpt->_idx, j);
982 }
983 tty->print(", which prevents elimination of: ");
984 if (res == NULL)
985 alloc->dump();
986 else
987 res->dump();
988 }
989 #endif
990 return false;
991 }
992 if (UseCompressedOops && field_type->isa_narrowoop()) {
993 // Enable "DecodeN(EncodeP(Allocate)) --> Allocate" transformation
994 // to be able scalar replace the allocation.
995 if (field_val->is_EncodeP()) {
996 field_val = field_val->in(1);
997 } else {
998 field_val = transform_later(new DecodeNNode(field_val, field_val->get_ptr_type()));
999 }
1000 } else if (field_val->is_ValueType()) {
1001 // Keep track of value types to scalarize them later
1002 value_worklist.push(field_val);
1003 }
1004 sfpt->add_req(field_val);
1005 }
1006 JVMState *jvms = sfpt->jvms();
1007 jvms->set_endoff(sfpt->req());
1008 // Now make a pass over the debug information replacing any references
1009 // to the allocated object with "sobj"
1010 int start = jvms->debug_start();
1011 int end = jvms->debug_end();
1012 sfpt->replace_edges_in_range(res, sobj, start, end);
1013 _igvn._worklist.push(sfpt);
1014 safepoints_done.append_if_missing(sfpt); // keep it for rollback
1015 }
1016 // Scalarize value types that were added to the safepoint
1017 for (uint i = 0; i < value_worklist.size(); ++i) {
1018 Node* vt = value_worklist.at(i);
1019 vt->as_ValueType()->make_scalar_in_safepoints(C->root(), &_igvn);
1020 }
1021 return true;
1022 }
1023
1024 static void disconnect_projections(MultiNode* n, PhaseIterGVN& igvn) {
1025 Node* ctl_proj = n->proj_out(TypeFunc::Control);
1026 Node* mem_proj = n->proj_out(TypeFunc::Memory);
1027 if (ctl_proj != NULL) {
1028 igvn.replace_node(ctl_proj, n->in(0));
1029 }
1030 if (mem_proj != NULL) {
1031 igvn.replace_node(mem_proj, n->in(TypeFunc::Memory));
1032 }
1033 }
1034
1035 // Process users of eliminated allocation.
1036 void PhaseMacroExpand::process_users_of_allocation(CallNode *alloc) {
1037 Node* res = alloc->result_cast();
1038 if (res != NULL) {
1039 for (DUIterator_Last jmin, j = res->last_outs(jmin); j >= jmin; ) {
|