Skip to content

Commit

Permalink
Unbreak support/gdb.py for hash tables
Browse files Browse the repository at this point in the history
Summary: These tests didn't fire on D40367479 (a20494d) for some reason.

Reviewed By: yfeldblum

Differential Revision: D42481274

fbshipit-source-id: b12266e88019822cf5da4c5fa3bbc5bb2f156a5e
  • Loading branch information
swolchok authored and facebook-github-bot committed Jan 13, 2023
1 parent 437b651 commit 1a7cc67
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
24 changes: 5 additions & 19 deletions folly/container/detail/F14Table.h
Original file line number Diff line number Diff line change
Expand Up @@ -846,14 +846,7 @@ struct PackedSizeAndChunkShift {
const auto shift = findFirstSet(newCount) - 1; // firstSet is 1-based.
packedSizeAndChunkShift_ =
(static_cast<uint64_t>(size()) << kSizeShift) | shift;
FOLLY_SAFE_DCHECK(
chunkCount() == newCount,
"shift: ",
shift,
" chunkCount: ",
chunkCount(),
" new count: ",
newCount);
FOLLY_SAFE_DCHECK(chunkCount() == newCount, "");
}

void swap(PackedSizeAndChunkShift& rhs) noexcept {
Expand Down Expand Up @@ -892,14 +885,7 @@ struct UnpackedSizeAndChunkShift {
const auto shift = findFirstSet(newCount) - 1; // firstSet is 1-based.
FOLLY_SAFE_DCHECK(shift <= std::numeric_limits<uint8_t>::max(), "");
chunkShift_ = static_cast<uint8_t>(shift);
FOLLY_SAFE_DCHECK(
chunkCount() == newCount,
"shift: ",
shift,
" chunkCount: ",
chunkCount(),
" new count: ",
newCount);
FOLLY_SAFE_DCHECK(chunkCount() == newCount, "");
}

void swap(UnpackedSizeAndChunkShift& rhs) noexcept {
Expand Down Expand Up @@ -1349,7 +1335,7 @@ class F14Table : public Policy {

static std::size_t chunkAllocSize(
std::size_t chunkCount, std::size_t capacityScale) {
FOLLY_SAFE_DCHECK(chunkCount > 0, chunkCount);
FOLLY_SAFE_DCHECK(chunkCount > 0, "");
FOLLY_SAFE_DCHECK(!(chunkCount > 1 && capacityScale == 0), "");
if (chunkCount == 1) {
static_assert(offsetof(Chunk, rawItems_) == 16, "");
Expand Down Expand Up @@ -1962,8 +1948,8 @@ class F14Table : public Policy {
}

void initialReserve(std::size_t desiredCapacity) {
FOLLY_SAFE_DCHECK(size() == 0, size());
FOLLY_SAFE_DCHECK(chunkShift() == 0, chunkShift());
FOLLY_SAFE_DCHECK(size() == 0, "");
FOLLY_SAFE_DCHECK(chunkShift() == 0, "");
FOLLY_SAFE_DCHECK(chunks_ == Chunk::emptyInstance(), "");
if (desiredCapacity == 0) {
return;
Expand Down
18 changes: 14 additions & 4 deletions folly/support/gdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,12 @@ def __init__(self, ht, is_node_container):
item_type = gdb.lookup_type("{}::{}".format(ht.type.name, "Item"))
self.item_ptr_type = item_type.pointer()
self.chunk_ptr = ht["chunks_"]
# chunk_count is always power of 2;
# For partial chunks, chunkMask_ = 0, so + 1 also works
chunk_count = ht["chunkMask_"] + 1
pair = ht["sizeAndChunkShiftAndPackedBegin_"]["sizeAndChunkShift_"]
size_of_size_t = gdb.lookup_type("size_t").sizeof
if size_of_size_t == 4:
chunk_count = 1 << pair["chunkShift_"]
else:
chunk_count = 1 << (pair["packedSizeAndChunkShift_"] & ((1 << 8) - 1))
self.chunk_end = self.chunk_ptr + chunk_count
self.current_chunk = self.chunk_iter(self.chunk_ptr)
self.is_node_container = is_node_container
Expand Down Expand Up @@ -286,7 +289,14 @@ def hashtable(self):
return self.val["table_"]

def size(self):
return self.hashtable()["sizeAndPackedBegin_"]["size_"]
pair = self.hashtable()["sizeAndChunkShiftAndPackedBegin_"][
"sizeAndChunkShift_"
]
size_of_size_t = gdb.lookup_type("size_t").sizeof
if size_of_size_t == 4:
return pair["size_"]
else:
return pair["packedSizeAndChunkShift_"] >> 8

def to_string(self):
return "%s with %d elements" % (
Expand Down

0 comments on commit 1a7cc67

Please sign in to comment.