16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "c1/c1_CFGPrinter.hpp"
27 #include "c1/c1_Canonicalizer.hpp"
28 #include "c1/c1_Compilation.hpp"
29 #include "c1/c1_GraphBuilder.hpp"
30 #include "c1/c1_InstructionPrinter.hpp"
31 #include "ci/ciCallSite.hpp"
32 #include "ci/ciField.hpp"
33 #include "ci/ciKlass.hpp"
34 #include "ci/ciMemberName.hpp"
35 #include "ci/ciUtilities.inline.hpp"
36 #include "compiler/compileBroker.hpp"
37 #include "interpreter/bytecode.hpp"
38 #include "jfr/jfrEvents.hpp"
39 #include "memory/resourceArea.hpp"
40 #include "oops/oop.inline.hpp"
41 #include "runtime/sharedRuntime.hpp"
42 #include "runtime/compilationPolicy.hpp"
43 #include "runtime/vm_version.hpp"
44 #include "utilities/bitMap.inline.hpp"
45
46 class BlockListBuilder {
47 private:
48 Compilation* _compilation;
49 IRScope* _scope;
50
51 BlockList _blocks; // internal list of all blocks
52 BlockList* _bci2block; // mapping from bci to blocks for GraphBuilder
53
54 // fields used by mark_loops
55 ResourceBitMap _active; // for iteration of control flow graph
631 }
632 #endif
633 assert(result->type()->tag() == load->type()->tag(), "wrong types");
634 return result;
635 }
636 }
637 return load;
638 }
639
640 // Record this newly allocated object
641 void new_instance(NewInstance* object) {
642 int index = _newobjects.length();
643 _newobjects.append(object);
644 if (_fields.at_grow(index, NULL) == NULL) {
645 _fields.at_put(index, new FieldBuffer());
646 } else {
647 _fields.at(index)->kill();
648 }
649 }
650
651 void store_value(Value value) {
652 int index = _newobjects.find(value);
653 if (index != -1) {
654 // stored a newly allocated object into another object.
655 // Assume we've lost track of it as separate slice of memory.
656 // We could do better by keeping track of whether individual
657 // fields could alias each other.
658 _newobjects.remove_at(index);
659 // pull out the field info and store it at the end up the list
660 // of field info list to be reused later.
661 _fields.append(_fields.at(index));
662 _fields.remove_at(index);
663 }
664 }
665
666 void kill() {
667 _newobjects.trunc_to(0);
668 _objects.trunc_to(0);
669 _values.kill();
670 }
962 scope_data()->set_jsr_return_address_local(-1);
963 }
964 }
965
966 state->store_local(index, round_fp(x));
967 }
968
969
970 void GraphBuilder::load_indexed(BasicType type) {
971 // In case of in block code motion in range check elimination
972 ValueStack* state_before = copy_state_indexed_access();
973 compilation()->set_has_access_indexed(true);
974 Value index = ipop();
975 Value array = apop();
976 Value length = NULL;
977 if (CSEArrayLength ||
978 (array->as_AccessField() && array->as_AccessField()->field()->is_constant()) ||
979 (array->as_NewArray() && array->as_NewArray()->length() && array->as_NewArray()->length()->type()->is_constant())) {
980 length = append(new ArrayLength(array, state_before));
981 }
982 push(as_ValueType(type), append(new LoadIndexed(array, index, length, type, state_before)));
983 }
984
985
986 void GraphBuilder::store_indexed(BasicType type) {
987 // In case of in block code motion in range check elimination
988 ValueStack* state_before = copy_state_indexed_access();
989 compilation()->set_has_access_indexed(true);
990 Value value = pop(as_ValueType(type));
991 Value index = ipop();
992 Value array = apop();
993 Value length = NULL;
994 if (CSEArrayLength ||
995 (array->as_AccessField() && array->as_AccessField()->field()->is_constant()) ||
996 (array->as_NewArray() && array->as_NewArray()->length() && array->as_NewArray()->length()->type()->is_constant())) {
997 length = append(new ArrayLength(array, state_before));
998 }
999 ciType* array_type = array->declared_type();
1000 bool check_boolean = false;
1001 if (array_type != NULL) {
1002 if (array_type->is_loaded() &&
1683 }
1684 break;
1685 }
1686 case Bytecodes::_putstatic: {
1687 Value val = pop(type);
1688 if (state_before == NULL) {
1689 state_before = copy_state_for_exception();
1690 }
1691 if (field->type()->basic_type() == T_BOOLEAN) {
1692 Value mask = append(new Constant(new IntConstant(1)));
1693 val = append(new LogicOp(Bytecodes::_iand, val, mask));
1694 }
1695 append(new StoreField(append(obj), offset, field, val, true, state_before, needs_patching));
1696 break;
1697 }
1698 case Bytecodes::_getfield: {
1699 // Check for compile-time constants, i.e., trusted final non-static fields.
1700 Value constant = NULL;
1701 obj = apop();
1702 ObjectType* obj_type = obj->type()->as_ObjectType();
1703 if (field->is_constant() && obj_type->is_constant() && !PatchALot) {
1704 ciObject* const_oop = obj_type->constant_value();
1705 if (!const_oop->is_null_object() && const_oop->is_loaded()) {
1706 ciConstant field_value = field->constant_value_of(const_oop);
1707 if (field_value.is_valid()) {
1708 constant = make_constant(field_value, field);
1709 // For CallSite objects add a dependency for invalidation of the optimization.
1710 if (field->is_call_site_target()) {
1711 ciCallSite* call_site = const_oop->as_call_site();
1712 if (!call_site->is_constant_call_site()) {
1713 ciMethodHandle* target = field_value.as_object()->as_method_handle();
1714 dependency_recorder()->assert_call_site_target_value(call_site, target);
1715 }
1716 }
1717 }
1718 }
1719 }
1720 if (constant != NULL) {
1721 push(type, append(constant));
1722 } else {
1723 if (state_before == NULL) {
1724 state_before = copy_state_for_exception();
1725 }
1726 LoadField* load = new LoadField(obj, offset, field, false, state_before, needs_patching);
1727 Value replacement = !needs_patching ? _memory->load(load) : load;
1728 if (replacement != load) {
1729 assert(replacement->is_linked() || !replacement->can_be_linked(), "should already by linked");
1730 push(type, replacement);
1731 } else {
1732 push(type, append(load));
1733 }
1734 }
1735 break;
1736 }
1737 case Bytecodes::_putfield: {
1738 Value val = pop(type);
1739 obj = apop();
1740 if (state_before == NULL) {
1741 state_before = copy_state_for_exception();
1742 }
1743 if (field->type()->basic_type() == T_BOOLEAN) {
1744 Value mask = append(new Constant(new IntConstant(1)));
1745 val = append(new LogicOp(Bytecodes::_iand, val, mask));
1746 }
1747 StoreField* store = new StoreField(obj, offset, field, val, false, state_before, needs_patching);
1748 if (!needs_patching) store = _memory->store(store);
1749 if (store != NULL) {
1750 append(store);
1751 }
1752 break;
1753 }
1754 default:
1755 ShouldNotReachHere();
1756 break;
1757 }
1758 }
1759
1760
1761 Dependencies* GraphBuilder::dependency_recorder() const {
1762 assert(DeoptC1, "need debug information");
1763 return compilation()->dependency_recorder();
1764 }
1765
1766 // How many arguments do we want to profile?
1767 Values* GraphBuilder::args_list_for_profiling(ciMethod* target, int& start, bool may_have_receiver) {
1768 int n = 0;
1769 bool has_receiver = may_have_receiver && Bytecodes::has_receiver(method()->java_code_at_bci(bci()));
1770 start = has_receiver ? 1 : 0;
1771 if (profile_arguments()) {
1772 ciProfileData* data = method()->method_data()->bci_to_data(bci());
1773 if (data != NULL && (data->is_CallTypeData() || data->is_VirtualCallTypeData())) {
1774 n = data->is_CallTypeData() ? data->as_CallTypeData()->number_of_arguments() : data->as_VirtualCallTypeData()->number_of_arguments();
1775 }
1776 }
1777 // If we are inlining then we need to collect arguments to profile parameters for the target
1778 if (profile_parameters() && target != NULL) {
1779 if (target->method_data() != NULL && target->method_data()->parameters_type_data() != NULL) {
2127 append_split(result);
2128
2129 if (result_type != voidType) {
2130 if (method()->is_strict()) {
2131 push(result_type, round_fp(result));
2132 } else {
2133 push(result_type, result);
2134 }
2135 }
2136 if (profile_return() && result_type->is_object_kind()) {
2137 profile_return_type(result, target);
2138 }
2139 }
2140
2141
2142 void GraphBuilder::new_instance(int klass_index) {
2143 ValueStack* state_before = copy_state_exhandling();
2144 bool will_link;
2145 ciKlass* klass = stream()->get_klass(will_link);
2146 assert(klass->is_instance_klass(), "must be an instance klass");
2147 NewInstance* new_instance = new NewInstance(klass->as_instance_klass(), state_before, stream()->is_unresolved_klass());
2148 _memory->new_instance(new_instance);
2149 apush(append_split(new_instance));
2150 }
2151
2152
2153 void GraphBuilder::new_type_array() {
2154 ValueStack* state_before = copy_state_exhandling();
2155 apush(append_split(new NewTypeArray(ipop(), (BasicType)stream()->get_index(), state_before)));
2156 }
2157
2158
2159 void GraphBuilder::new_object_array() {
2160 bool will_link;
2161 ciKlass* klass = stream()->get_klass(will_link);
2162 ValueStack* state_before = !klass->is_loaded() || PatchALot ? copy_state_before() : copy_state_exhandling();
2163 NewArray* n = new NewObjectArray(klass, ipop(), state_before);
2164 apush(append_split(n));
2165 }
2166
2167
2168 bool GraphBuilder::direct_compare(ciKlass* k) {
2169 if (k->is_loaded() && k->is_instance_klass() && !UseSlowPath) {
2170 ciInstanceKlass* ik = k->as_instance_klass();
2171 if (ik->is_final()) {
2866 case Bytecodes::_invokevirtual : // fall through
2867 case Bytecodes::_invokespecial : // fall through
2868 case Bytecodes::_invokestatic : // fall through
2869 case Bytecodes::_invokedynamic : // fall through
2870 case Bytecodes::_invokeinterface: invoke(code); break;
2871 case Bytecodes::_new : new_instance(s.get_index_u2()); break;
2872 case Bytecodes::_newarray : new_type_array(); break;
2873 case Bytecodes::_anewarray : new_object_array(); break;
2874 case Bytecodes::_arraylength : { ValueStack* state_before = copy_state_for_exception(); ipush(append(new ArrayLength(apop(), state_before))); break; }
2875 case Bytecodes::_athrow : throw_op(s.cur_bci()); break;
2876 case Bytecodes::_checkcast : check_cast(s.get_index_u2()); break;
2877 case Bytecodes::_instanceof : instance_of(s.get_index_u2()); break;
2878 case Bytecodes::_monitorenter : monitorenter(apop(), s.cur_bci()); break;
2879 case Bytecodes::_monitorexit : monitorexit (apop(), s.cur_bci()); break;
2880 case Bytecodes::_wide : ShouldNotReachHere(); break;
2881 case Bytecodes::_multianewarray : new_multi_array(s.cur_bcp()[3]); break;
2882 case Bytecodes::_ifnull : if_null(objectType, If::eql); break;
2883 case Bytecodes::_ifnonnull : if_null(objectType, If::neq); break;
2884 case Bytecodes::_goto_w : _goto(s.cur_bci(), s.get_far_dest()); break;
2885 case Bytecodes::_jsr_w : jsr(s.get_far_dest()); break;
2886 case Bytecodes::_breakpoint : BAILOUT_("concurrent setting of breakpoint", NULL);
2887 default : ShouldNotReachHere(); break;
2888 }
2889
2890 if (log != NULL)
2891 log->clear_context(); // skip marker if nothing was printed
2892
2893 // save current bci to setup Goto at the end
2894 prev_bci = s.cur_bci();
2895
2896 }
2897 CHECK_BAILOUT_(NULL);
2898 // stop processing of this block (see try_inline_full)
2899 if (_skip_block) {
2900 _skip_block = false;
2901 assert(_last && _last->as_BlockEnd(), "");
2902 return _last->as_BlockEnd();
2903 }
2904 // if there are any, check if last instruction is a BlockEnd instruction
2905 BlockEnd* end = last()->as_BlockEnd();
3161 }
3162
3163
3164 ValueStack* GraphBuilder::state_at_entry() {
3165 ValueStack* state = new ValueStack(scope(), NULL);
3166
3167 // Set up locals for receiver
3168 int idx = 0;
3169 if (!method()->is_static()) {
3170 // we should always see the receiver
3171 state->store_local(idx, new Local(method()->holder(), objectType, idx, true));
3172 idx = 1;
3173 }
3174
3175 // Set up locals for incoming arguments
3176 ciSignature* sig = method()->signature();
3177 for (int i = 0; i < sig->count(); i++) {
3178 ciType* type = sig->type_at(i);
3179 BasicType basic_type = type->basic_type();
3180 // don't allow T_ARRAY to propagate into locals types
3181 if (basic_type == T_ARRAY) basic_type = T_OBJECT;
3182 ValueType* vt = as_ValueType(basic_type);
3183 state->store_local(idx, new Local(type, vt, idx, false));
3184 idx += type->size();
3185 }
3186
3187 // lock synchronized method
3188 if (method()->is_synchronized()) {
3189 state->lock(NULL);
3190 }
3191
3192 return state;
3193 }
3194
3195
3196 GraphBuilder::GraphBuilder(Compilation* compilation, IRScope* scope)
3197 : _scope_data(NULL)
3198 , _compilation(compilation)
3199 , _memory(new MemoryBuffer())
3200 , _inline_bailout_msg(NULL)
3201 , _instruction_count(0)
|
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "c1/c1_CFGPrinter.hpp"
27 #include "c1/c1_Canonicalizer.hpp"
28 #include "c1/c1_Compilation.hpp"
29 #include "c1/c1_GraphBuilder.hpp"
30 #include "c1/c1_InstructionPrinter.hpp"
31 #include "ci/ciCallSite.hpp"
32 #include "ci/ciField.hpp"
33 #include "ci/ciKlass.hpp"
34 #include "ci/ciMemberName.hpp"
35 #include "ci/ciUtilities.inline.hpp"
36 #include "ci/ciValueKlass.hpp"
37 #include "compiler/compileBroker.hpp"
38 #include "interpreter/bytecode.hpp"
39 #include "jfr/jfrEvents.hpp"
40 #include "memory/resourceArea.hpp"
41 #include "oops/oop.inline.hpp"
42 #include "runtime/sharedRuntime.hpp"
43 #include "runtime/compilationPolicy.hpp"
44 #include "runtime/vm_version.hpp"
45 #include "utilities/bitMap.inline.hpp"
46
47 class BlockListBuilder {
48 private:
49 Compilation* _compilation;
50 IRScope* _scope;
51
52 BlockList _blocks; // internal list of all blocks
53 BlockList* _bci2block; // mapping from bci to blocks for GraphBuilder
54
55 // fields used by mark_loops
56 ResourceBitMap _active; // for iteration of control flow graph
632 }
633 #endif
634 assert(result->type()->tag() == load->type()->tag(), "wrong types");
635 return result;
636 }
637 }
638 return load;
639 }
640
641 // Record this newly allocated object
642 void new_instance(NewInstance* object) {
643 int index = _newobjects.length();
644 _newobjects.append(object);
645 if (_fields.at_grow(index, NULL) == NULL) {
646 _fields.at_put(index, new FieldBuffer());
647 } else {
648 _fields.at(index)->kill();
649 }
650 }
651
652 // Record this newly allocated object
653 void new_instance(NewValueTypeInstance* object) {
654 int index = _newobjects.length();
655 _newobjects.append(object);
656 if (_fields.at_grow(index, NULL) == NULL) {
657 _fields.at_put(index, new FieldBuffer());
658 } else {
659 _fields.at(index)->kill();
660 }
661 }
662
663 void store_value(Value value) {
664 int index = _newobjects.find(value);
665 if (index != -1) {
666 // stored a newly allocated object into another object.
667 // Assume we've lost track of it as separate slice of memory.
668 // We could do better by keeping track of whether individual
669 // fields could alias each other.
670 _newobjects.remove_at(index);
671 // pull out the field info and store it at the end up the list
672 // of field info list to be reused later.
673 _fields.append(_fields.at(index));
674 _fields.remove_at(index);
675 }
676 }
677
678 void kill() {
679 _newobjects.trunc_to(0);
680 _objects.trunc_to(0);
681 _values.kill();
682 }
974 scope_data()->set_jsr_return_address_local(-1);
975 }
976 }
977
978 state->store_local(index, round_fp(x));
979 }
980
981
982 void GraphBuilder::load_indexed(BasicType type) {
983 // In case of in block code motion in range check elimination
984 ValueStack* state_before = copy_state_indexed_access();
985 compilation()->set_has_access_indexed(true);
986 Value index = ipop();
987 Value array = apop();
988 Value length = NULL;
989 if (CSEArrayLength ||
990 (array->as_AccessField() && array->as_AccessField()->field()->is_constant()) ||
991 (array->as_NewArray() && array->as_NewArray()->length() && array->as_NewArray()->length()->type()->is_constant())) {
992 length = append(new ArrayLength(array, state_before));
993 }
994
995 if (array->is_flattened_array()) {
996 ciType* array_type = array->declared_type();
997 ciValueKlass* elem_klass = array_type->as_value_array_klass()->element_klass()->as_value_klass();
998 NewValueTypeInstance* new_instance = new NewValueTypeInstance(elem_klass, state_before, false);
999 _memory->new_instance(new_instance);
1000 apush(append_split(new_instance));
1001 LoadIndexed* load_indexed = new LoadIndexed(array, index, length, type, state_before);
1002 load_indexed->set_vt(new_instance);
1003 append(load_indexed);
1004 } else {
1005 push(as_ValueType(type), append(new LoadIndexed(array, index, length, type, state_before)));
1006 }
1007 }
1008
1009
1010 void GraphBuilder::store_indexed(BasicType type) {
1011 // In case of in block code motion in range check elimination
1012 ValueStack* state_before = copy_state_indexed_access();
1013 compilation()->set_has_access_indexed(true);
1014 Value value = pop(as_ValueType(type));
1015 Value index = ipop();
1016 Value array = apop();
1017 Value length = NULL;
1018 if (CSEArrayLength ||
1019 (array->as_AccessField() && array->as_AccessField()->field()->is_constant()) ||
1020 (array->as_NewArray() && array->as_NewArray()->length() && array->as_NewArray()->length()->type()->is_constant())) {
1021 length = append(new ArrayLength(array, state_before));
1022 }
1023 ciType* array_type = array->declared_type();
1024 bool check_boolean = false;
1025 if (array_type != NULL) {
1026 if (array_type->is_loaded() &&
1707 }
1708 break;
1709 }
1710 case Bytecodes::_putstatic: {
1711 Value val = pop(type);
1712 if (state_before == NULL) {
1713 state_before = copy_state_for_exception();
1714 }
1715 if (field->type()->basic_type() == T_BOOLEAN) {
1716 Value mask = append(new Constant(new IntConstant(1)));
1717 val = append(new LogicOp(Bytecodes::_iand, val, mask));
1718 }
1719 append(new StoreField(append(obj), offset, field, val, true, state_before, needs_patching));
1720 break;
1721 }
1722 case Bytecodes::_getfield: {
1723 // Check for compile-time constants, i.e., trusted final non-static fields.
1724 Value constant = NULL;
1725 obj = apop();
1726 ObjectType* obj_type = obj->type()->as_ObjectType();
1727 if (field->is_constant() && !field->is_flattened() && obj_type->is_constant() && !PatchALot) {
1728 ciObject* const_oop = obj_type->constant_value();
1729 if (!const_oop->is_null_object() && const_oop->is_loaded()) {
1730 ciConstant field_value = field->constant_value_of(const_oop);
1731 if (field_value.is_valid()) {
1732 constant = make_constant(field_value, field);
1733 // For CallSite objects add a dependency for invalidation of the optimization.
1734 if (field->is_call_site_target()) {
1735 ciCallSite* call_site = const_oop->as_call_site();
1736 if (!call_site->is_constant_call_site()) {
1737 ciMethodHandle* target = field_value.as_object()->as_method_handle();
1738 dependency_recorder()->assert_call_site_target_value(call_site, target);
1739 }
1740 }
1741 }
1742 }
1743 }
1744 if (constant != NULL) {
1745 push(type, append(constant));
1746 } else {
1747 if (state_before == NULL) {
1748 state_before = copy_state_for_exception();
1749 }
1750 // Pb with test below, is_flattened() can return true for fields that are not value types
1751 // (initialization issue of ciField?)
1752 if (!(field->type()->is_valuetype() && field->is_flattened())) {
1753 LoadField* load = new LoadField(obj, offset, field, false, state_before, needs_patching);
1754 Value replacement = !needs_patching ? _memory->load(load) : load;
1755 if (replacement != load) {
1756 assert(replacement->is_linked() || !replacement->can_be_linked(), "should already by linked");
1757 push(type, replacement);
1758 } else {
1759 push(type, append(load));
1760 }
1761 } else { // flattened field, not optimized solution: re-instantiate the flattened value
1762 ciValueKlass* value_klass = field->type()->as_value_klass();
1763 int flattening_offset = field->offset() - value_klass->first_field_offset();
1764 assert(field->type()->is_valuetype(), "Sanity check");
1765 scope()->set_wrote_final();
1766 scope()->set_wrote_fields();
1767 NewValueTypeInstance* new_instance = new NewValueTypeInstance(value_klass, state_before, false);
1768 _memory->new_instance(new_instance);
1769 apush(append_split(new_instance));
1770 for (int i = 0; i < holder->nof_nonstatic_fields(); i++) {
1771 ciField* inner_field = holder->nonstatic_field_at(i);
1772 int off = inner_field->offset();
1773 // Only load those fields who are not modified
1774 LoadField* load = new LoadField(obj, off + flattening_offset, inner_field, false, state_before, needs_patching);
1775 Value replacement = append(load);
1776 StoreField* store = new StoreField(new_instance, off, inner_field, replacement, false, state_before, needs_patching);
1777 append(store);
1778 }
1779 }
1780 }
1781 break;
1782 }
1783 case Bytecodes::_putfield: {
1784 Value val = pop(type);
1785 obj = apop();
1786 if (state_before == NULL) {
1787 state_before = copy_state_for_exception();
1788 }
1789 if (field->type()->basic_type() == T_BOOLEAN) {
1790 Value mask = append(new Constant(new IntConstant(1)));
1791 val = append(new LogicOp(Bytecodes::_iand, val, mask));
1792 }
1793 // Pb with test below, is_flattened() can return true for fields that are not value types
1794 // (initialization issue of ciField?)
1795 if (!(field->type()->is_valuetype() && field->is_flattened())) {
1796 StoreField* store = new StoreField(obj, offset, field, val, false, state_before, needs_patching);
1797 if (!needs_patching) store = _memory->store(store);
1798 if (store != NULL) {
1799 append(store);
1800 }
1801 } else {
1802 ciValueKlass* value_klass = field->type()->as_value_klass();
1803 int flattening_offset = field->offset() - value_klass->first_field_offset();
1804 for (int i = 0; i < holder->nof_nonstatic_fields(); i++) {
1805 ciField* inner_field = holder->nonstatic_field_at(i);
1806 int off = inner_field->offset();
1807 // Only load those fields who are not modified
1808 // LoadField* load = new LoadField(obj, off + flattening_offset, inner_field, false, state_before, needs_patching);
1809 LoadField* load = new LoadField(val, off, inner_field, false, state_before, needs_patching);
1810 Value replacement = append(load);
1811 StoreField* store = new StoreField(obj, off + flattening_offset, inner_field, replacement, false, state_before, needs_patching);
1812 append(store);
1813 }
1814 }
1815 break;
1816 }
1817 default:
1818 ShouldNotReachHere();
1819 break;
1820 }
1821 }
1822
1823 // Baseline version of withfield, allocate every time
1824 void GraphBuilder::withfield(int field_index)
1825 {
1826 bool will_link;
1827 ciField* field_modify = stream()->get_field(will_link);
1828 ciInstanceKlass* holder = field_modify->holder();
1829 assert(holder->is_valuetype(), "must be a value klass");
1830 BasicType field_type = field_modify->type()->basic_type();
1831 ValueType* type = as_ValueType(field_type);
1832
1833 // call will_link again to determine if the field is valid.
1834 const bool needs_patching = !holder->is_loaded() ||
1835 !field_modify->will_link(method(), Bytecodes::_withfield) ||
1836 PatchALot;
1837
1838
1839 scope()->set_wrote_final();
1840 scope()->set_wrote_fields();
1841
1842 const int offset = !needs_patching ? field_modify->offset() : -1;
1843 Value val = pop(type);
1844 Value obj = apop();
1845
1846 ValueStack* state_before = copy_state_for_exception();
1847
1848 NewValueTypeInstance* new_instance = new NewValueTypeInstance(holder->as_value_klass(), state_before, false);
1849 _memory->new_instance(new_instance);
1850 apush(append_split(new_instance));
1851
1852 for (int i = 0; i < holder->nof_nonstatic_fields(); i++) {
1853 ciField* field = holder->nonstatic_field_at(i);
1854 int off = field->offset();
1855
1856 if (field->offset() != offset) {
1857 // Only load those fields who are not modified
1858 LoadField* load = new LoadField(obj, off, field, false, state_before, needs_patching);
1859 Value replacement = append(load);
1860
1861 StoreField* store = new StoreField(new_instance, off, field, replacement, false, state_before, needs_patching);
1862 append(store);
1863 }
1864 }
1865
1866 // Field to modify
1867 if (field_modify->type()->basic_type() == T_BOOLEAN) {
1868 Value mask = append(new Constant(new IntConstant(1)));
1869 val = append(new LogicOp(Bytecodes::_iand, val, mask));
1870 }
1871 StoreField* store = new StoreField(new_instance, offset, field_modify, val, false, state_before, needs_patching);
1872 append(store);
1873 }
1874
1875 Dependencies* GraphBuilder::dependency_recorder() const {
1876 assert(DeoptC1, "need debug information");
1877 return compilation()->dependency_recorder();
1878 }
1879
1880 // How many arguments do we want to profile?
1881 Values* GraphBuilder::args_list_for_profiling(ciMethod* target, int& start, bool may_have_receiver) {
1882 int n = 0;
1883 bool has_receiver = may_have_receiver && Bytecodes::has_receiver(method()->java_code_at_bci(bci()));
1884 start = has_receiver ? 1 : 0;
1885 if (profile_arguments()) {
1886 ciProfileData* data = method()->method_data()->bci_to_data(bci());
1887 if (data != NULL && (data->is_CallTypeData() || data->is_VirtualCallTypeData())) {
1888 n = data->is_CallTypeData() ? data->as_CallTypeData()->number_of_arguments() : data->as_VirtualCallTypeData()->number_of_arguments();
1889 }
1890 }
1891 // If we are inlining then we need to collect arguments to profile parameters for the target
1892 if (profile_parameters() && target != NULL) {
1893 if (target->method_data() != NULL && target->method_data()->parameters_type_data() != NULL) {
2241 append_split(result);
2242
2243 if (result_type != voidType) {
2244 if (method()->is_strict()) {
2245 push(result_type, round_fp(result));
2246 } else {
2247 push(result_type, result);
2248 }
2249 }
2250 if (profile_return() && result_type->is_object_kind()) {
2251 profile_return_type(result, target);
2252 }
2253 }
2254
2255
2256 void GraphBuilder::new_instance(int klass_index) {
2257 ValueStack* state_before = copy_state_exhandling();
2258 bool will_link;
2259 ciKlass* klass = stream()->get_klass(will_link);
2260 assert(klass->is_instance_klass(), "must be an instance klass");
2261 assert(!klass->is_valuetype(), "must not be a value klass");
2262 NewInstance* new_instance = new NewInstance(klass->as_instance_klass(), state_before, stream()->is_unresolved_klass());
2263 _memory->new_instance(new_instance);
2264 apush(append_split(new_instance));
2265 }
2266
2267 void GraphBuilder::new_value_type_instance(int klass_index) {
2268 ValueStack* state_before = copy_state_exhandling();
2269 bool will_link;
2270 ciKlass* klass = stream()->get_klass(will_link);
2271 assert(klass->is_valuetype(), "must be a value klass");
2272 NewValueTypeInstance* new_instance = new NewValueTypeInstance(klass->as_value_klass(),
2273 state_before, stream()->is_unresolved_klass());
2274 _memory->new_instance(new_instance);
2275 apush(append_split(new_instance));
2276 }
2277
2278 void GraphBuilder::new_type_array() {
2279 ValueStack* state_before = copy_state_exhandling();
2280 apush(append_split(new NewTypeArray(ipop(), (BasicType)stream()->get_index(), state_before)));
2281 }
2282
2283
2284 void GraphBuilder::new_object_array() {
2285 bool will_link;
2286 ciKlass* klass = stream()->get_klass(will_link);
2287 ValueStack* state_before = !klass->is_loaded() || PatchALot ? copy_state_before() : copy_state_exhandling();
2288 NewArray* n = new NewObjectArray(klass, ipop(), state_before);
2289 apush(append_split(n));
2290 }
2291
2292
2293 bool GraphBuilder::direct_compare(ciKlass* k) {
2294 if (k->is_loaded() && k->is_instance_klass() && !UseSlowPath) {
2295 ciInstanceKlass* ik = k->as_instance_klass();
2296 if (ik->is_final()) {
2991 case Bytecodes::_invokevirtual : // fall through
2992 case Bytecodes::_invokespecial : // fall through
2993 case Bytecodes::_invokestatic : // fall through
2994 case Bytecodes::_invokedynamic : // fall through
2995 case Bytecodes::_invokeinterface: invoke(code); break;
2996 case Bytecodes::_new : new_instance(s.get_index_u2()); break;
2997 case Bytecodes::_newarray : new_type_array(); break;
2998 case Bytecodes::_anewarray : new_object_array(); break;
2999 case Bytecodes::_arraylength : { ValueStack* state_before = copy_state_for_exception(); ipush(append(new ArrayLength(apop(), state_before))); break; }
3000 case Bytecodes::_athrow : throw_op(s.cur_bci()); break;
3001 case Bytecodes::_checkcast : check_cast(s.get_index_u2()); break;
3002 case Bytecodes::_instanceof : instance_of(s.get_index_u2()); break;
3003 case Bytecodes::_monitorenter : monitorenter(apop(), s.cur_bci()); break;
3004 case Bytecodes::_monitorexit : monitorexit (apop(), s.cur_bci()); break;
3005 case Bytecodes::_wide : ShouldNotReachHere(); break;
3006 case Bytecodes::_multianewarray : new_multi_array(s.cur_bcp()[3]); break;
3007 case Bytecodes::_ifnull : if_null(objectType, If::eql); break;
3008 case Bytecodes::_ifnonnull : if_null(objectType, If::neq); break;
3009 case Bytecodes::_goto_w : _goto(s.cur_bci(), s.get_far_dest()); break;
3010 case Bytecodes::_jsr_w : jsr(s.get_far_dest()); break;
3011 case Bytecodes::_defaultvalue : new_value_type_instance(s.get_index_u2()); break;
3012 case Bytecodes::_withfield : withfield(s.get_index_u2()); break;
3013 case Bytecodes::_breakpoint : BAILOUT_("concurrent setting of breakpoint", NULL);
3014 default : ShouldNotReachHere(); break;
3015 }
3016
3017 if (log != NULL)
3018 log->clear_context(); // skip marker if nothing was printed
3019
3020 // save current bci to setup Goto at the end
3021 prev_bci = s.cur_bci();
3022
3023 }
3024 CHECK_BAILOUT_(NULL);
3025 // stop processing of this block (see try_inline_full)
3026 if (_skip_block) {
3027 _skip_block = false;
3028 assert(_last && _last->as_BlockEnd(), "");
3029 return _last->as_BlockEnd();
3030 }
3031 // if there are any, check if last instruction is a BlockEnd instruction
3032 BlockEnd* end = last()->as_BlockEnd();
3288 }
3289
3290
3291 ValueStack* GraphBuilder::state_at_entry() {
3292 ValueStack* state = new ValueStack(scope(), NULL);
3293
3294 // Set up locals for receiver
3295 int idx = 0;
3296 if (!method()->is_static()) {
3297 // we should always see the receiver
3298 state->store_local(idx, new Local(method()->holder(), objectType, idx, true));
3299 idx = 1;
3300 }
3301
3302 // Set up locals for incoming arguments
3303 ciSignature* sig = method()->signature();
3304 for (int i = 0; i < sig->count(); i++) {
3305 ciType* type = sig->type_at(i);
3306 BasicType basic_type = type->basic_type();
3307 // don't allow T_ARRAY to propagate into locals types
3308 if (basic_type == T_ARRAY || basic_type == T_VALUETYPE) basic_type = T_OBJECT;
3309 ValueType* vt = as_ValueType(basic_type);
3310 state->store_local(idx, new Local(type, vt, idx, false));
3311 idx += type->size();
3312 }
3313
3314 // lock synchronized method
3315 if (method()->is_synchronized()) {
3316 state->lock(NULL);
3317 }
3318
3319 return state;
3320 }
3321
3322
3323 GraphBuilder::GraphBuilder(Compilation* compilation, IRScope* scope)
3324 : _scope_data(NULL)
3325 , _compilation(compilation)
3326 , _memory(new MemoryBuffer())
3327 , _inline_bailout_msg(NULL)
3328 , _instruction_count(0)
|