8232165: Reduce allocations in ValueStack copying constructor
authorredestad
Mon, 14 Oct 2019 20:58:08 +0200
changeset 58586 cd9c4e6aa631
parent 58585 e69d6f076a6a
child 58587 90412c2a04c2
8232165: Reduce allocations in ValueStack copying constructor Reviewed-by: neliasso, kvn
src/hotspot/share/c1/c1_ValueStack.cpp
src/hotspot/share/c1/c1_ValueStack.hpp
src/hotspot/share/ci/ciMetadata.hpp
--- a/src/hotspot/share/c1/c1_ValueStack.cpp	Mon Oct 14 11:24:23 2019 -0700
+++ b/src/hotspot/share/c1/c1_ValueStack.cpp	Mon Oct 14 20:58:08 2019 +0200
@@ -42,31 +42,21 @@
   verify();
 }
 
-
 ValueStack::ValueStack(ValueStack* copy_from, Kind kind, int bci)
   : _scope(copy_from->scope())
   , _caller_state(copy_from->caller_state())
   , _bci(bci)
   , _kind(kind)
-  , _locals()
-  , _stack()
+  , _locals(copy_from->locals_size_for_copy(kind))
+  , _stack(copy_from->stack_size_for_copy(kind))
   , _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) {
-    // only allocate space if we need to copy the locals-array
-    _locals = Values(copy_from->locals_size());
     _locals.appendAll(&copy_from->_locals);
   }
 
   if (kind != ExceptionState && kind != EmptyExceptionState) {
-    if (kind == Parsing) {
-      // stack will be modified, so reserve enough space to avoid resizing
-      _stack = Values(scope()->method()->max_stack());
-    } else {
-      // stack will not be modified, so do not waste space
-      _stack = Values(copy_from->stack_size());
-    }
     _stack.appendAll(&copy_from->_stack);
   }
 
@@ -77,6 +67,25 @@
   verify();
 }
 
+int ValueStack::locals_size_for_copy(Kind kind) const {
+  if (kind != EmptyExceptionState) {
+    return locals_size();
+  }
+  return 0;
+}
+
+int ValueStack::stack_size_for_copy(Kind kind) const {
+  if (kind != ExceptionState && kind != EmptyExceptionState) {
+    if (kind == Parsing) {
+      // stack will be modified, so reserve enough space to avoid resizing
+      return scope()->method()->max_stack();
+    } else {
+      // stack will not be modified, so do not waste space
+      return stack_size();
+    }
+  }
+  return 0;
+}
 
 bool ValueStack::is_same(ValueStack* s) {
   if (scope() != s->scope()) return false;
--- a/src/hotspot/share/c1/c1_ValueStack.hpp	Mon Oct 14 11:24:23 2019 -0700
+++ b/src/hotspot/share/c1/c1_ValueStack.hpp	Mon Oct 14 20:58:08 2019 +0200
@@ -65,6 +65,8 @@
   // for simplified copying
   ValueStack(ValueStack* copy_from, Kind kind, int bci);
 
+  int locals_size_for_copy(Kind kind) const;
+  int stack_size_for_copy(Kind kind) const;
  public:
   // creation
   ValueStack(IRScope* scope, ValueStack* caller_state);
--- a/src/hotspot/share/ci/ciMetadata.hpp	Mon Oct 14 11:24:23 2019 -0700
+++ b/src/hotspot/share/ci/ciMetadata.hpp	Mon Oct 14 20:58:08 2019 +0200
@@ -51,7 +51,6 @@
   virtual bool is_metadata() const          { return true; }
 
   virtual bool is_type() const              { return false; }
-  virtual bool is_cpcache() const           { return false; }
   virtual bool is_return_address() const    { return false; }
   virtual bool is_method() const            { return false; }
   virtual bool is_method_data() const       { return false; }