Flutter Engine
The Flutter Engine
raw_object_fields.cc
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#include <type_traits>
6
8
9namespace dart {
10
11#if defined(DART_PRECOMPILER) || defined(DART_ENABLE_HEAP_SNAPSHOT_WRITER)
12
13// The list contains concrete classes and all of their fields (including ones
14// from super hierarchy)
15// If a class is listed here, only the fields in the list will appear in
16// heapsnapshots.
17#define COMMON_CLASSES_AND_FIELDS(F) \
18 F(Class, name_) \
19 F(Class, functions_) \
20 F(Class, functions_hash_table_) \
21 F(Class, fields_) \
22 F(Class, offset_in_words_to_field_) \
23 F(Class, interfaces_) \
24 F(Class, script_) \
25 F(Class, library_) \
26 F(Class, type_parameters_) \
27 F(Class, super_type_) \
28 F(Class, constants_) \
29 F(Class, declaration_type_) \
30 F(Class, invocation_dispatcher_cache_) \
31 F(PatchClass, wrapped_class_) \
32 F(PatchClass, script_) \
33 F(Function, name_) \
34 F(Function, owner_) \
35 F(Function, signature_) \
36 F(Function, data_) \
37 F(Function, ic_data_array_) \
38 F(Function, code_) \
39 F(ClosureData, context_scope_) \
40 F(ClosureData, parent_function_) \
41 F(ClosureData, closure_) \
42 F(Field, name_) \
43 F(Field, owner_) \
44 F(Field, type_) \
45 F(Field, initializer_function_) \
46 F(Field, host_offset_or_field_id_) \
47 F(Field, guarded_list_length_) \
48 F(Field, dependent_code_) \
49 F(Script, url_) \
50 F(Script, resolved_url_) \
51 F(Script, line_starts_) \
52 F(Script, debug_positions_) \
53 F(Script, kernel_program_info_) \
54 F(Script, source_) \
55 F(Library, name_) \
56 F(Library, url_) \
57 F(Library, private_key_) \
58 F(Library, dictionary_) \
59 F(Library, metadata_) \
60 F(Library, toplevel_class_) \
61 F(Library, used_scripts_) \
62 F(Library, loading_unit_) \
63 F(Library, imports_) \
64 F(Library, exports_) \
65 F(Library, dependencies_) \
66 F(Library, loaded_scripts_) \
67 F(Namespace, target_) \
68 F(Namespace, show_names_) \
69 F(Namespace, hide_names_) \
70 F(Namespace, owner_) \
71 F(KernelProgramInfo, kernel_component_) \
72 F(KernelProgramInfo, string_offsets_) \
73 F(KernelProgramInfo, string_data_) \
74 F(KernelProgramInfo, canonical_names_) \
75 F(KernelProgramInfo, metadata_payloads_) \
76 F(KernelProgramInfo, metadata_mappings_) \
77 F(KernelProgramInfo, scripts_) \
78 F(KernelProgramInfo, constants_) \
79 F(KernelProgramInfo, constants_table_) \
80 F(KernelProgramInfo, libraries_cache_) \
81 F(KernelProgramInfo, classes_cache_) \
82 F(WeakSerializationReference, target_) \
83 F(WeakSerializationReference, replacement_) \
84 F(WeakArray, length_) \
85 F(Code, object_pool_) \
86 F(Code, instructions_) \
87 F(Code, owner_) \
88 F(Code, exception_handlers_) \
89 F(Code, pc_descriptors_) \
90 F(Code, catch_entry_) \
91 F(Code, compressed_stackmaps_) \
92 F(Code, inlined_id_to_function_) \
93 F(Code, code_source_map_) \
94 F(ExceptionHandlers, handled_types_data_) \
95 F(Context, parent_) \
96 F(SingleTargetCache, target_) \
97 F(UnlinkedCall, target_name_) \
98 F(UnlinkedCall, args_descriptor_) \
99 F(MonomorphicSmiableCall, expected_cid_) \
100 F(MonomorphicSmiableCall, entrypoint_) \
101 F(CallSiteData, target_name_) \
102 F(CallSiteData, args_descriptor_) \
103 F(ICData, target_name_) \
104 F(ICData, args_descriptor_) \
105 F(ICData, entries_) \
106 F(ICData, owner_) \
107 F(InstructionsTable, code_objects_) \
108 F(MegamorphicCache, target_name_) \
109 F(MegamorphicCache, args_descriptor_) \
110 F(MegamorphicCache, buckets_) \
111 F(MegamorphicCache, mask_) \
112 F(SubtypeTestCache, cache_) \
113 F(LoadingUnit, parent_) \
114 F(LoadingUnit, base_objects_) \
115 F(ApiError, message_) \
116 F(LanguageError, previous_error_) \
117 F(LanguageError, script_) \
118 F(LanguageError, message_) \
119 F(LanguageError, formatted_message_) \
120 F(UnhandledException, exception_) \
121 F(UnhandledException, stacktrace_) \
122 F(UnwindError, message_) \
123 F(LibraryPrefix, name_) \
124 F(LibraryPrefix, importer_) \
125 F(LibraryPrefix, imports_) \
126 F(TypeArguments, instantiations_) \
127 F(TypeArguments, length_) \
128 F(TypeArguments, hash_) \
129 F(TypeArguments, nullability_) \
130 F(AbstractType, type_test_stub_) \
131 F(Type, type_test_stub_) \
132 F(Type, arguments_) \
133 F(Type, hash_) \
134 F(FunctionType, type_test_stub_) \
135 F(FunctionType, hash_) \
136 F(FunctionType, result_type_) \
137 F(FunctionType, parameter_types_) \
138 F(FunctionType, named_parameter_names_) \
139 F(FunctionType, type_parameters_) \
140 F(TypeParameter, type_test_stub_) \
141 F(TypeParameter, hash_) \
142 F(TypeParameter, owner_) \
143 F(TypeParameters, names_) \
144 F(TypeParameters, flags_) \
145 F(TypeParameters, bounds_) \
146 F(TypeParameters, defaults_) \
147 F(Closure, instantiator_type_arguments_) \
148 F(Closure, function_type_arguments_) \
149 F(Closure, delayed_type_arguments_) \
150 F(Closure, function_) \
151 F(Closure, context_) \
152 F(Closure, hash_) \
153 F(String, length_) \
154 F(Array, type_arguments_) \
155 F(Array, length_) \
156 F(ImmutableArray, type_arguments_) \
157 F(ImmutableArray, length_) \
158 F(GrowableObjectArray, type_arguments_) \
159 F(GrowableObjectArray, length_) \
160 F(GrowableObjectArray, data_) \
161 F(Map, type_arguments_) \
162 F(Map, index_) \
163 F(Map, hash_mask_) \
164 F(Map, data_) \
165 F(Map, used_data_) \
166 F(Map, deleted_keys_) \
167 F(ConstMap, type_arguments_) \
168 F(ConstMap, index_) \
169 F(ConstMap, hash_mask_) \
170 F(ConstMap, data_) \
171 F(ConstMap, used_data_) \
172 F(ConstMap, deleted_keys_) \
173 F(Set, type_arguments_) \
174 F(Set, index_) \
175 F(Set, hash_mask_) \
176 F(Set, data_) \
177 F(Set, used_data_) \
178 F(Set, deleted_keys_) \
179 F(ConstSet, type_arguments_) \
180 F(ConstSet, index_) \
181 F(ConstSet, hash_mask_) \
182 F(ConstSet, data_) \
183 F(ConstSet, used_data_) \
184 F(ConstSet, deleted_keys_) \
185 F(TypedData, length_) \
186 F(ExternalTypedData, length_) \
187 F(ReceivePort, send_port_) \
188 F(ReceivePort, handler_) \
189 F(ReceivePort, bitfield_) \
190 F(StackTrace, async_link_) \
191 F(StackTrace, code_array_) \
192 F(StackTrace, pc_offset_array_) \
193 F(RegExp, num_bracket_expressions_) \
194 F(RegExp, capture_name_map_) \
195 F(RegExp, pattern_) \
196 F(RegExp, one_byte_) \
197 F(RegExp, two_byte_) \
198 F(RegExp, one_byte_sticky_) \
199 F(RegExp, two_byte_sticky_) \
200 F(SuspendState, function_data_) \
201 F(SuspendState, then_callback_) \
202 F(SuspendState, error_callback_) \
203 F(WeakProperty, key_) \
204 F(WeakProperty, value_) \
205 F(WeakReference, target_) \
206 F(WeakReference, type_arguments_) \
207 F(Finalizer, detachments_) \
208 F(Finalizer, all_entries_) \
209 F(Finalizer, entries_collected_) \
210 F(Finalizer, callback_) \
211 F(Finalizer, type_arguments_) \
212 F(NativeFinalizer, detachments_) \
213 F(NativeFinalizer, all_entries_) \
214 F(NativeFinalizer, entries_collected_) \
215 F(NativeFinalizer, callback_) \
216 F(FinalizerEntry, value_) \
217 F(FinalizerEntry, detach_) \
218 F(FinalizerEntry, token_) \
219 F(FinalizerEntry, finalizer_) \
220 F(FinalizerEntry, next_) \
221 F(MirrorReference, referent_) \
222 F(UserTag, label_) \
223 F(Pointer, data_) \
224 F(Pointer, type_arguments_) \
225 F(DynamicLibrary, handle_) \
226 F(DynamicLibrary, isClosed_) \
227 F(DynamicLibrary, canBeClosed_) \
228 F(FfiTrampolineData, c_signature_) \
229 F(FfiTrampolineData, callback_target_) \
230 F(FfiTrampolineData, callback_exceptional_return_) \
231 F(TypedDataView, length_) \
232 F(TypedDataView, typed_data_) \
233 F(TypedDataView, offset_in_bytes_) \
234 F(FutureOr, type_arguments_)
235
236#define AOT_CLASSES_AND_FIELDS(F)
237
238#define AOT_NON_PRODUCT_CLASSES_AND_FIELDS(F) \
239 F(Class, direct_implementors_) \
240 F(Class, direct_subclasses_)
241
242#define JIT_CLASSES_AND_FIELDS(F) \
243 F(Class, allocation_stub_) \
244 F(Class, dependent_code_) \
245 F(Class, direct_implementors_) \
246 F(Class, direct_subclasses_) \
247 F(Code, active_instructions_) \
248 F(Code, deopt_info_array_) \
249 F(Code, static_calls_target_table_) \
250 F(ICData, receivers_static_type_) \
251 F(Function, positional_parameter_names_) \
252 F(Function, unoptimized_code_)
253
254#define JIT_NON_PRODUCT_CLASSES_AND_FIELDS(F) F(Script, constant_coverage_)
255
256#define NON_PRODUCT_CLASSES_AND_FIELDS(F) \
257 F(Class, user_name_) \
258 F(Code, return_address_metadata_) \
259 F(Code, var_descriptors_) \
260 F(Code, comments_) \
261 F(ReceivePort, debug_name_) \
262 F(ReceivePort, allocation_location_)
263
264#define NON_HEADER_HASH_CLASSES_AND_FIELDS(F) F(String, hash_)
265
266OffsetsTable::OffsetsTable(Zone* zone) : cached_offsets_(zone) {
267 for (const OffsetsTableEntry& entry : OffsetsTable::offsets_table()) {
268 cached_offsets_.Insert({{entry.class_id, entry.offset}, entry.field_name});
269 }
270}
271
272const char* OffsetsTable::FieldNameForOffset(intptr_t class_id,
273 intptr_t offset) {
274 return cached_offsets_.LookupValue({class_id, offset});
275}
276
277static MallocGrowableArray<OffsetsTable::OffsetsTableEntry> field_offsets_table;
278
279const MallocGrowableArray<OffsetsTable::OffsetsTableEntry>&
280OffsetsTable::offsets_table() {
281 ASSERT(field_offsets_table.length() > 0); // Initialized.
282 return field_offsets_table;
283}
284
285template <typename T>
286bool is_compressed_pointer() {
288}
289
290void OffsetsTable::Init() {
291 static const OffsetsTable::OffsetsTableEntry table[]{
292#define DEFINE_OFFSETS_TABLE_ENTRY(class_name, field_name) \
293 {class_name::kClassId, #field_name, \
294 is_compressed_pointer<decltype(Untagged##class_name::field_name)>(), \
295 OFFSET_OF(Untagged##class_name, field_name)},
296
297 COMMON_CLASSES_AND_FIELDS(DEFINE_OFFSETS_TABLE_ENTRY)
298#if !defined(PRODUCT)
299 NON_PRODUCT_CLASSES_AND_FIELDS(DEFINE_OFFSETS_TABLE_ENTRY)
300#endif
301
302#if !defined(HASH_IN_OBJECT_HEADER)
303 NON_HEADER_HASH_CLASSES_AND_FIELDS(DEFINE_OFFSETS_TABLE_ENTRY)
304#endif
305
306#if defined(DART_PRECOMPILED_RUNTIME)
307 AOT_CLASSES_AND_FIELDS(DEFINE_OFFSETS_TABLE_ENTRY)
308#if !defined(PRODUCT)
309 AOT_NON_PRODUCT_CLASSES_AND_FIELDS(
310 DEFINE_OFFSETS_TABLE_ENTRY)
311#endif
312#else
313 JIT_CLASSES_AND_FIELDS(DEFINE_OFFSETS_TABLE_ENTRY)
314#if !defined(PRODUCT)
315 JIT_NON_PRODUCT_CLASSES_AND_FIELDS(DEFINE_OFFSETS_TABLE_ENTRY)
316#endif
317#endif
318
319#undef DEFINE_OFFSETS_TABLE_ENTRY
320 };
321
322 for (const OffsetsTableEntry& entry : table) {
323 field_offsets_table.Add(entry);
324 }
325}
326
328 field_offsets_table.Clear();
329}
330
331#endif
332
333} // namespace dart
SI F table(const skcms_Curve *curve, F v)
OffsetsTable(Zone *zone)
#define ASSERT(E)
uint8_t value
void Init()
Definition: dart_vm.cc:33
SeparatedVector2 offset