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

Side by Side Diff: runtime/vm/raw_object_snapshot.cc

Issue 10836061: Change the zone allocation api. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 4 months 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
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/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 1184 matching lines...) Expand 10 before | Expand all | Expand 10 after
1218 1218
1219 1219
1220 RawBigint* Bigint::ReadFrom(SnapshotReader* reader, 1220 RawBigint* Bigint::ReadFrom(SnapshotReader* reader,
1221 intptr_t object_id, 1221 intptr_t object_id,
1222 intptr_t tags, 1222 intptr_t tags,
1223 Snapshot::Kind kind) { 1223 Snapshot::Kind kind) {
1224 ASSERT(reader != NULL); 1224 ASSERT(reader != NULL);
1225 1225
1226 // Read in the HexCString representation of the bigint. 1226 // Read in the HexCString representation of the bigint.
1227 intptr_t len = reader->ReadIntptrValue(); 1227 intptr_t len = reader->ReadIntptrValue();
1228 char* str = reinterpret_cast<char*>(ZoneAllocator(len + 1)); 1228 char* str = Isolate::Current()->current_zone()->Alloc<char>(len + 1);
1229 str[len] = '\0'; 1229 str[len] = '\0';
1230 reader->ReadBytes(reinterpret_cast<uint8_t*>(str), len); 1230 reader->ReadBytes(reinterpret_cast<uint8_t*>(str), len);
1231 1231
1232 // Create a Bigint object from HexCString. 1232 // Create a Bigint object from HexCString.
1233 Bigint& obj = Bigint::ZoneHandle( 1233 Bigint& obj = Bigint::ZoneHandle(
1234 reader->isolate(), 1234 reader->isolate(),
1235 (kind == Snapshot::kFull) ? reader->NewBigint(str) : 1235 (kind == Snapshot::kFull) ? reader->NewBigint(str) :
1236 BigintOperations::FromHexCString(str)); 1236 BigintOperations::FromHexCString(str));
1237 1237
1238 // If it is a canonical constant make it one. 1238 // If it is a canonical constant make it one.
(...skipping 26 matching lines...) Expand all
1265 bool is_negative = false; 1265 bool is_negative = false;
1266 if (length <= 0) { 1266 if (length <= 0) {
1267 length = -length; 1267 length = -length;
1268 is_negative = true; 1268 is_negative = true;
1269 } 1269 }
1270 uword data_start = reinterpret_cast<uword>(ptr()) + sizeof(RawBigint); 1270 uword data_start = reinterpret_cast<uword>(ptr()) + sizeof(RawBigint);
1271 const char* str = BigintOperations::ToHexCString( 1271 const char* str = BigintOperations::ToHexCString(
1272 length, 1272 length,
1273 is_negative, 1273 is_negative,
1274 reinterpret_cast<void*>(data_start), 1274 reinterpret_cast<void*>(data_start),
1275 &ZoneAllocator); 1275 &BigintAllocator);
1276 bool neg = false; 1276 bool neg = false;
1277 if (*str == '-') { 1277 if (*str == '-') {
1278 neg = true; 1278 neg = true;
1279 str++; 1279 str++;
1280 } 1280 }
1281 intptr_t len = strlen(str); 1281 intptr_t len = strlen(str);
1282 ASSERT(len > 2 && str[0] == '0' && str[1] == 'x'); 1282 ASSERT(len > 2 && str[0] == '0' && str[1] == 'x');
1283 if (neg) { 1283 if (neg) {
1284 writer->WriteIntptrValue(len - 1); // Include '-' in length. 1284 writer->WriteIntptrValue(len - 1); // Include '-' in length.
1285 writer->Write<uint8_t>('-'); 1285 writer->Write<uint8_t>('-');
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1353 1353
1354 template<typename HandleType, typename CharacterType> 1354 template<typename HandleType, typename CharacterType>
1355 void String::ReadFromImpl(SnapshotReader* reader, 1355 void String::ReadFromImpl(SnapshotReader* reader,
1356 HandleType* str_obj, 1356 HandleType* str_obj,
1357 intptr_t len, 1357 intptr_t len,
1358 intptr_t tags) { 1358 intptr_t tags) {
1359 ASSERT(reader != NULL); 1359 ASSERT(reader != NULL);
1360 if (RawObject::IsCanonical(tags)) { 1360 if (RawObject::IsCanonical(tags)) {
1361 // Set up canonical string object. 1361 // Set up canonical string object.
1362 ASSERT(reader != NULL); 1362 ASSERT(reader != NULL);
1363 CharacterType* ptr = reinterpret_cast<CharacterType*>(ZoneAllocator(len)); 1363 CharacterType* ptr =
1364 Isolate::Current()->current_zone()->Alloc<CharacterType>(len);
1364 for (intptr_t i = 0; i < len; i++) { 1365 for (intptr_t i = 0; i < len; i++) {
1365 ptr[i] = reader->Read<CharacterType>(); 1366 ptr[i] = reader->Read<CharacterType>();
1366 } 1367 }
1367 *str_obj ^= Symbols::New(ptr, len); 1368 *str_obj ^= Symbols::New(ptr, len);
1368 } else { 1369 } else {
1369 // Set up the string object. 1370 // Set up the string object.
1370 *str_obj = HandleType::New(len, Heap::kNew); 1371 *str_obj = HandleType::New(len, Heap::kNew);
1371 str_obj->set_tags(tags); 1372 str_obj->set_tags(tags);
1372 str_obj->SetHash(0); // Will get computed when needed. 1373 str_obj->SetHash(0); // Will get computed when needed.
1373 for (intptr_t i = 0; i < len; i++) { 1374 for (intptr_t i = 0; i < len; i++) {
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after
1989 writer->Write<RawObject*>(ptr()->num_bracket_expressions_); 1990 writer->Write<RawObject*>(ptr()->num_bracket_expressions_);
1990 writer->WriteObjectImpl(ptr()->pattern_); 1991 writer->WriteObjectImpl(ptr()->pattern_);
1991 writer->WriteIntptrValue(ptr()->type_); 1992 writer->WriteIntptrValue(ptr()->type_);
1992 writer->WriteIntptrValue(ptr()->flags_); 1993 writer->WriteIntptrValue(ptr()->flags_);
1993 1994
1994 // Do not write out the data part which is native. 1995 // Do not write out the data part which is native.
1995 } 1996 }
1996 1997
1997 1998
1998 } // namespace dart 1999 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698