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

Side by Side Diff: vm/snapshot.h

Issue 9021042: Make snapshots 32 or 64 bit compliant by using Write<int64_t> and Read<int64_t> for intptr_t type... (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: '' Created 8 years, 12 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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 #ifndef VM_SNAPSHOT_H_ 5 #ifndef VM_SNAPSHOT_H_
6 #define VM_SNAPSHOT_H_ 6 #define VM_SNAPSHOT_H_
7 7
8 #include "vm/allocation.h" 8 #include "vm/allocation.h"
9 #include "vm/assert.h" 9 #include "vm/assert.h"
10 #include "vm/bitfield.h" 10 #include "vm/bitfield.h"
(...skipping 22 matching lines...) Expand all
33 // Serialized object header encoding is as follows: 33 // Serialized object header encoding is as follows:
34 // - Smi: the Smi value is written as is (last bit is not tagged). 34 // - Smi: the Smi value is written as is (last bit is not tagged).
35 // - VM internal type (from VM isolate): (index of type in vm isolate | 0x3) 35 // - VM internal type (from VM isolate): (index of type in vm isolate | 0x3)
36 // - Object that has already been written: (negative id in stream | 0x3) 36 // - Object that has already been written: (negative id in stream | 0x3)
37 // - Object that is seen for the first time (inlined in the stream): 37 // - Object that is seen for the first time (inlined in the stream):
38 // (a unique id for this object | 0x1) 38 // (a unique id for this object | 0x1)
39 enum SerializedHeaderType { 39 enum SerializedHeaderType {
40 kInlined = 0x1, 40 kInlined = 0x1,
41 kObjectId = 0x3, 41 kObjectId = 0x3,
42 }; 42 };
43 43 static const int8_t kHeaderTagBits = 2;
44 static const int8_t kObjectIdTagBits = (kBitsPerWord - kHeaderTagBits);
45 static const intptr_t kMaxObjectId = (LONG_MAX >> kHeaderTagBits);
44 46
45 typedef uint8_t* (*ReAlloc)(uint8_t* ptr, intptr_t old_size, intptr_t new_size); 47 typedef uint8_t* (*ReAlloc)(uint8_t* ptr, intptr_t old_size, intptr_t new_size);
46 48
47 49 class SerializedHeaderTag : public BitField<enum SerializedHeaderType,
48 class SerializedHeaderTag : public BitField<enum SerializedHeaderType, 0, 2> { 50 0,
51 kHeaderTagBits> {
49 }; 52 };
50 53
51 54
52 class SerializedHeaderData : public BitField<intptr_t, 2, 30> { 55 class SerializedHeaderData : public BitField<intptr_t,
56 kHeaderTagBits,
57 kObjectIdTagBits> {
53 }; 58 };
54 59
55 60
56 // Structure capturing the raw snapshot. 61 // Structure capturing the raw snapshot.
57 class Snapshot { 62 class Snapshot {
58 public: 63 public:
59 enum Kind { 64 enum Kind {
60 kFull = 0, // Full snapshot of the current dart heap. 65 kFull = 0, // Full snapshot of the current dart heap.
61 kScript, // A partial snapshot of only the application script. 66 kScript, // A partial snapshot of only the application script.
62 kMessage, // A partial snapshot used only for isolate messaging. 67 kMessage, // A partial snapshot used only for isolate messaging.
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 backward_references_() { } 289 backward_references_() { }
285 ~SnapshotReader() { } 290 ~SnapshotReader() { }
286 291
287 // Reads raw data (for basic types). 292 // Reads raw data (for basic types).
288 // sizeof(T) must be in {1,2,4,8}. 293 // sizeof(T) must be in {1,2,4,8}.
289 template <typename T> 294 template <typename T>
290 T Read() { 295 T Read() {
291 return ReadStream::Raw<sizeof(T), T>::Read(&stream_); 296 return ReadStream::Raw<sizeof(T), T>::Read(&stream_);
292 } 297 }
293 298
299 // Reads an intptr_t type value.
300 intptr_t ReadIntptrValue() {
301 int64_t value = Read<int64_t>();
302 ASSERT((value <= LONG_MAX) && (value >= LONG_MIN));
Ivan Posva 2011/12/27 22:27:59 As discussed we should use the correct constant fo
siva 2011/12/27 23:47:20 Done.
303 return value;
304 }
305
294 Heap* heap() const { return heap_; } 306 Heap* heap() const { return heap_; }
295 ObjectStore* object_store() const { return object_store_; } 307 ObjectStore* object_store() const { return object_store_; }
296 308
297 // Reads an object. 309 // Reads an object.
298 RawObject* ReadObject(); 310 RawObject* ReadObject();
299 311
300 RawClass* ReadClassId(intptr_t object_id); 312 RawClass* ReadClassId(intptr_t object_id);
301 313
302 // Add object to backward references. 314 // Add object to backward references.
303 void AddBackwardReference(intptr_t id, Object* obj); 315 void AddBackwardReference(intptr_t id, Object* obj);
(...skipping 30 matching lines...) Expand all
334 // Size of the snapshot. 346 // Size of the snapshot.
335 intptr_t BytesWritten() const { return stream_.bytes_written(); } 347 intptr_t BytesWritten() const { return stream_.bytes_written(); }
336 348
337 // Writes raw data to the stream (basic type). 349 // Writes raw data to the stream (basic type).
338 // sizeof(T) must be in {1,2,4,8}. 350 // sizeof(T) must be in {1,2,4,8}.
339 template <typename T> 351 template <typename T>
340 void Write(T value) { 352 void Write(T value) {
341 WriteStream::Raw<sizeof(T), T>::Write(&stream_, value); 353 WriteStream::Raw<sizeof(T), T>::Write(&stream_, value);
342 } 354 }
343 355
356 // Writes an intptr_t type value out.
357 void WriteIntptrValue(intptr_t value) {
358 Write<int64_t>(value);
359 }
360
344 // Write an object that is serialized as an Id (singleton, object store, 361 // Write an object that is serialized as an Id (singleton, object store,
345 // or an object that was already serialized before). 362 // or an object that was already serialized before).
346 void WriteIndexedObject(intptr_t object_id) { 363 void WriteIndexedObject(intptr_t object_id) {
347 WriteSerializationMarker(kObjectId, object_id); 364 WriteSerializationMarker(kObjectId, object_id);
348 } 365 }
349 366
350 // Write out object header value. 367 // Write out object header value.
351 void WriteObjectHeader(intptr_t class_id, intptr_t tags) { 368 void WriteObjectHeader(intptr_t class_id, intptr_t tags) {
352 // Write out the class information. 369 // Write out the class information.
353 WriteIndexedObject(class_id); 370 WriteIndexedObject(class_id);
354 // Write out the tags information. 371 // Write out the tags information.
355 Write<intptr_t>(tags); 372 WriteIntptrValue(tags);
356 } 373 }
357 374
358 // Write serialization header information for an object. 375 // Write serialization header information for an object.
359 void WriteSerializationMarker(SerializedHeaderType type, intptr_t id) { 376 void WriteSerializationMarker(SerializedHeaderType type, intptr_t id) {
360 uword value = 0; 377 ASSERT(id <= kMaxObjectId);
378 intptr_t value = 0;
361 value = SerializedHeaderTag::update(type, value); 379 value = SerializedHeaderTag::update(type, value);
362 value = SerializedHeaderData::update(id, value); 380 value = SerializedHeaderData::update(id, value);
363 Write<uword>(value); 381 WriteIntptrValue(value);
364 } 382 }
365 383
366 // Finalize the serialized buffer by filling in the header information 384 // Finalize the serialized buffer by filling in the header information
367 // which comprises of a flag(snaphot kind) and the length of 385 // which comprises of a flag(snaphot kind) and the length of
368 // serialzed bytes. 386 // serialzed bytes.
369 void FinalizeBuffer(Snapshot::Kind kind) { 387 void FinalizeBuffer(Snapshot::Kind kind) {
370 int32_t* data = reinterpret_cast<int32_t*>(stream_.buffer()); 388 int32_t* data = reinterpret_cast<int32_t*>(stream_.buffer());
371 data[Snapshot::kLengthIndex] = stream_.bytes_written(); 389 data[Snapshot::kLengthIndex] = stream_.bytes_written();
372 data[Snapshot::kSnapshotFlagIndex] = kind; 390 data[Snapshot::kSnapshotFlagIndex] = kind;
373 } 391 }
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 509
492 private: 510 private:
493 SnapshotWriter* writer_; 511 SnapshotWriter* writer_;
494 512
495 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); 513 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor);
496 }; 514 };
497 515
498 } // namespace dart 516 } // namespace dart
499 517
500 #endif // VM_SNAPSHOT_H_ 518 #endif // VM_SNAPSHOT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698