My favorites | Sign in
Project Home Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

#include "vm/snapshot.h"

#include "platform/assert.h"
#include "vm/bigint_operations.h"
#include "vm/bootstrap.h"
#include "vm/exceptions.h"
#include "vm/heap.h"
#include "vm/object.h"
#include "vm/object_store.h"

namespace dart {

enum {
kInstanceId = ObjectStore::kMaxId,
kMaxPredefinedObjectIds,
};
static const int kNumInitialReferencesInFullSnapshot = 160 * KB;
static const int kNumInitialReferences = 4;


static bool IsSingletonClassId(intptr_t index) {
// Check if this is a singleton object class which is shared by all isolates.
return (index >= Object::kClassClass && index < Object::kMaxId);
}


static bool IsObjectStoreClassId(intptr_t index) {
// Check if this is a class which is stored in the object store.
return (index >= ObjectStore::kObjectClass && index < ObjectStore::kMaxId);
}


static bool IsObjectStoreTypeId(intptr_t index) {
// Check if this is a type which is stored in the object store.
return (index >= ObjectStore::kObjectType &&
index <= ObjectStore::kListInterface);
}


// TODO(5411462): Temporary setup of snapshot for testing purposes,
// the actual creation of a snapshot maybe done differently.
const Snapshot* Snapshot::SetupFromBuffer(const void* raw_memory) {
ASSERT(raw_memory != NULL);
ASSERT(kHeaderSize == sizeof(Snapshot));
ASSERT(kLengthIndex == length_offset());
ASSERT((kSnapshotFlagIndex * sizeof(int32_t)) == kind_offset());
ASSERT((kHeapObjectTag & kInlined));
ASSERT((kHeapObjectTag & kObjectId));
ASSERT((kObjectAlignmentMask & kObjectId) == kObjectId);
const Snapshot* snapshot = reinterpret_cast<const Snapshot*>(raw_memory);
return snapshot;
}


RawSmi* BaseReader::ReadAsSmi() {
intptr_t value = ReadIntptrValue();
ASSERT((value & kSmiTagMask) == 0);
return reinterpret_cast<RawSmi*>(value);
}


intptr_t BaseReader::ReadSmiValue() {
return Smi::Value(ReadAsSmi());
}


SnapshotReader::SnapshotReader(const Snapshot* snapshot, Isolate* isolate)
: BaseReader(snapshot->content(), snapshot->length()),
kind_(snapshot->kind()),
isolate_(isolate),
cls_(Class::Handle()),
obj_(Object::Handle()),
str_(String::Handle()),
library_(Library::Handle()),
type_(AbstractType::Handle()),
type_arguments_(AbstractTypeArguments::Handle()),
backward_references_((snapshot->kind() == Snapshot::kFull) ?
kNumInitialReferencesInFullSnapshot :
kNumInitialReferences) {
}


RawObject* SnapshotReader::ReadObject() {
int64_t value = Read<int64_t>();
if ((value & kSmiTagMask) == 0) {
return Integer::New((value >> kSmiTagShift));
}
ASSERT((value <= kIntptrMax) && (value >= kIntptrMin));
return ReadObjectImpl(value);
}


RawClass* SnapshotReader::ReadClassId(intptr_t object_id) {
ASSERT(kind_ != Snapshot::kFull);
// Read the class header information and lookup the class.
intptr_t class_header = ReadIntptrValue();
ASSERT((class_header & kSmiTagMask) != 0);
Class& cls = Class::ZoneHandle(isolate(), Class::null());
cls ^= LookupInternalClass(class_header);
AddBackwardReference(object_id, &cls);
if (cls.IsNull()) {
// Read the library/class information and lookup the class.
str_ ^= ReadObjectImpl(class_header);
library_ = Library::LookupLibrary(str_);
ASSERT(!library_.IsNull());
str_ ^= ReadObject();
cls ^= library_.LookupClass(str_);
}
ASSERT(!cls.IsNull());
return cls.raw();
}


void SnapshotReader::AddBackwardReference(intptr_t id, Object* obj) {
ASSERT((id - kMaxPredefinedObjectIds) == backward_references_.length());
backward_references_.Add(obj);
}


void SnapshotReader::ReadFullSnapshot() {
ASSERT(kind_ == Snapshot::kFull);
Isolate* isolate = Isolate::Current();
ASSERT(isolate != NULL);
ObjectStore* object_store = isolate->object_store();
ASSERT(object_store != NULL);
NoGCScope no_gc;

// TODO(asiva): Add a check here to ensure we have the right heap
// size for the full snapshot being read.

// Read in all the objects stored in the object store.
intptr_t num_flds = (object_store->to() - object_store->from());
for (intptr_t i = 0; i <= num_flds; i++) {
*(object_store->from() + i) = ReadObject();
}

// Setup native resolver for bootstrap impl.
Bootstrap::SetupNativeResolver();
}


#define ALLOC_NEW_OBJECT_WITH_LEN(type, class_obj, length) \
ASSERT(kind_ == Snapshot::kFull); \
ASSERT(isolate()->no_gc_scope_depth() != 0); \
cls_ = class_obj; \
Raw##type* obj = reinterpret_cast<Raw##type*>( \
AllocateUninitialized(cls_, type::InstanceSize(length))); \
obj->ptr()->length_ = Smi::New(length); \
return obj; \


