Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions ddprof-lib/src/main/cpp/profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
// The instance is not deleted on purpose, since profiler structures
// can be still accessed concurrently during VM termination
Profiler *const Profiler::_instance = new Profiler();
volatile bool Profiler::_signals_initialized = false;

static void (*orig_trapHandler)(int signo, siginfo_t *siginfo, void *ucontext);
static void (*orig_segvHandler)(int signo, siginfo_t *siginfo, void *ucontext);
Expand Down Expand Up @@ -975,11 +976,13 @@ bool Profiler::crashHandler(int signo, siginfo_t *siginfo, void *ucontext) {

void Profiler::setupSignalHandlers() {
// do not re-run the signal setup (run only when VM has not been loaded yet)
if (VM::java_version() > 0 && !VM::loaded()) {
// HotSpot and J9 tolerate interposed SIGSEGV/SIGBUS handler; other JVMs
// probably not
orig_segvHandler = OS::replaceSigsegvHandler(segvHandler);
orig_busHandler = OS::replaceSigbusHandler(busHandler);
if (__sync_bool_compare_and_swap(&_signals_initialized, false, true)) {
if (VM::isHotspot() || VM::isOpenJ9()) {
// HotSpot and J9 tolerate interposed SIGSEGV/SIGBUS handler; other JVMs
// probably not
orig_segvHandler = OS::replaceSigsegvHandler(segvHandler);
orig_busHandler = OS::replaceSigbusHandler(busHandler);
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions ddprof-lib/src/main/cpp/profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ class Profiler {
friend VM;

private:
// signal handlers
static volatile bool _signals_initialized;

Mutex _state_lock;
State _state;
// class unload hook
Expand Down
12 changes: 12 additions & 0 deletions ddprof-lib/src/main/cpp/vmEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ bool VM::init(JavaVM *vm, bool attach) {
prop = NULL;
}
if (_jvmti->GetSystemProperty("java.vm.version", &prop) == 0) {
if (_java_version == 0) {
// java.runtime.version was not found; try using java.vm.version to extract the information
JavaFullVersion version = JavaVersionAccess::get_java_version(prop);
_java_version = version.major;
_java_update_version = version.update;
}
_hotspot_version = JavaVersionAccess::get_hotspot_version(prop);
_jvmti->Deallocate((unsigned char *)prop);
prop = NULL;
Expand All @@ -236,6 +242,12 @@ bool VM::init(JavaVM *vm, bool attach) {
_jvmti->Deallocate((unsigned char *)prop);
}

if (_java_version == 0 && _hotspot_version > 0) {
// sanity fallback:
// - if we failed to resolve the _java_version but have _hotspot_version, let's use the hotspot version as java version
_java_version = _hotspot_version;
}

_can_sample_objects = !_hotspot || hotspot_version() >= 11;

CodeCache *lib =
Expand Down
Loading