# HG changeset patch # User Lukas Stadler # Date 1390983710 -3600 # Node ID 8cd953e97e2dfcb3647384f7774685059eece5ee # Parent cfe85a075924e9914d540c356182dec6f412ef33 rework of benchmark counters: fix size at VM entry, not at build time diff -r cfe85a075924 -r 8cd953e97e2d graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/debug/BenchmarkCounters.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/debug/BenchmarkCounters.java Wed Jan 29 10:45:43 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/debug/BenchmarkCounters.java Wed Jan 29 09:21:50 2014 +0100 @@ -107,7 +107,7 @@ public static int getIndex(DynamicCounterNode counter) { if (!enabled) { - throw new GraalInternalError("counter nodes shouldn't exist when counters are not enabled"); + throw new GraalInternalError("counter nodes shouldn't exist when counters are not enabled: " + counter.getGroup() + ", " + counter.getName()); } String name = counter.getName(); String group = counter.getGroup(); @@ -332,12 +332,15 @@ if (index >= config.graalCountersSize) { throw new GraalInternalError("too many counters, reduce number of counters or increase GRAAL_COUNTERS_SIZE (current value: " + config.graalCountersSize + ")"); } - ConstantLocationNode location = ConstantLocationNode.create(LocationIdentity.ANY_LOCATION, Kind.Long, config.graalCountersThreadOffset + Unsafe.ARRAY_LONG_INDEX_SCALE * index, graph); - ReadNode read = graph.add(new ReadNode(thread, location, StampFactory.forKind(Kind.Long), BarrierType.NONE, false)); + ConstantLocationNode arrayLocation = ConstantLocationNode.create(LocationIdentity.ANY_LOCATION, Kind.Long, config.graalCountersThreadOffset, graph); + ReadNode readArray = graph.add(new ReadNode(thread, arrayLocation, StampFactory.forKind(wordKind), BarrierType.NONE, false)); + ConstantLocationNode location = ConstantLocationNode.create(LocationIdentity.ANY_LOCATION, Kind.Long, Unsafe.ARRAY_LONG_INDEX_SCALE * index, graph); + ReadNode read = graph.add(new ReadNode(readArray, location, StampFactory.forKind(Kind.Long), BarrierType.NONE, false)); IntegerAddNode add = graph.unique(new IntegerAddNode(Kind.Long, read, counter.getIncrement())); - WriteNode write = graph.add(new WriteNode(thread, add, location, BarrierType.NONE, false)); + WriteNode write = graph.add(new WriteNode(readArray, add, location, BarrierType.NONE, false)); graph.addBeforeFixed(counter, thread); + graph.addBeforeFixed(counter, readArray); graph.addBeforeFixed(counter, read); graph.addBeforeFixed(counter, write); } diff -r cfe85a075924 -r 8cd953e97e2d src/share/vm/graal/graalCompilerToVM.cpp --- a/src/share/vm/graal/graalCompilerToVM.cpp Wed Jan 29 10:45:43 2014 +0100 +++ b/src/share/vm/graal/graalCompilerToVM.cpp Wed Jan 29 09:21:50 2014 +0100 @@ -553,7 +553,7 @@ //------------------------------------------------------------------------------------------------ set_int("graalCountersThreadOffset", in_bytes(JavaThread::graal_counters_offset())); - set_int("graalCountersSize", (jint) GRAAL_COUNTERS_SIZE); + set_int("graalCountersSize", (jint) GraalCounterSize); #undef set_boolean #undef set_int @@ -816,7 +816,7 @@ C2V_END C2V_VMENTRY(jlongArray, collectCounters, (JNIEnv *env, jobject)) - typeArrayOop arrayOop = oopFactory::new_longArray(GRAAL_COUNTERS_SIZE, CHECK_NULL); + typeArrayOop arrayOop = oopFactory::new_longArray(GraalCounterSize, CHECK_NULL); JavaThread::collect_counters(arrayOop); return (jlongArray) JNIHandles::make_local(arrayOop); C2V_END diff -r cfe85a075924 -r 8cd953e97e2d src/share/vm/graal/graalGlobals.hpp --- a/src/share/vm/graal/graalGlobals.hpp Wed Jan 29 10:45:43 2014 +0100 +++ b/src/share/vm/graal/graalGlobals.hpp Wed Jan 29 09:21:50 2014 +0100 @@ -55,6 +55,12 @@ product(intx, TraceGraal, 0, \ "Trace level for Graal") \ \ + product(intx, GraalCounterSize, 0, \ + "Reserved size for benchmark counters") \ + \ + product(bool, GraalCountersExcludeCompiler, true, \ + "Exclude Graal compiler threads from benchmark counters") \ + \ product(bool, GraalDeferredInitBarriers, true, \ "Defer write barriers of young objects") \ \ diff -r cfe85a075924 -r 8cd953e97e2d src/share/vm/runtime/thread.cpp --- a/src/share/vm/runtime/thread.cpp Wed Jan 29 10:45:43 2014 +0100 +++ b/src/share/vm/runtime/thread.cpp Wed Jan 29 09:21:50 2014 +0100 @@ -1418,31 +1418,27 @@ #ifdef GRAAL -#if GRAAL_COUNTERS_SIZE > 0 -jlong JavaThread::_graal_old_thread_counters[GRAAL_COUNTERS_SIZE]; +jlong* JavaThread::_graal_old_thread_counters; bool graal_counters_include(oop threadObj) { - return !GRAAL_COUNTERS_EXCLUDE_COMPILER_THREADS || threadObj == NULL || threadObj->klass() != SystemDictionary::CompilerThread_klass(); + return !GraalCountersExcludeCompiler || threadObj == NULL || threadObj->klass() != SystemDictionary::CompilerThread_klass(); } void JavaThread::collect_counters(typeArrayOop array) { - MutexLocker tl(Threads_lock); - for (int i = 0; i < array->length(); i++) { - array->long_at_put(i, _graal_old_thread_counters[i]); - } - for (JavaThread* tp = Threads::first(); tp != NULL; tp = tp->next()) { - if (graal_counters_include(tp->threadObj())) { - for (int i = 0; i < array->length(); i++) { - array->long_at_put(i, array->long_at(i) + tp->_graal_counters[i]); + if (GraalCounterSize > 0) { + MutexLocker tl(Threads_lock); + for (int i = 0; i < array->length(); i++) { + array->long_at_put(i, _graal_old_thread_counters[i]); + } + for (JavaThread* tp = Threads::first(); tp != NULL; tp = tp->next()) { + if (graal_counters_include(tp->threadObj())) { + for (int i = 0; i < array->length(); i++) { + array->long_at_put(i, array->long_at(i) + tp->_graal_counters[i]); + } } } } } -#else -void JavaThread::collect_counters(typeArrayOop array) { - // empty -} -#endif // GRAAL_COUNTERS_SIZE > 0 #endif // GRAAL @@ -1486,11 +1482,12 @@ _graal_alternate_call_target = NULL; _graal_implicit_exception_pc = NULL; _graal_compiling = false; -#if GRAAL_COUNTERS_SIZE > 0 - for (int i = 0; i < GRAAL_COUNTERS_SIZE; i++) { - _graal_counters[i] = 0; + if (GraalCounterSize > 0) { + _graal_counters = NEW_C_HEAP_ARRAY(jlong, GraalCounterSize, mtInternal); + memset(_graal_counters, 0, sizeof(jlong) * GraalCounterSize); + } else { + _graal_counters = NULL; } -#endif // GRAAL_COUNTER_SIZE > 0 #endif // GRAAL (void)const_cast(_exception_oop = NULL); _exception_pc = 0; @@ -1680,13 +1677,14 @@ if (_thread_profiler != NULL) delete _thread_profiler; if (_thread_stat != NULL) delete _thread_stat; -#if defined(GRAAL) && (GRAAL_COUNTERS_SIZE > 0) - if (graal_counters_include(threadObj())) { - for (int i = 0; i < GRAAL_COUNTERS_SIZE; i++) { +#ifdef GRAAL + if (GraalCounterSize > 0 && graal_counters_include(threadObj())) { + for (int i = 0; i < GraalCounterSize; i++) { _graal_old_thread_counters[i] += _graal_counters[i]; } + FREE_C_HEAP_ARRAY(jlong, _graal_counters, mtInternal); } -#endif +#endif // GRAAL } @@ -3458,6 +3456,15 @@ // Initialize global data structures and create system classes in heap vm_init_globals(); +#ifdef GRAAL + if (GraalCounterSize > 0) { + JavaThread::_graal_old_thread_counters = NEW_C_HEAP_ARRAY(jlong, GraalCounterSize, mtInternal); + memset(JavaThread::_graal_old_thread_counters, 0, sizeof(jlong) * GraalCounterSize); + } else { + JavaThread::_graal_old_thread_counters = NULL; + } +#endif // GRAAL + // Attach the main thread to this os thread JavaThread* main_thread = new JavaThread(); main_thread->set_thread_state(_thread_in_vm); @@ -4109,6 +4116,12 @@ delete thread; +#ifdef GRAAL + if (GraalCounterSize > 0) { + FREE_C_HEAP_ARRAY(jlong, JavaThread::_graal_old_thread_counters, mtInternal); + } +#endif // GRAAL + // exit_globals() will delete tty exit_globals(); diff -r cfe85a075924 -r 8cd953e97e2d src/share/vm/runtime/thread.hpp --- a/src/share/vm/runtime/thread.hpp Wed Jan 29 10:45:43 2014 +0100 +++ b/src/share/vm/runtime/thread.hpp Wed Jan 29 09:21:50 2014 +0100 @@ -922,16 +922,10 @@ address _graal_implicit_exception_pc; // pc at which the most recent implicit exception occurred bool _graal_compiling; - // number of counters, increase as needed. 0 == disabled -#define GRAAL_COUNTERS_SIZE (0) -#define GRAAL_COUNTERS_EXCLUDE_COMPILER_THREADS (true) - -#if GRAAL_COUNTERS_SIZE > 0 - jlong _graal_counters[GRAAL_COUNTERS_SIZE]; - static jlong _graal_old_thread_counters[GRAAL_COUNTERS_SIZE]; -#endif // GRAAL_COUNTERS_SIZE > 0 + jlong* _graal_counters; public: + static jlong* _graal_old_thread_counters; static void collect_counters(typeArrayOop array); private: #endif // GRAAL @@ -1394,11 +1388,7 @@ #ifdef GRAAL static ByteSize graal_alternate_call_target_offset() { return byte_offset_of(JavaThread, _graal_alternate_call_target); } static ByteSize graal_implicit_exception_pc_offset() { return byte_offset_of(JavaThread, _graal_implicit_exception_pc); } -#if GRAAL_COUNTERS_SIZE > 0 static ByteSize graal_counters_offset() { return byte_offset_of(JavaThread, _graal_counters ); } -#else - static ByteSize graal_counters_offset() { return in_ByteSize(0); } -#endif // GRAAL_COUNTERS_SIZE > 0 #endif // GRAAL static ByteSize exception_oop_offset() { return byte_offset_of(JavaThread, _exception_oop ); } static ByteSize exception_pc_offset() { return byte_offset_of(JavaThread, _exception_pc ); }