Path: blob/master/src/hotspot/share/compiler/methodLiveness.cpp
40930 views
/*1* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "ci/ciMethod.hpp"26#include "ci/ciMethodBlocks.hpp"27#include "ci/ciStreams.hpp"28#include "classfile/vmIntrinsics.hpp"29#include "compiler/methodLiveness.hpp"30#include "interpreter/bytecode.hpp"31#include "interpreter/bytecodes.hpp"32#include "memory/allocation.inline.hpp"33#include "memory/resourceArea.hpp"34#include "utilities/bitMap.inline.hpp"3536// The MethodLiveness class performs a simple liveness analysis on a method37// in order to decide which locals are live (that is, will be used again) at38// a particular bytecode index (bci).39//40// The algorithm goes:41//42// 1. Break the method into a set of basic blocks. For each basic block we43// also keep track of its set of predecessors through normal control flow44// and predecessors through exceptional control flow.45//46// 2. For each basic block, compute two sets, gen (the set of values used before47// they are defined) and kill (the set of values defined before they are used)48// in the basic block. A basic block "needs" the locals in its gen set to49// perform its computation. A basic block "provides" values for the locals in50// its kill set, allowing a need from a successor to be ignored.51//52// 3. Liveness information (the set of locals which are needed) is pushed backwards through53// the program, from blocks to their predecessors. We compute and store liveness54// information for the normal/exceptional exit paths for each basic block. When55// this process reaches a fixed point, we are done.56//57// 4. When we are asked about the liveness at a particular bci with a basic block, we58// compute gen/kill sets which represent execution from that bci to the exit of59// its blocks. We then compose this range gen/kill information with the normal60// and exceptional exit information for the block to produce liveness information61// at that bci.62//63// The algorithm is approximate in many respects. Notably:64//65// 1. We do not do the analysis necessary to match jsr's with the appropriate ret.66// Instead we make the conservative assumption that any ret can return to any67// jsr return site.68// 2. Instead of computing the effects of exceptions at every instruction, we69// summarize the effects of all exceptional continuations from the block as70// a single set (_exception_exit), losing some information but simplifying the71// analysis.7273MethodLiveness::MethodLiveness(Arena* arena, ciMethod* method)74#ifdef COMPILER175: _bci_block_start(arena, method->code_size())76#endif77{78_arena = arena;79_method = method;80_bit_map_size_bits = method->max_locals();81}8283void MethodLiveness::compute_liveness() {84#ifndef PRODUCT85if (TraceLivenessGen) {86tty->print_cr("################################################################");87tty->print("# Computing liveness information for ");88method()->print_short_name();89}90#endif9192init_basic_blocks();93init_gen_kill();94propagate_liveness();95}969798void MethodLiveness::init_basic_blocks() {99bool bailout = false;100101int method_len = method()->code_size();102ciMethodBlocks *mblocks = method()->get_method_blocks();103104// Create an array to store the bci->BasicBlock mapping.105_block_map = new (arena()) GrowableArray<BasicBlock*>(arena(), method_len, method_len, NULL);106107_block_count = mblocks->num_blocks();108_block_list = (BasicBlock **) arena()->Amalloc(sizeof(BasicBlock *) * _block_count);109110// Used for patching up jsr/ret control flow.111GrowableArray<BasicBlock*>* jsr_exit_list = new GrowableArray<BasicBlock*>(5);112GrowableArray<BasicBlock*>* ret_list = new GrowableArray<BasicBlock*>(5);113114// generate our block list from ciMethodBlocks115for (int blk = 0; blk < _block_count; blk++) {116ciBlock *cib = mblocks->block(blk);117int start_bci = cib->start_bci();118_block_list[blk] = new (arena()) BasicBlock(this, start_bci, cib->limit_bci());119_block_map->at_put(start_bci, _block_list[blk]);120#ifdef COMPILER1121// mark all bcis where a new basic block starts122_bci_block_start.set_bit(start_bci);123#endif // COMPILER1124}125// fill in the predecessors of blocks126ciBytecodeStream bytes(method());127128for (int blk = 0; blk < _block_count; blk++) {129BasicBlock *current_block = _block_list[blk];130int bci = mblocks->block(blk)->control_bci();131132if (bci == ciBlock::fall_through_bci) {133int limit = current_block->limit_bci();134if (limit < method_len) {135BasicBlock *next = _block_map->at(limit);136assert( next != NULL, "must be a block immediately following this one.");137next->add_normal_predecessor(current_block);138}139continue;140}141bytes.reset_to_bci(bci);142Bytecodes::Code code = bytes.next();143BasicBlock *dest;144145// Now we need to interpret the instruction's effect146// on control flow.147assert (current_block != NULL, "we must have a current block");148switch (code) {149case Bytecodes::_ifeq:150case Bytecodes::_ifne:151case Bytecodes::_iflt:152case Bytecodes::_ifge:153case Bytecodes::_ifgt:154case Bytecodes::_ifle:155case Bytecodes::_if_icmpeq:156case Bytecodes::_if_icmpne:157case Bytecodes::_if_icmplt:158case Bytecodes::_if_icmpge:159case Bytecodes::_if_icmpgt:160case Bytecodes::_if_icmple:161case Bytecodes::_if_acmpeq:162case Bytecodes::_if_acmpne:163case Bytecodes::_ifnull:164case Bytecodes::_ifnonnull:165// Two way branch. Set predecessors at each destination.166dest = _block_map->at(bytes.next_bci());167assert(dest != NULL, "must be a block immediately following this one.");168dest->add_normal_predecessor(current_block);169170dest = _block_map->at(bytes.get_dest());171assert(dest != NULL, "branch desination must start a block.");172dest->add_normal_predecessor(current_block);173break;174case Bytecodes::_goto:175dest = _block_map->at(bytes.get_dest());176assert(dest != NULL, "branch desination must start a block.");177dest->add_normal_predecessor(current_block);178break;179case Bytecodes::_goto_w:180dest = _block_map->at(bytes.get_far_dest());181assert(dest != NULL, "branch desination must start a block.");182dest->add_normal_predecessor(current_block);183break;184case Bytecodes::_tableswitch:185{186Bytecode_tableswitch tableswitch(&bytes);187188int len = tableswitch.length();189190dest = _block_map->at(bci + tableswitch.default_offset());191assert(dest != NULL, "branch desination must start a block.");192dest->add_normal_predecessor(current_block);193while (--len >= 0) {194dest = _block_map->at(bci + tableswitch.dest_offset_at(len));195assert(dest != NULL, "branch desination must start a block.");196dest->add_normal_predecessor(current_block);197}198break;199}200201case Bytecodes::_lookupswitch:202{203Bytecode_lookupswitch lookupswitch(&bytes);204205int npairs = lookupswitch.number_of_pairs();206207dest = _block_map->at(bci + lookupswitch.default_offset());208assert(dest != NULL, "branch desination must start a block.");209dest->add_normal_predecessor(current_block);210while(--npairs >= 0) {211LookupswitchPair pair = lookupswitch.pair_at(npairs);212dest = _block_map->at( bci + pair.offset());213assert(dest != NULL, "branch desination must start a block.");214dest->add_normal_predecessor(current_block);215}216break;217}218219case Bytecodes::_jsr:220{221assert(bytes.is_wide()==false, "sanity check");222dest = _block_map->at(bytes.get_dest());223assert(dest != NULL, "branch desination must start a block.");224dest->add_normal_predecessor(current_block);225BasicBlock *jsrExit = _block_map->at(current_block->limit_bci());226assert(jsrExit != NULL, "jsr return bci must start a block.");227jsr_exit_list->append(jsrExit);228break;229}230case Bytecodes::_jsr_w:231{232dest = _block_map->at(bytes.get_far_dest());233assert(dest != NULL, "branch desination must start a block.");234dest->add_normal_predecessor(current_block);235BasicBlock *jsrExit = _block_map->at(current_block->limit_bci());236assert(jsrExit != NULL, "jsr return bci must start a block.");237jsr_exit_list->append(jsrExit);238break;239}240241case Bytecodes::_wide:242assert(false, "wide opcodes should not be seen here");243break;244case Bytecodes::_athrow:245case Bytecodes::_ireturn:246case Bytecodes::_lreturn:247case Bytecodes::_freturn:248case Bytecodes::_dreturn:249case Bytecodes::_areturn:250case Bytecodes::_return:251// These opcodes are not the normal predecessors of any other opcodes.252break;253case Bytecodes::_ret:254// We will patch up jsr/rets in a subsequent pass.255ret_list->append(current_block);256break;257case Bytecodes::_breakpoint:258// Bail out of there are breakpoints in here.259bailout = true;260break;261default:262// Do nothing.263break;264}265}266// Patch up the jsr/ret's. We conservatively assume that any ret267// can return to any jsr site.268int ret_list_len = ret_list->length();269int jsr_exit_list_len = jsr_exit_list->length();270if (ret_list_len > 0 && jsr_exit_list_len > 0) {271for (int i = jsr_exit_list_len - 1; i >= 0; i--) {272BasicBlock *jsrExit = jsr_exit_list->at(i);273for (int i = ret_list_len - 1; i >= 0; i--) {274jsrExit->add_normal_predecessor(ret_list->at(i));275}276}277}278279// Compute exception edges.280for (int b=_block_count-1; b >= 0; b--) {281BasicBlock *block = _block_list[b];282int block_start = block->start_bci();283int block_limit = block->limit_bci();284ciExceptionHandlerStream handlers(method());285for (; !handlers.is_done(); handlers.next()) {286ciExceptionHandler* handler = handlers.handler();287int start = handler->start();288int limit = handler->limit();289int handler_bci = handler->handler_bci();290291int intersect_start = MAX2(block_start, start);292int intersect_limit = MIN2(block_limit, limit);293if (intersect_start < intersect_limit) {294// The catch range has a nonempty intersection with this295// basic block. That means this basic block can be an296// exceptional predecessor.297_block_map->at(handler_bci)->add_exception_predecessor(block);298299if (handler->is_catch_all()) {300// This is a catch-all block.301if (intersect_start == block_start && intersect_limit == block_limit) {302// The basic block is entirely contained in this catch-all block.303// Skip the rest of the exception handlers -- they can never be304// reached in execution.305break;306}307}308}309}310}311}312313void MethodLiveness::init_gen_kill() {314for (int i=_block_count-1; i >= 0; i--) {315_block_list[i]->compute_gen_kill(method());316}317}318319void MethodLiveness::propagate_liveness() {320int num_blocks = _block_count;321BasicBlock *block;322323// We start our work list off with all blocks in it.324// Alternately, we could start off the work list with the list of all325// blocks which could exit the method directly, along with one block326// from any infinite loop. If this matters, it can be changed. It327// may not be clear from looking at the code, but the order of the328// workList will be the opposite of the creation order of the basic329// blocks, which should be decent for quick convergence (with the330// possible exception of exception handlers, which are all created331// early).332_work_list = NULL;333for (int i = 0; i < num_blocks; i++) {334block = _block_list[i];335block->set_next(_work_list);336block->set_on_work_list(true);337_work_list = block;338}339340341while ((block = work_list_get()) != NULL) {342block->propagate(this);343}344}345346void MethodLiveness::work_list_add(BasicBlock *block) {347if (!block->on_work_list()) {348block->set_next(_work_list);349block->set_on_work_list(true);350_work_list = block;351}352}353354MethodLiveness::BasicBlock *MethodLiveness::work_list_get() {355BasicBlock *block = _work_list;356if (block != NULL) {357block->set_on_work_list(false);358_work_list = block->next();359}360return block;361}362363364MethodLivenessResult MethodLiveness::get_liveness_at(int entry_bci) {365int bci = entry_bci;366bool is_entry = false;367if (entry_bci == InvocationEntryBci) {368is_entry = true;369bci = 0;370}371372MethodLivenessResult answer;373374if (_block_count > 0) {375376assert( 0 <= bci && bci < method()->code_size(), "bci out of range" );377BasicBlock *block = _block_map->at(bci);378// We may not be at the block start, so search backwards to find the block379// containing bci.380int t = bci;381while (block == NULL && t > 0) {382block = _block_map->at(--t);383}384guarantee(block != NULL, "invalid bytecode index; must be instruction index");385assert(bci >= block->start_bci() && bci < block->limit_bci(), "block must contain bci.");386387answer = block->get_liveness_at(method(), bci);388389if (is_entry && method()->is_synchronized() && !method()->is_static()) {390// Synchronized methods use the receiver once on entry.391answer.at_put(0, true);392}393394#ifndef PRODUCT395if (TraceLivenessQuery) {396tty->print("Liveness query of ");397method()->print_short_name();398tty->print(" @ %d : result is ", bci);399answer.print_on(tty);400}401#endif402}403404return answer;405}406407MethodLiveness::BasicBlock::BasicBlock(MethodLiveness *analyzer, int start, int limit) :408_entry(analyzer->arena(), analyzer->bit_map_size_bits()),409_normal_exit(analyzer->arena(), analyzer->bit_map_size_bits()),410_exception_exit(analyzer->arena(), analyzer->bit_map_size_bits()),411_gen(analyzer->arena(), analyzer->bit_map_size_bits()),412_kill(analyzer->arena(), analyzer->bit_map_size_bits()),413_last_bci(-1) {414_analyzer = analyzer;415_start_bci = start;416_limit_bci = limit;417_normal_predecessors =418new (analyzer->arena()) GrowableArray<MethodLiveness::BasicBlock*>(analyzer->arena(), 5, 0, NULL);419_exception_predecessors =420new (analyzer->arena()) GrowableArray<MethodLiveness::BasicBlock*>(analyzer->arena(), 5, 0, NULL);421}422423424425MethodLiveness::BasicBlock *MethodLiveness::BasicBlock::split(int split_bci) {426int start = _start_bci;427int limit = _limit_bci;428429if (TraceLivenessGen) {430tty->print_cr(" ** Splitting block (%d,%d) at %d", start, limit, split_bci);431}432433GrowableArray<BasicBlock*>* save_predecessors = _normal_predecessors;434435assert (start < split_bci && split_bci < limit, "improper split");436437// Make a new block to cover the first half of the range.438BasicBlock *first_half = new (_analyzer->arena()) BasicBlock(_analyzer, start, split_bci);439440// Assign correct values to the second half (this)441_normal_predecessors = first_half->_normal_predecessors;442_start_bci = split_bci;443add_normal_predecessor(first_half);444445// Assign correct predecessors to the new first half446first_half->_normal_predecessors = save_predecessors;447448return first_half;449}450451void MethodLiveness::BasicBlock::compute_gen_kill(ciMethod* method) {452ciBytecodeStream bytes(method);453bytes.reset_to_bci(start_bci());454bytes.set_max_bci(limit_bci());455compute_gen_kill_range(&bytes);456457}458459void MethodLiveness::BasicBlock::compute_gen_kill_range(ciBytecodeStream *bytes) {460_gen.clear();461_kill.clear();462463while (bytes->next() != ciBytecodeStream::EOBC()) {464compute_gen_kill_single(bytes);465}466}467468void MethodLiveness::BasicBlock::compute_gen_kill_single(ciBytecodeStream *instruction) {469// We prohibit _gen and _kill from having locals in common. If we470// know that one is definitely going to be applied before the other,471// we could save some computation time by relaxing this prohibition.472473switch (instruction->cur_bc()) {474case Bytecodes::_nop:475case Bytecodes::_goto:476case Bytecodes::_goto_w:477case Bytecodes::_aconst_null:478case Bytecodes::_new:479case Bytecodes::_iconst_m1:480case Bytecodes::_iconst_0:481case Bytecodes::_iconst_1:482case Bytecodes::_iconst_2:483case Bytecodes::_iconst_3:484case Bytecodes::_iconst_4:485case Bytecodes::_iconst_5:486case Bytecodes::_fconst_0:487case Bytecodes::_fconst_1:488case Bytecodes::_fconst_2:489case Bytecodes::_bipush:490case Bytecodes::_sipush:491case Bytecodes::_lconst_0:492case Bytecodes::_lconst_1:493case Bytecodes::_dconst_0:494case Bytecodes::_dconst_1:495case Bytecodes::_ldc2_w:496case Bytecodes::_ldc:497case Bytecodes::_ldc_w:498case Bytecodes::_iaload:499case Bytecodes::_faload:500case Bytecodes::_baload:501case Bytecodes::_caload:502case Bytecodes::_saload:503case Bytecodes::_laload:504case Bytecodes::_daload:505case Bytecodes::_aaload:506case Bytecodes::_iastore:507case Bytecodes::_fastore:508case Bytecodes::_bastore:509case Bytecodes::_castore:510case Bytecodes::_sastore:511case Bytecodes::_lastore:512case Bytecodes::_dastore:513case Bytecodes::_aastore:514case Bytecodes::_pop:515case Bytecodes::_pop2:516case Bytecodes::_dup:517case Bytecodes::_dup_x1:518case Bytecodes::_dup_x2:519case Bytecodes::_dup2:520case Bytecodes::_dup2_x1:521case Bytecodes::_dup2_x2:522case Bytecodes::_swap:523case Bytecodes::_iadd:524case Bytecodes::_fadd:525case Bytecodes::_isub:526case Bytecodes::_fsub:527case Bytecodes::_imul:528case Bytecodes::_fmul:529case Bytecodes::_idiv:530case Bytecodes::_fdiv:531case Bytecodes::_irem:532case Bytecodes::_frem:533case Bytecodes::_ishl:534case Bytecodes::_ishr:535case Bytecodes::_iushr:536case Bytecodes::_iand:537case Bytecodes::_ior:538case Bytecodes::_ixor:539case Bytecodes::_l2f:540case Bytecodes::_l2i:541case Bytecodes::_d2f:542case Bytecodes::_d2i:543case Bytecodes::_fcmpl:544case Bytecodes::_fcmpg:545case Bytecodes::_ladd:546case Bytecodes::_dadd:547case Bytecodes::_lsub:548case Bytecodes::_dsub:549case Bytecodes::_lmul:550case Bytecodes::_dmul:551case Bytecodes::_ldiv:552case Bytecodes::_ddiv:553case Bytecodes::_lrem:554case Bytecodes::_drem:555case Bytecodes::_land:556case Bytecodes::_lor:557case Bytecodes::_lxor:558case Bytecodes::_ineg:559case Bytecodes::_fneg:560case Bytecodes::_i2f:561case Bytecodes::_f2i:562case Bytecodes::_i2c:563case Bytecodes::_i2s:564case Bytecodes::_i2b:565case Bytecodes::_lneg:566case Bytecodes::_dneg:567case Bytecodes::_l2d:568case Bytecodes::_d2l:569case Bytecodes::_lshl:570case Bytecodes::_lshr:571case Bytecodes::_lushr:572case Bytecodes::_i2l:573case Bytecodes::_i2d:574case Bytecodes::_f2l:575case Bytecodes::_f2d:576case Bytecodes::_lcmp:577case Bytecodes::_dcmpl:578case Bytecodes::_dcmpg:579case Bytecodes::_ifeq:580case Bytecodes::_ifne:581case Bytecodes::_iflt:582case Bytecodes::_ifge:583case Bytecodes::_ifgt:584case Bytecodes::_ifle:585case Bytecodes::_tableswitch:586case Bytecodes::_ireturn:587case Bytecodes::_freturn:588case Bytecodes::_if_icmpeq:589case Bytecodes::_if_icmpne:590case Bytecodes::_if_icmplt:591case Bytecodes::_if_icmpge:592case Bytecodes::_if_icmpgt:593case Bytecodes::_if_icmple:594case Bytecodes::_lreturn:595case Bytecodes::_dreturn:596case Bytecodes::_if_acmpeq:597case Bytecodes::_if_acmpne:598case Bytecodes::_jsr:599case Bytecodes::_jsr_w:600case Bytecodes::_getstatic:601case Bytecodes::_putstatic:602case Bytecodes::_getfield:603case Bytecodes::_putfield:604case Bytecodes::_invokevirtual:605case Bytecodes::_invokespecial:606case Bytecodes::_invokestatic:607case Bytecodes::_invokeinterface:608case Bytecodes::_invokedynamic:609case Bytecodes::_newarray:610case Bytecodes::_anewarray:611case Bytecodes::_checkcast:612case Bytecodes::_arraylength:613case Bytecodes::_instanceof:614case Bytecodes::_athrow:615case Bytecodes::_areturn:616case Bytecodes::_monitorenter:617case Bytecodes::_monitorexit:618case Bytecodes::_ifnull:619case Bytecodes::_ifnonnull:620case Bytecodes::_multianewarray:621case Bytecodes::_lookupswitch:622// These bytecodes have no effect on the method's locals.623break;624625case Bytecodes::_return:626if (instruction->method()->intrinsic_id() == vmIntrinsics::_Object_init) {627// return from Object.init implicitly registers a finalizer628// for the receiver if needed, so keep it alive.629load_one(0);630}631break;632633634case Bytecodes::_lload:635case Bytecodes::_dload:636load_two(instruction->get_index());637break;638639case Bytecodes::_lload_0:640case Bytecodes::_dload_0:641load_two(0);642break;643644case Bytecodes::_lload_1:645case Bytecodes::_dload_1:646load_two(1);647break;648649case Bytecodes::_lload_2:650case Bytecodes::_dload_2:651load_two(2);652break;653654case Bytecodes::_lload_3:655case Bytecodes::_dload_3:656load_two(3);657break;658659case Bytecodes::_iload:660case Bytecodes::_iinc:661case Bytecodes::_fload:662case Bytecodes::_aload:663case Bytecodes::_ret:664load_one(instruction->get_index());665break;666667case Bytecodes::_iload_0:668case Bytecodes::_fload_0:669case Bytecodes::_aload_0:670load_one(0);671break;672673case Bytecodes::_iload_1:674case Bytecodes::_fload_1:675case Bytecodes::_aload_1:676load_one(1);677break;678679case Bytecodes::_iload_2:680case Bytecodes::_fload_2:681case Bytecodes::_aload_2:682load_one(2);683break;684685case Bytecodes::_iload_3:686case Bytecodes::_fload_3:687case Bytecodes::_aload_3:688load_one(3);689break;690691case Bytecodes::_lstore:692case Bytecodes::_dstore:693store_two(instruction->get_index());694break;695696case Bytecodes::_lstore_0:697case Bytecodes::_dstore_0:698store_two(0);699break;700701case Bytecodes::_lstore_1:702case Bytecodes::_dstore_1:703store_two(1);704break;705706case Bytecodes::_lstore_2:707case Bytecodes::_dstore_2:708store_two(2);709break;710711case Bytecodes::_lstore_3:712case Bytecodes::_dstore_3:713store_two(3);714break;715716case Bytecodes::_istore:717case Bytecodes::_fstore:718case Bytecodes::_astore:719store_one(instruction->get_index());720break;721722case Bytecodes::_istore_0:723case Bytecodes::_fstore_0:724case Bytecodes::_astore_0:725store_one(0);726break;727728case Bytecodes::_istore_1:729case Bytecodes::_fstore_1:730case Bytecodes::_astore_1:731store_one(1);732break;733734case Bytecodes::_istore_2:735case Bytecodes::_fstore_2:736case Bytecodes::_astore_2:737store_one(2);738break;739740case Bytecodes::_istore_3:741case Bytecodes::_fstore_3:742case Bytecodes::_astore_3:743store_one(3);744break;745746case Bytecodes::_wide:747fatal("Iterator should skip this bytecode");748break;749750default:751tty->print("unexpected opcode: %d\n", instruction->cur_bc());752ShouldNotReachHere();753break;754}755}756757void MethodLiveness::BasicBlock::load_two(int local) {758load_one(local);759load_one(local+1);760}761762void MethodLiveness::BasicBlock::load_one(int local) {763if (!_kill.at(local)) {764_gen.at_put(local, true);765}766}767768void MethodLiveness::BasicBlock::store_two(int local) {769store_one(local);770store_one(local+1);771}772773void MethodLiveness::BasicBlock::store_one(int local) {774if (!_gen.at(local)) {775_kill.at_put(local, true);776}777}778779void MethodLiveness::BasicBlock::propagate(MethodLiveness *ml) {780// These set operations could be combined for efficiency if the781// performance of this analysis becomes an issue.782_entry.set_union(_normal_exit);783_entry.set_difference(_kill);784_entry.set_union(_gen);785786// Note that we merge information from our exceptional successors787// just once, rather than at individual bytecodes.788_entry.set_union(_exception_exit);789790if (TraceLivenessGen) {791tty->print_cr(" ** Visiting block at %d **", start_bci());792print_on(tty);793}794795int i;796for (i=_normal_predecessors->length()-1; i>=0; i--) {797BasicBlock *block = _normal_predecessors->at(i);798if (block->merge_normal(_entry)) {799ml->work_list_add(block);800}801}802for (i=_exception_predecessors->length()-1; i>=0; i--) {803BasicBlock *block = _exception_predecessors->at(i);804if (block->merge_exception(_entry)) {805ml->work_list_add(block);806}807}808}809810bool MethodLiveness::BasicBlock::merge_normal(const BitMap& other) {811return _normal_exit.set_union_with_result(other);812}813814bool MethodLiveness::BasicBlock::merge_exception(const BitMap& other) {815return _exception_exit.set_union_with_result(other);816}817818MethodLivenessResult MethodLiveness::BasicBlock::get_liveness_at(ciMethod* method, int bci) {819MethodLivenessResult answer(_analyzer->bit_map_size_bits());820answer.set_is_valid();821822#ifndef ASSERT823if (bci == start_bci()) {824answer.set_from(_entry);825return answer;826}827#endif828829#ifdef ASSERT830ResourceMark rm;831ResourceBitMap g(_gen.size(), false); g.set_from(_gen);832ResourceBitMap k(_kill.size(), false); k.set_from(_kill);833#endif834if (_last_bci != bci || trueInDebug) {835ciBytecodeStream bytes(method);836bytes.reset_to_bci(bci);837bytes.set_max_bci(limit_bci());838compute_gen_kill_range(&bytes);839assert(_last_bci != bci ||840(g.is_same(_gen) && k.is_same(_kill)), "cached computation is incorrect");841_last_bci = bci;842}843844answer.set_union(_normal_exit);845answer.set_difference(_kill);846answer.set_union(_gen);847answer.set_union(_exception_exit);848849#ifdef ASSERT850if (bci == start_bci()) {851assert(answer.is_same(_entry), "optimized answer must be accurate");852}853#endif854855return answer;856}857858#ifndef PRODUCT859860void MethodLiveness::BasicBlock::print_on(outputStream *os) const {861os->print_cr("===================================================================");862os->print_cr(" Block start: %4d, limit: %4d", _start_bci, _limit_bci);863os->print (" Normal predecessors (%2d) @", _normal_predecessors->length());864int i;865for (i=0; i < _normal_predecessors->length(); i++) {866os->print(" %4d", _normal_predecessors->at(i)->start_bci());867}868os->cr();869os->print (" Exceptional predecessors (%2d) @", _exception_predecessors->length());870for (i=0; i < _exception_predecessors->length(); i++) {871os->print(" %4d", _exception_predecessors->at(i)->start_bci());872}873os->cr();874os->print (" Normal Exit : ");875_normal_exit.print_on(os);876os->print (" Gen : ");877_gen.print_on(os);878os->print (" Kill : ");879_kill.print_on(os);880os->print (" Exception Exit: ");881_exception_exit.print_on(os);882os->print (" Entry : ");883_entry.print_on(os);884}885886#endif // PRODUCT887888889