src/share/vm/compiler/methodLiveness.hpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/compiler/methodLiveness.hpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,279 @@
     1.4 +/*
     1.5 + * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#ifndef SHARE_VM_COMPILER_METHODLIVENESS_HPP
    1.29 +#define SHARE_VM_COMPILER_METHODLIVENESS_HPP
    1.30 +
    1.31 +#include "utilities/bitMap.hpp"
    1.32 +#include "utilities/growableArray.hpp"
    1.33 +
    1.34 +class ciMethod;
    1.35 +
    1.36 +class MethodLivenessResult : public BitMap {
    1.37 + private:
    1.38 +  bool _is_valid;
    1.39 +
    1.40 + public:
    1.41 +  MethodLivenessResult(BitMap::bm_word_t* map, idx_t size_in_bits)
    1.42 +    : BitMap(map, size_in_bits)
    1.43 +    , _is_valid(false)
    1.44 +  {}
    1.45 +
    1.46 +  MethodLivenessResult(idx_t size_in_bits)
    1.47 +    : BitMap(size_in_bits)
    1.48 +    , _is_valid(false)
    1.49 +  {}
    1.50 +
    1.51 +  void set_is_valid() { _is_valid = true; }
    1.52 +  bool is_valid() { return _is_valid; }
    1.53 +};
    1.54 +
    1.55 +class MethodLiveness : public ResourceObj {
    1.56 + public:
    1.57 +  // The BasicBlock class is used to represent a basic block in the
    1.58 +  // liveness analysis.
    1.59 +  class BasicBlock : public ResourceObj {
    1.60 +   private:
    1.61 +    // This class is only used by the MethodLiveness class.
    1.62 +    friend class MethodLiveness;
    1.63 +
    1.64 +    // The analyzer which created this basic block.
    1.65 +    MethodLiveness* _analyzer;
    1.66 +
    1.67 +    // The range of this basic block is [start_bci,limit_bci)
    1.68 +    int _start_bci;
    1.69 +    int _limit_bci;
    1.70 +
    1.71 +    // The liveness at the start of the block;
    1.72 +    BitMap _entry;
    1.73 +
    1.74 +    // The summarized liveness effects of our direct successors reached
    1.75 +    // by normal control flow
    1.76 +    BitMap _normal_exit;
    1.77 +
    1.78 +    // The summarized liveness effects of our direct successors reached
    1.79 +    // by exceptional control flow
    1.80 +    BitMap _exception_exit;
    1.81 +
    1.82 +    // These members hold the results of the last call to
    1.83 +    // compute_gen_kill_range().  _gen is the set of locals
    1.84 +    // used before they are defined in the range.  _kill is the
    1.85 +    // set of locals defined before they are used.
    1.86 +    BitMap _gen;
    1.87 +    BitMap _kill;
    1.88 +    int    _last_bci;
    1.89 +
    1.90 +    // A list of all blocks which could come directly before this one
    1.91 +    // in normal (non-exceptional) control flow.  We propagate liveness
    1.92 +    // information to these blocks.
    1.93 +    GrowableArray<BasicBlock*>* _normal_predecessors;
    1.94 +
    1.95 +    // A list of all blocks which could come directly before this one
    1.96 +    // in exceptional control flow.
    1.97 +    GrowableArray<BasicBlock*>* _exception_predecessors;
    1.98 +
    1.99 +    // The following fields are used to manage a work list used in the
   1.100 +    // dataflow.
   1.101 +    BasicBlock *_next;
   1.102 +    bool _on_work_list;
   1.103 +
   1.104 +    // Our successors call this method to merge liveness information into
   1.105 +    // our _normal_exit member.
   1.106 +    bool merge_normal(BitMap other);
   1.107 +
   1.108 +    // Our successors call this method to merge liveness information into
   1.109 +    // our _exception_exit member.
   1.110 +    bool merge_exception(BitMap other);
   1.111 +
   1.112 +    // This helper routine is used to help compute the gen/kill pair for
   1.113 +    // the block.  It is also used to answer queries.
   1.114 +    void compute_gen_kill_range(ciBytecodeStream *bytes);
   1.115 +
   1.116 +    // Compute the gen/kill effect of a single instruction.
   1.117 +    void compute_gen_kill_single(ciBytecodeStream *instruction);
   1.118 +
   1.119 +    // Helpers for compute_gen_kill_single.
   1.120 +    void load_one(int local);
   1.121 +    void load_two(int local);
   1.122 +    void store_one(int local);
   1.123 +    void store_two(int local);
   1.124 +
   1.125 +    BasicBlock(MethodLiveness *analyzer, int start, int limit);
   1.126 +
   1.127 +    // -- Accessors
   1.128 +
   1.129 +    int start_bci() const { return _start_bci; }
   1.130 +
   1.131 +    int limit_bci() const { return _limit_bci; }
   1.132 +    void set_limit_bci(int limit) { _limit_bci = limit; }
   1.133 +
   1.134 +    BasicBlock *next() const { return _next; }
   1.135 +    void set_next(BasicBlock *next) { _next = next; }
   1.136 +
   1.137 +    bool on_work_list() const { return _on_work_list; }
   1.138 +    void set_on_work_list(bool val) { _on_work_list = val; }
   1.139 +
   1.140 +    // -- Flow graph construction.
   1.141 +
   1.142 +    // Add a basic block to our list of normal predecessors.
   1.143 +    void add_normal_predecessor(BasicBlock *pred) {
   1.144 +      _normal_predecessors->append_if_missing(pred);
   1.145 +    }
   1.146 +
   1.147 +    // Add a basic block to our list of exceptional predecessors
   1.148 +    void add_exception_predecessor(BasicBlock *pred) {
   1.149 +      _exception_predecessors->append_if_missing(pred);
   1.150 +    }
   1.151 +
   1.152 +    // Split the basic block at splitBci.  This basic block
   1.153 +    // becomes the second half.  The first half is newly created.
   1.154 +    BasicBlock *split(int splitBci);
   1.155 +
   1.156 +    // -- Dataflow.
   1.157 +
   1.158 +    void compute_gen_kill(ciMethod* method);
   1.159 +
   1.160 +    // Propagate changes from this basic block
   1.161 +    void propagate(MethodLiveness *ml);
   1.162 +
   1.163 +    // -- Query.
   1.164 +
   1.165 +    MethodLivenessResult get_liveness_at(ciMethod* method, int bci);
   1.166 +
   1.167 +    // -- Debugging.
   1.168 +
   1.169 +    void print_on(outputStream *os) const PRODUCT_RETURN;
   1.170 +
   1.171 +  }; // End of MethodLiveness::BasicBlock
   1.172 +
   1.173 + private:
   1.174 +  // The method we are analyzing.
   1.175 +  ciMethod* _method;
   1.176 +  ciMethod* method() const { return _method; }
   1.177 +
   1.178 +  // The arena for storing structures...
   1.179 +  Arena*       _arena;
   1.180 +  Arena*       arena() const { return _arena; }
   1.181 +
   1.182 +  // We cache the length of the method.
   1.183 +  int _code_size;
   1.184 +
   1.185 +  // The size of a BitMap.
   1.186 +  int _bit_map_size_bits;
   1.187 +  int _bit_map_size_words;
   1.188 +
   1.189 +  // A list of all BasicBlocks.
   1.190 +  BasicBlock **_block_list;
   1.191 +
   1.192 +  // number of blocks
   1.193 +  int  _block_count;
   1.194 +
   1.195 +  // Keeps track of bci->block mapping.  One entry for each bci.  Only block starts are
   1.196 +  // recorded.
   1.197 +  GrowableArray<BasicBlock*>* _block_map;
   1.198 +
   1.199 +  // Our work list.
   1.200 +  BasicBlock *_work_list;
   1.201 +
   1.202 +#ifdef COMPILER1
   1.203 +  // bcis where blocks start are marked
   1.204 +  BitMap _bci_block_start;
   1.205 +#endif // COMPILER1
   1.206 +
   1.207 +  // -- Graph construction & Analysis
   1.208 +
   1.209 +  // Compute ranges and predecessors for basic blocks.
   1.210 +  void init_basic_blocks();
   1.211 +
   1.212 +  // Compute gen/kill information for all basic blocks.
   1.213 +  void init_gen_kill();
   1.214 +
   1.215 +  // Perform the dataflow.
   1.216 +  void propagate_liveness();
   1.217 +
   1.218 + // The class MethodLiveness::BasicBlock needs special access to some
   1.219 + // of our members.
   1.220 + friend class MethodLiveness::BasicBlock;
   1.221 +
   1.222 +  // And accessors.
   1.223 +  int bit_map_size_bits() const { return _bit_map_size_bits; }
   1.224 +  int bit_map_size_words() const { return _bit_map_size_words; }
   1.225 +
   1.226 +  // Work list manipulation routines.  Called internally by BasicBlock.
   1.227 +  BasicBlock *work_list_get();
   1.228 +  void work_list_add(BasicBlock *block);
   1.229 +
   1.230 +  // -- Timing and Statistics.
   1.231 +
   1.232 +
   1.233 +  // Timers
   1.234 +  static elapsedTimer _time_build_graph;
   1.235 +  static elapsedTimer _time_gen_kill;
   1.236 +  static elapsedTimer _time_flow;
   1.237 +  static elapsedTimer _time_query;
   1.238 +  static elapsedTimer _time_total;
   1.239 +
   1.240 +#ifndef PRODUCT
   1.241 +
   1.242 +  // Counts
   1.243 +  static long _total_bytes;
   1.244 +  static int  _total_methods;
   1.245 +
   1.246 +  static long _total_blocks;
   1.247 +  static int  _max_method_blocks;
   1.248 +
   1.249 +  static long _total_edges;
   1.250 +  static int  _max_block_edges;
   1.251 +
   1.252 +  static long _total_exc_edges;
   1.253 +  static int  _max_block_exc_edges;
   1.254 +
   1.255 +  static long _total_method_locals;
   1.256 +  static int  _max_method_locals;
   1.257 +
   1.258 +  static long _total_locals_queried;
   1.259 +  static long _total_live_locals_queried;
   1.260 +
   1.261 +  static long _total_visits;
   1.262 +
   1.263 +#endif
   1.264 +
   1.265 + public:
   1.266 +  // Create a liveness analyzer for a method
   1.267 +  MethodLiveness(Arena* arena, ciMethod* method);
   1.268 +
   1.269 +  // Compute liveness information for the method
   1.270 +  void compute_liveness();
   1.271 +
   1.272 +  // Find out which locals are live at a specific bci.
   1.273 +  MethodLivenessResult get_liveness_at(int bci);
   1.274 +
   1.275 +#ifdef COMPILER1
   1.276 +  const BitMap get_bci_block_start() const { return _bci_block_start; }
   1.277 +#endif // COMPILER1
   1.278 +
   1.279 +  static void print_times() PRODUCT_RETURN;
   1.280 +};
   1.281 +
   1.282 +#endif // SHARE_VM_COMPILER_METHODLIVENESS_HPP

mercurial