/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "precompiled.hpp"
#include "c1/c1_Compilation.hpp"
#include "c1/c1_FrameMap.hpp"
#include "c1/c1_GraphBuilder.hpp"
#include "c1/c1_InstructionPrinter.hpp"
#include "c1/c1_Optimizer.hpp"
#include "utilities/bitMap.inline.hpp"
// Implementation of XHandlers
//
// Note: This code could eventually go away if we are
// just using the ciExceptionHandlerStream.
while (!s.is_done()) {
s.next();
}
}
// deep copy of all XHandler contained in list
{
}
}
// Returns whether a particular exception type can be caught. Also
// returns true if klass is unloaded or any exception handler
// classes are unloaded. type_is_exact indicates whether the throw
// is known to be exactly that class or it might throw a subtype.
// the type is unknown so be conservative
return true;
}
for (int i = 0; i < length(); i++) {
if (handler->is_catch_all()) {
// catch of ANY
return true;
}
// if it's unknown it might be catchable
if (!handler_klass->is_loaded()) {
return true;
}
// if the throw type is definitely a subtype of the catch type
// then it can be caught.
return true;
}
if (!type_is_exact) {
// If the type isn't exactly known then it can also be caught by
// catch statements where the inexact type is a subtype of the
// catch type.
// given: foo extends bar extends Exception
// throw bar can be caught by catch foo, catch bar, and catch
// Exception, however it can't be caught by any handlers without
// bar in its type hierarchy.
return true;
}
}
}
return false;
}
for (int i = 0; i < length(); i++) {
}
return true;
}
return true;
}
// Implementation of IRScope
}
IRScope::IRScope(Compilation* compilation, IRScope* caller, int caller_bci, ciMethod* method, int osr_bci, bool create_graph)
: _callees(2)
{
_number_of_locks = 0;
_wrote_final = false;
if (osr_bci == -1) {
} else {
// selective creation of phi functions is not possibel in osr-methods
}
// build graph if monitor pairing is ok
}
int callee_max = 0;
for (int i = 0; i < number_of_callees(); i++) {
}
return my_max + callee_max;
}
} else
return false;
}
// Implementation of CodeEmitInfo
// Stack must be NON-null
, _is_method_handle_invoke(false) {
}
// deep copy of exception handlers
}
}
// record the safepoint before recording the debug info for enclosing scopes
_scope_debug_info->record_debug_info(recorder, pc_offset, true/*topmost*/, _is_method_handle_invoke);
}
}
// Implementation of IR
, _num_loops(0) {
// setup IR fields
}
if (!compilation()->profile_branches()) {
if (DoCEE) {
#ifndef PRODUCT
#endif
}
if (EliminateBlocks) {
#ifndef PRODUCT
#endif
}
}
if (EliminateNullChecks) {
#ifndef PRODUCT
#endif
}
}
} else {
}
}
public:
if (nos >= 2) {
for (int i = 0; i < nos; i++) {
}
}
}
}
void split_edges() {
#ifndef PRODUCT
}
#endif
}
}
};
CriticalEdgeFinder cef(this);
cef.split_edges();
}
private:
// Local instructions and Phis for expression stack values at the
// start of basic blocks are not added to the instruction list
if (!(*n)->is_linked() && (*n)->can_be_linked()) {
assert(false, "a node was not appended to the graph");
}
// use n's input if not visited before
// note: a) if the instruction is pinned, it will be handled by compute_use_count
// b) if the instruction has uses, it was touched before
// => in both cases we don't need to update n's values
uses_do(n);
}
// use n
(*n)->_use_count++;
}
int depth;
enum {
};
depth++;
if (depth > max_recurse_depth) {
// don't allow the traversal to recurse too deeply
} else {
(*n)->input_values_do(this);
// special handling for some instructions
if ((*n)->as_BlockEnd() != NULL) {
// note on BlockEnd:
// must 'use' the stack only if the method doesn't
// terminate, however, in those cases stack is empty
(*n)->state_values_do(this);
}
}
depth--;
}
depth = 0;
// process all pinned nodes as the roots of expression trees
}
// now process any unpinned nodes which recursed too deeply
if (!t->is_pinned()) {
// compute the use count
uses_do(&t);
// pin the instruction so that LIRGenerator doesn't recurse
// too deeply during it's evaluation.
t->pin();
}
}
}
UseCountComputer() {
depth = 0;
}
public:
}
};
// helper macro for short definition of trace-output inside code
#ifndef PRODUCT
if (TraceLinearScanLevel >= level) { \
code; \
}
#else
#endif
private:
// accessors for _visited_blocks and _active_blocks
void set_visited(BlockBegin* b) { assert(!is_visited(b), "already set"); _visited_blocks.set_bit(b->block_id()); }
void set_active(BlockBegin* b) { assert(!is_active(b), "already set"); _active_blocks.set_bit(b->block_id()); }
void clear_active(BlockBegin* b) { assert(is_active(b), "not already"); _active_blocks.clear_bit(b->block_id()); }
// accessors for _forward_branches
void inc_forward_branches(BlockBegin* b) { _forward_branches.at_put(b->block_id(), _forward_branches.at(b->block_id()) + 1); }
int dec_forward_branches(BlockBegin* b) { _forward_branches.at_put(b->block_id(), _forward_branches.at(b->block_id()) - 1); return _forward_branches.at(b->block_id()); }
// accessors for _loop_map
bool is_block_in_loop (int loop_idx, BlockBegin* b) const { return _loop_map.at(loop_idx, b->block_id()); }
void set_block_in_loop (int loop_idx, BlockBegin* b) { _loop_map.set_bit(loop_idx, b->block_id()); }
// count edges between blocks
// loop detection
void mark_loops();
// computation of final block order
void sort_into_work_list(BlockBegin* b);
// fixup of dominators for non-natural loops
bool compute_dominators_iter();
void compute_dominators();
// debug functions
NOT_PRODUCT(void print_blocks();)
DEBUG_ONLY(void verify();)
public:
// accessors for final result
};
_num_blocks(0),
_num_loops(0),
_iterative_dominators(false),
_loop_end_blocks(8),
_work_list(8),
_loop_map(0, 0), // initialized later with correct size
_compilation(c)
{
init_visited();
if (compilation()->is_profiling()) {
if (!method->is_accessor()) {
}
}
if (_num_loops > 0) {
mark_loops();
}
DEBUG_ONLY(verify());
}
// Traverse the CFG:
// * count total number of blocks
// * count all incoming edges and backward incoming edges
// * number loop header blocks
// * create a list with all loop end blocks
TRACE_LINEAR_SCAN(3, tty->print_cr("Enter count_edges for block B%d coming from B%d", cur->block_id(), parent != NULL ? parent->block_id() : -1));
// When a loop header is also the start of an exception handler, then the backward branch is
// an exception edge. Because such edges are usually critical edges which cannot be split, the
// loop must be excluded here from processing.
// Make sure that dominators are correct in this weird situation
_iterative_dominators = true;
return;
}
"loop end blocks must have one successor (critical edges are split)");
return;
}
// increment number of incoming forward branches
if (is_visited(cur)) {
return;
}
_num_blocks++;
// recursive call for all successors
int i;
}
}
// Each loop has a unique number.
// When multiple loops are nested, assign_loop_depth assumes that the
// innermost loop has the lowest number. This is guaranteed by setting
// the loop number after the recursive calls for the successors above
// have returned.
TRACE_LINEAR_SCAN(3, tty->print_cr("Block B%d is loop header of loop %d", cur->block_id(), _num_loops));
_num_loops++;
}
}
TRACE_LINEAR_SCAN(3, tty->print_cr("Processing loop from B%d to B%d (loop %d):", loop_start->block_id(), loop_end->block_id(), loop_idx));
assert(loop_start->is_set(BlockBegin::linear_scan_loop_header_flag), "loop header flag must be set");
// add the end-block of the loop to the working list
do {
// recursive processing of all predecessors ends when start block of loop is reached
// this predecessor has not been processed yet, so add it to work list
}
}
}
} while (!_work_list.is_empty());
}
}
// check for non-natural loops (loops where the loop header does not dominate
// all other loop blocks = loops with mulitple entries).
// such loops are ignored
for (int i = _num_loops - 1; i >= 0; i--) {
if (is_block_in_loop(i, start_block)) {
// loop i contains the entry block of the method
// -> this is not a natural loop, so ignore it
}
_iterative_dominators = true;
}
}
}
init_visited();
do {
if (!is_visited(cur)) {
// compute loop-depth and loop-index for the block
int i;
int loop_depth = 0;
for (i = _num_loops - 1; i >= 0; i--) {
if (is_block_in_loop(i, cur)) {
loop_depth++;
min_loop_idx = i;
}
}
// append all unvisited successors to work list
}
}
}
} while (!_work_list.is_empty());
}
while (a != NULL) {
a = a->dominator();
}
b = b->dominator();
}
return b;
}
TRACE_LINEAR_SCAN(4, tty->print_cr("DOM: initializing dominator of B%d to B%d", cur->block_id(), parent->block_id()));
} else if (!(cur->is_set(BlockBegin::linear_scan_loop_header_flag) && parent->is_set(BlockBegin::linear_scan_loop_end_flag))) {
TRACE_LINEAR_SCAN(4, tty->print_cr("DOM: computing dominator of B%d: common dominator of B%d and B%d is B%d", cur->block_id(), parent->block_id(), cur->dominator()->block_id(), common_dominator(cur->dominator(), parent)->block_id()));
}
}
}
// limit loop-depth to 15 bit (only for security reason, it will never be so big)
// general macro for short definition of weight flags
// the first instance of INC_WEIGHT_IF has the highest priority
// this is necessery for the (very rare) case that two successing blocks have
// the same loop depth, but a different loop index (can happen for endless loops
// with exception handlers)
// loop end blocks (blocks that end with a backward branch) are added
// after all other blocks of the loop.
// critical edge split blocks are prefered because than they have a bigger
// proability to be completely empty
// exceptions should not be thrown in normal control flow, so these blocks
// are added as late as possible
INC_WEIGHT_IF(cur->end()->as_Throw() == NULL && (single_sux == NULL || single_sux->end()->as_Throw() == NULL));
INC_WEIGHT_IF(cur->end()->as_Return() == NULL && (single_sux == NULL || single_sux->end()->as_Return() == NULL));
// exceptions handlers are added as late as possible
// guarantee that weight is > 0
weight |= 1;
return weight;
}
// Discount the edge just traveled.
// When the number drops to zero, all forward branches were processed
if (dec_forward_branches(cur) != 0) {
return false;
}
assert(_linear_scan_order->index_of(cur) == -1, "block already processed (block can be ready only once)");
assert(_work_list.index_of(cur) == -1, "block already in work-list (block can be ready only once)");
return true;
}
// the linear_scan_number is used to cache the weight of a block
#ifndef PRODUCT
if (StressLinearScan) {
return;
}
#endif
insert_idx--;
}
TRACE_LINEAR_SCAN(3, for (int i = 0; i < _work_list.length(); i++) tty->print_cr("%8d B%2d weight:%6x", i, _work_list.at(i)->block_id(), _work_list.at(i)->linear_scan_number()));
#ifdef ASSERT
for (int i = 0; i < _work_list.length(); i++) {
assert(i == 0 || _work_list.at(i - 1)->linear_scan_number() <= _work_list.at(i)->linear_scan_number(), "incorrect order in worklist");
}
#endif
}
TRACE_LINEAR_SCAN(3, tty->print_cr("appending block B%d (weight 0x%6x) to linear-scan order", cur->block_id(), cur->linear_scan_number()));
// currently, the linear scan order and code emit order are equal.
// therefore the linear_scan_number and the weight of a block must also
// be equal.
}
// the start block is always the first block in the linear scan order
// special handling for osr entry:
// ignore the edge between the osr entry and its successor for processing
// the osr entry block is added manually below
assert(osr_entry->sux_at(0)->number_of_preds() >= 2, "sucessor of osr entry must have two predecessors (otherwise it is not present in normal control flow");
_iterative_dominators = true;
}
// start processing with standard entry block
if (ready_for_processing(std_entry)) {
} else {
assert(false, "the std_entry must be ready for processing (otherwise, the method has no start block)");
}
do {
if (cur == sux_of_osr_entry) {
// the osr entry block is ignored in normal processing, it is never added to the
// work list. Instead, it is added as late as possible manually here.
}
int i;
// changed loop order to get "intuitive" order of if- and else-blocks
for (i = 0; i < num_sux; i++) {
if (ready_for_processing(sux)) {
}
}
for (i = 0; i < num_sux; i++) {
if (ready_for_processing(sux)) {
}
}
} while (_work_list.length() > 0);
}
bool changed = false;
for (int i = 1; i < num_blocks; i++) {
for (int i = 1; i < num_preds; i++) {
}
TRACE_LINEAR_SCAN(4, tty->print_cr("DOM: updating dominator of B%d from B%d to B%d", block->block_id(), block->dominator()->block_id(), dominator->block_id()));
changed = true;
}
}
return changed;
}
TRACE_LINEAR_SCAN(3, tty->print_cr("----- computing dominators (iterative computation reqired: %d)", _iterative_dominators));
// iterative computation of dominators is only required for methods with non-natural loops
// and OSR-methods. For all other methods, the dominators computed when generating the
// linear scan block order are correct.
if (_iterative_dominators) {
do {
} while (compute_dominators_iter());
}
// check that dominators are correct
}
#ifndef PRODUCT
if (TraceLinearScanLevel >= 2) {
}
}
}
if (TraceLinearScanLevel >= 1) {
tty->print("%4d: B%2d loop: %2d depth: %2d", cur->linear_scan_number(), cur->block_id(), cur->loop_index(), cur->loop_depth());
} else {
}
if (cur->number_of_preds() > 0) {
for (int j = 0; j < cur->number_of_preds(); j++) {
}
}
if (cur->number_of_sux() > 0) {
for (int j = 0; j < cur->number_of_sux(); j++) {
}
}
if (cur->number_of_exception_handlers() > 0) {
for (int j = 0; j < cur->number_of_exception_handlers(); j++) {
}
}
}
}
}
#endif
#ifdef ASSERT
if (StressLinearScan) {
// blocks are scrambled when StressLinearScan is used
return;
}
// check that all successors of a block have a higher linear-scan-number
// and that all predecessors of a block have a lower linear-scan-number
// (only backward branches of loops are ignored)
int i;
for (i = 0; i < _linear_scan_order->length(); i++) {
assert(cur->linear_scan_number() >= 0 && cur->linear_scan_number() == _linear_scan_order->index_of(cur), "incorrect linear_scan_number");
int j;
assert(sux->linear_scan_number() >= 0 && sux->linear_scan_number() == _linear_scan_order->index_of(sux), "incorrect linear_scan_number");
}
assert(cur->loop_index() == sux->loop_index() || sux->is_set(BlockBegin::linear_scan_loop_header_flag), "successing blocks with same loop depth must have same loop index");
}
}
assert(pred->linear_scan_number() >= 0 && pred->linear_scan_number() == _linear_scan_order->index_of(pred), "incorrect linear_scan_number");
}
assert(cur->loop_index() == pred->loop_index() || cur->is_set(BlockBegin::linear_scan_loop_header_flag), "successing blocks with same loop depth must have same loop index");
}
assert(cur->dominator()->linear_scan_number() <= cur->pred_at(j)->linear_scan_number(), "dominator must be before predecessors");
}
// check dominator
if (i == 0) {
} else {
}
assert(cur->number_of_preds() != 1 || cur->dominator() == cur->pred_at(0), "Single predecessor must also be dominator");
}
// check that all loops are continuous
int block_idx = 0;
assert(!is_block_in_loop(loop_idx, _linear_scan_order->at(block_idx)), "the first block must not be present in any loop");
// skip blocks before the loop
block_idx++;
}
// skip blocks of loop
block_idx++;
}
// after the first non-loop block, there must not be another loop-block
while (block_idx < _num_blocks) {
assert(!is_block_in_loop(loop_idx, _linear_scan_order->at(block_idx)), "loop not continuous in linear-scan order");
block_idx++;
}
}
}
#endif
}
// make sure all values coming out of this block get evaluated.
for (int i = 0; i < num_blocks; i++) {
}
// compute use counts
}
}
}
}
#ifndef PRODUCT
private:
bool _cfg_only;
bool _live_only;
public:
}
if (_cfg_only) {
} else {
}
}
};
}
if (is_valid()) {
} else {
}
}
private:
}
public:
int i;
}
}
continue;
}
// clone the pred list so we can mutate it
int j;
for (j = 0; j < block->number_of_preds(); j++) {
}
// sort them in the same order
for (j = 0; j < block->number_of_preds(); j++) {
}
}
}
int n = be->number_of_sux();
int i;
for (i = 0; i < n; i++) {
}
}
n = block->number_of_exception_handlers();
for (i = 0; i < n; i++) {
}
}
}
};
#ifdef ASSERT
PredecessorValidator pv(this);
#endif
}
#endif // PRODUCT
if (v0) {
}
}
}
#ifdef ASSERT
if (v0) {
}
}
};
#endif
n->values_do(this);
// need to remove this instruction from the instruction stream
if (n->subst() != n) {
} else {
last = n;
}
}
#ifdef ASSERT
#endif
}