Flutter Engine
The Flutter Engine
object_store.h
Go to the documentation of this file.
1// Copyright (c) 2012, 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#ifndef RUNTIME_VM_OBJECT_STORE_H_
6#define RUNTIME_VM_OBJECT_STORE_H_
7
8#include "vm/object.h"
9
10namespace dart {
11
12// Forward declarations.
13class Isolate;
14class ObjectPointerVisitor;
15
16// A list of the bootstrap libraries including CamelName and name.
17//
18// These are listed in the order that they are compiled (see vm/bootstrap.cc).
19#define FOR_EACH_BOOTSTRAP_LIBRARY(M) \
20 M(Core, core) \
21 M(Async, async) \
22 M(Collection, collection) \
23 M(Convert, convert) \
24 M(Developer, developer) \
25 M(Ffi, ffi) \
26 M(Internal, _internal) \
27 M(Isolate, isolate) \
28 M(Math, math) \
29 M(Mirrors, mirrors) \
30 M(TypedData, typed_data) \
31 M(VMService, _vmservice)
32
33// R_ - needs getter only
34// RW - needs getter and setter
35// ARW_RELAXED - needs getter and setter with relaxed atomic access
36// ARW_AR - needs getter and setter with acq/rel atomic access
37// LAZY_CORE - needs lazy init getter for a "dart:core" member
38// LAZY_ASYNC - needs lazy init getter for a "dart:async" member
39// LAZY_ISOLATE - needs lazy init getter for a "dart:isolate" member
40// LAZY_INTERNAL - needs lazy init getter for a "dart:_internal" member
41#define OBJECT_STORE_FIELD_LIST(R_, RW, ARW_RELAXED, ARW_AR, LAZY_CORE, \
42 LAZY_ASYNC, LAZY_ISOLATE, LAZY_INTERNAL, \
43 LAZY_FFI) \
44 LAZY_CORE(Class, list_class) \
45 LAZY_CORE(Class, map_class) \
46 LAZY_CORE(Class, set_class) \
47 LAZY_CORE(Type, non_nullable_list_rare_type) \
48 LAZY_CORE(Type, non_nullable_map_rare_type) \
49 LAZY_CORE(Field, enum_index_field) \
50 LAZY_CORE(Field, enum_name_field) \
51 LAZY_CORE(Function, _object_equals_function) \
52 LAZY_CORE(Function, _object_hash_code_function) \
53 LAZY_CORE(Function, _object_to_string_function) \
54 LAZY_INTERNAL(Class, symbol_class) \
55 LAZY_INTERNAL(Field, symbol_name_field) \
56 LAZY_FFI(Class, varargs_class) \
57 LAZY_FFI(Function, ffi_resolver_function) \
58 LAZY_FFI(Function, handle_finalizer_message_function) \
59 LAZY_FFI(Function, handle_native_finalizer_message_function) \
60 LAZY_ASYNC(Type, non_nullable_future_never_type) \
61 LAZY_ASYNC(Type, nullable_future_null_type) \
62 LAZY_ISOLATE(Class, send_port_class) \
63 LAZY_ISOLATE(Class, capability_class) \
64 LAZY_ISOLATE(Class, transferable_class) \
65 LAZY_ISOLATE(Function, lookup_port_handler) \
66 LAZY_ISOLATE(Function, lookup_open_ports) \
67 LAZY_ISOLATE(Function, handle_message_function) \
68 RW(Class, object_class) \
69 RW(Type, object_type) \
70 RW(Type, non_nullable_object_type) \
71 RW(Type, nullable_object_type) \
72 RW(Class, null_class) \
73 RW(Type, null_type) \
74 RW(Class, never_class) \
75 RW(Type, never_type) \
76 RW(Type, function_type) \
77 RW(Type, type_type) \
78 RW(Class, closure_class) \
79 RW(Class, record_class) \
80 RW(Type, number_type) \
81 RW(Type, nullable_number_type) \
82 RW(Type, int_type) \
83 RW(Type, non_nullable_int_type) \
84 RW(Type, nullable_int_type) \
85 RW(Class, integer_implementation_class) \
86 RW(Type, int64_type) \
87 RW(Class, smi_class) \
88 RW(Type, smi_type) \
89 RW(Class, mint_class) \
90 RW(Type, mint_type) \
91 RW(Class, double_class) \
92 RW(Type, double_type) \
93 RW(Type, nullable_double_type) \
94 RW(Type, float32x4_type) \
95 RW(Type, int32x4_type) \
96 RW(Type, float64x2_type) \
97 RW(Type, string_type) \
98 RW(TypeArguments, type_argument_int) \
99 RW(TypeArguments, type_argument_double) \
100 RW(TypeArguments, type_argument_never) \
101 RW(TypeArguments, type_argument_string) \
102 RW(TypeArguments, type_argument_string_dynamic) \
103 RW(TypeArguments, type_argument_string_string) \
104 RW(Class, compiletime_error_class) \
105 RW(Class, pragma_class) \
106 RW(Field, pragma_name) \
107 RW(Field, pragma_options) \
108 RW(Class, future_class) \
109 RW(Class, future_or_class) \
110 RW(Class, one_byte_string_class) \
111 RW(Class, two_byte_string_class) \
112 RW(Type, bool_type) \
113 RW(Class, bool_class) \
114 RW(Class, array_class) \
115 RW(Type, array_type) \
116 RW(Class, immutable_array_class) \
117 RW(Class, growable_object_array_class) \
118 RW(Class, map_impl_class) \
119 RW(Class, const_map_impl_class) \
120 RW(Class, set_impl_class) \
121 RW(Class, const_set_impl_class) \
122 RW(Class, float32x4_class) \
123 RW(Class, int32x4_class) \
124 RW(Class, float64x2_class) \
125 RW(Class, error_class) \
126 RW(Class, expando_class) \
127 RW(Class, iterable_class) \
128 RW(Class, weak_property_class) \
129 RW(Class, weak_reference_class) \
130 RW(Class, finalizer_class) \
131 RW(Class, finalizer_entry_class) \
132 RW(Class, native_finalizer_class) \
133 ARW_AR(WeakArray, symbol_table) \
134 ARW_AR(WeakArray, regexp_table) \
135 RW(Array, canonical_types) \
136 RW(Array, canonical_function_types) \
137 RW(Array, canonical_record_types) \
138 RW(Array, canonical_type_parameters) \
139 RW(Array, canonical_type_arguments) \
140 RW(Library, async_library) \
141 RW(Library, core_library) \
142 RW(Library, collection_library) \
143 RW(Library, convert_library) \
144 RW(Library, developer_library) \
145 RW(Library, ffi_library) \
146 RW(Library, _internal_library) \
147 RW(Library, isolate_library) \
148 RW(Library, math_library) \
149 RW(Library, mirrors_library) \
150 RW(Library, native_wrappers_library) \
151 RW(Library, root_library) \
152 RW(Library, typed_data_library) \
153 RW(Library, _vmservice_library) \
154 RW(Library, native_assets_library) \
155 RW(Array, native_assets_map) \
156 RW(GrowableObjectArray, libraries) \
157 RW(Array, libraries_map) \
158 RW(Array, uri_to_resolved_uri_map) \
159 RW(Array, resolved_uri_to_uri_map) \
160 RW(Smi, last_libraries_count) \
161 RW(Array, loading_units) \
162 RW(GrowableObjectArray, closure_functions) \
163 RW(Array, closure_functions_table) \
164 RW(GrowableObjectArray, pending_classes) \
165 RW(Array, record_field_names_map) \
166 ARW_RELAXED(Array, record_field_names) \
167 RW(Instance, stack_overflow) \
168 RW(Instance, out_of_memory) \
169 RW(Function, growable_list_factory) \
170 RW(Function, simple_instance_of_function) \
171 RW(Function, simple_instance_of_true_function) \
172 RW(Function, simple_instance_of_false_function) \
173 RW(Function, async_star_stream_controller_add) \
174 RW(Function, async_star_stream_controller_add_stream) \
175 RW(Function, suspend_state_init_async) \
176 RW(Function, suspend_state_await) \
177 RW(Function, suspend_state_await_with_type_check) \
178 RW(Function, suspend_state_return_async) \
179 RW(Function, suspend_state_return_async_not_future) \
180 RW(Function, suspend_state_init_async_star) \
181 RW(Function, suspend_state_yield_async_star) \
182 RW(Function, suspend_state_return_async_star) \
183 RW(Function, suspend_state_init_sync_star) \
184 RW(Function, suspend_state_suspend_sync_star_at_start) \
185 RW(Function, suspend_state_handle_exception) \
186 RW(Class, async_star_stream_controller) \
187 RW(Class, stream_class) \
188 RW(Class, sync_star_iterator_class) \
189 RW(Field, async_star_stream_controller_async_star_body) \
190 RW(Field, sync_star_iterator_current) \
191 RW(Field, sync_star_iterator_state) \
192 RW(Field, sync_star_iterator_yield_star_iterable) \
193 RW(CompressedStackMaps, canonicalized_stack_map_entries) \
194 RW(ObjectPool, global_object_pool) \
195 RW(Array, unique_dynamic_targets) \
196 RW(GrowableObjectArray, megamorphic_cache_table) \
197 RW(GrowableObjectArray, ffi_callback_code) \
198 RW(Code, dispatch_table_null_error_stub) \
199 RW(Code, late_initialization_error_stub_with_fpu_regs_stub) \
200 RW(Code, late_initialization_error_stub_without_fpu_regs_stub) \
201 RW(Code, null_error_stub_with_fpu_regs_stub) \
202 RW(Code, null_error_stub_without_fpu_regs_stub) \
203 RW(Code, null_arg_error_stub_with_fpu_regs_stub) \
204 RW(Code, null_arg_error_stub_without_fpu_regs_stub) \
205 RW(Code, null_cast_error_stub_with_fpu_regs_stub) \
206 RW(Code, null_cast_error_stub_without_fpu_regs_stub) \
207 RW(Code, range_error_stub_with_fpu_regs_stub) \
208 RW(Code, range_error_stub_without_fpu_regs_stub) \
209 RW(Code, write_error_stub_with_fpu_regs_stub) \
210 RW(Code, write_error_stub_without_fpu_regs_stub) \
211 RW(Code, allocate_mint_with_fpu_regs_stub) \
212 RW(Code, allocate_mint_without_fpu_regs_stub) \
213 RW(Code, stack_overflow_stub_with_fpu_regs_stub) \
214 RW(Code, stack_overflow_stub_without_fpu_regs_stub) \
215 RW(Code, allocate_array_stub) \
216 RW(Code, allocate_mint_stub) \
217 RW(Code, allocate_double_stub) \
218 RW(Code, allocate_float32x4_stub) \
219 RW(Code, allocate_float64x2_stub) \
220 RW(Code, allocate_int32x4_stub) \
221 RW(Code, allocate_int8_array_stub) \
222 RW(Code, allocate_uint8_array_stub) \
223 RW(Code, allocate_uint8_clamped_array_stub) \
224 RW(Code, allocate_int16_array_stub) \
225 RW(Code, allocate_uint16_array_stub) \
226 RW(Code, allocate_int32_array_stub) \
227 RW(Code, allocate_uint32_array_stub) \
228 RW(Code, allocate_int64_array_stub) \
229 RW(Code, allocate_uint64_array_stub) \
230 RW(Code, allocate_float32_array_stub) \
231 RW(Code, allocate_float64_array_stub) \
232 RW(Code, allocate_float32x4_array_stub) \
233 RW(Code, allocate_int32x4_array_stub) \
234 RW(Code, allocate_float64x2_array_stub) \
235 RW(Code, allocate_closure_stub) \
236 RW(Code, allocate_closure_generic_stub) \
237 RW(Code, allocate_closure_ta_stub) \
238 RW(Code, allocate_closure_ta_generic_stub) \
239 RW(Code, allocate_context_stub) \
240 RW(Code, allocate_growable_array_stub) \
241 RW(Code, allocate_object_stub) \
242 RW(Code, allocate_object_parametrized_stub) \
243 RW(Code, allocate_record_stub) \
244 RW(Code, allocate_record2_stub) \
245 RW(Code, allocate_record2_named_stub) \
246 RW(Code, allocate_record3_stub) \
247 RW(Code, allocate_record3_named_stub) \
248 RW(Code, allocate_unhandled_exception_stub) \
249 RW(Code, clone_context_stub) \
250 RW(Code, write_barrier_wrappers_stub) \
251 RW(Code, array_write_barrier_stub) \
252 RW(Code, throw_stub) \
253 RW(Code, re_throw_stub) \
254 RW(Code, assert_boolean_stub) \
255 RW(Code, instance_of_stub) \
256 RW(Code, init_static_field_stub) \
257 RW(Code, init_late_static_field_stub) \
258 RW(Code, init_late_final_static_field_stub) \
259 RW(Code, init_instance_field_stub) \
260 RW(Code, init_late_instance_field_stub) \
261 RW(Code, init_late_final_instance_field_stub) \
262 RW(Code, init_shared_late_static_field_stub) \
263 RW(Code, init_shared_late_final_static_field_stub) \
264 RW(Code, call_closure_no_such_method_stub) \
265 RW(Code, default_tts_stub) \
266 RW(Code, default_nullable_tts_stub) \
267 RW(Code, top_type_tts_stub) \
268 RW(Code, nullable_type_parameter_tts_stub) \
269 RW(Code, type_parameter_tts_stub) \
270 RW(Code, unreachable_tts_stub) \
271 RW(Array, ffi_callback_functions) \
272 RW(Code, slow_tts_stub) \
273 /* Roots for JIT/AOT snapshots are up until here (see to_snapshot() below)*/ \
274 RW(Code, await_stub) \
275 RW(Code, await_with_type_check_stub) \
276 RW(Code, clone_suspend_state_stub) \
277 RW(Code, ffi_async_callback_send_stub) \
278 RW(Code, init_async_stub) \
279 RW(Code, resume_stub) \
280 RW(Code, return_async_stub) \
281 RW(Code, return_async_not_future_stub) \
282 RW(Code, init_async_star_stub) \
283 RW(Code, yield_async_star_stub) \
284 RW(Code, return_async_star_stub) \
285 RW(Code, init_sync_star_stub) \
286 RW(Code, suspend_sync_star_at_start_stub) \
287 RW(Code, suspend_sync_star_at_yield_stub) \
288 RW(Array, dispatch_table_code_entries) \
289 RW(GrowableObjectArray, instructions_tables) \
290 RW(Array, obfuscation_map) \
291 RW(Array, loading_unit_uris) \
292 RW(Class, ffi_pointer_class) \
293 RW(Class, ffi_native_type_class) \
294 // Please remember the last entry must be referred in the 'to' function below.
295
296#define OBJECT_STORE_STUB_CODE_LIST(DO) \
297 DO(dispatch_table_null_error_stub, DispatchTableNullError) \
298 DO(late_initialization_error_stub_with_fpu_regs_stub, \
299 LateInitializationErrorSharedWithFPURegs) \
300 DO(late_initialization_error_stub_without_fpu_regs_stub, \
301 LateInitializationErrorSharedWithoutFPURegs) \
302 DO(null_error_stub_with_fpu_regs_stub, NullErrorSharedWithFPURegs) \
303 DO(null_error_stub_without_fpu_regs_stub, NullErrorSharedWithoutFPURegs) \
304 DO(null_arg_error_stub_with_fpu_regs_stub, NullArgErrorSharedWithFPURegs) \
305 DO(null_arg_error_stub_without_fpu_regs_stub, \
306 NullArgErrorSharedWithoutFPURegs) \
307 DO(null_cast_error_stub_with_fpu_regs_stub, NullCastErrorSharedWithFPURegs) \
308 DO(null_cast_error_stub_without_fpu_regs_stub, \
309 NullCastErrorSharedWithoutFPURegs) \
310 DO(range_error_stub_with_fpu_regs_stub, RangeErrorSharedWithFPURegs) \
311 DO(range_error_stub_without_fpu_regs_stub, RangeErrorSharedWithoutFPURegs) \
312 DO(write_error_stub_with_fpu_regs_stub, WriteErrorSharedWithFPURegs) \
313 DO(write_error_stub_without_fpu_regs_stub, WriteErrorSharedWithoutFPURegs) \
314 DO(allocate_mint_with_fpu_regs_stub, AllocateMintSharedWithFPURegs) \
315 DO(allocate_mint_without_fpu_regs_stub, AllocateMintSharedWithoutFPURegs) \
316 DO(stack_overflow_stub_with_fpu_regs_stub, StackOverflowSharedWithFPURegs) \
317 DO(stack_overflow_stub_without_fpu_regs_stub, \
318 StackOverflowSharedWithoutFPURegs) \
319 DO(allocate_array_stub, AllocateArray) \
320 DO(allocate_mint_stub, AllocateMint) \
321 DO(allocate_double_stub, AllocateDouble) \
322 DO(allocate_float32x4_stub, AllocateFloat32x4) \
323 DO(allocate_float64x2_stub, AllocateFloat64x2) \
324 DO(allocate_int32x4_stub, AllocateInt32x4) \
325 DO(allocate_int8_array_stub, AllocateInt8Array) \
326 DO(allocate_uint8_array_stub, AllocateUint8Array) \
327 DO(allocate_uint8_clamped_array_stub, AllocateUint8ClampedArray) \
328 DO(allocate_int16_array_stub, AllocateInt16Array) \
329 DO(allocate_uint16_array_stub, AllocateUint16Array) \
330 DO(allocate_int32_array_stub, AllocateInt32Array) \
331 DO(allocate_uint32_array_stub, AllocateUint32Array) \
332 DO(allocate_int64_array_stub, AllocateInt64Array) \
333 DO(allocate_uint64_array_stub, AllocateUint64Array) \
334 DO(allocate_float32_array_stub, AllocateFloat32Array) \
335 DO(allocate_float64_array_stub, AllocateFloat64Array) \
336 DO(allocate_float32x4_array_stub, AllocateFloat32x4Array) \
337 DO(allocate_int32x4_array_stub, AllocateInt32x4Array) \
338 DO(allocate_float64x2_array_stub, AllocateFloat64x2Array) \
339 DO(allocate_closure_stub, AllocateClosure) \
340 DO(allocate_closure_generic_stub, AllocateClosureGeneric) \
341 DO(allocate_closure_ta_stub, AllocateClosureTA) \
342 DO(allocate_closure_ta_generic_stub, AllocateClosureTAGeneric) \
343 DO(allocate_context_stub, AllocateContext) \
344 DO(allocate_growable_array_stub, AllocateGrowableArray) \
345 DO(allocate_object_stub, AllocateObject) \
346 DO(allocate_object_parametrized_stub, AllocateObjectParameterized) \
347 DO(allocate_record_stub, AllocateRecord) \
348 DO(allocate_record2_stub, AllocateRecord2) \
349 DO(allocate_record2_named_stub, AllocateRecord2Named) \
350 DO(allocate_record3_stub, AllocateRecord3) \
351 DO(allocate_record3_named_stub, AllocateRecord3Named) \
352 DO(allocate_unhandled_exception_stub, AllocateUnhandledException) \
353 DO(clone_context_stub, CloneContext) \
354 DO(call_closure_no_such_method_stub, CallClosureNoSuchMethod) \
355 DO(default_tts_stub, DefaultTypeTest) \
356 DO(default_nullable_tts_stub, DefaultNullableTypeTest) \
357 DO(top_type_tts_stub, TopTypeTypeTest) \
358 DO(nullable_type_parameter_tts_stub, NullableTypeParameterTypeTest) \
359 DO(type_parameter_tts_stub, TypeParameterTypeTest) \
360 DO(unreachable_tts_stub, UnreachableTypeTest) \
361 DO(slow_tts_stub, SlowTypeTest) \
362 DO(write_barrier_wrappers_stub, WriteBarrierWrappers) \
363 DO(array_write_barrier_stub, ArrayWriteBarrier) \
364 DO(throw_stub, Throw) \
365 DO(re_throw_stub, ReThrow) \
366 DO(assert_boolean_stub, AssertBoolean) \
367 DO(init_static_field_stub, InitStaticField) \
368 DO(init_late_static_field_stub, InitLateStaticField) \
369 DO(init_late_final_static_field_stub, InitLateFinalStaticField) \
370 DO(init_instance_field_stub, InitInstanceField) \
371 DO(init_late_instance_field_stub, InitLateInstanceField) \
372 DO(init_late_final_instance_field_stub, InitLateFinalInstanceField) \
373 DO(init_shared_late_static_field_stub, InitSharedLateStaticField) \
374 DO(init_shared_late_final_static_field_stub, InitSharedLateFinalStaticField) \
375 DO(await_stub, Await) \
376 DO(await_with_type_check_stub, AwaitWithTypeCheck) \
377 DO(clone_suspend_state_stub, CloneSuspendState) \
378 DO(ffi_async_callback_send_stub, FfiAsyncCallbackSend) \
379 DO(init_async_stub, InitAsync) \
380 DO(resume_stub, Resume) \
381 DO(return_async_stub, ReturnAsync) \
382 DO(return_async_not_future_stub, ReturnAsyncNotFuture) \
383 DO(init_async_star_stub, InitAsyncStar) \
384 DO(yield_async_star_stub, YieldAsyncStar) \
385 DO(return_async_star_stub, ReturnAsyncStar) \
386 DO(init_sync_star_stub, InitSyncStar) \
387 DO(suspend_sync_star_at_start_stub, SuspendSyncStarAtStart) \
388 DO(suspend_sync_star_at_yield_stub, SuspendSyncStarAtYield) \
389 DO(instance_of_stub, InstanceOf)
390
391#define ISOLATE_OBJECT_STORE_FIELD_LIST(R_, RW) \
392 RW(UnhandledException, preallocated_unhandled_exception) \
393 RW(StackTrace, preallocated_stack_trace) \
394 RW(UnwindError, preallocated_unwind_error) \
395 R_(Array, dart_args_1) \
396 R_(Array, dart_args_2) \
397 R_(GrowableObjectArray, resume_capabilities) \
398 R_(GrowableObjectArray, exit_listeners) \
399 R_(GrowableObjectArray, error_listeners)
400// Please remember the last entry must be referred in the 'to' function below.
401
403 public:
406
407#define DECLARE_GETTER(Type, name) \
408 Type##Ptr name() const { return name##_; } \
409 static intptr_t name##_offset() { \
410 return OFFSET_OF(IsolateObjectStore, name##_); \
411 }
412
413#define DECLARE_GETTER_AND_SETTER(Type, name) \
414 DECLARE_GETTER(Type, name) \
415 void set_##name(const Type& value) { name##_ = value.ptr(); }
416 ISOLATE_OBJECT_STORE_FIELD_LIST(DECLARE_GETTER, DECLARE_GETTER_AND_SETTER)
417#undef DECLARE_GETTER
418#undef DECLARE_GETTER_AND_SETTER
419
420 // Visit all object pointers.
422
423 // Called to initialize objects required by the vm but which invoke
424 // dart code. If an error occurs the error object is returned otherwise
425 // a null object is returned.
426 ErrorPtr PreallocateObjects(const Object& out_of_memory);
427
428 void Init();
429 void PostLoad();
430
431#ifndef PRODUCT
432 void PrintToJSONObject(JSONObject* jsobj);
433#endif
434
435 private:
436 // Finds a core library private method in Object.
437 FunctionPtr PrivateObjectLookup(const String& name);
438
439 ObjectPtr* from() {
440 return reinterpret_cast<ObjectPtr*>(&preallocated_unhandled_exception_);
441 }
442#define DECLARE_OBJECT_STORE_FIELD(type, name) type##Ptr name##_;
443 ISOLATE_OBJECT_STORE_FIELD_LIST(DECLARE_OBJECT_STORE_FIELD,
445#undef DECLARE_OBJECT_STORE_FIELD
446 ObjectPtr* to() { return reinterpret_cast<ObjectPtr*>(&error_listeners_); }
447
448 friend class Serializer;
449 friend class Deserializer;
450
452};
453
454// The object store is a per isolate group instance which stores references to
455// objects used by the VM shared by all isolates in a group.
457 public:
459#define MAKE_ID(Name, _) k##Name,
460
462#undef MAKE_ID
463 };
464
465 ObjectStore();
466 ~ObjectStore();
467
468#define DECLARE_OFFSET(name) \
469 static intptr_t name##_offset() { return OFFSET_OF(ObjectStore, name##_); }
470#define DECLARE_GETTER(Type, name) \
471 Type##Ptr name() const { return name##_; } \
472 DECLARE_OFFSET(name)
473#define DECLARE_GETTER_AND_SETTER(Type, name) \
474 DECLARE_GETTER(Type, name) \
475 void set_##name(const Type& value) { name##_ = value.ptr(); }
476#define DECLARE_RELAXED_ATOMIC_GETTER_AND_SETTER(Type, name) \
477 template <std::memory_order order = std::memory_order_relaxed> \
478 Type##Ptr name() const { \
479 return name##_.load(order); \
480 } \
481 template <std::memory_order order = std::memory_order_relaxed> \
482 void set_##name(const Type& value) { \
483 name##_.store(value.ptr(), order); \
484 } \
485 DECLARE_OFFSET(name)
486#define DECLARE_ACQREL_ATOMIC_GETTER_AND_SETTER(Type, name) \
487 Type##Ptr name() const { return name##_.load(); } \
488 void set_##name(const Type& value) { name##_.store(value.ptr()); } \
489 DECLARE_OFFSET(name)
490#define DECLARE_LAZY_INIT_GETTER(Type, name, init) \
491 Type##Ptr name() { \
492 if (name##_.load() == Type::null()) { \
493 init(); \
494 } \
495 return name##_.load(); \
496 } \
497 DECLARE_OFFSET(name)
498#define DECLARE_LAZY_INIT_CORE_GETTER(Type, name) \
499 DECLARE_LAZY_INIT_GETTER(Type, name, LazyInitCoreMembers)
500#define DECLARE_LAZY_INIT_ASYNC_GETTER(Type, name) \
501 DECLARE_LAZY_INIT_GETTER(Type, name, LazyInitAsyncMembers)
502#define DECLARE_LAZY_INIT_ISOLATE_GETTER(Type, name) \
503 DECLARE_LAZY_INIT_GETTER(Type, name, LazyInitIsolateMembers)
504#define DECLARE_LAZY_INIT_INTERNAL_GETTER(Type, name) \
505 DECLARE_LAZY_INIT_GETTER(Type, name, LazyInitInternalMembers)
506#define DECLARE_LAZY_INIT_FFI_GETTER(Type, name) \
507 DECLARE_LAZY_INIT_GETTER(Type, name, LazyInitFfiMembers)
517#undef DECLARE_OFFSET
518#undef DECLARE_GETTER
519#undef DECLARE_GETTER_AND_SETTER
520#undef DECLARE_RELAXED_ATOMIC_GETTER_AND_SETTER
521#undef DECLARE_ACQREL_ATOMIC_GETTER_AND_SETTER
522#undef DECLARE_LAZY_INIT_GETTER
523#undef DECLARE_LAZY_INIT_CORE_GETTER
524#undef DECLARE_LAZY_INIT_ASYNC_GETTER
525#undef DECLARE_LAZY_INIT_ISOLATE_GETTER
526#undef DECLARE_LAZY_INIT_INTERNAL_GETTER
527#undef DECLARE_LAZY_INIT_TYPED_DATA_GETTER
528
529 LibraryPtr bootstrap_library(BootstrapLibraryId index) {
530 switch (index) {
531#define MAKE_CASE(CamelName, name) \
532 case k##CamelName: \
533 return name##_library_;
534
536#undef MAKE_CASE
537
538 default:
539 UNREACHABLE();
540 return Library::null();
541 }
542 }
543
545 switch (index) {
546#define MAKE_CASE(CamelName, name) \
547 case k##CamelName: \
548 name##_library_ = value.ptr(); \
549 break;
550
552#undef MAKE_CASE
553 default:
554 UNREACHABLE();
555 }
556 }
557
558 // Visit all object pointers.
560
561 // Called to initialize objects required by the vm but which invoke
562 // dart code. If an error occurs the error object is returned otherwise
563 // a null object is returned.
564 ErrorPtr PreallocateObjects();
565
566 void InitKnownObjects();
567
568 void InitStubs();
569
570#ifndef PRODUCT
571 void PrintToJSONObject(JSONObject* jsobj);
572#endif
573
574 private:
575 void LazyInitCoreMembers();
576 void LazyInitAsyncMembers();
577 void LazyInitFfiMembers();
578 void LazyInitIsolateMembers();
579 void LazyInitInternalMembers();
580
581 // Finds a core library private method in Object.
582 FunctionPtr PrivateObjectLookup(const String& name);
583
584 ObjectPtr* from() { return reinterpret_cast<ObjectPtr*>(&list_class_); }
585#define DECLARE_OBJECT_STORE_FIELD(type, name) type##Ptr name##_;
586#define DECLARE_ATOMIC_OBJECT_STORE_FIELD(type, name) \
587 std::atomic<type##Ptr> name##_;
588#define DECLARE_LAZY_OBJECT_STORE_FIELD(type, name) \
589 AcqRelAtomic<type##Ptr> name##_;
599#undef DECLARE_OBJECT_STORE_FIELD
600#undef DECLARE_ATOMIC_OBJECT_STORE_FIELD
601#undef DECLARE_LAZY_OBJECT_STORE_FIELD
602 ObjectPtr* to() {
603 return reinterpret_cast<ObjectPtr*>(&ffi_native_type_class_);
604 }
605 ObjectPtr* to_snapshot(Snapshot::Kind kind) {
606 switch (kind) {
607 case Snapshot::kFull:
609 return reinterpret_cast<ObjectPtr*>(&global_object_pool_);
612 return reinterpret_cast<ObjectPtr*>(&slow_tts_stub_);
613 case Snapshot::kNone:
615 break;
616 }
617 UNREACHABLE();
618 return nullptr;
619 }
620 uword unused_field_;
621
624 friend class ProgramVisitor;
625
627};
628
629} // namespace dart
630
631#endif // RUNTIME_VM_OBJECT_STORE_H_
#define UNREACHABLE()
Definition: assert.h:248
void PrintToJSONObject(JSONObject *jsobj)
Definition: object_store.cc:33
ErrorPtr PreallocateObjects(const Object &out_of_memory)
Definition: object_store.cc:72
void VisitObjectPointers(ObjectPointerVisitor *visitor)
Definition: object_store.cc:19
ErrorPtr PreallocateObjects()
void VisitObjectPointers(ObjectPointerVisitor *visitor)
void PrintToJSONObject(JSONObject *jsobj)
void set_bootstrap_library(BootstrapLibraryId index, const Library &value)
Definition: object_store.h:544
OBJECT_STORE_FIELD_LIST(DECLARE_GETTER, DECLARE_GETTER_AND_SETTER, DECLARE_RELAXED_ATOMIC_GETTER_AND_SETTER, DECLARE_ACQREL_ATOMIC_GETTER_AND_SETTER, DECLARE_LAZY_INIT_CORE_GETTER, DECLARE_LAZY_INIT_ASYNC_GETTER, DECLARE_LAZY_INIT_ISOLATE_GETTER, DECLARE_LAZY_INIT_INTERNAL_GETTER, DECLARE_LAZY_INIT_FFI_GETTER) LibraryPtr bootstrap_library(BootstrapLibraryId index)
Definition: object_store.h:508
static ObjectPtr null()
Definition: object.h:433
uint8_t value
Definition: dart_vm.cc:33
const char *const name
uintptr_t uword
Definition: globals.h:501
#define DECLARE_GETTER(Type, name)
Definition: object_store.h:470
#define MAKE_ID(Name, _)
Definition: object_store.h:459
#define DECLARE_ATOMIC_OBJECT_STORE_FIELD(type, name)
Definition: object_store.h:586
#define DECLARE_LAZY_INIT_CORE_GETTER(Type, name)
Definition: object_store.h:498
#define FOR_EACH_BOOTSTRAP_LIBRARY(M)
Definition: object_store.h:19
#define DECLARE_GETTER_AND_SETTER(Type, name)
Definition: object_store.h:473
#define DECLARE_LAZY_INIT_ISOLATE_GETTER(Type, name)
Definition: object_store.h:502
#define DECLARE_OBJECT_STORE_FIELD(type, name)
Definition: object_store.h:585
#define DECLARE_RELAXED_ATOMIC_GETTER_AND_SETTER(Type, name)
Definition: object_store.h:476
#define DECLARE_LAZY_INIT_ASYNC_GETTER(Type, name)
Definition: object_store.h:500
#define DECLARE_ACQREL_ATOMIC_GETTER_AND_SETTER(Type, name)
Definition: object_store.h:486
#define DECLARE_LAZY_INIT_INTERNAL_GETTER(Type, name)
Definition: object_store.h:504
#define DECLARE_LAZY_INIT_FFI_GETTER(Type, name)
Definition: object_store.h:506
#define MAKE_CASE(CamelName, name)
#define DECLARE_LAZY_OBJECT_STORE_FIELD(type, name)
Definition: object_store.h:588
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition: globals.h:581