Path: blob/jdk8u272-b10-aarch32-20201026/hotspot/src/share/vm/c1/c1_IR.cpp
83404 views
/*1* Copyright (c) 1999, 2013, 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 "utilities/bitMap.inline.hpp"323334// Implementation of XHandlers35//36// Note: This code could eventually go away if we are37// just using the ciExceptionHandlerStream.3839XHandlers::XHandlers(ciMethod* method) : _list(method->exception_table_length()) {40ciExceptionHandlerStream s(method);41while (!s.is_done()) {42_list.append(new XHandler(s.handler()));43s.next();44}45assert(s.count() == method->exception_table_length(), "exception table lengths inconsistent");46}4748// deep copy of all XHandler contained in list49XHandlers::XHandlers(XHandlers* other) :50_list(other->length())51{52for (int i = 0; i < other->length(); i++) {53_list.append(new XHandler(other->handler_at(i)));54}55}5657// Returns whether a particular exception type can be caught. Also58// returns true if klass is unloaded or any exception handler59// classes are unloaded. type_is_exact indicates whether the throw60// is known to be exactly that class or it might throw a subtype.61bool XHandlers::could_catch(ciInstanceKlass* klass, bool type_is_exact) const {62// the type is unknown so be conservative63if (!klass->is_loaded()) {64return true;65}6667for (int i = 0; i < length(); i++) {68XHandler* handler = handler_at(i);69if (handler->is_catch_all()) {70// catch of ANY71return true;72}73ciInstanceKlass* handler_klass = handler->catch_klass();74// if it's unknown it might be catchable75if (!handler_klass->is_loaded()) {76return true;77}78// if the throw type is definitely a subtype of the catch type79// then it can be caught.80if (klass->is_subtype_of(handler_klass)) {81return true;82}83if (!type_is_exact) {84// If the type isn't exactly known then it can also be caught by85// catch statements where the inexact type is a subtype of the86// catch type.87// given: foo extends bar extends Exception88// throw bar can be caught by catch foo, catch bar, and catch89// Exception, however it can't be caught by any handlers without90// bar in its type hierarchy.91if (handler_klass->is_subtype_of(klass)) {92return true;93}94}95}9697return false;98}99100101bool XHandlers::equals(XHandlers* others) const {102if (others == NULL) return false;103if (length() != others->length()) return false;104105for (int i = 0; i < length(); i++) {106if (!handler_at(i)->equals(others->handler_at(i))) return false;107}108return true;109}110111bool XHandler::equals(XHandler* other) const {112assert(entry_pco() != -1 && other->entry_pco() != -1, "must have entry_pco");113114if (entry_pco() != other->entry_pco()) return false;115if (scope_count() != other->scope_count()) return false;116if (_desc != other->_desc) return false;117118assert(entry_block() == other->entry_block(), "entry_block must be equal when entry_pco is equal");119return true;120}121122123// Implementation of IRScope124BlockBegin* IRScope::build_graph(Compilation* compilation, int osr_bci) {125GraphBuilder gm(compilation, this);126NOT_PRODUCT(if (PrintValueNumbering && Verbose) gm.print_stats());127if (compilation->bailed_out()) return NULL;128return gm.start();129}130131132IRScope::IRScope(Compilation* compilation, IRScope* caller, int caller_bci, ciMethod* method, int osr_bci, bool create_graph)133: _callees(2)134, _compilation(compilation)135, _requires_phi_function(method->max_locals())136{137_caller = caller;138_level = caller == NULL ? 0 : caller->level() + 1;139_method = method;140_xhandlers = new XHandlers(method);141_number_of_locks = 0;142_monitor_pairing_ok = method->has_balanced_monitors();143_wrote_final = false;144_start = NULL;145146if (osr_bci == -1) {147_requires_phi_function.clear();148} else {149// selective creation of phi functions is not possibel in osr-methods150_requires_phi_function.set_range(0, method->max_locals());151}152153assert(method->holder()->is_loaded() , "method holder must be loaded");154155// build graph if monitor pairing is ok156if (create_graph && monitor_pairing_ok()) _start = build_graph(compilation, osr_bci);157}158159160int IRScope::max_stack() const {161int my_max = method()->max_stack();162int callee_max = 0;163for (int i = 0; i < number_of_callees(); i++) {164callee_max = MAX2(callee_max, callee_no(i)->max_stack());165}166return my_max + callee_max;167}168169170bool IRScopeDebugInfo::should_reexecute() {171ciMethod* cur_method = scope()->method();172int cur_bci = bci();173if (cur_method != NULL && cur_bci != SynchronizationEntryBCI) {174Bytecodes::Code code = cur_method->java_code_at_bci(cur_bci);175return Interpreter::bytecode_should_reexecute(code);176} else177return false;178}179180181// Implementation of CodeEmitInfo182183// Stack must be NON-null184CodeEmitInfo::CodeEmitInfo(ValueStack* stack, XHandlers* exception_handlers, bool deoptimize_on_exception)185: _scope(stack->scope())186, _scope_debug_info(NULL)187, _oop_map(NULL)188, _stack(stack)189, _exception_handlers(exception_handlers)190, _is_method_handle_invoke(false)191, _deoptimize_on_exception(deoptimize_on_exception) {192assert(_stack != NULL, "must be non null");193}194195196CodeEmitInfo::CodeEmitInfo(CodeEmitInfo* info, ValueStack* stack)197: _scope(info->_scope)198, _exception_handlers(NULL)199, _scope_debug_info(NULL)200, _oop_map(NULL)201, _stack(stack == NULL ? info->_stack : stack)202, _is_method_handle_invoke(info->_is_method_handle_invoke)203, _deoptimize_on_exception(info->_deoptimize_on_exception) {204205// deep copy of exception handlers206if (info->_exception_handlers != NULL) {207_exception_handlers = new XHandlers(info->_exception_handlers);208}209}210211212void CodeEmitInfo::record_debug_info(DebugInformationRecorder* recorder, int pc_offset) {213// record the safepoint before recording the debug info for enclosing scopes214recorder->add_safepoint(pc_offset, _oop_map->deep_copy());215_scope_debug_info->record_debug_info(recorder, pc_offset, true/*topmost*/, _is_method_handle_invoke);216recorder->end_safepoint(pc_offset);217}218219220void CodeEmitInfo::add_register_oop(LIR_Opr opr) {221assert(_oop_map != NULL, "oop map must already exist");222assert(opr->is_single_cpu(), "should not call otherwise");223224VMReg name = frame_map()->regname(opr);225_oop_map->set_oop(name);226}227228// Mirror the stack size calculation in the deopt code229// How much stack space would we need at this point in the program in230// case of deoptimization?231int CodeEmitInfo::interpreter_frame_size() const {232ValueStack* state = _stack;233int size = 0;234int callee_parameters = 0;235int callee_locals = 0;236int extra_args = state->scope()->method()->max_stack() - state->stack_size();237238while (state != NULL) {239int locks = state->locks_size();240int temps = state->stack_size();241bool is_top_frame = (state == _stack);242ciMethod* method = state->scope()->method();243244int frame_size = BytesPerWord * Interpreter::size_activation(method->max_stack(),245temps + callee_parameters,246extra_args,247locks,248callee_parameters,249callee_locals,250is_top_frame);251size += frame_size;252253callee_parameters = method->size_of_parameters();254callee_locals = method->max_locals();255extra_args = 0;256state = state->caller_state();257}258return size + Deoptimization::last_frame_adjust(0, callee_locals) * BytesPerWord;259}260261// Implementation of IR262263IR::IR(Compilation* compilation, ciMethod* method, int osr_bci) :264_locals_size(in_WordSize(-1))265, _num_loops(0) {266// setup IR fields267_compilation = compilation;268_top_scope = new IRScope(compilation, NULL, -1, method, osr_bci, true);269_code = NULL;270}271272273void IR::optimize_blocks() {274Optimizer opt(this);275if (!compilation()->profile_branches()) {276if (DoCEE) {277opt.eliminate_conditional_expressions();278#ifndef PRODUCT279if (PrintCFG || PrintCFG1) { tty->print_cr("CFG after CEE"); print(true); }280if (PrintIR || PrintIR1 ) { tty->print_cr("IR after CEE"); print(false); }281#endif282}283if (EliminateBlocks) {284opt.eliminate_blocks();285#ifndef PRODUCT286if (PrintCFG || PrintCFG1) { tty->print_cr("CFG after block elimination"); print(true); }287if (PrintIR || PrintIR1 ) { tty->print_cr("IR after block elimination"); print(false); }288#endif289}290}291}292293void IR::eliminate_null_checks() {294Optimizer opt(this);295if (EliminateNullChecks) {296opt.eliminate_null_checks();297#ifndef PRODUCT298if (PrintCFG || PrintCFG1) { tty->print_cr("CFG after null check elimination"); print(true); }299if (PrintIR || PrintIR1 ) { tty->print_cr("IR after null check elimination"); print(false); }300#endif301}302}303304305static int sort_pairs(BlockPair** a, BlockPair** b) {306if ((*a)->from() == (*b)->from()) {307return (*a)->to()->block_id() - (*b)->to()->block_id();308} else {309return (*a)->from()->block_id() - (*b)->from()->block_id();310}311}312313314class CriticalEdgeFinder: public BlockClosure {315BlockPairList blocks;316IR* _ir;317318public:319CriticalEdgeFinder(IR* ir): _ir(ir) {}320void block_do(BlockBegin* bb) {321BlockEnd* be = bb->end();322int nos = be->number_of_sux();323if (nos >= 2) {324for (int i = 0; i < nos; i++) {325BlockBegin* sux = be->sux_at(i);326if (sux->number_of_preds() >= 2) {327blocks.append(new BlockPair(bb, sux));328}329}330}331}332333void split_edges() {334BlockPair* last_pair = NULL;335blocks.sort(sort_pairs);336for (int i = 0; i < blocks.length(); i++) {337BlockPair* pair = blocks.at(i);338if (last_pair != NULL && pair->is_same(last_pair)) continue;339BlockBegin* from = pair->from();340BlockBegin* to = pair->to();341BlockBegin* split = from->insert_block_between(to);342#ifndef PRODUCT343if ((PrintIR || PrintIR1) && Verbose) {344tty->print_cr("Split critical edge B%d -> B%d (new block B%d)",345from->block_id(), to->block_id(), split->block_id());346}347#endif348last_pair = pair;349}350}351};352353void IR::split_critical_edges() {354CriticalEdgeFinder cef(this);355356iterate_preorder(&cef);357cef.split_edges();358}359360361class UseCountComputer: public ValueVisitor, BlockClosure {362private:363void visit(Value* n) {364// Local instructions and Phis for expression stack values at the365// start of basic blocks are not added to the instruction list366if (!(*n)->is_linked() && (*n)->can_be_linked()) {367assert(false, "a node was not appended to the graph");368Compilation::current()->bailout("a node was not appended to the graph");369}370// use n's input if not visited before371if (!(*n)->is_pinned() && !(*n)->has_uses()) {372// note: a) if the instruction is pinned, it will be handled by compute_use_count373// b) if the instruction has uses, it was touched before374// => in both cases we don't need to update n's values375uses_do(n);376}377// use n378(*n)->_use_count++;379}380381Values* worklist;382int depth;383enum {384max_recurse_depth = 20385};386387void uses_do(Value* n) {388depth++;389if (depth > max_recurse_depth) {390// don't allow the traversal to recurse too deeply391worklist->push(*n);392} else {393(*n)->input_values_do(this);394// special handling for some instructions395if ((*n)->as_BlockEnd() != NULL) {396// note on BlockEnd:397// must 'use' the stack only if the method doesn't398// terminate, however, in those cases stack is empty399(*n)->state_values_do(this);400}401}402depth--;403}404405void block_do(BlockBegin* b) {406depth = 0;407// process all pinned nodes as the roots of expression trees408for (Instruction* n = b; n != NULL; n = n->next()) {409if (n->is_pinned()) uses_do(&n);410}411assert(depth == 0, "should have counted back down");412413// now process any unpinned nodes which recursed too deeply414while (worklist->length() > 0) {415Value t = worklist->pop();416if (!t->is_pinned()) {417// compute the use count418uses_do(&t);419420// pin the instruction so that LIRGenerator doesn't recurse421// too deeply during it's evaluation.422t->pin();423}424}425assert(depth == 0, "should have counted back down");426}427428UseCountComputer() {429worklist = new Values();430depth = 0;431}432433public:434static void compute(BlockList* blocks) {435UseCountComputer ucc;436blocks->iterate_backward(&ucc);437}438};439440441// helper macro for short definition of trace-output inside code442#ifndef PRODUCT443#define TRACE_LINEAR_SCAN(level, code) \444if (TraceLinearScanLevel >= level) { \445code; \446}447#else448#define TRACE_LINEAR_SCAN(level, code)449#endif450451class ComputeLinearScanOrder : public StackObj {452private:453int _max_block_id; // the highest block_id of a block454int _num_blocks; // total number of blocks (smaller than _max_block_id)455int _num_loops; // total number of loops456bool _iterative_dominators;// method requires iterative computation of dominatiors457458BlockList* _linear_scan_order; // the resulting list of blocks in correct order459460BitMap _visited_blocks; // used for recursive processing of blocks461BitMap _active_blocks; // used for recursive processing of blocks462BitMap _dominator_blocks; // temproary BitMap used for computation of dominator463intArray _forward_branches; // number of incoming forward branches for each block464BlockList _loop_end_blocks; // list of all loop end blocks collected during count_edges465BitMap2D _loop_map; // two-dimensional bit set: a bit is set if a block is contained in a loop466BlockList _work_list; // temporary list (used in mark_loops and compute_order)467BlockList _loop_headers;468469Compilation* _compilation;470471// accessors for _visited_blocks and _active_blocks472void init_visited() { _active_blocks.clear(); _visited_blocks.clear(); }473bool is_visited(BlockBegin* b) const { return _visited_blocks.at(b->block_id()); }474bool is_active(BlockBegin* b) const { return _active_blocks.at(b->block_id()); }475void set_visited(BlockBegin* b) { assert(!is_visited(b), "already set"); _visited_blocks.set_bit(b->block_id()); }476void set_active(BlockBegin* b) { assert(!is_active(b), "already set"); _active_blocks.set_bit(b->block_id()); }477void clear_active(BlockBegin* b) { assert(is_active(b), "not already"); _active_blocks.clear_bit(b->block_id()); }478479// accessors for _forward_branches480void inc_forward_branches(BlockBegin* b) { _forward_branches.at_put(b->block_id(), _forward_branches.at(b->block_id()) + 1); }481int 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()); }482483// accessors for _loop_map484bool is_block_in_loop (int loop_idx, BlockBegin* b) const { return _loop_map.at(loop_idx, b->block_id()); }485void set_block_in_loop (int loop_idx, BlockBegin* b) { _loop_map.set_bit(loop_idx, b->block_id()); }486void clear_block_in_loop(int loop_idx, int block_id) { _loop_map.clear_bit(loop_idx, block_id); }487488// count edges between blocks489void count_edges(BlockBegin* cur, BlockBegin* parent);490491// loop detection492void mark_loops();493void clear_non_natural_loops(BlockBegin* start_block);494void assign_loop_depth(BlockBegin* start_block);495496// computation of final block order497BlockBegin* common_dominator(BlockBegin* a, BlockBegin* b);498void compute_dominator(BlockBegin* cur, BlockBegin* parent);499int compute_weight(BlockBegin* cur);500bool ready_for_processing(BlockBegin* cur);501void sort_into_work_list(BlockBegin* b);502void append_block(BlockBegin* cur);503void compute_order(BlockBegin* start_block);504505// fixup of dominators for non-natural loops506bool compute_dominators_iter();507void compute_dominators();508509// debug functions510NOT_PRODUCT(void print_blocks();)511DEBUG_ONLY(void verify();)512513Compilation* compilation() const { return _compilation; }514public:515ComputeLinearScanOrder(Compilation* c, BlockBegin* start_block);516517// accessors for final result518BlockList* linear_scan_order() const { return _linear_scan_order; }519int num_loops() const { return _num_loops; }520};521522523ComputeLinearScanOrder::ComputeLinearScanOrder(Compilation* c, BlockBegin* start_block) :524_max_block_id(BlockBegin::number_of_blocks()),525_num_blocks(0),526_num_loops(0),527_iterative_dominators(false),528_visited_blocks(_max_block_id),529_active_blocks(_max_block_id),530_dominator_blocks(_max_block_id),531_forward_branches(_max_block_id, 0),532_loop_end_blocks(8),533_work_list(8),534_linear_scan_order(NULL), // initialized later with correct size535_loop_map(0, 0), // initialized later with correct size536_compilation(c)537{538TRACE_LINEAR_SCAN(2, tty->print_cr("***** computing linear-scan block order"));539540init_visited();541count_edges(start_block, NULL);542543if (compilation()->is_profiling()) {544ciMethod *method = compilation()->method();545if (!method->is_accessor()) {546ciMethodData* md = method->method_data_or_null();547assert(md != NULL, "Sanity");548md->set_compilation_stats(_num_loops, _num_blocks);549}550}551552if (_num_loops > 0) {553mark_loops();554clear_non_natural_loops(start_block);555assign_loop_depth(start_block);556}557558compute_order(start_block);559compute_dominators();560561NOT_PRODUCT(print_blocks());562DEBUG_ONLY(verify());563}564565566// Traverse the CFG:567// * count total number of blocks568// * count all incoming edges and backward incoming edges569// * number loop header blocks570// * create a list with all loop end blocks571void ComputeLinearScanOrder::count_edges(BlockBegin* cur, BlockBegin* parent) {572TRACE_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));573assert(cur->dominator() == NULL, "dominator already initialized");574575if (is_active(cur)) {576TRACE_LINEAR_SCAN(3, tty->print_cr("backward branch"));577assert(is_visited(cur), "block must be visisted when block is active");578assert(parent != NULL, "must have parent");579580cur->set(BlockBegin::linear_scan_loop_header_flag);581cur->set(BlockBegin::backward_branch_target_flag);582583parent->set(BlockBegin::linear_scan_loop_end_flag);584585// When a loop header is also the start of an exception handler, then the backward branch is586// an exception edge. Because such edges are usually critical edges which cannot be split, the587// loop must be excluded here from processing.588if (cur->is_set(BlockBegin::exception_entry_flag)) {589// Make sure that dominators are correct in this weird situation590_iterative_dominators = true;591return;592}593assert(parent->number_of_sux() == 1 && parent->sux_at(0) == cur,594"loop end blocks must have one successor (critical edges are split)");595596_loop_end_blocks.append(parent);597return;598}599600// increment number of incoming forward branches601inc_forward_branches(cur);602603if (is_visited(cur)) {604TRACE_LINEAR_SCAN(3, tty->print_cr("block already visited"));605return;606}607608_num_blocks++;609set_visited(cur);610set_active(cur);611612// recursive call for all successors613int i;614for (i = cur->number_of_sux() - 1; i >= 0; i--) {615count_edges(cur->sux_at(i), cur);616}617for (i = cur->number_of_exception_handlers() - 1; i >= 0; i--) {618count_edges(cur->exception_handler_at(i), cur);619}620621clear_active(cur);622623// Each loop has a unique number.624// When multiple loops are nested, assign_loop_depth assumes that the625// innermost loop has the lowest number. This is guaranteed by setting626// the loop number after the recursive calls for the successors above627// have returned.628if (cur->is_set(BlockBegin::linear_scan_loop_header_flag)) {629assert(cur->loop_index() == -1, "cannot set loop-index twice");630TRACE_LINEAR_SCAN(3, tty->print_cr("Block B%d is loop header of loop %d", cur->block_id(), _num_loops));631632cur->set_loop_index(_num_loops);633_loop_headers.append(cur);634_num_loops++;635}636637TRACE_LINEAR_SCAN(3, tty->print_cr("Finished count_edges for block B%d", cur->block_id()));638}639640641void ComputeLinearScanOrder::mark_loops() {642TRACE_LINEAR_SCAN(3, tty->print_cr("----- marking loops"));643644_loop_map = BitMap2D(_num_loops, _max_block_id);645_loop_map.clear();646647for (int i = _loop_end_blocks.length() - 1; i >= 0; i--) {648BlockBegin* loop_end = _loop_end_blocks.at(i);649BlockBegin* loop_start = loop_end->sux_at(0);650int loop_idx = loop_start->loop_index();651652TRACE_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));653assert(loop_end->is_set(BlockBegin::linear_scan_loop_end_flag), "loop end flag must be set");654assert(loop_end->number_of_sux() == 1, "incorrect number of successors");655assert(loop_start->is_set(BlockBegin::linear_scan_loop_header_flag), "loop header flag must be set");656assert(loop_idx >= 0 && loop_idx < _num_loops, "loop index not set");657assert(_work_list.is_empty(), "work list must be empty before processing");658659// add the end-block of the loop to the working list660_work_list.push(loop_end);661set_block_in_loop(loop_idx, loop_end);662do {663BlockBegin* cur = _work_list.pop();664665TRACE_LINEAR_SCAN(3, tty->print_cr(" processing B%d", cur->block_id()));666assert(is_block_in_loop(loop_idx, cur), "bit in loop map must be set when block is in work list");667668// recursive processing of all predecessors ends when start block of loop is reached669if (cur != loop_start && !cur->is_set(BlockBegin::osr_entry_flag)) {670for (int j = cur->number_of_preds() - 1; j >= 0; j--) {671BlockBegin* pred = cur->pred_at(j);672673if (!is_block_in_loop(loop_idx, pred) /*&& !pred->is_set(BlockBeginosr_entry_flag)*/) {674// this predecessor has not been processed yet, so add it to work list675TRACE_LINEAR_SCAN(3, tty->print_cr(" pushing B%d", pred->block_id()));676_work_list.push(pred);677set_block_in_loop(loop_idx, pred);678}679}680}681} while (!_work_list.is_empty());682}683}684685686// check for non-natural loops (loops where the loop header does not dominate687// all other loop blocks = loops with mulitple entries).688// such loops are ignored689void ComputeLinearScanOrder::clear_non_natural_loops(BlockBegin* start_block) {690for (int i = _num_loops - 1; i >= 0; i--) {691if (is_block_in_loop(i, start_block)) {692// loop i contains the entry block of the method693// -> this is not a natural loop, so ignore it694TRACE_LINEAR_SCAN(2, tty->print_cr("Loop %d is non-natural, so it is ignored", i));695696BlockBegin *loop_header = _loop_headers.at(i);697assert(loop_header->is_set(BlockBegin::linear_scan_loop_header_flag), "Must be loop header");698699for (int j = 0; j < loop_header->number_of_preds(); j++) {700BlockBegin *pred = loop_header->pred_at(j);701pred->clear(BlockBegin::linear_scan_loop_end_flag);702}703704loop_header->clear(BlockBegin::linear_scan_loop_header_flag);705706for (int block_id = _max_block_id - 1; block_id >= 0; block_id--) {707clear_block_in_loop(i, block_id);708}709_iterative_dominators = true;710}711}712}713714void ComputeLinearScanOrder::assign_loop_depth(BlockBegin* start_block) {715TRACE_LINEAR_SCAN(3, tty->print_cr("----- computing loop-depth and weight"));716init_visited();717718assert(_work_list.is_empty(), "work list must be empty before processing");719_work_list.append(start_block);720721do {722BlockBegin* cur = _work_list.pop();723724if (!is_visited(cur)) {725set_visited(cur);726TRACE_LINEAR_SCAN(4, tty->print_cr("Computing loop depth for block B%d", cur->block_id()));727728// compute loop-depth and loop-index for the block729assert(cur->loop_depth() == 0, "cannot set loop-depth twice");730int i;731int loop_depth = 0;732int min_loop_idx = -1;733for (i = _num_loops - 1; i >= 0; i--) {734if (is_block_in_loop(i, cur)) {735loop_depth++;736min_loop_idx = i;737}738}739cur->set_loop_depth(loop_depth);740cur->set_loop_index(min_loop_idx);741742// append all unvisited successors to work list743for (i = cur->number_of_sux() - 1; i >= 0; i--) {744_work_list.append(cur->sux_at(i));745}746for (i = cur->number_of_exception_handlers() - 1; i >= 0; i--) {747_work_list.append(cur->exception_handler_at(i));748}749}750} while (!_work_list.is_empty());751}752753754BlockBegin* ComputeLinearScanOrder::common_dominator(BlockBegin* a, BlockBegin* b) {755assert(a != NULL && b != NULL, "must have input blocks");756757_dominator_blocks.clear();758while (a != NULL) {759_dominator_blocks.set_bit(a->block_id());760assert(a->dominator() != NULL || a == _linear_scan_order->at(0), "dominator must be initialized");761a = a->dominator();762}763while (b != NULL && !_dominator_blocks.at(b->block_id())) {764assert(b->dominator() != NULL || b == _linear_scan_order->at(0), "dominator must be initialized");765b = b->dominator();766}767768assert(b != NULL, "could not find dominator");769return b;770}771772void ComputeLinearScanOrder::compute_dominator(BlockBegin* cur, BlockBegin* parent) {773if (cur->dominator() == NULL) {774TRACE_LINEAR_SCAN(4, tty->print_cr("DOM: initializing dominator of B%d to B%d", cur->block_id(), parent->block_id()));775cur->set_dominator(parent);776777} else if (!(cur->is_set(BlockBegin::linear_scan_loop_header_flag) && parent->is_set(BlockBegin::linear_scan_loop_end_flag))) {778TRACE_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()));779// Does not hold for exception blocks780assert(cur->number_of_preds() > 1 || cur->is_set(BlockBegin::exception_entry_flag), "");781cur->set_dominator(common_dominator(cur->dominator(), parent));782}783784// Additional edge to xhandler of all our successors785// range check elimination needs that the state at the end of a786// block be valid in every block it dominates so cur must dominate787// the exception handlers of its successors.788int num_cur_xhandler = cur->number_of_exception_handlers();789for (int j = 0; j < num_cur_xhandler; j++) {790BlockBegin* xhandler = cur->exception_handler_at(j);791compute_dominator(xhandler, parent);792}793}794795796int ComputeLinearScanOrder::compute_weight(BlockBegin* cur) {797BlockBegin* single_sux = NULL;798if (cur->number_of_sux() == 1) {799single_sux = cur->sux_at(0);800}801802// limit loop-depth to 15 bit (only for security reason, it will never be so big)803int weight = (cur->loop_depth() & 0x7FFF) << 16;804805// general macro for short definition of weight flags806// the first instance of INC_WEIGHT_IF has the highest priority807int cur_bit = 15;808#define INC_WEIGHT_IF(condition) if ((condition)) { weight |= (1 << cur_bit); } cur_bit--;809810// this is necessery for the (very rare) case that two successing blocks have811// the same loop depth, but a different loop index (can happen for endless loops812// with exception handlers)813INC_WEIGHT_IF(!cur->is_set(BlockBegin::linear_scan_loop_header_flag));814815// loop end blocks (blocks that end with a backward branch) are added816// after all other blocks of the loop.817INC_WEIGHT_IF(!cur->is_set(BlockBegin::linear_scan_loop_end_flag));818819// critical edge split blocks are prefered because than they have a bigger820// proability to be completely empty821INC_WEIGHT_IF(cur->is_set(BlockBegin::critical_edge_split_flag));822823// exceptions should not be thrown in normal control flow, so these blocks824// are added as late as possible825INC_WEIGHT_IF(cur->end()->as_Throw() == NULL && (single_sux == NULL || single_sux->end()->as_Throw() == NULL));826INC_WEIGHT_IF(cur->end()->as_Return() == NULL && (single_sux == NULL || single_sux->end()->as_Return() == NULL));827828// exceptions handlers are added as late as possible829INC_WEIGHT_IF(!cur->is_set(BlockBegin::exception_entry_flag));830831// guarantee that weight is > 0832weight |= 1;833834#undef INC_WEIGHT_IF835assert(cur_bit >= 0, "too many flags");836assert(weight > 0, "weight cannot become negative");837838return weight;839}840841bool ComputeLinearScanOrder::ready_for_processing(BlockBegin* cur) {842// Discount the edge just traveled.843// When the number drops to zero, all forward branches were processed844if (dec_forward_branches(cur) != 0) {845return false;846}847848assert(_linear_scan_order->index_of(cur) == -1, "block already processed (block can be ready only once)");849assert(_work_list.index_of(cur) == -1, "block already in work-list (block can be ready only once)");850return true;851}852853void ComputeLinearScanOrder::sort_into_work_list(BlockBegin* cur) {854assert(_work_list.index_of(cur) == -1, "block already in work list");855856int cur_weight = compute_weight(cur);857858// the linear_scan_number is used to cache the weight of a block859cur->set_linear_scan_number(cur_weight);860861#ifndef PRODUCT862if (StressLinearScan) {863_work_list.insert_before(0, cur);864return;865}866#endif867868_work_list.append(NULL); // provide space for new element869870int insert_idx = _work_list.length() - 1;871while (insert_idx > 0 && _work_list.at(insert_idx - 1)->linear_scan_number() > cur_weight) {872_work_list.at_put(insert_idx, _work_list.at(insert_idx - 1));873insert_idx--;874}875_work_list.at_put(insert_idx, cur);876877TRACE_LINEAR_SCAN(3, tty->print_cr("Sorted B%d into worklist. new worklist:", cur->block_id()));878TRACE_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()));879880#ifdef ASSERT881for (int i = 0; i < _work_list.length(); i++) {882assert(_work_list.at(i)->linear_scan_number() > 0, "weight not set");883assert(i == 0 || _work_list.at(i - 1)->linear_scan_number() <= _work_list.at(i)->linear_scan_number(), "incorrect order in worklist");884}885#endif886}887888void ComputeLinearScanOrder::append_block(BlockBegin* cur) {889TRACE_LINEAR_SCAN(3, tty->print_cr("appending block B%d (weight 0x%6x) to linear-scan order", cur->block_id(), cur->linear_scan_number()));890assert(_linear_scan_order->index_of(cur) == -1, "cannot add the same block twice");891892// currently, the linear scan order and code emit order are equal.893// therefore the linear_scan_number and the weight of a block must also894// be equal.895cur->set_linear_scan_number(_linear_scan_order->length());896_linear_scan_order->append(cur);897}898899void ComputeLinearScanOrder::compute_order(BlockBegin* start_block) {900TRACE_LINEAR_SCAN(3, tty->print_cr("----- computing final block order"));901902// the start block is always the first block in the linear scan order903_linear_scan_order = new BlockList(_num_blocks);904append_block(start_block);905906assert(start_block->end()->as_Base() != NULL, "start block must end with Base-instruction");907BlockBegin* std_entry = ((Base*)start_block->end())->std_entry();908BlockBegin* osr_entry = ((Base*)start_block->end())->osr_entry();909910BlockBegin* sux_of_osr_entry = NULL;911if (osr_entry != NULL) {912// special handling for osr entry:913// ignore the edge between the osr entry and its successor for processing914// the osr entry block is added manually below915assert(osr_entry->number_of_sux() == 1, "osr entry must have exactly one successor");916assert(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");917918sux_of_osr_entry = osr_entry->sux_at(0);919dec_forward_branches(sux_of_osr_entry);920921compute_dominator(osr_entry, start_block);922_iterative_dominators = true;923}924compute_dominator(std_entry, start_block);925926// start processing with standard entry block927assert(_work_list.is_empty(), "list must be empty before processing");928929if (ready_for_processing(std_entry)) {930sort_into_work_list(std_entry);931} else {932assert(false, "the std_entry must be ready for processing (otherwise, the method has no start block)");933}934935do {936BlockBegin* cur = _work_list.pop();937938if (cur == sux_of_osr_entry) {939// the osr entry block is ignored in normal processing, it is never added to the940// work list. Instead, it is added as late as possible manually here.941append_block(osr_entry);942compute_dominator(cur, osr_entry);943}944append_block(cur);945946int i;947int num_sux = cur->number_of_sux();948// changed loop order to get "intuitive" order of if- and else-blocks949for (i = 0; i < num_sux; i++) {950BlockBegin* sux = cur->sux_at(i);951compute_dominator(sux, cur);952if (ready_for_processing(sux)) {953sort_into_work_list(sux);954}955}956num_sux = cur->number_of_exception_handlers();957for (i = 0; i < num_sux; i++) {958BlockBegin* sux = cur->exception_handler_at(i);959if (ready_for_processing(sux)) {960sort_into_work_list(sux);961}962}963} while (_work_list.length() > 0);964}965966967bool ComputeLinearScanOrder::compute_dominators_iter() {968bool changed = false;969int num_blocks = _linear_scan_order->length();970971assert(_linear_scan_order->at(0)->dominator() == NULL, "must not have dominator");972assert(_linear_scan_order->at(0)->number_of_preds() == 0, "must not have predecessors");973for (int i = 1; i < num_blocks; i++) {974BlockBegin* block = _linear_scan_order->at(i);975976BlockBegin* dominator = block->pred_at(0);977int num_preds = block->number_of_preds();978979TRACE_LINEAR_SCAN(4, tty->print_cr("DOM: Processing B%d", block->block_id()));980981for (int j = 0; j < num_preds; j++) {982983BlockBegin *pred = block->pred_at(j);984TRACE_LINEAR_SCAN(4, tty->print_cr(" DOM: Subrocessing B%d", pred->block_id()));985986if (block->is_set(BlockBegin::exception_entry_flag)) {987dominator = common_dominator(dominator, pred);988int num_pred_preds = pred->number_of_preds();989for (int k = 0; k < num_pred_preds; k++) {990dominator = common_dominator(dominator, pred->pred_at(k));991}992} else {993dominator = common_dominator(dominator, pred);994}995}996997if (dominator != block->dominator()) {998TRACE_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()));9991000block->set_dominator(dominator);1001changed = true;1002}1003}1004return changed;1005}10061007void ComputeLinearScanOrder::compute_dominators() {1008TRACE_LINEAR_SCAN(3, tty->print_cr("----- computing dominators (iterative computation reqired: %d)", _iterative_dominators));10091010// iterative computation of dominators is only required for methods with non-natural loops1011// and OSR-methods. For all other methods, the dominators computed when generating the1012// linear scan block order are correct.1013if (_iterative_dominators) {1014do {1015TRACE_LINEAR_SCAN(1, tty->print_cr("DOM: next iteration of fix-point calculation"));1016} while (compute_dominators_iter());1017}10181019// check that dominators are correct1020assert(!compute_dominators_iter(), "fix point not reached");10211022// Add Blocks to dominates-Array1023int num_blocks = _linear_scan_order->length();1024for (int i = 0; i < num_blocks; i++) {1025BlockBegin* block = _linear_scan_order->at(i);10261027BlockBegin *dom = block->dominator();1028if (dom) {1029assert(dom->dominator_depth() != -1, "Dominator must have been visited before");1030dom->dominates()->append(block);1031block->set_dominator_depth(dom->dominator_depth() + 1);1032} else {1033block->set_dominator_depth(0);1034}1035}1036}103710381039#ifndef PRODUCT1040void ComputeLinearScanOrder::print_blocks() {1041if (TraceLinearScanLevel >= 2) {1042tty->print_cr("----- loop information:");1043for (int block_idx = 0; block_idx < _linear_scan_order->length(); block_idx++) {1044BlockBegin* cur = _linear_scan_order->at(block_idx);10451046tty->print("%4d: B%2d: ", cur->linear_scan_number(), cur->block_id());1047for (int loop_idx = 0; loop_idx < _num_loops; loop_idx++) {1048tty->print ("%d ", is_block_in_loop(loop_idx, cur));1049}1050tty->print_cr(" -> loop_index: %2d, loop_depth: %2d", cur->loop_index(), cur->loop_depth());1051}1052}10531054if (TraceLinearScanLevel >= 1) {1055tty->print_cr("----- linear-scan block order:");1056for (int block_idx = 0; block_idx < _linear_scan_order->length(); block_idx++) {1057BlockBegin* cur = _linear_scan_order->at(block_idx);1058tty->print("%4d: B%2d loop: %2d depth: %2d", cur->linear_scan_number(), cur->block_id(), cur->loop_index(), cur->loop_depth());10591060tty->print(cur->is_set(BlockBegin::exception_entry_flag) ? " ex" : " ");1061tty->print(cur->is_set(BlockBegin::critical_edge_split_flag) ? " ce" : " ");1062tty->print(cur->is_set(BlockBegin::linear_scan_loop_header_flag) ? " lh" : " ");1063tty->print(cur->is_set(BlockBegin::linear_scan_loop_end_flag) ? " le" : " ");10641065if (cur->dominator() != NULL) {1066tty->print(" dom: B%d ", cur->dominator()->block_id());1067} else {1068tty->print(" dom: NULL ");1069}10701071if (cur->number_of_preds() > 0) {1072tty->print(" preds: ");1073for (int j = 0; j < cur->number_of_preds(); j++) {1074BlockBegin* pred = cur->pred_at(j);1075tty->print("B%d ", pred->block_id());1076}1077}1078if (cur->number_of_sux() > 0) {1079tty->print(" sux: ");1080for (int j = 0; j < cur->number_of_sux(); j++) {1081BlockBegin* sux = cur->sux_at(j);1082tty->print("B%d ", sux->block_id());1083}1084}1085if (cur->number_of_exception_handlers() > 0) {1086tty->print(" ex: ");1087for (int j = 0; j < cur->number_of_exception_handlers(); j++) {1088BlockBegin* ex = cur->exception_handler_at(j);1089tty->print("B%d ", ex->block_id());1090}1091}1092tty->cr();1093}1094}1095}1096#endif10971098#ifdef ASSERT1099void ComputeLinearScanOrder::verify() {1100assert(_linear_scan_order->length() == _num_blocks, "wrong number of blocks in list");11011102if (StressLinearScan) {1103// blocks are scrambled when StressLinearScan is used1104return;1105}11061107// check that all successors of a block have a higher linear-scan-number1108// and that all predecessors of a block have a lower linear-scan-number1109// (only backward branches of loops are ignored)1110int i;1111for (i = 0; i < _linear_scan_order->length(); i++) {1112BlockBegin* cur = _linear_scan_order->at(i);11131114assert(cur->linear_scan_number() == i, "incorrect linear_scan_number");1115assert(cur->linear_scan_number() >= 0 && cur->linear_scan_number() == _linear_scan_order->index_of(cur), "incorrect linear_scan_number");11161117int j;1118for (j = cur->number_of_sux() - 1; j >= 0; j--) {1119BlockBegin* sux = cur->sux_at(j);11201121assert(sux->linear_scan_number() >= 0 && sux->linear_scan_number() == _linear_scan_order->index_of(sux), "incorrect linear_scan_number");1122if (!sux->is_set(BlockBegin::backward_branch_target_flag)) {1123assert(cur->linear_scan_number() < sux->linear_scan_number(), "invalid order");1124}1125if (cur->loop_depth() == sux->loop_depth()) {1126assert(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");1127}1128}11291130for (j = cur->number_of_preds() - 1; j >= 0; j--) {1131BlockBegin* pred = cur->pred_at(j);11321133assert(pred->linear_scan_number() >= 0 && pred->linear_scan_number() == _linear_scan_order->index_of(pred), "incorrect linear_scan_number");1134if (!cur->is_set(BlockBegin::backward_branch_target_flag)) {1135assert(cur->linear_scan_number() > pred->linear_scan_number(), "invalid order");1136}1137if (cur->loop_depth() == pred->loop_depth()) {1138assert(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");1139}11401141assert(cur->dominator()->linear_scan_number() <= cur->pred_at(j)->linear_scan_number(), "dominator must be before predecessors");1142}11431144// check dominator1145if (i == 0) {1146assert(cur->dominator() == NULL, "first block has no dominator");1147} else {1148assert(cur->dominator() != NULL, "all but first block must have dominator");1149}1150// Assertion does not hold for exception handlers1151assert(cur->number_of_preds() != 1 || cur->dominator() == cur->pred_at(0) || cur->is_set(BlockBegin::exception_entry_flag), "Single predecessor must also be dominator");1152}11531154// check that all loops are continuous1155for (int loop_idx = 0; loop_idx < _num_loops; loop_idx++) {1156int block_idx = 0;1157assert(!is_block_in_loop(loop_idx, _linear_scan_order->at(block_idx)), "the first block must not be present in any loop");11581159// skip blocks before the loop1160while (block_idx < _num_blocks && !is_block_in_loop(loop_idx, _linear_scan_order->at(block_idx))) {1161block_idx++;1162}1163// skip blocks of loop1164while (block_idx < _num_blocks && is_block_in_loop(loop_idx, _linear_scan_order->at(block_idx))) {1165block_idx++;1166}1167// after the first non-loop block, there must not be another loop-block1168while (block_idx < _num_blocks) {1169assert(!is_block_in_loop(loop_idx, _linear_scan_order->at(block_idx)), "loop not continuous in linear-scan order");1170block_idx++;1171}1172}1173}1174#endif117511761177void IR::compute_code() {1178assert(is_valid(), "IR must be valid");11791180ComputeLinearScanOrder compute_order(compilation(), start());1181_num_loops = compute_order.num_loops();1182_code = compute_order.linear_scan_order();1183}118411851186void IR::compute_use_counts() {1187// make sure all values coming out of this block get evaluated.1188int num_blocks = _code->length();1189for (int i = 0; i < num_blocks; i++) {1190_code->at(i)->end()->state()->pin_stack_for_linear_scan();1191}11921193// compute use counts1194UseCountComputer::compute(_code);1195}119611971198void IR::iterate_preorder(BlockClosure* closure) {1199assert(is_valid(), "IR must be valid");1200start()->iterate_preorder(closure);1201}120212031204void IR::iterate_postorder(BlockClosure* closure) {1205assert(is_valid(), "IR must be valid");1206start()->iterate_postorder(closure);1207}12081209void IR::iterate_linear_scan_order(BlockClosure* closure) {1210linear_scan_order()->iterate_forward(closure);1211}121212131214#ifndef PRODUCT1215class BlockPrinter: public BlockClosure {1216private:1217InstructionPrinter* _ip;1218bool _cfg_only;1219bool _live_only;12201221public:1222BlockPrinter(InstructionPrinter* ip, bool cfg_only, bool live_only = false) {1223_ip = ip;1224_cfg_only = cfg_only;1225_live_only = live_only;1226}12271228virtual void block_do(BlockBegin* block) {1229if (_cfg_only) {1230_ip->print_instr(block); tty->cr();1231} else {1232block->print_block(*_ip, _live_only);1233}1234}1235};123612371238void IR::print(BlockBegin* start, bool cfg_only, bool live_only) {1239ttyLocker ttyl;1240InstructionPrinter ip(!cfg_only);1241BlockPrinter bp(&ip, cfg_only, live_only);1242start->iterate_preorder(&bp);1243tty->cr();1244}12451246void IR::print(bool cfg_only, bool live_only) {1247if (is_valid()) {1248print(start(), cfg_only, live_only);1249} else {1250tty->print_cr("invalid IR");1251}1252}125312541255define_array(BlockListArray, BlockList*)1256define_stack(BlockListList, BlockListArray)12571258class PredecessorValidator : public BlockClosure {1259private:1260BlockListList* _predecessors;1261BlockList* _blocks;12621263static int cmp(BlockBegin** a, BlockBegin** b) {1264return (*a)->block_id() - (*b)->block_id();1265}12661267public:1268PredecessorValidator(IR* hir) {1269ResourceMark rm;1270_predecessors = new BlockListList(BlockBegin::number_of_blocks(), NULL);1271_blocks = new BlockList();12721273int i;1274hir->start()->iterate_preorder(this);1275if (hir->code() != NULL) {1276assert(hir->code()->length() == _blocks->length(), "must match");1277for (i = 0; i < _blocks->length(); i++) {1278assert(hir->code()->contains(_blocks->at(i)), "should be in both lists");1279}1280}12811282for (i = 0; i < _blocks->length(); i++) {1283BlockBegin* block = _blocks->at(i);1284BlockList* preds = _predecessors->at(block->block_id());1285if (preds == NULL) {1286assert(block->number_of_preds() == 0, "should be the same");1287continue;1288}12891290// clone the pred list so we can mutate it1291BlockList* pred_copy = new BlockList();1292int j;1293for (j = 0; j < block->number_of_preds(); j++) {1294pred_copy->append(block->pred_at(j));1295}1296// sort them in the same order1297preds->sort(cmp);1298pred_copy->sort(cmp);1299int length = MIN2(preds->length(), block->number_of_preds());1300for (j = 0; j < block->number_of_preds(); j++) {1301assert(preds->at(j) == pred_copy->at(j), "must match");1302}13031304assert(preds->length() == block->number_of_preds(), "should be the same");1305}1306}13071308virtual void block_do(BlockBegin* block) {1309_blocks->append(block);1310BlockEnd* be = block->end();1311int n = be->number_of_sux();1312int i;1313for (i = 0; i < n; i++) {1314BlockBegin* sux = be->sux_at(i);1315assert(!sux->is_set(BlockBegin::exception_entry_flag), "must not be xhandler");13161317BlockList* preds = _predecessors->at_grow(sux->block_id(), NULL);1318if (preds == NULL) {1319preds = new BlockList();1320_predecessors->at_put(sux->block_id(), preds);1321}1322preds->append(block);1323}13241325n = block->number_of_exception_handlers();1326for (i = 0; i < n; i++) {1327BlockBegin* sux = block->exception_handler_at(i);1328assert(sux->is_set(BlockBegin::exception_entry_flag), "must be xhandler");13291330BlockList* preds = _predecessors->at_grow(sux->block_id(), NULL);1331if (preds == NULL) {1332preds = new BlockList();1333_predecessors->at_put(sux->block_id(), preds);1334}1335preds->append(block);1336}1337}1338};13391340class VerifyBlockBeginField : public BlockClosure {13411342public:13431344virtual void block_do(BlockBegin *block) {1345for ( Instruction *cur = block; cur != NULL; cur = cur->next()) {1346assert(cur->block() == block, "Block begin is not correct");1347}1348}1349};13501351void IR::verify() {1352#ifdef ASSERT1353PredecessorValidator pv(this);1354VerifyBlockBeginField verifier;1355this->iterate_postorder(&verifier);1356#endif1357}13581359#endif // PRODUCT13601361void SubstitutionResolver::visit(Value* v) {1362Value v0 = *v;1363if (v0) {1364Value vs = v0->subst();1365if (vs != v0) {1366*v = v0->subst();1367}1368}1369}13701371#ifdef ASSERT1372class SubstitutionChecker: public ValueVisitor {1373void visit(Value* v) {1374Value v0 = *v;1375if (v0) {1376Value vs = v0->subst();1377assert(vs == v0, "missed substitution");1378}1379}1380};1381#endif138213831384void SubstitutionResolver::block_do(BlockBegin* block) {1385Instruction* last = NULL;1386for (Instruction* n = block; n != NULL;) {1387n->values_do(this);1388// need to remove this instruction from the instruction stream1389if (n->subst() != n) {1390assert(last != NULL, "must have last");1391last->set_next(n->next());1392} else {1393last = n;1394}1395n = last->next();1396}13971398#ifdef ASSERT1399SubstitutionChecker check_substitute;1400if (block->state()) block->state()->values_do(&check_substitute);1401block->block_values_do(&check_substitute);1402if (block->end() && block->end()->state()) block->end()->state()->values_do(&check_substitute);1403#endif1404}140514061407