Skip to content

Commit 75aa5f1

Browse files
committed
[K/N] Fix ExtraObjectCell::size on 32-bit targets ^KT-78925
Allocate multiples of `sizeof(Cell)` bytes, even if `sizeof(ExtraObjectCell)` is less than this.
1 parent 1a3b7b2 commit 75aa5f1

File tree

6 files changed

+11
-7
lines changed

6 files changed

+11
-7
lines changed

kotlin-native/runtime/src/alloc/custom/cpp/CustomAllocatorTestSupport.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ kotlin::alloc::test_support::WithSchedulerNotificationHook::~WithSchedulerNotifi
2626
}
2727

2828
kotlin::alloc::ExtraObjectCell* kotlin::alloc::test_support::initExtraObjectCell(uint8_t* ptr) {
29-
EXPECT_TRUE(ptr[0] == 0 && memcmp(ptr, ptr + 1, kExtraObjCellSize.inBytes() - 1) == 0);
29+
EXPECT_TRUE(ptr[0] == 0 && memcmp(ptr, ptr + 1, ExtraObjectCell::size().inBytes() - 1) == 0);
3030
auto* extraObjCell = new(ptr) ExtraObjectCell();
3131
new(extraObjCell->data_) kotlin::mm::ExtraObjectData(nullptr, nullptr);
3232
return extraObjCell;

kotlin-native/runtime/src/alloc/custom/cpp/CustomAllocatorTestSupport.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ class WithSchedulerNotificationHook {
8383
testing::StrictMock<testing::MockFunction<void(std::size_t)>> schedulerNotificationHook_;
8484
};
8585

86-
constexpr auto kExtraObjCellSize = AllocationSize::bytesExactly(sizeof(kotlin::alloc::ExtraObjectCell));
87-
8886
ExtraObjectCell* initExtraObjectCell(uint8_t* ptr);
8987
ExtraObjectCell* allocExtraObjectCell(kotlin::alloc::FixedBlockPage* page);
9088
ExtraObjectCell* allocExtraObjectCell(kotlin::alloc::SingleObjectPage* page);

kotlin-native/runtime/src/alloc/custom/cpp/ExtraObjectCell.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace kotlin::alloc {
1111

1212
struct ExtraObjectCell {
1313
static constexpr AllocationSize size() {
14-
return AllocationSize::bytesExactly(sizeof(ExtraObjectCell));
14+
return AllocationSize::bytesAtLeast(sizeof(ExtraObjectCell));
1515
}
1616

1717
static ExtraObjectCell* fromExtraObject(mm::ExtraObjectData* extraObjectData) {
@@ -27,4 +27,7 @@ struct ExtraObjectCell {
2727
};
2828
};
2929

30-
} // namespace kotlin::alloc
30+
// ensure const-evaluatable
31+
static_assert(ExtraObjectCell::size().inCells() > 0);
32+
33+
} // namespace kotlin::alloc

kotlin-native/runtime/src/alloc/custom/cpp/GCApi.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ bool kotlin::alloc::ExtraDataSweepTraits::trySweepElement(uint8_t* element, Fina
103103
}
104104

105105
kotlin::alloc::AllocationSize kotlin::alloc::ExtraDataSweepTraits::elementSize(uint8_t*) {
106-
return AllocationSize::bytesExactly(sizeof(ExtraObjectCell));
106+
return ExtraObjectCell::size();
107107
}
108108

109109
void* kotlin::alloc::SafeAlloc(uint64_t size) noexcept {

kotlin-native/runtime/src/alloc/custom/cpp/NextFitPage.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ class alignas(kPageAlignment) NextFitPage : public MultiObjectPage<NextFitPage>
104104
Cell cells_[]; // cells_[0] is reserved for an empty block
105105
};
106106

107+
// ensure const-evaluatable
108+
static_assert(NextFitPage::cellCount() > 0);
109+
107110
} // namespace kotlin::alloc
108111

109112
#endif

kotlin-native/runtime/src/alloc/custom/cpp/SweepTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ using ExtraObjectCell = typename kotlin::alloc::ExtraObjectCell;
2727
} // namespace
2828

2929
TEST_F(CustomAllocatorTest, ExtraDataSweepFullFinalizedPage) {
30-
auto* page = FixedBlockPage::Create(kExtraObjCellSize.inCells());
30+
auto* page = FixedBlockPage::Create(ExtraObjectCell::size().inCells());
3131
while (ExtraObjectCell* cell = allocExtraObjectCell(page)) {
3232
cell->Data()->setFlag(kotlin::mm::ExtraObjectData::FLAGS_SWEEPABLE);
3333
}

0 commit comments

Comments
 (0)