Skip to content

Commit 9b861da

Browse files
committed
Fix frame_ut for isRawPointer() hotspot gating
TrueWhenBit30IsSet assumed isRawPointer() ignores VM kind; split into hotspot/non-hotspot cases now that it's gated on VM::isHotspot().
1 parent 95a3498 commit 9b861da

1 file changed

Lines changed: 28 additions & 3 deletions

File tree

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)