Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
enhance and cleanup
  • Loading branch information
zhengyu123 committed Jul 9, 2025
commit 57e602282509eb253ca7a70d25a133f57d9cccc2
6 changes: 6 additions & 0 deletions ddprof-lib/src/main/cpp/safeAccess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@
SafeAccess::SafeFetch32 SafeAccess::_safeFetch32Func = nullptr;

void SafeAccess::initSafeFetch(CodeCache* libjvm) {
// Hotspot JVM's safefetch implementation appears better, e.g. it actually returns errorValue,
// when the address is invalid. let's use it whenever possible.
Comment thread
zhengyu123 marked this conversation as resolved.
_safeFetch32Func = (SafeFetch32)libjvm->findSymbol("SafeFetch32_impl");
if (_safeFetch32Func == nullptr && !WX_MEMORY) {
// jdk11 stub implementation other than Macosx/aarch64
void** entry = (void**)libjvm->findSymbol("_ZN12StubRoutines18_safefetch32_entryE");
_safeFetch32Func = (SafeFetch32)*entry;
}
// Fallback
if (_safeFetch32Func == nullptr) {
_safeFetch32Func = (SafeFetch32)load32;
}
}
13 changes: 6 additions & 7 deletions ddprof-lib/src/main/cpp/safeAccess.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "arch_dd.h"
#include "codeCache.h"
#include <cassert>
#include <stdint.h>

#ifdef __clang__
Expand All @@ -30,21 +31,19 @@

class SafeAccess {
private:
typedef int (*SafeFetch32)(int* ptr, int defaultValue);
typedef int (*SafeFetch32)(int* ptr, int errorValue);
static SafeFetch32 _safeFetch32Func;

public:
static void initSafeFetch(CodeCache* libjvm);

static bool hasSafeFetch() {
return _safeFetch32Func != nullptr;
}

static int safeFetch(int* ptr, int defaultValue) {
if (_safeFetch32Func != nullptr) {
return _safeFetch32Func(ptr, defaultValue);
} else {
return defaultValue;
}
static inline int safeFetch(int* ptr, int errorValue) {
Comment thread
zhengyu123 marked this conversation as resolved.
Outdated
assert(_safeFetch32Func != nullptr);
return _safeFetch32Func(ptr, errorValue);
}

NOINLINE NOADDRSANITIZE __attribute__((aligned(16))) static void *load(void **ptr) {
Expand Down