567 #endif
568 first_ind, nfields);
569 sobj->init_req(0, sfpt->in(TypeFunc::Control));
570 transform_later(sobj);
571
572 // Scan object's fields adding an input to the safepoint for each field.
573 for (int j = 0; j < nfields; j++) {
574 int offset;
575 ciField* field = NULL;
576 if (iklass != NULL) {
577 field = iklass->nonstatic_field_at(j);
578 offset = field->offset();
579 elem_type = field->type();
580 basic_elem_type = field->layout_type();
581 } else {
582 offset = array_base + j * element_size;
583 }
584
585 const Type *field_type;
586 // The next code is taken from Parse::do_get_xxx().
587 if (basic_elem_type == T_OBJECT) {
588 if (!elem_type->is_loaded()) {
589 field_type = TypeInstPtr::BOTTOM;
590 } else if (field != NULL && field->is_constant()) {
591 // This can happen if the constant oop is non-perm.
592 ciObject* con = field->constant_value().as_object();
593 // Do not "join" in the previous type; it doesn't add value,
594 // and may yield a vacuous result if the field is of interface type.
595 field_type = TypeOopPtr::make_from_constant(con)->isa_oopptr();
596 assert(field_type != NULL, "field singleton type must be consistent");
597 } else {
598 field_type = TypeOopPtr::make_from_klass(elem_type->as_klass());
599 }
600 } else {
601 field_type = Type::get_const_basic_type(basic_elem_type);
602 }
603
604 const TypeOopPtr *field_addr_type = res_type->add_offset(offset)->isa_oopptr();
605
606 Node *field_val = value_from_mem(mem, basic_elem_type, field_type, field_addr_type, alloc);
607 if (field_val == NULL) {
608 // we weren't able to find a value for this field,
609 // give up on eliminating this allocation
610 alloc->_is_scalar_replaceable = false; // don't try again
611 // remove any extra entries we added to the safepoint
612 uint last = sfpt->req() - 1;
613 for (int k = 0; k < j; k++) {
614 sfpt->del_req(last--);
615 }
616 // rollback processed safepoints
617 while (safepoints_done.length() > 0) {
618 SafePointNode* sfpt_done = safepoints_done.pop();
619 // remove any extra entries we added to the safepoint
642 if (PrintEliminateAllocations) {
643 if (field != NULL) {
644 tty->print("=== At SafePoint node %d can't find value of Field: ",
645 sfpt->_idx);
646 field->print();
647 int field_idx = C->get_alias_index(field_addr_type);
648 tty->print(" (alias_idx=%d)", field_idx);
649 } else { // Array's element
650 tty->print("=== At SafePoint node %d can't find value of array element [%d]",
651 sfpt->_idx, j);
652 }
653 tty->print(", which prevents elimination of: ");
654 if (res == NULL)
655 alloc->dump();
656 else
657 res->dump();
658 }
659 #endif
660 return false;
661 }
662 sfpt->add_req(field_val);
663 }
664 JVMState *jvms = sfpt->jvms();
665 jvms->set_endoff(sfpt->req());
666 // Now make a pass over the debug information replacing any references
667 // to the allocated object with "sobj"
668 int start = jvms->debug_start();
669 int end = jvms->debug_end();
670 for (int i = start; i < end; i++) {
671 if (sfpt->in(i) == res) {
672 sfpt->set_req(i, sobj);
673 }
674 }
675 safepoints_done.append_if_missing(sfpt); // keep it for rollback
676 }
677 return true;
678 }
679
680 // Process users of eliminated allocation.
681 void PhaseMacroExpand::process_users_of_allocation(AllocateNode *alloc) {
|
567 #endif
568 first_ind, nfields);
569 sobj->init_req(0, sfpt->in(TypeFunc::Control));
570 transform_later(sobj);
571
572 // Scan object's fields adding an input to the safepoint for each field.
573 for (int j = 0; j < nfields; j++) {
574 int offset;
575 ciField* field = NULL;
576 if (iklass != NULL) {
577 field = iklass->nonstatic_field_at(j);
578 offset = field->offset();
579 elem_type = field->type();
580 basic_elem_type = field->layout_type();
581 } else {
582 offset = array_base + j * element_size;
583 }
584
585 const Type *field_type;
586 // The next code is taken from Parse::do_get_xxx().
587 if (basic_elem_type == T_OBJECT || basic_elem_type == T_ARRAY) {
588 if (!elem_type->is_loaded()) {
589 field_type = TypeInstPtr::BOTTOM;
590 } else if (field != NULL && field->is_constant()) {
591 // This can happen if the constant oop is non-perm.
592 ciObject* con = field->constant_value().as_object();
593 // Do not "join" in the previous type; it doesn't add value,
594 // and may yield a vacuous result if the field is of interface type.
595 field_type = TypeOopPtr::make_from_constant(con)->isa_oopptr();
596 assert(field_type != NULL, "field singleton type must be consistent");
597 } else {
598 field_type = TypeOopPtr::make_from_klass(elem_type->as_klass());
599 }
600 if (UseCompressedOops) {
601 field_type = field_type->is_oopptr()->make_narrowoop();
602 basic_elem_type = T_NARROWOOP;
603 }
604 } else {
605 field_type = Type::get_const_basic_type(basic_elem_type);
606 }
607
608 const TypeOopPtr *field_addr_type = res_type->add_offset(offset)->isa_oopptr();
609
610 Node *field_val = value_from_mem(mem, basic_elem_type, field_type, field_addr_type, alloc);
611 if (field_val == NULL) {
612 // we weren't able to find a value for this field,
613 // give up on eliminating this allocation
614 alloc->_is_scalar_replaceable = false; // don't try again
615 // remove any extra entries we added to the safepoint
616 uint last = sfpt->req() - 1;
617 for (int k = 0; k < j; k++) {
618 sfpt->del_req(last--);
619 }
620 // rollback processed safepoints
621 while (safepoints_done.length() > 0) {
622 SafePointNode* sfpt_done = safepoints_done.pop();
623 // remove any extra entries we added to the safepoint
646 if (PrintEliminateAllocations) {
647 if (field != NULL) {
648 tty->print("=== At SafePoint node %d can't find value of Field: ",
649 sfpt->_idx);
650 field->print();
651 int field_idx = C->get_alias_index(field_addr_type);
652 tty->print(" (alias_idx=%d)", field_idx);
653 } else { // Array's element
654 tty->print("=== At SafePoint node %d can't find value of array element [%d]",
655 sfpt->_idx, j);
656 }
657 tty->print(", which prevents elimination of: ");
658 if (res == NULL)
659 alloc->dump();
660 else
661 res->dump();
662 }
663 #endif
664 return false;
665 }
666 if (UseCompressedOops && field_type->isa_narrowoop()) {
667 // Enable "DecodeN(EncodeP(Allocate)) --> Allocate" transformation
668 // to be able scalar replace the allocation.
669 _igvn.set_delay_transform(false);
670 field_val = DecodeNNode::decode(&_igvn, field_val);
671 _igvn.set_delay_transform(true);
672 }
673 sfpt->add_req(field_val);
674 }
675 JVMState *jvms = sfpt->jvms();
676 jvms->set_endoff(sfpt->req());
677 // Now make a pass over the debug information replacing any references
678 // to the allocated object with "sobj"
679 int start = jvms->debug_start();
680 int end = jvms->debug_end();
681 for (int i = start; i < end; i++) {
682 if (sfpt->in(i) == res) {
683 sfpt->set_req(i, sobj);
684 }
685 }
686 safepoints_done.append_if_missing(sfpt); // keep it for rollback
687 }
688 return true;
689 }
690
691 // Process users of eliminated allocation.
692 void PhaseMacroExpand::process_users_of_allocation(AllocateNode *alloc) {
|