Skip to content

Instantly share code, notes, and snippets.

@deepak1556
Created February 19, 2024 17:52
Show Gist options
  • Select an option

  • Save deepak1556/4dd8533d90c7ba3a44a683bb879ab5b0 to your computer and use it in GitHub Desktop.

Select an option

Save deepak1556/4dd8533d90c7ba3a44a683bb879ab5b0 to your computer and use it in GitHub Desktop.

Revisions

  1. deepak1556 created this gist Feb 19, 2024.
    71 changes: 71 additions & 0 deletions external-pointer-table-tracer.cc
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,71 @@
    // 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
    36 changes: 36 additions & 0 deletions sample.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    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 %