| 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/bigint_operations.h" | 5 #include "vm/bigint_operations.h" | 
| 6 #include "vm/object.h" | 6 #include "vm/object.h" | 
| 7 #include "vm/object_store.h" | 7 #include "vm/object_store.h" | 
| 8 #include "vm/snapshot.h" | 8 #include "vm/snapshot.h" | 
| 9 #include "vm/symbols.h" | 9 #include "vm/symbols.h" | 
| 10 #include "vm/visitor.h" | 10 #include "vm/visitor.h" | 
| 11 | 11 | 
| 12 namespace dart { | 12 namespace dart { | 
| 13 | 13 | 
| 14 #define NEW_OBJECT(type)                                                       \ | 14 #define NEW_OBJECT(type)                                                       \ | 
| 15   ((kind == Snapshot::kFull) ? reader->New##type() : type::New()) | 15   ((kind == Snapshot::kFull) ? reader->New##type() : type::New()) | 
| 16 | 16 | 
| 17 #define NEW_OBJECT_WITH_LEN(type, len)                                         \ | 17 #define NEW_OBJECT_WITH_LEN(type, len)                                         \ | 
| 18   ((kind == Snapshot::kFull) ? reader->New##type(len) : type::New(len)) | 18   ((kind == Snapshot::kFull) ? reader->New##type(len) : type::New(len)) | 
| 19 | 19 | 
| 20 | 20 | 
| 21 static uword ZoneAllocator(intptr_t size) { | 21 static uword BigintAllocator(intptr_t size) { | 
| 22   Zone* zone = Isolate::Current()->current_zone(); | 22   Zone* zone = Isolate::Current()->current_zone(); | 
| 23   return zone->Allocate(size); | 23   return zone->AllocUnsafe(size); | 
| 24 } | 24 } | 
| 25 | 25 | 
| 26 | 26 | 
| 27 RawClass* Class::ReadFrom(SnapshotReader* reader, | 27 RawClass* Class::ReadFrom(SnapshotReader* reader, | 
| 28                           intptr_t object_id, | 28                           intptr_t object_id, | 
| 29                           intptr_t tags, | 29                           intptr_t tags, | 
| 30                           Snapshot::Kind kind) { | 30                           Snapshot::Kind kind) { | 
| 31   ASSERT(reader != NULL); | 31   ASSERT(reader != NULL); | 
| 32 | 32 | 
| 33   Class& cls = Class::ZoneHandle(reader->isolate(), Class::null()); | 33   Class& cls = Class::ZoneHandle(reader->isolate(), Class::null()); | 
| (...skipping 1202 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1236 | 1236 | 
| 1237 | 1237 | 
| 1238 RawBigint* Bigint::ReadFrom(SnapshotReader* reader, | 1238 RawBigint* Bigint::ReadFrom(SnapshotReader* reader, | 
| 1239                             intptr_t object_id, | 1239                             intptr_t object_id, | 
| 1240                             intptr_t tags, | 1240                             intptr_t tags, | 
| 1241                             Snapshot::Kind kind) { | 1241                             Snapshot::Kind kind) { | 
| 1242   ASSERT(reader != NULL); | 1242   ASSERT(reader != NULL); | 
| 1243 | 1243 | 
| 1244   // Read in the HexCString representation of the bigint. | 1244   // Read in the HexCString representation of the bigint. | 
| 1245   intptr_t len = reader->ReadIntptrValue(); | 1245   intptr_t len = reader->ReadIntptrValue(); | 
| 1246   char* str = reinterpret_cast<char*>(ZoneAllocator(len + 1)); | 1246   char* str = Isolate::Current()->current_zone()->Alloc<char>(len + 1); | 
| 1247   str[len] = '\0'; | 1247   str[len] = '\0'; | 
| 1248   reader->ReadBytes(reinterpret_cast<uint8_t*>(str), len); | 1248   reader->ReadBytes(reinterpret_cast<uint8_t*>(str), len); | 
| 1249 | 1249 | 
| 1250   // Create a Bigint object from HexCString. | 1250   // Create a Bigint object from HexCString. | 
| 1251   Bigint& obj = Bigint::ZoneHandle( | 1251   Bigint& obj = Bigint::ZoneHandle( | 
| 1252       reader->isolate(), | 1252       reader->isolate(), | 
| 1253       (kind == Snapshot::kFull) ? reader->NewBigint(str) : | 1253       (kind == Snapshot::kFull) ? reader->NewBigint(str) : | 
| 1254                                   BigintOperations::FromHexCString(str)); | 1254                                   BigintOperations::FromHexCString(str)); | 
| 1255 | 1255 | 
| 1256   // If it is a canonical constant make it one. | 1256   // If it is a canonical constant make it one. | 
| (...skipping 26 matching lines...) Expand all  Loading... | 
| 1283   bool is_negative = false; | 1283   bool is_negative = false; | 
| 1284   if (length <= 0) { | 1284   if (length <= 0) { | 
| 1285     length = -length; | 1285     length = -length; | 
| 1286     is_negative = true; | 1286     is_negative = true; | 
| 1287   } | 1287   } | 
| 1288   uword data_start = reinterpret_cast<uword>(ptr()) + sizeof(RawBigint); | 1288   uword data_start = reinterpret_cast<uword>(ptr()) + sizeof(RawBigint); | 
| 1289   const char* str = BigintOperations::ToHexCString( | 1289   const char* str = BigintOperations::ToHexCString( | 
| 1290       length, | 1290       length, | 
| 1291       is_negative, | 1291       is_negative, | 
| 1292       reinterpret_cast<void*>(data_start), | 1292       reinterpret_cast<void*>(data_start), | 
| 1293       &ZoneAllocator); | 1293       &BigintAllocator); | 
| 1294   bool neg = false; | 1294   bool neg = false; | 
| 1295   if (*str == '-') { | 1295   if (*str == '-') { | 
| 1296     neg = true; | 1296     neg = true; | 
| 1297     str++; | 1297     str++; | 
| 1298   } | 1298   } | 
| 1299   intptr_t len = strlen(str); | 1299   intptr_t len = strlen(str); | 
| 1300   ASSERT(len > 2 && str[0] == '0' && str[1] == 'x'); | 1300   ASSERT(len > 2 && str[0] == '0' && str[1] == 'x'); | 
| 1301   if (neg) { | 1301   if (neg) { | 
| 1302     writer->WriteIntptrValue(len - 1);  // Include '-' in length. | 1302     writer->WriteIntptrValue(len - 1);  // Include '-' in length. | 
| 1303     writer->Write<uint8_t>('-'); | 1303     writer->Write<uint8_t>('-'); | 
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1371 | 1371 | 
| 1372 template<typename HandleType, typename CharacterType> | 1372 template<typename HandleType, typename CharacterType> | 
| 1373 void String::ReadFromImpl(SnapshotReader* reader, | 1373 void String::ReadFromImpl(SnapshotReader* reader, | 
| 1374                           HandleType* str_obj, | 1374                           HandleType* str_obj, | 
| 1375                           intptr_t len, | 1375                           intptr_t len, | 
| 1376                           intptr_t tags) { | 1376                           intptr_t tags) { | 
| 1377   ASSERT(reader != NULL); | 1377   ASSERT(reader != NULL); | 
| 1378   if (RawObject::IsCanonical(tags)) { | 1378   if (RawObject::IsCanonical(tags)) { | 
| 1379     // Set up canonical string object. | 1379     // Set up canonical string object. | 
| 1380     ASSERT(reader != NULL); | 1380     ASSERT(reader != NULL); | 
| 1381     CharacterType* ptr = reinterpret_cast<CharacterType*>(ZoneAllocator(len)); | 1381     CharacterType* ptr = | 
|  | 1382         Isolate::Current()->current_zone()->Alloc<CharacterType>(len); | 
| 1382     for (intptr_t i = 0; i < len; i++) { | 1383     for (intptr_t i = 0; i < len; i++) { | 
| 1383       ptr[i] = reader->Read<CharacterType>(); | 1384       ptr[i] = reader->Read<CharacterType>(); | 
| 1384     } | 1385     } | 
| 1385     *str_obj ^= Symbols::New(ptr, len); | 1386     *str_obj ^= Symbols::New(ptr, len); | 
| 1386   } else { | 1387   } else { | 
| 1387     // Set up the string object. | 1388     // Set up the string object. | 
| 1388     *str_obj = HandleType::New(len, Heap::kNew); | 1389     *str_obj = HandleType::New(len, Heap::kNew); | 
| 1389     str_obj->set_tags(tags); | 1390     str_obj->set_tags(tags); | 
| 1390     str_obj->SetHash(0);  // Will get computed when needed. | 1391     str_obj->SetHash(0);  // Will get computed when needed. | 
| 1391     for (intptr_t i = 0; i < len; i++) { | 1392     for (intptr_t i = 0; i < len; i++) { | 
| (...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2007   writer->Write<RawObject*>(ptr()->num_bracket_expressions_); | 2008   writer->Write<RawObject*>(ptr()->num_bracket_expressions_); | 
| 2008   writer->WriteObjectImpl(ptr()->pattern_); | 2009   writer->WriteObjectImpl(ptr()->pattern_); | 
| 2009   writer->WriteIntptrValue(ptr()->type_); | 2010   writer->WriteIntptrValue(ptr()->type_); | 
| 2010   writer->WriteIntptrValue(ptr()->flags_); | 2011   writer->WriteIntptrValue(ptr()->flags_); | 
| 2011 | 2012 | 
| 2012   // Do not write out the data part which is native. | 2013   // Do not write out the data part which is native. | 
| 2013 } | 2014 } | 
| 2014 | 2015 | 
| 2015 | 2016 | 
| 2016 }  // namespace dart | 2017 }  // namespace dart | 
| OLD | NEW | 
|---|