Skip to content

Commit 39149af

Browse files
committed
Review comments
1 parent 4d6724c commit 39149af

6 files changed

Lines changed: 33 additions & 32 deletions

File tree

ddprof-lib/src/main/cpp/flightRecorder.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,11 +493,12 @@ MethodInfo *Lookup::resolveMethod(ASGCT_CallFrame &frame) {
493493
method_id = JVMSupport::resolve(frame.method);
494494
}
495495

496+
/**
496497
// Maps JMETHODID_NOT_WAKEABLE back to nullptr
497498
if (method_id == JMETHODID_NOT_WALKABLE) {
498499
method_id = nullptr;
499500
}
500-
501+
*/
501502
// BCI_VTABLE_RECEIVER: method holds a VMSymbol* (see vmEntry.h). Resolve
502503
// to a class_id via the per-dump cache once, then key MethodMap by the
503504
// resolved class_id so two distinct Symbol addresses for the same class

ddprof-lib/src/main/cpp/flightRecorder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ class MethodInfo {
9090
std::shared_ptr<SharedLineNumberTable> _line_number_table;
9191
FrameTypeId _type;
9292

93-
jint getLineNumber(jint bci);
94-
bool isHidden();
93+
inline jint getLineNumber(jint bci);
94+
inline bool isHidden();
9595
};
9696

9797
// MethodMap's key can be derived from 3 sources:

ddprof-lib/src/main/cpp/hotspot/hotspotSupport.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,15 @@ static void fillFrameTypes(ASGCT_CallFrame *frames, int num_frames, VMNMethod *n
171171
}
172172

