|
7 | 7 | #include "../../main/cpp/frame.h" |
8 | 8 | #include "../../main/cpp/gtest_crash_handler.h" |
9 | 9 |
|
| 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 | + |
10 | 18 | static constexpr char FRAME_TEST_NAME[] = "FrameTest"; |
11 | 19 |
|
12 | 20 | class GlobalSetup { |
@@ -139,12 +147,29 @@ TEST(FrameTypeIsRawPointerTest, FalseForEncodedWithoutFlag) { |
139 | 147 | } |
140 | 148 | } |
141 | 149 |
|
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); |
144 | 155 | int base = FrameType::encode(FRAME_JIT_COMPILED, 0); |
145 | 156 | int withFlag = base | (1 << 30); |
146 | 157 | 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); |
148 | 173 | } |
149 | 174 |
|
150 | 175 | TEST(FrameTypeIsRawPointerTest, FalseWithOnlyBit30SetOnNegative) { |
|
0 commit comments