Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/c1/c1_IR.cpp
32285 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::backward_branch_target_flag);581582// When a loop header is also the start of an exception handler, then the backward branch is583// an exception edge. Because such edges are usually critical edges which cannot be split, the584// loop must be excluded here from processing.585if (cur->is_set(BlockBegin::exception_entry_flag)) {586// Make sure that dominators are correct in this weird situation587_iterative_dominators = true;588return;589}590591cur->set(BlockBegin::linear_scan_loop_header_flag);592parent->set(BlockBegin::linear_scan_loop_end_flag);593594assert(parent->number_of_sux() == 1 && parent->sux_at(0) == cur,595"loop end blocks must have one successor (critical edges are split)");596597_loop_end_blocks.append(parent);598return;599}600601// increment number of incoming forward branches602inc_forward_branches(cur);603604if (is_visited(cur)) {605TRACE_LINEAR_SCAN(3, tty->print_cr("block already visited"));606return;607}608609_num_blocks++;610set_visited(cur);611set_active(cur);612613// recursive call for all successors614int i;615for (i = cur->number_of_sux() - 1; i >= 0; i--) {616count_edges(cur->sux_at(i), cur);617}618for (i = cur->number_of_exception_handlers() - 1; i >= 0; i--) {619count_edges(cur->exception_handler_at(i), cur);620}621622clear_active(cur);623624// Each loop has a unique number.625// When multiple loops are nested, assign_loop_depth assumes that the626// innermost loop has the lowest number. This is guaranteed by setting627// the loop number after the recursive calls for the successors above628// have returned.629if (cur->is_set(BlockBegin::linear_scan_loop_header_flag)) {630assert(cur->loop_index() == -1, "cannot set loop-index twice");631TRACE_LINEAR_SCAN(3, tty->print_cr("Block B%d is loop header of loop %d", cur->block_id(), _num_loops));632633cur->set_loop_index(_num_loops);634_loop_headers.append(cur);635_num_loops++;636}637638TRACE_LINEAR_SCAN(3, tty->print_cr("Finished count_edges for block B%d", cur->block_id()));639}640641642void ComputeLinearScanOrder::mark_loops() {643TRACE_LINEAR_SCAN(3, tty->print_cr("----- marking loops"));644645_loop_map = BitMap2D(_num_loops, _max_block_id);646_loop_map.clear();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) {774if (cur->dominator() == NULL) {775TRACE_LINEAR_SCAN(4, tty->print_cr("DOM: initializing dominator of B%d to B%d", cur->block_id(), parent->block_id()));776cur->set_dominator(parent);777778} else if (!(cur->is_set(BlockBegin::linear_scan_loop_header_flag) && parent->is_set(BlockBegin::linear_scan_loop_end_flag))) {779TRACE_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()));780// Does not hold for exception blocks781assert(cur->number_of_preds() > 1 || cur->is_set(BlockBegin::exception_entry_flag), "");782cur->set_dominator(common_dominator(cur->dominator(), parent));783}784785// Additional edge to xhandler of all our successors786// range check elimination needs that the state at the end of a787// block be valid in every block it dominates so cur must dominate788// the exception handlers of its successors.789int num_cur_xhandler = cur->number_of_exception_handlers();790for (int j = 0; j < num_cur_xhandler; j++) {791BlockBegin* xhandler = cur->exception_handler_at(j);792compute_dominator(xhandler, parent);793}794}795796797int ComputeLinearScanOrder::compute_weight(BlockBegin* cur) {798BlockBegin* single_sux = NULL;799if (cur->number_of_sux() == 1) {800single_sux = cur->sux_at(0);801}802803// limit loop-depth to 15 bit (only for security reason, it will never be so big)804int weight = (cur->loop_depth() & 0x7FFF) << 16;805806// general macro for short definition of weight flags807// the first instance of INC_WEIGHT_IF has the highest priority808int cur_bit = 15;809#define INC_WEIGHT_IF(condition) if ((condition)) { weight |= (1 << cur_bit); } cur_bit--;810811// this is necessery for the (very rare) case that two successing blocks have812// the same loop depth, but a different loop index (can happen for endless loops813// with exception handlers)814INC_WEIGHT_IF(!cur->is_set(BlockBegin::linear_scan_loop_header_flag));815816// loop end blocks (blocks that end with a backward branch) are added817// after all other blocks of the loop.818INC_WEIGHT_IF(!cur->is_set(BlockBegin::linear_scan_loop_end_flag));819820// critical edge split blocks are prefered because than they have a bigger821// proability to be completely empty822INC_WEIGHT_IF(cur->is_set(BlockBegin::critical_edge_split_flag));823824// exceptions should not be thrown in normal control flow, so these blocks825// are added as late as possible826INC_WEIGHT_IF(cur->end()->as_Throw() == NULL && (single_sux == NULL || single_sux->end()->as_Throw() == NULL));827INC_WEIGHT_IF(cur->end()->as_Return() == NULL && (single_sux == NULL || single_sux->end()->as_Return() == NULL));828829// exceptions handlers are added as late as possible830INC_WEIGHT_IF(!cur->is_set(BlockBegin::exception_entry_flag));831832// guarantee that weight is > 0833weight |= 1;834835#undef INC_WEIGHT_IF836assert(cur_bit >= 0, "too many flags");837assert(weight > 0, "weight cannot become negative");838839return weight;840}841842bool ComputeLinearScanOrder::ready_for_processing(BlockBegin* cur) {843// Discount the edge just traveled.844// When the number drops to zero, all forward branches were processed845if (dec_forward_branches(cur) != 0) {846return false;847}848849assert(_linear_scan_order->index_of(cur) == -1, "block already processed (block can be ready only once)");850assert(_work_list.index_of(cur) == -1, "block already in work-list (block can be ready only once)");851return true;852}853854void ComputeLinearScanOrder::sort_into_work_list(BlockBegin* cur) {855assert(_work_list.index_of(cur) == -1, "block already in work list");856857int cur_weight = compute_weight(cur);858859// the linear_scan_number is used to cache the weight of a block860cur->set_linear_scan_number(cur_weight);861862#ifndef PRODUCT863if (StressLinearScan) {864_work_list.insert_before(0, cur);865return;866}867#endif868869_work_list.append(NULL); // provide space for new element870871int insert_idx = _work_list.length() - 1;872while (insert_idx > 0 && _work_list.at(insert_idx - 1)->linear_scan_number() > cur_weight) {873_work_list.at_put(insert_idx, _work_list.at(insert_idx - 1));874insert_idx--;875}876_work_list.at_put(insert_idx, cur);877878TRACE_LINEAR_SCAN(3, tty->print_cr("Sorted B%d into worklist. new worklist:", cur->block_id()));879TRACE_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()));880881#ifdef ASSERT882for (int i = 0; i < _work_list.length(); i++) {883assert(_work_list.at(i)->linear_scan_number() > 0, "weight not set");884assert(i == 0 || _work_list.at(i - 1)->linear_scan_number() <= _work_list.at(i)->linear_scan_number(), "incorrect order in worklist");885}886#endif887}888889void ComputeLinearScanOrder::append_block(BlockBegin* cur) {890TRACE_LINEAR_SCAN(3, tty->print_cr("appending block B%d (weight 0x%6x) to linear-scan order", cur->block_id(), cur->linear_scan_number()));891assert(_linear_scan_order->index_of(cur) == -1, "cannot add the same block twice");892893// currently, the linear scan order and code emit order are equal.894// therefore the linear_scan_number and the weight of a block must also895// be equal.896cur->set_linear_scan_number(_linear_scan_order->length());897_linear_scan_order->append(cur);898}899900void ComputeLinearScanOrder::compute_order(BlockBegin* start_block) {901TRACE_LINEAR_SCAN(3, tty->print_cr("----- computing final block order"));902903// the start block is always the first block in the linear scan order904_linear_scan_order = new BlockList(_num_blocks);905append_block(start_block);906907assert(start_block->end()->as_Base() != NULL, "start block must end with Base-instruction");908BlockBegin* std_entry = ((Base*)start_block->end())->std_entry();909BlockBegin* osr_entry = ((Base*)start_block->end())->osr_entry();910911BlockBegin* sux_of_osr_entry = NULL;912if (osr_entry != NULL) {913// special handling for osr entry:914// ignore the edge between the osr entry and its successor for processing915// the osr entry block is added manually below916assert(osr_entry->number_of_sux() == 1, "osr entry must have exactly one successor");917assert(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");918919sux_of_osr_entry = osr_entry->sux_at(0);920dec_forward_branches(sux_of_osr_entry);921922compute_dominator(osr_entry, start_block);923_iterative_dominators = true;924}925compute_dominator(std_entry, start_block);926927// start processing with standard entry block928assert(_work_list.is_empty(), "list must be empty before processing");929930if (ready_for_processing(std_entry)) {931sort_into_work_list(std_entry);932} else {933assert(false, "the std_entry must be ready for processing (otherwise, the method has no start block)");934}935936do {937BlockBegin* cur = _work_list.pop();938939if (cur == sux_of_osr_entry) {940// the osr entry block is ignored in normal processing, it is never added to the941// work list. Instead, it is added as late as possible manually here.942append_block(osr_entry);943compute_dominator(cur, osr_entry);944}945append_block(cur);946947int i;948int num_sux = cur->number_of_sux();949// changed loop order to get "intuitive" order of if- and else-blocks950for (i = 0; i < num_sux; i++) {951BlockBegin* sux = cur->sux_at(i);952compute_dominator(sux, cur);953if (ready_for_processing(sux)) {954sort_into_work_list(sux);955}956}957num_sux = cur->number_of_exception_handlers();958for (i = 0; i < num_sux; i++) {959BlockBegin* sux = cur->exception_handler_at(i);960if (ready_for_processing(sux)) {961sort_into_work_list(sux);962}963}964} while (_work_list.length() > 0);965}966967968bool ComputeLinearScanOrder::compute_dominators_iter() {969bool changed = false;970int num_blocks = _linear_scan_order->length();971972assert(_linear_scan_order->at(0)->dominator() == NULL, "must not have dominator");973assert(_linear_scan_order->at(0)->number_of_preds() == 0, "must not have predecessors");974for (int i = 1; i < num_blocks; i++) {975BlockBegin* block = _linear_scan_order->at(i);976977BlockBegin* dominator = block->pred_at(0);978int num_preds = block->number_of_preds();979980TRACE_LINEAR_SCAN(4, tty->print_cr("DOM: Processing B%d", block->block_id()));981982for (int j = 0; j < num_preds; j++) {983984BlockBegin *pred = block->pred_at(j);985TRACE_LINEAR_SCAN(4, tty->print_cr(" DOM: Subrocessing B%d", pred->block_id()));986987if (block->is_set(BlockBegin::exception_entry_flag)) {988dominator = common_dominator(dominator, pred);989int num_pred_preds = pred->number_of_preds();990for (int k = 0; k < num_pred_preds; k++) {991dominator = common_dominator(dominator, pred->pred_at(k));992}993} else {994dominator = common_dominator(dominator, pred);995}996}997998if (dominator != block->dominator()) {999TRACE_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()));10001001block->set_dominator(dominator);1002changed = true;1003}1004}1005return changed;1006}10071008void ComputeLinearScanOrder::compute_dominators() {1009TRACE_LINEAR_SCAN(3, tty->print_cr("----- computing dominators (iterative computation reqired: %d)", _iterative_dominators));10101011// iterative computation of dominators is only required for methods with non-natural loops1012// and OSR-methods. For all other methods, the dominators computed when generating the1013// linear scan block order are correct.1014if (_iterative_dominators) {1015do {1016TRACE_LINEAR_SCAN(1, tty->print_cr("DOM: next iteration of fix-point calculation"));1017} while (compute_dominators_iter());1018}10191020// check that dominators are correct1021assert(!compute_dominators_iter(), "fix point not reached");10221023// Add Blocks to dominates-Array1024int num_blocks = _linear_scan_order->length();1025for (int i = 0; i < num_blocks; i++) {1026BlockBegin* block = _linear_scan_order->at(i);10271028BlockBegin *dom = block->dominator();1029if (dom) {1030assert(dom->dominator_depth() != -1, "Dominator must have been visited before");1031dom->dominates()->append(block);1032block->set_dominator_depth(dom->dominator_depth() + 1);1033} else {1034block->set_dominator_depth(0);1035}1036}1037}103810391040#ifndef PRODUCT1041void ComputeLinearScanOrder::print_blocks() {1042if (TraceLinearScanLevel >= 2) {1043tty->print_cr("----- loop information:");1044for (int block_idx = 0; block_idx < _linear_scan_order->length(); block_idx++) {1045BlockBegin* cur = _linear_scan_order->at(block_idx);10461047tty->print("%4d: B%2d: ", cur->linear_scan_number(), cur->block_id());1048for (int loop_idx = 0; loop_idx < _num_loops; loop_idx++) {1049tty->print ("%d ", is_block_in_loop(loop_idx, cur));1050}1051tty->print_cr(" -> loop_index: %2d, loop_depth: %2d", cur->loop_index(), cur->loop_depth());1052}1053}10541055if (TraceLinearScanLevel >= 1) {1056tty->print_cr("----- linear-scan block order:");1057for (int block_idx = 0; block_idx < _linear_scan_order->length(); block_idx++) {1058BlockBegin* cur = _linear_scan_order->at(block_idx);1059tty->print("%4d: B%2d loop: %2d depth: %2d", cur->linear_scan_number(), cur->block_id(), cur->loop_index(), cur->loop_depth());10601061tty->print(cur->is_set(BlockBegin::exception_entry_flag) ? " ex" : " ");1062tty->print(cur->is_set(BlockBegin::critical_edge_split_flag) ? " ce" : " ");1063tty->print(cur->is_set(BlockBegin::linear_scan_loop_header_flag) ? " lh" : " ");1064tty->print(cur->is_set(BlockBegin::linear_scan_loop_end_flag) ? " le" : " ");10651066if (cur->dominator() != NULL) {1067tty->print(" dom: B%d ", cur->dominator()->block_id());1068} else {1069tty->print(" dom: NULL ");1070}10711072if (cur->number_of_preds() > 0) {1073tty->print(" preds: ");1074for (int j = 0; j < cur->number_of_preds(); j++) {1075BlockBegin* pred = cur->pred_at(j);1076tty->print("B%d ", pred->block_id());1077}1078}1079if (cur->number_of_sux() > 0) {1080tty->print(" sux: ");1081for (int j = 0; j < cur->number_of_sux(); j++) {1082BlockBegin* sux = cur->sux_at(j);1083tty->print("B%d ", sux->block_id());1084}1085}1086if (cur->number_of_exception_handlers() > 0) {1087tty->print(" ex: ");1088for (int j = 0; j < cur->number_of_exception_handlers(); j++) {1089BlockBegin* ex = cur->exception_handler_at(j);1090tty->print("B%d ", ex->block_id());1091}1092}1093tty->cr();1094}1095}1096}1097#endif10981099#ifdef ASSERT1100void ComputeLinearScanOrder::verify() {1101assert(_linear_scan_order->length() == _num_blocks, "wrong number of blocks in list");11021103if (StressLinearScan) {1104// blocks are scrambled when StressLinearScan is used1105return;1106}11071108// check that all successors of a block have a higher linear-scan-number1109// and that all predecessors of a block have a lower linear-scan-number1110// (only backward branches of loops are ignored)1111int i;1112for (i = 0; i < _linear_scan_order->length(); i++) {1113BlockBegin* cur = _linear_scan_order->at(i);11141115assert(cur->linear_scan_number() == i, "incorrect linear_scan_number");1116assert(cur->linear_scan_number() >= 0 && cur->linear_scan_number() == _linear_scan_order->index_of(cur), "incorrect linear_scan_number");11171118int j;1119for (j = cur->number_of_sux() - 1; j >= 0; j--) {1120BlockBegin* sux = cur->sux_at(j);11211122assert(sux->linear_scan_number() >= 0 && sux->linear_scan_number() == _linear_scan_order->index_of(sux), "incorrect linear_scan_number");1123if (!sux->is_set(BlockBegin::backward_branch_target_flag)) {1124assert(cur->linear_scan_number() < sux->linear_scan_number(), "invalid order");1125}1126if (cur->loop_depth() == sux->loop_depth()) {1127assert(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");1128}1129}11301131for (j = cur->number_of_preds() - 1; j >= 0; j--) {1132BlockBegin* pred = cur->pred_at(j);11331134assert(pred->linear_scan_number() >= 0 && pred->linear_scan_number() == _linear_scan_order->index_of(pred), "incorrect linear_scan_number");1135if (!cur->is_set(BlockBegin::backward_branch_target_flag)) {1136assert(cur->linear_scan_number() > pred->linear_scan_number(), "invalid order");1137}1138if (cur->loop_depth() == pred->loop_depth()) {1139assert(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");1140}11411142assert(cur->dominator()->linear_scan_number() <= cur->pred_at(j)->linear_scan_number(), "dominator must be before predecessors");1143}11441145// check dominator1146if (i == 0) {1147assert(cur->dominator() == NULL, "first block has no dominator");1148} else {1149assert(cur->dominator() != NULL, "all but first block must have dominator");1150}1151// Assertion does not hold for exception handlers1152assert(cur->number_of_preds() != 1 || cur->dominator() == cur->pred_at(0) || cur->is_set(BlockBegin::exception_entry_flag), "Single predecessor must also be dominator");1153}11541155// check that all loops are continuous1156for (int loop_idx = 0; loop_idx < _num_loops; loop_idx++) {1157int block_idx = 0;1158assert(!is_block_in_loop(loop_idx, _linear_scan_order->at(block_idx)), "the first block must not be present in any loop");11591160// skip blocks before the loop1161while (block_idx < _num_blocks && !is_block_in_loop(loop_idx, _linear_scan_order->at(block_idx))) {1162block_idx++;1163}1164// skip blocks of loop1165while (block_idx < _num_blocks && is_block_in_loop(loop_idx, _linear_scan_order->at(block_idx))) {1166block_idx++;1167}1168// after the first non-loop block, there must not be another loop-block1169while (block_idx < _num_blocks) {1170assert(!is_block_in_loop(loop_idx, _linear_scan_order->at(block_idx)), "loop not continuous in linear-scan order");1171block_idx++;1172}1173}1174}1175#endif117611771178void IR::compute_code() {1179assert(is_valid(), "IR must be valid");11801181ComputeLinearScanOrder compute_order(compilation(), start());1182_num_loops = compute_order.num_loops();1183_code = compute_order.linear_scan_order();1184}118511861187void IR::compute_use_counts() {1188// make sure all values coming out of this block get evaluated.1189int num_blocks = _code->length();1190for (int i = 0; i < num_blocks; i++) {1191_code->at(i)->end()->state()->pin_stack_for_linear_scan();1192}11931194// compute use counts1195UseCountComputer::compute(_code);1196}119711981199void IR::iterate_preorder(BlockClosure* closure) {1200assert(is_valid(), "IR must be valid");1201start()->iterate_preorder(closure);1202}120312041205void IR::iterate_postorder(BlockClosure* closure) {1206assert(is_valid(), "IR must be valid");1207start()->iterate_postorder(closure);1208}12091210void IR::iterate_linear_scan_order(BlockClosure* closure) {1211linear_scan_order()->iterate_forward(closure);1212}121312141215#ifndef PRODUCT1216class BlockPrinter: public BlockClosure {1217private:1218InstructionPrinter* _ip;1219bool _cfg_only;1220bool _live_only;12211222public:1223BlockPrinter(InstructionPrinter* ip, bool cfg_only, bool live_only = false) {1224_ip = ip;1225_cfg_only = cfg_only;1226_live_only = live_only;1227}12281229virtual void block_do(BlockBegin* block) {1230if (_cfg_only) {1231_ip->print_instr(block); tty->cr();1232} else {1233block->print_block(*_ip, _live_only);1234}1235}1236};123712381239void IR::print(BlockBegin* start, bool cfg_only, bool live_only) {1240ttyLocker ttyl;1241InstructionPrinter ip(!cfg_only);1242BlockPrinter bp(&ip, cfg_only, live_only);1243start->iterate_preorder(&bp);1244tty->cr();1245}12461247void IR::print(bool cfg_only, bool live_only) {1248if (is_valid()) {1249print(start(), cfg_only, live_only);1250} else {1251tty->print_cr("invalid IR");1252}1253}125412551256define_array(BlockListArray, BlockList*)1257define_stack(BlockListList, BlockListArray)12581259class PredecessorValidator : public BlockClosure {1260private:1261BlockListList* _predecessors;1262BlockList* _blocks;12631264static int cmp(BlockBegin** a, BlockBegin** b) {1265return (*a)->block_id() - (*b)->block_id();1266}12671268public:1269PredecessorValidator(IR* hir) {1270ResourceMark rm;1271_predecessors = new BlockListList(BlockBegin::number_of_blocks(), NULL);1272_blocks = new BlockList();12731274int i;1275hir->start()->iterate_preorder(this);1276if (hir->code() != NULL) {1277assert(hir->code()->length() == _blocks->length(), "must match");1278for (i = 0; i < _blocks->length(); i++) {1279assert(hir->code()->contains(_blocks->at(i)), "should be in both lists");1280}1281}12821283for (i = 0; i < _blocks->length(); i++) {1284BlockBegin* block = _blocks->at(i);1285BlockList* preds = _predecessors->at(block->block_id());1286if (preds == NULL) {1287assert(block->number_of_preds() == 0, "should be the same");1288continue;1289}12901291// clone the pred list so we can mutate it1292BlockList* pred_copy = new BlockList();1293int j;1294for (j = 0; j < block->number_of_preds(); j++) {1295pred_copy->append(block->pred_at(j));1296}1297// sort them in the same order1298preds->sort(cmp);1299pred_copy->sort(cmp);1300int length = MIN2(preds->length(), block->number_of_preds());1301for (j = 0; j < block->number_of_preds(); j++) {1302assert(preds->at(j) == pred_copy->at(j), "must match");1303}13041305assert(preds->length() == block->number_of_preds(), "should be the same");1306}1307}13081309virtual void block_do(BlockBegin* block) {1310_blocks->append(block);1311BlockEnd* be = block->end();1312int n = be->number_of_sux();1313int i;1314for (i = 0; i < n; i++) {1315BlockBegin* sux = be->sux_at(i);1316assert(!sux->is_set(BlockBegin::exception_entry_flag), "must not be xhandler");13171318BlockList* preds = _predecessors->at_grow(sux->block_id(), NULL);1319if (preds == NULL) {1320preds = new BlockList();1321_predecessors->at_put(sux->block_id(), preds);1322}1323preds->append(block);1324}13251326n = block->number_of_exception_handlers();1327for (i = 0; i < n; i++) {1328BlockBegin* sux = block->exception_handler_at(i);1329assert(sux->is_set(BlockBegin::exception_entry_flag), "must be xhandler");13301331BlockList* preds = _predecessors->at_grow(sux->block_id(), NULL);1332if (preds == NULL) {1333preds = new BlockList();1334_predecessors->at_put(sux->block_id(), preds);1335}1336preds->append(block);1337}1338}1339};13401341class VerifyBlockBeginField : public BlockClosure {13421343public:13441345virtual void block_do(BlockBegin *block) {1346for ( Instruction *cur = block; cur != NULL; cur = cur->next()) {1347assert(cur->block() == block, "Block begin is not correct");1348}1349}1350};13511352void IR::verify() {1353#ifdef ASSERT1354PredecessorValidator pv(this);1355VerifyBlockBeginField verifier;1356this->iterate_postorder(&verifier);1357#endif1358}13591360#endif // PRODUCT13611362void SubstitutionResolver::visit(Value* v) {1363Value v0 = *v;1364if (v0) {1365Value vs = v0->subst();1366if (vs != v0) {1367*v = v0->subst();1368}1369}1370}13711372#ifdef ASSERT1373class SubstitutionChecker: public ValueVisitor {1374void visit(Value* v) {1375Value v0 = *v;1376if (v0) {1377Value vs = v0->subst();1378assert(vs == v0, "missed substitution");1379}1380}1381};1382#endif138313841385void SubstitutionResolver::block_do(BlockBegin* block) {1386Instruction* last = NULL;1387for (Instruction* n = block; n != NULL;) {1388n->values_do(this);1389// need to remove this instruction from the instruction stream1390if (n->subst() != n) {1391assert(last != NULL, "must have last");1392last->set_next(n->next());1393} else {1394last = n;1395}1396n = last->next();1397}13981399#ifdef ASSERT1400SubstitutionChecker check_substitute;1401if (block->state()) block->state()->values_do(&check_substitute);1402block->block_values_do(&check_substitute);1403if (block->end() && block->end()->state()) block->end()->state()->values_do(&check_substitute);1404#endif1405}140614071408