| 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" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 } | 111 } |
| 112 | 112 |
| 113 | 113 |
| 114 void ObjectStore::Init(Isolate* isolate) { | 114 void ObjectStore::Init(Isolate* isolate) { |
| 115 ASSERT(isolate->object_store() == NULL); | 115 ASSERT(isolate->object_store() == NULL); |
| 116 ObjectStore* store = new ObjectStore(); | 116 ObjectStore* store = new ObjectStore(); |
| 117 isolate->set_object_store(store); | 117 isolate->set_object_store(store); |
| 118 } | 118 } |
| 119 | 119 |
| 120 | 120 |
| 121 bool ObjectStore::PreallocateObjects() { | 121 RawError* ObjectStore::PreallocateObjects() { |
| 122 Thread* thread = Thread::Current(); | 122 Thread* thread = Thread::Current(); |
| 123 Isolate* isolate = thread->isolate(); | 123 Isolate* isolate = thread->isolate(); |
| 124 Zone* zone = thread->zone(); | 124 Zone* zone = thread->zone(); |
| 125 ASSERT(isolate != NULL && isolate->object_store() == this); | 125 ASSERT(isolate != NULL && isolate->object_store() == this); |
| 126 if (this->stack_overflow() != Instance::null()) { | 126 if (this->stack_overflow() != Instance::null()) { |
| 127 ASSERT(this->out_of_memory() != Instance::null()); | 127 ASSERT(this->out_of_memory() != Instance::null()); |
| 128 ASSERT(this->preallocated_stack_trace() != Stacktrace::null()); | 128 ASSERT(this->preallocated_stack_trace() != Stacktrace::null()); |
| 129 return true; | 129 return Error::null(); |
| 130 } | 130 } |
| 131 ASSERT(this->stack_overflow() == Instance::null()); | 131 ASSERT(this->stack_overflow() == Instance::null()); |
| 132 ASSERT(this->out_of_memory() == Instance::null()); | 132 ASSERT(this->out_of_memory() == Instance::null()); |
| 133 ASSERT(this->preallocated_stack_trace() == Stacktrace::null()); | 133 ASSERT(this->preallocated_stack_trace() == Stacktrace::null()); |
| 134 | 134 |
| 135 this->pending_deferred_loads_ = GrowableObjectArray::New(); | 135 this->pending_deferred_loads_ = GrowableObjectArray::New(); |
| 136 | 136 |
| 137 this->closure_functions_ = GrowableObjectArray::New(); | 137 this->closure_functions_ = GrowableObjectArray::New(); |
| 138 this->resume_capabilities_ = GrowableObjectArray::New(); | 138 this->resume_capabilities_ = GrowableObjectArray::New(); |
| 139 this->exit_listeners_ = GrowableObjectArray::New(); | 139 this->exit_listeners_ = GrowableObjectArray::New(); |
| 140 this->error_listeners_ = GrowableObjectArray::New(); | 140 this->error_listeners_ = GrowableObjectArray::New(); |
| 141 | 141 |
| 142 Object& result = Object::Handle(); | 142 Object& result = Object::Handle(); |
| 143 const Library& library = Library::Handle(Library::CoreLibrary()); | 143 const Library& library = Library::Handle(Library::CoreLibrary()); |
| 144 | 144 |
| 145 result = DartLibraryCalls::InstanceCreate(library, | 145 result = DartLibraryCalls::InstanceCreate(library, |
| 146 Symbols::StackOverflowError(), | 146 Symbols::StackOverflowError(), |
| 147 Symbols::Dot(), | 147 Symbols::Dot(), |
| 148 Object::empty_array()); | 148 Object::empty_array()); |
| 149 if (result.IsError()) { | 149 if (result.IsError()) { |
| 150 return false; | 150 return Error::Cast(result).raw(); |
| 151 } | 151 } |
| 152 set_stack_overflow(Instance::Cast(result)); | 152 set_stack_overflow(Instance::Cast(result)); |
| 153 | 153 |
| 154 result = DartLibraryCalls::InstanceCreate(library, | 154 result = DartLibraryCalls::InstanceCreate(library, |
| 155 Symbols::OutOfMemoryError(), | 155 Symbols::OutOfMemoryError(), |
| 156 Symbols::Dot(), | 156 Symbols::Dot(), |
| 157 Object::empty_array()); | 157 Object::empty_array()); |
| 158 if (result.IsError()) { | 158 if (result.IsError()) { |
| 159 return false; | 159 return Error::Cast(result).raw(); |
| 160 } | 160 } |
| 161 set_out_of_memory(Instance::Cast(result)); | 161 set_out_of_memory(Instance::Cast(result)); |
| 162 | 162 |
| 163 // Allocate pre-allocated unhandled exception object initialized with the | 163 // Allocate pre-allocated unhandled exception object initialized with the |
| 164 // pre-allocated OutOfMemoryError. | 164 // pre-allocated OutOfMemoryError. |
| 165 const UnhandledException& unhandled_exception = UnhandledException::Handle( | 165 const UnhandledException& unhandled_exception = UnhandledException::Handle( |
| 166 UnhandledException::New(Instance::Cast(result), | 166 UnhandledException::New(Instance::Cast(result), |
| 167 Stacktrace::Handle(zone))); | 167 Stacktrace::Handle(zone))); |
| 168 set_preallocated_unhandled_exception(unhandled_exception); | 168 set_preallocated_unhandled_exception(unhandled_exception); |
| 169 | 169 |
| 170 const Array& code_array = Array::Handle(zone, | 170 const Array& code_array = Array::Handle(zone, |
| 171 Array::New(Stacktrace::kPreallocatedStackdepth, Heap::kOld)); | 171 Array::New(Stacktrace::kPreallocatedStackdepth, Heap::kOld)); |
| 172 const Array& pc_offset_array = Array::Handle(zone, | 172 const Array& pc_offset_array = Array::Handle(zone, |
| 173 Array::New(Stacktrace::kPreallocatedStackdepth, Heap::kOld)); | 173 Array::New(Stacktrace::kPreallocatedStackdepth, Heap::kOld)); |
| 174 const Stacktrace& stack_trace = Stacktrace::Handle(zone, | 174 const Stacktrace& stack_trace = Stacktrace::Handle(zone, |
| 175 Stacktrace::New(code_array, pc_offset_array)); | 175 Stacktrace::New(code_array, pc_offset_array)); |
| 176 // Expansion of inlined functions requires additional memory at run time, | 176 // Expansion of inlined functions requires additional memory at run time, |
| 177 // avoid it. | 177 // avoid it. |
| 178 stack_trace.set_expand_inlined(false); | 178 stack_trace.set_expand_inlined(false); |
| 179 set_preallocated_stack_trace(stack_trace); | 179 set_preallocated_stack_trace(stack_trace); |
| 180 | 180 |
| 181 return true; | 181 return Error::null(); |
| 182 } | 182 } |
| 183 | 183 |
| 184 | 184 |
| 185 void ObjectStore::InitKnownObjects() { | 185 void ObjectStore::InitKnownObjects() { |
| 186 Thread* thread = Thread::Current(); | 186 Thread* thread = Thread::Current(); |
| 187 Zone* zone = thread->zone(); | 187 Zone* zone = thread->zone(); |
| 188 Isolate* isolate = thread->isolate(); | 188 Isolate* isolate = thread->isolate(); |
| 189 ASSERT(isolate != NULL && isolate->object_store() == this); | 189 ASSERT(isolate != NULL && isolate->object_store() == this); |
| 190 | 190 |
| 191 const Library& async_lib = Library::Handle(async_library()); | 191 const Library& async_lib = Library::Handle(async_library()); |
| 192 ASSERT(!async_lib.IsNull()); | 192 ASSERT(!async_lib.IsNull()); |
| 193 Class& cls = Class::Handle(zone); | 193 Class& cls = Class::Handle(zone); |
| 194 cls = async_lib.LookupClass(Symbols::Future()); | 194 cls = async_lib.LookupClass(Symbols::Future()); |
| 195 ASSERT(!cls.IsNull()); | 195 ASSERT(!cls.IsNull()); |
| 196 set_future_class(cls); | 196 set_future_class(cls); |
| 197 cls = async_lib.LookupClass(Symbols::Completer()); | 197 cls = async_lib.LookupClass(Symbols::Completer()); |
| 198 ASSERT(!cls.IsNull()); | 198 ASSERT(!cls.IsNull()); |
| 199 set_completer_class(cls); | 199 set_completer_class(cls); |
| 200 cls = async_lib.LookupClass(Symbols::StreamIterator()); | 200 cls = async_lib.LookupClass(Symbols::StreamIterator()); |
| 201 ASSERT(!cls.IsNull()); | 201 ASSERT(!cls.IsNull()); |
| 202 set_stream_iterator_class(cls); | 202 set_stream_iterator_class(cls); |
| 203 | 203 |
| 204 const Library& internal_lib = Library::Handle(internal_library()); | 204 const Library& internal_lib = Library::Handle(internal_library()); |
| 205 cls = internal_lib.LookupClass(Symbols::Symbol()); | 205 cls = internal_lib.LookupClass(Symbols::Symbol()); |
| 206 set_symbol_class(cls); | 206 set_symbol_class(cls); |
| 207 } | 207 } |
| 208 | 208 |
| 209 } // namespace dart | 209 } // namespace dart |
| OLD | NEW |