1647 void GraphBuilder::copy_value_content(ciValueKlass* vk, Value src, int src_off, Value dest, int dest_off, 1648 ValueStack* state_before, bool needs_patching) { 1649 for (int i = 0; i < vk->nof_nonstatic_fields(); i++) { 1650 ciField* inner_field = vk->nonstatic_field_at(i); 1651 assert(!inner_field->is_flattened(), "the iteration over nested fields is handled by the loop itself"); 1652 int off = inner_field->offset() - vk->first_field_offset(); 1653 LoadField* load = new LoadField(src, src_off + off, inner_field, false, state_before, needs_patching); 1654 Value replacement = append(load); 1655 StoreField* store = new StoreField(dest, dest_off + off, inner_field, replacement, false, state_before, needs_patching); 1656 append(store); 1657 } 1658 } 1659 1660 void GraphBuilder::access_field(Bytecodes::Code code) { 1661 bool will_link; 1662 ciField* field = stream()->get_field(will_link); 1663 ciInstanceKlass* holder = field->holder(); 1664 BasicType field_type = field->type()->basic_type(); 1665 ValueType* type = as_ValueType(field_type); 1666 1667 // Null check and deopt for getting static value field 1668 ciValueKlass* value_klass = NULL; 1669 Value default_value = NULL; 1670 bool needs_deopt = false; 1671 if (code == Bytecodes::_getstatic && !field->is_static_constant() && 1672 field->layout_type() == T_VALUETYPE && field->is_flattenable()) { 1673 value_klass = field->type()->as_value_klass(); 1674 if (holder->is_loaded()) { 1675 ciInstance* mirror = field->holder()->java_mirror(); 1676 ciObject* val = mirror->field_value(field).as_object(); 1677 if (val->is_null_object()) { 1678 // This is a non-nullable static field, but it's not initialized. 1679 // We need to do a null check, and replace it with the default value. 1680 } else { 1681 // No need to perform null check on this static field 1682 value_klass = NULL; 1683 } 1684 } 1685 if (value_klass != NULL) { 1686 if (value_klass->is_loaded()) { 1687 default_value = new Constant(new InstanceConstant(value_klass->default_value_instance())); 1688 } else { 1689 needs_deopt = true; 1690 } 1691 } 1692 } 1693 1694 // call will_link again to determine if the field is valid. 1695 const bool needs_patching = !holder->is_loaded() || 1696 !field->will_link(method(), code) || 1697 needs_deopt || 1698 PatchALot; 1699 1700 ValueStack* state_before = NULL; 1701 if (!holder->is_initialized() || needs_patching) { 1702 // save state before instruction for debug info when 1703 // deoptimization happens during patching 1704 state_before = copy_state_before(); 1705 } 1706 1707 Value obj = NULL; 1708 if (code == Bytecodes::_getstatic || code == Bytecodes::_putstatic) { 1709 if (state_before != NULL) { 1710 // build a patching constant 1711 obj = new Constant(new InstanceConstant(holder->java_mirror()), state_before); 1712 } else { 1713 obj = new Constant(new InstanceConstant(holder->java_mirror())); 1714 } 1715 } 1716 1717 if (field->is_final() && (code == Bytecodes::_putfield)) { 1726 } 1727 1728 const int offset = !needs_patching ? field->offset() : -1; 1729 switch (code) { 1730 case Bytecodes::_getstatic: { 1731 // check for compile-time constants, i.e., initialized static final fields 1732 Value constant = NULL; 1733 if (field->is_static_constant() && !PatchALot) { 1734 ciConstant field_value = field->constant_value(); 1735 assert(!field->is_stable() || !field_value.is_null_or_zero(), 1736 "stable static w/ default value shouldn't be a constant"); 1737 constant = make_constant(field_value, field); 1738 } 1739 if (constant != NULL) { 1740 push(type, append(constant)); 1741 } else { 1742 if (state_before == NULL) { 1743 state_before = copy_state_for_exception(); 1744 } 1745 LoadField* load_field = new LoadField(append(obj), offset, field, true, 1746 state_before, needs_patching, 1747 value_klass, default_value); 1748 if (field->layout_type() == T_VALUETYPE && field->is_flattenable()) { 1749 load_field->set_never_null(true); 1750 } 1751 push(type, append(load_field)); 1752 } 1753 break; 1754 } 1755 case Bytecodes::_putstatic: { 1756 Value val = pop(type); 1757 if (state_before == NULL) { 1758 state_before = copy_state_for_exception(); 1759 } 1760 if (field->type()->basic_type() == T_BOOLEAN) { 1761 Value mask = append(new Constant(new IntConstant(1))); 1762 val = append(new LogicOp(Bytecodes::_iand, val, mask)); 1763 } 1764 append(new StoreField(append(obj), offset, field, val, true, state_before, needs_patching)); 1765 break; 1766 } 1767 case Bytecodes::_getfield: { 1768 // Check for compile-time constants, i.e., trusted final non-static fields. | 1647 void GraphBuilder::copy_value_content(ciValueKlass* vk, Value src, int src_off, Value dest, int dest_off, 1648 ValueStack* state_before, bool needs_patching) { 1649 for (int i = 0; i < vk->nof_nonstatic_fields(); i++) { 1650 ciField* inner_field = vk->nonstatic_field_at(i); 1651 assert(!inner_field->is_flattened(), "the iteration over nested fields is handled by the loop itself"); 1652 int off = inner_field->offset() - vk->first_field_offset(); 1653 LoadField* load = new LoadField(src, src_off + off, inner_field, false, state_before, needs_patching); 1654 Value replacement = append(load); 1655 StoreField* store = new StoreField(dest, dest_off + off, inner_field, replacement, false, state_before, needs_patching); 1656 append(store); 1657 } 1658 } 1659 1660 void GraphBuilder::access_field(Bytecodes::Code code) { 1661 bool will_link; 1662 ciField* field = stream()->get_field(will_link); 1663 ciInstanceKlass* holder = field->holder(); 1664 BasicType field_type = field->type()->basic_type(); 1665 ValueType* type = as_ValueType(field_type); 1666 1667 // call will_link again to determine if the field is valid. 1668 const bool needs_patching = !holder->is_loaded() || 1669 !field->will_link(method(), code) || 1670 PatchALot; 1671 1672 ValueStack* state_before = NULL; 1673 if (!holder->is_initialized() || needs_patching) { 1674 // save state before instruction for debug info when 1675 // deoptimization happens during patching 1676 state_before = copy_state_before(); 1677 } 1678 1679 Value obj = NULL; 1680 if (code == Bytecodes::_getstatic || code == Bytecodes::_putstatic) { 1681 if (state_before != NULL) { 1682 // build a patching constant 1683 obj = new Constant(new InstanceConstant(holder->java_mirror()), state_before); 1684 } else { 1685 obj = new Constant(new InstanceConstant(holder->java_mirror())); 1686 } 1687 } 1688 1689 if (field->is_final() && (code == Bytecodes::_putfield)) { 1698 } 1699 1700 const int offset = !needs_patching ? field->offset() : -1; 1701 switch (code) { 1702 case Bytecodes::_getstatic: { 1703 // check for compile-time constants, i.e., initialized static final fields 1704 Value constant = NULL; 1705 if (field->is_static_constant() && !PatchALot) { 1706 ciConstant field_value = field->constant_value(); 1707 assert(!field->is_stable() || !field_value.is_null_or_zero(), 1708 "stable static w/ default value shouldn't be a constant"); 1709 constant = make_constant(field_value, field); 1710 } 1711 if (constant != NULL) { 1712 push(type, append(constant)); 1713 } else { 1714 if (state_before == NULL) { 1715 state_before = copy_state_for_exception(); 1716 } 1717 LoadField* load_field = new LoadField(append(obj), offset, field, true, 1718 state_before, needs_patching); 1719 if (field->is_flattenable()) { 1720 load_field->set_never_null(true); 1721 } 1722 push(type, append(load_field)); 1723 } 1724 break; 1725 } 1726 case Bytecodes::_putstatic: { 1727 Value val = pop(type); 1728 if (state_before == NULL) { 1729 state_before = copy_state_for_exception(); 1730 } 1731 if (field->type()->basic_type() == T_BOOLEAN) { 1732 Value mask = append(new Constant(new IntConstant(1))); 1733 val = append(new LogicOp(Bytecodes::_iand, val, mask)); 1734 } 1735 append(new StoreField(append(obj), offset, field, val, true, state_before, needs_patching)); 1736 break; 1737 } 1738 case Bytecodes::_getfield: { 1739 // Check for compile-time constants, i.e., trusted final non-static fields. |