diff src/hotspot/share/c1/c1_ValueStack.cpp @ 54074:9c6508806663

8220501: Improve c1_ValueStack locks handling Reviewed-by: thartmann, neliasso
author redestad
date Tue, 12 Mar 2019 15:29:59 +0100
parents 71c04702a3d5
children
line wrap: on
line diff
--- a/src/hotspot/share/c1/c1_ValueStack.cpp	Tue Mar 12 09:59:58 2019 -0400
+++ b/src/hotspot/share/c1/c1_ValueStack.cpp	Tue Mar 12 15:29:59 2019 +0100
@@ -37,7 +37,7 @@
 , _kind(Parsing)
 , _locals(scope->method()->max_locals(), scope->method()->max_locals(), NULL)
 , _stack(scope->method()->max_stack())
-, _locks()
+, _locks(NULL)
 {
   verify();
 }
@@ -50,7 +50,7 @@
   , _kind(kind)
   , _locals()
   , _stack()
-  , _locks(copy_from->locks_size())
+  , _locks(copy_from->locks_size() == 0 ? NULL : new Values(copy_from->locks_size()))
 {
   assert(kind != EmptyExceptionState || !Compilation::current()->env()->should_retain_local_variables(), "need locals");
   if (kind != EmptyExceptionState) {
@@ -70,7 +70,9 @@
     _stack.appendAll(&copy_from->_stack);
   }
 
-  _locks.appendAll(&copy_from->_locks);
+  if (copy_from->locks_size() > 0) {
+    _locks->appendAll(copy_from->_locks);
+  }
 
   verify();
 }
@@ -90,8 +92,11 @@
   for_each_stack_value(this, index, value) {
     if (value->type()->tag() != s->stack_at(index)->type()->tag()) return false;
   }
-  for_each_lock_value(this, index, value) {
-    if (value != s->lock_at(index)) return false;
+  for (int i = 0; i < locks_size(); i++) {
+    value = lock_at(i);
+    if (value != NULL && value != s->lock_at(i)) {
+      return false;
+    }
   }
   return true;
 }
@@ -113,7 +118,7 @@
 
 
 // apply function to all values of a list; factored out from values_do(f)
-void ValueStack::apply(Values list, ValueVisitor* f) {
+void ValueStack::apply(const Values& list, ValueVisitor* f) {
   for (int i = 0; i < list.length(); i++) {
     Value* va = list.adr_at(i);
     Value v0 = *va;
@@ -135,7 +140,9 @@
   for_each_state(state) {
     apply(state->_locals, f);
     apply(state->_stack, f);
-    apply(state->_locks, f);
+    if (state->_locks != NULL) {
+      apply(*state->_locks, f);
+    }
   }
 }
 
@@ -160,7 +167,10 @@
 }
 
 int ValueStack::lock(Value obj) {
-  _locks.push(obj);
+  if (_locks == NULL) {
+    _locks = new Values();
+  }
+  _locks->push(obj);
   int num_locks = total_locks_size();
   scope()->set_min_number_of_locks(num_locks);
   return num_locks - 1;
@@ -168,7 +178,8 @@
 
 
 int ValueStack::unlock() {
-  _locks.pop();
+  assert(locks_size() > 0, "sanity");
+  _locks->pop();
   return total_locks_size();
 }