# HG changeset patch # User mgronlun # Date 1498066890 -7200 # Node ID d3b0c2c2a6f0dcc981fa35c88932628eb9569e21 # Parent 96306b5205416ff40bbb8d09d5f7647de422e7dd 8182651: Add TRACE_ONLY conditional macro to support more fine-grained INCLUDE_TRACE programming Reviewed-by: diff --git a/src/share/vm/c1/c1_GraphBuilder.cpp b/src/share/vm/c1/c1_GraphBuilder.cpp --- a/src/share/vm/c1/c1_GraphBuilder.cpp +++ b/src/share/vm/c1/c1_GraphBuilder.cpp @@ -40,6 +40,10 @@ #include "runtime/compilationPolicy.hpp" #include "runtime/vm_version.hpp" #include "utilities/bitMap.inline.hpp" +#if INCLUDE_TRACE +#include "trace/tracing.hpp" +#include "tracefiles/traceEventClasses.hpp" +#endif class BlockListBuilder VALUE_OBJ_CLASS_SPEC { private: @@ -4277,6 +4281,33 @@ } } +#if INCLUDE_TRACE +static void post_inlining_event(int compile_id, + const char* msg, + bool success, + int bci, + ciMethod* caller, + ciMethod* callee) { + assert(caller != NULL, "invariant"); + assert(callee != NULL, "invariant"); + + EventCompilerInlining event; + if (event.should_commit()) { + TraceStructCalleeMethod callee_struct; + callee_struct.set_type(callee->holder()->name()->as_utf8()); + callee_struct.set_name(callee->name()->as_utf8()); + callee_struct.set_descriptor(callee->signature()->as_symbol()->as_utf8()); + event.set_compileId(compile_id); + event.set_message(msg); + event.set_succeeded(success); + event.set_bci(bci); + event.set_caller(caller->get_Method()); + event.set_callee(callee_struct); + event.commit(); + } +} +#endif // INCLUDE_TRACE + void GraphBuilder::print_inlining(ciMethod* callee, const char* msg, bool success) { CompileLog* log = compilation()->log(); if (log != NULL) { @@ -4292,18 +4323,13 @@ log->inline_fail("reason unknown"); } } -#if INCLUDE_TRACE - EventCompilerInlining event; - if (event.should_commit()) { - event.set_compileId(compilation()->env()->task()->compile_id()); - event.set_message(msg); - event.set_succeeded(success); - event.set_bci(bci()); - event.set_caller(method()->get_Method()); - event.set_callee(callee->to_trace_struct()); - event.commit(); - } -#endif // INCLUDE_TRACE + + TRACE_ONLY(post_inlining_event(compilation()->env()->task()->compile_id(), + msg, + success, + bci(), + method(), + callee);) CompileTask::print_inlining_ul(callee, scope()->level(), bci(), msg); diff --git a/src/share/vm/ci/ciEnv.cpp b/src/share/vm/ci/ciEnv.cpp --- a/src/share/vm/ci/ciEnv.cpp +++ b/src/share/vm/ci/ciEnv.cpp @@ -54,7 +54,6 @@ #include "runtime/reflection.hpp" #include "runtime/sharedRuntime.hpp" #include "runtime/thread.inline.hpp" -#include "trace/tracing.hpp" #include "utilities/dtrace.hpp" #include "utilities/macros.hpp" #ifdef COMPILER1 @@ -63,6 +62,9 @@ #ifdef COMPILER2 #include "opto/runtime.hpp" #endif +#if INCLUDE_TRACE +#include "trace/tracing.hpp" +#endif // ciEnv // @@ -1154,13 +1156,14 @@ } void ciEnv::report_failure(const char* reason) { - // Create and fire JFR event +#if INCLUDE_TRACE EventCompilationFailure event; if (event.should_commit()) { event.set_compileId(compile_id()); event.set_failureMessage(reason); event.commit(); } +#endif } // ------------------------------------------------------------------ diff --git a/src/share/vm/ci/ciMethod.cpp b/src/share/vm/ci/ciMethod.cpp --- a/src/share/vm/ci/ciMethod.cpp +++ b/src/share/vm/ci/ciMethod.cpp @@ -47,7 +47,6 @@ #include "runtime/deoptimization.hpp" #include "utilities/bitMap.inline.hpp" #include "utilities/xmlstream.hpp" -#include "trace/tracing.hpp" #ifdef COMPILER2 #include "ci/bcEscapeAnalyzer.hpp" #include "ci/ciTypeFlow.hpp" @@ -1511,13 +1510,3 @@ } // ------------------------------------------------------------------ - -#if INCLUDE_TRACE -TraceStructCalleeMethod ciMethod::to_trace_struct() const { - TraceStructCalleeMethod result; - result.set_type(holder()->name()->as_utf8()); - result.set_name(name()->as_utf8()); - result.set_descriptor(signature()->as_symbol()->as_utf8()); - return result; -} -#endif diff --git a/src/share/vm/ci/ciMethod.hpp b/src/share/vm/ci/ciMethod.hpp --- a/src/share/vm/ci/ciMethod.hpp +++ b/src/share/vm/ci/ciMethod.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -32,7 +32,6 @@ #include "compiler/methodLiveness.hpp" #include "prims/methodHandles.hpp" #include "utilities/bitMap.hpp" -#include "trace/tracing.hpp" class ciMethodBlocks; class MethodLiveness; @@ -363,10 +362,6 @@ void print_short_name(outputStream* st = tty); static bool is_consistent_info(ciMethod* declared_method, ciMethod* resolved_method); - -#if INCLUDE_TRACE - TraceStructCalleeMethod to_trace_struct() const; -#endif }; #endif // SHARE_VM_CI_CIMETHOD_HPP diff --git a/src/share/vm/classfile/classLoaderData.cpp b/src/share/vm/classfile/classLoaderData.cpp --- a/src/share/vm/classfile/classLoaderData.cpp +++ b/src/share/vm/classfile/classLoaderData.cpp @@ -75,6 +75,7 @@ #include "utilities/ostream.hpp" #if INCLUDE_TRACE #include "trace/tracing.hpp" +#include "utilities/ticks.hpp" #endif // helper function to avoid in-line casts @@ -1018,6 +1019,30 @@ } #endif // PRODUCT +#if INCLUDE_TRACE +static Ticks class_unload_time; + +static void post_class_unload_event(Klass* const k) { + assert(k != NULL, "invariant"); + EventClassUnload event(UNTIMED); + event.set_endtime(class_unload_time); + event.set_unloadedClass(k); + event.set_definingClassLoader(k->class_loader_data()); + event.commit(); +} + +static void post_class_unload_events() { + assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!"); + if (Tracing::enabled()) { + if (Tracing::is_event_enabled(TraceClassUnloadEvent)) { + class_unload_time = Ticks::now(); + ClassLoaderDataGraph::classes_unloading_do(&post_class_unload_event); + } + Tracing::on_unloading_classes(); + } +} + +#endif // INCLUDE_TRACE // Move class loader data from main list to the unloaded list for unloading // and deallocation later. @@ -1088,7 +1113,7 @@ data = data->next(); } - post_class_unload_events(); + TRACE_ONLY(post_class_unload_events();) } return seen_dead_loader; @@ -1112,20 +1137,6 @@ } } -void ClassLoaderDataGraph::post_class_unload_events() { -#if INCLUDE_TRACE - assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!"); - if (Tracing::enabled()) { - if (Tracing::is_event_enabled(TraceClassUnloadEvent)) { - assert(_unloading != NULL, "need class loader data unload list!"); - _class_unload_time = Ticks::now(); - classes_unloading_do(&class_unload_event); - } - Tracing::on_unloading_classes(); - } -#endif -} - // CDS support // Global metaspaces for writing information to the shared archive. When @@ -1249,20 +1260,3 @@ class_loader()->print_value_on(out); } } - -#if INCLUDE_TRACE - -Ticks ClassLoaderDataGraph::_class_unload_time; - -void ClassLoaderDataGraph::class_unload_event(Klass* const k) { - assert(k != NULL, "invariant"); - - // post class unload event - EventClassUnload event(UNTIMED); - event.set_endtime(_class_unload_time); - event.set_unloadedClass(k); - event.set_definingClassLoader(k->class_loader_data()); - event.commit(); -} - -#endif // INCLUDE_TRACE diff --git a/src/share/vm/classfile/classLoaderData.hpp b/src/share/vm/classfile/classLoaderData.hpp --- a/src/share/vm/classfile/classLoaderData.hpp +++ b/src/share/vm/classfile/classLoaderData.hpp @@ -33,9 +33,6 @@ #include "trace/traceMacros.hpp" #include "utilities/growableArray.hpp" #include "utilities/macros.hpp" -#if INCLUDE_TRACE -#include "utilities/ticks.hpp" -#endif // // A class loader represents a linkset. Conceptually, a linkset identifies @@ -78,7 +75,6 @@ static bool _metaspace_oom; static ClassLoaderData* add(Handle class_loader, bool anonymous, TRAPS); - static void post_class_unload_events(); public: static ClassLoaderData* find_or_create(Handle class_loader, TRAPS); static void purge(); @@ -135,12 +131,6 @@ #ifndef PRODUCT static bool contains_loader_data(ClassLoaderData* loader_data); #endif - -#if INCLUDE_TRACE - private: - static Ticks _class_unload_time; - static void class_unload_event(Klass* const k); -#endif }; // ClassLoaderData class diff --git a/src/share/vm/classfile/systemDictionary.cpp b/src/share/vm/classfile/systemDictionary.cpp --- a/src/share/vm/classfile/systemDictionary.cpp +++ b/src/share/vm/classfile/systemDictionary.cpp @@ -72,9 +72,7 @@ #include "runtime/signature.hpp" #include "services/classLoadingService.hpp" #include "services/threadService.hpp" -#include "trace/traceMacros.hpp" #include "utilities/macros.hpp" -#include "utilities/ticks.hpp" #if INCLUDE_CDS #include "classfile/sharedClassUtil.hpp" #include "classfile/systemDictionaryShared.hpp" @@ -615,32 +613,31 @@ return NULL; } -static void post_class_load_event(const Ticks& start_time, - InstanceKlass* k, +#if INCLUDE_TRACE +static void post_class_load_event(EventClassLoad* event, + const InstanceKlass* k, const ClassLoaderData* init_cld) { -#if INCLUDE_TRACE - EventClassLoad event(UNTIMED); - if (event.should_commit()) { - event.set_starttime(start_time); - event.set_loadedClass(k); - event.set_definingClassLoader(k->class_loader_data()); - event.set_initiatingClassLoader(init_cld); - event.commit(); + assert(event != NULL, "invariant"); + assert(k != NULL, "invariant"); + + if (event->should_commit()) { + event->set_loadedClass(k); + //event->set_definingClassLoader(k->class_loader_data()); + event->set_initiatingClassLoader(init_cld); + event->commit(); } -#endif // INCLUDE_TRACE } -static void class_define_event(InstanceKlass* k, - const ClassLoaderData* def_cld) { -#if INCLUDE_TRACE +static void post_class_define_event(const InstanceKlass* k, + const ClassLoaderData* def_cld) { EventClassDefine event; if (event.should_commit()) { event.set_definedClass(k); event.set_definingClassLoader(def_cld); event.commit(); } +} #endif // INCLUDE_TRACE -} // Be careful when modifying this code: once you have run // placeholders()->find_and_add(PlaceholderTable::LOAD_INSTANCE), @@ -653,7 +650,7 @@ assert(name != NULL && !FieldType::is_array(name) && !FieldType::is_obj(name), "invalid class name"); - Ticks class_load_start_time = Ticks::now(); + TRACE_ONLY(EventClassLoad ev;) HandleMark hm(THREAD); @@ -899,7 +896,7 @@ return NULL; } - post_class_load_event(class_load_start_time, k, loader_data); + TRACE_ONLY(post_class_load_event(&ev, k, loader_data);) #ifdef ASSERT { @@ -1022,8 +1019,7 @@ const InstanceKlass* host_klass, GrowableArray* cp_patches, TRAPS) { - - Ticks class_load_start_time = Ticks::now(); + TRACE_ONLY(EventClassLoad ev;) ClassLoaderData* loader_data; if (host_klass != NULL) { @@ -1082,7 +1078,7 @@ JvmtiExport::post_class_load((JavaThread *) THREAD, k); } - post_class_load_event(class_load_start_time, k, loader_data); + TRACE_ONLY(post_class_load_event(&ev, k, loader_data);) } assert(host_klass != NULL || NULL == cp_patches, "cp_patches only found with host_klass"); @@ -1664,7 +1660,7 @@ JvmtiExport::post_class_load((JavaThread *) THREAD, k); } - class_define_event(k, loader_data); + TRACE_ONLY(post_class_define_event(k, loader_data);) } // Support parallel classloading diff --git a/src/share/vm/code/codeCache.cpp b/src/share/vm/code/codeCache.cpp --- a/src/share/vm/code/codeCache.cpp +++ b/src/share/vm/code/codeCache.cpp @@ -49,7 +49,6 @@ #include "runtime/mutexLocker.hpp" #include "runtime/sweeper.hpp" #include "services/memoryService.hpp" -#include "trace/tracing.hpp" #include "utilities/xmlstream.hpp" #ifdef COMPILER1 #include "c1/c1_Compilation.hpp" @@ -60,6 +59,9 @@ #include "opto/compile.hpp" #include "opto/node.hpp" #endif +#if INCLUDE_TRACE +#include "trace/tracing.hpp" +#endif // Helper class for printing in CodeCache class CodeBlob_sizes { @@ -1355,6 +1357,7 @@ heap->report_full(); +#if INCLUDE_TRACE EventCodeCacheFull event; if (event.should_commit()) { event.set_codeBlobType((u1)code_blob_type); @@ -1367,6 +1370,7 @@ event.set_unallocatedCapacity(heap->unallocated_capacity()); event.set_fullCount(heap->full_count()); event.commit(); +#endif } } PRAGMA_DIAG_POP @@ -1624,4 +1628,3 @@ blob_count(), nmethod_count(), adapter_count(), unallocated_capacity()); } - diff --git a/src/share/vm/compiler/compileBroker.cpp b/src/share/vm/compiler/compileBroker.cpp --- a/src/share/vm/compiler/compileBroker.cpp +++ b/src/share/vm/compiler/compileBroker.cpp @@ -50,7 +50,6 @@ #include "runtime/sharedRuntime.hpp" #include "runtime/sweeper.hpp" #include "runtime/timerTrace.hpp" -#include "trace/tracing.hpp" #include "utilities/dtrace.hpp" #include "utilities/events.hpp" #ifdef COMPILER1 @@ -68,6 +67,9 @@ #ifdef SHARK #include "shark/sharkCompiler.hpp" #endif +#if INCLUDE_TRACE +#include "trace/tracing.hpp" +#endif #ifdef DTRACE_ENABLED @@ -1751,8 +1753,10 @@ } } -void CompileBroker::post_compile(CompilerThread* thread, CompileTask* task, EventCompilation& event, bool success, ciEnv* ci_env) { - +void CompileBroker::post_compile(CompilerThread* thread, + CompileTask* task, + bool success, + ciEnv* ci_env) { if (success) { task->mark_success(); if (ci_env != NULL) { @@ -1768,17 +1772,28 @@ // simulate crash during compilation assert(task->compile_id() != CICrashAt, "just as planned"); - if (event.should_commit()) { - event.set_method(task->method()); - event.set_compileId(task->compile_id()); - event.set_compileLevel(task->comp_level()); - event.set_succeded(task->is_success()); - event.set_isOsr(task->osr_bci() != CompileBroker::standard_entry_bci); - event.set_codeSize((task->code() == NULL) ? 0 : task->code()->total_size()); - event.set_inlinedBytes(task->num_inlined_bytecodes()); - event.commit(); +} + +#if INCLUDE_TRACE +static void post_compilation_event(EventCompilation* event, + CompilerThread* thread, + CompileTask* task, + CompilationLog* log, + bool success, + ciEnv* ci_env) { + assert(event != NULL, "invariant"); + if (event->should_commit()) { + event->set_method(task->method()); + event->set_compileId(task->compile_id()); + event->set_compileLevel(task->comp_level()); + event->set_succeded(task->is_success()); + event->set_isOsr(task->osr_bci() != CompileBroker::standard_entry_bci); + event->set_codeSize((task->code() == NULL) ? 0 : task->code()->total_size()); + event->set_inlinedBytes(task->num_inlined_bytecodes()); + event->commit(); } } +#endif // INCLUDE_TRACE int DirectivesStack::_depth = 0; CompilerDirectives* DirectivesStack::_top = NULL; @@ -1854,13 +1869,18 @@ JVMCICompiler* jvmci = (JVMCICompiler*) comp; TraceTime t1("compilation", &time); - EventCompilation event; + TRACE_ONLY(EventCompilation event;) JVMCIEnv env(task, system_dictionary_modification_counter); methodHandle method(thread, target_handle); jvmci->compile_method(method, osr_bci, &env); - - post_compile(thread, task, event, task->code() != NULL, NULL); + post_compile(thread, task, task->code() != NULL, NULL); + TRACE_ONLY(post_compilation_event(&event, + thread, + task, + _compilation_log, + task->code() != NULL, + NULL);) failure_reason = env.failure_reason(); if (!env.retryable()) { @@ -1893,7 +1913,7 @@ ciMethod* target = ci_env.get_method_from_handle(target_handle); TraceTime t1("compilation", &time); - EventCompilation event; + TRACE_ONLY(EventCompilation event;) if (comp == NULL) { ci_env.record_method_not_compilable("no compiler", !TieredCompilation); @@ -1923,7 +1943,13 @@ ci_env.report_failure(failure_reason); } - post_compile(thread, task, event, !ci_env.failing(), &ci_env); + post_compile(thread, task, !ci_env.failing(), &ci_env); + TRACE_ONLY(post_compilation_event(&event, + thread, + task, + _compilation_log, + !ci_env.failing(), + &ci_env);) } // Remove the JNI handle block after the ciEnv destructor has run in // the previous block. diff --git a/src/share/vm/compiler/compileBroker.hpp b/src/share/vm/compiler/compileBroker.hpp --- a/src/share/vm/compiler/compileBroker.hpp +++ b/src/share/vm/compiler/compileBroker.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -30,7 +30,6 @@ #include "compiler/compileTask.hpp" #include "compiler/compilerDirectives.hpp" #include "runtime/perfData.hpp" -#include "trace/tracing.hpp" #include "utilities/stack.hpp" #if INCLUDE_JVMCI #include "jvmci/jvmciCompiler.hpp" @@ -240,7 +239,7 @@ #endif static void invoke_compiler_on_method(CompileTask* task); - static void post_compile(CompilerThread* thread, CompileTask* task, EventCompilation& event, bool success, ciEnv* ci_env); + static void post_compile(CompilerThread* thread, CompileTask* task, bool success, ciEnv* ci_env); static void set_last_compile(CompilerThread *thread, const methodHandle& method, bool is_osr, int comp_level); static void push_jni_handle_block(); static void pop_jni_handle_block(); diff --git a/src/share/vm/opto/bytecodeInfo.cpp b/src/share/vm/opto/bytecodeInfo.cpp --- a/src/share/vm/opto/bytecodeInfo.cpp +++ b/src/share/vm/opto/bytecodeInfo.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -34,6 +34,10 @@ #include "opto/parse.hpp" #include "runtime/handles.inline.hpp" #include "utilities/events.hpp" +#if INCLUDE_TRACE +#include "trace/tracing.hpp" +#include "tracefiles/traceEventClasses.hpp" +#endif //============================================================================= //------------------------------InlineTree------------------------------------- @@ -484,6 +488,33 @@ return NULL; } +#if INCLUDE_TRACE +static void post_inlining_event(int compile_id, + const char* msg, + bool success, + int bci, + ciMethod* caller, + ciMethod* callee) { + assert(caller != NULL, "invariant"); + assert(callee != NULL, "invariant"); + + EventCompilerInlining event; + if (event.should_commit()) { + TraceStructCalleeMethod callee_struct; + callee_struct.set_type(callee->holder()->name()->as_utf8()); + callee_struct.set_name(callee->name()->as_utf8()); + callee_struct.set_descriptor(callee->signature()->as_symbol()->as_utf8()); + event.set_compileId(compile_id); + event.set_message(msg); + event.set_succeeded(success); + event.set_bci(bci); + event.set_caller(caller->get_Method()); + event.set_callee(callee_struct); + event.commit(); + } +} +#endif // INCLUDE_TRACE + //------------------------------print_inlining--------------------------------- void InlineTree::print_inlining(ciMethod* callee_method, int caller_bci, ciMethod* caller_method, bool success) const { @@ -507,18 +538,12 @@ //tty->print(" bcs: %d+%d invoked: %d", top->count_inline_bcs(), callee_method->code_size(), callee_method->interpreter_invocation_count()); } } -#if INCLUDE_TRACE - EventCompilerInlining event; - if (event.should_commit()) { - event.set_compileId(C->compile_id()); - event.set_message(inline_msg); - event.set_succeeded(success); - event.set_bci(caller_bci); - event.set_caller(caller_method->get_Method()); - event.set_callee(callee_method->to_trace_struct()); - event.commit(); - } -#endif // INCLUDE_TRACE + TRACE_ONLY(post_inlining_event(C->compile_id(), + inline_msg, + success, + caller_bci, + caller_method, + callee_method);) } //------------------------------ok_to_inline----------------------------------- diff --git a/src/share/vm/prims/jni.cpp b/src/share/vm/prims/jni.cpp --- a/src/share/vm/prims/jni.cpp +++ b/src/share/vm/prims/jni.cpp @@ -76,8 +76,6 @@ #include "runtime/vm_operations.hpp" #include "services/memTracker.hpp" #include "services/runtimeService.hpp" -#include "trace/traceMacros.hpp" -#include "trace/tracing.hpp" #include "utilities/defaultStream.hpp" #include "utilities/dtrace.hpp" #include "utilities/events.hpp" @@ -91,6 +89,10 @@ #include "jvmci/jvmciCompiler.hpp" #include "jvmci/jvmciRuntime.hpp" #endif +#if INCLUDE_TRACE +#include "trace/traceMacros.hpp" +#include "trace/tracing.hpp" +#endif static jint CurrentVersion = JNI_VERSION_9; @@ -3825,6 +3827,17 @@ } } +#if INCLUDE_TRACE +static void post_thread_start_event(const JavaThread* jt) { + assert(jt != NULL, "invariant"); + EventThreadStart event; + if (event.should_commit()) { + event.set_thread(THREAD_TRACE_ID(jt)); + event.commit(); + } +} +#endif + // Returns the function structure struct JNINativeInterface_* jni_functions() { #if INCLUDE_JNI_CHECK @@ -3970,11 +3983,7 @@ JvmtiExport::post_thread_start(thread); } - EventThreadStart event; - if (event.should_commit()) { - event.set_thread(THREAD_TRACE_ID(thread)); - event.commit(); - } + TRACE_ONLY(post_thread_start_event(thread);) #ifndef PRODUCT // Check if we should compile all classes on bootclasspath @@ -4190,11 +4199,7 @@ JvmtiExport::post_thread_start(thread); } - EventThreadStart event; - if (event.should_commit()) { - event.set_thread(THREAD_TRACE_ID(thread)); - event.commit(); - } + TRACE_ONLY(post_thread_start_event(thread);) *(JNIEnv**)penv = thread->jni_environment(); diff --git a/src/share/vm/prims/jvm.cpp b/src/share/vm/prims/jvm.cpp --- a/src/share/vm/prims/jvm.cpp +++ b/src/share/vm/prims/jvm.cpp @@ -72,7 +72,6 @@ #include "services/attachListener.hpp" #include "services/management.hpp" #include "services/threadService.hpp" -#include "trace/tracing.hpp" #include "utilities/copy.hpp" #include "utilities/defaultStream.hpp" #include "utilities/dtrace.hpp" @@ -84,7 +83,9 @@ #include "classfile/sharedClassUtil.hpp" #include "classfile/systemDictionaryShared.hpp" #endif - +#if INCLUDE_TRACE +#include "trace/tracing.hpp" +#endif #include /* @@ -2970,6 +2971,15 @@ os::naked_yield(); JVM_END +#if INCLUDE_TRACE +static void post_thread_sleep_event(EventThreadSleep* event, jlong millis) { + assert(event != NULL, "invariant"); + if (event->should_commit()) { + event->set_time(millis); + event->commit(); + } +} +#endif JVM_ENTRY(void, JVM_Sleep(JNIEnv* env, jclass threadClass, jlong millis)) JVMWrapper("JVM_Sleep"); @@ -2987,8 +2997,7 @@ JavaThreadSleepState jtss(thread); HOTSPOT_THREAD_SLEEP_BEGIN(millis); - - EventThreadSleep event; + TRACE_ONLY(EventThreadSleep event;) if (millis == 0) { os::naked_yield(); @@ -2999,10 +3008,7 @@ // An asynchronous exception (e.g., ThreadDeathException) could have been thrown on // us while we were sleeping. We do not overwrite those. if (!HAS_PENDING_EXCEPTION) { - if (event.should_commit()) { - event.set_time(millis); - event.commit(); - } + TRACE_ONLY(post_thread_sleep_event(&event, millis);) HOTSPOT_THREAD_SLEEP_END(1); // TODO-FIXME: THROW_MSG returns which means we will not call set_state() @@ -3012,10 +3018,7 @@ } thread->osthread()->set_state(old_state); } - if (event.should_commit()) { - event.set_time(millis); - event.commit(); - } + TRACE_ONLY(post_thread_sleep_event(&event, millis);) HOTSPOT_THREAD_SLEEP_END(0); JVM_END diff --git a/src/share/vm/prims/unsafe.cpp b/src/share/vm/prims/unsafe.cpp --- a/src/share/vm/prims/unsafe.cpp +++ b/src/share/vm/prims/unsafe.cpp @@ -39,14 +39,15 @@ #include "runtime/reflection.hpp" #include "runtime/vm_version.hpp" #include "services/threadService.hpp" -#include "trace/tracing.hpp" #include "utilities/copy.hpp" #include "utilities/dtrace.hpp" #include "utilities/macros.hpp" #if INCLUDE_ALL_GCS #include "gc/g1/g1SATBCardTableModRefBS.hpp" #endif // INCLUDE_ALL_GCS - +#if INCLUDE_TRACE +#include "trace/tracing.hpp" +#endif /** * Implementation of the jdk.internal.misc.Unsafe class */ @@ -1057,22 +1058,27 @@ #endif } UNSAFE_END +#if INCLUDE_TRACE +static void post_thread_park_event(EventThreadPark* event, const oop obj, jlong timeout) { + assert(event != NULL, "invariant"); + if (event->should_commit()) { + event->set_parkedClass((obj != NULL) ? obj->klass() : NULL); + event->set_timeout(timeout); + event->set_address((obj != NULL) ? (TYPE_ADDRESS) cast_from_oop(obj) : 0); + event->commit(); + } +} +#endif + UNSAFE_ENTRY(void, Unsafe_Park(JNIEnv *env, jobject unsafe, jboolean isAbsolute, jlong time)) { - EventThreadPark event; HOTSPOT_THREAD_PARK_BEGIN((uintptr_t) thread->parker(), (int) isAbsolute, time); - + TRACE_ONLY(EventThreadPark event;) JavaThreadParkedState jtps(thread, time != 0); thread->parker()->park(isAbsolute != 0, time); + HOTSPOT_THREAD_PARK_END((uintptr_t) thread->parker()); + TRACE_ONLY(post_thread_park_event(&event, thread->current_park_blocker(), time);) - HOTSPOT_THREAD_PARK_END((uintptr_t) thread->parker()); - if (event.should_commit()) { - oop obj = thread->current_park_blocker(); - event.set_parkedClass((obj != NULL) ? obj->klass() : NULL); - event.set_timeout(time); - event.set_address((obj != NULL) ? (TYPE_ADDRESS) cast_from_oop(obj) : 0); - event.commit(); - } } UNSAFE_END UNSAFE_ENTRY(void, Unsafe_Unpark(JNIEnv *env, jobject unsafe, jobject jthread)) { diff --git a/src/share/vm/runtime/globals.cpp b/src/share/vm/runtime/globals.cpp --- a/src/share/vm/runtime/globals.cpp +++ b/src/share/vm/runtime/globals.cpp @@ -33,7 +33,6 @@ #include "runtime/commandLineFlagRangeList.hpp" #include "runtime/os.hpp" #include "runtime/sharedRuntime.hpp" -#include "trace/tracing.hpp" #include "utilities/defaultStream.hpp" #include "utilities/macros.hpp" #include "utilities/ostream.hpp" @@ -52,6 +51,9 @@ #ifdef SHARK #include "shark/shark_globals.hpp" #endif +#if INCLUDE_TRACE +#include "trace/tracing.hpp" +#endif RUNTIME_FLAGS(MATERIALIZE_DEVELOPER_FLAG, \ MATERIALIZE_PD_DEVELOPER_FLAG, \ @@ -988,12 +990,14 @@ template static void trace_flag_changed(const char* name, const T old_value, const T new_value, const Flag::Flags origin) { +#if INCLUDE_TRACE E e; e.set_name(name); e.set_oldValue(old_value); e.set_newValue(new_value); e.set_origin(origin); e.commit(); +#endif } static Flag::Error apply_constraint_and_check_range_bool(const char* name, bool new_value, bool verbose) { diff --git a/src/share/vm/runtime/java.cpp b/src/share/vm/runtime/java.cpp --- a/src/share/vm/runtime/java.cpp +++ b/src/share/vm/runtime/java.cpp @@ -66,8 +66,6 @@ #include "runtime/timer.hpp" #include "runtime/vm_operations.hpp" #include "services/memTracker.hpp" -#include "trace/traceMacros.hpp" -#include "trace/tracing.hpp" #include "utilities/dtrace.hpp" #include "utilities/globalDefinitions.hpp" #include "utilities/histogram.hpp" @@ -88,6 +86,10 @@ #include "opto/indexSet.hpp" #include "opto/runtime.hpp" #endif +#if INCLUDE_TRACE +#include "trace/traceMacros.hpp" +#include "trace/tracing.hpp" +#endif GrowableArray* collected_profiled_methods; @@ -399,6 +401,16 @@ #endif +#if INCLUDE_TRACE +static void post_thread_end_event(const JavaThread* jt) { + EventThreadEnd event; + if (event.should_commit()) { + event.set_thread(THREAD_TRACE_ID(jt)); + event.commit(); + } +} +#endif + // Note: before_exit() can be executed only once, if more than one threads // are trying to shutdown the VM at the same time, only one thread // can run before_exit() and all other threads must wait. @@ -448,12 +460,7 @@ os::infinite_sleep(); } - EventThreadEnd event; - if (event.should_commit()) { - event.set_thread(THREAD_TRACE_ID(thread)); - event.commit(); - } - + TRACE_ONLY(post_thread_end_event(thread);) TRACE_VM_EXIT(); // Stop the WatcherThread. We do this before disenrolling various diff --git a/src/share/vm/runtime/safepoint.cpp b/src/share/vm/runtime/safepoint.cpp --- a/src/share/vm/runtime/safepoint.cpp +++ b/src/share/vm/runtime/safepoint.cpp @@ -56,8 +56,6 @@ #include "runtime/thread.inline.hpp" #include "runtime/timerTrace.hpp" #include "services/runtimeService.hpp" -#include "trace/tracing.hpp" -#include "trace/traceMacros.hpp" #include "utilities/events.hpp" #include "utilities/macros.hpp" #if INCLUDE_ALL_GCS @@ -67,6 +65,76 @@ #ifdef COMPILER1 #include "c1/c1_globals.hpp" #endif +#if INCLUDE_TRACE +#include "trace/tracing.hpp" + +static void post_safepoint_begin_event(EventSafepointBegin* event, + int safepoint_id, + int thread_count, + int critical_thread_count) { + assert(event != NULL, "invariant"); + if (event->should_commit()) { + event->set_safepointId(safepoint_id); + event->set_totalThreadCount(thread_count); + event->set_jniCriticalThreadCount(critical_thread_count); + event->commit(); + } +} + +static void post_safepoint_cleanup_event(EventSafepointCleanup* event, + int safepoint_id) { + assert(event != NULL, "invariant"); + if (event->should_commit()) { + event->set_safepointId(safepoint_id); + event->commit(); + } +} + +static void post_safepoint_synchronize_event(EventSafepointStateSynchronization* event, + int safepoint_id, + int initial_number_of_threads, + int threads_waiting_to_block, + unsigned int iterations) { + assert(event != NULL, "invariant"); + if (event->should_commit()) { + event->set_safepointId(safepoint_id); + event->set_initialThreadCount(initial_number_of_threads); + event->set_runningThreadCount(threads_waiting_to_block); + event->set_iterations(iterations); + event->commit(); + } +} + +static void post_safepoint_wait_blocked_event(EventSafepointWaitBlocked* event, + int safepoint_id, + int initial_threads_waiting_to_block) { + assert(event != NULL, "invariant"); + if (event->should_commit()) { + event->set_safepointId(safepoint_id); + event->set_runningThreadCount(initial_threads_waiting_to_block); + event->commit(); + } +} + +static void post_safepoint_end_event(EventSafepointEnd* event, int safepoint_id) { + assert(event != NULL, "invariant"); + if (event->should_commit()) { + event->set_safepointId(safepoint_id); + event->commit(); + } +} + +static void post_safepoint_cleanup_task_event(EventSafepointCleanupTask* event, + int safepoint_id, + const char* name) { + assert(event != NULL, "invariant"); + if (event->should_commit()) { + event->set_safepointId(safepoint_id); + event->set_name(name); + event->commit(); + } +} +#endif // INCLUDE_TRACE // -------------------------------------------------------------------------------------------------- // Implementation of Safepoint begin/end @@ -82,7 +150,7 @@ // Roll all threads forward to a safepoint and suspend them all void SafepointSynchronize::begin() { - EventSafepointBegin begin_event; + TRACE_ONLY(EventSafepointBegin begin_event;) Thread* myThread = Thread::current(); assert(myThread->is_VM_thread(), "Only VM thread may execute a safepoint"); @@ -173,7 +241,7 @@ // block itself when it attempts transitions to a new state. // { - EventSafepointStateSynchronization sync_event; + TRACE_ONLY(EventSafepointStateSynchronization sync_event;) int initial_running = 0; _state = _synchronizing; @@ -327,18 +395,16 @@ update_statistics_on_spin_end(); } - if (sync_event.should_commit()) { - sync_event.set_safepointId(safepoint_counter()); - sync_event.set_initialThreadCount(initial_running); - sync_event.set_runningThreadCount(_waiting_to_block); - sync_event.set_iterations(iterations); - sync_event.commit(); - } - } //EventSafepointStateSync + TRACE_ONLY(post_safepoint_synchronize_event(&sync_event, + safepoint_counter(), + initial_running, + _waiting_to_block, + iterations);) + } // wait until all threads are stopped { - EventSafepointWaitBlocked wait_blocked_event; + TRACE_ONLY(EventSafepointWaitBlocked wait_blocked_event;) int initial_waiting_to_block = _waiting_to_block; while (_waiting_to_block > 0) { @@ -378,12 +444,10 @@ OrderAccess::fence(); - if (wait_blocked_event.should_commit()) { - wait_blocked_event.set_safepointId(safepoint_counter()); - wait_blocked_event.set_runningThreadCount(initial_waiting_to_block); - wait_blocked_event.commit(); - } - } // EventSafepointWaitBlocked + TRACE_ONLY(post_safepoint_wait_blocked_event(&wait_blocked_event, + safepoint_counter(), + initial_waiting_to_block);) + } #ifdef ASSERT for (JavaThread *cur = Threads::first(); cur != NULL; cur = cur->next()) { @@ -406,30 +470,23 @@ // Call stuff that needs to be run when a safepoint is just about to be completed { - EventSafepointCleanup cleanup_event; + TRACE_ONLY(EventSafepointCleanup cleanup_event;) do_cleanup_tasks(); - if (cleanup_event.should_commit()) { - cleanup_event.set_safepointId(safepoint_counter()); - cleanup_event.commit(); - } + TRACE_ONLY(post_safepoint_cleanup_event(&cleanup_event, safepoint_counter());) } if (PrintSafepointStatistics) { // Record how much time spend on the above cleanup tasks update_statistics_on_cleanup_end(os::javaTimeNanos()); } - if (begin_event.should_commit()) { - begin_event.set_safepointId(safepoint_counter()); - begin_event.set_totalThreadCount(nof_threads); - begin_event.set_jniCriticalThreadCount(_current_jni_active_count); - begin_event.commit(); - } + TRACE_ONLY(post_safepoint_begin_event(&begin_event, safepoint_counter(), + nof_threads, _current_jni_active_count);) } // Wake up all threads, so they are ready to resume execution after the safepoint // operation has been carried out void SafepointSynchronize::end() { - EventSafepointEnd event; + TRACE_ONLY(EventSafepointEnd event;) int safepoint_id = safepoint_counter(); // Keep the odd counter as "id" assert(Threads_lock->owned_by_self(), "must hold Threads_lock"); @@ -518,10 +575,7 @@ // since last safepoint. _end_of_last_safepoint = os::javaTimeMillis(); - if (event.should_commit()) { - event.set_safepointId(safepoint_id); - event.commit(); - } + TRACE_ONLY(post_safepoint_end_event(&event, safepoint_id);) } bool SafepointSynchronize::is_cleanup_needed() { @@ -532,71 +586,63 @@ return false; } -static void event_safepoint_cleanup_task_commit(EventSafepointCleanupTask& event, const char* name) { - if (event.should_commit()) { - event.set_safepointId(SafepointSynchronize::safepoint_counter()); - event.set_name(name); - event.commit(); - } -} - // Various cleaning tasks that should be done periodically at safepoints void SafepointSynchronize::do_cleanup_tasks() { { const char* name = "deflating idle monitors"; - EventSafepointCleanupTask event; + TRACE_ONLY(EventSafepointCleanupTask event;) TraceTime timer(name, TRACETIME_LOG(Info, safepoint, cleanup)); ObjectSynchronizer::deflate_idle_monitors(); - event_safepoint_cleanup_task_commit(event, name); + TRACE_ONLY(post_safepoint_cleanup_task_event(&event, safepoint_counter(), name);) } { const char* name = "updating inline caches"; - EventSafepointCleanupTask event; + TRACE_ONLY(EventSafepointCleanupTask event;) TraceTime timer(name, TRACETIME_LOG(Info, safepoint, cleanup)); InlineCacheBuffer::update_inline_caches(); - event_safepoint_cleanup_task_commit(event, name); + TRACE_ONLY(post_safepoint_cleanup_task_event(&event, safepoint_counter(), name);) } { const char* name = "compilation policy safepoint handler"; - EventSafepointCleanupTask event; + TRACE_ONLY(EventSafepointCleanupTask event;) TraceTime timer("compilation policy safepoint handler", TRACETIME_LOG(Info, safepoint, cleanup)); CompilationPolicy::policy()->do_safepoint_work(); - event_safepoint_cleanup_task_commit(event, name); + TRACE_ONLY(post_safepoint_cleanup_task_event(&event, safepoint_counter(), name);) } { const char* name = "mark nmethods"; - EventSafepointCleanupTask event; + TRACE_ONLY(EventSafepointCleanupTask event;) TraceTime timer(name, TRACETIME_LOG(Info, safepoint, cleanup)); NMethodSweeper::mark_active_nmethods(); - event_safepoint_cleanup_task_commit(event, name); + TRACE_ONLY(post_safepoint_cleanup_task_event(&event, safepoint_counter(), name);) } if (SymbolTable::needs_rehashing()) { const char* name = "rehashing symbol table"; - EventSafepointCleanupTask event; + TRACE_ONLY(EventSafepointCleanupTask event;) TraceTime timer(name, TRACETIME_LOG(Info, safepoint, cleanup)); SymbolTable::rehash_table(); - event_safepoint_cleanup_task_commit(event, name); + TRACE_ONLY(post_safepoint_cleanup_task_event(&event, safepoint_counter(), name);) } if (StringTable::needs_rehashing()) { const char* name = "rehashing string table"; - EventSafepointCleanupTask event; + TRACE_ONLY(EventSafepointCleanupTask event;) TraceTime timer(name, TRACETIME_LOG(Info, safepoint, cleanup)); StringTable::rehash_table(); - event_safepoint_cleanup_task_commit(event, name); + TRACE_ONLY(post_safepoint_cleanup_task_event(&event, safepoint_counter(), name);) } { // CMS delays purging the CLDG until the beginning of the next safepoint and to // make sure concurrent sweep is done const char* name = "purging class loader data graph"; - EventSafepointCleanupTask event; + TRACE_ONLY(EventSafepointCleanupTask event;) TraceTime timer(name, TRACETIME_LOG(Info, safepoint, cleanup)); ClassLoaderDataGraph::purge_if_needed(); - event_safepoint_cleanup_task_commit(event, name); + TRACE_ONLY(post_safepoint_cleanup_task_event(&event, safepoint_counter(), name);) } } diff --git a/src/share/vm/runtime/sharedRuntime.cpp b/src/share/vm/runtime/sharedRuntime.cpp --- a/src/share/vm/runtime/sharedRuntime.cpp +++ b/src/share/vm/runtime/sharedRuntime.cpp @@ -61,7 +61,6 @@ #include "runtime/stubRoutines.hpp" #include "runtime/vframe.hpp" #include "runtime/vframeArray.hpp" -#include "trace/tracing.hpp" #include "utilities/copy.hpp" #include "utilities/dtrace.hpp" #include "utilities/events.hpp" @@ -71,6 +70,9 @@ #ifdef COMPILER1 #include "c1/c1_Runtime1.hpp" #endif +#if INCLUDE_TRACE +#include "trace/tracing.hpp" +#endif // Shared stub locations RuntimeStub* SharedRuntime::_wrong_method_blob; @@ -3129,6 +3131,16 @@ thread->set_reserved_stack_activation(thread->stack_base()); JRT_END +#if INCLUDE_TRACE +static void post_stack_reservation_event(const Method* method) { + EventReservedStackActivation event; + if (event.should_commit()) { + event.set_method(method); + event.commit(); + } +} +#endif + frame SharedRuntime::look_for_reserved_stack_annotated_method(JavaThread* thread, frame fr) { frame activation; CompiledMethod* nm = NULL; @@ -3153,11 +3165,7 @@ warning("Potentially dangerous stack overflow in " "ReservedStackAccess annotated method %s [%d]", method->name_and_sig_as_C_string(), count++); - EventReservedStackActivation event; - if (event.should_commit()) { - event.set_method(method); - event.commit(); - } + TRACE_ONLY(post_stack_reservation_event(method);) } if (fr.is_first_java_frame()) { break; @@ -3167,4 +3175,3 @@ } return activation; } - diff --git a/src/share/vm/runtime/sweeper.cpp b/src/share/vm/runtime/sweeper.cpp --- a/src/share/vm/runtime/sweeper.cpp +++ b/src/share/vm/runtime/sweeper.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -38,10 +38,14 @@ #include "runtime/sweeper.hpp" #include "runtime/thread.inline.hpp" #include "runtime/vm_operations.hpp" -#include "trace/tracing.hpp" #include "utilities/events.hpp" +#include "utilities/macros.hpp" #include "utilities/ticks.inline.hpp" #include "utilities/xmlstream.hpp" +#if INCLUDE_TRACE +#include "trace/tracing.hpp" +#endif + #ifdef ASSERT @@ -485,6 +489,8 @@ _total_nof_c2_methods_reclaimed += flushed_c2_count; _peak_sweep_time = MAX2(_peak_sweep_time, _total_time_this_sweep); } + +#if INCLUDE_TRACE EventSweepCodeCache event(UNTIMED); if (event.should_commit()) { event.set_starttime(sweep_start_counter); @@ -495,6 +501,7 @@ event.set_zombifiedCount(zombified_count); event.commit(); } +#endif // INCLUDE_TRACE #ifdef ASSERT if(PrintMethodFlushing) { diff --git a/src/share/vm/runtime/synchronizer.cpp b/src/share/vm/runtime/synchronizer.cpp --- a/src/share/vm/runtime/synchronizer.cpp +++ b/src/share/vm/runtime/synchronizer.cpp @@ -42,11 +42,12 @@ #include "runtime/synchronizer.hpp" #include "runtime/thread.inline.hpp" #include "runtime/vframe.hpp" -#include "trace/traceMacros.hpp" -#include "trace/tracing.hpp" #include "utilities/dtrace.hpp" #include "utilities/events.hpp" #include "utilities/preserveException.hpp" +#if INCLUDE_TRACE +#include "trace/tracing.hpp" +#endif // The "core" versions of monitor enter and exit reside in this file. // The interpreter and compilers contain specialized transliterated @@ -125,10 +126,6 @@ static volatile int gMonitorFreeCount = 0; // # on gFreeList static volatile int gMonitorPopulation = 0; // # Extant -- in circulation -static void post_monitor_inflate_event(EventJavaMonitorInflate&, - const oop, - const ObjectSynchronizer::InflateCause); - #define CHAINMARKER (cast_to_oop(-1)) @@ -1380,16 +1377,30 @@ inflate_cause_vm_internal); } +#if INCLUDE_TRACE +static void post_monitor_inflate_event(EventJavaMonitorInflate* event, + const oop obj, + ObjectSynchronizer::InflateCause cause) { + assert(event != NULL, "invariant"); + if (event->should_commit()) { + event->set_monitorClass(obj->klass()); + event->set_address((TYPE_ADDRESS)(uintptr_t)(void*)obj); + event->set_cause((u1)cause); + event->commit(); + } +} +#endif + ObjectMonitor* ObjectSynchronizer::inflate(Thread * Self, - oop object, - const InflateCause cause) { + oop object, + const InflateCause cause) { // Inflate mutates the heap ... // Relaxing assertion for bug 6320749. assert(Universe::verify_in_progress() || !SafepointSynchronize::is_at_safepoint(), "invariant"); - EventJavaMonitorInflate event; + TRACE_ONLY(EventJavaMonitorInflate event;) for (;;) { const markOop mark = object->mark(); @@ -1408,7 +1419,6 @@ assert(inf->header()->is_neutral(), "invariant"); assert(inf->object() == object, "invariant"); assert(ObjectSynchronizer::verify_objmon_isinpool(inf), "monitor is invalid"); - event.cancel(); // let's not post an inflation event, unless we did the deed ourselves return inf; } @@ -1521,9 +1531,7 @@ object->klass()->external_name()); } } - if (event.should_commit()) { - post_monitor_inflate_event(event, object, cause); - } + TRACE_ONLY(post_monitor_inflate_event(&event, object, cause);) return m; } @@ -1572,9 +1580,7 @@ object->klass()->external_name()); } } - if (event.should_commit()) { - post_monitor_inflate_event(event, object, cause); - } + TRACE_ONLY(post_monitor_inflate_event(&event, object, cause);) return m; } } @@ -1862,18 +1868,6 @@ return "Unknown"; } -static void post_monitor_inflate_event(EventJavaMonitorInflate& event, - const oop obj, - const ObjectSynchronizer::InflateCause cause) { -#if INCLUDE_TRACE - assert(event.should_commit(), "check outside"); - event.set_monitorClass(obj->klass()); - event.set_address((TYPE_ADDRESS)(uintptr_t)(void*)obj); - event.set_cause((u1)cause); - event.commit(); -#endif -} - //------------------------------------------------------------------------------ // Debugging code diff --git a/src/share/vm/runtime/thread.cpp b/src/share/vm/runtime/thread.cpp --- a/src/share/vm/runtime/thread.cpp +++ b/src/share/vm/runtime/thread.cpp @@ -93,8 +93,6 @@ #include "services/management.hpp" #include "services/memTracker.hpp" #include "services/threadService.hpp" -#include "trace/traceMacros.hpp" -#include "trace/tracing.hpp" #include "utilities/defaultStream.hpp" #include "utilities/dtrace.hpp" #include "utilities/events.hpp" @@ -119,6 +117,10 @@ #if INCLUDE_RTM_OPT #include "runtime/rtmLocking.hpp" #endif +#if INCLUDE_TRACE +#include "trace/traceMacros.hpp" +#include "trace/tracing.hpp" +#endif // Initialization after module runtime initialization void universe_post_module_init(); // must happen after call_initPhase2 @@ -1663,6 +1665,24 @@ #endif // INCLUDE_JVMCI } +#if INCLUDE_TRACE +static void post_thread_start_event(const JavaThread* jt) { + assert(jt != NULL, "invariant"); + EventThreadStart event; + if (event.should_commit()) { + event.set_thread(THREAD_TRACE_ID(jt)); + event.commit(); + } +} + +static void post_thread_end_event(const JavaThread* jt) { + EventThreadEnd event; + if (event.should_commit()) { + event.set_thread(THREAD_TRACE_ID(jt)); + event.commit(); + } +} +#endif // INCLUDE_TRACE // The first routine called by a new Java thread void JavaThread::run() { @@ -1696,11 +1716,7 @@ JvmtiExport::post_thread_start(this); } - EventThreadStart event; - if (event.should_commit()) { - event.set_thread(THREAD_TRACE_ID(this)); - event.commit(); - } + TRACE_ONLY(post_thread_start_event(this)); // We call another function to do the rest so we are sure that the stack addresses used // from there will be lower than the stack base just computed @@ -1801,11 +1817,7 @@ // Called before the java thread exit since we want to read info // from java_lang_Thread object - EventThreadEnd event; - if (event.should_commit()) { - event.set_thread(THREAD_TRACE_ID(this)); - event.commit(); - } + TRACE_ONLY(post_thread_end_event(this);) // Call after last event on thread EVENT_THREAD_EXIT(this); diff --git a/src/share/vm/runtime/vmThread.cpp b/src/share/vm/runtime/vmThread.cpp --- a/src/share/vm/runtime/vmThread.cpp +++ b/src/share/vm/runtime/vmThread.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -37,10 +37,12 @@ #include "runtime/vmThread.hpp" #include "runtime/vm_operations.hpp" #include "services/runtimeService.hpp" -#include "trace/tracing.hpp" #include "utilities/dtrace.hpp" #include "utilities/events.hpp" #include "utilities/xmlstream.hpp" +#if INCLUDE_TRACE +#include "trace/tracing.hpp" +#endif // Dummy VM operation to act as first element in our circular double-linked list class VM_Dummy: public VM_Operation { @@ -336,6 +338,27 @@ } } +#if INCLUDE_TRACE +static void post_vm_operation_event(EventExecuteVMOperation* event, + VM_Operation* op) { + assert(event != NULL, "invariant"); + assert(op != NULL, "invariant"); + if (event->should_commit()) { + const bool is_concurrent = op->evaluate_concurrently(); + const bool evaluate_at_safepoint = op->evaluate_at_safepoint(); + event->set_operation(op->type()); + event->set_safepoint(evaluate_at_safepoint); + event->set_blocking(!is_concurrent); + // Only write caller thread information for non-concurrent vm operations. + // For concurrent vm operations, the thread id is set to 0 indicating thread is unknown. + // This is because the caller thread could have exited already. + event->set_caller(is_concurrent ? 0 : THREAD_TRACE_ID(op->calling_thread())); + event->set_safepointId(evaluate_at_safepoint ? SafepointSynchronize::safepoint_counter() : 0); + event->commit(); + } +} +#endif // INCLUDE_TRACE + void VMThread::evaluate_operation(VM_Operation* op) { ResourceMark rm; @@ -344,24 +367,11 @@ HOTSPOT_VMOPS_BEGIN( (char *) op->name(), strlen(op->name()), op->evaluation_mode()); - - EventExecuteVMOperation event; + TRACE_ONLY(EventExecuteVMOperation event;) op->evaluate(); - if (event.should_commit()) { - const bool is_concurrent = op->evaluate_concurrently(); - const bool evaluate_at_safepoint = op->evaluate_at_safepoint(); - event.set_operation(op->type()); - event.set_safepoint(evaluate_at_safepoint); - event.set_blocking(!is_concurrent); - // Only write caller thread information for non-concurrent vm operations. - // For concurrent vm operations, the thread id is set to 0 indicating thread is unknown. - // This is because the caller thread could have exited already. - event.set_caller(is_concurrent ? 0 : THREAD_TRACE_ID(op->calling_thread())); - event.set_safepointId(evaluate_at_safepoint ? SafepointSynchronize::safepoint_counter() : 0); - event.commit(); - } + TRACE_ONLY(post_vm_operation_event(&event, op);) HOTSPOT_VMOPS_END( (char *) op->name(), strlen(op->name()), diff --git a/src/share/vm/runtime/vm_operations.cpp b/src/share/vm/runtime/vm_operations.cpp --- a/src/share/vm/runtime/vm_operations.cpp +++ b/src/share/vm/runtime/vm_operations.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -39,7 +39,6 @@ #include "runtime/thread.inline.hpp" #include "runtime/vm_operations.hpp" #include "services/threadService.hpp" -#include "trace/tracing.hpp" #define VM_OP_NAME_INITIALIZE(name) #name, diff --git a/src/share/vm/trace/traceDataTypes.hpp b/src/share/vm/trace/traceDataTypes.hpp --- a/src/share/vm/trace/traceDataTypes.hpp +++ b/src/share/vm/trace/traceDataTypes.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,8 +25,6 @@ #ifndef SHARE_VM_TRACE_TRACEDATATYPES_HPP #define SHARE_VM_TRACE_TRACEDATATYPES_HPP -#include - #include "utilities/globalDefinitions.hpp" enum { @@ -54,8 +52,6 @@ NUM_RESERVED_EVENTS = JVM_CONTENT_TYPES_END }; -typedef enum ReservedEvent ReservedEvent; - typedef u8 traceid; class ModuleEntry; diff --git a/src/share/vm/trace/traceEvent.hpp b/src/share/vm/trace/traceEvent.hpp --- a/src/share/vm/trace/traceEvent.hpp +++ b/src/share/vm/trace/traceEvent.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -34,21 +34,15 @@ #if INCLUDE_TRACE #include "trace/traceBackend.hpp" -#include "trace/tracing.hpp" +#include "trace/traceTime.hpp" #include "tracefiles/traceEventIds.hpp" -#include "tracefiles/traceTypes.hpp" #include "utilities/ticks.hpp" template -class TraceEvent : public StackObj { +class TraceEvent { private: bool _started; -#ifdef ASSERT - bool _committed; - bool _cancelled; - protected: - bool _ignore_check; -#endif + DEBUG_ONLY(bool _committed;) protected: jlong _startTime; @@ -67,10 +61,7 @@ _endTime(0), _started(false) #ifdef ASSERT - , - _committed(false), - _cancelled(false), - _ignore_check(false) + , _committed(false) #endif { if (T::is_enabled()) { @@ -100,10 +91,9 @@ void commit() { if (!should_commit()) { - DEBUG_ONLY(cancel()); return; } - assert(!_cancelled, "Committing an event that has already been cancelled"); + assert(!is_committed(), "invariant"); if (_startTime == 0) { static_cast(this)->set_starttime(Tracing::time()); } else if (_endTime == 0) { @@ -111,8 +101,8 @@ } if (static_cast(this)->should_write()) { static_cast(this)->writeEvent(); + DEBUG_ONLY(set_committed()); } - DEBUG_ONLY(set_commited()); } static TraceEventId id() { @@ -135,32 +125,15 @@ return T::hasStackTrace; } - void cancel() { - assert(!_committed && !_cancelled, - "event was already committed/cancelled"); - DEBUG_ONLY(_cancelled = true); - } +#ifdef ASSERT + private: + bool is_committed() const { return _committed; } - ~TraceEvent() { - if (_started) { - assert(_ignore_check || _committed || _cancelled, - "event was not committed/cancelled"); - } - } - -#ifdef ASSERT - protected: - void ignoreCheck() { - _ignore_check = true; - } - - private: - void set_commited() { - assert(!_committed, "event has already been committed"); + void set_committed() { + assert(!_committed, "event already committed"); _committed = true; } #endif // ASSERT }; - #endif // INCLUDE_TRACE #endif // SHARE_VM_TRACE_TRACEEVENT_HPP diff --git a/src/share/vm/trace/traceEventClasses.xsl b/src/share/vm/trace/traceEventClasses.xsl --- a/src/share/vm/trace/traceEventClasses.xsl +++ b/src/share/vm/trace/traceEventClasses.xsl @@ -1,6 +1,6 @@