Commit 46a1fa1a authored by Omer Katz's avatar Omer Katz Committed by Commit Bot

cppgc: Fix GetHeapFromPayload

GetHeapFromPayload returned the page header address instead of the
value of the first field of the header.

Bug: chromium:1056170
Change-Id: I4de5be975accced32460d6fab91543e6a5b07ba0
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2143825
Auto-Submit: Omer Katz <omerkatz@chromium.org>
Reviewed-by: 's avatarAnton Bikineev <bikineev@chromium.org>
Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67079}
parent 8e755eaa
......@@ -5,14 +5,16 @@
#ifndef INCLUDE_CPPGC_INTERNAL_ACCESSORS_H_
#define INCLUDE_CPPGC_INTERNAL_ACCESSORS_H_
#include "include/cppgc/heap.h"
#include "include/cppgc/internal/api-constants.h"
namespace cppgc {
class Heap;
namespace internal {
inline cppgc::Heap* GetHeapFromPayload(const void* payload) {
return reinterpret_cast<cppgc::Heap*>(
return *reinterpret_cast<cppgc::Heap**>(
(reinterpret_cast<uintptr_t>(payload) & api_constants::kPageBaseMask) +
api_constants::kHeapOffset);
}
......
......@@ -3,6 +3,8 @@
// found in the LICENSE file.
#include "src/heap/cppgc/heap-page.h"
#include "include/cppgc/allocation.h"
#include "include/cppgc/internal/accessors.h"
#include "test/unittests/heap/cppgc/tests.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -13,6 +15,8 @@ namespace {
class PageTest : public testing::TestWithHeap {};
class GCed : public GarbageCollected<GCed> {};
} // namespace
TEST_F(PageTest, PageLayout) {
......@@ -20,5 +24,10 @@ TEST_F(PageTest, PageLayout) {
NormalPage::Destroy(np);
}
TEST_F(PageTest, GetHeapForAllocatedObject) {
GCed* gced = MakeGarbageCollected<GCed>(GetHeap());
EXPECT_EQ(GetHeap(), GetHeapFromPayload(gced));
}
} // namespace internal
} // namespace cppgc
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment