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

Side by Side Diff: runtime/vm/snapshot.h

Issue 343803002: Finishes removing intptr_t from raw object fields. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 3 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 #ifndef VM_SNAPSHOT_H_ 5 #ifndef VM_SNAPSHOT_H_
6 #define VM_SNAPSHOT_H_ 6 #define VM_SNAPSHOT_H_
7 7
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/allocation.h" 9 #include "vm/allocation.h"
10 #include "vm/bitfield.h" 10 #include "vm/bitfield.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 // using ths unique ID assigned to them). 85 // using ths unique ID assigned to them).
86 // - Reference to object that has already been written: (object id | 0x3) 86 // - Reference to object that has already been written: (object id | 0x3)
87 // This valus is serialized as a positive number. 87 // This valus is serialized as a positive number.
88 // - Object that is seen for the first time (inlined in the stream): 88 // - Object that is seen for the first time (inlined in the stream):
89 // (a unique id for this object | 0x1) 89 // (a unique id for this object | 0x1)
90 enum SerializedHeaderType { 90 enum SerializedHeaderType {
91 kInlined = 0x1, 91 kInlined = 0x1,
92 kObjectId = 0x3, 92 kObjectId = 0x3,
93 }; 93 };
94 static const int8_t kHeaderTagBits = 2; 94 static const int8_t kHeaderTagBits = 2;
95 static const int8_t kObjectIdBits = (kBitsPerWord - (kHeaderTagBits + 1)); 95 static const int8_t kObjectIdBits = (kBitsPerInt32 - (kHeaderTagBits + 1));
96 static const intptr_t kMaxObjectId = (kUwordMax >> (kHeaderTagBits + 1)); 96 static const intptr_t kMaxObjectId = (kMaxUint32 >> (kHeaderTagBits + 1));
97 97
98 98
99 class SerializedHeaderTag : public BitField<enum SerializedHeaderType, 99 class SerializedHeaderTag : public BitField<enum SerializedHeaderType,
100 0, 100 0,
101 kHeaderTagBits> { 101 kHeaderTagBits> {
102 }; 102 };
103 103
104 104
105 class SerializedHeaderData : public BitField<intptr_t, 105 class SerializedHeaderData : public BitField<intptr_t,
106 kHeaderTagBits, 106 kHeaderTagBits,
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 class BaseReader { 179 class BaseReader {
180 public: 180 public:
181 BaseReader(const uint8_t* buffer, intptr_t size) : stream_(buffer, size) {} 181 BaseReader(const uint8_t* buffer, intptr_t size) : stream_(buffer, size) {}
182 // Reads raw data (for basic types). 182 // Reads raw data (for basic types).
183 // sizeof(T) must be in {1,2,4,8}. 183 // sizeof(T) must be in {1,2,4,8}.
184 template <typename T> 184 template <typename T>
185 T Read() { 185 T Read() {
186 return ReadStream::Raw<sizeof(T), T>::Read(&stream_); 186 return ReadStream::Raw<sizeof(T), T>::Read(&stream_);
187 } 187 }
188 188
189 // Reads an intptr_t type value.
190 intptr_t ReadIntptrValue() {
191 int64_t value = Read<int64_t>();
192 ASSERT((value <= kIntptrMax) && (value >= kIntptrMin));
193 return static_cast<intptr_t>(value);
194 }
195
196 intptr_t ReadRawPointerValue() { 189 intptr_t ReadRawPointerValue() {
197 int64_t value = Read<int64_t>(); 190 int64_t value = Read<int64_t>();
198 return static_cast<intptr_t>(value); 191 return static_cast<intptr_t>(value);
199 } 192 }
200 193
201 void ReadBytes(uint8_t* addr, intptr_t len) { 194 void ReadBytes(uint8_t* addr, intptr_t len) {
202 stream_.ReadBytes(addr, len); 195 stream_.ReadBytes(addr, len);
203 } 196 }
204 197
205 double ReadDouble() { 198 double ReadDouble() {
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 // Size of the snapshot. 414 // Size of the snapshot.
422 intptr_t BytesWritten() const { return stream_.bytes_written(); } 415 intptr_t BytesWritten() const { return stream_.bytes_written(); }
423 416
424 // Writes raw data to the stream (basic type). 417 // Writes raw data to the stream (basic type).
425 // sizeof(T) must be in {1,2,4,8}. 418 // sizeof(T) must be in {1,2,4,8}.
426 template <typename T> 419 template <typename T>
427 void Write(T value) { 420 void Write(T value) {
428 WriteStream::Raw<sizeof(T), T>::Write(&stream_, value); 421 WriteStream::Raw<sizeof(T), T>::Write(&stream_, value);
429 } 422 }
430 423
431 // Writes an intptr_t type value out.
432 void WriteIntptrValue(intptr_t value) {
433 ASSERT((value >= kMinInt32) && (value <= kMaxInt32));
434 Write<int64_t>(value);
435 }
436
437 void WriteRawPointerValue(intptr_t value) { 424 void WriteRawPointerValue(intptr_t value) {
438 Write<int64_t>(value); 425 Write<int64_t>(value);
439 } 426 }
440 427
441 // Write an object that is serialized as an Id (singleton in object store, 428 // Write an object that is serialized as an Id (singleton in object store,
442 // or an object that was already serialized before). 429 // or an object that was already serialized before).
443 void WriteIndexedObject(intptr_t object_id) { 430 void WriteIndexedObject(intptr_t object_id) {
444 ASSERT(object_id <= kMaxObjectId); 431 ASSERT(object_id <= kMaxObjectId);
445 intptr_t value = 0; 432 intptr_t value = 0;
446 value = SerializedHeaderTag::update(kObjectId, value); 433 value = SerializedHeaderTag::update(kObjectId, value);
447 value = SerializedHeaderData::update(object_id, value); 434 value = SerializedHeaderData::update(object_id, value);
448 WriteIntptrValue(value); 435 Write<int32_t>(value);
449 } 436 }
450 437
451 // Write a VM Isolateobject that is serialized as an Id. 438 // Write a VM Isolateobject that is serialized as an Id.
452 void WriteVMIsolateObject(intptr_t object_id) { 439 void WriteVMIsolateObject(intptr_t object_id) {
453 ASSERT(object_id <= kMaxObjectId); 440 ASSERT(object_id <= kMaxObjectId);
454 intptr_t value = 0; 441 intptr_t value = 0;
455 value = SerializedHeaderTag::update(kObjectId, value); 442 value = SerializedHeaderTag::update(kObjectId, value);
456 value = SerializedHeaderData::update(object_id, value); 443 value = SerializedHeaderData::update(object_id, value);
457 WriteIntptrValue(-value); // Write as a negative value. 444 Write<int32_t>(-value); // Write as a negative value.
458 } 445 }
459 446
460 // Write serialization header information for an object. 447 // Write serialization header information for an object.
461 void WriteInlinedObjectHeader(intptr_t id) { 448 void WriteInlinedObjectHeader(intptr_t id) {
462 ASSERT(id <= kMaxObjectId); 449 ASSERT(id <= kMaxObjectId);
463 intptr_t value = 0; 450 intptr_t value = 0;
464 value = SerializedHeaderTag::update(kInlined, value); 451 value = SerializedHeaderTag::update(kInlined, value);
465 value = SerializedHeaderData::update(id, value); 452 value = SerializedHeaderData::update(id, value);
466 WriteIntptrValue(value); 453 Write<int32_t>(value);
467 } 454 }
468 455
469 void WriteTags(intptr_t tags) { 456 void WriteTags(intptr_t tags) {
470 ASSERT(SerializedHeaderTag::decode(tags) != kObjectId); 457 ASSERT(SerializedHeaderTag::decode(tags) != kObjectId);
471 const intptr_t flags = tags & 0xff; 458 const intptr_t flags = tags & 0xff;
472 Write<int8_t>(static_cast<int8_t>(flags)); 459 Write<int8_t>(static_cast<int8_t>(flags));
473 } 460 }
474 461
475 // Write out a buffer of bytes. 462 // Write out a buffer of bytes.
476 void WriteBytes(const uint8_t* addr, intptr_t len) { 463 void WriteBytes(const uint8_t* addr, intptr_t len) {
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 private: 707 private:
721 SnapshotWriter* writer_; 708 SnapshotWriter* writer_;
722 bool as_references_; 709 bool as_references_;
723 710
724 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); 711 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor);
725 }; 712 };
726 713
727 } // namespace dart 714 } // namespace dart
728 715
729 #endif // VM_SNAPSHOT_H_ 716 #endif // VM_SNAPSHOT_H_
OLDNEW
« runtime/vm/raw_object.h ('K') | « runtime/vm/scopes.cc ('k') | runtime/vm/snapshot.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698