From f0edd16cd2b5ad0b5851c79b4e2684c1814e4284 Mon Sep 17 00:00:00 2001 From: dcubed Date: Thu, 28 Apr 2011 08:24:46 -0700 Subject: [PATCH] 7039447: 2/1 java profiling is broken in build 139 (garbage in function name) Summary: The name in a deferred JVM/TI DynamicCodeGenerated event needs to be explicitly saved. Reviewed-by: acorn, never, dsamersoff, dholmes --- src/share/vm/prims/jvmtiExport.cpp | 2 ++ src/share/vm/prims/jvmtiImpl.cpp | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/share/vm/prims/jvmtiExport.cpp b/src/share/vm/prims/jvmtiExport.cpp index 6f6cf6f4c..48401caaf 100644 --- a/src/share/vm/prims/jvmtiExport.cpp +++ b/src/share/vm/prims/jvmtiExport.cpp @@ -1804,6 +1804,8 @@ void JvmtiExport::post_compiled_method_load(JvmtiEnv* env, const jmethodID metho } void JvmtiExport::post_dynamic_code_generated_internal(const char *name, const void *code_begin, const void *code_end) { + assert(name != NULL && name[0] != '\0', "sanity check"); + JavaThread* thread = JavaThread::current(); // In theory everyone coming thru here is in_vm but we need to be certain // because a callee will do a vm->native transition diff --git a/src/share/vm/prims/jvmtiImpl.cpp b/src/share/vm/prims/jvmtiImpl.cpp index 5bb68f7ab..f673e92ca 100644 --- a/src/share/vm/prims/jvmtiImpl.cpp +++ b/src/share/vm/prims/jvmtiImpl.cpp @@ -38,6 +38,7 @@ #include "runtime/handles.inline.hpp" #include "runtime/interfaceSupport.hpp" #include "runtime/javaCalls.hpp" +#include "runtime/os.hpp" #include "runtime/serviceThread.hpp" #include "runtime/signature.hpp" #include "runtime/vframe.hpp" @@ -939,10 +940,15 @@ JvmtiDeferredEvent JvmtiDeferredEvent::compiled_method_unload_event( nmethodLocker::lock_nmethod(nm, true /* zombie_ok */); return event; } + JvmtiDeferredEvent JvmtiDeferredEvent::dynamic_code_generated_event( const char* name, const void* code_begin, const void* code_end) { JvmtiDeferredEvent event = JvmtiDeferredEvent(TYPE_DYNAMIC_CODE_GENERATED); - event._event_data.dynamic_code_generated.name = name; + // Need to make a copy of the name since we don't know how long + // the event poster will keep it around after we enqueue the + // deferred event and return. strdup() failure is handled in + // the post() routine below. + event._event_data.dynamic_code_generated.name = os::strdup(name); event._event_data.dynamic_code_generated.code_begin = code_begin; event._event_data.dynamic_code_generated.code_end = code_end; return event; @@ -968,12 +974,19 @@ void JvmtiDeferredEvent::post() { nmethodLocker::unlock_nmethod(nm); break; } - case TYPE_DYNAMIC_CODE_GENERATED: + case TYPE_DYNAMIC_CODE_GENERATED: { JvmtiExport::post_dynamic_code_generated_internal( - _event_data.dynamic_code_generated.name, + // if strdup failed give the event a default name + (_event_data.dynamic_code_generated.name == NULL) + ? "unknown_code" : _event_data.dynamic_code_generated.name, _event_data.dynamic_code_generated.code_begin, _event_data.dynamic_code_generated.code_end); + if (_event_data.dynamic_code_generated.name != NULL) { + // release our copy + os::free((void *)_event_data.dynamic_code_generated.name); + } break; + } default: ShouldNotReachHere(); } -- GitLab