# HG changeset patch # User Tom Rodriguez # Date 1414180133 25200 # Node ID 8c079b8d0446b3b4555c6f09a4012f722b02892b # Parent c59612b9d1109e7bd5c78fba00e7a29c230a6ef8 Reduce allocation during scope recording diff -r c59612b9d110 -r 8c079b8d0446 src/share/vm/graal/graalCodeInstaller.cpp --- 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* 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* locals = new GrowableArray (); - GrowableArray* expressions = new GrowableArray (); - GrowableArray* monitors = new GrowableArray (); + GrowableArray* locals = local_count > 0 ? new GrowableArray (local_count) : NULL; + GrowableArray* expressions = expression_count > 0 ? new GrowableArray (expression_count) : NULL; + GrowableArray* monitors = monitor_count > 0 ? new GrowableArray (monitor_count) : NULL; if (TraceGraal >= 2) { tty->print_cr("Scope at bci %d with %d values", bci, values->length()); diff -r c59612b9d110 -r 8c079b8d0446 src/share/vm/graal/graalCodeInstaller.hpp --- 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);