Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/compiler/methodLiveness.hpp
32285 views
/*1* Copyright (c) 1998, 2010, 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_VM_COMPILER_METHODLIVENESS_HPP25#define SHARE_VM_COMPILER_METHODLIVENESS_HPP2627#include "utilities/bitMap.hpp"28#include "utilities/growableArray.hpp"2930class ciMethod;3132class MethodLivenessResult : public BitMap {33private:34bool _is_valid;3536public:37MethodLivenessResult(BitMap::bm_word_t* map, idx_t size_in_bits)38: BitMap(map, size_in_bits)39, _is_valid(false)40{}4142MethodLivenessResult(idx_t size_in_bits)43: BitMap(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;68BitMap _entry;6970// The summarized liveness effects of our direct successors reached71// by normal control flow72BitMap _normal_exit;7374// The summarized liveness effects of our direct successors reached75// by exceptional control flow76BitMap _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.82BitMap _gen;83BitMap _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(BitMap other);103104// Our successors call this method to merge liveness information into105// our _exception_exit member.106bool merge_exception(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;183int _bit_map_size_words;184185// A list of all BasicBlocks.186BasicBlock **_block_list;187188// number of blocks189int _block_count;190191// Keeps track of bci->block mapping. One entry for each bci. Only block starts are192// recorded.193GrowableArray<BasicBlock*>* _block_map;194195// Our work list.196BasicBlock *_work_list;197198#ifdef COMPILER1199// bcis where blocks start are marked200BitMap _bci_block_start;201#endif // COMPILER1202203// -- Graph construction & Analysis204205// Compute ranges and predecessors for basic blocks.206void init_basic_blocks();207208// Compute gen/kill information for all basic blocks.209void init_gen_kill();210211// Perform the dataflow.212void propagate_liveness();213214// The class MethodLiveness::BasicBlock needs special access to some215// of our members.216friend class MethodLiveness::BasicBlock;217218// And accessors.219int bit_map_size_bits() const { return _bit_map_size_bits; }220int bit_map_size_words() const { return _bit_map_size_words; }221222// Work list manipulation routines. Called internally by BasicBlock.223BasicBlock *work_list_get();224void work_list_add(BasicBlock *block);225226// -- Timing and Statistics.227228229// Timers230static elapsedTimer _time_build_graph;231static elapsedTimer _time_gen_kill;232static elapsedTimer _time_flow;233static elapsedTimer _time_query;234static elapsedTimer _time_total;235236#ifndef PRODUCT237238// Counts239static long _total_bytes;240static int _total_methods;241242static long _total_blocks;243static int _max_method_blocks;244245static long _total_edges;246static int _max_block_edges;247248static long _total_exc_edges;249static int _max_block_exc_edges;250251static long _total_method_locals;252static int _max_method_locals;253254static long _total_locals_queried;255static long _total_live_locals_queried;256257static long _total_visits;258259#endif260261public:262// Create a liveness analyzer for a method263MethodLiveness(Arena* arena, ciMethod* method);264265// Compute liveness information for the method266void compute_liveness();267268// Find out which locals are live at a specific bci.269MethodLivenessResult get_liveness_at(int bci);270271#ifdef COMPILER1272const BitMap get_bci_block_start() const { return _bci_block_start; }273#endif // COMPILER1274275static void print_times() PRODUCT_RETURN;276};277278#endif // SHARE_VM_COMPILER_METHODLIVENESS_HPP279280281