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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 | 57 |
58 // These are initialized to a value that will force a illegal memory access if | 58 // These are initialized to a value that will force a illegal memory access if |
59 // they are being used. | 59 // they are being used. |
60 #if defined(RAW_NULL) | 60 #if defined(RAW_NULL) |
61 #error RAW_NULL should not be defined. | 61 #error RAW_NULL should not be defined. |
62 #endif | 62 #endif |
63 #define RAW_NULL kHeapObjectTag | 63 #define RAW_NULL kHeapObjectTag |
64 Array* Object::empty_array_ = NULL; | 64 Array* Object::empty_array_ = NULL; |
65 Instance* Object::sentinel_ = NULL; | 65 Instance* Object::sentinel_ = NULL; |
66 Instance* Object::transition_sentinel_ = NULL; | 66 Instance* Object::transition_sentinel_ = NULL; |
| 67 Bool* Object::bool_true_ = NULL; |
| 68 Bool* Object::bool_false_ = NULL; |
67 | 69 |
68 RawObject* Object::null_ = reinterpret_cast<RawObject*>(RAW_NULL); | 70 RawObject* Object::null_ = reinterpret_cast<RawObject*>(RAW_NULL); |
69 RawClass* Object::class_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 71 RawClass* Object::class_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
70 RawClass* Object::null_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 72 RawClass* Object::null_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
71 RawClass* Object::dynamic_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 73 RawClass* Object::dynamic_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
72 RawClass* Object::void_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 74 RawClass* Object::void_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
73 RawClass* Object::unresolved_class_class_ = | 75 RawClass* Object::unresolved_class_class_ = |
74 reinterpret_cast<RawClass*>(RAW_NULL); | 76 reinterpret_cast<RawClass*>(RAW_NULL); |
75 RawClass* Object::type_arguments_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 77 RawClass* Object::type_arguments_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
76 RawClass* Object::instantiated_type_arguments_class_ = | 78 RawClass* Object::instantiated_type_arguments_class_ = |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 Smi fake_smi; | 241 Smi fake_smi; |
240 Object::handle_vtable_ = fake_object.vtable(); | 242 Object::handle_vtable_ = fake_object.vtable(); |
241 Smi::handle_vtable_ = fake_smi.vtable(); | 243 Smi::handle_vtable_ = fake_smi.vtable(); |
242 } | 244 } |
243 | 245 |
244 // Allocate the read only object handles here. | 246 // Allocate the read only object handles here. |
245 empty_array_ = reinterpret_cast<Array*>(Dart::AllocateReadOnlyHandle()); | 247 empty_array_ = reinterpret_cast<Array*>(Dart::AllocateReadOnlyHandle()); |
246 sentinel_ = reinterpret_cast<Instance*>(Dart::AllocateReadOnlyHandle()); | 248 sentinel_ = reinterpret_cast<Instance*>(Dart::AllocateReadOnlyHandle()); |
247 transition_sentinel_ = | 249 transition_sentinel_ = |
248 reinterpret_cast<Instance*>(Dart::AllocateReadOnlyHandle()); | 250 reinterpret_cast<Instance*>(Dart::AllocateReadOnlyHandle()); |
| 251 bool_true_ = reinterpret_cast<Bool*>(Dart::AllocateReadOnlyHandle()); |
| 252 bool_false_ = reinterpret_cast<Bool*>(Dart::AllocateReadOnlyHandle()); |
249 | 253 |
250 Isolate* isolate = Isolate::Current(); | 254 Isolate* isolate = Isolate::Current(); |
251 Heap* heap = isolate->heap(); | 255 Heap* heap = isolate->heap(); |
252 // Allocate and initialize the null instance. | 256 // Allocate and initialize the null instance. |
253 // 'null_' must be the first object allocated as it is used in allocation to | 257 // 'null_' must be the first object allocated as it is used in allocation to |
254 // clear the object. | 258 // clear the object. |
255 { | 259 { |
256 uword address = heap->Allocate(Instance::InstanceSize(), Heap::kOld); | 260 uword address = heap->Allocate(Instance::InstanceSize(), Heap::kOld); |
257 null_ = reinterpret_cast<RawInstance*>(address + kHeapObjectTag); | 261 null_ = reinterpret_cast<RawInstance*>(address + kHeapObjectTag); |
258 // The call below is using 'null_' to initialize itself. | 262 // The call below is using 'null_' to initialize itself. |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 cls = Class::NewStringClass(kTwoByteStringCid); | 424 cls = Class::NewStringClass(kTwoByteStringCid); |
421 isolate->object_store()->set_two_byte_string_class(cls); | 425 isolate->object_store()->set_two_byte_string_class(cls); |
422 | 426 |
423 // Allocate and initialize the empty_array instance. | 427 // Allocate and initialize the empty_array instance. |
424 { | 428 { |
425 uword address = heap->Allocate(Array::InstanceSize(0), Heap::kOld); | 429 uword address = heap->Allocate(Array::InstanceSize(0), Heap::kOld); |
426 *empty_array_ = reinterpret_cast<RawArray*>(address + kHeapObjectTag); | 430 *empty_array_ = reinterpret_cast<RawArray*>(address + kHeapObjectTag); |
427 InitializeObject(address, kArrayCid, Array::InstanceSize(0)); | 431 InitializeObject(address, kArrayCid, Array::InstanceSize(0)); |
428 empty_array_->raw()->ptr()->length_ = Smi::New(0); | 432 empty_array_->raw()->ptr()->length_ = Smi::New(0); |
429 } | 433 } |
| 434 |
| 435 // Allocate and initialize singleton true and false boolean objects. |
| 436 cls = Class::New<Bool>(); |
| 437 isolate->object_store()->set_bool_class(cls); |
| 438 *bool_true_ = Bool::New(true); |
| 439 *bool_false_ = Bool::New(false); |
430 } | 440 } |
431 | 441 |
432 | 442 |
433 #define SET_CLASS_NAME(class_name, name) \ | 443 #define SET_CLASS_NAME(class_name, name) \ |
434 cls = class_name##_class(); \ | 444 cls = class_name##_class(); \ |
435 cls.set_name(Symbols::name()); \ | 445 cls.set_name(Symbols::name()); \ |
436 | 446 |
437 void Object::RegisterSingletonClassNames() { | 447 void Object::RegisterSingletonClassNames() { |
438 Class& cls = Class::Handle(); | 448 Class& cls = Class::Handle(); |
439 | 449 |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
890 object_store->set_void_type(type); | 900 object_store->set_void_type(type); |
891 | 901 |
892 // The class 'dynamic' is registered in the class dictionary because its name | 902 // The class 'dynamic' is registered in the class dictionary because its name |
893 // is a built-in identifier, rather than a reserved keyword. Its name is not | 903 // is a built-in identifier, rather than a reserved keyword. Its name is not |
894 // heap allocated, because the class resides in the VM isolate. | 904 // heap allocated, because the class resides in the VM isolate. |
895 // The corresponding type, the "unknown type", is stored in the object store. | 905 // The corresponding type, the "unknown type", is stored in the object store. |
896 cls = dynamic_class(); | 906 cls = dynamic_class(); |
897 type = Type::NewNonParameterizedType(cls); | 907 type = Type::NewNonParameterizedType(cls); |
898 object_store->set_dynamic_type(type); | 908 object_store->set_dynamic_type(type); |
899 | 909 |
900 // Allocate pre-initialized values. | |
901 Bool& bool_value = Bool::Handle(); | |
902 bool_value = Bool::New(true); | |
903 object_store->set_true_value(bool_value); | |
904 bool_value = Bool::New(false); | |
905 object_store->set_false_value(bool_value); | |
906 | |
907 // Setup some default native field classes which can be extended for | 910 // Setup some default native field classes which can be extended for |
908 // specifying native fields in dart classes. | 911 // specifying native fields in dart classes. |
909 Library::InitNativeWrappersLibrary(isolate); | 912 Library::InitNativeWrappersLibrary(isolate); |
910 ASSERT(isolate->object_store()->native_wrappers_library() != Library::null()); | 913 ASSERT(isolate->object_store()->native_wrappers_library() != Library::null()); |
911 | 914 |
912 // Finish the initialization by compiling the bootstrap scripts containing the | 915 // Finish the initialization by compiling the bootstrap scripts containing the |
913 // base interfaces and the implementation of the internal classes. | 916 // base interfaces and the implementation of the internal classes. |
914 Error& error = Error::Handle(); | 917 Error& error = Error::Handle(); |
915 error = Bootstrap::Compile(core_lib, script); | 918 error = Bootstrap::Compile(core_lib, script); |
916 if (!error.IsNull()) { | 919 if (!error.IsNull()) { |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1124 object_store->set_jsregexp_class(cls); | 1127 object_store->set_jsregexp_class(cls); |
1125 | 1128 |
1126 // Some classes are not stored in the object store. Yet we still need to | 1129 // Some classes are not stored in the object store. Yet we still need to |
1127 // create their Class object so that they get put into the class_table | 1130 // create their Class object so that they get put into the class_table |
1128 // (as a side effect of Class::New()). | 1131 // (as a side effect of Class::New()). |
1129 cls = Class::New<DartFunction>(); | 1132 cls = Class::New<DartFunction>(); |
1130 cls = Class::New<Number>(); | 1133 cls = Class::New<Number>(); |
1131 | 1134 |
1132 cls = Class::New<WeakProperty>(); | 1135 cls = Class::New<WeakProperty>(); |
1133 object_store->set_weak_property_class(cls); | 1136 object_store->set_weak_property_class(cls); |
1134 | |
1135 // Allocate pre-initialized values. | |
1136 Bool& bool_value = Bool::Handle(); | |
1137 bool_value = Bool::New(true); | |
1138 object_store->set_true_value(bool_value); | |
1139 bool_value = Bool::New(false); | |
1140 object_store->set_false_value(bool_value); | |
1141 } | 1137 } |
1142 | 1138 |
1143 | 1139 |
1144 void Object::Print() const { | 1140 void Object::Print() const { |
1145 OS::Print("%s\n", ToCString()); | 1141 OS::Print("%s\n", ToCString()); |
1146 } | 1142 } |
1147 | 1143 |
1148 | 1144 |
1149 RawString* Object::DictionaryName() const { | 1145 RawString* Object::DictionaryName() const { |
1150 return String::null(); | 1146 return String::null(); |
(...skipping 10129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11280 return ExternalTwoByteString::raw(result); | 11276 return ExternalTwoByteString::raw(result); |
11281 } | 11277 } |
11282 | 11278 |
11283 | 11279 |
11284 void ExternalTwoByteString::Finalize(Dart_Handle handle, void* peer) { | 11280 void ExternalTwoByteString::Finalize(Dart_Handle handle, void* peer) { |
11285 delete reinterpret_cast<ExternalStringData<uint16_t>*>(peer); | 11281 delete reinterpret_cast<ExternalStringData<uint16_t>*>(peer); |
11286 DeleteWeakPersistentHandle(handle); | 11282 DeleteWeakPersistentHandle(handle); |
11287 } | 11283 } |
11288 | 11284 |
11289 | 11285 |
11290 RawBool* Bool::True() { | |
11291 return Isolate::Current()->object_store()->true_value(); | |
11292 } | |
11293 | |
11294 | |
11295 RawBool* Bool::False() { | |
11296 return Isolate::Current()->object_store()->false_value(); | |
11297 } | |
11298 | |
11299 | |
11300 RawBool* Bool::New(bool value) { | 11286 RawBool* Bool::New(bool value) { |
11301 ASSERT(Isolate::Current()->object_store()->bool_class() != Class::null()); | 11287 ASSERT(Isolate::Current()->object_store()->bool_class() != Class::null()); |
11302 Bool& result = Bool::Handle(); | 11288 Bool& result = Bool::Handle(); |
11303 { | 11289 { |
11304 // Since the two boolean instances are singletons we allocate them straight | 11290 // Since the two boolean instances are singletons we allocate them straight |
11305 // in the old generation. | 11291 // in the old generation. |
11306 RawObject* raw = Object::Allocate(Bool::kClassId, | 11292 RawObject* raw = Object::Allocate(Bool::kClassId, |
11307 Bool::InstanceSize(), | 11293 Bool::InstanceSize(), |
11308 Heap::kOld); | 11294 Heap::kOld); |
11309 NoGCScope no_gc; | 11295 NoGCScope no_gc; |
11310 result ^= raw; | 11296 result ^= raw; |
11311 } | 11297 } |
11312 result.set_value(value); | 11298 result.set_value(value); |
| 11299 result.SetCanonical(); |
11313 return result.raw(); | 11300 return result.raw(); |
11314 } | 11301 } |
11315 | 11302 |
11316 | 11303 |
11317 const char* Bool::ToCString() const { | 11304 const char* Bool::ToCString() const { |
11318 return value() ? "true" : "false"; | 11305 return value() ? "true" : "false"; |
11319 } | 11306 } |
11320 | 11307 |
11321 | 11308 |
11322 bool Array::Equals(const Instance& other) const { | 11309 bool Array::Equals(const Instance& other) const { |
(...skipping 1109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12432 } | 12419 } |
12433 return result.raw(); | 12420 return result.raw(); |
12434 } | 12421 } |
12435 | 12422 |
12436 | 12423 |
12437 const char* WeakProperty::ToCString() const { | 12424 const char* WeakProperty::ToCString() const { |
12438 return "_WeakProperty"; | 12425 return "_WeakProperty"; |
12439 } | 12426 } |
12440 | 12427 |
12441 } // namespace dart | 12428 } // namespace dart |
OLD | NEW |