RawArray* SnapshotReader::NewArray(intptr_t len) {
ALLOC_NEW_OBJECT_WITH_LEN(Array, object_store()->array_class(), len);
}


RawImmutableArray* SnapshotReader::NewImmutableArray(intptr_t len) {
ALLOC_NEW_OBJECT_WITH_LEN(ImmutableArray,
object_store()->immutable_array_class(),
len);
}


RawOneByteString* SnapshotReader::NewOneByteString(intptr_t len) {
ALLOC_NEW_OBJECT_WITH_LEN(OneByteString,
object_store()->one_byte_string_class(),
len);
}


RawTwoByteString* SnapshotReader::NewTwoByteString(intptr_t len) {
ALLOC_NEW_OBJECT_WITH_LEN(TwoByteString,
object_store()->two_byte_string_class(),
len);
}


RawFourByteString* SnapshotReader::NewFourByteString(intptr_t len) {
ALLOC_NEW_OBJECT_WITH_LEN(FourByteString,
object_store()->four_byte_string_class(),
len);
}


RawTypeArguments* SnapshotReader::NewTypeArguments(intptr_t len) {
ALLOC_NEW_OBJECT_WITH_LEN(TypeArguments,
Object::type_arguments_class(),
len);
}


RawTokenStream* SnapshotReader::NewTokenStream(intptr_t len) {
ALLOC_NEW_OBJECT_WITH_LEN(TokenStream,
Object::token_stream_class(),
len);
}


RawContext* SnapshotReader::NewContext(intptr_t num_variables) {
ASSERT(kind_ == Snapshot::kFull);
ASSERT(isolate()->no_gc_scope_depth() != 0);
cls_ = Object::context_class();
RawContext* obj = reinterpret_cast<RawContext*>(
AllocateUninitialized(cls_, Context::InstanceSize(num_variables)));
obj->ptr()->num_variables_ = num_variables;
return obj;
}


RawClass* SnapshotReader::NewClass(int value) {
ASSERT(kind_ == Snapshot::kFull);
ASSERT(isolate()->no_gc_scope_depth() != 0);
ObjectKind object_kind = static_cast<ObjectKind>(value);
if ((object_kind == kInstance || object_kind == kClosure)) {
cls_ = Object::class_class();
RawClass* obj = reinterpret_cast<RawClass*>(
AllocateUninitialized(cls_, Class::InstanceSize()));
if (object_kind == kInstance) {
Instance fake;
obj->ptr()->handle_vtable_ = fake.vtable();
} else {
Closure fake;
obj->ptr()->handle_vtable_ = fake.vtable();
}
cls_ = obj;
cls_.set_instance_kind(object_kind);
cls_.set_index(kIllegalObjectKind);
isolate()->class_table()->Register(cls_);
return cls_.raw();
}
return Class::GetClass(object_kind);
}


