Path: blob/master/src/hotspot/share/compiler/methodLiveness.hpp
40930 views
/*1* Copyright (c) 1998, 2019, 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#ifndef SHARE_COMPILER_METHODLIVENESS_HPP25#define SHARE_COMPILER_METHODLIVENESS_HPP2627#include "utilities/bitMap.hpp"28#include "utilities/growableArray.hpp"2930class ciMethod;3132class MethodLivenessResult : public ResourceBitMap {33private:34bool _is_valid;3536public:37MethodLivenessResult()38: ResourceBitMap()39, _is_valid(false)40{}4142MethodLivenessResult(idx_t size_in_bits)43: ResourceBitMap(size_in_bits)44, _is_valid(false)45{}4647void set_is_valid() { _is_valid = true; }48bool is_valid() { return _is_valid; }49};5051class MethodLiveness : public ResourceObj {52public:53// The BasicBlock class is used to represent a basic block in the54// liveness analysis.55class BasicBlock : public ResourceObj {56private:57// This class is only used by the MethodLiveness class.58friend class MethodLiveness;5960// The analyzer which created this basic block.61MethodLiveness* _analyzer;6263// The range of this basic block is [start_bci,limit_bci)64int _start_bci;65int _limit_bci;6667// The liveness at the start of the block;68ArenaBitMap _entry;6970// The summarized liveness effects of our direct successors reached71// by normal control flow72ArenaBitMap _normal_exit;7374// The summarized liveness effects of our direct successors reached75// by exceptional control flow76ArenaBitMap _exception_exit;7778// These members hold the results of the last call to79// compute_gen_kill_range(). _gen is the set of locals80// used before they are defined in the range. _kill is the81// set of locals defined before they are used.82ArenaBitMap _gen;83ArenaBitMap _kill;84int _last_bci;8586// A list of all blocks which could come directly before this one87// in normal (non-exceptional) control flow. We propagate liveness88// information to these blocks.89GrowableArray<BasicBlock*>* _normal_predecessors;9091// A list of all blocks which could come directly before this one92// in exceptional control flow.93GrowableArray<BasicBlock*>* _exception_predecessors;9495// The following fields are used to manage a work list used in the96// dataflow.97BasicBlock *_next;98bool _on_work_list;99100// Our successors call this method to merge liveness information into101// our _normal_exit member.102bool merge_normal(const BitMap& other);103104// Our successors call this method to merge liveness information into105// our _exception_exit member.106bool merge_exception(const BitMap& other);107108// This helper routine is used to help compute the gen/kill pair for109// the block. It is also used to answer queries.110void compute_gen_kill_range(ciBytecodeStream *bytes);111112// Compute the gen/kill effect of a single instruction.113void compute_gen_kill_single(ciBytecodeStream *instruction);114115// Helpers for compute_gen_kill_single.116void load_one(int local);117void load_two(int local);118void store_one(int local);119void store_two(int local);120121BasicBlock(MethodLiveness *analyzer, int start, int limit);122123// -- Accessors124125int start_bci() const { return _start_bci; }126127int limit_bci() const { return _limit_bci; }128void set_limit_bci(int limit) { _limit_bci = limit; }129130BasicBlock *next() const { return _next; }131void set_next(BasicBlock *next) { _next = next; }132133bool on_work_list() const { return _on_work_list; }134void set_on_work_list(bool val) { _on_work_list = val; }135136// -- Flow graph construction.137138// Add a basic block to our list of normal predecessors.139void add_normal_predecessor(BasicBlock *pred) {140_normal_predecessors->append_if_missing(pred);141}142143// Add a basic block to our list of exceptional predecessors144void add_exception_predecessor(BasicBlock *pred) {145_exception_predecessors->append_if_missing(pred);146}147148// Split the basic block at splitBci. This basic block149// becomes the second half. The first half is newly created.150BasicBlock *split(int splitBci);151152// -- Dataflow.153154void compute_gen_kill(ciMethod* method);155156// Propagate changes from this basic block157void propagate(MethodLiveness *ml);158159// -- Query.160161MethodLivenessResult get_liveness_at(ciMethod* method, int bci);162163// -- Debugging.164165void print_on(outputStream *os) const PRODUCT_RETURN;166167}; // End of MethodLiveness::BasicBlock168169private:170// The method we are analyzing.171ciMethod* _method;172ciMethod* method() const { return _method; }173174// The arena for storing structures...175Arena* _arena;176Arena* arena() const { return _arena; }177178// We cache the length of the method.179int _code_size;180181// The size of a BitMap.182int _bit_map_size_bits;183184// A list of all BasicBlocks.185BasicBlock **_block_list;186187// number of blocks188int _block_count;189190// Keeps track of bci->block mapping. One entry for each bci. Only block starts are191// recorded.192GrowableArray<BasicBlock*>* _block_map;193194// Our work list.195BasicBlock *_work_list;196197#ifdef COMPILER1198// bcis where blocks start are marked199ArenaBitMap _bci_block_start;200#endif // COMPILER1201202// -- Graph construction & Analysis203204// Compute ranges and predecessors for basic blocks.205void init_basic_blocks();206207// Compute gen/kill information for all basic blocks.208void init_gen_kill();209210// Perform the dataflow.211void propagate_liveness();212213// The class MethodLiveness::BasicBlock needs special access to some214// of our members.215friend class MethodLiveness::BasicBlock;216217// And accessors.218int bit_map_size_bits() const { return _bit_map_size_bits; }219220// Work list manipulation routines. Called internally by BasicBlock.221BasicBlock *work_list_get();222void work_list_add(BasicBlock *block);223224public:225// Create a liveness analyzer for a method226MethodLiveness(Arena* arena, ciMethod* method);227228// Compute liveness information for the method229void compute_liveness();230231// Find out which locals are live at a specific bci.232MethodLivenessResult get_liveness_at(int bci);233234#ifdef COMPILER1235const BitMap& get_bci_block_start() const { return _bci_block_start; }236#endif // COMPILER1237238};239240#endif // SHARE_COMPILER_METHODLIVENESS_HPP241242243