1 /*
2 * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
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 *
339 // set block for each case
340 Bytecode_lookupswitch sw(&s);
341 int l = sw.number_of_pairs();
342 for (int i = 0; i < l; i++) {
343 make_block_at(cur_bci + sw.pair_at(i).offset(), current);
344 }
345 make_block_at(cur_bci + sw.default_offset(), current);
346 current = NULL;
347 break;
348 }
349 }
350 }
351 }
352
353
354 void BlockListBuilder::mark_loops() {
355 ResourceMark rm;
356
357 _active = BitMap(BlockBegin::number_of_blocks()); _active.clear();
358 _visited = BitMap(BlockBegin::number_of_blocks()); _visited.clear();
359 _loop_map = intArray(BlockBegin::number_of_blocks(), 0);
360 _next_loop_index = 0;
361 _next_block_number = _blocks.length();
362
363 // recursively iterate the control flow graph
364 mark_loops(_bci2block->at(0), false);
365 assert(_next_block_number >= 0, "invalid block numbers");
366 }
367
368 void BlockListBuilder::make_loop_header(BlockBegin* block) {
369 if (block->is_set(BlockBegin::exception_entry_flag)) {
370 // exception edges may look like loops but don't mark them as such
371 // since it screws up block ordering.
372 return;
373 }
374 if (!block->is_set(BlockBegin::parser_loop_header_flag)) {
375 block->set(BlockBegin::parser_loop_header_flag);
376
377 assert(_loop_map.at(block->block_id()) == 0, "must not be set yet");
378 assert(0 <= _next_loop_index && _next_loop_index < BitsPerInt, "_next_loop_index is used as a bit-index in integer");
379 _loop_map.at_put(block->block_id(), 1 << _next_loop_index);
1336 void GraphBuilder::lookup_switch() {
1337 Bytecode_lookupswitch sw(stream());
1338 const int l = sw.number_of_pairs();
1339 if (CanonicalizeNodes && l == 1) {
1340 // total of 2 successors => use If instead of switch
1341 // Note: This code should go into the canonicalizer as soon as it can
1342 // can handle canonicalized forms that contain more than one node.
1343 // simplify to If
1344 LookupswitchPair pair = sw.pair_at(0);
1345 Value key = append(new Constant(new IntConstant(pair.match())));
1346 BlockBegin* tsux = block_at(bci() + pair.offset());
1347 BlockBegin* fsux = block_at(bci() + sw.default_offset());
1348 bool is_bb = tsux->bci() < bci() || fsux->bci() < bci();
1349 // In case of loop invariant code motion or predicate insertion
1350 // before the body of a loop the state is needed
1351 ValueStack* state_before = copy_state_if_bb(is_bb);;
1352 append(new If(ipop(), If::eql, true, key, tsux, fsux, state_before, is_bb));
1353 } else {
1354 // collect successors & keys
1355 BlockList* sux = new BlockList(l + 1, NULL);
1356 intArray* keys = new intArray(l, 0);
1357 int i;
1358 bool has_bb = false;
1359 for (i = 0; i < l; i++) {
1360 LookupswitchPair pair = sw.pair_at(i);
1361 if (pair.offset() < 0) has_bb = true;
1362 sux->at_put(i, block_at(bci() + pair.offset()));
1363 keys->at_put(i, pair.match());
1364 }
1365 // add default successor
1366 if (sw.default_offset() < 0) has_bb = true;
1367 sux->at_put(i, block_at(bci() + sw.default_offset()));
1368 // In case of loop invariant code motion or predicate insertion
1369 // before the body of a loop the state is needed
1370 ValueStack* state_before = copy_state_if_bb(has_bb);
1371 Instruction* res = append(new LookupSwitch(ipop(), sux, keys, state_before, has_bb));
1372 #ifdef ASSERT
1373 if (res->as_Goto()) {
1374 for (i = 0; i < l; i++) {
1375 if (sux->at(i) == res->as_Goto()->sux_at(0)) {
1376 assert(res->as_Goto()->is_safepoint() == sw.pair_at(i).offset() < 0, "safepoint state of Goto returned by canonicalizer incorrect");
1704 // If we are inlining then we need to collect arguments to profile parameters for the target
1705 if (profile_parameters() && target != NULL) {
1706 if (target->method_data() != NULL && target->method_data()->parameters_type_data() != NULL) {
1707 // The receiver is profiled on method entry so it's included in
1708 // the number of parameters but here we're only interested in
1709 // actual arguments.
1710 n = MAX2(n, target->method_data()->parameters_type_data()->number_of_parameters() - start);
1711 }
1712 }
1713 if (n > 0) {
1714 return new Values(n);
1715 }
1716 return NULL;
1717 }
1718
1719 void GraphBuilder::check_args_for_profiling(Values* obj_args, int expected) {
1720 #ifdef ASSERT
1721 bool ignored_will_link;
1722 ciSignature* declared_signature = NULL;
1723 ciMethod* real_target = method()->get_method_at_bci(bci(), ignored_will_link, &declared_signature);
1724 assert(expected == obj_args->length() || real_target->is_method_handle_intrinsic(), "missed on arg?");
1725 #endif
1726 }
1727
1728 // Collect arguments that we want to profile in a list
1729 Values* GraphBuilder::collect_args_for_profiling(Values* args, ciMethod* target, bool may_have_receiver) {
1730 int start = 0;
1731 Values* obj_args = args_list_for_profiling(target, start, may_have_receiver);
1732 if (obj_args == NULL) {
1733 return NULL;
1734 }
1735 int s = obj_args->size();
1736 // if called through method handle invoke, some arguments may have been popped
1737 for (int i = start, j = 0; j < s && i < args->length(); i++) {
1738 if (args->at(i)->type()->is_object_kind()) {
1739 obj_args->push(args->at(i));
1740 j++;
1741 }
1742 }
1743 check_args_for_profiling(obj_args, s);
1744 return obj_args;
1745 }
1746
1747
1748 void GraphBuilder::invoke(Bytecodes::Code code) {
1749 bool will_link;
1750 ciSignature* declared_signature = NULL;
1751 ciMethod* target = stream()->get_method(will_link, &declared_signature);
1752 ciKlass* holder = stream()->get_declared_method_holder();
1753 const Bytecodes::Code bc_raw = stream()->cur_bc_raw();
1754 assert(declared_signature != NULL, "cannot be null");
1755
2152
2153 void GraphBuilder::monitorenter(Value x, int bci) {
2154 // save state before locking in case of deoptimization after a NullPointerException
2155 ValueStack* state_before = copy_state_for_exception_with_bci(bci);
2156 append_with_bci(new MonitorEnter(x, state()->lock(x), state_before), bci);
2157 kill_all();
2158 }
2159
2160
2161 void GraphBuilder::monitorexit(Value x, int bci) {
2162 append_with_bci(new MonitorExit(x, state()->unlock()), bci);
2163 kill_all();
2164 }
2165
2166
2167 void GraphBuilder::new_multi_array(int dimensions) {
2168 bool will_link;
2169 ciKlass* klass = stream()->get_klass(will_link);
2170 ValueStack* state_before = !klass->is_loaded() || PatchALot ? copy_state_before() : copy_state_exhandling();
2171
2172 Values* dims = new Values(dimensions, NULL);
2173 // fill in all dimensions
2174 int i = dimensions;
2175 while (i-- > 0) dims->at_put(i, ipop());
2176 // create array
2177 NewArray* n = new NewMultiArray(klass, dims, state_before);
2178 apush(append_split(n));
2179 }
2180
2181
2182 void GraphBuilder::throw_op(int bci) {
2183 // We require that the debug info for a Throw be the "state before"
2184 // the Throw (i.e., exception oop is still on TOS)
2185 ValueStack* state_before = copy_state_before_with_bci(bci);
2186 Throw* t = new Throw(apop(), state_before);
2187 // operand stack not needed after a throw
2188 state()->truncate_stack(0);
2189 append_with_bci(t, bci);
2190 }
2191
2192
3755 Value recv = NULL;
3756 if (has_receiver) {
3757 // note: null check must happen even if first instruction of callee does
3758 // an implicit null check since the callee is in a different scope
3759 // and we must make sure exception handling does the right thing
3760 assert(!callee->is_static(), "callee must not be static");
3761 assert(callee->arg_size() > 0, "must have at least a receiver");
3762 recv = state()->stack_at(args_base);
3763 null_check(recv);
3764 }
3765
3766 if (is_profiling()) {
3767 // Note that we'd collect profile data in this method if we wanted it.
3768 // this may be redundant here...
3769 compilation()->set_would_profile(true);
3770
3771 if (profile_calls()) {
3772 int start = 0;
3773 Values* obj_args = args_list_for_profiling(callee, start, has_receiver);
3774 if (obj_args != NULL) {
3775 int s = obj_args->size();
3776 // if called through method handle invoke, some arguments may have been popped
3777 for (int i = args_base+start, j = 0; j < obj_args->size() && i < state()->stack_size(); ) {
3778 Value v = state()->stack_at_inc(i);
3779 if (v->type()->is_object_kind()) {
3780 obj_args->push(v);
3781 j++;
3782 }
3783 }
3784 check_args_for_profiling(obj_args, s);
3785 }
3786 profile_call(callee, recv, holder_known ? callee->holder() : NULL, obj_args, true);
3787 }
3788 }
3789
3790 // Introduce a new callee continuation point - if the callee has
3791 // more than one return instruction or the return does not allow
3792 // fall-through of control flow, all return instructions of the
3793 // callee will need to be replaced by Goto's pointing to this
3794 // continuation point.
3795 BlockBegin* cont = block_at(next_bci());
3796 bool continuation_existed = true;
3797 if (cont == NULL) {
4074
4075 set_state(new ValueStack(callee_scope, state()->copy(ValueStack::CallerState, bci())));
4076
4077 ScopeData* data = new ScopeData(scope_data());
4078 data->set_scope(callee_scope);
4079 data->set_bci2block(blb.bci2block());
4080 data->set_continuation(continuation);
4081 _scope_data = data;
4082 }
4083
4084
4085 void GraphBuilder::push_scope_for_jsr(BlockBegin* jsr_continuation, int jsr_dest_bci) {
4086 ScopeData* data = new ScopeData(scope_data());
4087 data->set_parsing_jsr();
4088 data->set_jsr_entry_bci(jsr_dest_bci);
4089 data->set_jsr_return_address_local(-1);
4090 // Must clone bci2block list as we will be mutating it in order to
4091 // properly clone all blocks in jsr region as well as exception
4092 // handlers containing rets
4093 BlockList* new_bci2block = new BlockList(bci2block()->length());
4094 new_bci2block->push_all(bci2block());
4095 data->set_bci2block(new_bci2block);
4096 data->set_scope(scope());
4097 data->setup_jsr_xhandlers();
4098 data->set_continuation(continuation());
4099 data->set_jsr_continuation(jsr_continuation);
4100 _scope_data = data;
4101 }
4102
4103
4104 void GraphBuilder::pop_scope() {
4105 int number_of_locks = scope()->number_of_locks();
4106 _scope_data = scope_data()->parent();
4107 // accumulate minimum number of monitor slots to be reserved
4108 scope()->set_min_number_of_locks(number_of_locks);
4109 }
4110
4111
4112 void GraphBuilder::pop_scope_for_jsr() {
4113 _scope_data = scope_data()->parent();
4114 }
|
1 /*
2 * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
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 *
339 // set block for each case
340 Bytecode_lookupswitch sw(&s);
341 int l = sw.number_of_pairs();
342 for (int i = 0; i < l; i++) {
343 make_block_at(cur_bci + sw.pair_at(i).offset(), current);
344 }
345 make_block_at(cur_bci + sw.default_offset(), current);
346 current = NULL;
347 break;
348 }
349 }
350 }
351 }
352
353
354 void BlockListBuilder::mark_loops() {
355 ResourceMark rm;
356
357 _active = BitMap(BlockBegin::number_of_blocks()); _active.clear();
358 _visited = BitMap(BlockBegin::number_of_blocks()); _visited.clear();
359 _loop_map = intArray(BlockBegin::number_of_blocks(), BlockBegin::number_of_blocks(), 0);
360 _next_loop_index = 0;
361 _next_block_number = _blocks.length();
362
363 // recursively iterate the control flow graph
364 mark_loops(_bci2block->at(0), false);
365 assert(_next_block_number >= 0, "invalid block numbers");
366 }
367
368 void BlockListBuilder::make_loop_header(BlockBegin* block) {
369 if (block->is_set(BlockBegin::exception_entry_flag)) {
370 // exception edges may look like loops but don't mark them as such
371 // since it screws up block ordering.
372 return;
373 }
374 if (!block->is_set(BlockBegin::parser_loop_header_flag)) {
375 block->set(BlockBegin::parser_loop_header_flag);
376
377 assert(_loop_map.at(block->block_id()) == 0, "must not be set yet");
378 assert(0 <= _next_loop_index && _next_loop_index < BitsPerInt, "_next_loop_index is used as a bit-index in integer");
379 _loop_map.at_put(block->block_id(), 1 << _next_loop_index);
1336 void GraphBuilder::lookup_switch() {
1337 Bytecode_lookupswitch sw(stream());
1338 const int l = sw.number_of_pairs();
1339 if (CanonicalizeNodes && l == 1) {
1340 // total of 2 successors => use If instead of switch
1341 // Note: This code should go into the canonicalizer as soon as it can
1342 // can handle canonicalized forms that contain more than one node.
1343 // simplify to If
1344 LookupswitchPair pair = sw.pair_at(0);
1345 Value key = append(new Constant(new IntConstant(pair.match())));
1346 BlockBegin* tsux = block_at(bci() + pair.offset());
1347 BlockBegin* fsux = block_at(bci() + sw.default_offset());
1348 bool is_bb = tsux->bci() < bci() || fsux->bci() < bci();
1349 // In case of loop invariant code motion or predicate insertion
1350 // before the body of a loop the state is needed
1351 ValueStack* state_before = copy_state_if_bb(is_bb);;
1352 append(new If(ipop(), If::eql, true, key, tsux, fsux, state_before, is_bb));
1353 } else {
1354 // collect successors & keys
1355 BlockList* sux = new BlockList(l + 1, NULL);
1356 intArray* keys = new intArray(l, l, 0);
1357 int i;
1358 bool has_bb = false;
1359 for (i = 0; i < l; i++) {
1360 LookupswitchPair pair = sw.pair_at(i);
1361 if (pair.offset() < 0) has_bb = true;
1362 sux->at_put(i, block_at(bci() + pair.offset()));
1363 keys->at_put(i, pair.match());
1364 }
1365 // add default successor
1366 if (sw.default_offset() < 0) has_bb = true;
1367 sux->at_put(i, block_at(bci() + sw.default_offset()));
1368 // In case of loop invariant code motion or predicate insertion
1369 // before the body of a loop the state is needed
1370 ValueStack* state_before = copy_state_if_bb(has_bb);
1371 Instruction* res = append(new LookupSwitch(ipop(), sux, keys, state_before, has_bb));
1372 #ifdef ASSERT
1373 if (res->as_Goto()) {
1374 for (i = 0; i < l; i++) {
1375 if (sux->at(i) == res->as_Goto()->sux_at(0)) {
1376 assert(res->as_Goto()->is_safepoint() == sw.pair_at(i).offset() < 0, "safepoint state of Goto returned by canonicalizer incorrect");
1704 // If we are inlining then we need to collect arguments to profile parameters for the target
1705 if (profile_parameters() && target != NULL) {
1706 if (target->method_data() != NULL && target->method_data()->parameters_type_data() != NULL) {
1707 // The receiver is profiled on method entry so it's included in
1708 // the number of parameters but here we're only interested in
1709 // actual arguments.
1710 n = MAX2(n, target->method_data()->parameters_type_data()->number_of_parameters() - start);
1711 }
1712 }
1713 if (n > 0) {
1714 return new Values(n);
1715 }
1716 return NULL;
1717 }
1718
1719 void GraphBuilder::check_args_for_profiling(Values* obj_args, int expected) {
1720 #ifdef ASSERT
1721 bool ignored_will_link;
1722 ciSignature* declared_signature = NULL;
1723 ciMethod* real_target = method()->get_method_at_bci(bci(), ignored_will_link, &declared_signature);
1724 assert(expected == obj_args->max_length() || real_target->is_method_handle_intrinsic(), "missed on arg?");
1725 #endif
1726 }
1727
1728 // Collect arguments that we want to profile in a list
1729 Values* GraphBuilder::collect_args_for_profiling(Values* args, ciMethod* target, bool may_have_receiver) {
1730 int start = 0;
1731 Values* obj_args = args_list_for_profiling(target, start, may_have_receiver);
1732 if (obj_args == NULL) {
1733 return NULL;
1734 }
1735 int s = obj_args->max_length();
1736 // if called through method handle invoke, some arguments may have been popped
1737 for (int i = start, j = 0; j < s && i < args->length(); i++) {
1738 if (args->at(i)->type()->is_object_kind()) {
1739 obj_args->push(args->at(i));
1740 j++;
1741 }
1742 }
1743 check_args_for_profiling(obj_args, s);
1744 return obj_args;
1745 }
1746
1747
1748 void GraphBuilder::invoke(Bytecodes::Code code) {
1749 bool will_link;
1750 ciSignature* declared_signature = NULL;
1751 ciMethod* target = stream()->get_method(will_link, &declared_signature);
1752 ciKlass* holder = stream()->get_declared_method_holder();
1753 const Bytecodes::Code bc_raw = stream()->cur_bc_raw();
1754 assert(declared_signature != NULL, "cannot be null");
1755
2152
2153 void GraphBuilder::monitorenter(Value x, int bci) {
2154 // save state before locking in case of deoptimization after a NullPointerException
2155 ValueStack* state_before = copy_state_for_exception_with_bci(bci);
2156 append_with_bci(new MonitorEnter(x, state()->lock(x), state_before), bci);
2157 kill_all();
2158 }
2159
2160
2161 void GraphBuilder::monitorexit(Value x, int bci) {
2162 append_with_bci(new MonitorExit(x, state()->unlock()), bci);
2163 kill_all();
2164 }
2165
2166
2167 void GraphBuilder::new_multi_array(int dimensions) {
2168 bool will_link;
2169 ciKlass* klass = stream()->get_klass(will_link);
2170 ValueStack* state_before = !klass->is_loaded() || PatchALot ? copy_state_before() : copy_state_exhandling();
2171
2172 Values* dims = new Values(dimensions, dimensions, NULL);
2173 // fill in all dimensions
2174 int i = dimensions;
2175 while (i-- > 0) dims->at_put(i, ipop());
2176 // create array
2177 NewArray* n = new NewMultiArray(klass, dims, state_before);
2178 apush(append_split(n));
2179 }
2180
2181
2182 void GraphBuilder::throw_op(int bci) {
2183 // We require that the debug info for a Throw be the "state before"
2184 // the Throw (i.e., exception oop is still on TOS)
2185 ValueStack* state_before = copy_state_before_with_bci(bci);
2186 Throw* t = new Throw(apop(), state_before);
2187 // operand stack not needed after a throw
2188 state()->truncate_stack(0);
2189 append_with_bci(t, bci);
2190 }
2191
2192
3755 Value recv = NULL;
3756 if (has_receiver) {
3757 // note: null check must happen even if first instruction of callee does
3758 // an implicit null check since the callee is in a different scope
3759 // and we must make sure exception handling does the right thing
3760 assert(!callee->is_static(), "callee must not be static");
3761 assert(callee->arg_size() > 0, "must have at least a receiver");
3762 recv = state()->stack_at(args_base);
3763 null_check(recv);
3764 }
3765
3766 if (is_profiling()) {
3767 // Note that we'd collect profile data in this method if we wanted it.
3768 // this may be redundant here...
3769 compilation()->set_would_profile(true);
3770
3771 if (profile_calls()) {
3772 int start = 0;
3773 Values* obj_args = args_list_for_profiling(callee, start, has_receiver);
3774 if (obj_args != NULL) {
3775 int s = obj_args->max_length();
3776 // if called through method handle invoke, some arguments may have been popped
3777 for (int i = args_base+start, j = 0; j < obj_args->max_length() && i < state()->stack_size(); ) {
3778 Value v = state()->stack_at_inc(i);
3779 if (v->type()->is_object_kind()) {
3780 obj_args->push(v);
3781 j++;
3782 }
3783 }
3784 check_args_for_profiling(obj_args, s);
3785 }
3786 profile_call(callee, recv, holder_known ? callee->holder() : NULL, obj_args, true);
3787 }
3788 }
3789
3790 // Introduce a new callee continuation point - if the callee has
3791 // more than one return instruction or the return does not allow
3792 // fall-through of control flow, all return instructions of the
3793 // callee will need to be replaced by Goto's pointing to this
3794 // continuation point.
3795 BlockBegin* cont = block_at(next_bci());
3796 bool continuation_existed = true;
3797 if (cont == NULL) {
4074
4075 set_state(new ValueStack(callee_scope, state()->copy(ValueStack::CallerState, bci())));
4076
4077 ScopeData* data = new ScopeData(scope_data());
4078 data->set_scope(callee_scope);
4079 data->set_bci2block(blb.bci2block());
4080 data->set_continuation(continuation);
4081 _scope_data = data;
4082 }
4083
4084
4085 void GraphBuilder::push_scope_for_jsr(BlockBegin* jsr_continuation, int jsr_dest_bci) {
4086 ScopeData* data = new ScopeData(scope_data());
4087 data->set_parsing_jsr();
4088 data->set_jsr_entry_bci(jsr_dest_bci);
4089 data->set_jsr_return_address_local(-1);
4090 // Must clone bci2block list as we will be mutating it in order to
4091 // properly clone all blocks in jsr region as well as exception
4092 // handlers containing rets
4093 BlockList* new_bci2block = new BlockList(bci2block()->length());
4094 new_bci2block->appendAll(bci2block());
4095 data->set_bci2block(new_bci2block);
4096 data->set_scope(scope());
4097 data->setup_jsr_xhandlers();
4098 data->set_continuation(continuation());
4099 data->set_jsr_continuation(jsr_continuation);
4100 _scope_data = data;
4101 }
4102
4103
4104 void GraphBuilder::pop_scope() {
4105 int number_of_locks = scope()->number_of_locks();
4106 _scope_data = scope_data()->parent();
4107 // accumulate minimum number of monitor slots to be reserved
4108 scope()->set_min_number_of_locks(number_of_locks);
4109 }
4110
4111
4112 void GraphBuilder::pop_scope_for_jsr() {
4113 _scope_data = scope_data()->parent();
4114 }
|