RawMint* SnapshotReader::NewMint(int64_t value) {
ASSERT(kind_ == Snapshot::kFull);
ASSERT(isolate()->no_gc_scope_depth() != 0);
cls_ = object_store()->mint_class();
RawMint* obj = reinterpret_cast<RawMint*>(
AllocateUninitialized(cls_, Mint::InstanceSize()));
obj->ptr()->value_ = value;
return obj;
}


RawBigint* SnapshotReader::NewBigint(const char* hex_string) {
ASSERT(kind_ == Snapshot::kFull);
ASSERT(isolate()->no_gc_scope_depth() != 0);
cls_ = object_store()->bigint_class();
intptr_t bigint_length = BigintOperations::ComputeChunkLength(hex_string);
RawBigint* obj = reinterpret_cast<RawBigint*>(
AllocateUninitialized(cls_, Bigint::InstanceSize(bigint_length)));
obj->ptr()->allocated_length_ = bigint_length;
obj->ptr()->signed_length_ = bigint_length;
BigintOperations::FromHexCString(hex_string, Bigint::Handle(obj));
return obj;
}


RawDouble* SnapshotReader::NewDouble(double value) {
ASSERT(kind_ == Snapshot::kFull);
ASSERT(isolate()->no_gc_scope_depth() != 0);
cls_ = object_store()->double_class();
RawDouble* obj = reinterpret_cast<RawDouble*>(
AllocateUninitialized(cls_, Double::InstanceSize()));
obj->ptr()->value_ = value;
return obj;
}


#define ALLOC_NEW_OBJECT(type, class_obj) \
ASSERT(kind_ == Snapshot::kFull); \
ASSERT(isolate()->no_gc_scope_depth() != 0); \
cls_ = class_obj; \
return reinterpret_cast<Raw##type*>( \
AllocateUninitialized(cls_, type::InstanceSize())); \


RawUnresolvedClass* SnapshotReader::NewUnresolvedClass() {
ALLOC_NEW_OBJECT(UnresolvedClass, Object::unresolved_class_class());
}


RawType* SnapshotReader::NewType() {
ALLOC_NEW_OBJECT(Type, Object::type_class());
}


RawTypeParameter* SnapshotReader::NewTypeParameter() {
ALLOC_NEW_OBJECT(TypeParameter, Object::type_parameter_class());
}


RawFunction* SnapshotReader::NewFunction() {
ALLOC_NEW_OBJECT(Function, Object::function_class());
}


RawField* SnapshotReader::NewField() {
ALLOC_NEW_OBJECT(Field, Object::field_class());
}


RawLibrary* SnapshotReader::NewLibrary() {
ALLOC_NEW_OBJECT(Library, Object::library_class());
}


RawLibraryPrefix* SnapshotReader::NewLibraryPrefix() {
ALLOC_NEW_OBJECT(LibraryPrefix, Object::library_prefix_class());
}


RawScript* SnapshotReader::NewScript() {
ALLOC_NEW_OBJECT(Script, Object::script_class());
}


RawLiteralToken* SnapshotReader::NewLiteralToken() {
ALLOC_NEW_OBJECT(LiteralToken, Object::literal_token_class());
}


RawGrowableObjectArray* SnapshotReader::NewGrowableObjectArray() {
ALLOC_NEW_OBJECT(GrowableObjectArray,
object_store()->growable_object_array_class());
}


RawClass* SnapshotReader::LookupInternalClass(intptr_t class_header) {
SerializedHeaderType header_type = SerializedHeaderTag::decode(class_header);

// If the header is an object Id, lookup singleton VM classes or classes
// stored in the object store.
if (header_type == kObjectId) {
intptr_t header_value = SerializedHeaderData::decode(class_header);
if (IsObjectStoreClassId(header_value)) {
return object_store()->GetClass(header_value);
} else if (IsSingletonClassId(header_value)) {
return Object::GetSingletonClass(header_value); // return the singleton.
}
}
return Class::null();
}


