| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/object_store.h" | 5 #include "vm/object_store.h" |
| 6 | 6 |
| 7 #include "vm/exceptions.h" | 7 #include "vm/exceptions.h" |
| 8 #include "vm/dart_entry.h" | 8 #include "vm/dart_entry.h" |
| 9 #include "vm/isolate.h" | 9 #include "vm/isolate.h" |
| 10 #include "vm/object.h" | 10 #include "vm/object.h" |
| 11 #include "vm/raw_object.h" | 11 #include "vm/raw_object.h" |
| 12 #include "vm/symbols.h" | 12 #include "vm/symbols.h" |
| 13 #include "vm/visitor.h" | 13 #include "vm/visitor.h" |
| 14 | 14 |
| 15 namespace dart { | 15 namespace dart { |
| 16 | 16 |
| 17 ObjectStore::ObjectStore() | 17 ObjectStore::ObjectStore() |
| 18 : object_class_(Class::null()), | 18 : object_class_(Class::null()), |
| 19 object_type_(Type::null()), | 19 object_type_(Type::null()), |
| 20 null_class_(Class::null()), | 20 null_class_(Class::null()), |
| 21 null_type_(Type::null()), | 21 null_type_(Type::null()), |
| 22 function_type_(Type::null()), | 22 function_type_(Type::null()), |
| 23 closure_class_(Class::null()), | 23 closure_class_(Class::null()), |
| 24 number_type_(Type::null()), | 24 number_type_(Type::null()), |
| 25 int_type_(Type::null()), | 25 int_type_(Type::null()), |
| 26 integer_implementation_class_(Class::null()), | 26 integer_implementation_class_(Class::null()), |
| 27 smi_class_(Class::null()), | 27 smi_class_(Class::null()), |
| 28 smi_type_(Type::null()), | 28 smi_type_(Type::null()), |
| 29 mint_class_(Class::null()), | 29 mint_class_(Class::null()), |
| 30 mint_type_(Type::null()), | 30 mint_type_(Type::null()), |
| 31 bigint_class_(Class::null()), | 31 bigint_class_(Class::null()), |
| 32 double_class_(Class::null()), | 32 double_class_(Class::null()), |
| 33 double_type_(Type::null()), | 33 double_type_(Type::null()), |
| 34 float32x4_type_(Type::null()), | 34 float32x4_type_(Type::null()), |
| 35 int32x4_type_(Type::null()), | 35 int32x4_type_(Type::null()), |
| 36 float64x2_type_(Type::null()), | 36 float64x2_type_(Type::null()), |
| 37 string_type_(Type::null()), | 37 string_type_(Type::null()), |
| 38 compiletime_error_class_(Class::null()), | 38 compiletime_error_class_(Class::null()), |
| 39 future_class_(Class::null()), | 39 future_class_(Class::null()), |
| 40 completer_class_(Class::null()), | 40 completer_class_(Class::null()), |
| 41 stream_iterator_class_(Class::null()), | 41 stream_iterator_class_(Class::null()), |
| 42 symbol_class_(Class::null()), | 42 symbol_class_(Class::null()), |
| 43 one_byte_string_class_(Class::null()), | 43 one_byte_string_class_(Class::null()), |
| 44 two_byte_string_class_(Class::null()), | 44 two_byte_string_class_(Class::null()), |
| 45 external_one_byte_string_class_(Class::null()), | 45 external_one_byte_string_class_(Class::null()), |
| 46 external_two_byte_string_class_(Class::null()), | 46 external_two_byte_string_class_(Class::null()), |
| 47 bool_type_(Type::null()), | 47 bool_type_(Type::null()), |
| 48 bool_class_(Class::null()), | 48 bool_class_(Class::null()), |
| 49 array_class_(Class::null()), | 49 array_class_(Class::null()), |
| 50 array_type_(Type::null()), | 50 array_type_(Type::null()), |
| 51 immutable_array_class_(Class::null()), | 51 immutable_array_class_(Class::null()), |
| 52 growable_object_array_class_(Class::null()), | 52 growable_object_array_class_(Class::null()), |
| 53 linked_hash_map_class_(Class::null()), | 53 linked_hash_map_class_(Class::null()), |
| 54 float32x4_class_(Class::null()), | 54 float32x4_class_(Class::null()), |
| 55 int32x4_class_(Class::null()), | 55 int32x4_class_(Class::null()), |
| 56 float64x2_class_(Class::null()), | 56 float64x2_class_(Class::null()), |
| 57 error_class_(Class::null()), | 57 error_class_(Class::null()), |
| 58 weak_property_class_(Class::null()), | 58 weak_property_class_(Class::null()), |
| 59 symbol_table_(Array::null()), | 59 symbol_table_(Array::null()), |
| 60 canonical_types_(Array::null()), | 60 canonical_types_(Array::null()), |
| 61 canonical_type_arguments_(Array::null()), | 61 canonical_type_arguments_(Array::null()), |
| 62 async_library_(Library::null()), | 62 async_library_(Library::null()), |
| 63 builtin_library_(Library::null()), | 63 builtin_library_(Library::null()), |
| 64 core_library_(Library::null()), | 64 core_library_(Library::null()), |
| 65 collection_library_(Library::null()), | 65 collection_library_(Library::null()), |
| 66 convert_library_(Library::null()), | 66 convert_library_(Library::null()), |
| 67 developer_library_(Library::null()), | 67 developer_library_(Library::null()), |
| 68 internal_library_(Library::null()), | 68 internal_library_(Library::null()), |
| 69 isolate_library_(Library::null()), | 69 isolate_library_(Library::null()), |
| 70 math_library_(Library::null()), | 70 math_library_(Library::null()), |
| 71 mirrors_library_(Library::null()), | 71 mirrors_library_(Library::null()), |
| 72 native_wrappers_library_(Library::null()), | 72 native_wrappers_library_(Library::null()), |
| 73 profiler_library_(Library::null()), | 73 profiler_library_(Library::null()), |
| 74 root_library_(Library::null()), | 74 root_library_(Library::null()), |
| 75 typed_data_library_(Library::null()), | 75 typed_data_library_(Library::null()), |
| 76 vmservice_library_(Library::null()), | 76 vmservice_library_(Library::null()), |
| 77 libraries_(GrowableObjectArray::null()), | 77 libraries_(GrowableObjectArray::null()), |
| 78 libraries_map_(Array::null()), | 78 libraries_map_(Array::null()), |
| 79 closure_functions_(GrowableObjectArray::null()), | 79 closure_functions_(GrowableObjectArray::null()), |
| 80 pending_classes_(GrowableObjectArray::null()), | 80 pending_classes_(GrowableObjectArray::null()), |
| 81 pending_deferred_loads_(GrowableObjectArray::null()), | 81 pending_deferred_loads_(GrowableObjectArray::null()), |
| 82 resume_capabilities_(GrowableObjectArray::null()), | 82 resume_capabilities_(GrowableObjectArray::null()), |
| 83 exit_listeners_(GrowableObjectArray::null()), | 83 exit_listeners_(GrowableObjectArray::null()), |
| 84 error_listeners_(GrowableObjectArray::null()), | 84 error_listeners_(GrowableObjectArray::null()), |
| 85 empty_context_(Context::null()), | 85 empty_context_(Context::null()), |
| 86 stack_overflow_(Instance::null()), | 86 stack_overflow_(Instance::null()), |
| 87 out_of_memory_(Instance::null()), | 87 out_of_memory_(Instance::null()), |
| 88 preallocated_unhandled_exception_(UnhandledException::null()), | 88 preallocated_unhandled_exception_(UnhandledException::null()), |
| 89 preallocated_stack_trace_(Stacktrace::null()), | 89 preallocated_stack_trace_(Stacktrace::null()), |
| 90 lookup_port_handler_(Function::null()), | 90 lookup_port_handler_(Function::null()), |
| 91 empty_uint32_array_(TypedData::null()), | 91 empty_uint32_array_(TypedData::null()), |
| 92 handle_message_function_(Function::null()), | 92 handle_message_function_(Function::null()), |
| 93 simple_instance_of_function_(Function::null()), | 93 simple_instance_of_function_(Function::null()), |
| 94 simple_instance_of_true_function_(Function::null()), | 94 simple_instance_of_true_function_(Function::null()), |
| 95 simple_instance_of_false_function_(Function::null()), | 95 simple_instance_of_false_function_(Function::null()), |
| 96 library_load_error_table_(Array::null()), | 96 library_load_error_table_(Array::null()), |
| 97 unique_dynamic_targets_(Array::null()), | 97 unique_dynamic_targets_(Array::null()), |
| 98 token_objects_(GrowableObjectArray::null()), | 98 token_objects_(GrowableObjectArray::null()), |
| 99 token_objects_map_(Array::null()), | 99 token_objects_map_(Array::null()), |
| 100 megamorphic_cache_table_(GrowableObjectArray::null()), | 100 megamorphic_cache_table_(GrowableObjectArray::null()), |
| 101 megamorphic_miss_code_(Code::null()), | 101 megamorphic_miss_code_(Code::null()), |
| 102 megamorphic_miss_function_(Function::null()) { | 102 megamorphic_miss_function_(Function::null()) { |
| 103 for (RawObject** current = from(); current <= to(); current++) { | 103 for (RawObject** current = from(); current <= to(); current++) { |
| 104 ASSERT(*current == Object::null()); | 104 ASSERT(*current == Object::null()); |
| 105 } | 105 } |
| 106 } | 106 } |
| 107 | 107 |
| 108 | 108 |
| 109 ObjectStore::~ObjectStore() { | 109 ObjectStore::~ObjectStore() {} |
| 110 } | |
| 111 | 110 |
| 112 | 111 |
| 113 void ObjectStore::VisitObjectPointers(ObjectPointerVisitor* visitor) { | 112 void ObjectStore::VisitObjectPointers(ObjectPointerVisitor* visitor) { |
| 114 ASSERT(visitor != NULL); | 113 ASSERT(visitor != NULL); |
| 115 visitor->VisitPointers(from(), to()); | 114 visitor->VisitPointers(from(), to()); |
| 116 } | 115 } |
| 117 | 116 |
| 118 | 117 |
| 119 void ObjectStore::Init(Isolate* isolate) { | 118 void ObjectStore::Init(Isolate* isolate) { |
| 120 ASSERT(isolate->object_store() == NULL); | 119 ASSERT(isolate->object_store() == NULL); |
| 121 ObjectStore* store = new ObjectStore(); | 120 ObjectStore* store = new ObjectStore(); |
| 122 isolate->set_object_store(store); | 121 isolate->set_object_store(store); |
| 123 } | 122 } |
| 124 | 123 |
| 125 | 124 |
| 126 #ifndef PRODUCT | 125 #ifndef PRODUCT |
| 127 void ObjectStore::PrintToJSONObject(JSONObject* jsobj) { | 126 void ObjectStore::PrintToJSONObject(JSONObject* jsobj) { |
| 128 if (!FLAG_support_service) { | 127 if (!FLAG_support_service) { |
| 129 return; | 128 return; |
| 130 } | 129 } |
| 131 jsobj->AddProperty("type", "_ObjectStore"); | 130 jsobj->AddProperty("type", "_ObjectStore"); |
| 132 | 131 |
| 133 { | 132 { |
| 134 JSONObject fields(jsobj, "fields"); | 133 JSONObject fields(jsobj, "fields"); |
| 135 Object& value = Object::Handle(); | 134 Object& value = Object::Handle(); |
| 136 #define PRINT_OBJECT_STORE_FIELD(type, name) \ | 135 #define PRINT_OBJECT_STORE_FIELD(type, name) \ |
| 137 value = name; \ | 136 value = name; \ |
| 138 fields.AddProperty(#name, value); | 137 fields.AddProperty(#name, value); |
| 139 OBJECT_STORE_FIELD_LIST(PRINT_OBJECT_STORE_FIELD); | 138 OBJECT_STORE_FIELD_LIST(PRINT_OBJECT_STORE_FIELD); |
| 140 #undef PRINT_OBJECT_STORE_FIELD | 139 #undef PRINT_OBJECT_STORE_FIELD |
| 141 } | 140 } |
| 142 } | 141 } |
| 143 #endif // !PRODUCT | 142 #endif // !PRODUCT |
| 144 | 143 |
| 145 | 144 |
| 146 RawError* ObjectStore::PreallocateObjects() { | 145 RawError* ObjectStore::PreallocateObjects() { |
| 147 Thread* thread = Thread::Current(); | 146 Thread* thread = Thread::Current(); |
| 148 Isolate* isolate = thread->isolate(); | 147 Isolate* isolate = thread->isolate(); |
| 149 Zone* zone = thread->zone(); | 148 Zone* zone = thread->zone(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 160 this->pending_deferred_loads_ = GrowableObjectArray::New(); | 159 this->pending_deferred_loads_ = GrowableObjectArray::New(); |
| 161 | 160 |
| 162 this->closure_functions_ = GrowableObjectArray::New(); | 161 this->closure_functions_ = GrowableObjectArray::New(); |
| 163 this->resume_capabilities_ = GrowableObjectArray::New(); | 162 this->resume_capabilities_ = GrowableObjectArray::New(); |
| 164 this->exit_listeners_ = GrowableObjectArray::New(); | 163 this->exit_listeners_ = GrowableObjectArray::New(); |
| 165 this->error_listeners_ = GrowableObjectArray::New(); | 164 this->error_listeners_ = GrowableObjectArray::New(); |
| 166 | 165 |
| 167 Object& result = Object::Handle(); | 166 Object& result = Object::Handle(); |
| 168 const Library& library = Library::Handle(Library::CoreLibrary()); | 167 const Library& library = Library::Handle(Library::CoreLibrary()); |
| 169 | 168 |
| 170 result = DartLibraryCalls::InstanceCreate(library, | 169 result = |
| 171 Symbols::StackOverflowError(), | 170 DartLibraryCalls::InstanceCreate(library, Symbols::StackOverflowError(), |
| 172 Symbols::Dot(), | 171 Symbols::Dot(), Object::empty_array()); |
| 173 Object::empty_array()); | |
| 174 if (result.IsError()) { | 172 if (result.IsError()) { |
| 175 return Error::Cast(result).raw(); | 173 return Error::Cast(result).raw(); |
| 176 } | 174 } |
| 177 set_stack_overflow(Instance::Cast(result)); | 175 set_stack_overflow(Instance::Cast(result)); |
| 178 | 176 |
| 179 result = DartLibraryCalls::InstanceCreate(library, | 177 result = |
| 180 Symbols::OutOfMemoryError(), | 178 DartLibraryCalls::InstanceCreate(library, Symbols::OutOfMemoryError(), |
| 181 Symbols::Dot(), | 179 Symbols::Dot(), Object::empty_array()); |
| 182 Object::empty_array()); | |
| 183 if (result.IsError()) { | 180 if (result.IsError()) { |
| 184 return Error::Cast(result).raw(); | 181 return Error::Cast(result).raw(); |
| 185 } | 182 } |
| 186 set_out_of_memory(Instance::Cast(result)); | 183 set_out_of_memory(Instance::Cast(result)); |
| 187 | 184 |
| 188 // Allocate pre-allocated unhandled exception object initialized with the | 185 // Allocate pre-allocated unhandled exception object initialized with the |
| 189 // pre-allocated OutOfMemoryError. | 186 // pre-allocated OutOfMemoryError. |
| 190 const UnhandledException& unhandled_exception = UnhandledException::Handle( | 187 const UnhandledException& unhandled_exception = |
| 191 UnhandledException::New(Instance::Cast(result), | 188 UnhandledException::Handle(UnhandledException::New( |
| 192 Stacktrace::Handle(zone))); | 189 Instance::Cast(result), Stacktrace::Handle(zone))); |
| 193 set_preallocated_unhandled_exception(unhandled_exception); | 190 set_preallocated_unhandled_exception(unhandled_exception); |
| 194 | 191 |
| 195 const Array& code_array = Array::Handle(zone, | 192 const Array& code_array = Array::Handle( |
| 196 Array::New(Stacktrace::kPreallocatedStackdepth, Heap::kOld)); | 193 zone, Array::New(Stacktrace::kPreallocatedStackdepth, Heap::kOld)); |
| 197 const Array& pc_offset_array = Array::Handle(zone, | 194 const Array& pc_offset_array = Array::Handle( |
| 198 Array::New(Stacktrace::kPreallocatedStackdepth, Heap::kOld)); | 195 zone, Array::New(Stacktrace::kPreallocatedStackdepth, Heap::kOld)); |
| 199 const Stacktrace& stack_trace = Stacktrace::Handle(zone, | 196 const Stacktrace& stack_trace = |
| 200 Stacktrace::New(code_array, pc_offset_array)); | 197 Stacktrace::Handle(zone, Stacktrace::New(code_array, pc_offset_array)); |
| 201 // Expansion of inlined functions requires additional memory at run time, | 198 // Expansion of inlined functions requires additional memory at run time, |
| 202 // avoid it. | 199 // avoid it. |
| 203 stack_trace.set_expand_inlined(false); | 200 stack_trace.set_expand_inlined(false); |
| 204 set_preallocated_stack_trace(stack_trace); | 201 set_preallocated_stack_trace(stack_trace); |
| 205 | 202 |
| 206 return Error::null(); | 203 return Error::null(); |
| 207 } | 204 } |
| 208 | 205 |
| 209 | 206 |
| 210 RawFunction* ObjectStore::PrivateObjectLookup(const String& name) { | 207 RawFunction* ObjectStore::PrivateObjectLookup(const String& name) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 simple_instance_of_function_ = | 250 simple_instance_of_function_ = |
| 254 PrivateObjectLookup(Symbols::_simpleInstanceOf()); | 251 PrivateObjectLookup(Symbols::_simpleInstanceOf()); |
| 255 simple_instance_of_true_function_ = | 252 simple_instance_of_true_function_ = |
| 256 PrivateObjectLookup(Symbols::_simpleInstanceOfTrue()); | 253 PrivateObjectLookup(Symbols::_simpleInstanceOfTrue()); |
| 257 simple_instance_of_false_function_ = | 254 simple_instance_of_false_function_ = |
| 258 PrivateObjectLookup(Symbols::_simpleInstanceOfFalse()); | 255 PrivateObjectLookup(Symbols::_simpleInstanceOfFalse()); |
| 259 #endif | 256 #endif |
| 260 } | 257 } |
| 261 | 258 |
| 262 } // namespace dart | 259 } // namespace dart |
| OLD | NEW |