Skip to content

Instantly share code, notes, and snippets.

@deepak1556
Created February 19, 2024 17:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deepak1556/4dd8533d90c7ba3a44a683bb879ab5b0 to your computer and use it in GitHub Desktop.
Save deepak1556/4dd8533d90c7ba3a44a683bb879ab5b0 to your computer and use it in GitHub Desktop.
Dump EPT contents for an isolate
// Copyright 2024 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/sandbox/external-pointer-table-tracer.h"
#include <iostream>
#include "src/common/globals.h"
#include "src/execution/isolate.h"
#include "src/sandbox/external-entity-table-inl.h"
#include "src/sandbox/external-pointer-table.h"
#include "src/utils/ostreams.h"
namespace v8 {
namespace internal {
// static
void EPTTracer::Print(IsolateForSandbox ifs) {
//ExternalPointerTable& ept = ifs.isolate()->external_pointer_table();
ExternalPointerTable& shared_ept = ifs.isolate()->shared_external_pointer_table();
StdoutStream os;
/*if (reinterpret_cast<ExternalPointerTableEntry*>(ept.base()) != nullptr) {
os << "External Pointer Table Layout" << std::endl;
os << "Base address: 0x" << std::hex << ept.base() << std::endl;
}*/
if (reinterpret_cast<ExternalPointerTableEntry*>(shared_ept.base()) != nullptr) {
os << "Shared External Pointer Table Layout" << std::endl;
os << "Base address: 0x" << std::hex << shared_ept.base() << std::endl;
auto* space = ifs.isolate()->shared_external_pointer_space();
DCHECK(space->BelongsTo(&shared_ept));
base::MutexGuard guard(&space->mutex_);
if (!space->is_empty()) {
os << "Number of segments in the space: " << space->num_segments() << std::endl;
for (auto segment : space->segments_) {
os << "Segment: " << segment.number() << std::endl;
uint32_t first = segment.first_entry();
uint32_t last = segment.last_entry();
os << "| Index | Marked | Encoded Address | Description |" << std::endl;
for (uint32_t i = first; i < last; i++) {
auto& entry = reinterpret_cast<ExternalPointerTableEntry*>(shared_ept.base())[i];
bool is_freelist = entry.GetRawPayload().ContainsFreelistLink();
if (is_freelist)
continue;
bool is_marked = entry.GetRawPayload().HasMarkBitSet();
os << "| " << i << " | " << is_marked << " | ";
uint64_t value = static_cast<uint64_t>(entry.GetRawPayload().encoded_word());
for (int i = 63; i >= 0; --i) {
if (value & (1ULL << i)) {
os << '1';
} else {
os << '0';
}
}
if (is_freelist) {
//uint32_t next_free_entry = entry.GetRawPayload().ExtractFreelistLink();
//os << " | Next free entry index: " << next_free_entry << " |" << std::endl;
} else {
os << " | External pointer object |" << std::endl;
}
}
}
}
}
os << std::endl << std::flush;
}
} // namespace internal
} // namespace v8
demohan@Deepaks-MacBook-Pro v8 % ./out/Release/d8 --expose-gc --expose-externalize-string ./test/mjsunit/large-external-string.js
Address of resource data to validate: 0x600002afcb91
Shared External Pointer Table Layout
Base address: 0x340000000
Number of segments in the space: 1
Segment: 1
| Index | Marked | Encoded Address | Description |
| 1000 | 1 | 0100000000010111011000000000000000000000000111111100001010000000 | External pointer object |
| 1001 | 1 | 0100000000011011011000000000000000000010101011111100101110010001 | External pointer object |
Address of resource to validate: 0x6000001fc280
Address of resource data to validate: 0x125705171
Shared External Pointer Table Layout
Base address: 0x340000000
Number of segments in the space: 1
Segment: 1
| Index | Marked | Encoded Address | Description |
| 1000 | 1 | 0100000000010111011000000000000000000000000111111100001010000000 | External pointer object |
| 1001 | 1 | 0100000000011011011000000000000000000010101011111100101110010001 | External pointer object |
| 1002 | 1 | 0100000000010111011000000000000000000000000111111100001010100000 | External pointer object |
| 1003 | 1 | 0100000000011011000000000000000100100101011100000101000101110001 | External pointer object |
Address of resource to validate: 0x6000001fc2a0
Address of resource data to validate: 0x1181c0000
Shared External Pointer Table Layout
Base address: 0x340000000
Number of segments in the space: 1
Segment: 1
| Index | Marked | Encoded Address | Description |
| 1000 | 1 | 0100000000010111011000000000000000000000000111111100001010000000 | External pointer object |
| 1001 | 1 | 0100000000011011011000000000000000000010101011111100101110010001 | External pointer object |
| 1002 | 1 | 0100000000010111011000000000000000000000000111111100001010100000 | External pointer object |
| 1003 | 1 | 0100000000011011000000000000000100100101011100000101000101110001 | External pointer object |
| 1004 | 1 | 0100000000010111011000000000000000000000000111101000100001000000 | External pointer object |
| 1005 | 1 | 0100000000011011000000000000000100011000000111000000000000000000 | External pointer object |
demohan@Deepaks-MacBook-Pro v8 %
@deepak1556
Copy link
Author

deepak1556 commented Feb 22, 2024

Table layout with separate space for double pointer-sized word entries

Shared External Pointer Table Layout
Base address: 0x340000000
Number of segments in the space: 1
Segment: 1
| Index | Marked | Encoded Address | Description |
| 2000 | 1 | 00100000000010111011000000000000000000000011011001101000101100000 | External pointer object |
| 2001 | 1 | 00100000000010111011000000000000000000000011011001101000110000000 | External pointer object |
| 2002 | 1 | 00100000000010111011000000000000000000000011011000100011001000000 | External pointer object |
Number of segments in the space: 1
Segment: 2
| Index | Marked | Encoded Address | Description |
| 2000 | 1 | 101000000000110110110000000000000000000101101110000001001011000010100000000011011011000000000000000000010110111000000100101100001 | External pointer object |
| 2001 | 1 | 101000000000110110000000000000001001001001111000001010111010100010100000000011011000000000000000100100100111100000101011101010001 | External pointer object |
| 2002 | 1 | 001000000000110110000000000000001000110000000000010000000000000000100000000011011000000000000000100011000000000001000000000000000 | External pointer object |

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment