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");
1699 // If we are inlining then we need to collect arguments to profile parameters for the target
1700 if (profile_parameters() && target != NULL) {
1701 if (target->method_data() != NULL && target->method_data()->parameters_type_data() != NULL) {
1702 // The receiver is profiled on method entry so it's included in
1703 // the number of parameters but here we're only interested in
1704 // actual arguments.
1705 n = MAX2(n, target->method_data()->parameters_type_data()->number_of_parameters() - start);
1706 }
1707 }
1708 if (n > 0) {
1709 return new Values(n);
1710 }
1711 return NULL;
1712 }
1713
1714 void GraphBuilder::check_args_for_profiling(Values* obj_args, int expected) {
1715 #ifdef ASSERT
1716 bool ignored_will_link;
1717 ciSignature* declared_signature = NULL;
1718 ciMethod* real_target = method()->get_method_at_bci(bci(), ignored_will_link, &declared_signature);
1719 assert(expected == obj_args->length() || real_target->is_method_handle_intrinsic(), "missed on arg?");
1720 #endif
1721 }
1722
1723 // Collect arguments that we want to profile in a list
1724 Values* GraphBuilder::collect_args_for_profiling(Values* args, ciMethod* target, bool may_have_receiver) {
1725 int start = 0;
1726 Values* obj_args = args_list_for_profiling(target, start, may_have_receiver);
1727 if (obj_args == NULL) {
1728 return NULL;
1729 }
1730 int s = obj_args->size();
1731 // if called through method handle invoke, some arguments may have been popped
1732 for (int i = start, j = 0; j < s && i < args->length(); i++) {
1733 if (args->at(i)->type()->is_object_kind()) {
1734 obj_args->push(args->at(i));
1735 j++;
1736 }
1737 }
1738 check_args_for_profiling(obj_args, s);
1739 return obj_args;
1740 }
1741
1742
1743 void GraphBuilder::invoke(Bytecodes::Code code) {
1744 bool will_link;
1745 ciSignature* declared_signature = NULL;
1746 ciMethod* target = stream()->get_method(will_link, &declared_signature);
1747 ciKlass* holder = stream()->get_declared_method_holder();
1748 const Bytecodes::Code bc_raw = stream()->cur_bc_raw();
1749 assert(declared_signature != NULL, "cannot be null");
1750
2147
2148 void GraphBuilder::monitorenter(Value x, int bci) {
2149 // save state before locking in case of deoptimization after a NullPointerException
2150 ValueStack* state_before = copy_state_for_exception_with_bci(bci);
2151 append_with_bci(new MonitorEnter(x, state()->lock(x), state_before), bci);
2152 kill_all();
2153 }
2154
2155
2156 void GraphBuilder::monitorexit(Value x, int bci) {
2157 append_with_bci(new MonitorExit(x, state()->unlock()), bci);
2158 kill_all();
2159 }
2160
2161
2162 void GraphBuilder::new_multi_array(int dimensions) {
2163 bool will_link;
2164 ciKlass* klass = stream()->get_klass(will_link);
2165 ValueStack* state_before = !klass->is_loaded() || PatchALot ? copy_state_before() : copy_state_exhandling();
2166
2167 Values* dims = new Values(dimensions, NULL);
2168 // fill in all dimensions
2169 int i = dimensions;
2170 while (i-- > 0) dims->at_put(i, ipop());
2171 // create array
2172 NewArray* n = new NewMultiArray(klass, dims, state_before);
2173 apush(append_split(n));
2174 }
2175
2176
2177 void GraphBuilder::throw_op(int bci) {
2178 // We require that the debug info for a Throw be the "state before"
2179 // the Throw (i.e., exception oop is still on TOS)
2180 ValueStack* state_before = copy_state_before_with_bci(bci);
2181 Throw* t = new Throw(apop(), state_before);
2182 // operand stack not needed after a throw
2183 state()->truncate_stack(0);
2184 append_with_bci(t, bci);
2185 }
2186
2187
3753 Value recv = NULL;
3754 if (has_receiver) {
3755 // note: null check must happen even if first instruction of callee does
3756 // an implicit null check since the callee is in a different scope
3757 // and we must make sure exception handling does the right thing
3758 assert(!callee->is_static(), "callee must not be static");
3759 assert(callee->arg_size() > 0, "must have at least a receiver");
3760 recv = state()->stack_at(args_base);
3761 null_check(recv);
3762 }
3763
3764 if (is_profiling()) {
3765 // Note that we'd collect profile data in this method if we wanted it.
3766 // this may be redundant here...
3767 compilation()->set_would_profile(true);
3768
3769 if (profile_calls()) {
3770 int start = 0;
3771 Values* obj_args = args_list_for_profiling(callee, start, has_receiver);
3772 if (obj_args != NULL) {
3773 int s = obj_args->size();
3774 // if called through method handle invoke, some arguments may have been popped
3775 for (int i = args_base+start, j = 0; j < obj_args->size() && i < state()->stack_size(); ) {
3776 Value v = state()->stack_at_inc(i);
3777 if (v->type()->is_object_kind()) {
3778 obj_args->push(v);
3779 j++;
3780 }
3781 }
3782 check_args_for_profiling(obj_args, s);
3783 }
3784 profile_call(callee, recv, holder_known ? callee->holder() : NULL, obj_args, true);
3785 }
3786 }
3787
3788 // Introduce a new callee continuation point - if the callee has
3789 // more than one return instruction or the return does not allow
3790 // fall-through of control flow, all return instructions of the
3791 // callee will need to be replaced by Goto's pointing to this
3792 // continuation point.
3793 BlockBegin* cont = block_at(next_bci());
3794 bool continuation_existed = true;
3795 if (cont == NULL) {
4072
4073 set_state(new ValueStack(callee_scope, state()->copy(ValueStack::CallerState, bci())));
4074
4075 ScopeData* data = new ScopeData(scope_data());
4076 data->set_scope(callee_scope);
4077 data->set_bci2block(blb.bci2block());
4078 data->set_continuation(continuation);
4079 _scope_data = data;
4080 }
4081
4082
4083 void GraphBuilder::push_scope_for_jsr(BlockBegin* jsr_continuation, int jsr_dest_bci) {
4084 ScopeData* data = new ScopeData(scope_data());
4085 data->set_parsing_jsr();
4086 data->set_jsr_entry_bci(jsr_dest_bci);
4087 data->set_jsr_return_address_local(-1);
4088 // Must clone bci2block list as we will be mutating it in order to
4089 // properly clone all blocks in jsr region as well as exception
4090 // handlers containing rets
4091 BlockList* new_bci2block = new BlockList(bci2block()->length());
4092 new_bci2block->push_all(bci2block());
4093 data->set_bci2block(new_bci2block);
4094 data->set_scope(scope());
4095 data->setup_jsr_xhandlers();
4096 data->set_continuation(continuation());
4097 data->set_jsr_continuation(jsr_continuation);
4098 _scope_data = data;
4099 }
4100
4101
4102 void GraphBuilder::pop_scope() {
4103 int number_of_locks = scope()->number_of_locks();
4104 _scope_data = scope_data()->parent();
4105 // accumulate minimum number of monitor slots to be reserved
4106 scope()->set_min_number_of_locks(number_of_locks);
4107 }
4108
4109
4110 void GraphBuilder::pop_scope_for_jsr() {
4111 _scope_data = scope_data()->parent();
4112 }
|
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");
1699 // If we are inlining then we need to collect arguments to profile parameters for the target
1700 if (profile_parameters() && target != NULL) {
1701 if (target->method_data() != NULL && target->method_data()->parameters_type_data() != NULL) {
1702 // The receiver is profiled on method entry so it's included in
1703 // the number of parameters but here we're only interested in
1704 // actual arguments.
1705 n = MAX2(n, target->method_data()->parameters_type_data()->number_of_parameters() - start);
1706 }
1707 }
1708 if (n > 0) {
1709 return new Values(n);
1710 }
1711 return NULL;
1712 }
1713
1714 void GraphBuilder::check_args_for_profiling(Values* obj_args, int expected) {
1715 #ifdef ASSERT
1716 bool ignored_will_link;
1717 ciSignature* declared_signature = NULL;
1718 ciMethod* real_target = method()->get_method_at_bci(bci(), ignored_will_link, &declared_signature);
1719 assert(expected == obj_args->max_length() || real_target->is_method_handle_intrinsic(), "missed on arg?");
1720 #endif
1721 }
1722
1723 // Collect arguments that we want to profile in a list
1724 Values* GraphBuilder::collect_args_for_profiling(Values* args, ciMethod* target, bool may_have_receiver) {
1725 int start = 0;
1726 Values* obj_args = args_list_for_profiling(target, start, may_have_receiver);
1727 if (obj_args == NULL) {
1728 return NULL;
1729 }
1730 int s = obj_args->max_length();
1731 // if called through method handle invoke, some arguments may have been popped
1732 for (int i = start, j = 0; j < s && i < args->length(); i++) {
1733 if (args->at(i)->type()->is_object_kind()) {
1734 obj_args->push(args->at(i));
1735 j++;
1736 }
1737 }
1738 check_args_for_profiling(obj_args, s);
1739 return obj_args;
1740 }
1741
1742
1743 void GraphBuilder::invoke(Bytecodes::Code code) {
1744 bool will_link;
1745 ciSignature* declared_signature = NULL;
1746 ciMethod* target = stream()->get_method(will_link, &declared_signature);
1747 ciKlass* holder = stream()->get_declared_method_holder();
1748 const Bytecodes::Code bc_raw = stream()->cur_bc_raw();
1749 assert(declared_signature != NULL, "cannot be null");
1750
2147
2148 void GraphBuilder::monitorenter(Value x, int bci) {
2149 // save state before locking in case of deoptimization after a NullPointerException
2150 ValueStack* state_before = copy_state_for_exception_with_bci(bci);
2151 append_with_bci(new MonitorEnter(x, state()->lock(x), state_before), bci);
2152 kill_all();
2153 }
2154
2155
2156 void GraphBuilder::monitorexit(Value x, int bci) {
2157 append_with_bci(new MonitorExit(x, state()->unlock()), bci);
2158 kill_all();
2159 }
2160
2161
2162 void GraphBuilder::new_multi_array(int dimensions) {
2163 bool will_link;
2164 ciKlass* klass = stream()->get_klass(will_link);
2165 ValueStack* state_before = !klass->is_loaded() || PatchALot ? copy_state_before() : copy_state_exhandling();
2166
2167 Values* dims = new Values(dimensions, dimensions, NULL);
2168 // fill in all dimensions
2169 int i = dimensions;
2170 while (i-- > 0) dims->at_put(i, ipop());
2171 // create array
2172 NewArray* n = new NewMultiArray(klass, dims, state_before);
2173 apush(append_split(n));
2174 }
2175
2176
2177 void GraphBuilder::throw_op(int bci) {
2178 // We require that the debug info for a Throw be the "state before"
2179 // the Throw (i.e., exception oop is still on TOS)
2180 ValueStack* state_before = copy_state_before_with_bci(bci);
2181 Throw* t = new Throw(apop(), state_before);
2182 // operand stack not needed after a throw
2183 state()->truncate_stack(0);
2184 append_with_bci(t, bci);
2185 }
2186
2187
3753 Value recv = NULL;
3754 if (has_receiver) {
3755 // note: null check must happen even if first instruction of callee does
3756 // an implicit null check since the callee is in a different scope
3757 // and we must make sure exception handling does the right thing
3758 assert(!callee->is_static(), "callee must not be static");
3759 assert(callee->arg_size() > 0, "must have at least a receiver");
3760 recv = state()->stack_at(args_base);
3761 null_check(recv);
3762 }
3763
3764 if (is_profiling()) {
3765 // Note that we'd collect profile data in this method if we wanted it.
3766 // this may be redundant here...
3767 compilation()->set_would_profile(true);
3768
3769 if (profile_calls()) {
3770 int start = 0;
3771 Values* obj_args = args_list_for_profiling(callee, start, has_receiver);
3772 if (obj_args != NULL) {
3773 int s = obj_args->max_length();
3774 // if called through method handle invoke, some arguments may have been popped
3775 for (int i = args_base+start, j = 0; j < obj_args->max_length() && i < state()->stack_size(); ) {
3776 Value v = state()->stack_at_inc(i);
3777 if (v->type()->is_object_kind()) {
3778 obj_args->push(v);
3779 j++;
3780 }
3781 }
3782 check_args_for_profiling(obj_args, s);
3783 }
3784 profile_call(callee, recv, holder_known ? callee->holder() : NULL, obj_args, true);
3785 }
3786 }
3787
3788 // Introduce a new callee continuation point - if the callee has
3789 // more than one return instruction or the return does not allow
3790 // fall-through of control flow, all return instructions of the
3791 // callee will need to be replaced by Goto's pointing to this
3792 // continuation point.
3793 BlockBegin* cont = block_at(next_bci());
3794 bool continuation_existed = true;
3795 if (cont == NULL) {
4072
4073 set_state(new ValueStack(callee_scope, state()->copy(ValueStack::CallerState, bci())));
4074
4075 ScopeData* data = new ScopeData(scope_data());
4076 data->set_scope(callee_scope);
4077 data->set_bci2block(blb.bci2block());
4078 data->set_continuation(continuation);
4079 _scope_data = data;
4080 }
4081
4082
4083 void GraphBuilder::push_scope_for_jsr(BlockBegin* jsr_continuation, int jsr_dest_bci) {
4084 ScopeData* data = new ScopeData(scope_data());
4085 data->set_parsing_jsr();
4086 data->set_jsr_entry_bci(jsr_dest_bci);
4087 data->set_jsr_return_address_local(-1);
4088 // Must clone bci2block list as we will be mutating it in order to
4089 // properly clone all blocks in jsr region as well as exception
4090 // handlers containing rets
4091 BlockList* new_bci2block = new BlockList(bci2block()->length());
4092 new_bci2block->appendAll(bci2block());
4093 data->set_bci2block(new_bci2block);
4094 data->set_scope(scope());
4095 data->setup_jsr_xhandlers();
4096 data->set_continuation(continuation());
4097 data->set_jsr_continuation(jsr_continuation);
4098 _scope_data = data;
4099 }
4100
4101
4102 void GraphBuilder::pop_scope() {
4103 int number_of_locks = scope()->number_of_locks();
4104 _scope_data = scope_data()->parent();
4105 // accumulate minimum number of monitor slots to be reserved
4106 scope()->set_min_number_of_locks(number_of_locks);
4107 }
4108
4109
4110 void GraphBuilder::pop_scope_for_jsr() {
4111 _scope_data = scope_data()->parent();
4112 }
|