| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS 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 | 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.h" | 5 #include "vm/object.h" |
| 6 | 6 |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
| 10 #include "vm/bigint_operations.h" | 10 #include "vm/bigint_operations.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 cpp_vtable Object::builtin_vtables_[kNumPredefinedCids] = { 0 }; | 52 cpp_vtable Object::builtin_vtables_[kNumPredefinedCids] = { 0 }; |
| 53 cpp_vtable Smi::handle_vtable_ = 0; | 53 cpp_vtable Smi::handle_vtable_ = 0; |
| 54 | 54 |
| 55 // These are initialized to a value that will force a illegal memory access if | 55 // These are initialized to a value that will force a illegal memory access if |
| 56 // they are being used. | 56 // they are being used. |
| 57 #if defined(RAW_NULL) | 57 #if defined(RAW_NULL) |
| 58 #error RAW_NULL should not be defined. | 58 #error RAW_NULL should not be defined. |
| 59 #endif | 59 #endif |
| 60 #define RAW_NULL kHeapObjectTag | 60 #define RAW_NULL kHeapObjectTag |
| 61 RawObject* Object::null_ = reinterpret_cast<RawInstance*>(RAW_NULL); | 61 RawObject* Object::null_ = reinterpret_cast<RawInstance*>(RAW_NULL); |
| 62 RawArray* Object::empty_array_ = reinterpret_cast<RawArray*>(RAW_NULL); |
| 62 RawInstance* Object::sentinel_ = reinterpret_cast<RawInstance*>(RAW_NULL); | 63 RawInstance* Object::sentinel_ = reinterpret_cast<RawInstance*>(RAW_NULL); |
| 63 RawInstance* Object::transition_sentinel_ = | 64 RawInstance* Object::transition_sentinel_ = |
| 64 reinterpret_cast<RawInstance*>(RAW_NULL); | 65 reinterpret_cast<RawInstance*>(RAW_NULL); |
| 65 RawClass* Object::class_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 66 RawClass* Object::class_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
| 66 RawClass* Object::null_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 67 RawClass* Object::null_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
| 67 RawClass* Object::dynamic_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 68 RawClass* Object::dynamic_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
| 68 RawClass* Object::void_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 69 RawClass* Object::void_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
| 69 RawClass* Object::unresolved_class_class_ = | 70 RawClass* Object::unresolved_class_class_ = |
| 70 reinterpret_cast<RawClass*>(RAW_NULL); | 71 reinterpret_cast<RawClass*>(RAW_NULL); |
| 71 RawClass* Object::type_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 72 RawClass* Object::type_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 if (is_setter) { | 179 if (is_setter) { |
| 179 // Setters need to end with '='. | 180 // Setters need to end with '='. |
| 180 const String& suffix = String::Handle(Symbols::Equals()); | 181 const String& suffix = String::Handle(Symbols::Equals()); |
| 181 return String::Concat(result, suffix); | 182 return String::Concat(result, suffix); |
| 182 } | 183 } |
| 183 | 184 |
| 184 return result.raw(); | 185 return result.raw(); |
| 185 } | 186 } |
| 186 | 187 |
| 187 | 188 |
| 188 // TODO(asiva): Get rid of this function once we have predefined names for | |
| 189 // the shared classes and set that up in the name field. | |
| 190 const char* Object::GetSingletonClassName(intptr_t class_id) { | |
| 191 switch (class_id) { | |
| 192 case kClassCid: return "Class"; | |
| 193 case kNullCid: return "Null"; | |
| 194 case kDynamicCid: return "Dynamic"; | |
| 195 case kVoidCid: return "void"; | |
| 196 case kUnresolvedClassCid: return "UnresolvedClass"; | |
| 197 case kTypeCid: return "Type"; | |
| 198 case kTypeParameterCid: return "TypeParameter"; | |
| 199 case kTypeArgumentsCid: return "TypeArguments"; | |
| 200 case kInstantiatedTypeArgumentsCid: return "InstantiatedTypeArguments"; | |
| 201 case kFunctionCid: return "Function"; | |
| 202 case kFieldCid: return "Field"; | |
| 203 case kLiteralTokenCid: return "LiteralToken"; | |
| 204 case kTokenStreamCid: return "TokenStream"; | |
| 205 case kScriptCid: return "Script"; | |
| 206 case kLibraryCid: return "Library"; | |
| 207 case kLibraryPrefixCid: return "LibraryPrefix"; | |
| 208 case kCodeCid: return "Code"; | |
| 209 case kInstructionsCid: return "Instructions"; | |
| 210 case kPcDescriptorsCid: return "PcDescriptors"; | |
| 211 case kStackmapCid: return "Stackmap"; | |
| 212 case kLocalVarDescriptorsCid: return "LocalVarDescriptors"; | |
| 213 case kExceptionHandlersCid: return "ExceptionHandlers"; | |
| 214 case kContextCid: return "Context"; | |
| 215 case kContextScopeCid: return "ContextScope"; | |
| 216 case kICDataCid: return "ICData"; | |
| 217 case kSubtypeTestCacheCid: return "SubtypeTestCache"; | |
| 218 case kApiErrorCid: return "ApiError"; | |
| 219 case kLanguageErrorCid: return "LanguageError"; | |
| 220 case kUnhandledExceptionCid: return "UnhandledException"; | |
| 221 case kUnwindErrorCid: return "UnwindError"; | |
| 222 default: break; | |
| 223 } | |
| 224 UNREACHABLE(); | |
| 225 return NULL; | |
| 226 } | |
| 227 | |
| 228 | |
| 229 void Object::InitOnce() { | 189 void Object::InitOnce() { |
| 230 // TODO(iposva): NoGCScope needs to be added here. | 190 // TODO(iposva): NoGCScope needs to be added here. |
| 231 ASSERT(class_class() == null_); | 191 ASSERT(class_class() == null_); |
| 232 // Initialize the static vtable values. | 192 // Initialize the static vtable values. |
| 233 { | 193 { |
| 234 Object fake_object; | 194 Object fake_object; |
| 235 Smi fake_smi; | 195 Smi fake_smi; |
| 236 Object::handle_vtable_ = fake_object.vtable(); | 196 Object::handle_vtable_ = fake_object.vtable(); |
| 237 Smi::handle_vtable_ = fake_smi.vtable(); | 197 Smi::handle_vtable_ = fake_smi.vtable(); |
| 238 } | 198 } |
| 239 | 199 |
| 240 Isolate* isolate = Isolate::Current(); | 200 Isolate* isolate = Isolate::Current(); |
| 241 Heap* heap = isolate->heap(); | 201 Heap* heap = isolate->heap(); |
| 242 // Allocate and initialize the null instance, except its class_ field. | 202 // Allocate and initialize the null instance. |
| 243 // 'null_' must be the first object allocated as it is used in allocation to | 203 // 'null_' must be the first object allocated as it is used in allocation to |
| 244 // clear the object. | 204 // clear the object. |
| 245 { | 205 { |
| 246 uword address = heap->Allocate(Instance::InstanceSize(), Heap::kOld); | 206 uword address = heap->Allocate(Instance::InstanceSize(), Heap::kOld); |
| 247 null_ = reinterpret_cast<RawInstance*>(address + kHeapObjectTag); | 207 null_ = reinterpret_cast<RawInstance*>(address + kHeapObjectTag); |
| 248 // The call below is using 'null_' to initialize itself. | 208 // The call below is using 'null_' to initialize itself. |
| 249 InitializeObject(address, kNullCid, Instance::InstanceSize()); | 209 InitializeObject(address, kNullCid, Instance::InstanceSize()); |
| 250 } | 210 } |
| 251 | 211 |
| 252 // Initialize object_store empty array to null_ in order to be able to check | 212 // Initialize object_store empty array to null_ in order to be able to check |
| 253 // if the empty array was allocated (RAW_NULL is not available). | 213 // if the empty array was allocated (RAW_NULL is not available). |
| 254 isolate->object_store()->set_empty_array(Array::Handle()); | 214 empty_array_ = Array::null(); |
| 255 | 215 |
| 256 Class& cls = Class::Handle(); | 216 Class& cls = Class::Handle(); |
| 257 | 217 |
| 258 // Allocate and initialize the class class. | 218 // Allocate and initialize the class class. |
| 259 { | 219 { |
| 260 intptr_t size = Class::InstanceSize(); | 220 intptr_t size = Class::InstanceSize(); |
| 261 uword address = heap->Allocate(size, Heap::kOld); | 221 uword address = heap->Allocate(size, Heap::kOld); |
| 262 class_class_ = reinterpret_cast<RawClass*>(address + kHeapObjectTag); | 222 class_class_ = reinterpret_cast<RawClass*>(address + kHeapObjectTag); |
| 263 InitializeObject(address, Class::kClassId, size); | 223 InitializeObject(address, Class::kClassId, size); |
| 264 | 224 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 sentinel ^= | 256 sentinel ^= |
| 297 Object::Allocate(kNullCid, Instance::InstanceSize(), Heap::kOld); | 257 Object::Allocate(kNullCid, Instance::InstanceSize(), Heap::kOld); |
| 298 sentinel_ = sentinel.raw(); | 258 sentinel_ = sentinel.raw(); |
| 299 | 259 |
| 300 Instance& transition_sentinel = Instance::Handle(); | 260 Instance& transition_sentinel = Instance::Handle(); |
| 301 transition_sentinel ^= | 261 transition_sentinel ^= |
| 302 Object::Allocate(kNullCid, Instance::InstanceSize(), Heap::kOld); | 262 Object::Allocate(kNullCid, Instance::InstanceSize(), Heap::kOld); |
| 303 transition_sentinel_ = transition_sentinel.raw(); | 263 transition_sentinel_ = transition_sentinel.raw(); |
| 304 } | 264 } |
| 305 | 265 |
| 306 // The interface "Dynamic" is not a VM internal class. It is the type class of | |
| 307 // the "unknown type". For efficiency, we allocate it in the VM isolate. | |
| 308 // Therefore, it cannot have a heap allocated name (the name is hard coded, | |
| 309 // see GetSingletonClassName) and its array fields cannot be set to the empty | |
| 310 // array, but remain null. | |
| 311 // | |
| 312 // TODO(turnidge): Once the empty array is allocated in the vm | |
| 313 // isolate, use it here. | |
| 314 cls = Class::New<Instance>(kDynamicCid); | 266 cls = Class::New<Instance>(kDynamicCid); |
| 315 cls.set_is_finalized(); | 267 cls.set_is_finalized(); |
| 316 cls.set_is_interface(); | 268 cls.set_is_interface(); |
| 317 dynamic_class_ = cls.raw(); | 269 dynamic_class_ = cls.raw(); |
| 318 | 270 |
| 319 // Allocate the remaining VM internal classes. | 271 // Allocate the remaining VM internal classes. |
| 320 cls = Class::New<UnresolvedClass>(); | 272 cls = Class::New<UnresolvedClass>(); |
| 321 unresolved_class_class_ = cls.raw(); | 273 unresolved_class_class_ = cls.raw(); |
| 322 | 274 |
| 323 cls = Class::New<Instance>(kVoidCid); | 275 cls = Class::New<Instance>(kVoidCid); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 | 356 |
| 405 ASSERT(class_class() != null_); | 357 ASSERT(class_class() != null_); |
| 406 | 358 |
| 407 // Pre-allocate the Array and OneByteString class in the vm isolate so that | 359 // Pre-allocate the Array and OneByteString class in the vm isolate so that |
| 408 // we can create a symbol table and populate it with some frequently used | 360 // we can create a symbol table and populate it with some frequently used |
| 409 // strings as symbols. | 361 // strings as symbols. |
| 410 cls = Class::New<Array>(); | 362 cls = Class::New<Array>(); |
| 411 isolate->object_store()->set_array_class(cls); | 363 isolate->object_store()->set_array_class(cls); |
| 412 cls = Class::New<OneByteString>(); | 364 cls = Class::New<OneByteString>(); |
| 413 isolate->object_store()->set_one_byte_string_class(cls); | 365 isolate->object_store()->set_one_byte_string_class(cls); |
| 366 |
| 367 // Allocate and initialize the empty_array instance. |
| 368 { |
| 369 uword address = heap->Allocate(Array::InstanceSize(0), Heap::kOld); |
| 370 empty_array_ = reinterpret_cast<RawArray*>(address + kHeapObjectTag); |
| 371 InitializeObject(address, kArrayCid, Array::InstanceSize(0)); |
| 372 empty_array_->ptr()->length_ = Smi::New(0); |
| 373 } |
| 374 } |
| 375 |
| 376 |
| 377 #define SET_CLASS_NAME(class_name, name) \ |
| 378 cls = class_name##_class(); \ |
| 379 str = Symbols::name(); \ |
| 380 cls.set_name(str); \ |
| 381 |
| 382 void Object::RegisterSingletonClassNames() { |
| 383 Class& cls = Class::Handle(); |
| 384 String& str = String::Handle(); |
| 385 |
| 386 SET_CLASS_NAME(class, Class); |
| 387 SET_CLASS_NAME(null, Null); |
| 388 SET_CLASS_NAME(dynamic, Dynamic); |
| 389 SET_CLASS_NAME(void, Void); |
| 390 SET_CLASS_NAME(unresolved_class, UnresolvedClass); |
| 391 SET_CLASS_NAME(type, Type); |
| 392 SET_CLASS_NAME(type_parameter, TypeParameter); |
| 393 SET_CLASS_NAME(type_arguments, TypeArguments); |
| 394 SET_CLASS_NAME(instantiated_type_arguments, InstantiatedTypeArguments); |
| 395 SET_CLASS_NAME(function, Function); |
| 396 SET_CLASS_NAME(field, Field); |
| 397 SET_CLASS_NAME(literal_token, LiteralToken); |
| 398 SET_CLASS_NAME(token_stream, TokenStream); |
| 399 SET_CLASS_NAME(script, Script); |
| 400 SET_CLASS_NAME(library, LibraryClass); |
| 401 SET_CLASS_NAME(library_prefix, LibraryPrefix); |
| 402 SET_CLASS_NAME(code, Code); |
| 403 SET_CLASS_NAME(instructions, Instructions); |
| 404 SET_CLASS_NAME(pc_descriptors, PcDescriptors); |
| 405 SET_CLASS_NAME(stackmap, Stackmap); |
| 406 SET_CLASS_NAME(var_descriptors, LocalVarDescriptors); |
| 407 SET_CLASS_NAME(exception_handlers, ExceptionHandlers); |
| 408 SET_CLASS_NAME(deopt_info, DeoptInfo); |
| 409 SET_CLASS_NAME(context, Context); |
| 410 SET_CLASS_NAME(context_scope, ContextScope); |
| 411 SET_CLASS_NAME(icdata, ICData); |
| 412 SET_CLASS_NAME(subtypetestcache, SubtypeTestCache); |
| 413 SET_CLASS_NAME(api_error, ApiError); |
| 414 SET_CLASS_NAME(language_error, LanguageError); |
| 415 SET_CLASS_NAME(unhandled_exception, UnhandledException); |
| 416 SET_CLASS_NAME(unwind_error, UnwindError); |
| 414 } | 417 } |
| 415 | 418 |
| 416 | 419 |
| 417 RawClass* Object::CreateAndRegisterInterface(const char* cname, | 420 RawClass* Object::CreateAndRegisterInterface(const char* cname, |
| 418 const Script& script, | 421 const Script& script, |
| 419 const Library& lib) { | 422 const Library& lib) { |
| 420 const String& name = String::Handle(Symbols::New(cname)); | 423 const String& name = String::Handle(Symbols::New(cname)); |
| 421 const Class& cls = Class::Handle( | 424 const Class& cls = Class::Handle( |
| 422 Class::NewInterface(name, script, Scanner::kDummyTokenIndex)); | 425 Class::NewInterface(name, script, Scanner::kDummyTokenIndex)); |
| 423 lib.AddClass(cls); | 426 lib.AddClass(cls); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 // initialize array class first. | 464 // initialize array class first. |
| 462 cls = Class::New<Array>(); | 465 cls = Class::New<Array>(); |
| 463 object_store->set_array_class(cls); | 466 object_store->set_array_class(cls); |
| 464 | 467 |
| 465 // Array and ImmutableArray are the only VM classes that are parameterized. | 468 // Array and ImmutableArray are the only VM classes that are parameterized. |
| 466 // Since they are pre-finalized, CalculateFieldOffsets() is not called, so we | 469 // Since they are pre-finalized, CalculateFieldOffsets() is not called, so we |
| 467 // need to set the offset of their type_arguments_ field, which is explicitly | 470 // need to set the offset of their type_arguments_ field, which is explicitly |
| 468 // declared in RawArray. | 471 // declared in RawArray. |
| 469 cls.set_type_arguments_instance_field_offset(Array::type_arguments_offset()); | 472 cls.set_type_arguments_instance_field_offset(Array::type_arguments_offset()); |
| 470 | 473 |
| 471 Array& empty_array = Array::Handle(); | |
| 472 empty_array = Array::New(0, Heap::kOld); | |
| 473 object_store->set_empty_array(empty_array); | |
| 474 | |
| 475 // Re-initialize fields of the array class now that the empty array | |
| 476 // has been created. | |
| 477 cls.InitEmptyFields(); | |
| 478 | |
| 479 // Set up the growable object array class (Has to be done after the array | 474 // Set up the growable object array class (Has to be done after the array |
| 480 // class is setup as one of its field is an array object). | 475 // class is setup as one of its field is an array object). |
| 481 cls = Class::New<GrowableObjectArray>(); | 476 cls = Class::New<GrowableObjectArray>(); |
| 482 object_store->set_growable_object_array_class(cls); | 477 object_store->set_growable_object_array_class(cls); |
| 483 cls.set_type_arguments_instance_field_offset( | 478 cls.set_type_arguments_instance_field_offset( |
| 484 GrowableObjectArray::type_arguments_offset()); | 479 GrowableObjectArray::type_arguments_offset()); |
| 485 | 480 |
| 486 // canonical_type_arguments_ are NULL terminated. | 481 // canonical_type_arguments_ are NULL terminated. |
| 487 array = Array::New(4); | 482 array = Array::New(4); |
| 488 object_store->set_canonical_type_arguments(array); | 483 object_store->set_canonical_type_arguments(array); |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 828 ObjectStore* object_store = isolate->object_store(); | 823 ObjectStore* object_store = isolate->object_store(); |
| 829 | 824 |
| 830 Class& cls = Class::Handle(); | 825 Class& cls = Class::Handle(); |
| 831 | 826 |
| 832 // Set up empty classes in the object store, these will get | 827 // Set up empty classes in the object store, these will get |
| 833 // initialized correctly when we read from the snapshot. | 828 // initialized correctly when we read from the snapshot. |
| 834 // This is done to allow bootstrapping of reading classes from the snapshot. | 829 // This is done to allow bootstrapping of reading classes from the snapshot. |
| 835 cls = Class::New<Array>(); | 830 cls = Class::New<Array>(); |
| 836 object_store->set_array_class(cls); | 831 object_store->set_array_class(cls); |
| 837 | 832 |
| 838 Array& empty_array = Array::Handle(); | |
| 839 empty_array = Array::New(0); | |
| 840 object_store->set_empty_array(empty_array); | |
| 841 | |
| 842 cls = Class::New<ImmutableArray>(); | 833 cls = Class::New<ImmutableArray>(); |
| 843 object_store->set_immutable_array_class(cls); | 834 object_store->set_immutable_array_class(cls); |
| 844 | 835 |
| 845 cls = Class::New<GrowableObjectArray>(); | 836 cls = Class::New<GrowableObjectArray>(); |
| 846 object_store->set_growable_object_array_class(cls); | 837 object_store->set_growable_object_array_class(cls); |
| 847 | 838 |
| 848 cls = Class::New<Int8Array>(); | 839 cls = Class::New<Int8Array>(); |
| 849 object_store->set_int8_array_class(cls); | 840 object_store->set_int8_array_class(cls); |
| 850 | 841 |
| 851 cls = Class::New<Uint8Array>(); | 842 cls = Class::New<Uint8Array>(); |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1030 memmove(raw_obj->ptr(), src.raw()->ptr(), size); | 1021 memmove(raw_obj->ptr(), src.raw()->ptr(), size); |
| 1031 if (space == Heap::kOld) { | 1022 if (space == Heap::kOld) { |
| 1032 StoreBufferObjectPointerVisitor visitor(Isolate::Current()); | 1023 StoreBufferObjectPointerVisitor visitor(Isolate::Current()); |
| 1033 raw_obj->VisitPointers(&visitor); | 1024 raw_obj->VisitPointers(&visitor); |
| 1034 } | 1025 } |
| 1035 return raw_obj; | 1026 return raw_obj; |
| 1036 } | 1027 } |
| 1037 | 1028 |
| 1038 | 1029 |
| 1039 RawString* Class::Name() const { | 1030 RawString* Class::Name() const { |
| 1040 if (raw_ptr()->name_ != String::null()) { | 1031 ASSERT(raw_ptr()->name_ != String::null()); |
| 1041 return raw_ptr()->name_; | 1032 return raw_ptr()->name_; |
| 1042 } | |
| 1043 ASSERT(class_class() != Class::null()); // class_class_ should be set up. | |
| 1044 return Symbols::New(GetSingletonClassName(raw_ptr()->id_)); | |
| 1045 } | 1033 } |
| 1046 | 1034 |
| 1047 | 1035 |
| 1048 RawString* Class::UserVisibleName() const { | 1036 RawString* Class::UserVisibleName() const { |
| 1049 if (FLAG_show_internal_names) { | 1037 if (FLAG_show_internal_names) { |
| 1050 return Name(); | 1038 return Name(); |
| 1051 } | 1039 } |
| 1052 switch (id()) { | 1040 switch (id()) { |
| 1053 case kIntegerCid: | 1041 case kIntegerCid: |
| 1054 case kSmiCid: | 1042 case kSmiCid: |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1179 result.raw_ptr()->num_native_fields_ = 0; | 1167 result.raw_ptr()->num_native_fields_ = 0; |
| 1180 result.raw_ptr()->token_pos_ = Scanner::kDummyTokenIndex; | 1168 result.raw_ptr()->token_pos_ = Scanner::kDummyTokenIndex; |
| 1181 result.InitEmptyFields(); | 1169 result.InitEmptyFields(); |
| 1182 Isolate::Current()->class_table()->Register(result); | 1170 Isolate::Current()->class_table()->Register(result); |
| 1183 return result.raw(); | 1171 return result.raw(); |
| 1184 } | 1172 } |
| 1185 | 1173 |
| 1186 | 1174 |
| 1187 // Initialize class fields of type Array with empty array. | 1175 // Initialize class fields of type Array with empty array. |
| 1188 void Class::InitEmptyFields() { | 1176 void Class::InitEmptyFields() { |
| 1189 const Array& empty_array = Array::Handle(Array::Empty()); | 1177 if (Object::empty_array() == Array::null()) { |
| 1190 if (empty_array.IsNull()) { | |
| 1191 // The empty array has not been initialized yet. | 1178 // The empty array has not been initialized yet. |
| 1192 return; | 1179 return; |
| 1193 } | 1180 } |
| 1194 StorePointer(&raw_ptr()->interfaces_, empty_array.raw()); | 1181 StorePointer(&raw_ptr()->interfaces_, Object::empty_array()); |
| 1195 // TODO(srdjan): Make functions_cache growable and start with a smaller size. | 1182 StorePointer(&raw_ptr()->constants_, Object::empty_array()); |
| 1196 Array& fcache = | 1183 StorePointer(&raw_ptr()->canonical_types_, Object::empty_array()); |
| 1197 Array::Handle(Array::New(FunctionsCache::kNumEntries * 32, Heap::kOld)); | 1184 StorePointer(&raw_ptr()->functions_, Object::empty_array()); |
| 1198 StorePointer(&raw_ptr()->functions_cache_, fcache.raw()); | 1185 StorePointer(&raw_ptr()->fields_, Object::empty_array()); |
| 1199 StorePointer(&raw_ptr()->constants_, empty_array.raw()); | 1186 } |
| 1200 StorePointer(&raw_ptr()->canonical_types_, empty_array.raw()); | 1187 |
| 1201 StorePointer(&raw_ptr()->functions_, empty_array.raw()); | 1188 |
| 1202 StorePointer(&raw_ptr()->fields_, empty_array.raw()); | 1189 void Class::InitFunctionsCache() const { |
| 1190 // TODO(srdjan): Make functions_cache growable and start with smaller size. |
| 1191 StorePointer(&raw_ptr()->functions_cache_, |
| 1192 Array::New(FunctionsCache::kNumEntries * 32, Heap::kOld)); |
| 1203 } | 1193 } |
| 1204 | 1194 |
| 1205 | 1195 |
| 1206 bool Class::HasInstanceFields() const { | 1196 bool Class::HasInstanceFields() const { |
| 1207 const Array& field_array = Array::Handle(fields()); | 1197 const Array& field_array = Array::Handle(fields()); |
| 1208 Field& field = Field::Handle(); | 1198 Field& field = Field::Handle(); |
| 1209 for (intptr_t i = 0; i < field_array.Length(); ++i) { | 1199 for (intptr_t i = 0; i < field_array.Length(); ++i) { |
| 1210 field ^= field_array.At(i); | 1200 field ^= field_array.At(i); |
| 1211 if (!field.is_static()) { | 1201 if (!field.is_static()) { |
| 1212 return true; | 1202 return true; |
| (...skipping 8693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9906 Object& obj = Object::Handle(); | 9896 Object& obj = Object::Handle(); |
| 9907 for (int i = 0; i < len; i++) { | 9897 for (int i = 0; i < len; i++) { |
| 9908 obj = source.At(i); | 9898 obj = source.At(i); |
| 9909 result.SetAt(i, obj); | 9899 result.SetAt(i, obj); |
| 9910 } | 9900 } |
| 9911 return result.raw(); | 9901 return result.raw(); |
| 9912 } | 9902 } |
| 9913 | 9903 |
| 9914 | 9904 |
| 9915 RawArray* Array::Empty() { | 9905 RawArray* Array::Empty() { |
| 9916 return Isolate::Current()->object_store()->empty_array(); | 9906 return Object::empty_array(); |
| 9917 } | 9907 } |
| 9918 | 9908 |
| 9919 | 9909 |
| 9920 RawArray* Array::MakeArray(const GrowableObjectArray& growable_array) { | 9910 RawArray* Array::MakeArray(const GrowableObjectArray& growable_array) { |
| 9921 intptr_t used_len = growable_array.Length(); | 9911 intptr_t used_len = growable_array.Length(); |
| 9922 intptr_t capacity_len = growable_array.Capacity(); | 9912 intptr_t capacity_len = growable_array.Capacity(); |
| 9923 Isolate* isolate = Isolate::Current(); | 9913 Isolate* isolate = Isolate::Current(); |
| 9924 const Array& array = Array::Handle(isolate, growable_array.data()); | 9914 const Array& array = Array::Handle(isolate, growable_array.data()); |
| 9925 const Array& new_array = Array::Handle(isolate, Array::Empty()); | 9915 const Array& new_array = Array::Handle(isolate, Array::Empty()); |
| 9926 intptr_t capacity_size = Array::InstanceSize(capacity_len); | 9916 intptr_t capacity_size = Array::InstanceSize(capacity_len); |
| (...skipping 1058 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10985 const char* JSRegExp::ToCString() const { | 10975 const char* JSRegExp::ToCString() const { |
| 10986 const String& str = String::Handle(pattern()); | 10976 const String& str = String::Handle(pattern()); |
| 10987 const char* format = "JSRegExp: pattern=%s flags=%s"; | 10977 const char* format = "JSRegExp: pattern=%s flags=%s"; |
| 10988 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); | 10978 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); |
| 10989 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len + 1); | 10979 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len + 1); |
| 10990 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); | 10980 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); |
| 10991 return chars; | 10981 return chars; |
| 10992 } | 10982 } |
| 10993 | 10983 |
| 10994 } // namespace dart | 10984 } // namespace dart |
| OLD | NEW |