Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Side by Side Diff: vm/snapshot.cc

Issue 11475012: Return an unhandled exception error on an OOM or other errors while (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « vm/snapshot.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/snapshot.h" 5 #include "vm/snapshot.h"
6 6
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 #include "vm/bigint_operations.h" 8 #include "vm/bigint_operations.h"
9 #include "vm/bootstrap.h" 9 #include "vm/bootstrap.h"
10 #include "vm/exceptions.h" 10 #include "vm/exceptions.h"
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 isolate_(isolate), 150 isolate_(isolate),
151 cls_(Class::Handle()), 151 cls_(Class::Handle()),
152 obj_(Object::Handle()), 152 obj_(Object::Handle()),
153 str_(String::Handle()), 153 str_(String::Handle()),
154 library_(Library::Handle()), 154 library_(Library::Handle()),
155 type_(AbstractType::Handle()), 155 type_(AbstractType::Handle()),
156 type_arguments_(AbstractTypeArguments::Handle()), 156 type_arguments_(AbstractTypeArguments::Handle()),
157 tokens_(Array::Handle()), 157 tokens_(Array::Handle()),
158 stream_(TokenStream::Handle()), 158 stream_(TokenStream::Handle()),
159 data_(ExternalUint8Array::Handle()), 159 data_(ExternalUint8Array::Handle()),
160 error_(UnhandledException::Handle()),
160 backward_references_((kind == Snapshot::kFull) ? 161 backward_references_((kind == Snapshot::kFull) ?
161 kNumInitialReferencesInFullSnapshot : 162 kNumInitialReferencesInFullSnapshot :
162 kNumInitialReferences) { 163 kNumInitialReferences) {
163 } 164 }
164 165
165 166
166 RawObject* SnapshotReader::ReadObject() { 167 RawObject* SnapshotReader::ReadObject() {
167 Object& obj = Object::Handle(ReadObjectImpl()); 168 // Setup for long jump in case there is an exception while reading.
168 for (intptr_t i = 0; i < backward_references_.length(); i++) { 169 LongJump* base = isolate()->long_jump_base();
169 if (!backward_references_[i]->is_deserialized()) { 170 LongJump jump;
170 ReadObjectImpl(); 171 isolate()->set_long_jump_base(&jump);
171 backward_references_[i]->set_state(kIsDeserialized); 172 const Instance& null_object = Instance::Handle();
173 *ErrorHandle() = UnhandledException::New(null_object, null_object);
174 if (setjmp(*jump.Set()) == 0) {
175 Object& obj = Object::Handle(ReadObjectImpl());
176 for (intptr_t i = 0; i < backward_references_.length(); i++) {
177 if (!backward_references_[i]->is_deserialized()) {
178 ReadObjectImpl();
179 backward_references_[i]->set_state(kIsDeserialized);
180 }
172 } 181 }
182 isolate()->set_long_jump_base(base);
183 return obj.raw();
184 } else {
185 // An error occurred while reading, return the error object.
186 const Error& err = Error::Handle(isolate()->object_store()->sticky_error());
187 isolate()->object_store()->clear_sticky_error();
188 isolate()->set_long_jump_base(base);
189 return err.raw();
173 } 190 }
174 return obj.raw();
175 } 191 }
176 192
177 193
178 RawClass* SnapshotReader::ReadClassId(intptr_t object_id) { 194 RawClass* SnapshotReader::ReadClassId(intptr_t object_id) {
179 ASSERT(kind_ != Snapshot::kFull); 195 ASSERT(kind_ != Snapshot::kFull);
180 // Read the class header information and lookup the class. 196 // Read the class header information and lookup the class.
181 intptr_t class_header = ReadIntptrValue(); 197 intptr_t class_header = ReadIntptrValue();
182 ASSERT((class_header & kSmiTagMask) != kSmiTag); 198 ASSERT((class_header & kSmiTagMask) != kSmiTag);
183 Class& cls = Class::ZoneHandle(isolate(), Class::null()); 199 Class& cls = Class::ZoneHandle(isolate(), Class::null());
184 cls = LookupInternalClass(class_header); 200 cls = LookupInternalClass(class_header);
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 RawObject* SnapshotReader::AllocateUninitialized(const Class& cls, 624 RawObject* SnapshotReader::AllocateUninitialized(const Class& cls,
609 intptr_t size) { 625 intptr_t size) {
610 ASSERT(isolate()->no_gc_scope_depth() != 0); 626 ASSERT(isolate()->no_gc_scope_depth() != 0);
611 ASSERT(Utils::IsAligned(size, kObjectAlignment)); 627 ASSERT(Utils::IsAligned(size, kObjectAlignment));
612 Heap* heap = isolate()->heap(); 628 Heap* heap = isolate()->heap();
613 629
614 uword address = heap->TryAllocate(size, Heap::kOld); 630 uword address = heap->TryAllocate(size, Heap::kOld);
615 if (address == 0) { 631 if (address == 0) {
616 // Use the preallocated out of memory exception to avoid calling 632 // Use the preallocated out of memory exception to avoid calling
617 // into dart code or allocating any code. 633 // into dart code or allocating any code.
634 // We do a longjmp at this point to unwind out of the entire
635 // read part and return the error object back.
618 const Instance& exception = 636 const Instance& exception =
619 Instance::Handle(object_store()->out_of_memory()); 637 Instance::Handle(object_store()->out_of_memory());
620 Exceptions::Throw(exception); 638 ErrorHandle()->set_exception(exception);
621 UNREACHABLE(); 639 Isolate::Current()->long_jump_base()->Jump(1, *ErrorHandle());
622 } 640 }
623 RawObject* raw_obj = reinterpret_cast<RawObject*>(address + kHeapObjectTag); 641 RawObject* raw_obj = reinterpret_cast<RawObject*>(address + kHeapObjectTag);
624 uword tags = 0; 642 uword tags = 0;
625 intptr_t index = cls.id(); 643 intptr_t index = cls.id();
626 ASSERT(index != kIllegalCid); 644 ASSERT(index != kIllegalCid);
627 tags = RawObject::ClassIdTag::update(index, tags); 645 tags = RawObject::ClassIdTag::update(index, tags);
628 tags = RawObject::SizeTag::update(size, tags); 646 tags = RawObject::SizeTag::update(size, tags);
629 raw_obj->ptr()->tags_ = tags; 647 raw_obj->ptr()->tags_ = tags;
630 return raw_obj; 648 return raw_obj;
631 } 649 }
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after
1297 UnmarkAll(); 1315 UnmarkAll();
1298 isolate->set_long_jump_base(base); 1316 isolate->set_long_jump_base(base);
1299 } else { 1317 } else {
1300 isolate->set_long_jump_base(base); 1318 isolate->set_long_jump_base(base);
1301 ThrowException(exception_type(), exception_msg()); 1319 ThrowException(exception_type(), exception_msg());
1302 } 1320 }
1303 } 1321 }
1304 1322
1305 1323
1306 } // namespace dart 1324 } // namespace dart
OLDNEW
« no previous file with comments | « vm/snapshot.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698