RawObject* SnapshotReader::AllocateUninitialized(const Class& cls,
intptr_t size) {
ASSERT(isolate()->no_gc_scope_depth() != 0);
ASSERT(Utils::IsAligned(size, kObjectAlignment));
Heap* heap = isolate()->heap();

uword address = heap->TryAllocate(size, Heap::kOld);
if (address == 0) {
// Use the preallocated out of memory exception to avoid calling
// into dart code or allocating any code.
const Instance& exception =
Instance::Handle(object_store()->out_of_memory());
Exceptions::Throw(exception);
UNREACHABLE();
}
RawObject* raw_obj = reinterpret_cast<RawObject*>(address + kHeapObjectTag);
raw_obj->ptr()->class_ = cls.raw();
uword tags = 0;
intptr_t index = cls.index();
ASSERT(index != kIllegalObjectKind);
tags = RawObject::ClassTag::update(index, tags);
tags = RawObject::SizeTag::update(size, tags);
raw_obj->ptr()->tags_ = tags;
return raw_obj;
}


RawObject* SnapshotReader::ReadObjectImpl(intptr_t header) {
SerializedHeaderType header_type = SerializedHeaderTag::decode(header);
intptr_t header_value = SerializedHeaderData::decode(header);

if (header_type == kObjectId) {
return ReadIndexedObject(header_value);
}
ASSERT(header_type == kInlined);
return ReadInlinedObject(header_value);
}


RawObject* SnapshotReader::ReadIndexedObject(intptr_t object_id) {
if (object_id == Object::kNullObject) {
// This is a singleton null object, return it.
return Object::null();
}
if (object_id == Object::kSentinelObject) {
return Object::sentinel();
}
if (IsSingletonClassId(object_id)) {
return Object::GetSingletonClass(object_id); // return singleton object.
} else if (IsObjectStoreClassId(object_id)) {
return object_store()->GetClass(object_id);
} else if (object_id == ObjectStore::kTrueValue) {
return object_store()->true_value();
} else if (object_id == ObjectStore::kFalseValue) {
return object_store()->false_value();
} else if (kind_ != Snapshot::kFull) {
if (IsObjectStoreTypeId(object_id)) {
return object_store()->GetType(object_id); // return type object.
}
}

ASSERT(object_id >= kMaxPredefinedObjectIds);
intptr_t index = object_id - kMaxPredefinedObjectIds;
ASSERT(index < backward_references_.length());
return backward_references_[index]->raw();
}


RawObject* SnapshotReader::ReadInlinedObject(intptr_t object_id) {
// Read the class header information and lookup the class.
intptr_t class_header = ReadIntptrValue();
intptr_t tags = ReadIntptrValue();
if (SerializedHeaderData::decode(class_header) == kInstanceId) {
// Object is regular dart instance.
Instance& result = Instance::ZoneHandle(isolate(), Instance::null());
AddBackwardReference(object_id, &result);

cls_ ^= ReadObject();
ASSERT(!cls_.IsNull());
intptr_t instance_size = cls_.instance_size();
ASSERT(instance_size > 0);
// Allocate the instance and read in all the fields for the object.
if (kind_ == Snapshot::kFull) {
result ^= AllocateUninitialized(cls_, instance_size);
} else {
result ^= Object::Allocate(cls_, instance_size, Heap::kNew);
}
intptr_t offset = Object::InstanceSize();
while (offset < instance_size) {
obj_ = ReadObject();
result.SetFieldAtOffset(offset, obj_);
offset += kWordSize;
}
if (kind_ == Snapshot::kFull) {
result.SetCreatedFromSnapshot();
} else if (result.IsCanonical()) {
result = result.Canonicalize();
}
return result.raw();
} else {
ASSERT((class_header & kSmiTagMask) != 0);
cls_ ^= LookupInternalClass(class_header);
ASSERT(!cls_.IsNull());
}
switch (cls_.instance_kind()) {
#define SNAPSHOT_READ(clazz) \
case clazz::kInstanceKind: { \
obj_ = clazz::ReadFrom(this, object_id, tags, kind_); \
break; \
}
CLASS_LIST_NO_OBJECT(SNAPSHOT_READ)
#undef SNAPSHOT_READ
default: UNREACHABLE(); break;
}
if (kind_ == Snapshot::kFull) {
obj_.SetCreatedFromSnapshot();
}
return obj_.raw();
}


