5#ifndef RUNTIME_VM_V8_SNAPSHOT_WRITER_H_
6#define RUNTIME_VM_V8_SNAPSHOT_WRITER_H_
35 : encoded_((static_cast<uint64_t>(
nonce) << kIdSpaceBits) |
36 static_cast<intptr_t>(
space)) {
41 return encoded_ != other.encoded_;
44 return !(*
this != other);
48 inline int64_t
nonce()
const {
return encoded_ >> kIdSpaceBits; }
50 return static_cast<IdSpace>(encoded_ & kIdSpaceMask);
59 static constexpr size_t kIdSpaceBits =
61 static constexpr int64_t kIdSpaceMask =
62 Utils::NBitMask<int64_t>(kIdSpaceBits);
88#if !defined(DART_PRECOMPILER)
102 const ObjectId& replacement_object_id) {}
125 const Reference& reference,
126 const ObjectId& to_object_id);
134 void AttributeDroppedReferenceTo(
const ObjectId& from_object_id,
135 const Reference& reference,
136 const ObjectId& to_object_id,
137 const ObjectId& replacement_object_id);
141 void AddRoot(
const ObjectId& object_id,
const char*
name =
nullptr);
144 void Write(
const char*
file);
148 bool HasId(
const ObjectId& object_id);
151 static constexpr intptr_t kInvalidString =
153 static constexpr intptr_t kNumNodeFields = 5;
154 static constexpr intptr_t kNumEdgeFields = 3;
157 enum class Type : int32_t {
171 :
Edge(profile_writer,
172 reference.
type == Reference::
Type::kElement ?
Type::kElement
174 reference.
type == Reference::
Type::kElement
176 : profile_writer->strings_.Add(reference.
name)) {}
179 intptr_t name_or_offset)
180 :
type(
type), name_or_offset(name_or_offset) {}
183 return type != other.type || name_or_offset != other.name_or_offset;
185 inline bool operator==(
const Edge& other) {
return !(*
this != other); }
189 const ObjectId& target_id)
const;
192 const ObjectId& target_id)
const;
195 int32_t name_or_offset;
198 struct EdgeToObjectIdMapTrait {
200 using Value = ObjectId;
209 static Key KeyOf(
Pair kv) {
return kv.edge; }
210 static Value ValueOf(
Pair kv) {
return kv.target; }
215 static bool IsKeyEqual(
Pair kv,
Key key) {
return kv.edge ==
key; }
218 struct EdgeMap :
public ZoneDirectChainedHashMap<EdgeToObjectIdMapTrait> {
220 : ZoneDirectChainedHashMap<EdgeToObjectIdMapTrait>(zone, 1) {}
226 const char* property =
nullptr)
const;
233 intptr_t
type = kInvalidString,
234 intptr_t
name = kInvalidString)
236 edges(new(profile_writer->zone_)
EdgeMap(profile_writer->zone_)),
240 inline bool operator!=(
const NodeInfo& other) {
241 return id != other.id ||
type != other.type ||
name != other.name ||
242 self_size != other.self_size || edges != other.edges ||
243 offset_ != other.offset_;
245 inline bool operator==(
const NodeInfo& other) {
return !(*
this != other); }
247 void AddEdge(
const Edge& edge,
const ObjectId&
target) {
248 edges->Insert({edge,
target});
250 bool HasEdge(
const Edge& edge) {
return edges->HasKey(edge); }
255 JSONWriter* writer)
const;
257 JSONWriter* writer)
const;
259 intptr_t
offset()
const {
return offset_; }
260 void set_offset(intptr_t
offset) {
267 intptr_t
type = kInvalidString;
268 intptr_t
name = kInvalidString;
269 intptr_t self_size = 0;
273 intptr_t offset_ = -1;
278 NodeInfo* EnsureId(
const ObjectId& object_id);
279 void Write(JSONWriter* writer);
285 explicit StringsTable(Zone* zone)
286 : zone_(zone), index_map_(zone), strings_(zone, 2) {}
288 intptr_t Add(
const char* str);
290 const
char* At(intptr_t index) const;
291 void Write(JSONWriter* writer, const
char* property =
nullptr) const;
295 CStringIntMap index_map_;
296 GrowableArray<const
char*> strings_;
299 struct ObjectIdToNodeInfoTraits {
300 typedef NodeInfo
Pair;
301 typedef ObjectId
Key;
304 static Key KeyOf(
const Pair& pair) {
return pair.id; }
306 static Value ValueOf(
const Pair& pair) {
return pair; }
310 static bool IsKeyEqual(
const Pair&
x,
const Key&
y) {
return x.id ==
y; }
313 struct ObjectIdSetKeyValueTrait {
314 using Pair = ObjectId;
318 static Key KeyOf(
const Pair& pair) {
return pair; }
319 static Value ValueOf(
const Pair& pair) {
return pair; }
321 static bool IsKeyEqual(
const Pair& pair,
const Key&
key) {
327 DirectChainedHashMap<ObjectIdToNodeInfoTraits> nodes_;
328 StringsTable node_types_;
329 StringsTable edge_types_;
330 StringsTable strings_;
331 DirectChainedHashMap<ObjectIdSetKeyValueTrait> roots_;
GrTriangulator::Edge Edge
std::map< Edge, int > EdgeMap
#define ASSERT_EQUAL(expected, actual)
static bool IsInt(intptr_t N, T value)
static uint32_t WordHash(intptr_t key)
static constexpr size_t BitLength(int64_t value)
static const ObjectId kArtificialRootId
void AttributeReferenceTo(const ObjectId &from_object_id, const Reference &reference, const ObjectId &to_object_id)
V8SnapshotProfileWriter(Zone *zone)
virtual ~V8SnapshotProfileWriter()
void SetObjectTypeAndName(const ObjectId &object_id, const char *type, const char *name)
void AddRoot(const ObjectId &object_id, const char *name=nullptr)
void AttributeBytesTo(const ObjectId &object_id, size_t num_bytes)
bool HasId(const ObjectId &object_id)
void AttributeWeakReferenceTo(const ObjectId &from_object_id, const Reference &reference, const ObjectId &to_object_id, const ObjectId &replacement_object_id)
constexpr bool operator!=(Register r, LinkRegister lr)
uint32_t CombineHashes(uint32_t hash, uint32_t other_hash)
constexpr bool operator==(Register r, LinkRegister)
uint32_t FinalizeHash(uint32_t hash, intptr_t hashbits=kBitsPerInt32)
static uint32_t Hash(uint32_t key)
constexpr intptr_t kBitsPerInt64
static SkString fmt(SkColor4f c)
static constexpr Value kNoValue
void WriteDebug(JSONWriter *writer, const char *property=nullptr) const
bool IsArtificial() const
void Write(JSONWriter *writer, const char *property=nullptr) const
ObjectId(IdSpace space, int64_t nonce)
bool operator==(const ObjectId &other) const
const char * ToCString(Zone *zone) const
bool operator!=(const ObjectId &other) const
static Reference Element(intptr_t offset)
static Reference Property(const char *name)
enum dart::V8SnapshotProfileWriter::Reference::Type type