| 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/snapshot.h" | 5 #include "vm/snapshot.h" |
| 6 | 6 |
| 7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
| 8 #include "vm/bootstrap.h" | 8 #include "vm/bootstrap.h" |
| 9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
| 10 #include "vm/dart.h" | 10 #include "vm/dart.h" |
| 11 #include "vm/dart_entry.h" | 11 #include "vm/dart_entry.h" |
| 12 #include "vm/exceptions.h" | 12 #include "vm/exceptions.h" |
| 13 #include "vm/heap.h" | 13 #include "vm/heap.h" |
| 14 #include "vm/lockers.h" | 14 #include "vm/lockers.h" |
| 15 #include "vm/longjump.h" | 15 #include "vm/longjump.h" |
| 16 #include "vm/object.h" | 16 #include "vm/object.h" |
| 17 #include "vm/object_store.h" | 17 #include "vm/object_store.h" |
| 18 #include "vm/snapshot_ids.h" | 18 #include "vm/snapshot_ids.h" |
| 19 #include "vm/symbols.h" | 19 #include "vm/symbols.h" |
| 20 #include "vm/verified_memory.h" | 20 #include "vm/verified_memory.h" |
| 21 #include "vm/version.h" | 21 #include "vm/version.h" |
| 22 | 22 |
| 23 // We currently only expect the Dart mutator to read snapshots. | 23 // We currently only expect the Dart mutator to read snapshots. |
| 24 #define ASSERT_NO_SAFEPOINT_SCOPE() \ | 24 #define ASSERT_NO_SAFEPOINT_SCOPE() \ |
| 25 isolate()->AssertCurrentThreadIsMutator(); \ | 25 isolate()->AssertCurrentThreadIsMutator(); \ |
| 26 ASSERT(Thread::Current()->no_safepoint_scope_depth() != 0) | 26 ASSERT(thread()->no_safepoint_scope_depth() != 0) |
| 27 | 27 |
| 28 namespace dart { | 28 namespace dart { |
| 29 | 29 |
| 30 static const int kNumVmIsolateSnapshotReferences = 32 * KB; | 30 static const int kNumVmIsolateSnapshotReferences = 32 * KB; |
| 31 static const int kNumInitialReferencesInFullSnapshot = 160 * KB; | 31 static const int kNumInitialReferencesInFullSnapshot = 160 * KB; |
| 32 static const int kNumInitialReferences = 64; | 32 static const int kNumInitialReferences = 64; |
| 33 | 33 |
| 34 | 34 |
| 35 static bool IsSingletonClassId(intptr_t class_id) { | 35 static bool IsSingletonClassId(intptr_t class_id) { |
| 36 // Check if this is a singleton object class which is shared by all isolates. | 36 // Check if this is a singleton object class which is shared by all isolates. |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 intptr_t BaseReader::ReadSmiValue() { | 166 intptr_t BaseReader::ReadSmiValue() { |
| 167 return Smi::Value(ReadAsSmi()); | 167 return Smi::Value(ReadAsSmi()); |
| 168 } | 168 } |
| 169 | 169 |
| 170 | 170 |
| 171 SnapshotReader::SnapshotReader( | 171 SnapshotReader::SnapshotReader( |
| 172 const uint8_t* buffer, | 172 const uint8_t* buffer, |
| 173 intptr_t size, | 173 intptr_t size, |
| 174 Snapshot::Kind kind, | 174 Snapshot::Kind kind, |
| 175 ZoneGrowableArray<BackRefNode>* backward_refs, | 175 ZoneGrowableArray<BackRefNode>* backward_refs, |
| 176 Isolate* isolate, | 176 Thread* thread) |
| 177 Zone* zone) | |
| 178 : BaseReader(buffer, size), | 177 : BaseReader(buffer, size), |
| 179 kind_(kind), | 178 kind_(kind), |
| 180 snapshot_code_(false), | 179 snapshot_code_(false), |
| 181 isolate_(isolate), | 180 thread_(thread), |
| 182 zone_(zone), | 181 zone_(thread->zone()), |
| 183 heap_(isolate->heap()), | 182 heap_(isolate()->heap()), |
| 184 old_space_(isolate->heap()->old_space()), | 183 old_space_(thread_->isolate()->heap()->old_space()), |
| 185 cls_(Class::Handle(isolate)), | 184 cls_(Class::Handle(zone_)), |
| 186 obj_(Object::Handle(isolate)), | 185 obj_(Object::Handle(zone_)), |
| 187 pobj_(PassiveObject::Handle(isolate)), | 186 pobj_(PassiveObject::Handle(zone_)), |
| 188 array_(Array::Handle(isolate)), | 187 array_(Array::Handle(zone_)), |
| 189 field_(Field::Handle(isolate)), | 188 field_(Field::Handle(zone_)), |
| 190 str_(String::Handle(isolate)), | 189 str_(String::Handle(zone_)), |
| 191 library_(Library::Handle(isolate)), | 190 library_(Library::Handle(zone_)), |
| 192 type_(AbstractType::Handle(isolate)), | 191 type_(AbstractType::Handle(zone_)), |
| 193 type_arguments_(TypeArguments::Handle(isolate)), | 192 type_arguments_(TypeArguments::Handle(zone_)), |
| 194 tokens_(Array::Handle(isolate)), | 193 tokens_(Array::Handle(zone_)), |
| 195 stream_(TokenStream::Handle(isolate)), | 194 stream_(TokenStream::Handle(zone_)), |
| 196 data_(ExternalTypedData::Handle(isolate)), | 195 data_(ExternalTypedData::Handle(zone_)), |
| 197 typed_data_(TypedData::Handle(isolate)), | 196 typed_data_(TypedData::Handle(zone_)), |
| 198 error_(UnhandledException::Handle(isolate)), | 197 error_(UnhandledException::Handle(zone_)), |
| 199 max_vm_isolate_object_id_( | 198 max_vm_isolate_object_id_( |
| 200 (kind == Snapshot::kFull) ? | 199 (kind == Snapshot::kFull) ? |
| 201 Object::vm_isolate_snapshot_object_table().Length() : 0), | 200 Object::vm_isolate_snapshot_object_table().Length() : 0), |
| 202 backward_references_(backward_refs) { | 201 backward_references_(backward_refs) { |
| 203 } | 202 } |
| 204 | 203 |
| 205 | 204 |
| 206 RawObject* SnapshotReader::ReadObject() { | 205 RawObject* SnapshotReader::ReadObject() { |
| 207 // Setup for long jump in case there is an exception while reading. | 206 // Setup for long jump in case there is an exception while reading. |
| 208 LongJumpScope jump; | 207 LongJumpScope jump; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 } | 296 } |
| 298 | 297 |
| 299 | 298 |
| 300 intptr_t SnapshotReader::NextAvailableObjectId() const { | 299 intptr_t SnapshotReader::NextAvailableObjectId() const { |
| 301 return backward_references_->length() + | 300 return backward_references_->length() + |
| 302 kMaxPredefinedObjectIds + max_vm_isolate_object_id_; | 301 kMaxPredefinedObjectIds + max_vm_isolate_object_id_; |
| 303 } | 302 } |
| 304 | 303 |
| 305 | 304 |
| 306 void SnapshotReader::SetReadException(const char* msg) { | 305 void SnapshotReader::SetReadException(const char* msg) { |
| 307 Thread* thread = Thread::Current(); | 306 const String& error_str = String::Handle(zone(), String::New(msg)); |
| 308 Zone* zone = thread->zone(); | 307 const Array& args = Array::Handle(zone(), Array::New(1)); |
| 309 const String& error_str = String::Handle(zone, String::New(msg)); | |
| 310 const Array& args = Array::Handle(zone, Array::New(1)); | |
| 311 args.SetAt(0, error_str); | 308 args.SetAt(0, error_str); |
| 312 Object& result = Object::Handle(zone); | 309 Object& result = Object::Handle(zone()); |
| 313 const Library& library = Library::Handle(zone, Library::CoreLibrary()); | 310 const Library& library = Library::Handle(zone(), Library::CoreLibrary()); |
| 314 result = DartLibraryCalls::InstanceCreate(library, | 311 result = DartLibraryCalls::InstanceCreate(library, |
| 315 Symbols::ArgumentError(), | 312 Symbols::ArgumentError(), |
| 316 Symbols::Dot(), | 313 Symbols::Dot(), |
| 317 args); | 314 args); |
| 318 const Stacktrace& stacktrace = Stacktrace::Handle(zone); | 315 const Stacktrace& stacktrace = Stacktrace::Handle(zone()); |
| 319 const UnhandledException& error = UnhandledException::Handle( | 316 const UnhandledException& error = UnhandledException::Handle( |
| 320 zone, UnhandledException::New(Instance::Cast(result), stacktrace)); | 317 zone(), UnhandledException::New(Instance::Cast(result), stacktrace)); |
| 321 thread->long_jump_base()->Jump(1, error); | 318 thread()->long_jump_base()->Jump(1, error); |
| 322 } | 319 } |
| 323 | 320 |
| 324 | 321 |
| 325 RawObject* SnapshotReader::VmIsolateSnapshotObject(intptr_t index) const { | 322 RawObject* SnapshotReader::VmIsolateSnapshotObject(intptr_t index) const { |
| 326 return Object::vm_isolate_snapshot_object_table().At(index); | 323 return Object::vm_isolate_snapshot_object_table().At(index); |
| 327 } | 324 } |
| 328 | 325 |
| 329 | 326 |
| 330 bool SnapshotReader::is_vm_isolate() const { | 327 bool SnapshotReader::is_vm_isolate() const { |
| 331 return isolate_ == Dart::vm_isolate(); | 328 return isolate() == Dart::vm_isolate(); |
| 332 } | 329 } |
| 333 | 330 |
| 334 | 331 |
| 335 RawObject* SnapshotReader::ReadObjectImpl(bool as_reference, | 332 RawObject* SnapshotReader::ReadObjectImpl(bool as_reference, |
| 336 intptr_t patch_object_id, | 333 intptr_t patch_object_id, |
| 337 intptr_t patch_offset) { | 334 intptr_t patch_offset) { |
| 338 int64_t header_value = Read<int64_t>(); | 335 int64_t header_value = Read<int64_t>(); |
| 339 if ((header_value & kSmiTagMask) == kSmiTag) { | 336 if ((header_value & kSmiTagMask) == kSmiTag) { |
| 340 return NewInteger(header_value); | 337 return NewInteger(header_value); |
| 341 } | 338 } |
| (...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1092 uword address = | 1089 uword address = |
| 1093 old_space()->TryAllocateSmiInitializedLocked(size, | 1090 old_space()->TryAllocateSmiInitializedLocked(size, |
| 1094 PageSpace::kForceGrowth); | 1091 PageSpace::kForceGrowth); |
| 1095 if (address == 0) { | 1092 if (address == 0) { |
| 1096 // Use the preallocated out of memory exception to avoid calling | 1093 // Use the preallocated out of memory exception to avoid calling |
| 1097 // into dart code or allocating any code. | 1094 // into dart code or allocating any code. |
| 1098 // We do a longjmp at this point to unwind out of the entire | 1095 // We do a longjmp at this point to unwind out of the entire |
| 1099 // read part and return the error object back. | 1096 // read part and return the error object back. |
| 1100 const UnhandledException& error = UnhandledException::Handle( | 1097 const UnhandledException& error = UnhandledException::Handle( |
| 1101 object_store()->preallocated_unhandled_exception()); | 1098 object_store()->preallocated_unhandled_exception()); |
| 1102 Thread::Current()->long_jump_base()->Jump(1, error); | 1099 thread()->long_jump_base()->Jump(1, error); |
| 1103 } | 1100 } |
| 1104 VerifiedMemory::Accept(address, size); | 1101 VerifiedMemory::Accept(address, size); |
| 1105 | 1102 |
| 1106 RawObject* raw_obj = reinterpret_cast<RawObject*>(address + kHeapObjectTag); | 1103 RawObject* raw_obj = reinterpret_cast<RawObject*>(address + kHeapObjectTag); |
| 1107 uword tags = 0; | 1104 uword tags = 0; |
| 1108 ASSERT(class_id != kIllegalCid); | 1105 ASSERT(class_id != kIllegalCid); |
| 1109 tags = RawObject::ClassIdTag::update(class_id, tags); | 1106 tags = RawObject::ClassIdTag::update(class_id, tags); |
| 1110 tags = RawObject::SizeTag::update(size, tags); | 1107 tags = RawObject::SizeTag::update(size, tags); |
| 1111 tags = RawObject::VMHeapObjectTag::update(is_vm_isolate(), tags); | 1108 tags = RawObject::VMHeapObjectTag::update(is_vm_isolate(), tags); |
| 1112 raw_obj->ptr()->tags_ = tags; | 1109 raw_obj->ptr()->tags_ = tags; |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1269 *PassiveObjectHandle() = ReadObjectImpl(as_reference, | 1266 *PassiveObjectHandle() = ReadObjectImpl(as_reference, |
| 1270 object_id, | 1267 object_id, |
| 1271 (i + offset)); | 1268 (i + offset)); |
| 1272 result.SetAt(i, *PassiveObjectHandle()); | 1269 result.SetAt(i, *PassiveObjectHandle()); |
| 1273 } | 1270 } |
| 1274 } | 1271 } |
| 1275 | 1272 |
| 1276 | 1273 |
| 1277 VmIsolateSnapshotReader::VmIsolateSnapshotReader(const uint8_t* buffer, | 1274 VmIsolateSnapshotReader::VmIsolateSnapshotReader(const uint8_t* buffer, |
| 1278 intptr_t size, | 1275 intptr_t size, |
| 1279 Zone* zone) | 1276 Thread* thread) |
| 1280 : SnapshotReader(buffer, | 1277 : SnapshotReader(buffer, |
| 1281 size, | 1278 size, |
| 1282 Snapshot::kFull, | 1279 Snapshot::kFull, |
| 1283 new ZoneGrowableArray<BackRefNode>( | 1280 new ZoneGrowableArray<BackRefNode>( |
| 1284 kNumVmIsolateSnapshotReferences), | 1281 kNumVmIsolateSnapshotReferences), |
| 1285 Dart::vm_isolate(), | 1282 thread) { |
| 1286 zone) { | |
| 1287 } | 1283 } |
| 1288 | 1284 |
| 1289 | 1285 |
| 1290 VmIsolateSnapshotReader::~VmIsolateSnapshotReader() { | 1286 VmIsolateSnapshotReader::~VmIsolateSnapshotReader() { |
| 1291 intptr_t len = GetBackwardReferenceTable()->length(); | 1287 intptr_t len = GetBackwardReferenceTable()->length(); |
| 1292 Object::InitVmIsolateSnapshotObjectTable(len); | 1288 Object::InitVmIsolateSnapshotObjectTable(len); |
| 1293 ZoneGrowableArray<BackRefNode>* backrefs = GetBackwardReferenceTable(); | 1289 ZoneGrowableArray<BackRefNode>* backrefs = GetBackwardReferenceTable(); |
| 1294 for (intptr_t i = 0; i < len; i++) { | 1290 for (intptr_t i = 0; i < len; i++) { |
| 1295 Object::vm_isolate_snapshot_object_table().SetAt( | 1291 Object::vm_isolate_snapshot_object_table().SetAt( |
| 1296 i, *(backrefs->At(i).reference())); | 1292 i, *(backrefs->At(i).reference())); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1334 isolate->ValidateClassTable(); | 1330 isolate->ValidateClassTable(); |
| 1335 #endif | 1331 #endif |
| 1336 | 1332 |
| 1337 return ApiError::null(); | 1333 return ApiError::null(); |
| 1338 } | 1334 } |
| 1339 } | 1335 } |
| 1340 | 1336 |
| 1341 | 1337 |
| 1342 IsolateSnapshotReader::IsolateSnapshotReader(const uint8_t* buffer, | 1338 IsolateSnapshotReader::IsolateSnapshotReader(const uint8_t* buffer, |
| 1343 intptr_t size, | 1339 intptr_t size, |
| 1344 Isolate* isolate, | 1340 Thread* thread) |
| 1345 Zone* zone) | |
| 1346 : SnapshotReader(buffer, | 1341 : SnapshotReader(buffer, |
| 1347 size, | 1342 size, |
| 1348 Snapshot::kFull, | 1343 Snapshot::kFull, |
| 1349 new ZoneGrowableArray<BackRefNode>( | 1344 new ZoneGrowableArray<BackRefNode>( |
| 1350 kNumInitialReferencesInFullSnapshot), | 1345 kNumInitialReferencesInFullSnapshot), |
| 1351 isolate, | 1346 thread) { |
| 1352 zone) { | |
| 1353 } | 1347 } |
| 1354 | 1348 |
| 1355 | 1349 |
| 1356 IsolateSnapshotReader::~IsolateSnapshotReader() { | 1350 IsolateSnapshotReader::~IsolateSnapshotReader() { |
| 1357 ResetBackwardReferenceTable(); | 1351 ResetBackwardReferenceTable(); |
| 1358 } | 1352 } |
| 1359 | 1353 |
| 1360 | 1354 |
| 1361 ScriptSnapshotReader::ScriptSnapshotReader(const uint8_t* buffer, | 1355 ScriptSnapshotReader::ScriptSnapshotReader(const uint8_t* buffer, |
| 1362 intptr_t size, | 1356 intptr_t size, |
| 1363 Isolate* isolate, | 1357 Thread* thread) |
| 1364 Zone* zone) | |
| 1365 : SnapshotReader(buffer, | 1358 : SnapshotReader(buffer, |
| 1366 size, | 1359 size, |
| 1367 Snapshot::kScript, | 1360 Snapshot::kScript, |
| 1368 new ZoneGrowableArray<BackRefNode>(kNumInitialReferences), | 1361 new ZoneGrowableArray<BackRefNode>(kNumInitialReferences), |
| 1369 isolate, | 1362 thread) { |
| 1370 zone) { | |
| 1371 } | 1363 } |
| 1372 | 1364 |
| 1373 | 1365 |
| 1374 ScriptSnapshotReader::~ScriptSnapshotReader() { | 1366 ScriptSnapshotReader::~ScriptSnapshotReader() { |
| 1375 ResetBackwardReferenceTable(); | 1367 ResetBackwardReferenceTable(); |
| 1376 } | 1368 } |
| 1377 | 1369 |
| 1378 | 1370 |
| 1379 MessageSnapshotReader::MessageSnapshotReader(const uint8_t* buffer, | 1371 MessageSnapshotReader::MessageSnapshotReader(const uint8_t* buffer, |
| 1380 intptr_t size, | 1372 intptr_t size, |
| 1381 Isolate* isolate, | 1373 Thread* thread) |
| 1382 Zone* zone) | |
| 1383 : SnapshotReader(buffer, | 1374 : SnapshotReader(buffer, |
| 1384 size, | 1375 size, |
| 1385 Snapshot::kMessage, | 1376 Snapshot::kMessage, |
| 1386 new ZoneGrowableArray<BackRefNode>(kNumInitialReferences), | 1377 new ZoneGrowableArray<BackRefNode>(kNumInitialReferences), |
| 1387 isolate, | 1378 thread) { |
| 1388 zone) { | |
| 1389 } | 1379 } |
| 1390 | 1380 |
| 1391 | 1381 |
| 1392 MessageSnapshotReader::~MessageSnapshotReader() { | 1382 MessageSnapshotReader::~MessageSnapshotReader() { |
| 1393 ResetBackwardReferenceTable(); | 1383 ResetBackwardReferenceTable(); |
| 1394 } | 1384 } |
| 1395 | 1385 |
| 1396 | 1386 |
| 1397 SnapshotWriter::SnapshotWriter(Snapshot::Kind kind, | 1387 SnapshotWriter::SnapshotWriter(Snapshot::Kind kind, |
| 1398 uint8_t** buffer, | 1388 uint8_t** buffer, |
| 1399 ReAlloc alloc, | 1389 ReAlloc alloc, |
| 1400 intptr_t initial_size, | 1390 intptr_t initial_size, |
| 1401 ForwardList* forward_list, | 1391 ForwardList* forward_list, |
| 1402 bool can_send_any_object, | 1392 bool can_send_any_object, |
| 1403 bool snapshot_code) | 1393 bool snapshot_code) |
| 1404 : BaseWriter(buffer, alloc, initial_size), | 1394 : BaseWriter(buffer, alloc, initial_size), |
| 1405 kind_(kind), | 1395 kind_(kind), |
| 1406 isolate_(Isolate::Current()), | 1396 thread_(Thread::Current()), |
| 1407 object_store_(isolate_->object_store()), | 1397 object_store_(thread_->isolate()->object_store()), |
| 1408 class_table_(isolate_->class_table()), | 1398 class_table_(thread_->isolate()->class_table()), |
| 1409 forward_list_(forward_list), | 1399 forward_list_(forward_list), |
| 1410 exception_type_(Exceptions::kNone), | 1400 exception_type_(Exceptions::kNone), |
| 1411 exception_msg_(NULL), | 1401 exception_msg_(NULL), |
| 1412 unmarked_objects_(false), | 1402 unmarked_objects_(false), |
| 1413 can_send_any_object_(can_send_any_object), | 1403 can_send_any_object_(can_send_any_object), |
| 1414 snapshot_code_(snapshot_code) { | 1404 snapshot_code_(snapshot_code) { |
| 1415 ASSERT(forward_list_ != NULL); | 1405 ASSERT(forward_list_ != NULL); |
| 1416 } | 1406 } |
| 1417 | 1407 |
| 1418 | 1408 |
| (...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2211 // isolate message. | 2201 // isolate message. |
| 2212 RawFunction* func = Closure::GetFunction(obj); | 2202 RawFunction* func = Closure::GetFunction(obj); |
| 2213 // We only allow closure of top level methods or static functions in a | 2203 // We only allow closure of top level methods or static functions in a |
| 2214 // class to be sent in isolate messages. | 2204 // class to be sent in isolate messages. |
| 2215 if (can_send_any_object() && | 2205 if (can_send_any_object() && |
| 2216 Function::IsImplicitStaticClosureFunction(func)) { | 2206 Function::IsImplicitStaticClosureFunction(func)) { |
| 2217 return func; | 2207 return func; |
| 2218 } | 2208 } |
| 2219 // Not a closure of a top level method or static function, throw an | 2209 // Not a closure of a top level method or static function, throw an |
| 2220 // exception as we do not allow these objects to be serialized. | 2210 // exception as we do not allow these objects to be serialized. |
| 2221 HANDLESCOPE(isolate()); | 2211 HANDLESCOPE(thread()); |
| 2222 | 2212 |
| 2223 const Class& clazz = Class::Handle(isolate(), cls); | 2213 const Class& clazz = Class::Handle(isolate(), cls); |
| 2224 const Function& errorFunc = Function::Handle(isolate(), func); | 2214 const Function& errorFunc = Function::Handle(isolate(), func); |
| 2225 ASSERT(!errorFunc.IsNull()); | 2215 ASSERT(!errorFunc.IsNull()); |
| 2226 | 2216 |
| 2227 // All other closures are errors. | 2217 // All other closures are errors. |
| 2228 const char* format = "Illegal argument in isolate message" | 2218 const char* format = "Illegal argument in isolate message" |
| 2229 " : (object is a closure - %s %s)"; | 2219 " : (object is a closure - %s %s)"; |
| 2230 UnmarkAll(); // Unmark objects now as we are about to print stuff. | 2220 UnmarkAll(); // Unmark objects now as we are about to print stuff. |
| 2231 intptr_t len = OS::SNPrint(NULL, 0, format, | 2221 intptr_t len = OS::SNPrint(NULL, 0, format, |
| 2232 clazz.ToCString(), errorFunc.ToCString()) + 1; | 2222 clazz.ToCString(), errorFunc.ToCString()) + 1; |
| 2233 char* chars = Thread::Current()->zone()->Alloc<char>(len); | 2223 char* chars = thread()->zone()->Alloc<char>(len); |
| 2234 OS::SNPrint(chars, len, format, clazz.ToCString(), errorFunc.ToCString()); | 2224 OS::SNPrint(chars, len, format, clazz.ToCString(), errorFunc.ToCString()); |
| 2235 SetWriteException(Exceptions::kArgument, chars); | 2225 SetWriteException(Exceptions::kArgument, chars); |
| 2236 } | 2226 } |
| 2237 return Function::null(); | 2227 return Function::null(); |
| 2238 } | 2228 } |
| 2239 | 2229 |
| 2240 | 2230 |
| 2241 RawClass* SnapshotWriter::GetFunctionOwner(RawFunction* func) { | 2231 RawClass* SnapshotWriter::GetFunctionOwner(RawFunction* func) { |
| 2242 RawObject* owner = func->ptr()->owner_; | 2232 RawObject* owner = func->ptr()->owner_; |
| 2243 uword tags = GetObjectTags(owner); | 2233 uword tags = GetObjectTags(owner); |
| 2244 intptr_t class_id = RawObject::ClassIdTag::decode(tags); | 2234 intptr_t class_id = RawObject::ClassIdTag::decode(tags); |
| 2245 if (class_id == kClassCid) { | 2235 if (class_id == kClassCid) { |
| 2246 return reinterpret_cast<RawClass*>(owner); | 2236 return reinterpret_cast<RawClass*>(owner); |
| 2247 } | 2237 } |
| 2248 ASSERT(class_id == kPatchClassCid); | 2238 ASSERT(class_id == kPatchClassCid); |
| 2249 return reinterpret_cast<RawPatchClass*>(owner)->ptr()->patched_class_; | 2239 return reinterpret_cast<RawPatchClass*>(owner)->ptr()->patched_class_; |
| 2250 } | 2240 } |
| 2251 | 2241 |
| 2252 | 2242 |
| 2253 void SnapshotWriter::CheckForNativeFields(RawClass* cls) { | 2243 void SnapshotWriter::CheckForNativeFields(RawClass* cls) { |
| 2254 if (cls->ptr()->num_native_fields_ != 0) { | 2244 if (cls->ptr()->num_native_fields_ != 0) { |
| 2255 // We do not allow objects with native fields in an isolate message. | 2245 // We do not allow objects with native fields in an isolate message. |
| 2256 HANDLESCOPE(isolate()); | 2246 HANDLESCOPE(thread()); |
| 2257 const char* format = "Illegal argument in isolate message" | 2247 const char* format = "Illegal argument in isolate message" |
| 2258 " : (object extends NativeWrapper - %s)"; | 2248 " : (object extends NativeWrapper - %s)"; |
| 2259 UnmarkAll(); // Unmark objects now as we are about to print stuff. | 2249 UnmarkAll(); // Unmark objects now as we are about to print stuff. |
| 2260 const Class& clazz = Class::Handle(isolate(), cls); | 2250 const Class& clazz = Class::Handle(isolate(), cls); |
| 2261 intptr_t len = OS::SNPrint(NULL, 0, format, clazz.ToCString()) + 1; | 2251 intptr_t len = OS::SNPrint(NULL, 0, format, clazz.ToCString()) + 1; |
| 2262 char* chars = Thread::Current()->zone()->Alloc<char>(len); | 2252 char* chars = thread()->zone()->Alloc<char>(len); |
| 2263 OS::SNPrint(chars, len, format, clazz.ToCString()); | 2253 OS::SNPrint(chars, len, format, clazz.ToCString()); |
| 2264 SetWriteException(Exceptions::kArgument, chars); | 2254 SetWriteException(Exceptions::kArgument, chars); |
| 2265 } | 2255 } |
| 2266 } | 2256 } |
| 2267 | 2257 |
| 2268 | 2258 |
| 2269 void SnapshotWriter::SetWriteException(Exceptions::ExceptionType type, | 2259 void SnapshotWriter::SetWriteException(Exceptions::ExceptionType type, |
| 2270 const char* msg) { | 2260 const char* msg) { |
| 2271 set_exception_type(type); | 2261 set_exception_type(type); |
| 2272 set_exception_msg(msg); | 2262 set_exception_msg(msg); |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2492 NoSafepointScope no_safepoint; | 2482 NoSafepointScope no_safepoint; |
| 2493 WriteObject(obj.raw()); | 2483 WriteObject(obj.raw()); |
| 2494 UnmarkAll(); | 2484 UnmarkAll(); |
| 2495 } else { | 2485 } else { |
| 2496 ThrowException(exception_type(), exception_msg()); | 2486 ThrowException(exception_type(), exception_msg()); |
| 2497 } | 2487 } |
| 2498 } | 2488 } |
| 2499 | 2489 |
| 2500 | 2490 |
| 2501 } // namespace dart | 2491 } // namespace dart |
| OLD | NEW |