< prev index next >

src/hotspot/share/c1/c1_ValueStack.hpp

Print this page
rev 54069 : 8220501: Improve c1_ValueStack locks handling
Reviewed-by: TBD


  30 class ValueStack: public CompilationResourceObj {
  31  public:
  32   enum Kind {
  33     Parsing,             // During abstract interpretation in GraphBuilder
  34     CallerState,         // Caller state when inlining
  35     StateBefore,         // Before before execution of instruction
  36     StateAfter,          // After execution of instruction
  37     ExceptionState,      // Exception handling of instruction
  38     EmptyExceptionState, // Exception handling of instructions not covered by an xhandler
  39     BlockBeginState      // State of BlockBegin instruction with phi functions of this block
  40   };
  41 
  42  private:
  43   IRScope* _scope;                               // the enclosing scope
  44   ValueStack* _caller_state;
  45   int      _bci;
  46   Kind     _kind;
  47 
  48   Values   _locals;                              // the locals
  49   Values   _stack;                               // the expression stack
  50   Values   _locks;                               // the monitor stack (holding the locked values)
  51 
  52   Value check(ValueTag tag, Value t) {
  53     assert(tag == t->type()->tag() || tag == objectTag && t->type()->tag() == addressTag, "types must correspond");
  54     return t;
  55   }
  56 
  57   Value check(ValueTag tag, Value t, Value h) {
  58     assert(h == NULL, "hi-word of doubleword value must be NULL");
  59     return check(tag, t);
  60   }
  61 
  62   // helper routine
  63   static void apply(Values list, ValueVisitor* f);
  64 
  65   // for simplified copying
  66   ValueStack(ValueStack* copy_from, Kind kind, int bci);
  67 
  68  public:
  69   // creation
  70   ValueStack(IRScope* scope, ValueStack* caller_state);
  71 
  72   ValueStack* copy()                             { return new ValueStack(this, _kind, _bci); }
  73   ValueStack* copy(Kind new_kind, int new_bci)   { return new ValueStack(this, new_kind, new_bci); }
  74   ValueStack* copy_for_parsing()                 { return new ValueStack(this, Parsing, -99); }
  75 
  76   void set_caller_state(ValueStack* s)           {
  77     assert(kind() == EmptyExceptionState ||
  78            (Compilation::current()->env()->should_retain_local_variables() && kind() == ExceptionState),
  79            "only EmptyExceptionStates can be modified");
  80     _caller_state = s;
  81   }
  82 
  83   bool is_same(ValueStack* s);                   // returns true if this & s's types match (w/o checking locals)
  84 
  85   // accessors
  86   IRScope* scope() const                         { return _scope; }
  87   ValueStack* caller_state() const               { return _caller_state; }
  88   int bci() const                                { return _bci; }
  89   Kind kind() const                              { return _kind; }
  90 
  91   int locals_size() const                        { return _locals.length(); }
  92   int stack_size() const                         { return _stack.length(); }
  93   int locks_size() const                         { return _locks.length(); }
  94   bool stack_is_empty() const                    { return _stack.is_empty(); }
  95   bool no_active_locks() const                   { return _locks.is_empty(); }
  96   int total_locks_size() const;
  97 
  98   // locals access
  99   void clear_locals();                           // sets all locals to NULL;
 100 
 101   void invalidate_local(int i) {
 102     assert(!_locals.at(i)->type()->is_double_word() ||
 103            _locals.at(i + 1) == NULL, "hi-word of doubleword value must be NULL");
 104     _locals.at_put(i, NULL);
 105   }
 106 
 107   Value local_at(int i) const {
 108     Value x = _locals.at(i);
 109     assert(x == NULL || !x->type()->is_double_word() ||
 110            _locals.at(i + 1) == NULL, "hi-word of doubleword value must be NULL");
 111     return x;
 112   }
 113 
 114   void store_local(int i, Value x) {
 115     // When overwriting local i, check if i - 1 was the start of a


 184   Value lpop()                                   { Value h = _stack.pop(); return check(longTag  , _stack.pop(), h); }
 185   Value dpop()                                   { Value h = _stack.pop(); return check(doubleTag, _stack.pop(), h); }
 186 
 187   Value pop(ValueType* type) {
 188     switch (type->tag()) {
 189       case intTag    : return ipop();
 190       case longTag   : return lpop();
 191       case floatTag  : return fpop();
 192       case doubleTag : return dpop();
 193       case objectTag : return apop();
 194       case addressTag: return rpop();
 195       default        : ShouldNotReachHere(); return NULL;
 196     }
 197   }
 198 
 199   Values* pop_arguments(int argument_size);
 200 
 201   // locks access
 202   int lock  (Value obj);
 203   int unlock();
 204   Value lock_at(int i) const                     { return _locks.at(i); }
 205 
 206   // SSA form IR support
 207   void setup_phi_for_stack(BlockBegin* b, int index);
 208   void setup_phi_for_local(BlockBegin* b, int index);
 209 
 210   // debugging
 211   void print()  PRODUCT_RETURN;
 212   void verify() PRODUCT_RETURN;
 213 };
 214 
 215 
 216 
 217 // Macro definitions for simple iteration of stack and local values of a ValueStack
 218 // The macros can be used like a for-loop. All variables (state, index and value)
 219 // must be defined before the loop.
 220 // When states are nested because of inlining, the stack of the innermost state
 221 // cumulates also the stack of the nested states. In contrast, the locals of all
 222 // states must be iterated each.
 223 // Use the following code pattern to iterate all stack values and all nested local values:
 224 //


 242 #define temp_var3(x) temp__ ## x
 243 #define temp_var2(x) temp_var3(x)
 244 #define temp_var     temp_var2(__LINE__)
 245 
 246 #define for_each_state(state)  \
 247   for (; state != NULL; state = state->caller_state())
 248 
 249 #define for_each_local_value(state, index, value)                                              \
 250   int temp_var = state->locals_size();                                                         \
 251   for (index = 0;                                                                              \
 252        index < temp_var && (value = state->local_at(index), true);                             \
 253        index += (value == NULL || value->type()->is_illegal() ? 1 : value->type()->size()))    \
 254     if (value != NULL)
 255 
 256 
 257 #define for_each_stack_value(state, index, value)                                              \
 258   int temp_var = state->stack_size();                                                          \
 259   for (index = 0;                                                                              \
 260        index < temp_var && (value = state->stack_at(index), true);                             \
 261        index += value->type()->size())
 262 
 263 
 264 #define for_each_lock_value(state, index, value)                                               \
 265   int temp_var = state->locks_size();                                                          \
 266   for (index = 0;                                                                              \
 267        index < temp_var && (value = state->lock_at(index), true);                              \
 268        index++)                                                                                \
 269     if (value != NULL)
 270 
 271 
 272 // Macro definition for simple iteration of all state values of a ValueStack
 273 // Because the code cannot be executed in a single loop, the code must be passed
 274 // as a macro parameter.
 275 // Use the following code pattern to iterate all stack values and all nested local values:
 276 //
 277 // ValueStack* state = ...   // state that is iterated
 278 // for_each_state_value(state, value,
 279 //   do something with value (note that this is a macro parameter)
 280 // );
 281 
 282 #define for_each_state_value(v_state, v_value, v_code)                                         \
 283 {                                                                                              \
 284   int cur_index;                                                                               \
 285   ValueStack* cur_state = v_state;                                                             \
 286   Value v_value;                                                                               \
 287   for_each_state(cur_state) {                                                                  \
 288     {                                                                                            \
 289       for_each_local_value(cur_state, cur_index, v_value) {                                      \




  30 class ValueStack: public CompilationResourceObj {
  31  public:
  32   enum Kind {
  33     Parsing,             // During abstract interpretation in GraphBuilder
  34     CallerState,         // Caller state when inlining
  35     StateBefore,         // Before before execution of instruction
  36     StateAfter,          // After execution of instruction
  37     ExceptionState,      // Exception handling of instruction
  38     EmptyExceptionState, // Exception handling of instructions not covered by an xhandler
  39     BlockBeginState      // State of BlockBegin instruction with phi functions of this block
  40   };
  41 
  42  private:
  43   IRScope* _scope;                               // the enclosing scope
  44   ValueStack* _caller_state;
  45   int      _bci;
  46   Kind     _kind;
  47 
  48   Values   _locals;                              // the locals
  49   Values   _stack;                               // the expression stack
  50   Values*  _locks;                               // the monitor stack (holding the locked values)
  51 
  52   Value check(ValueTag tag, Value t) {
  53     assert(tag == t->type()->tag() || tag == objectTag && t->type()->tag() == addressTag, "types must correspond");
  54     return t;
  55   }
  56 
  57   Value check(ValueTag tag, Value t, Value h) {
  58     assert(h == NULL, "hi-word of doubleword value must be NULL");
  59     return check(tag, t);
  60   }
  61 
  62   // helper routine
  63   static void apply(const Values& list, ValueVisitor* f);
  64 
  65   // for simplified copying
  66   ValueStack(ValueStack* copy_from, Kind kind, int bci);
  67 
  68  public:
  69   // creation
  70   ValueStack(IRScope* scope, ValueStack* caller_state);
  71 
  72   ValueStack* copy()                             { return new ValueStack(this, _kind, _bci); }
  73   ValueStack* copy(Kind new_kind, int new_bci)   { return new ValueStack(this, new_kind, new_bci); }
  74   ValueStack* copy_for_parsing()                 { return new ValueStack(this, Parsing, -99); }
  75 
  76   void set_caller_state(ValueStack* s)           {
  77     assert(kind() == EmptyExceptionState ||
  78            (Compilation::current()->env()->should_retain_local_variables() && kind() == ExceptionState),
  79            "only EmptyExceptionStates can be modified");
  80     _caller_state = s;
  81   }
  82 
  83   bool is_same(ValueStack* s);                   // returns true if this & s's types match (w/o checking locals)
  84 
  85   // accessors
  86   IRScope* scope() const                         { return _scope; }
  87   ValueStack* caller_state() const               { return _caller_state; }
  88   int bci() const                                { return _bci; }
  89   Kind kind() const                              { return _kind; }
  90 
  91   int locals_size() const                        { return _locals.length(); }
  92   int stack_size() const                         { return _stack.length(); }
  93   int locks_size() const                         { return _locks == NULL ? 0 : _locks->length(); }
  94   bool stack_is_empty() const                    { return _stack.is_empty(); }
  95   bool no_active_locks() const                   { return _locks == NULL || _locks->is_empty(); }
  96   int total_locks_size() const;
  97 
  98   // locals access
  99   void clear_locals();                           // sets all locals to NULL;
 100 
 101   void invalidate_local(int i) {
 102     assert(!_locals.at(i)->type()->is_double_word() ||
 103            _locals.at(i + 1) == NULL, "hi-word of doubleword value must be NULL");
 104     _locals.at_put(i, NULL);
 105   }
 106 
 107   Value local_at(int i) const {
 108     Value x = _locals.at(i);
 109     assert(x == NULL || !x->type()->is_double_word() ||
 110            _locals.at(i + 1) == NULL, "hi-word of doubleword value must be NULL");
 111     return x;
 112   }
 113 
 114   void store_local(int i, Value x) {
 115     // When overwriting local i, check if i - 1 was the start of a


 184   Value lpop()                                   { Value h = _stack.pop(); return check(longTag  , _stack.pop(), h); }
 185   Value dpop()                                   { Value h = _stack.pop(); return check(doubleTag, _stack.pop(), h); }
 186 
 187   Value pop(ValueType* type) {
 188     switch (type->tag()) {
 189       case intTag    : return ipop();
 190       case longTag   : return lpop();
 191       case floatTag  : return fpop();
 192       case doubleTag : return dpop();
 193       case objectTag : return apop();
 194       case addressTag: return rpop();
 195       default        : ShouldNotReachHere(); return NULL;
 196     }
 197   }
 198 
 199   Values* pop_arguments(int argument_size);
 200 
 201   // locks access
 202   int lock  (Value obj);
 203   int unlock();
 204   Value lock_at(int i) const                     { return _locks->at(i); }
 205 
 206   // SSA form IR support
 207   void setup_phi_for_stack(BlockBegin* b, int index);
 208   void setup_phi_for_local(BlockBegin* b, int index);
 209 
 210   // debugging
 211   void print()  PRODUCT_RETURN;
 212   void verify() PRODUCT_RETURN;
 213 };
 214 
 215 
 216 
 217 // Macro definitions for simple iteration of stack and local values of a ValueStack
 218 // The macros can be used like a for-loop. All variables (state, index and value)
 219 // must be defined before the loop.
 220 // When states are nested because of inlining, the stack of the innermost state
 221 // cumulates also the stack of the nested states. In contrast, the locals of all
 222 // states must be iterated each.
 223 // Use the following code pattern to iterate all stack values and all nested local values:
 224 //


 242 #define temp_var3(x) temp__ ## x
 243 #define temp_var2(x) temp_var3(x)
 244 #define temp_var     temp_var2(__LINE__)
 245 
 246 #define for_each_state(state)  \
 247   for (; state != NULL; state = state->caller_state())
 248 
 249 #define for_each_local_value(state, index, value)                                              \
 250   int temp_var = state->locals_size();                                                         \
 251   for (index = 0;                                                                              \
 252        index < temp_var && (value = state->local_at(index), true);                             \
 253        index += (value == NULL || value->type()->is_illegal() ? 1 : value->type()->size()))    \
 254     if (value != NULL)
 255 
 256 
 257 #define for_each_stack_value(state, index, value)                                              \
 258   int temp_var = state->stack_size();                                                          \
 259   for (index = 0;                                                                              \
 260        index < temp_var && (value = state->stack_at(index), true);                             \
 261        index += value->type()->size())








 262 
 263 
 264 // Macro definition for simple iteration of all state values of a ValueStack
 265 // Because the code cannot be executed in a single loop, the code must be passed
 266 // as a macro parameter.
 267 // Use the following code pattern to iterate all stack values and all nested local values:
 268 //
 269 // ValueStack* state = ...   // state that is iterated
 270 // for_each_state_value(state, value,
 271 //   do something with value (note that this is a macro parameter)
 272 // );
 273 
 274 #define for_each_state_value(v_state, v_value, v_code)                                         \
 275 {                                                                                              \
 276   int cur_index;                                                                               \
 277   ValueStack* cur_state = v_state;                                                             \
 278   Value v_value;                                                                               \
 279   for_each_state(cur_state) {                                                                  \
 280     {                                                                                            \
 281       for_each_local_value(cur_state, cur_index, v_value) {                                      \


< prev index next >