annotate src/hotspot/share/c1/c1_ValueStack.hpp @ 54077:b4f4778cf3d9

8220515: Revert removal of for_each_lock_value removal Reviewed-by: thartmann
author redestad
date Tue, 12 Mar 2019 16:18:31 +0100
parents 9c6508806663
children
rev   line source
duke@1 1 /*
coleenp@53244 2 * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
duke@1 7 * published by the Free Software Foundation.
duke@1 8 *
duke@1 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 13 * accompanied this code).
duke@1 14 *
duke@1 15 * You should have received a copy of the GNU General Public License version
duke@1 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 18 *
trims@5547 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@5547 20 * or visit www.oracle.com if you need additional information or have any
trims@5547 21 * questions.
duke@1 22 *
duke@1 23 */
duke@1 24
coleenp@53244 25 #ifndef SHARE_C1_C1_VALUESTACK_HPP
coleenp@53244 26 #define SHARE_C1_C1_VALUESTACK_HPP
stefank@7397 27
stefank@7397 28 #include "c1/c1_Instruction.hpp"
stefank@7397 29
duke@1 30 class ValueStack: public CompilationResourceObj {
roland@6745 31 public:
roland@6745 32 enum Kind {
roland@6745 33 Parsing, // During abstract interpretation in GraphBuilder
roland@6745 34 CallerState, // Caller state when inlining
roland@6745 35 StateBefore, // Before before execution of instruction
roland@6745 36 StateAfter, // After execution of instruction
roland@6745 37 ExceptionState, // Exception handling of instruction
roland@6745 38 EmptyExceptionState, // Exception handling of instructions not covered by an xhandler
roland@6745 39 BlockBeginState // State of BlockBegin instruction with phi functions of this block
roland@6745 40 };
roland@6745 41
duke@1 42 private:
duke@1 43 IRScope* _scope; // the enclosing scope
roland@6745 44 ValueStack* _caller_state;
roland@6745 45 int _bci;
roland@6745 46 Kind _kind;
roland@6745 47
duke@1 48 Values _locals; // the locals
duke@1 49 Values _stack; // the expression stack
redestad@54074 50 Values* _locks; // the monitor stack (holding the locked values)
duke@1 51
duke@1 52 Value check(ValueTag tag, Value t) {
duke@1 53 assert(tag == t->type()->tag() || tag == objectTag && t->type()->tag() == addressTag, "types must correspond");
duke@1 54 return t;
duke@1 55 }
duke@1 56
duke@1 57 Value check(ValueTag tag, Value t, Value h) {
roland@6745 58 assert(h == NULL, "hi-word of doubleword value must be NULL");
duke@1 59 return check(tag, t);
duke@1 60 }
duke@1 61
duke@1 62 // helper routine
redestad@54074 63 static void apply(const Values& list, ValueVisitor* f);
duke@1 64
roland@6745 65 // for simplified copying
roland@6745 66 ValueStack(ValueStack* copy_from, Kind kind, int bci);
roland@6745 67
duke@1 68 public:
duke@1 69 // creation
roland@6745 70 ValueStack(IRScope* scope, ValueStack* caller_state);
duke@1 71
roland@6745 72 ValueStack* copy() { return new ValueStack(this, _kind, _bci); }
roland@6745 73 ValueStack* copy(Kind new_kind, int new_bci) { return new ValueStack(this, new_kind, new_bci); }
roland@6745 74 ValueStack* copy_for_parsing() { return new ValueStack(this, Parsing, -99); }
roland@6745 75
never@6748 76 void set_caller_state(ValueStack* s) {
never@6748 77 assert(kind() == EmptyExceptionState ||
mgronlun@22893 78 (Compilation::current()->env()->should_retain_local_variables() && kind() == ExceptionState),
never@6748 79 "only EmptyExceptionStates can be modified");
never@6748 80 _caller_state = s;
never@6748 81 }
roland@6745 82
duke@1 83 bool is_same(ValueStack* s); // returns true if this & s's types match (w/o checking locals)
duke@1 84
duke@1 85 // accessors
duke@1 86 IRScope* scope() const { return _scope; }
roland@6745 87 ValueStack* caller_state() const { return _caller_state; }
roland@6745 88 int bci() const { return _bci; }
roland@6745 89 Kind kind() const { return _kind; }
roland@6745 90
duke@1 91 int locals_size() const { return _locals.length(); }
duke@1 92 int stack_size() const { return _stack.length(); }
redestad@54074 93 int locks_size() const { return _locks == NULL ? 0 : _locks->length(); }
duke@1 94 bool stack_is_empty() const { return _stack.is_empty(); }
redestad@54074 95 bool no_active_locks() const { return _locks == NULL || _locks->is_empty(); }
roland@6745 96 int total_locks_size() const;
duke@1 97
duke@1 98 // locals access
duke@1 99 void clear_locals(); // sets all locals to NULL;
duke@1 100
duke@1 101 void invalidate_local(int i) {
mdoerr@36817 102 assert(!_locals.at(i)->type()->is_double_word() ||
roland@6745 103 _locals.at(i + 1) == NULL, "hi-word of doubleword value must be NULL");
duke@1 104 _locals.at_put(i, NULL);
duke@1 105 }
duke@1 106
roland@6745 107 Value local_at(int i) const {
duke@1 108 Value x = _locals.at(i);
mdoerr@36817 109 assert(x == NULL || !x->type()->is_double_word() ||
roland@6745 110 _locals.at(i + 1) == NULL, "hi-word of doubleword value must be NULL");
duke@1 111 return x;
duke@1 112 }
duke@1 113
duke@1 114 void store_local(int i, Value x) {
roland@6745 115 // When overwriting local i, check if i - 1 was the start of a
roland@6745 116 // double word local and kill it.
duke@1 117 if (i > 0) {
duke@1 118 Value prev = _locals.at(i - 1);
duke@1 119 if (prev != NULL && prev->type()->is_double_word()) {
duke@1 120 _locals.at_put(i - 1, NULL);
duke@1 121 }
duke@1 122 }
roland@6745 123
roland@6745 124 _locals.at_put(i, x);
roland@6745 125 if (x->type()->is_double_word()) {
roland@6745 126 // hi-word of doubleword value is always NULL
roland@6745 127 _locals.at_put(i + 1, NULL);
roland@6745 128 }
duke@1 129 }
duke@1 130
duke@1 131 // stack access
duke@1 132 Value stack_at(int i) const {
duke@1 133 Value x = _stack.at(i);
mdoerr@36817 134 assert(!x->type()->is_double_word() ||
roland@6745 135 _stack.at(i + 1) == NULL, "hi-word of doubleword value must be NULL");
duke@1 136 return x;
duke@1 137 }
duke@1 138
duke@1 139 Value stack_at_inc(int& i) const {
duke@1 140 Value x = stack_at(i);
duke@1 141 i += x->type()->size();
duke@1 142 return x;
duke@1 143 }
duke@1 144
twisti@13391 145 void stack_at_put(int i, Value x) {
twisti@13391 146 _stack.at_put(i, x);
twisti@13391 147 }
twisti@13391 148
duke@1 149 // pinning support
duke@1 150 void pin_stack_for_linear_scan();
duke@1 151
duke@1 152 // iteration
iveresov@5707 153 void values_do(ValueVisitor* f);
duke@1 154
duke@1 155 // untyped manipulation (for dup_x1, etc.)
duke@1 156 void truncate_stack(int size) { _stack.trunc_to(size); }
duke@1 157 void raw_push(Value t) { _stack.push(t); }
duke@1 158 Value raw_pop() { return _stack.pop(); }
duke@1 159
duke@1 160 // typed manipulation
duke@1 161 void ipush(Value t) { _stack.push(check(intTag , t)); }
duke@1 162 void fpush(Value t) { _stack.push(check(floatTag , t)); }
duke@1 163 void apush(Value t) { _stack.push(check(objectTag , t)); }
duke@1 164 void rpush(Value t) { _stack.push(check(addressTag, t)); }
duke@1 165 void lpush(Value t) { _stack.push(check(longTag , t)); _stack.push(NULL); }
duke@1 166 void dpush(Value t) { _stack.push(check(doubleTag , t)); _stack.push(NULL); }
duke@1 167
duke@1 168 void push(ValueType* type, Value t) {
duke@1 169 switch (type->tag()) {
duke@1 170 case intTag : ipush(t); return;
duke@1 171 case longTag : lpush(t); return;
duke@1 172 case floatTag : fpush(t); return;
duke@1 173 case doubleTag : dpush(t); return;
duke@1 174 case objectTag : apush(t); return;
duke@1 175 case addressTag: rpush(t); return;
jwilhelm@46630 176 default : ShouldNotReachHere(); return;
duke@1 177 }
duke@1 178 }
duke@1 179
duke@1 180 Value ipop() { return check(intTag , _stack.pop()); }
duke@1 181 Value fpop() { return check(floatTag , _stack.pop()); }
duke@1 182 Value apop() { return check(objectTag , _stack.pop()); }
duke@1 183 Value rpop() { return check(addressTag, _stack.pop()); }
duke@1 184 Value lpop() { Value h = _stack.pop(); return check(longTag , _stack.pop(), h); }
duke@1 185 Value dpop() { Value h = _stack.pop(); return check(doubleTag, _stack.pop(), h); }
duke@1 186
duke@1 187 Value pop(ValueType* type) {
duke@1 188 switch (type->tag()) {
duke@1 189 case intTag : return ipop();
duke@1 190 case longTag : return lpop();
duke@1 191 case floatTag : return fpop();
duke@1 192 case doubleTag : return dpop();
duke@1 193 case objectTag : return apop();
duke@1 194 case addressTag: return rpop();
jwilhelm@46630 195 default : ShouldNotReachHere(); return NULL;
duke@1 196 }
duke@1 197 }
duke@1 198
duke@1 199 Values* pop_arguments(int argument_size);
duke@1 200
duke@1 201 // locks access
roland@6745 202 int lock (Value obj);
duke@1 203 int unlock();
redestad@54074 204 Value lock_at(int i) const { return _locks->at(i); }
duke@1 205
duke@1 206 // SSA form IR support
duke@1 207 void setup_phi_for_stack(BlockBegin* b, int index);
duke@1 208 void setup_phi_for_local(BlockBegin* b, int index);
duke@1 209
duke@1 210 // debugging
duke@1 211 void print() PRODUCT_RETURN;
duke@1 212 void verify() PRODUCT_RETURN;
duke@1 213 };
duke@1 214
duke@1 215
duke@1 216
duke@1 217 // Macro definitions for simple iteration of stack and local values of a ValueStack
duke@1 218 // The macros can be used like a for-loop. All variables (state, index and value)
duke@1 219 // must be defined before the loop.
duke@1 220 // When states are nested because of inlining, the stack of the innermost state
duke@1 221 // cumulates also the stack of the nested states. In contrast, the locals of all
duke@1 222 // states must be iterated each.
duke@1 223 // Use the following code pattern to iterate all stack values and all nested local values:
duke@1 224 //
duke@1 225 // ValueStack* state = ... // state that is iterated
duke@1 226 // int index; // current loop index (overwritten in loop)
duke@1 227 // Value value; // value at current loop index (overwritten in loop)
duke@1 228 //
duke@1 229 // for_each_stack_value(state, index, value {
duke@1 230 // do something with value and index
duke@1 231 // }
duke@1 232 //
duke@1 233 // for_each_state(state) {
duke@1 234 // for_each_local_value(state, index, value) {
duke@1 235 // do something with value and index
duke@1 236 // }
duke@1 237 // }
duke@1 238 // as an invariant, state is NULL now
duke@1 239
duke@1 240
duke@1 241 // construct a unique variable name with the line number where the macro is used
duke@1 242 #define temp_var3(x) temp__ ## x
duke@1 243 #define temp_var2(x) temp_var3(x)
duke@1 244 #define temp_var temp_var2(__LINE__)
duke@1 245
duke@1 246 #define for_each_state(state) \
duke@1 247 for (; state != NULL; state = state->caller_state())
duke@1 248
duke@1 249 #define for_each_local_value(state, index, value) \
duke@1 250 int temp_var = state->locals_size(); \
duke@1 251 for (index = 0; \
duke@1 252 index < temp_var && (value = state->local_at(index), true); \
duke@1 253 index += (value == NULL || value->type()->is_illegal() ? 1 : value->type()->size())) \
duke@1 254 if (value != NULL)
duke@1 255
duke@1 256
duke@1 257 #define for_each_stack_value(state, index, value) \
duke@1 258 int temp_var = state->stack_size(); \
duke@1 259 for (index = 0; \
duke@1 260 index < temp_var && (value = state->stack_at(index), true); \
duke@1 261 index += value->type()->size())
duke@1 262
duke@1 263
redestad@54077 264 #define for_each_lock_value(state, index, value) \
redestad@54077 265 int temp_var = state->locks_size(); \
redestad@54077 266 for (index = 0; \
redestad@54077 267 index < temp_var && (value = state->lock_at(index), true); \
redestad@54077 268 index++) \
redestad@54077 269 if (value != NULL)
redestad@54077 270
redestad@54077 271
duke@1 272 // Macro definition for simple iteration of all state values of a ValueStack
duke@1 273 // Because the code cannot be executed in a single loop, the code must be passed
duke@1 274 // as a macro parameter.
duke@1 275 // Use the following code pattern to iterate all stack values and all nested local values:
duke@1 276 //
duke@1 277 // ValueStack* state = ... // state that is iterated
duke@1 278 // for_each_state_value(state, value,
duke@1 279 // do something with value (note that this is a macro parameter)
duke@1 280 // );
duke@1 281
duke@1 282 #define for_each_state_value(v_state, v_value, v_code) \
duke@1 283 { \
duke@1 284 int cur_index; \
duke@1 285 ValueStack* cur_state = v_state; \
roland@6745 286 Value v_value; \
roland@6745 287 for_each_state(cur_state) { \
roland@6745 288 { \
roland@6745 289 for_each_local_value(cur_state, cur_index, v_value) { \
roland@6745 290 v_code; \
roland@6745 291 } \
duke@1 292 } \
roland@6745 293 { \
roland@6745 294 for_each_stack_value(cur_state, cur_index, v_value) { \
roland@6745 295 v_code; \
roland@6745 296 } \
roland@6745 297 } \
duke@1 298 } \
duke@1 299 }
duke@1 300
duke@1 301
mdoerr@53028 302 // Macro definition for simple iteration of all phi functions of a block, i.e all
duke@1 303 // phi functions of the ValueStack where the block matches.
duke@1 304 // Use the following code pattern to iterate all phi functions of a block:
duke@1 305 //
duke@1 306 // BlockBegin* block = ... // block that is iterated
duke@1 307 // for_each_phi_function(block, phi,
duke@1 308 // do something with the phi function phi (note that this is a macro parameter)
duke@1 309 // );
duke@1 310
duke@1 311 #define for_each_phi_fun(v_block, v_phi, v_code) \
duke@1 312 { \
duke@1 313 int cur_index; \
duke@1 314 ValueStack* cur_state = v_block->state(); \
duke@1 315 Value value; \
duke@1 316 { \
duke@1 317 for_each_stack_value(cur_state, cur_index, value) { \
mdoerr@53028 318 Phi* v_phi = value->as_Phi(); \
duke@1 319 if (v_phi != NULL && v_phi->block() == v_block) { \
duke@1 320 v_code; \
duke@1 321 } \
duke@1 322 } \
duke@1 323 } \
duke@1 324 { \
duke@1 325 for_each_local_value(cur_state, cur_index, value) { \
mdoerr@53028 326 Phi* v_phi = value->as_Phi(); \
duke@1 327 if (v_phi != NULL && v_phi->block() == v_block) { \
duke@1 328 v_code; \
duke@1 329 } \
duke@1 330 } \
duke@1 331 } \
duke@1 332 }
stefank@7397 333
coleenp@53244 334 #endif // SHARE_C1_C1_VALUESTACK_HPP