hotspot/src/share/vm/ci/bcEscapeAnalyzer.hpp
author kvn
Tue, 11 Mar 2008 19:00:38 -0700
changeset 218 a0e996680b05
parent 1 489c9b5090e2
child 251 cb2e73f71205
permissions -rw-r--r--
6667615: (Escape Analysis) extend MDO to cache arguments escape state Summary: Use MDO to cache arguments escape state determined by the byte code escape analyzer. Reviewed-by: never
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2005-2006 Sun Microsystems, Inc.  All Rights Reserved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
define_array(ciObjectArray, ciObject*);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
define_stack(ciObjectList, ciObjectArray);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
// This class implements a fast, conservative analysis of effect of methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
// on the escape state of their arguments.  The analysis is at the bytecode
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
// level.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
class  ciMethodBlocks;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
class  ciBlock;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
class BCEscapeAnalyzer : public ResourceObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  bool              _conservative; // If true, return maximally
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
                                   // conservative results.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  ciMethod*         _method;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  ciMethodData*     _methodData;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  int               _arg_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  intStack          _stack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  BitMap            _arg_local;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  BitMap            _arg_stack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  BitMap            _arg_returned;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  BitMap            _dirty;
218
a0e996680b05 6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents: 1
diff changeset
    49
  enum{ ARG_OFFSET_MAX = 31};
a0e996680b05 6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents: 1
diff changeset
    50
  uint              *_arg_modified;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  bool              _return_local;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  bool              _allocated_escapes;
218
a0e996680b05 6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents: 1
diff changeset
    54
  bool              _unknown_modified;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  bool              _return_allocated;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  ciObjectList     _dependencies;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  ciMethodBlocks   *_methodBlocks;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  BCEscapeAnalyzer* _parent;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  int               _level;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  class  ArgumentMap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  class  StateInfo;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  // helper functions
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  bool is_argument(int i)    { return i >= 0 && i < _arg_size; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  void raw_push(int i)       { _stack.push(i); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  int  raw_pop()             { return _stack.is_empty() ? -1 : _stack.pop(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  void apush(int i)          { raw_push(i); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  void spush()               { raw_push(-1); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  void lpush()               { spush(); spush(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  int  apop()                { return raw_pop(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  void spop()                { assert(_stack.is_empty() || _stack.top() == -1, ""); raw_pop(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  void lpop()                { spop(); spop(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  void set_returned(ArgumentMap vars);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  bool is_argument(ArgumentMap vars);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  bool is_arg_stack(ArgumentMap vars);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  void clear_bits(ArgumentMap vars, BitMap &bs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  void set_method_escape(ArgumentMap vars);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  void set_global_escape(ArgumentMap vars);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  void set_dirty(ArgumentMap vars);
218
a0e996680b05 6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents: 1
diff changeset
    86
  void set_modified(ArgumentMap vars, int offs, int size);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  bool is_recursive_call(ciMethod* callee);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  void add_dependence(ciKlass *klass, ciMethod *meth);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  void propagate_dependencies(ciMethod *meth);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  void invoke(StateInfo &state, Bytecodes::Code code, ciMethod* target, ciKlass* holder);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  void iterate_one_block(ciBlock *blk, StateInfo &state, GrowableArray<ciBlock *> &successors);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  void iterate_blocks(Arena *);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  void merge_block_states(StateInfo *blockstates, ciBlock *dest, StateInfo *s_state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  // analysis
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  void initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  void clear_escape_info();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  void compute_escape_info();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  vmIntrinsics::ID known_intrinsic();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  bool compute_escape_for_intrinsic(vmIntrinsics::ID iid);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  bool do_analysis();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  void read_escape_info();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  bool contains(uint arg_set1, uint arg_set2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  BCEscapeAnalyzer(ciMethod* method, BCEscapeAnalyzer* parent = NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  // accessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  ciMethod*         method() const               { return _method; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  ciMethodData*     methodData() const           { return _methodData; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  BCEscapeAnalyzer* parent() const               { return _parent; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  int               level() const                { return _level; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  ciObjectList*     dependencies()               { return &_dependencies; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  bool              has_dependencies() const     { return !_dependencies.is_empty(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  // retrieval of interprocedural escape information
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  // The given argument does not escape the callee.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  bool is_arg_local(int i) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    return !_conservative && _arg_local.at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  // The given argument escapes the callee, but does not become globally
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  // reachable.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  bool is_arg_stack(int i) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    return !_conservative && _arg_stack.at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  // The given argument does not escape globally, and may be returned.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  bool is_arg_returned(int i) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    return !_conservative && _arg_returned.at(i); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  // True iff only input arguments are returned.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  bool is_return_local() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    return !_conservative && _return_local;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  // True iff only newly allocated unescaped objects are returned.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  bool is_return_allocated() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    return !_conservative && _return_allocated && !_allocated_escapes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
218
a0e996680b05 6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents: 1
diff changeset
   147
  // Tracking of argument modification
a0e996680b05 6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents: 1
diff changeset
   148
a0e996680b05 6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents: 1
diff changeset
   149
  enum {OFFSET_ANY = -1};
a0e996680b05 6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents: 1
diff changeset
   150
  bool is_arg_modified(int arg, int offset, int size_in_bytes);
a0e996680b05 6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents: 1
diff changeset
   151
  void set_arg_modified(int arg, int offset, int size_in_bytes);
a0e996680b05 6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents: 1
diff changeset
   152
  bool has_non_arg_side_affects()    { return _unknown_modified; }
a0e996680b05 6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents: 1
diff changeset
   153
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  // Copy dependencies from this analysis into "deps"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  void copy_dependencies(Dependencies *deps);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
};