Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
raw_object_fields.h
Go to the documentation of this file.
1// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4//
5// This file (and "raw_object_fields.cc") provide a kind of reflection that
6// allows us to identify the name of fields in hand-written "Raw..." classes
7// (from "raw_object.h") given the class and the offset within the object. This
8// is used for example by the snapshot profile writer ("v8_snapshot_writer.h")
9// to show the property names of these built-in objects in the snapshot profile.
10
11#ifndef RUNTIME_VM_RAW_OBJECT_FIELDS_H_
12#define RUNTIME_VM_RAW_OBJECT_FIELDS_H_
13
14#include <utility>
15
16#include "vm/hash_map.h"
17#include "vm/object.h"
18#include "vm/raw_object.h"
19
20namespace dart {
21
22#if defined(DART_PRECOMPILER) || defined(DART_ENABLE_HEAP_SNAPSHOT_WRITER)
23
24class OffsetsTable : public ZoneAllocated {
25 public:
26 explicit OffsetsTable(Zone* zone);
27
28 // Returns 'nullptr' if no offset was found.
29 // Otherwise, the returned string is allocated in global static memory.
30 const char* FieldNameForOffset(intptr_t cid, intptr_t offset);
31
32 struct OffsetsTableEntry {
33 intptr_t class_id;
34 const char* field_name;
35 bool is_compressed_pointer;
36 intptr_t offset;
37 };
38
39 static const MallocGrowableArray<OffsetsTableEntry>& offsets_table();
40 static void Init();
41 static void Cleanup();
42
43 private:
44 struct IntAndIntToStringMapTraits {
45 typedef std::pair<intptr_t, intptr_t> Key;
46 typedef const char* Value;
47
48 struct Pair {
49 Key key;
51 Pair() : key({-1, -1}), value(nullptr) {}
52 Pair(Key k, Value v) : key(k), value(v) {}
53 };
54
55 static Value ValueOf(Pair pair) { return pair.value; }
56 static Key KeyOf(Pair pair) { return pair.key; }
57 static uword Hash(Key key) {
58 return Utils::WordHash(key.first ^ key.second);
59 }
60 static bool IsKeyEqual(Pair x, Key y) {
61 return x.key.first == y.first && x.key.second == y.second;
62 }
63 };
64
65 DirectChainedHashMap<IntAndIntToStringMapTraits> cached_offsets_;
66};
67
68#else
69
71 public:
72 explicit OffsetsTable(Zone* zone) {}
73
74 const char* FieldNameForOffset(intptr_t cid, intptr_t offset) {
75 return nullptr;
76 }
77
78 static void Init() {}
79 static void Cleanup() {}
80};
81
82#endif
83
84} // namespace dart
85
86#endif // RUNTIME_VM_RAW_OBJECT_FIELDS_H_
TArray< uint32_t > Key
const char * FieldNameForOffset(intptr_t cid, intptr_t offset)
uint8_t value
double y
double x
uintptr_t uword
Definition globals.h:501
const intptr_t cid
Point offset