Skip to content

Commit ef38fb4

Browse files
committed
8220501: Improve c1_ValueStack locks handling
Reviewed-by: thartmann, neliasso
1 parent f15a31f commit ef38fb4

2 files changed

Lines changed: 25 additions & 22 deletions

File tree

src/hotspot/share/c1/c1_ValueStack.cpp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ ValueStack::ValueStack(IRScope* scope, ValueStack* caller_state)
3737
, _kind(Parsing)
3838
, _locals(scope->method()->max_locals(), scope->method()->max_locals(), NULL)
3939
, _stack(scope->method()->max_stack())
40-
, _locks()
40+
, _locks(NULL)
4141
{
4242
verify();
4343
}
@@ -50,7 +50,7 @@ ValueStack::ValueStack(ValueStack* copy_from, Kind kind, int bci)
5050
, _kind(kind)
5151
, _locals()
5252
, _stack()
53-
, _locks(copy_from->locks_size())
53+
, _locks(copy_from->locks_size() == 0 ? NULL : new Values(copy_from->locks_size()))
5454
{
5555
assert(kind != EmptyExceptionState || !Compilation::current()->env()->should_retain_local_variables(), "need locals");
5656
if (kind != EmptyExceptionState) {
@@ -70,7 +70,9 @@ ValueStack::ValueStack(ValueStack* copy_from, Kind kind, int bci)
7070
_stack.appendAll(&copy_from->_stack);
7171
}
7272

73-
_locks.appendAll(&copy_from->_locks);
73+
if (copy_from->locks_size() > 0) {
74+
_locks->appendAll(copy_from->_locks);
75+
}
7476

7577
verify();
7678
}
@@ -90,8 +92,11 @@ bool ValueStack::is_same(ValueStack* s) {
9092
for_each_stack_value(this, index, value) {
9193
if (value->type()->tag() != s->stack_at(index)->type()->tag()) return false;
9294
}
93-
for_each_lock_value(this, index, value) {
94-
if (value != s->lock_at(index)) return false;
95+
for (int i = 0; i < locks_size(); i++) {
96+
value = lock_at(i);
97+
if (value != NULL && value != s->lock_at(i)) {
98+
return false;
99+
}
95100
}
96101
return true;
97102
}
@@ -113,7 +118,7 @@ void ValueStack::pin_stack_for_linear_scan() {
113118

114119

115120
// apply function to all values of a list; factored out from values_do(f)
116-
void ValueStack::apply(Values list, ValueVisitor* f) {
121+
void ValueStack::apply(const Values& list, ValueVisitor* f) {
117122
for (int i = 0; i < list.length(); i++) {
118123
Value* va = list.adr_at(i);
119124
Value v0 = *va;
@@ -135,7 +140,9 @@ void ValueStack::values_do(ValueVisitor* f) {
135140
for_each_state(state) {
136141
apply(state->_locals, f);
137142
apply(state->_stack, f);
138-
apply(state->_locks, f);
143+
if (state->_locks != NULL) {
144+
apply(*state->_locks, f);
145+
}
139146
}
140147
}
141148

@@ -160,15 +167,19 @@ int ValueStack::total_locks_size() const {
160167
}
161168

162169
int ValueStack::lock(Value obj) {
163-
_locks.push(obj);
170+
if (_locks == NULL) {
171+
_locks = new Values();
172+
}
173+
_locks->push(obj);
164174
int num_locks = total_locks_size();
165175
scope()->set_min_number_of_locks(num_locks);
166176
return num_locks - 1;
167177
}
168178

169179

170180
int ValueStack::unlock() {
171-
_locks.pop();
181+
assert(locks_size() > 0, "sanity");
182+
_locks->pop();
172183
return total_locks_size();
173184
}
174185

src/hotspot/share/c1/c1_ValueStack.hpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class ValueStack: public CompilationResourceObj {
4747

4848
Values _locals; // the locals
4949
Values _stack; // the expression stack
50-
Values _locks; // the monitor stack (holding the locked values)
50+
Values* _locks; // the monitor stack (holding the locked values)
5151

5252
Value check(ValueTag tag, Value t) {
5353
assert(tag == t->type()->tag() || tag == objectTag && t->type()->tag() == addressTag, "types must correspond");
@@ -60,7 +60,7 @@ class ValueStack: public CompilationResourceObj {
6060
}
6161

6262
// helper routine
63-
static void apply(Values list, ValueVisitor* f);
63+
static void apply(const Values& list, ValueVisitor* f);
6464

6565
// for simplified copying
6666
ValueStack(ValueStack* copy_from, Kind kind, int bci);
@@ -90,9 +90,9 @@ class ValueStack: public CompilationResourceObj {
9090

9191
int locals_size() const { return _locals.length(); }
9292
int stack_size() const { return _stack.length(); }
93-
int locks_size() const { return _locks.length(); }
93+
int locks_size() const { return _locks == NULL ? 0 : _locks->length(); }
9494
bool stack_is_empty() const { return _stack.is_empty(); }
95-
bool no_active_locks() const { return _locks.is_empty(); }
95+
bool no_active_locks() const { return _locks == NULL || _locks->is_empty(); }
9696
int total_locks_size() const;
9797

9898
// locals access
@@ -201,7 +201,7 @@ class ValueStack: public CompilationResourceObj {
201201
// locks access
202202
int lock (Value obj);
203203
int unlock();
204-
Value lock_at(int i) const { return _locks.at(i); }
204+
Value lock_at(int i) const { return _locks->at(i); }
205205

206206
// SSA form IR support
207207
void setup_phi_for_stack(BlockBegin* b, int index);
@@ -261,14 +261,6 @@ class ValueStack: public CompilationResourceObj {
261261
index += value->type()->size())
262262

263263

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-
272264
// Macro definition for simple iteration of all state values of a ValueStack
273265
// Because the code cannot be executed in a single loop, the code must be passed
274266
// as a macro parameter.

0 commit comments

Comments
 (0)