void SnapshotWriter::WriteObject(RawObject* rawobj) {
// An object is written in one of the following ways:
// - Smi: the Smi value is written as is (last bit is not tagged).
// - VM internal class (from VM isolate): (index of class in vm isolate | 0x3)
// - Object that has already been written: (negative id in stream | 0x3)
// - Object that is seen for the first time (inlined as follows):
// (object size in multiples of kObjectAlignment | 0x1)
// serialized fields of the object
// ......

NoGCScope no_gc;
// writing a snap shot.

// First check if it is a Smi (i.e not a heap object).
if (!rawobj->IsHeapObject()) {
Write<int64_t>(reinterpret_cast<intptr_t>(rawobj));
return;
}

// Check if it is a singleton null object which is shared by all isolates.
if (rawobj == Object::null()) {
WriteIndexedObject(Object::kNullObject);
return;
}

// Check if it is a singleton sentinel object which is shared by all isolates.
if (rawobj == Object::sentinel()) {
WriteIndexedObject(Object::kSentinelObject);
return;
}

// Check if it is a singleton class object which is shared by
// all isolates.
RawClass* raw_class = reinterpret_cast<RawClass*>(rawobj);
intptr_t index = Object::GetSingletonClassIndex(raw_class);
if (index != Object::kInvalidIndex) {
WriteIndexedObject(index);
return;
}

// Check if it is a singleton boolean true value.
if (rawobj == object_store()->true_value()) {
WriteIndexedObject(ObjectStore::kTrueValue);
return;
}

// Check if it is a singleton boolean false value.
if (rawobj == object_store()->false_value()) {
WriteIndexedObject(ObjectStore::kFalseValue);
return;
}

// Check if it is a code object in that case just write a Null object
// as we do not want code objects in the snapshot.
if (rawobj->ptr()->class_ == Object::code_class()) {
WriteIndexedObject(Object::kNullObject);
return;
}

// Check if classes are not being serialized and it is preinitialized type.
if (kind_ != Snapshot::kFull) {
RawType* raw_type = reinterpret_cast<RawType*>(rawobj);
index = object_store()->GetTypeIndex(raw_type);
if (index != ObjectStore::kInvalidIndex) {
WriteIndexedObject(index);
return;
}
}

// Now write the object out inline in the stream.
WriteInlinedObject(rawobj);
}


void SnapshotWriter::UnmarkAll() {
NoGCScope no_gc;
for (intptr_t i = 0; i < forward_list_.length(); i++) {
RawObject* raw = forward_list_[i]->raw();
raw->ptr()->class_ = forward_list_[i]->cls(); // Restore original class.
}
}


void SnapshotWriter::WriteFullSnapshot() {
ASSERT(kind_ == Snapshot::kFull);
Isolate* isolate = Isolate::Current();
ASSERT(isolate != NULL);
ObjectStore* object_store = isolate->object_store();
ASSERT(object_store != NULL);

// Write out all the objects in the object store of the isolate which
// is the root set for all dart allocated objects at this point.
SnapshotWriterVisitor visitor(this);
object_store->VisitObjectPointers(&visitor);

// Finalize the snapshot buffer.
FinalizeBuffer();
}


intptr_t SnapshotWriter::MarkObject(RawObject* raw, RawClass* cls) {
NoGCScope no_gc;
intptr_t object_id = forward_list_.length() + kMaxPredefinedObjectIds;
ASSERT(object_id <= kMaxObjectId);
uword value = 0;
value = SerializedHeaderTag::update(kObjectId, value);
value = SerializedHeaderData::update(object_id, value);
raw->ptr()->class_ = reinterpret_cast<RawClass*>(value);
ForwardObjectNode* node = new ForwardObjectNode(raw, cls);
ASSERT(node != NULL);
forward_list_.Add(node);
return object_id;
}


