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 "vm/raw_object_fields.h" |
6 | |
7 | namespace dart { |
8 | |
9 | #if defined(DART_PRECOMPILER) || !defined(DART_PRODUCT) |
10 | |
11 | #define COMMON_CLASSES_AND_FIELDS(F) \ |
12 | F(Class, name_) \ |
13 | F(Class, user_name_) \ |
14 | F(Class, functions_) \ |
15 | F(Class, functions_hash_table_) \ |
16 | F(Class, fields_) \ |
17 | F(Class, offset_in_words_to_field_) \ |
18 | F(Class, interfaces_) \ |
19 | F(Class, script_) \ |
20 | F(Class, library_) \ |
21 | F(Class, type_parameters_) \ |
22 | F(Class, super_type_) \ |
23 | F(Class, signature_function_) \ |
24 | F(Class, constants_) \ |
25 | F(Class, declaration_type_) \ |
26 | F(Class, invocation_dispatcher_cache_) \ |
27 | F(Class, allocation_stub_) \ |
28 | F(Class, direct_implementors_) \ |
29 | F(Class, direct_subclasses_) \ |
30 | F(Class, dependent_code_) \ |
31 | F(PatchClass, patched_class_) \ |
32 | F(PatchClass, origin_class_) \ |
33 | F(PatchClass, script_) \ |
34 | F(PatchClass, library_kernel_data_) \ |
35 | F(Function, name_) \ |
36 | F(Function, owner_) \ |
37 | F(Function, result_type_) \ |
38 | F(Function, parameter_types_) \ |
39 | F(Function, parameter_names_) \ |
40 | F(Function, type_parameters_) \ |
41 | F(Function, data_) \ |
42 | F(Function, ic_data_array_) \ |
43 | F(Function, code_) \ |
44 | F(ClosureData, context_scope_) \ |
45 | F(ClosureData, parent_function_) \ |
46 | F(ClosureData, signature_type_) \ |
47 | F(ClosureData, closure_) \ |
48 | F(SignatureData, parent_function_) \ |
49 | F(SignatureData, signature_type_) \ |
50 | F(RedirectionData, type_) \ |
51 | F(RedirectionData, identifier_) \ |
52 | F(RedirectionData, target_) \ |
53 | F(Field, name_) \ |
54 | F(Field, owner_) \ |
55 | F(Field, type_) \ |
56 | F(Field, guarded_list_length_) \ |
57 | F(Field, dependent_code_) \ |
58 | F(Field, initializer_function_) \ |
59 | F(Field, host_offset_or_field_id_) \ |
60 | F(Script, url_) \ |
61 | F(Script, resolved_url_) \ |
62 | F(Script, compile_time_constants_) \ |
63 | F(Script, line_starts_) \ |
64 | F(Script, debug_positions_) \ |
65 | F(Script, kernel_program_info_) \ |
66 | F(Script, source_) \ |
67 | F(Library, name_) \ |
68 | F(Library, url_) \ |
69 | F(Library, private_key_) \ |
70 | F(Library, dictionary_) \ |
71 | F(Library, metadata_) \ |
72 | F(Library, toplevel_class_) \ |
73 | F(Library, used_scripts_) \ |
74 | F(Library, loading_unit_) \ |
75 | F(Library, imports_) \ |
76 | F(Library, exports_) \ |
77 | F(Library, kernel_data_) \ |
78 | F(Library, resolved_names_) \ |
79 | F(Library, exported_names_) \ |
80 | F(Library, loaded_scripts_) \ |
81 | F(Namespace, library_) \ |
82 | F(Namespace, show_names_) \ |
83 | F(Namespace, hide_names_) \ |
84 | F(Namespace, metadata_field_) \ |
85 | F(KernelProgramInfo, string_offsets_) \ |
86 | F(KernelProgramInfo, string_data_) \ |
87 | F(KernelProgramInfo, canonical_names_) \ |
88 | F(KernelProgramInfo, metadata_payloads_) \ |
89 | F(KernelProgramInfo, metadata_mappings_) \ |
90 | F(KernelProgramInfo, scripts_) \ |
91 | F(KernelProgramInfo, constants_) \ |
92 | F(KernelProgramInfo, bytecode_component_) \ |
93 | F(KernelProgramInfo, potential_natives_) \ |
94 | F(KernelProgramInfo, potential_pragma_functions_) \ |
95 | F(KernelProgramInfo, constants_table_) \ |
96 | F(KernelProgramInfo, libraries_cache_) \ |
97 | F(KernelProgramInfo, classes_cache_) \ |
98 | F(KernelProgramInfo, retained_kernel_blob_) \ |
99 | F(Code, object_pool_) \ |
100 | F(Code, instructions_) \ |
101 | F(Code, owner_) \ |
102 | F(Code, exception_handlers_) \ |
103 | F(Code, pc_descriptors_) \ |
104 | F(Code, catch_entry_) \ |
105 | F(Code, compressed_stackmaps_) \ |
106 | F(Code, inlined_id_to_function_) \ |
107 | F(Code, code_source_map_) \ |
108 | F(Bytecode, object_pool_) \ |
109 | F(Bytecode, instructions_) \ |
110 | F(Bytecode, function_) \ |
111 | F(Bytecode, exception_handlers_) \ |
112 | F(Bytecode, pc_descriptors_) \ |
113 | F(Bytecode, closures_) \ |
114 | F(ExceptionHandlers, handled_types_data_) \ |
115 | F(Context, parent_) \ |
116 | F(ParameterTypeCheck, param_) \ |
117 | F(ParameterTypeCheck, type_or_bound_) \ |
118 | F(ParameterTypeCheck, name_) \ |
119 | F(ParameterTypeCheck, cache_) \ |
120 | F(SingleTargetCache, target_) \ |
121 | F(UnlinkedCall, target_name_) \ |
122 | F(UnlinkedCall, args_descriptor_) \ |
123 | F(MonomorphicSmiableCall, expected_cid_) \ |
124 | F(MonomorphicSmiableCall, target_) \ |
125 | F(CallSiteData, target_name_) \ |
126 | F(CallSiteData, args_descriptor_) \ |
127 | F(ICData, entries_) \ |
128 | F(ICData, owner_) \ |
129 | F(MegamorphicCache, buckets_) \ |
130 | F(MegamorphicCache, mask_) \ |
131 | F(SubtypeTestCache, cache_) \ |
132 | F(LoadingUnit, parent_) \ |
133 | F(LoadingUnit, base_objects_) \ |
134 | F(ApiError, message_) \ |
135 | F(LanguageError, previous_error_) \ |
136 | F(LanguageError, script_) \ |
137 | F(LanguageError, message_) \ |
138 | F(LanguageError, formatted_message_) \ |
139 | F(UnhandledException, exception_) \ |
140 | F(UnhandledException, stacktrace_) \ |
141 | F(UnwindError, message_) \ |
142 | F(LibraryPrefix, name_) \ |
143 | F(LibraryPrefix, importer_) \ |
144 | F(LibraryPrefix, imports_) \ |
145 | F(TypeArguments, instantiations_) \ |
146 | F(TypeArguments, length_) \ |
147 | F(TypeArguments, hash_) \ |
148 | F(TypeArguments, nullability_) \ |
149 | F(AbstractType, type_test_stub_) \ |
150 | F(Type, type_test_stub_) \ |
151 | F(Type, type_class_id_) \ |
152 | F(Type, arguments_) \ |
153 | F(Type, hash_) \ |
154 | F(Type, signature_) \ |
155 | F(TypeRef, type_test_stub_) \ |
156 | F(TypeRef, type_) \ |
157 | F(TypeParameter, type_test_stub_) \ |
158 | F(TypeParameter, name_) \ |
159 | F(TypeParameter, hash_) \ |
160 | F(TypeParameter, bound_) \ |
161 | F(TypeParameter, parameterized_function_) \ |
162 | F(Closure, instantiator_type_arguments_) \ |
163 | F(Closure, function_type_arguments_) \ |
164 | F(Closure, delayed_type_arguments_) \ |
165 | F(Closure, function_) \ |
166 | F(Closure, context_) \ |
167 | F(Closure, hash_) \ |
168 | F(String, length_) \ |
169 | F(String, hash_) \ |
170 | F(Array, type_arguments_) \ |
171 | F(Array, length_) \ |
172 | F(GrowableObjectArray, type_arguments_) \ |
173 | F(GrowableObjectArray, length_) \ |
174 | F(GrowableObjectArray, data_) \ |
175 | F(LinkedHashMap, type_arguments_) \ |
176 | F(LinkedHashMap, index_) \ |
177 | F(LinkedHashMap, hash_mask_) \ |
178 | F(LinkedHashMap, data_) \ |
179 | F(LinkedHashMap, used_data_) \ |
180 | F(LinkedHashMap, deleted_keys_) \ |
181 | F(TypedData, length_) \ |
182 | F(ExternalTypedData, length_) \ |
183 | F(ReceivePort, send_port_) \ |
184 | F(ReceivePort, handler_) \ |
185 | F(StackTrace, async_link_) \ |
186 | F(StackTrace, code_array_) \ |
187 | F(StackTrace, pc_offset_array_) \ |
188 | F(RegExp, num_bracket_expressions_) \ |
189 | F(RegExp, capture_name_map_) \ |
190 | F(RegExp, pattern_) \ |
191 | F(RegExp, external_one_byte_function_) \ |
192 | F(RegExp, external_two_byte_function_) \ |
193 | F(RegExp, external_one_byte_sticky_function_) \ |
194 | F(RegExp, external_two_byte_sticky_function_) \ |
195 | F(WeakProperty, key_) \ |
196 | F(WeakProperty, value_) \ |
197 | F(MirrorReference, referent_) \ |
198 | F(UserTag, label_) \ |
199 | F(PointerBase, data_) \ |
200 | F(Pointer, type_arguments_) \ |
201 | F(DynamicLibrary, handle_) \ |
202 | F(FfiTrampolineData, signature_type_) \ |
203 | F(FfiTrampolineData, c_signature_) \ |
204 | F(FfiTrampolineData, callback_target_) \ |
205 | F(FfiTrampolineData, callback_exceptional_return_) \ |
206 | F(TypedDataBase, length_) \ |
207 | F(TypedDataView, typed_data_) \ |
208 | F(TypedDataView, offset_in_bytes_) \ |
209 | F(FutureOr, type_arguments_) |
210 | |
211 | #define AOT_CLASSES_AND_FIELDS(F) F(WeakSerializationReference, cid_) |
212 | |
213 | #define JIT_CLASSES_AND_FIELDS(F) \ |
214 | F(Code, active_instructions_) \ |
215 | F(Code, deopt_info_array_) \ |
216 | F(Code, static_calls_target_table_) \ |
217 | F(ICData, receivers_static_type_) \ |
218 | F(Function, bytecode_) \ |
219 | F(Function, unoptimized_code_) \ |
220 | F(Field, saved_initial_value_) \ |
221 | F(Field, type_test_cache_) \ |
222 | F(WeakSerializationReference, target_) |
223 | |
224 | OffsetsTable::OffsetsTable(Zone* zone) : cached_offsets_(zone) { |
225 | for (intptr_t i = 0; offsets_table[i].class_id != -1; ++i) { |
226 | OffsetsTableEntry entry = offsets_table[i]; |
227 | cached_offsets_.Insert({{entry.class_id, entry.offset}, entry.field_name}); |
228 | } |
229 | } |
230 | |
231 | const char* OffsetsTable::FieldNameForOffset(intptr_t class_id, |
232 | intptr_t offset) { |
233 | return cached_offsets_.LookupValue({class_id, offset}); |
234 | } |
235 | |
236 | #define DEFINE_OFFSETS_TABLE_ENTRY(class_name, field_name) \ |
237 | {class_name::kClassId, #field_name, \ |
238 | OFFSET_OF(class_name##Layout, field_name)}, |
239 | |
240 | // clang-format off |
241 | OffsetsTable::OffsetsTableEntry OffsetsTable::offsets_table[] = { |
242 | COMMON_CLASSES_AND_FIELDS(DEFINE_OFFSETS_TABLE_ENTRY) |
243 | #if defined(DART_PRECOMPILED_RUNTIME) |
244 | AOT_CLASSES_AND_FIELDS(DEFINE_OFFSETS_TABLE_ENTRY) |
245 | #else |
246 | JIT_CLASSES_AND_FIELDS(DEFINE_OFFSETS_TABLE_ENTRY) |
247 | #endif |
248 | {-1, nullptr, -1} |
249 | }; |
250 | // clang-format on |
251 | |
252 | #undef DEFINE_OFFSETS_TABLE_ENTRY |
253 | |
254 | #endif |
255 | |
256 | } // namespace dart |
257 | |