Skip to content

Commit 94bf8cb

Browse files
authored
(fix): gate FrameType::isRawPointer on HotSpot (#658)
1 parent 4e0e178 commit 94bf8cb

2 files changed

Lines changed: 32 additions & 4 deletions

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,11 @@ class FrameType {
7979
return (FrameTypeId)((bci >> TYPE_SHIFT) & FRAME_TYPE_MASK);
8080
}
8181

82+
// Raw pointers only exist on HotSpot (see hotspotSupport.cpp fillFrameRaw).
83+
// On other VMs an unencoded, VM-supplied bci can coincidentally have bit 30
84+
// set; that must not be mistaken for our raw-pointer encoding.
8285
static inline bool isRawPointer(int bci) {
83-
return bci > 0 && (bci & RAW_POINTER_MASK) != 0;
86+
return VM::isHotspot() && bci > 0 && (bci & RAW_POINTER_MASK) != 0;
8487
}
8588
};
8689

ddprof-lib/src/test/cpp/frame_ut.cpp

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
#include "../../main/cpp/frame.h"
88
#include "../../main/cpp/gtest_crash_handler.h"
99

10+
// VMTestAccessor — friend of VM, lets tests toggle VM::isHotspot() since
11+
// isRawPointer() now gates on it (raw pointers only exist on HotSpot).
12+
class VMTestAccessor {
13+
public:
14+
static bool getHotspot() { return VM::_hotspot; }
15+
static void setHotspot(bool v) { VM::_hotspot = v; }
16+
};
17+
1018
static constexpr char FRAME_TEST_NAME[] = "FrameTest";
1119

1220
class GlobalSetup {
@@ -139,12 +147,29 @@ TEST(FrameTypeIsRawPointerTest, FalseForEncodedWithoutFlag) {
139147
}
140148
}
141149

142-
TEST(FrameTypeIsRawPointerTest, TrueWhenBit30IsSet) {
143-
// Manually set the raw-pointer flag (bit 30) on an encoded value
150+
TEST(FrameTypeIsRawPointerTest, TrueWhenBit30IsSetOnHotspot) {
151+
// Manually set the raw-pointer flag (bit 30) on an encoded value.
152+
// Raw pointers only exist on HotSpot, so isRawPointer() must be gated on it.
153+
bool saved = VMTestAccessor::getHotspot();
154+
VMTestAccessor::setHotspot(true);
144155
int base = FrameType::encode(FRAME_JIT_COMPILED, 0);
145156
int withFlag = base | (1 << 30);
146157
EXPECT_TRUE(FrameType::isRawPointer(withFlag))
147-
<< "isRawPointer() must be true when bit 30 is set and value is positive";
158+
<< "isRawPointer() must be true when bit 30 is set, value is positive, and VM is HotSpot";
159+
VMTestAccessor::setHotspot(saved);
160+
}
161+
162+
TEST(FrameTypeIsRawPointerTest, FalseWhenBit30IsSetOnNonHotspot) {
163+
// Non-HotSpot VMs can coincidentally produce an unencoded bci with bit 30
164+
// set (e.g. OpenJ9's raw AsyncGetCallTrace output); that must not be
165+
// mistaken for HotSpot's raw-pointer encoding.
166+
bool saved = VMTestAccessor::getHotspot();
167+
VMTestAccessor::setHotspot(false);
168+
int base = FrameType::encode(FRAME_JIT_COMPILED, 0);
169+
int withFlag = base | (1 << 30);
170+
EXPECT_FALSE(FrameType::isRawPointer(withFlag))
171+
<< "isRawPointer() must be false when VM is not HotSpot, even with bit 30 set";
172+
VMTestAccessor::setHotspot(saved);
148173
}
149174

150175
TEST(FrameTypeIsRawPointerTest, FalseWithOnlyBit30SetOnNegative) {

0 commit comments

Comments
 (0)