src/hotspot/share/c1/c1_ValueStack.hpp
author vromero
Mon, 08 Oct 2018 06:52:41 -0700
changeset 52038 957de5be48bc
parent 47216 71c04702a3d5
child 53028 b3830528df29
permissions -rw-r--r--
8209407: VerifyError is thrown for inner class with lambda Reviewed-by: mcimadamore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 36817
diff changeset
     2
 * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
1
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
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6748
diff changeset
    25
#ifndef SHARE_VM_C1_C1_VALUESTACK_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6748
diff changeset
    26
#define SHARE_VM_C1_C1_VALUESTACK_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6748
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6748
diff changeset
    28
#include "c1/c1_Instruction.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6748
diff changeset
    29
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
class ValueStack: public CompilationResourceObj {
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    31
 public:
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    32
  enum Kind {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    33
    Parsing,             // During abstract interpretation in GraphBuilder
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    34
    CallerState,         // Caller state when inlining
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    35
    StateBefore,         // Before before execution of instruction
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    36
    StateAfter,          // After execution of instruction
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    37
    ExceptionState,      // Exception handling of instruction
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    38
    EmptyExceptionState, // Exception handling of instructions not covered by an xhandler
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    39
    BlockBeginState      // State of BlockBegin instruction with phi functions of this block
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    40
  };
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    41
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  IRScope* _scope;                               // the enclosing scope
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    44
  ValueStack* _caller_state;
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    45
  int      _bci;
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    46
  Kind     _kind;
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    47
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  Values   _locals;                              // the locals
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  Values   _stack;                               // the expression stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  Values   _locks;                               // the monitor stack (holding the locked values)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  Value check(ValueTag tag, Value t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    assert(tag == t->type()->tag() || tag == objectTag && t->type()->tag() == addressTag, "types must correspond");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    return t;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  Value check(ValueTag tag, Value t, Value h) {
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    58
    assert(h == NULL, "hi-word of doubleword value must be NULL");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    return check(tag, t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  // helper routine
5707
6c66849ed24e 6958292: C1: Enable parallel compilation
iveresov
parents: 5547
diff changeset
    63
  static void apply(Values list, ValueVisitor* f);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    65
  // for simplified copying
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    66
  ValueStack(ValueStack* copy_from, Kind kind, int bci);
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    67
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  // creation
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    70
  ValueStack(IRScope* scope, ValueStack* caller_state);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    72
  ValueStack* copy()                             { return new ValueStack(this, _kind, _bci); }
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    73
  ValueStack* copy(Kind new_kind, int new_bci)   { return new ValueStack(this, new_kind, new_bci); }
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    74
  ValueStack* copy_for_parsing()                 { return new ValueStack(this, Parsing, -99); }
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    75
6748
5084ee905ab5 6987763: assert(kind() == EmptyExceptionState) failed: only EmptyExceptionStates can be modified
never
parents: 6745
diff changeset
    76
  void set_caller_state(ValueStack* s)           {
5084ee905ab5 6987763: assert(kind() == EmptyExceptionState) failed: only EmptyExceptionStates can be modified
never
parents: 6745
diff changeset
    77
    assert(kind() == EmptyExceptionState ||
22893
e3a2b513713a 8035493: JVMTI PopFrame capability must instruct compilers not to prune locals
mgronlun
parents: 13963
diff changeset
    78
           (Compilation::current()->env()->should_retain_local_variables() && kind() == ExceptionState),
6748
5084ee905ab5 6987763: assert(kind() == EmptyExceptionState) failed: only EmptyExceptionStates can be modified
never
parents: 6745
diff changeset
    79
           "only EmptyExceptionStates can be modified");
5084ee905ab5 6987763: assert(kind() == EmptyExceptionState) failed: only EmptyExceptionStates can be modified
never
parents: 6745
diff changeset
    80
    _caller_state = s;
5084ee905ab5 6987763: assert(kind() == EmptyExceptionState) failed: only EmptyExceptionStates can be modified
never
parents: 6745
diff changeset
    81
  }
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    82
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  bool is_same(ValueStack* s);                   // returns true if this & s's types match (w/o checking locals)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  // accessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  IRScope* scope() const                         { return _scope; }
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    87
  ValueStack* caller_state() const               { return _caller_state; }
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    88
  int bci() const                                { return _bci; }
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    89
  Kind kind() const                              { return _kind; }
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    90
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  int locals_size() const                        { return _locals.length(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  int stack_size() const                         { return _stack.length(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  int locks_size() const                         { return _locks.length(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  bool stack_is_empty() const                    { return _stack.is_empty(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  bool no_active_locks() const                   { return _locks.is_empty(); }
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    96
  int total_locks_size() const;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  // locals access
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  void clear_locals();                           // sets all locals to NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  void invalidate_local(int i) {
36817
57ce0a76b6b0 8151818: C1: LIRGenerator::move_to_phi can't deal with illegal phi
mdoerr
parents: 22893
diff changeset
   102
    assert(!_locals.at(i)->type()->is_double_word() ||
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   103
           _locals.at(i + 1) == NULL, "hi-word of doubleword value must be NULL");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    _locals.at_put(i, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   107
  Value local_at(int i) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    Value x = _locals.at(i);
36817
57ce0a76b6b0 8151818: C1: LIRGenerator::move_to_phi can't deal with illegal phi
mdoerr
parents: 22893
diff changeset
   109
    assert(x == NULL || !x->type()->is_double_word() ||
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   110
           _locals.at(i + 1) == NULL, "hi-word of doubleword value must be NULL");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    return x;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  void store_local(int i, Value x) {
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   115
    // When overwriting local i, check if i - 1 was the start of a
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   116
    // double word local and kill it.
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
    }
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   123
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   124
    _locals.at_put(i, x);
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   125
    if (x->type()->is_double_word()) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   126
      // hi-word of doubleword value is always NULL
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   127
      _locals.at_put(i + 1, NULL);
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   128
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  // stack access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  Value stack_at(int i) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    Value x = _stack.at(i);
36817
57ce0a76b6b0 8151818: C1: LIRGenerator::move_to_phi can't deal with illegal phi
mdoerr
parents: 22893
diff changeset
   134
    assert(!x->type()->is_double_word() ||
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   135
           _stack.at(i + 1) == NULL, "hi-word of doubleword value must be NULL");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
    return x;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  Value stack_at_inc(int& i) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    Value x = stack_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    i += x->type()->size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
    return x;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 7397
diff changeset
   145
  void stack_at_put(int i, Value x) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 7397
diff changeset
   146
    _stack.at_put(i, x);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 7397
diff changeset
   147
  }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 7397
diff changeset
   148
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  // pinning support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  void pin_stack_for_linear_scan();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  // iteration
5707
6c66849ed24e 6958292: C1: Enable parallel compilation
iveresov
parents: 5547
diff changeset
   153
  void values_do(ValueVisitor* f);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  // untyped manipulation (for dup_x1, etc.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  void truncate_stack(int size)                  { _stack.trunc_to(size); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  void raw_push(Value t)                         { _stack.push(t); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  Value raw_pop()                                { return _stack.pop(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  // typed manipulation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  void ipush(Value t)                            { _stack.push(check(intTag    , t)); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  void fpush(Value t)                            { _stack.push(check(floatTag  , t)); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  void apush(Value t)                            { _stack.push(check(objectTag , t)); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  void rpush(Value t)                            { _stack.push(check(addressTag, t)); }
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
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  void push(ValueType* type, Value t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
    switch (type->tag()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
      case intTag    : ipush(t); return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
      case longTag   : lpush(t); return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
      case floatTag  : fpush(t); return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
      case doubleTag : dpush(t); return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
      case objectTag : apush(t); return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
      case addressTag: rpush(t); return;
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 36817
diff changeset
   176
      default        : ShouldNotReachHere(); return;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  Value ipop()                                   { return check(intTag    , _stack.pop()); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  Value fpop()                                   { return check(floatTag  , _stack.pop()); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  Value apop()                                   { return check(objectTag , _stack.pop()); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  Value rpop()                                   { return check(addressTag, _stack.pop()); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  Value lpop()                                   { Value h = _stack.pop(); return check(longTag  , _stack.pop(), h); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  Value dpop()                                   { Value h = _stack.pop(); return check(doubleTag, _stack.pop(), h); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  Value pop(ValueType* type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
    switch (type->tag()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
      case intTag    : return ipop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
      case longTag   : return lpop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
      case floatTag  : return fpop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
      case doubleTag : return dpop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
      case objectTag : return apop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
      case addressTag: return rpop();
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 36817
diff changeset
   195
      default        : ShouldNotReachHere(); return NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  Values* pop_arguments(int argument_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  // locks access
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   202
  int lock  (Value obj);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  int unlock();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  Value lock_at(int i) const                     { return _locks.at(i); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  // SSA form IR support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  void setup_phi_for_stack(BlockBegin* b, int index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  void setup_phi_for_local(BlockBegin* b, int index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  // debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  void print()  PRODUCT_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  void verify() PRODUCT_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
// Macro definitions for simple iteration of stack and local values of a ValueStack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
// The macros can be used like a for-loop. All variables (state, index and value)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
// must be defined before the loop.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
// When states are nested because of inlining, the stack of the innermost state
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
// cumulates also the stack of the nested states. In contrast, the locals of all
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
// states must be iterated each.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
// Use the following code pattern to iterate all stack values and all nested local values:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
// ValueStack* state = ...   // state that is iterated
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
// int index;                // current loop index (overwritten in loop)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
// Value value;              // value at current loop index (overwritten in loop)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
// for_each_stack_value(state, index, value {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
//   do something with value and index
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
// }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
// for_each_state(state) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
//   for_each_local_value(state, index, value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
//     do something with value and index
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
//   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
// }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
// as an invariant, state is NULL now
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
// construct a unique variable name with the line number where the macro is used
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
#define temp_var3(x) temp__ ## x
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
#define temp_var2(x) temp_var3(x)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
#define temp_var     temp_var2(__LINE__)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
#define for_each_state(state)  \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  for (; state != NULL; state = state->caller_state())
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
#define for_each_local_value(state, index, value)                                              \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  int temp_var = state->locals_size();                                                         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  for (index = 0;                                                                              \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
       index < temp_var && (value = state->local_at(index), true);                             \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
       index += (value == NULL || value->type()->is_illegal() ? 1 : value->type()->size()))    \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
    if (value != NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
#define for_each_stack_value(state, index, value)                                              \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  int temp_var = state->stack_size();                                                          \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  for (index = 0;                                                                              \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
       index < temp_var && (value = state->stack_at(index), true);                             \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
       index += value->type()->size())
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
#define for_each_lock_value(state, index, value)                                               \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  int temp_var = state->locks_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->lock_at(index), true);                              \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
       index++)                                                                                \
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
// Macro definition for simple iteration of all state values of a ValueStack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
// Because the code cannot be executed in a single loop, the code must be passed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
// as a macro parameter.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
// Use the following code pattern to iterate all stack values and all nested local values:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
// ValueStack* state = ...   // state that is iterated
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
// for_each_state_value(state, value,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
//   do something with value (note that this is a macro parameter)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
// );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
#define for_each_state_value(v_state, v_value, v_code)                                         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
{                                                                                              \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  int cur_index;                                                                               \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  ValueStack* cur_state = v_state;                                                             \
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   286
  Value v_value;                                                                               \
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   287
  for_each_state(cur_state) {                                                                  \
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   288
    {                                                                                            \
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   289
      for_each_local_value(cur_state, cur_index, v_value) {                                      \
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   290
        v_code;                                                                                  \
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   291
      }                                                                                          \
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
    }                                                                                          \
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   293
    {                                                                                            \
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   294
      for_each_stack_value(cur_state, cur_index, v_value) {                                      \
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   295
        v_code;                                                                                  \
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   296
      }                                                                                          \
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   297
    }                                                                                            \
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  }                                                                                            \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
// Macro definition for simple iteration of all phif functions of a block, i.e all
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
// phi functions of the ValueStack where the block matches.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
// Use the following code pattern to iterate all phi functions of a block:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
// BlockBegin* block = ...   // block that is iterated
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
// for_each_phi_function(block, phi,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
//   do something with the phi function phi (note that this is a macro parameter)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
// );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
#define for_each_phi_fun(v_block, v_phi, v_code)                                               \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
{                                                                                              \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  int cur_index;                                                                               \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  ValueStack* cur_state = v_block->state();                                                    \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
  Value value;                                                                                 \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  {                                                                                            \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
    for_each_stack_value(cur_state, cur_index, value) {                                        \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
      Phi* v_phi = value->as_Phi();                                                      \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
      if (v_phi != NULL && v_phi->block() == v_block) {                                        \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
        v_code;                                                                                \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
      }                                                                                        \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
    }                                                                                          \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  }                                                                                            \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  {                                                                                            \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
    for_each_local_value(cur_state, cur_index, value) {                                        \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
      Phi* v_phi = value->as_Phi();                                                      \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
      if (v_phi != NULL && v_phi->block() == v_block) {                                        \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
        v_code;                                                                                \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
      }                                                                                        \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
    }                                                                                          \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
  }                                                                                            \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
}
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6748
diff changeset
   333
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6748
diff changeset
   334
#endif // SHARE_VM_C1_C1_VALUESTACK_HPP