void SnapshotWriter::WriteInlinedObject(RawObject* raw) {
NoGCScope no_gc;
RawClass* cls = raw->ptr()->class_;

// Check if object has already been serialized, in that
// case just write the object id out.
if (SerializedHeaderTag::decode(reinterpret_cast<uword>(cls)) == kObjectId) {
intptr_t id = SerializedHeaderData::decode(reinterpret_cast<intptr_t>(cls));
WriteIndexedObject(id);
return;
}

// Object is being serialized, add it to the forward ref list and mark
// it so that future references to this object in the snapshot will use
// an object id, instead of trying to serialize it again.
intptr_t object_id = MarkObject(raw, cls);

ObjectKind kind = cls->ptr()->instance_kind_;
if (kind == Instance::kInstanceKind) {
// Object is regular dart instance.
// TODO(5411462): figure out what we need to do if an object with native
// fields is serialized (throw exception or serialize a null object).
ASSERT(cls->ptr()->num_native_fields_ == 0);
intptr_t instance_size = cls->ptr()->instance_size_;
ASSERT(instance_size != 0);

// Write out the serialization header value for this object.
WriteSerializationMarker(kInlined, object_id);

// Indicate this is an instance object.
WriteIntptrValue(SerializedHeaderData::encode(kInstanceId));

// Write out the tags.
WriteIntptrValue(raw->ptr()->tags_);

// Write out the class information for this object.
WriteObject(cls);

// Write out all the fields for the object.
intptr_t offset = Object::InstanceSize();
while (offset < instance_size) {
WriteObject(*reinterpret_cast<RawObject**>(
reinterpret_cast<uword>(raw->ptr()) + offset));
offset += kWordSize;
}
return;
}
switch (kind) {
#define SNAPSHOT_WRITE(clazz) \
case clazz::kInstanceKind: { \
Raw##clazz* raw_obj = reinterpret_cast<Raw##clazz*>(raw); \
raw_obj->WriteTo(this, object_id, kind_); \
return; \
} \

CLASS_LIST_NO_OBJECT(SNAPSHOT_WRITE)
#undef SNAPSHOT_WRITE
default: break;
}
UNREACHABLE();
}


void SnapshotWriter::WriteClassId(RawClass* cls) {
ASSERT(kind_ != Snapshot::kFull);
int id = object_store()->GetClassIndex(cls);
if (IsSingletonClassId(id) || IsObjectStoreClassId(id)) {
WriteIndexedObject(id);
} else {
// TODO(5411462): Should restrict this to only core-lib classes in this
// case.
// Write out the class and tags information.
WriteObjectHeader(Object::kClassClass, cls->ptr()->tags_);

// Write out the library url and class name.
RawLibrary* library = cls->ptr()->library_;
ASSERT(library != Library::null());
WriteObject(library->ptr()->url_);
WriteObject(cls->ptr()->name_);
}
}


void ScriptSnapshotWriter::WriteScriptSnapshot(const Library& lib) {
ASSERT(kind() == Snapshot::kScript);

// Write out the library object.
WriteObject(lib.raw());

// Finalize the snapshot buffer.
FinalizeBuffer();
}


void SnapshotWriterVisitor::VisitPointers(RawObject** first, RawObject** last) {
for (RawObject** current = first; current <= last; current++) {
RawObject* raw_obj = *current;
writer_->WriteObject(raw_obj);
}
}

} // namespace dart

Change log

r7237 by dgr...@google.com on May 2, 2012   Diff
result of

 svn merge -r 7144:7232 https://dart.googl
ecode.com/svn/branches/bleeding_edge trunk

Go to: 

Older revisions

r7150 by dgr...@google.com on Apr 30, 2012   Diff
result of

svn merge -r 6943:7144 https://dart.go
oglecode.com/svn/branches/bleeding_edg
e trunk
...
r5857 by dgr...@google.com on Mar 26, 2012   Diff
result of

svn merge -r 5780:5848 https://dart.go
oglecode.com/svn/branches/bleeding_edg
e
...
r5173 by dgr...@google.com on Mar 8, 2012   Diff
Result of

svn merge -r 4953:5169 https://dart.go
oglecode.com/svn/branches/bleeding_edg
e trunk
...
All revisions of this file

File info

Size: 22720 bytes, 688 lines
Powered by Google Project Hosting