changeset 18173:8c079b8d0446

Reduce allocation during scope recording
author Tom Rodriguez <tom.rodriguez@oracle.com>
date Fri, 24 Oct 2014 12:48:53 -0700
parents c59612b9d110
children 26d381457145
files src/share/vm/graal/graalCodeInstaller.cpp src/share/vm/graal/graalCodeInstaller.hpp
diffstat 2 files changed, 34 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/graal/graalCodeInstaller.cpp	Fri Oct 24 12:45:27 2014 -0700
+++ b/src/share/vm/graal/graalCodeInstaller.cpp	Fri Oct 24 12:48:53 2014 -0700
@@ -52,6 +52,18 @@
 # include "vmreg_ppc.inline.hpp"
 #endif
 
+
+// frequently used constants
+// Allocate them with new so they are never destroyed (otherwise, a
+// forced exit could destroy these objects while they are still in
+// use).
+ConstantOopWriteValue* CodeInstaller::_oop_null_scope_value = new (ResourceObj::C_HEAP, mtCompiler) ConstantOopWriteValue(NULL);
+ConstantIntValue*      CodeInstaller::_int_m1_scope_value = new (ResourceObj::C_HEAP, mtCompiler) ConstantIntValue(-1);
+ConstantIntValue*      CodeInstaller::_int_0_scope_value =  new (ResourceObj::C_HEAP, mtCompiler) ConstantIntValue(0);
+ConstantIntValue*      CodeInstaller::_int_1_scope_value =  new (ResourceObj::C_HEAP, mtCompiler) ConstantIntValue(1);
+ConstantIntValue*      CodeInstaller::_int_2_scope_value =  new (ResourceObj::C_HEAP, mtCompiler) ConstantIntValue(2);
+LocationValue*         CodeInstaller::_illegal_value = new (ResourceObj::C_HEAP, mtCompiler) LocationValue(Location());
+
 Method* getMethodFromHotSpotMethod(oop hotspot_method) {
   assert(hotspot_method != NULL && hotspot_method->is_a(HotSpotResolvedJavaMethod::klass()), "sanity");
   return asMethod(HotSpotResolvedJavaMethod::metaspaceMethod(hotspot_method));
@@ -192,7 +204,7 @@
 ScopeValue* CodeInstaller::get_scope_value(oop value, int total_frame_size, GrowableArray<ScopeValue*>* objects, ScopeValue* &second, OopRecorder* oop_recorder) {
   second = NULL;
   if (value == Value::ILLEGAL()) {
-    return new LocationValue(Location::new_stk_loc(Location::invalid, 0));
+    return _illegal_value;
   }
 
   oop lirKind = AbstractValue::lirKind(value);
@@ -283,17 +295,23 @@
         return new ConstantLongValue(prim);
       } else if (type == T_INT || type == T_FLOAT) {
         jint prim = (jint)PrimitiveConstant::primitive(value);
-        return new ConstantIntValue(prim);
+        switch (prim) {
+          case -1: return _int_m1_scope_value;
+          case  0: return _int_0_scope_value;
+          case  1: return _int_1_scope_value;
+          case  2: return _int_2_scope_value;
+          default: return new ConstantIntValue(prim);
+        }
       } else {
         assert(type == T_LONG || type == T_DOUBLE, "unexpected primitive constant type");
         jlong prim = PrimitiveConstant::primitive(value);
-        second = new ConstantIntValue(0);
+        second = _int_1_scope_value;
         return new ConstantLongValue(prim);
       }
     } else {
         assert(reference, "unexpected object constant type");
       if (value->is_a(NullConstant::klass()) || value->is_a(HotSpotCompressedNullConstant::klass())) {
-        return new ConstantOopWriteValue(NULL);
+        return _oop_null_scope_value;
       } else {
         assert(value->is_a(HotSpotObjectConstant::klass()), "unexpected constant type");
         oop obj = HotSpotObjectConstant::object(value);
@@ -328,10 +346,10 @@
         // we're trying to put ints into a long array... this isn't really valid, but it's used for some optimizations.
         // add an int 0 constant
 #ifdef VM_LITTLE_ENDIAN
-        cur_second = new ConstantIntValue(0);
+        cur_second = _int_0_scope_value;
 #else
         cur_second = value;
-        value = new ConstantIntValue(0);
+        value = _int_0_scope_value;
 #endif
       }
 
@@ -747,9 +765,9 @@
 
     assert(local_count + expression_count + monitor_count == values->length(), "unexpected values length");
 
-    GrowableArray<ScopeValue*>* locals = new GrowableArray<ScopeValue*> ();
-    GrowableArray<ScopeValue*>* expressions = new GrowableArray<ScopeValue*> ();
-    GrowableArray<MonitorValue*>* monitors = new GrowableArray<MonitorValue*> ();
+    GrowableArray<ScopeValue*>* locals = local_count > 0 ? new GrowableArray<ScopeValue*> (local_count) : NULL;
+    GrowableArray<ScopeValue*>* expressions = expression_count > 0 ? new GrowableArray<ScopeValue*> (expression_count) : NULL;
+    GrowableArray<MonitorValue*>* monitors = monitor_count > 0 ? new GrowableArray<MonitorValue*> (monitor_count) : NULL;
 
     if (TraceGraal >= 2) {
       tty->print_cr("Scope at bci %d with %d values", bci, values->length());
--- a/src/share/vm/graal/graalCodeInstaller.hpp	Fri Oct 24 12:45:27 2014 -0700
+++ b/src/share/vm/graal/graalCodeInstaller.hpp	Fri Oct 24 12:48:53 2014 -0700
@@ -78,6 +78,13 @@
   Dependencies*             _dependencies;
   ExceptionHandlerTable     _exception_handler_table;
 
+  static ConstantOopWriteValue* _oop_null_scope_value;
+  static ConstantIntValue*    _int_m1_scope_value;
+  static ConstantIntValue*    _int_0_scope_value;
+  static ConstantIntValue*    _int_1_scope_value;
+  static ConstantIntValue*    _int_2_scope_value;
+  static LocationValue*       _illegal_value;
+
   jint pd_next_offset(NativeInstruction* inst, jint pc_offset, oop method);
   void pd_patch_OopData(int pc_offset, oop data);
   void pd_patch_DataSectionReference(int pc_offset, oop data);