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

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
« no previous file with comments | « runtime/vm/scopes.cc ('k') | runtime/vm/snapshot.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 // using ths unique ID assigned to them). 86 // using ths unique ID assigned to them).
87 // - Reference to object that has already been written: (object id | 0x3) 87 // - Reference to object that has already been written: (object id | 0x3)
88 // This valus is serialized as a positive number. 88 // This valus is serialized as a positive number.
89 // - Object that is seen for the first time (inlined in the stream): 89 // - Object that is seen for the first time (inlined in the stream):
90 // (a unique id for this object | 0x1) 90 // (a unique id for this object | 0x1)
91 enum SerializedHeaderType { 91 enum SerializedHeaderType {
92 kInlined = 0x1, 92 kInlined = 0x1,
93 kObjectId = 0x3, 93 kObjectId = 0x3,
94 }; 94 };
95 static const int8_t kHeaderTagBits = 2; 95 static const int8_t kHeaderTagBits = 2;
96 static const int8_t kObjectIdBits = (kBitsPerWord - (kHeaderTagBits + 1)); 96 static const int8_t kObjectIdBits = (kBitsPerInt32 - (kHeaderTagBits + 1));
97 static const intptr_t kMaxObjectId = (kUwordMax >> (kHeaderTagBits + 1)); 97 static const intptr_t kMaxObjectId = (kMaxUint32 >> (kHeaderTagBits + 1));
98 98
99 99
100 class SerializedHeaderTag : public BitField<enum SerializedHeaderType, 100 class SerializedHeaderTag : public BitField<enum SerializedHeaderType,
101 0, 101 0,
102 kHeaderTagBits> { 102 kHeaderTagBits> {
103 }; 103 };
104 104
105 105
106 class SerializedHeaderData : public BitField<intptr_t, 106 class SerializedHeaderData : public BitField<intptr_t,
107 kHeaderTagBits, 107 kHeaderTagBits,
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 class BaseReader { 180 class BaseReader {
181 public: 181 public:
182 BaseReader(const uint8_t* buffer, intptr_t size) : stream_(buffer, size) {} 182 BaseReader(const uint8_t* buffer, intptr_t size) : stream_(buffer, size) {}
183 // Reads raw data (for basic types). 183 // Reads raw data (for basic types).
184 // sizeof(T) must be in {1,2,4,8}. 184 // sizeof(T) must be in {1,2,4,8}.
185 template <typename T> 185 template <typename T>
186 T Read() { 186 T Read() {
187 return ReadStream::Raw<sizeof(T), T>::Read(&stream_); 187 return ReadStream::Raw<sizeof(T), T>::Read(&stream_);
188 } 188 }
189 189
190 // Reads an intptr_t type value.
191 intptr_t ReadIntptrValue() {
192 int64_t value = Read<int64_t>();
193 ASSERT((value <= kIntptrMax) && (value >= kIntptrMin));
194 return static_cast<intptr_t>(value);
195 }
196
197 intptr_t ReadRawPointerValue() { 190 intptr_t ReadRawPointerValue() {
198 int64_t value = Read<int64_t>(); 191 int64_t value = Read<int64_t>();
199 return static_cast<intptr_t>(value); 192 return static_cast<intptr_t>(value);
200 } 193 }
201 194
202 void ReadBytes(uint8_t* addr, intptr_t len) { 195 void ReadBytes(uint8_t* addr, intptr_t len) {
203 stream_.ReadBytes(addr, len); 196 stream_.ReadBytes(addr, len);
204 } 197 }
205 198
206 double ReadDouble() { 199 double ReadDouble() {
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 // Size of the snapshot. 426 // Size of the snapshot.
434 intptr_t BytesWritten() const { return stream_.bytes_written(); } 427 intptr_t BytesWritten() const { return stream_.bytes_written(); }
435 428
436 // Writes raw data to the stream (basic type). 429 // Writes raw data to the stream (basic type).
437 // sizeof(T) must be in {1,2,4,8}. 430 // sizeof(T) must be in {1,2,4,8}.
438 template <typename T> 431 template <typename T>
439 void Write(T value) { 432 void Write(T value) {
440 WriteStream::Raw<sizeof(T), T>::Write(&stream_, value); 433 WriteStream::Raw<sizeof(T), T>::Write(&stream_, value);
441 } 434 }
442 435
443 // Writes an intptr_t type value out.
444 void WriteIntptrValue(intptr_t value) {
445 ASSERT((value >= kMinInt32) && (value <= kMaxInt32));
446 Write<int64_t>(value);
447 }
448
449 void WriteRawPointerValue(intptr_t value) { 436 void WriteRawPointerValue(intptr_t value) {
450 Write<int64_t>(value); 437 Write<int64_t>(value);
451 } 438 }
452 439
453 // Write an object that is serialized as an Id (singleton in object store, 440 // Write an object that is serialized as an Id (singleton in object store,
454 // or an object that was already serialized before). 441 // or an object that was already serialized before).
455 void WriteIndexedObject(intptr_t object_id) { 442 void WriteIndexedObject(intptr_t object_id) {
456 ASSERT(object_id <= kMaxObjectId); 443 ASSERT(object_id <= kMaxObjectId);
457 intptr_t value = 0; 444 intptr_t value = 0;
458 value = SerializedHeaderTag::update(kObjectId, value); 445 value = SerializedHeaderTag::update(kObjectId, value);
459 value = SerializedHeaderData::update(object_id, value); 446 value = SerializedHeaderData::update(object_id, value);
460 WriteIntptrValue(value); 447 Write<int32_t>(value);
461 } 448 }
462 449
463 // Write a VM Isolateobject that is serialized as an Id. 450 // Write a VM Isolateobject that is serialized as an Id.
464 void WriteVMIsolateObject(intptr_t object_id) { 451 void WriteVMIsolateObject(intptr_t object_id) {
465 ASSERT(object_id <= kMaxObjectId); 452 ASSERT(object_id <= kMaxObjectId);
466 intptr_t value = 0; 453 intptr_t value = 0;
467 value = SerializedHeaderTag::update(kObjectId, value); 454 value = SerializedHeaderTag::update(kObjectId, value);
468 value = SerializedHeaderData::update(object_id, value); 455 value = SerializedHeaderData::update(object_id, value);
469 WriteIntptrValue(-value); // Write as a negative value. 456 Write<int32_t>(-value); // Write as a negative value.
470 } 457 }
471 458
472 // Write serialization header information for an object. 459 // Write serialization header information for an object.
473 void WriteInlinedObjectHeader(intptr_t id) { 460 void WriteInlinedObjectHeader(intptr_t id) {
474 ASSERT(id <= kMaxObjectId); 461 ASSERT(id <= kMaxObjectId);
475 intptr_t value = 0; 462 intptr_t value = 0;
476 value = SerializedHeaderTag::update(kInlined, value); 463 value = SerializedHeaderTag::update(kInlined, value);
477 value = SerializedHeaderData::update(id, value); 464 value = SerializedHeaderData::update(id, value);
478 WriteIntptrValue(value); 465 Write<int32_t>(value);
479 } 466 }
480 467
481 void WriteTags(intptr_t tags) { 468 void WriteTags(intptr_t tags) {
482 ASSERT(SerializedHeaderTag::decode(tags) != kObjectId); 469 ASSERT(SerializedHeaderTag::decode(tags) != kObjectId);
483 const intptr_t flags = tags & 0xff; 470 const intptr_t flags = tags & 0xff;
484 Write<int8_t>(static_cast<int8_t>(flags)); 471 Write<int8_t>(static_cast<int8_t>(flags));
485 } 472 }
486 473
487 // Write out a buffer of bytes. 474 // Write out a buffer of bytes.
488 void WriteBytes(const uint8_t* addr, intptr_t len) { 475 void WriteBytes(const uint8_t* addr, intptr_t len) {
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 private: 724 private:
738 SnapshotWriter* writer_; 725 SnapshotWriter* writer_;
739 bool as_references_; 726 bool as_references_;
740 727
741 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); 728 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor);
742 }; 729 };
743 730
744 } // namespace dart 731 } // namespace dart
745 732
746 #endif // VM_SNAPSHOT_H_ 733 #endif // VM_SNAPSHOT_H_
OLDNEW
« no previous file with comments | « runtime/vm/scopes.cc ('k') | runtime/vm/snapshot.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698