Path: blob/master/src/hotspot/share/c1/c1_IR.cpp
40930 views
/*1* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "c1/c1_Compilation.hpp"26#include "c1/c1_FrameMap.hpp"27#include "c1/c1_GraphBuilder.hpp"28#include "c1/c1_IR.hpp"29#include "c1/c1_InstructionPrinter.hpp"30#include "c1/c1_Optimizer.hpp"31#include "compiler/oopMap.hpp"32#include "memory/resourceArea.hpp"33#include "utilities/bitMap.inline.hpp"343536// Implementation of XHandlers37//38// Note: This code could eventually go away if we are39// just using the ciExceptionHandlerStream.4041XHandlers::XHandlers(ciMethod* method) : _list(method->exception_table_length()) {42ciExceptionHandlerStream s(method);43while (!s.is_done()) {44_list.append(new XHandler(s.handler()));45s.next();46}47assert(s.count() == method->exception_table_length(), "exception table lengths inconsistent");48}4950// deep copy of all XHandler contained in list51XHandlers::XHandlers(XHandlers* other) :52_list(other->length())53{54for (int i = 0; i < other->length(); i++) {55_list.append(new XHandler(other->handler_at(i)));56}57}5859// Returns whether a particular exception type can be caught. Also60// returns true if klass is unloaded or any exception handler61// classes are unloaded. type_is_exact indicates whether the throw62// is known to be exactly that class or it might throw a subtype.63bool XHandlers::could_catch(ciInstanceKlass* klass, bool type_is_exact) const {64// the type is unknown so be conservative65if (!klass->is_loaded()) {66return true;67}6869for (int i = 0; i < length(); i++) {70XHandler* handler = handler_at(i);71if (handler->is_catch_all()) {72// catch of ANY73return true;74}75ciInstanceKlass* handler_klass = handler->catch_klass();76// if it's unknown it might be catchable77if (!handler_klass->is_loaded()) {78return true;79}80// if the throw type is definitely a subtype of the catch type81// then it can be caught.82if (klass->is_subtype_of(handler_klass)) {83return true;84}85if (!type_is_exact) {86// If the type isn't exactly known then it can also be caught by87// catch statements where the inexact type is a subtype of the88// catch type.89// given: foo extends bar extends Exception90// throw bar can be caught by catch foo, catch bar, and catch91// Exception, however it can't be caught by any handlers without92// bar in its type hierarchy.93if (handler_klass->is_subtype_of(klass)) {94return true;95}96}97}9899return false;100}101102103bool XHandlers::equals(XHandlers* others) const {104if (others == NULL) return false;105if (length() != others->length()) return false;106107for (int i = 0; i < length(); i++) {108if (!handler_at(i)->equals(others->handler_at(i))) return false;109}110return true;111}112113bool XHandler::equals(XHandler* other) const {114assert(entry_pco() != -1 && other->entry_pco() != -1, "must have entry_pco");115116if (entry_pco() != other->entry_pco()) return false;117if (scope_count() != other->scope_count()) return false;118if (_desc != other->_desc) return false;119120assert(entry_block() == other->entry_block(), "entry_block must be equal when entry_pco is equal");121return true;122}123124125// Implementation of IRScope126BlockBegin* IRScope::build_graph(Compilation* compilation, int osr_bci) {127GraphBuilder gm(compilation, this);128NOT_PRODUCT(if (PrintValueNumbering && Verbose) gm.print_stats());129if (compilation->bailed_out()) return NULL;130return gm.start();131}132133134IRScope::IRScope(Compilation* compilation, IRScope* caller, int caller_bci, ciMethod* method, int osr_bci, bool create_graph)135: _compilation(compilation)136, _callees(2)137, _requires_phi_function(method->max_locals())138{139_caller = caller;140_level = caller == NULL ? 0 : caller->level() + 1;141_method = method;142_xhandlers = new XHandlers(method);143_number_of_locks = 0;144_monitor_pairing_ok = method->has_balanced_monitors();145_wrote_final = false;146_wrote_fields = false;147_wrote_volatile = false;148_start = NULL;149150if (osr_bci != -1) {151// selective creation of phi functions is not possibel in osr-methods152_requires_phi_function.set_range(0, method->max_locals());153}154155assert(method->holder()->is_loaded() , "method holder must be loaded");156157// build graph if monitor pairing is ok158if (create_graph && monitor_pairing_ok()) _start = build_graph(compilation, osr_bci);159}160161162int IRScope::max_stack() const {163int my_max = method()->max_stack();164int callee_max = 0;165for (int i = 0; i < number_of_callees(); i++) {166callee_max = MAX2(callee_max, callee_no(i)->max_stack());167}168return my_max + callee_max;169}170171172bool IRScopeDebugInfo::should_reexecute() {173ciMethod* cur_method = scope()->method();174int cur_bci = bci();175if (cur_method != NULL && cur_bci != SynchronizationEntryBCI) {176Bytecodes::Code code = cur_method->java_code_at_bci(cur_bci);177return Interpreter::bytecode_should_reexecute(code);178} else179return false;180}181182183// Implementation of CodeEmitInfo184185// Stack must be NON-null186CodeEmitInfo::CodeEmitInfo(ValueStack* stack, XHandlers* exception_handlers, bool deoptimize_on_exception)187: _scope_debug_info(NULL)188, _scope(stack->scope())189, _exception_handlers(exception_handlers)190, _oop_map(NULL)191, _stack(stack)192, _is_method_handle_invoke(false)193, _deoptimize_on_exception(deoptimize_on_exception) {194assert(_stack != NULL, "must be non null");195}196197198CodeEmitInfo::CodeEmitInfo(CodeEmitInfo* info, ValueStack* stack)199: _scope_debug_info(NULL)200, _scope(info->_scope)201, _exception_handlers(NULL)202, _oop_map(NULL)203, _stack(stack == NULL ? info->_stack : stack)204, _is_method_handle_invoke(info->_is_method_handle_invoke)205, _deoptimize_on_exception(info->_deoptimize_on_exception) {206207// deep copy of exception handlers208if (info->_exception_handlers != NULL) {209_exception_handlers = new XHandlers(info->_exception_handlers);210}211}212213214void CodeEmitInfo::record_debug_info(DebugInformationRecorder* recorder, int pc_offset) {215// record the safepoint before recording the debug info for enclosing scopes216recorder->add_safepoint(pc_offset, _oop_map->deep_copy());217_scope_debug_info->record_debug_info(recorder, pc_offset, true/*topmost*/, _is_method_handle_invoke);218recorder->end_safepoint(pc_offset);219}220221222void CodeEmitInfo::add_register_oop(LIR_Opr opr) {223assert(_oop_map != NULL, "oop map must already exist");224assert(opr->is_single_cpu(), "should not call otherwise");225226VMReg name = frame_map()->regname(opr);227_oop_map->set_oop(name);228}229230// Mirror the stack size calculation in the deopt code231// How much stack space would we need at this point in the program in232// case of deoptimization?233int CodeEmitInfo::interpreter_frame_size() const {234ValueStack* state = _stack;235int size = 0;236int callee_parameters = 0;237int callee_locals = 0;238int extra_args = state->scope()->method()->max_stack() - state->stack_size();239240while (state != NULL) {241int locks = state->locks_size();242int temps = state->stack_size();243bool is_top_frame = (state == _stack);244ciMethod* method = state->scope()->method();245246int frame_size = BytesPerWord * Interpreter::size_activation(method->max_stack(),247temps + callee_parameters,248extra_args,249locks,250callee_parameters,251callee_locals,252is_top_frame);253size += frame_size;254255callee_parameters = method->size_of_parameters();256callee_locals = method->max_locals();257extra_args = 0;258state = state->caller_state();259}260return size + Deoptimization::last_frame_adjust(0, callee_locals) * BytesPerWord;261}262263// Implementation of IR264265IR::IR(Compilation* compilation, ciMethod* method, int osr_bci) :266_num_loops(0) {267// setup IR fields268_compilation = compilation;269_top_scope = new IRScope(compilation, NULL, -1, method, osr_bci, true);270_code = NULL;271}272273274void IR::optimize_blocks() {275Optimizer opt(this);276if (!compilation()->profile_branches()) {277if (DoCEE) {278opt.eliminate_conditional_expressions();279#ifndef PRODUCT280if (PrintCFG || PrintCFG1) { tty->print_cr("CFG after CEE"); print(true); }281if (PrintIR || PrintIR1 ) { tty->print_cr("IR after CEE"); print(false); }282#endif283}284if (EliminateBlocks) {285opt.eliminate_blocks();286#ifndef PRODUCT287if (PrintCFG || PrintCFG1) { tty->print_cr("CFG after block elimination"); print(true); }288if (PrintIR || PrintIR1 ) { tty->print_cr("IR after block elimination"); print(false); }289#endif290}291}292}293294void IR::eliminate_null_checks() {295Optimizer opt(this);296if (EliminateNullChecks) {297opt.eliminate_null_checks();298#ifndef PRODUCT299if (PrintCFG || PrintCFG1) { tty->print_cr("CFG after null check elimination"); print(true); }300if (PrintIR || PrintIR1 ) { tty->print_cr("IR after null check elimination"); print(false); }301#endif302}303}304305306static int sort_pairs(BlockPair** a, BlockPair** b) {307if ((*a)->from() == (*b)->from()) {308return (*a)->to()->block_id() - (*b)->to()->block_id();309} else {310return (*a)->from()->block_id() - (*b)->from()->block_id();311}312}313314315class CriticalEdgeFinder: public BlockClosure {316BlockPairList blocks;317IR* _ir;318319public:320CriticalEdgeFinder(IR* ir): _ir(ir) {}321void block_do(BlockBegin* bb) {322BlockEnd* be = bb->end();323int nos = be->number_of_sux();324if (nos >= 2) {325for (int i = 0; i < nos; i++) {326BlockBegin* sux = be->sux_at(i);327if (sux->number_of_preds() >= 2) {328blocks.append(new BlockPair(bb, sux));329}330}331}332}333334void split_edges() {335BlockPair* last_pair = NULL;336blocks.sort(sort_pairs);337for (int i = 0; i < blocks.length(); i++) {338BlockPair* pair = blocks.at(i);339if (last_pair != NULL && pair->is_same(last_pair)) continue;340BlockBegin* from = pair->from();341BlockBegin* to = pair->to();342BlockBegin* split = from->insert_block_between(to);343#ifndef PRODUCT344if ((PrintIR || PrintIR1) && Verbose) {345tty->print_cr("Split critical edge B%d -> B%d (new block B%d)",346from->block_id(), to->block_id(), split->block_id());347}348#endif349last_pair = pair;350}351}352};353354void IR::split_critical_edges() {355CriticalEdgeFinder cef(this);356357iterate_preorder(&cef);358cef.split_edges();359}360361362class UseCountComputer: public ValueVisitor, BlockClosure {363private:364void visit(Value* n) {365// Local instructions and Phis for expression stack values at the366// start of basic blocks are not added to the instruction list367if (!(*n)->is_linked() && (*n)->can_be_linked()) {368assert(false, "a node was not appended to the graph");369Compilation::current()->bailout("a node was not appended to the graph");370}371// use n's input if not visited before372if (!(*n)->is_pinned() && !(*n)->has_uses()) {373// note: a) if the instruction is pinned, it will be handled by compute_use_count374// b) if the instruction has uses, it was touched before375// => in both cases we don't need to update n's values376uses_do(n);377}378// use n379(*n)->_use_count++;380}381382Values* worklist;383int depth;384enum {385max_recurse_depth = 20386};387388void uses_do(Value* n) {389depth++;390if (depth > max_recurse_depth) {391// don't allow the traversal to recurse too deeply392worklist->push(*n);393} else {394(*n)->input_values_do(this);395// special handling for some instructions396if ((*n)->as_BlockEnd() != NULL) {397// note on BlockEnd:398// must 'use' the stack only if the method doesn't399// terminate, however, in those cases stack is empty400(*n)->state_values_do(this);401}402}403depth--;404}405406void block_do(BlockBegin* b) {407depth = 0;408// process all pinned nodes as the roots of expression trees409for (Instruction* n = b; n != NULL; n = n->next()) {410if (n->is_pinned()) uses_do(&n);411}412assert(depth == 0, "should have counted back down");413414// now process any unpinned nodes which recursed too deeply415while (worklist->length() > 0) {416Value t = worklist->pop();417if (!t->is_pinned()) {418// compute the use count419uses_do(&t);420421// pin the instruction so that LIRGenerator doesn't recurse422// too deeply during it's evaluation.423t->pin();424}425}426assert(depth == 0, "should have counted back down");427}428429UseCountComputer() {430worklist = new Values();431depth = 0;432}433434public:435static void compute(BlockList* blocks) {436UseCountComputer ucc;437blocks->iterate_backward(&ucc);438}439};440441442// helper macro for short definition of trace-output inside code443#ifdef ASSERT444#define TRACE_LINEAR_SCAN(level, code) \445if (TraceLinearScanLevel >= level) { \446code; \447}448#else449#define TRACE_LINEAR_SCAN(level, code)450#endif451452class ComputeLinearScanOrder : public StackObj {453private:454int _max_block_id; // the highest block_id of a block455int _num_blocks; // total number of blocks (smaller than _max_block_id)456int _num_loops; // total number of loops457bool _iterative_dominators;// method requires iterative computation of dominatiors458459BlockList* _linear_scan_order; // the resulting list of blocks in correct order460461ResourceBitMap _visited_blocks; // used for recursive processing of blocks462ResourceBitMap _active_blocks; // used for recursive processing of blocks463ResourceBitMap _dominator_blocks; // temproary BitMap used for computation of dominator464intArray _forward_branches; // number of incoming forward branches for each block465BlockList _loop_end_blocks; // list of all loop end blocks collected during count_edges466BitMap2D _loop_map; // two-dimensional bit set: a bit is set if a block is contained in a loop467BlockList _work_list; // temporary list (used in mark_loops and compute_order)468BlockList _loop_headers;469470Compilation* _compilation;471472// accessors for _visited_blocks and _active_blocks473void init_visited() { _active_blocks.clear(); _visited_blocks.clear(); }474bool is_visited(BlockBegin* b) const { return _visited_blocks.at(b->block_id()); }475bool is_active(BlockBegin* b) const { return _active_blocks.at(b->block_id()); }476void set_visited(BlockBegin* b) { assert(!is_visited(b), "already set"); _visited_blocks.set_bit(b->block_id()); }477void set_active(BlockBegin* b) { assert(!is_active(b), "already set"); _active_blocks.set_bit(b->block_id()); }478void clear_active(BlockBegin* b) { assert(is_active(b), "not already"); _active_blocks.clear_bit(b->block_id()); }479480// accessors for _forward_branches481void inc_forward_branches(BlockBegin* b) { _forward_branches.at_put(b->block_id(), _forward_branches.at(b->block_id()) + 1); }482int 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()); }483484// accessors for _loop_map485bool is_block_in_loop (int loop_idx, BlockBegin* b) const { return _loop_map.at(loop_idx, b->block_id()); }486void set_block_in_loop (int loop_idx, BlockBegin* b) { _loop_map.set_bit(loop_idx, b->block_id()); }487void clear_block_in_loop(int loop_idx, int block_id) { _loop_map.clear_bit(loop_idx, block_id); }488489// count edges between blocks490void count_edges(BlockBegin* cur, BlockBegin* parent);491492// loop detection493void mark_loops();494void clear_non_natural_loops(BlockBegin* start_block);495void assign_loop_depth(BlockBegin* start_block);496497// computation of final block order498BlockBegin* common_dominator(BlockBegin* a, BlockBegin* b);499void compute_dominator(BlockBegin* cur, BlockBegin* parent);500void compute_dominator_impl(BlockBegin* cur, BlockBegin* parent);501int compute_weight(BlockBegin* cur);502bool ready_for_processing(BlockBegin* cur);503void sort_into_work_list(BlockBegin* b);504void append_block(BlockBegin* cur);505void compute_order(BlockBegin* start_block);506507// fixup of dominators for non-natural loops508bool compute_dominators_iter();509void compute_dominators();510511// debug functions512DEBUG_ONLY(void print_blocks();)513DEBUG_ONLY(void verify();)514515Compilation* compilation() const { return _compilation; }516public:517ComputeLinearScanOrder(Compilation* c, BlockBegin* start_block);518519// accessors for final result520BlockList* linear_scan_order() const { return _linear_scan_order; }521int num_loops() const { return _num_loops; }522};523524525ComputeLinearScanOrder::ComputeLinearScanOrder(Compilation* c, BlockBegin* start_block) :526_max_block_id(BlockBegin::number_of_blocks()),527_num_blocks(0),528_num_loops(0),529_iterative_dominators(false),530_linear_scan_order(NULL), // initialized later with correct size531_visited_blocks(_max_block_id),532_active_blocks(_max_block_id),533_dominator_blocks(_max_block_id),534_forward_branches(_max_block_id, _max_block_id, 0),535_loop_end_blocks(8),536_loop_map(0), // initialized later with correct size537_work_list(8),538_compilation(c)539{540TRACE_LINEAR_SCAN(2, tty->print_cr("***** computing linear-scan block order"));541542count_edges(start_block, NULL);543544if (compilation()->is_profiling()) {545ciMethod *method = compilation()->method();546if (!method->is_accessor()) {547ciMethodData* md = method->method_data_or_null();548assert(md != NULL, "Sanity");549md->set_compilation_stats(_num_loops, _num_blocks);550}551}552553if (_num_loops > 0) {554mark_loops();555clear_non_natural_loops(start_block);556assign_loop_depth(start_block);557}558559compute_order(start_block);560compute_dominators();561562DEBUG_ONLY(print_blocks());563DEBUG_ONLY(verify());564}565566567// Traverse the CFG:568// * count total number of blocks569// * count all incoming edges and backward incoming edges570// * number loop header blocks571// * create a list with all loop end blocks572void ComputeLinearScanOrder::count_edges(BlockBegin* cur, BlockBegin* parent) {573TRACE_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));574assert(cur->dominator() == NULL, "dominator already initialized");575576if (is_active(cur)) {577TRACE_LINEAR_SCAN(3, tty->print_cr("backward branch"));578assert(is_visited(cur), "block must be visisted when block is active");579assert(parent != NULL, "must have parent");580581cur->set(BlockBegin::backward_branch_target_flag);582583// When a loop header is also the start of an exception handler, then the backward branch is584// an exception edge. Because such edges are usually critical edges which cannot be split, the585// loop must be excluded here from processing.586if (cur->is_set(BlockBegin::exception_entry_flag)) {587// Make sure that dominators are correct in this weird situation588_iterative_dominators = true;589return;590}591592cur->set(BlockBegin::linear_scan_loop_header_flag);593parent->set(BlockBegin::linear_scan_loop_end_flag);594595assert(parent->number_of_sux() == 1 && parent->sux_at(0) == cur,596"loop end blocks must have one successor (critical edges are split)");597598_loop_end_blocks.append(parent);599return;600}601602// increment number of incoming forward branches603inc_forward_branches(cur);604605if (is_visited(cur)) {606TRACE_LINEAR_SCAN(3, tty->print_cr("block already visited"));607return;608}609610_num_blocks++;611set_visited(cur);612set_active(cur);613614// recursive call for all successors615int i;616for (i = cur->number_of_sux() - 1; i >= 0; i--) {617count_edges(cur->sux_at(i), cur);618}619for (i = cur->number_of_exception_handlers() - 1; i >= 0; i--) {620count_edges(cur->exception_handler_at(i), cur);621}622623clear_active(cur);624625// Each loop has a unique number.626// When multiple loops are nested, assign_loop_depth assumes that the627// innermost loop has the lowest number. This is guaranteed by setting628// the loop number after the recursive calls for the successors above629// have returned.630if (cur->is_set(BlockBegin::linear_scan_loop_header_flag)) {631assert(cur->loop_index() == -1, "cannot set loop-index twice");632TRACE_LINEAR_SCAN(3, tty->print_cr("Block B%d is loop header of loop %d", cur->block_id(), _num_loops));633634cur->set_loop_index(_num_loops);635_loop_headers.append(cur);636_num_loops++;637}638639TRACE_LINEAR_SCAN(3, tty->print_cr("Finished count_edges for block B%d", cur->block_id()));640}641642643void ComputeLinearScanOrder::mark_loops() {644TRACE_LINEAR_SCAN(3, tty->print_cr("----- marking loops"));645646_loop_map = BitMap2D(_num_loops, _max_block_id);647648for (int i = _loop_end_blocks.length() - 1; i >= 0; i--) {649BlockBegin* loop_end = _loop_end_blocks.at(i);650BlockBegin* loop_start = loop_end->sux_at(0);651int loop_idx = loop_start->loop_index();652653TRACE_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));654assert(loop_end->is_set(BlockBegin::linear_scan_loop_end_flag), "loop end flag must be set");655assert(loop_end->number_of_sux() == 1, "incorrect number of successors");656assert(loop_start->is_set(BlockBegin::linear_scan_loop_header_flag), "loop header flag must be set");657assert(loop_idx >= 0 && loop_idx < _num_loops, "loop index not set");658assert(_work_list.is_empty(), "work list must be empty before processing");659660// add the end-block of the loop to the working list661_work_list.push(loop_end);662set_block_in_loop(loop_idx, loop_end);663do {664BlockBegin* cur = _work_list.pop();665666TRACE_LINEAR_SCAN(3, tty->print_cr(" processing B%d", cur->block_id()));667assert(is_block_in_loop(loop_idx, cur), "bit in loop map must be set when block is in work list");668669// recursive processing of all predecessors ends when start block of loop is reached670if (cur != loop_start && !cur->is_set(BlockBegin::osr_entry_flag)) {671for (int j = cur->number_of_preds() - 1; j >= 0; j--) {672BlockBegin* pred = cur->pred_at(j);673674if (!is_block_in_loop(loop_idx, pred) /*&& !pred->is_set(BlockBeginosr_entry_flag)*/) {675// this predecessor has not been processed yet, so add it to work list676TRACE_LINEAR_SCAN(3, tty->print_cr(" pushing B%d", pred->block_id()));677_work_list.push(pred);678set_block_in_loop(loop_idx, pred);679}680}681}682} while (!_work_list.is_empty());683}684}685686687// check for non-natural loops (loops where the loop header does not dominate688// all other loop blocks = loops with mulitple entries).689// such loops are ignored690void ComputeLinearScanOrder::clear_non_natural_loops(BlockBegin* start_block) {691for (int i = _num_loops - 1; i >= 0; i--) {692if (is_block_in_loop(i, start_block)) {693// loop i contains the entry block of the method694// -> this is not a natural loop, so ignore it695TRACE_LINEAR_SCAN(2, tty->print_cr("Loop %d is non-natural, so it is ignored", i));696697BlockBegin *loop_header = _loop_headers.at(i);698assert(loop_header->is_set(BlockBegin::linear_scan_loop_header_flag), "Must be loop header");699700for (int j = 0; j < loop_header->number_of_preds(); j++) {701BlockBegin *pred = loop_header->pred_at(j);702pred->clear(BlockBegin::linear_scan_loop_end_flag);703}704705loop_header->clear(BlockBegin::linear_scan_loop_header_flag);706707for (int block_id = _max_block_id - 1; block_id >= 0; block_id--) {708clear_block_in_loop(i, block_id);709}710_iterative_dominators = true;711}712}713}714715void ComputeLinearScanOrder::assign_loop_depth(BlockBegin* start_block) {716TRACE_LINEAR_SCAN(3, tty->print_cr("----- computing loop-depth and weight"));717init_visited();718719assert(_work_list.is_empty(), "work list must be empty before processing");720_work_list.append(start_block);721722do {723BlockBegin* cur = _work_list.pop();724725if (!is_visited(cur)) {726set_visited(cur);727TRACE_LINEAR_SCAN(4, tty->print_cr("Computing loop depth for block B%d", cur->block_id()));728729// compute loop-depth and loop-index for the block730assert(cur->loop_depth() == 0, "cannot set loop-depth twice");731int i;732int loop_depth = 0;733int min_loop_idx = -1;734for (i = _num_loops - 1; i >= 0; i--) {735if (is_block_in_loop(i, cur)) {736loop_depth++;737min_loop_idx = i;738}739}740cur->set_loop_depth(loop_depth);741cur->set_loop_index(min_loop_idx);742743// append all unvisited successors to work list744for (i = cur->number_of_sux() - 1; i >= 0; i--) {745_work_list.append(cur->sux_at(i));746}747for (i = cur->number_of_exception_handlers() - 1; i >= 0; i--) {748_work_list.append(cur->exception_handler_at(i));749}750}751} while (!_work_list.is_empty());752}753754755BlockBegin* ComputeLinearScanOrder::common_dominator(BlockBegin* a, BlockBegin* b) {756assert(a != NULL && b != NULL, "must have input blocks");757758_dominator_blocks.clear();759while (a != NULL) {760_dominator_blocks.set_bit(a->block_id());761assert(a->dominator() != NULL || a == _linear_scan_order->at(0), "dominator must be initialized");762a = a->dominator();763}764while (b != NULL && !_dominator_blocks.at(b->block_id())) {765assert(b->dominator() != NULL || b == _linear_scan_order->at(0), "dominator must be initialized");766b = b->dominator();767}768769assert(b != NULL, "could not find dominator");770return b;771}772773void ComputeLinearScanOrder::compute_dominator(BlockBegin* cur, BlockBegin* parent) {774init_visited();775compute_dominator_impl(cur, parent);776}777778void ComputeLinearScanOrder::compute_dominator_impl(BlockBegin* cur, BlockBegin* parent) {779// Mark as visited to avoid recursive calls with same parent780set_visited(cur);781782if (cur->dominator() == NULL) {783TRACE_LINEAR_SCAN(4, tty->print_cr("DOM: initializing dominator of B%d to B%d", cur->block_id(), parent->block_id()));784cur->set_dominator(parent);785786} else if (!(cur->is_set(BlockBegin::linear_scan_loop_header_flag) && parent->is_set(BlockBegin::linear_scan_loop_end_flag))) {787TRACE_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()));788// Does not hold for exception blocks789assert(cur->number_of_preds() > 1 || cur->is_set(BlockBegin::exception_entry_flag), "");790cur->set_dominator(common_dominator(cur->dominator(), parent));791}792793// Additional edge to xhandler of all our successors794// range check elimination needs that the state at the end of a795// block be valid in every block it dominates so cur must dominate796// the exception handlers of its successors.797int num_cur_xhandler = cur->number_of_exception_handlers();798for (int j = 0; j < num_cur_xhandler; j++) {799BlockBegin* xhandler = cur->exception_handler_at(j);800if (!is_visited(xhandler)) {801compute_dominator_impl(xhandler, parent);802}803}804}805806807int ComputeLinearScanOrder::compute_weight(BlockBegin* cur) {808BlockBegin* single_sux = NULL;809if (cur->number_of_sux() == 1) {810single_sux = cur->sux_at(0);811}812813// limit loop-depth to 15 bit (only for security reason, it will never be so big)814int weight = (cur->loop_depth() & 0x7FFF) << 16;815816// general macro for short definition of weight flags817// the first instance of INC_WEIGHT_IF has the highest priority818int cur_bit = 15;819#define INC_WEIGHT_IF(condition) if ((condition)) { weight |= (1 << cur_bit); } cur_bit--;820821// this is necessery for the (very rare) case that two successing blocks have822// the same loop depth, but a different loop index (can happen for endless loops823// with exception handlers)824INC_WEIGHT_IF(!cur->is_set(BlockBegin::linear_scan_loop_header_flag));825826// loop end blocks (blocks that end with a backward branch) are added827// after all other blocks of the loop.828INC_WEIGHT_IF(!cur->is_set(BlockBegin::linear_scan_loop_end_flag));829830// critical edge split blocks are prefered because than they have a bigger831// proability to be completely empty832INC_WEIGHT_IF(cur->is_set(BlockBegin::critical_edge_split_flag));833834// exceptions should not be thrown in normal control flow, so these blocks835// are added as late as possible836INC_WEIGHT_IF(cur->end()->as_Throw() == NULL && (single_sux == NULL || single_sux->end()->as_Throw() == NULL));837INC_WEIGHT_IF(cur->end()->as_Return() == NULL && (single_sux == NULL || single_sux->end()->as_Return() == NULL));838839// exceptions handlers are added as late as possible840INC_WEIGHT_IF(!cur->is_set(BlockBegin::exception_entry_flag));841842// guarantee that weight is > 0843weight |= 1;844845#undef INC_WEIGHT_IF846assert(cur_bit >= 0, "too many flags");847assert(weight > 0, "weight cannot become negative");848849return weight;850}851852bool ComputeLinearScanOrder::ready_for_processing(BlockBegin* cur) {853// Discount the edge just traveled.854// When the number drops to zero, all forward branches were processed855if (dec_forward_branches(cur) != 0) {856return false;857}858859assert(_linear_scan_order->find(cur) == -1, "block already processed (block can be ready only once)");860assert(_work_list.find(cur) == -1, "block already in work-list (block can be ready only once)");861return true;862}863864void ComputeLinearScanOrder::sort_into_work_list(BlockBegin* cur) {865assert(_work_list.find(cur) == -1, "block already in work list");866867int cur_weight = compute_weight(cur);868869// the linear_scan_number is used to cache the weight of a block870cur->set_linear_scan_number(cur_weight);871872#ifndef PRODUCT873if (StressLinearScan) {874_work_list.insert_before(0, cur);875return;876}877#endif878879_work_list.append(NULL); // provide space for new element880881int insert_idx = _work_list.length() - 1;882while (insert_idx > 0 && _work_list.at(insert_idx - 1)->linear_scan_number() > cur_weight) {883_work_list.at_put(insert_idx, _work_list.at(insert_idx - 1));884insert_idx--;885}886_work_list.at_put(insert_idx, cur);887888TRACE_LINEAR_SCAN(3, tty->print_cr("Sorted B%d into worklist. new worklist:", cur->block_id()));889TRACE_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()));890891#ifdef ASSERT892for (int i = 0; i < _work_list.length(); i++) {893assert(_work_list.at(i)->linear_scan_number() > 0, "weight not set");894assert(i == 0 || _work_list.at(i - 1)->linear_scan_number() <= _work_list.at(i)->linear_scan_number(), "incorrect order in worklist");895}896#endif897}898899void ComputeLinearScanOrder::append_block(BlockBegin* cur) {900TRACE_LINEAR_SCAN(3, tty->print_cr("appending block B%d (weight 0x%6x) to linear-scan order", cur->block_id(), cur->linear_scan_number()));901assert(_linear_scan_order->find(cur) == -1, "cannot add the same block twice");902903// currently, the linear scan order and code emit order are equal.904// therefore the linear_scan_number and the weight of a block must also905// be equal.906cur->set_linear_scan_number(_linear_scan_order->length());907_linear_scan_order->append(cur);908}909910void ComputeLinearScanOrder::compute_order(BlockBegin* start_block) {911TRACE_LINEAR_SCAN(3, tty->print_cr("----- computing final block order"));912913// the start block is always the first block in the linear scan order914_linear_scan_order = new BlockList(_num_blocks);915append_block(start_block);916917assert(start_block->end()->as_Base() != NULL, "start block must end with Base-instruction");918BlockBegin* std_entry = ((Base*)start_block->end())->std_entry();919BlockBegin* osr_entry = ((Base*)start_block->end())->osr_entry();920921BlockBegin* sux_of_osr_entry = NULL;922if (osr_entry != NULL) {923// special handling for osr entry:924// ignore the edge between the osr entry and its successor for processing925// the osr entry block is added manually below926assert(osr_entry->number_of_sux() == 1, "osr entry must have exactly one successor");927assert(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");928929sux_of_osr_entry = osr_entry->sux_at(0);930dec_forward_branches(sux_of_osr_entry);931932compute_dominator(osr_entry, start_block);933_iterative_dominators = true;934}935compute_dominator(std_entry, start_block);936937// start processing with standard entry block938assert(_work_list.is_empty(), "list must be empty before processing");939940if (ready_for_processing(std_entry)) {941sort_into_work_list(std_entry);942} else {943assert(false, "the std_entry must be ready for processing (otherwise, the method has no start block)");944}945946do {947BlockBegin* cur = _work_list.pop();948949if (cur == sux_of_osr_entry) {950// the osr entry block is ignored in normal processing, it is never added to the951// work list. Instead, it is added as late as possible manually here.952append_block(osr_entry);953compute_dominator(cur, osr_entry);954}955append_block(cur);956957int i;958int num_sux = cur->number_of_sux();959// changed loop order to get "intuitive" order of if- and else-blocks960for (i = 0; i < num_sux; i++) {961BlockBegin* sux = cur->sux_at(i);962compute_dominator(sux, cur);963if (ready_for_processing(sux)) {964sort_into_work_list(sux);965}966}967num_sux = cur->number_of_exception_handlers();968for (i = 0; i < num_sux; i++) {969BlockBegin* sux = cur->exception_handler_at(i);970if (ready_for_processing(sux)) {971sort_into_work_list(sux);972}973}974} while (_work_list.length() > 0);975}976977978bool ComputeLinearScanOrder::compute_dominators_iter() {979bool changed = false;980int num_blocks = _linear_scan_order->length();981982assert(_linear_scan_order->at(0)->dominator() == NULL, "must not have dominator");983assert(_linear_scan_order->at(0)->number_of_preds() == 0, "must not have predecessors");984for (int i = 1; i < num_blocks; i++) {985BlockBegin* block = _linear_scan_order->at(i);986987BlockBegin* dominator = block->pred_at(0);988int num_preds = block->number_of_preds();989990TRACE_LINEAR_SCAN(4, tty->print_cr("DOM: Processing B%d", block->block_id()));991992for (int j = 0; j < num_preds; j++) {993994BlockBegin *pred = block->pred_at(j);995TRACE_LINEAR_SCAN(4, tty->print_cr(" DOM: Subrocessing B%d", pred->block_id()));996997if (block->is_set(BlockBegin::exception_entry_flag)) {998dominator = common_dominator(dominator, pred);999int num_pred_preds = pred->number_of_preds();1000for (int k = 0; k < num_pred_preds; k++) {1001dominator = common_dominator(dominator, pred->pred_at(k));1002}1003} else {1004dominator = common_dominator(dominator, pred);1005}1006}10071008if (dominator != block->dominator()) {1009TRACE_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()));10101011block->set_dominator(dominator);1012changed = true;1013}1014}1015return changed;1016}10171018void ComputeLinearScanOrder::compute_dominators() {1019TRACE_LINEAR_SCAN(3, tty->print_cr("----- computing dominators (iterative computation reqired: %d)", _iterative_dominators));10201021// iterative computation of dominators is only required for methods with non-natural loops1022// and OSR-methods. For all other methods, the dominators computed when generating the1023// linear scan block order are correct.1024if (_iterative_dominators) {1025do {1026TRACE_LINEAR_SCAN(1, tty->print_cr("DOM: next iteration of fix-point calculation"));1027} while (compute_dominators_iter());1028}10291030// check that dominators are correct1031assert(!compute_dominators_iter(), "fix point not reached");10321033// Add Blocks to dominates-Array1034int num_blocks = _linear_scan_order->length();1035for (int i = 0; i < num_blocks; i++) {1036BlockBegin* block = _linear_scan_order->at(i);10371038BlockBegin *dom = block->dominator();1039if (dom) {1040assert(dom->dominator_depth() != -1, "Dominator must have been visited before");1041dom->dominates()->append(block);1042block->set_dominator_depth(dom->dominator_depth() + 1);1043} else {1044block->set_dominator_depth(0);1045}1046}1047}104810491050#ifdef ASSERT1051void ComputeLinearScanOrder::print_blocks() {1052if (TraceLinearScanLevel >= 2) {1053tty->print_cr("----- loop information:");1054for (int block_idx = 0; block_idx < _linear_scan_order->length(); block_idx++) {1055BlockBegin* cur = _linear_scan_order->at(block_idx);10561057tty->print("%4d: B%2d: ", cur->linear_scan_number(), cur->block_id());1058for (int loop_idx = 0; loop_idx < _num_loops; loop_idx++) {1059tty->print ("%d ", is_block_in_loop(loop_idx, cur));1060}1061tty->print_cr(" -> loop_index: %2d, loop_depth: %2d", cur->loop_index(), cur->loop_depth());1062}1063}10641065if (TraceLinearScanLevel >= 1) {1066tty->print_cr("----- linear-scan block order:");1067for (int block_idx = 0; block_idx < _linear_scan_order->length(); block_idx++) {1068BlockBegin* cur = _linear_scan_order->at(block_idx);1069tty->print("%4d: B%2d loop: %2d depth: %2d", cur->linear_scan_number(), cur->block_id(), cur->loop_index(), cur->loop_depth());10701071tty->print(cur->is_set(BlockBegin::exception_entry_flag) ? " ex" : " ");1072tty->print(cur->is_set(BlockBegin::critical_edge_split_flag) ? " ce" : " ");1073tty->print(cur->is_set(BlockBegin::linear_scan_loop_header_flag) ? " lh" : " ");1074tty->print(cur->is_set(BlockBegin::linear_scan_loop_end_flag) ? " le" : " ");10751076if (cur->dominator() != NULL) {1077tty->print(" dom: B%d ", cur->dominator()->block_id());1078} else {1079tty->print(" dom: NULL ");1080}10811082if (cur->number_of_preds() > 0) {1083tty->print(" preds: ");1084for (int j = 0; j < cur->number_of_preds(); j++) {1085BlockBegin* pred = cur->pred_at(j);1086tty->print("B%d ", pred->block_id());1087}1088}1089if (cur->number_of_sux() > 0) {1090tty->print(" sux: ");1091for (int j = 0; j < cur->number_of_sux(); j++) {1092BlockBegin* sux = cur->sux_at(j);1093tty->print("B%d ", sux->block_id());1094}1095}1096if (cur->number_of_exception_handlers() > 0) {1097tty->print(" ex: ");1098for (int j = 0; j < cur->number_of_exception_handlers(); j++) {1099BlockBegin* ex = cur->exception_handler_at(j);1100tty->print("B%d ", ex->block_id());1101}1102}1103tty->cr();1104}1105}1106}11071108void ComputeLinearScanOrder::verify() {1109assert(_linear_scan_order->length() == _num_blocks, "wrong number of blocks in list");11101111if (StressLinearScan) {1112// blocks are scrambled when StressLinearScan is used1113return;1114}11151116// check that all successors of a block have a higher linear-scan-number1117// and that all predecessors of a block have a lower linear-scan-number1118// (only backward branches of loops are ignored)1119int i;1120for (i = 0; i < _linear_scan_order->length(); i++) {1121BlockBegin* cur = _linear_scan_order->at(i);11221123assert(cur->linear_scan_number() == i, "incorrect linear_scan_number");1124assert(cur->linear_scan_number() >= 0 && cur->linear_scan_number() == _linear_scan_order->find(cur), "incorrect linear_scan_number");11251126int j;1127for (j = cur->number_of_sux() - 1; j >= 0; j--) {1128BlockBegin* sux = cur->sux_at(j);11291130assert(sux->linear_scan_number() >= 0 && sux->linear_scan_number() == _linear_scan_order->find(sux), "incorrect linear_scan_number");1131if (!sux->is_set(BlockBegin::backward_branch_target_flag)) {1132assert(cur->linear_scan_number() < sux->linear_scan_number(), "invalid order");1133}1134if (cur->loop_depth() == sux->loop_depth()) {1135assert(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");1136}1137}11381139for (j = cur->number_of_preds() - 1; j >= 0; j--) {1140BlockBegin* pred = cur->pred_at(j);11411142assert(pred->linear_scan_number() >= 0 && pred->linear_scan_number() == _linear_scan_order->find(pred), "incorrect linear_scan_number");1143if (!cur->is_set(BlockBegin::backward_branch_target_flag)) {1144assert(cur->linear_scan_number() > pred->linear_scan_number(), "invalid order");1145}1146if (cur->loop_depth() == pred->loop_depth()) {1147assert(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");1148}11491150assert(cur->dominator()->linear_scan_number() <= cur->pred_at(j)->linear_scan_number(), "dominator must be before predecessors");1151}11521153// check dominator1154if (i == 0) {1155assert(cur->dominator() == NULL, "first block has no dominator");1156} else {1157assert(cur->dominator() != NULL, "all but first block must have dominator");1158}1159// Assertion does not hold for exception handlers1160assert(cur->number_of_preds() != 1 || cur->dominator() == cur->pred_at(0) || cur->is_set(BlockBegin::exception_entry_flag), "Single predecessor must also be dominator");1161}11621163// check that all loops are continuous1164for (int loop_idx = 0; loop_idx < _num_loops; loop_idx++) {1165int block_idx = 0;1166assert(!is_block_in_loop(loop_idx, _linear_scan_order->at(block_idx)), "the first block must not be present in any loop");11671168// skip blocks before the loop1169while (block_idx < _num_blocks && !is_block_in_loop(loop_idx, _linear_scan_order->at(block_idx))) {1170block_idx++;1171}1172// skip blocks of loop1173while (block_idx < _num_blocks && is_block_in_loop(loop_idx, _linear_scan_order->at(block_idx))) {1174block_idx++;1175}1176// after the first non-loop block, there must not be another loop-block1177while (block_idx < _num_blocks) {1178assert(!is_block_in_loop(loop_idx, _linear_scan_order->at(block_idx)), "loop not continuous in linear-scan order");1179block_idx++;1180}1181}1182}1183#endif // ASSERT118411851186void IR::compute_code() {1187assert(is_valid(), "IR must be valid");11881189ComputeLinearScanOrder compute_order(compilation(), start());1190_num_loops = compute_order.num_loops();1191_code = compute_order.linear_scan_order();1192}119311941195void IR::compute_use_counts() {1196// make sure all values coming out of this block get evaluated.1197int num_blocks = _code->length();1198for (int i = 0; i < num_blocks; i++) {1199_code->at(i)->end()->state()->pin_stack_for_linear_scan();1200}12011202// compute use counts1203UseCountComputer::compute(_code);1204}120512061207void IR::iterate_preorder(BlockClosure* closure) {1208assert(is_valid(), "IR must be valid");1209start()->iterate_preorder(closure);1210}121112121213void IR::iterate_postorder(BlockClosure* closure) {1214assert(is_valid(), "IR must be valid");1215start()->iterate_postorder(closure);1216}12171218void IR::iterate_linear_scan_order(BlockClosure* closure) {1219linear_scan_order()->iterate_forward(closure);1220}122112221223#ifndef PRODUCT1224class BlockPrinter: public BlockClosure {1225private:1226InstructionPrinter* _ip;1227bool _cfg_only;1228bool _live_only;12291230public:1231BlockPrinter(InstructionPrinter* ip, bool cfg_only, bool live_only = false) {1232_ip = ip;1233_cfg_only = cfg_only;1234_live_only = live_only;1235}12361237virtual void block_do(BlockBegin* block) {1238if (_cfg_only) {1239_ip->print_instr(block); tty->cr();1240} else {1241block->print_block(*_ip, _live_only);1242}1243}1244};124512461247void IR::print(BlockBegin* start, bool cfg_only, bool live_only) {1248ttyLocker ttyl;1249InstructionPrinter ip(!cfg_only);1250BlockPrinter bp(&ip, cfg_only, live_only);1251start->iterate_preorder(&bp);1252tty->cr();1253}12541255void IR::print(bool cfg_only, bool live_only) {1256if (is_valid()) {1257print(start(), cfg_only, live_only);1258} else {1259tty->print_cr("invalid IR");1260}1261}126212631264typedef GrowableArray<BlockList*> BlockListList;12651266class PredecessorValidator : public BlockClosure {1267private:1268BlockListList* _predecessors;1269BlockList* _blocks;12701271static int cmp(BlockBegin** a, BlockBegin** b) {1272return (*a)->block_id() - (*b)->block_id();1273}12741275public:1276PredecessorValidator(IR* hir) {1277ResourceMark rm;1278_predecessors = new BlockListList(BlockBegin::number_of_blocks(), BlockBegin::number_of_blocks(), NULL);1279_blocks = new BlockList();12801281int i;1282hir->start()->iterate_preorder(this);1283if (hir->code() != NULL) {1284assert(hir->code()->length() == _blocks->length(), "must match");1285for (i = 0; i < _blocks->length(); i++) {1286assert(hir->code()->contains(_blocks->at(i)), "should be in both lists");1287}1288}12891290for (i = 0; i < _blocks->length(); i++) {1291BlockBegin* block = _blocks->at(i);1292BlockList* preds = _predecessors->at(block->block_id());1293if (preds == NULL) {1294assert(block->number_of_preds() == 0, "should be the same");1295continue;1296}12971298// clone the pred list so we can mutate it1299BlockList* pred_copy = new BlockList();1300int j;1301for (j = 0; j < block->number_of_preds(); j++) {1302pred_copy->append(block->pred_at(j));1303}1304// sort them in the same order1305preds->sort(cmp);1306pred_copy->sort(cmp);1307int length = MIN2(preds->length(), block->number_of_preds());1308for (j = 0; j < block->number_of_preds(); j++) {1309assert(preds->at(j) == pred_copy->at(j), "must match");1310}13111312assert(preds->length() == block->number_of_preds(), "should be the same");1313}1314}13151316virtual void block_do(BlockBegin* block) {1317_blocks->append(block);1318BlockEnd* be = block->end();1319int n = be->number_of_sux();1320int i;1321for (i = 0; i < n; i++) {1322BlockBegin* sux = be->sux_at(i);1323assert(!sux->is_set(BlockBegin::exception_entry_flag), "must not be xhandler");13241325BlockList* preds = _predecessors->at_grow(sux->block_id(), NULL);1326if (preds == NULL) {1327preds = new BlockList();1328_predecessors->at_put(sux->block_id(), preds);1329}1330preds->append(block);1331}13321333n = block->number_of_exception_handlers();1334for (i = 0; i < n; i++) {1335BlockBegin* sux = block->exception_handler_at(i);1336assert(sux->is_set(BlockBegin::exception_entry_flag), "must be xhandler");13371338BlockList* preds = _predecessors->at_grow(sux->block_id(), NULL);1339if (preds == NULL) {1340preds = new BlockList();1341_predecessors->at_put(sux->block_id(), preds);1342}1343preds->append(block);1344}1345}1346};13471348class VerifyBlockBeginField : public BlockClosure {13491350public:13511352virtual void block_do(BlockBegin *block) {1353for ( Instruction *cur = block; cur != NULL; cur = cur->next()) {1354assert(cur->block() == block, "Block begin is not correct");1355}1356}1357};13581359void IR::verify() {1360#ifdef ASSERT1361PredecessorValidator pv(this);1362VerifyBlockBeginField verifier;1363this->iterate_postorder(&verifier);1364#endif1365}13661367#endif // PRODUCT13681369void SubstitutionResolver::visit(Value* v) {1370Value v0 = *v;1371if (v0) {1372Value vs = v0->subst();1373if (vs != v0) {1374*v = v0->subst();1375}1376}1377}13781379#ifdef ASSERT1380class SubstitutionChecker: public ValueVisitor {1381void visit(Value* v) {1382Value v0 = *v;1383if (v0) {1384Value vs = v0->subst();1385assert(vs == v0, "missed substitution");1386}1387}1388};1389#endif139013911392void SubstitutionResolver::block_do(BlockBegin* block) {1393Instruction* last = NULL;1394for (Instruction* n = block; n != NULL;) {1395n->values_do(this);1396// need to remove this instruction from the instruction stream1397if (n->subst() != n) {1398guarantee(last != NULL, "must have last");1399last->set_next(n->next());1400} else {1401last = n;1402}1403n = last->next();1404}14051406#ifdef ASSERT1407SubstitutionChecker check_substitute;1408if (block->state()) block->state()->values_do(&check_substitute);1409block->block_values_do(&check_substitute);1410if (block->end() && block->end()->state()) block->end()->state()->values_do(&check_substitute);1411#endif1412}141314141415