| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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/isolate.h" | 8 #include "vm/isolate.h" |
| 9 #include "vm/longjump.h" |
| 8 #include "vm/object.h" | 10 #include "vm/object.h" |
| 9 #include "vm/raw_object.h" | 11 #include "vm/raw_object.h" |
| 10 #include "vm/visitor.h" | 12 #include "vm/visitor.h" |
| 11 | 13 |
| 12 namespace dart { | 14 namespace dart { |
| 13 | 15 |
| 14 ObjectStore::ObjectStore() | 16 ObjectStore::ObjectStore() |
| 15 : object_class_(Class::null()), | 17 : object_class_(Class::null()), |
| 16 function_interface_(Type::null()), | 18 function_interface_(Type::null()), |
| 17 number_interface_(Type::null()), | 19 number_interface_(Type::null()), |
| (...skipping 23 matching lines...) Expand all Loading... |
| 41 false_value_(Bool::null()), | 43 false_value_(Bool::null()), |
| 42 empty_array_(Array::null()), | 44 empty_array_(Array::null()), |
| 43 symbol_table_(Array::null()), | 45 symbol_table_(Array::null()), |
| 44 core_library_(Library::null()), | 46 core_library_(Library::null()), |
| 45 core_impl_library_(Library::null()), | 47 core_impl_library_(Library::null()), |
| 46 native_wrappers_library_(Library::null()), | 48 native_wrappers_library_(Library::null()), |
| 47 root_library_(Library::null()), | 49 root_library_(Library::null()), |
| 48 registered_libraries_(Library::null()), | 50 registered_libraries_(Library::null()), |
| 49 pending_classes_(Array::null()), | 51 pending_classes_(Array::null()), |
| 50 sticky_error_(String::null()), | 52 sticky_error_(String::null()), |
| 51 empty_context_(Context::null()) { | 53 empty_context_(Context::null()), |
| 54 stack_overflow_(Instance::null()), |
| 55 preallocate_objects_called_(false) { |
| 52 } | 56 } |
| 53 | 57 |
| 54 | 58 |
| 55 ObjectStore::~ObjectStore() { | 59 ObjectStore::~ObjectStore() { |
| 56 } | 60 } |
| 57 | 61 |
| 58 | 62 |
| 59 void ObjectStore::VisitObjectPointers(ObjectPointerVisitor* visitor) { | 63 void ObjectStore::VisitObjectPointers(ObjectPointerVisitor* visitor) { |
| 60 ASSERT(visitor != NULL); | 64 ASSERT(visitor != NULL); |
| 61 visitor->VisitPointers(from(), to()); | 65 visitor->VisitPointers(from(), to()); |
| 62 } | 66 } |
| 63 | 67 |
| 64 | 68 |
| 65 void ObjectStore::Init(Isolate* isolate) { | 69 void ObjectStore::Init(Isolate* isolate) { |
| 66 ASSERT(isolate->object_store() == NULL); | 70 ASSERT(isolate->object_store() == NULL); |
| 67 ObjectStore* store = new ObjectStore(); | 71 ObjectStore* store = new ObjectStore(); |
| 68 isolate->set_object_store(store); | 72 isolate->set_object_store(store); |
| 69 } | 73 } |
| 70 | 74 |
| 71 | 75 |
| 76 bool ObjectStore::PreallocateObjects() { |
| 77 if (preallocate_objects_called_) { |
| 78 return true; |
| 79 } |
| 80 |
| 81 Isolate* isolate = Isolate::Current(); |
| 82 ASSERT(isolate != NULL && isolate->object_store() == this); |
| 83 LongJump* base = isolate->long_jump_base(); |
| 84 LongJump jump; |
| 85 isolate->set_long_jump_base(&jump); |
| 86 if (setjmp(*jump.Set()) == 0) { |
| 87 GrowableArray<const Object*> args; |
| 88 const Instance& exception = |
| 89 Instance::Handle(Exceptions::Create(Exceptions::kStackOverflow, args)); |
| 90 set_stack_overflow(exception); |
| 91 } else { |
| 92 return false; |
| 93 } |
| 94 isolate->set_long_jump_base(base); |
| 95 preallocate_objects_called_ = true; |
| 96 return true; |
| 97 } |
| 98 |
| 99 |
| 72 RawClass* ObjectStore::GetClass(int index) { | 100 RawClass* ObjectStore::GetClass(int index) { |
| 73 switch (index) { | 101 switch (index) { |
| 74 case kObjectClass: return object_class_; | 102 case kObjectClass: return object_class_; |
| 75 case kSmiClass: return smi_class_; | 103 case kSmiClass: return smi_class_; |
| 76 case kMintClass: return mint_class_; | 104 case kMintClass: return mint_class_; |
| 77 case kBigintClass: return bigint_class_; | 105 case kBigintClass: return bigint_class_; |
| 78 case kDoubleClass: return double_class_; | 106 case kDoubleClass: return double_class_; |
| 79 case kOneByteStringClass: return one_byte_string_class_; | 107 case kOneByteStringClass: return one_byte_string_class_; |
| 80 case kTwoByteStringClass: return two_byte_string_class_; | 108 case kTwoByteStringClass: return two_byte_string_class_; |
| 81 case kFourByteStringClass: return four_byte_string_class_; | 109 case kFourByteStringClass: return four_byte_string_class_; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 return kBoolInterface; | 209 return kBoolInterface; |
| 182 } else if (raw_type == string_interface()) { | 210 } else if (raw_type == string_interface()) { |
| 183 return kStringInterface; | 211 return kStringInterface; |
| 184 } else if (raw_type == list_interface()) { | 212 } else if (raw_type == list_interface()) { |
| 185 return kListInterface; | 213 return kListInterface; |
| 186 } | 214 } |
| 187 return kInvalidIndex; | 215 return kInvalidIndex; |
| 188 } | 216 } |
| 189 | 217 |
| 190 } // namespace dart | 218 } // namespace dart |
| OLD | NEW |