173173
// Fill the frame with raw method pointer
174-
static inline void fillFrameRaw(ASGCT_CallFrame& frame, FrameTypeId type, int bci, const VMMethod* method) {
174+
static void fillFrameRaw(ASGCT_CallFrame& frame, FrameTypeId type, int bci, const VMMethod* method) {
175175
assert(method != nullptr);
176176
frame.bci = FrameType::encode(type, bci, true /*raw method pointer*/);
177177
frame.method = static_cast<const void*>(method);
178178
}
179179

180-
static inline void fillFrame(ASGCT_CallFrame& frame, FrameTypeId type, int bci, jmethodID method_id, const VMMethod* method) {
181-
if (method_id != nullptr) {
180+
static void fillFrame(ASGCT_CallFrame& frame, FrameTypeId type, int bci, jmethodID method_id, const VMMethod* method) {
181+
// Pack JMETHODID_NOT_WALKABLE frame as raw pointer frame, so it can not resolved into nullptr to shared code.
182+
if (method_id != nullptr && method_id != JMETHODID_NOT_WALKABLE) {
182183
fillFrame(frame, type, bci, method_id);
183184
} else {
184185
assert(method != nullptr);
@@ -1250,7 +1251,7 @@ static bool isLambdaClass(const char* signature) {
12501251
strncmp(signature, FFM_PREFIX, strlen(FFM_PREFIX)) == 0;
12511252
}
12521253

1253-
static inline bool isSystemClassLoaders(JNIEnv* jni, jobject cl) {
1254+
static bool isSystemClassLoader(JNIEnv* jni, jobject cl) {
12541255
return cl == nullptr || // bootstrap class loader
12551256
jni->IsSameObject(cl, JAVA_PLATFORM_CLASSLOADER) || // platform class loader
12561257
jni->IsSameObject(cl, JAVA_APPLICATION_CLASSLOADER); // application class loader (system class loader)
@@ -1271,7 +1272,7 @@ bool HotspotSupport::loadMethodIDsImpl(jvmtiEnv *jvmti, JNIEnv *jni, jclass klas
12711272
// we use Method instead.
12721273
if (!isHiddenClass(jvmti, klass) &&
12731274
jvmti->GetClassLoader(klass, &cl) == JVMTI_ERROR_NONE &&
1274-
isSystemClassLoaders(jni, cl)) {
1275+
isSystemClassLoader(jni, cl)) {
12751276
char* signature_ptr = nullptr;
12761277
if (jvmti->GetClassSignature(klass, &signature_ptr, nullptr) == JVMTI_ERROR_NONE) {
12771278
// Lambda classes, even loaded by bootstrap class loader, can be unloaded,
@@ -1299,6 +1300,13 @@ bool HotspotSupport::loadMethodIDsImpl(jvmtiEnv *jvmti, JNIEnv *jni, jclass klas
12991300
jmethodID HotspotSupport::resolve(const void* method) {
13001301
assert(VM::isHotspot());
13011302
assert(method != nullptr);
1303+
// We packed not walkable method as raw pointer,
1304+
// map it back to nullptr, as JMETHODID_NOT_WALKABLE is only
1305+
// known in hotspot.
1306+
if ((jmethodID)method == JMETHODID_NOT_WALKABLE) {
1307+
return nullptr;
1308+
}
1309+
13021310
VMMethod* vm_method = VMMethod::cast_or_null(method);
13031311
if (vm_method == nullptr) {
13041312
return nullptr;

ddprof-lib/src/main/cpp/hotspot/vmStructs.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
#include "threadState.h"
2121
#include "vmEntry.h"
2222

23+
#define JMETHODID_NOT_WALKABLE (jmethodID)((uintptr_t)-1)
24+
inline bool isValidJMethodID(jmethodID method_id) {
25+
return method_id != JMETHODID_NOT_WALKABLE && method_id != nullptr;
26+
}
27+
2328
class GCHeapSummary;
2429
class HeapUsage;
2530
class VMNMethod;
@@ -48,7 +53,7 @@ inline T* cast_to(const void* ptr) {
4853
}
4954

5055
template <typename T>
51-
inline T* cast_or_null(const void* ptr) {
56+
T* cast_or_null(const void* ptr) {
5257
assert(VM::isHotspot()); // This should only be used in HotSpot-specific code
5358
assert(T::type_size() > 0); // Ensure type size has been initialized
5459
if(ptr == nullptr || SafeAccess::isReadableRange(ptr, T::type_size())) {
@@ -615,7 +620,6 @@ class VMNMethod;
615620
class VMMethod;
616621

617622
DECLARE(VMSymbol)
618-
public:
619623
unsigned short length() {
620624
assert(_symbol_length_offset >= 0);
621625
return *(unsigned short*) at(_symbol_length_offset);
@@ -654,7 +658,6 @@ DECLARE(VMClassLoaderData)
654658
DECLARE_END
655659

656660
DECLARE(VMKlass)
657-
public:
658661
static VMKlass* fromJavaClass(JNIEnv* env, jclass cls) {
659662
if (sizeof(VMKlass*) == 8) {
660663
return VMKlass::cast((const void*)(intptr_t)env->GetLongField(cls, _klass));
@@ -754,7 +757,6 @@ DECLARE(VMJavaFrameAnchor)
754757
DECLARE_END
755758

756759
DECLARE(VMContinuationEntry)
757-
public:
758760
// Address of the enterSpecial frame's {saved_fp, return_addr} pair.
759761
// Layout above this address: [saved_fp][return_addr_to_carrier][carrier_sp...]
760762
// The ContinuationEntry struct is embedded on the carrier stack immediately
@@ -795,7 +797,6 @@ enum JVMJavaThreadState {
795797

796798
DECLARE(VMThread)
797799
friend class JVMThread;
798-
public:
799800
static void* initialize(jthread thread);
800801

801802
static inline VMThread* current();
@@ -889,15 +890,13 @@ DECLARE(VMThread)
889890
DECLARE_END
890891

891892
DECLARE(VMConstantPool)
892-
public:
893893
inline VMKlass* holder_or_null() const;
894894
inline VMSymbol* symbolAt(int index) const;
895895
private:
896896
inline intptr_t* base() const;
897897
DECLARE_END
898898

899899
DECLARE(VMConstMethod)
900-
public:
901900
inline VMConstantPool* constants_or_null() const;
902901
inline VMSymbol* name() const;
903902
inline VMSymbol* signature() const;
@@ -948,7 +947,6 @@ static inline bool startsWith(const char* s, const char (&pattern)[N]) {
948947
}
949948

950949
DECLARE(VMNMethod)
951-
public:
952950
int size() {
953951
assert(_blob_size_offset >= 0);
954952
return *(int*) at(_blob_size_offset);

ddprof-lib/src/main/cpp/hotspot/vmStructs.inline.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,17 @@ jmethodID VMMethod::id() {
110110

111111
jmethodID VMMethod::validatedId() {
112112
jmethodID method_id = id();
113-
if (isValidJMethodID(method_id)) {
114-
if (!_can_dereference_jmethod_id ||
115-
((goodPtr(method_id) && SafeAccess::loadPtr((void**)method_id, nullptr) == this))) {
116-
return method_id;
117-
} else {
118-
return JMETHODID_NOT_WALKABLE;
119-
}
113+
// We are sure about the value, return it
114+
if (method_id == JMETHODID_NOT_WALKABLE || method_id == nullptr) {
115+
return method_id;
116+
}
117+
// Check if the value make sense
118+
if (!_can_dereference_jmethod_id ||
119+
((goodPtr(method_id) && SafeAccess::loadPtr((void**)method_id, nullptr) == this))) {
120+
return method_id;
120121
}
121-
return method_id;
122+
123+
return JMETHODID_NOT_WALKABLE;
122124
}
123125

124126
VMKlass* VMConstantPool::holder_or_null() const {

ddprof-lib/src/main/cpp/vmEntry.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,6 @@
2020
#define DLLEXPORT __attribute__((visibility("default"), externally_visible))
2121
#endif
2222

23-
#ifndef JMETHODID_NOT_WALKABLE
24-
#define JMETHODID_NOT_WALKABLE (jmethodID)((uintptr_t)-1)
25-
#endif // JMETHODID_NOT_WALKABLE
26-
27-
inline bool isValidJMethodID(jmethodID method_id) {
28-
return method_id != JMETHODID_NOT_WALKABLE && method_id != nullptr;
29-
}
30-
3123
// Denotes ASGCT_CallFrame where method_id has special meaning (not jmethodID)
3224
enum ASGCT_CallFrameType {
3325
BCI_CPU = 0, // cpu time

0 commit comments

Comments
 (0)