hotspot/src/share/vm/c1/c1_ValueStack.hpp
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1 489c9b5090e2
child 5547 f4b087cbb361
permissions -rw-r--r--
Initial load
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 1999-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
class ValueStack: public CompilationResourceObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
  IRScope* _scope;                               // the enclosing scope
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
  bool     _lock_stack;                          // indicates that this ValueStack is for an exception site
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
  Values   _locals;                              // the locals
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
  Values   _stack;                               // the expression stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
  Values   _locks;                               // the monitor stack (holding the locked values)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  Value check(ValueTag tag, Value t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
    assert(tag == t->type()->tag() || tag == objectTag && t->type()->tag() == addressTag, "types must correspond");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
    return t;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  Value check(ValueTag tag, Value t, Value h) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
    assert(h->as_HiWord()->lo_word() == t, "incorrect stack pair");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
    return check(tag, t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  // helper routine
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  static void apply(Values list, void f(Value*));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  // creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  ValueStack(IRScope* scope, int locals_size, int max_stack_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  // merging
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  ValueStack* copy();                            // returns a copy of this w/ cleared locals
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  ValueStack* copy_locks();                      // returns a copy of this w/ cleared locals and stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
                                                 // Note that when inlining of methods with exception
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
                                                 // handlers is enabled, this stack may have a
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
                                                 // non-empty expression stack (size defined by
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
                                                 // scope()->lock_stack_size())
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  bool is_same(ValueStack* s);                   // returns true if this & s's types match (w/o checking locals)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  bool is_same_across_scopes(ValueStack* s);     // same as is_same but returns true even if stacks are in different scopes (used for block merging w/inlining)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  // accessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  IRScope* scope() const                         { return _scope; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  bool is_lock_stack() const                     { return _lock_stack; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  int locals_size() const                        { return _locals.length(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  int stack_size() const                         { return _stack.length(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  int locks_size() const                         { return _locks.length(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  int max_stack_size() const                     { return _stack.capacity(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  bool stack_is_empty() const                    { return _stack.is_empty(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  bool no_active_locks() const                   { return _locks.is_empty(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  ValueStack* caller_state() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  // locals access
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  void clear_locals();                           // sets all locals to NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  // Kill local i.  Also kill local i+1 if i was a long or double.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  void invalidate_local(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    Value x = _locals.at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    if (x != NULL && x->type()->is_double_word()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
      assert(_locals.at(i + 1)->as_HiWord()->lo_word() == x, "locals inconsistent");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
      _locals.at_put(i + 1, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    _locals.at_put(i, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  Value load_local(int i) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    Value x = _locals.at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    if (x != NULL && x->type()->is_illegal()) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    assert(x == NULL || x->as_HiWord() == NULL, "index points to hi word");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    assert(x == NULL || x->type()->is_illegal() || x->type()->is_single_word() || x == _locals.at(i+1)->as_HiWord()->lo_word(), "locals inconsistent");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    return x;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  Value local_at(int i) const { return _locals.at(i); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  // Store x into local i.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  void store_local(int i, Value x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    // Kill the old value
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
    invalidate_local(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    _locals.at_put(i, x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    // Writing a double word can kill other locals
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    if (x != NULL && x->type()->is_double_word()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
      // If x + i was the start of a double word local then kill i + 2.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
      Value x2 = _locals.at(i + 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
      if (x2 != NULL && x2->type()->is_double_word()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
        _locals.at_put(i + 2, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
      // If x is a double word local, also update i + 1.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
      _locals.at_put(i + 1, x->hi_word());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
      _locals.at_put(i + 1, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    // If x - 1 was the start of a double word local then kill i - 1.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    if (i > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
      Value prev = _locals.at(i - 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
      if (prev != NULL && prev->type()->is_double_word()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
        _locals.at_put(i - 1, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  void replace_locals(ValueStack* with);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  // stack access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  Value stack_at(int i) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    Value x = _stack.at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    assert(x->as_HiWord() == NULL, "index points to hi word");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    assert(x->type()->is_single_word() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
           x->subst() == _stack.at(i+1)->as_HiWord()->lo_word(), "stack inconsistent");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    return x;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  Value stack_at_inc(int& i) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
    Value x = stack_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    i += x->type()->size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    return x;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  // pinning support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  void pin_stack_for_linear_scan();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  // iteration
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  void values_do(void f(Value*));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  // untyped manipulation (for dup_x1, etc.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  void clear_stack()                             { _stack.clear(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  void truncate_stack(int size)                  { _stack.trunc_to(size); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  void raw_push(Value t)                         { _stack.push(t); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  Value raw_pop()                                { return _stack.pop(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  // typed manipulation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  void ipush(Value t)                            { _stack.push(check(intTag    , t)); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  void fpush(Value t)                            { _stack.push(check(floatTag  , t)); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  void apush(Value t)                            { _stack.push(check(objectTag , t)); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  void rpush(Value t)                            { _stack.push(check(addressTag, t)); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  // in debug mode, use HiWord for 2-word values
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  void lpush(Value t)                            { _stack.push(check(longTag   , t)); _stack.push(new HiWord(t)); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  void dpush(Value t)                            { _stack.push(check(doubleTag , t)); _stack.push(new HiWord(t)); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  // in optimized mode, use NULL for 2-word values
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  void lpush(Value t)                            { _stack.push(check(longTag   , t)); _stack.push(NULL); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  void dpush(Value t)                            { _stack.push(check(doubleTag , t)); _stack.push(NULL); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
#endif // ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  void push(ValueType* type, Value t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    switch (type->tag()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
      case intTag    : ipush(t); return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
      case longTag   : lpush(t); return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
      case floatTag  : fpush(t); return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
      case doubleTag : dpush(t); return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
      case objectTag : apush(t); return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
      case addressTag: rpush(t); return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  Value ipop()                                   { return check(intTag    , _stack.pop()); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  Value fpop()                                   { return check(floatTag  , _stack.pop()); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  Value apop()                                   { return check(objectTag , _stack.pop()); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  Value rpop()                                   { return check(addressTag, _stack.pop()); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  // in debug mode, check for HiWord consistency
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  Value lpop()                                   { Value h = _stack.pop(); return check(longTag  , _stack.pop(), h); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  Value dpop()                                   { Value h = _stack.pop(); return check(doubleTag, _stack.pop(), h); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  // in optimized mode, ignore HiWord since it is NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  Value lpop()                                   { _stack.pop(); return check(longTag  , _stack.pop()); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  Value dpop()                                   { _stack.pop(); return check(doubleTag, _stack.pop()); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
#endif // ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  Value pop(ValueType* type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
    switch (type->tag()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
      case intTag    : return ipop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
      case longTag   : return lpop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
      case floatTag  : return fpop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
      case doubleTag : return dpop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
      case objectTag : return apop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
      case addressTag: return rpop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
    ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  Values* pop_arguments(int argument_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  // locks access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  int lock  (IRScope* scope, Value obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  int unlock();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  Value lock_at(int i) const                     { return _locks.at(i); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  // Inlining support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  ValueStack* push_scope(IRScope* scope);         // "Push" new scope, returning new resulting stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
                                                  // Preserves stack and locks, destroys locals
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  ValueStack* pop_scope();                        // "Pop" topmost scope, returning new resulting stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
                                                  // Preserves stack and locks, destroys locals
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  // SSA form IR support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  void setup_phi_for_stack(BlockBegin* b, int index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  void setup_phi_for_local(BlockBegin* b, int index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  // debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  void print()  PRODUCT_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  void verify() PRODUCT_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
// Macro definitions for simple iteration of stack and local values of a ValueStack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
// The macros can be used like a for-loop. All variables (state, index and value)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
// must be defined before the loop.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
// When states are nested because of inlining, the stack of the innermost state
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
// cumulates also the stack of the nested states. In contrast, the locals of all
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
// states must be iterated each.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
// Use the following code pattern to iterate all stack values and all nested local values:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
// ValueStack* state = ...   // state that is iterated
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
// int index;                // current loop index (overwritten in loop)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
// Value value;              // value at current loop index (overwritten in loop)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
// for_each_stack_value(state, index, value {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
//   do something with value and index
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
// }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
// for_each_state(state) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
//   for_each_local_value(state, index, value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
//     do something with value and index
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
//   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
// }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
// as an invariant, state is NULL now
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
// construct a unique variable name with the line number where the macro is used
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
#define temp_var3(x) temp__ ## x
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
#define temp_var2(x) temp_var3(x)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
#define temp_var     temp_var2(__LINE__)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
#define for_each_state(state)  \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  for (; state != NULL; state = state->caller_state())
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
#define for_each_local_value(state, index, value)                                              \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  int temp_var = state->locals_size();                                                         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  for (index = 0;                                                                              \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
       index < temp_var && (value = state->local_at(index), true);                             \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
       index += (value == NULL || value->type()->is_illegal() ? 1 : value->type()->size()))    \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
    if (value != NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
#define for_each_stack_value(state, index, value)                                              \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  int temp_var = state->stack_size();                                                          \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  for (index = 0;                                                                              \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
       index < temp_var && (value = state->stack_at(index), true);                             \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
       index += value->type()->size())
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
#define for_each_lock_value(state, index, value)                                               \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  int temp_var = state->locks_size();                                                          \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  for (index = 0;                                                                              \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
       index < temp_var && (value = state->lock_at(index), true);                              \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
       index++)                                                                                \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
    if (value != NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
// Macro definition for simple iteration of all state values of a ValueStack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
// Because the code cannot be executed in a single loop, the code must be passed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
// as a macro parameter.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
// Use the following code pattern to iterate all stack values and all nested local values:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
// ValueStack* state = ...   // state that is iterated
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
// for_each_state_value(state, value,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
//   do something with value (note that this is a macro parameter)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
// );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
#define for_each_state_value(v_state, v_value, v_code)                                         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
{                                                                                              \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  int cur_index;                                                                               \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  ValueStack* cur_state = v_state;                                                             \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  Value v_value;                                                                                 \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
  {                                                                                            \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
    for_each_stack_value(cur_state, cur_index, v_value) {                                      \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
      v_code;                                                                                  \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
    }                                                                                          \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  }                                                                                            \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  for_each_state(cur_state) {                                                                  \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
    for_each_local_value(cur_state, cur_index, v_value) {                                      \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
      v_code;                                                                                  \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
    }                                                                                          \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
  }                                                                                            \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
// Macro definition for simple iteration of all phif functions of a block, i.e all
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
// phi functions of the ValueStack where the block matches.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
// Use the following code pattern to iterate all phi functions of a block:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
// BlockBegin* block = ...   // block that is iterated
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
// for_each_phi_function(block, phi,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
//   do something with the phi function phi (note that this is a macro parameter)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
// );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
#define for_each_phi_fun(v_block, v_phi, v_code)                                               \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
{                                                                                              \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
  int cur_index;                                                                               \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  ValueStack* cur_state = v_block->state();                                                    \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
  Value value;                                                                                 \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  {                                                                                            \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
    for_each_stack_value(cur_state, cur_index, value) {                                        \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
      Phi* v_phi = value->as_Phi();                                                      \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
      if (v_phi != NULL && v_phi->block() == v_block) {                                        \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
        v_code;                                                                                \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
      }                                                                                        \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
    }                                                                                          \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  }                                                                                            \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
  {                                                                                            \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
    for_each_local_value(cur_state, cur_index, value) {                                        \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
      Phi* v_phi = value->as_Phi();                                                      \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
      if (v_phi != NULL && v_phi->block() == v_block) {                                        \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
        v_code;                                                                                \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
      }                                                                                        \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
    }                                                                                          \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  }                                                                                            \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
}