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

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, 5 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 // using ths unique ID assigned to them). 81 // using ths unique ID assigned to them).
82 // - Reference to object that has already been written: (object id | 0x3) 82 // - Reference to object that has already been written: (object id | 0x3)
83 // This valus is serialized as a positive number. 83 // This valus is serialized as a positive number.
84 // - Object that is seen for the first time (inlined in the stream): 84 // - Object that is seen for the first time (inlined in the stream):
85 // (a unique id for this object | 0x1) 85 // (a unique id for this object | 0x1)
86 enum SerializedHeaderType { 86 enum SerializedHeaderType {
87 kInlined = 0x1, 87 kInlined = 0x1,
88 kObjectId = 0x3, 88 kObjectId = 0x3,
89 }; 89 };
90 static const int8_t kHeaderTagBits = 2; 90 static const int8_t kHeaderTagBits = 2;
91 static const int8_t kObjectIdBits = (kBitsPerWord - (kHeaderTagBits + 1)); 91 static const int8_t kObjectIdBits = (kBitsPerInt32 - (kHeaderTagBits + 1));
92 static const intptr_t kMaxObjectId = (kUwordMax >> (kHeaderTagBits + 1)); 92 static const intptr_t kMaxObjectId = (kMaxUint32 >> (kHeaderTagBits + 1));
93 93
94 94
95 class SerializedHeaderTag : public BitField<enum SerializedHeaderType, 95 class SerializedHeaderTag : public BitField<enum SerializedHeaderType,
96 0, 96 0,
97 kHeaderTagBits> { 97 kHeaderTagBits> {
98 }; 98 };
99 99
100 100
101 class SerializedHeaderData : public BitField<intptr_t, 101 class SerializedHeaderData : public BitField<intptr_t,
102 kHeaderTagBits, 102 kHeaderTagBits,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 class BaseReader { 167 class BaseReader {
168 public: 168 public:
169 BaseReader(const uint8_t* buffer, intptr_t size) : stream_(buffer, size) {} 169 BaseReader(const uint8_t* buffer, intptr_t size) : stream_(buffer, size) {}
170 // Reads raw data (for basic types). 170 // Reads raw data (for basic types).
171 // sizeof(T) must be in {1,2,4,8}. 171 // sizeof(T) must be in {1,2,4,8}.
172 template <typename T> 172 template <typename T>
173 T Read() { 173 T Read() {
174 return ReadStream::Raw<sizeof(T), T>::Read(&stream_); 174 return ReadStream::Raw<sizeof(T), T>::Read(&stream_);
175 } 175 }
176 176
177 // Reads an intptr_t type value.
178 intptr_t ReadIntptrValue() {
179 int64_t value = Read<int64_t>();
180 ASSERT((value <= kIntptrMax) && (value >= kIntptrMin));
181 return static_cast<intptr_t>(value);
182 }
183
184 intptr_t ReadRawPointerValue() { 177 intptr_t ReadRawPointerValue() {
185 int64_t value = Read<int64_t>(); 178 int64_t value = Read<int64_t>();
186 return static_cast<intptr_t>(value); 179 return static_cast<intptr_t>(value);
187 } 180 }
188 181
189 void ReadBytes(uint8_t* addr, intptr_t len) { 182 void ReadBytes(uint8_t* addr, intptr_t len) {
190 stream_.ReadBytes(addr, len); 183 stream_.ReadBytes(addr, len);
191 } 184 }
192 185
193 double ReadDouble() { 186 double ReadDouble() {
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 // Size of the snapshot. 393 // Size of the snapshot.
401 intptr_t BytesWritten() const { return stream_.bytes_written(); } 394 intptr_t BytesWritten() const { return stream_.bytes_written(); }
402 395
403 // Writes raw data to the stream (basic type). 396 // Writes raw data to the stream (basic type).
404 // sizeof(T) must be in {1,2,4,8}. 397 // sizeof(T) must be in {1,2,4,8}.
405 template <typename T> 398 template <typename T>
406 void Write(T value) { 399 void Write(T value) {
407 WriteStream::Raw<sizeof(T), T>::Write(&stream_, value); 400 WriteStream::Raw<sizeof(T), T>::Write(&stream_, value);
408 } 401 }
409 402
410 // Writes an intptr_t type value out.
411 void WriteIntptrValue(intptr_t value) {
412 ASSERT((value >= kMinInt32) && (value <= kMaxInt32));
413 Write<int64_t>(value);
414 }
415
416 void WriteRawPointerValue(intptr_t value) { 403 void WriteRawPointerValue(intptr_t value) {
417 Write<int64_t>(value); 404 Write<int64_t>(value);
418 } 405 }
419 406
420 // Write an object that is serialized as an Id (singleton in object store, 407 // Write an object that is serialized as an Id (singleton in object store,
421 // or an object that was already serialized before). 408 // or an object that was already serialized before).
422 void WriteIndexedObject(intptr_t object_id) { 409 void WriteIndexedObject(intptr_t object_id) {
423 ASSERT(object_id <= kMaxObjectId); 410 ASSERT(object_id <= kMaxObjectId);
424 intptr_t value = 0; 411 intptr_t value = 0;
425 value = SerializedHeaderTag::update(kObjectId, value); 412 value = SerializedHeaderTag::update(kObjectId, value);
426 value = SerializedHeaderData::update(object_id, value); 413 value = SerializedHeaderData::update(object_id, value);
427 WriteIntptrValue(value); 414 Write<int32_t>(value);
428 } 415 }
429 416
430 // Write a VM Isolateobject that is serialized as an Id. 417 // Write a VM Isolateobject that is serialized as an Id.
431 void WriteVMIsolateObject(intptr_t object_id) { 418 void WriteVMIsolateObject(intptr_t object_id) {
432 ASSERT(object_id <= kMaxObjectId); 419 ASSERT(object_id <= kMaxObjectId);
433 intptr_t value = 0; 420 intptr_t value = 0;
434 value = SerializedHeaderTag::update(kObjectId, value); 421 value = SerializedHeaderTag::update(kObjectId, value);
435 value = SerializedHeaderData::update(object_id, value); 422 value = SerializedHeaderData::update(object_id, value);
436 WriteIntptrValue(-value); // Write as a negative value. 423 Write<int32_t>(-value); // Write as a negative value.
437 } 424 }
438 425
439 // Write serialization header information for an object. 426 // Write serialization header information for an object.
440 void WriteInlinedObjectHeader(intptr_t id) { 427 void WriteInlinedObjectHeader(intptr_t id) {
441 ASSERT(id <= kMaxObjectId); 428 ASSERT(id <= kMaxObjectId);
442 intptr_t value = 0; 429 intptr_t value = 0;
443 value = SerializedHeaderTag::update(kInlined, value); 430 value = SerializedHeaderTag::update(kInlined, value);
444 value = SerializedHeaderData::update(id, value); 431 value = SerializedHeaderData::update(id, value);
445 WriteIntptrValue(value); 432 Write<int32_t>(value);
446 } 433 }
447 434
448 void WriteTags(intptr_t tags) { 435 void WriteTags(intptr_t tags) {
449 ASSERT(SerializedHeaderTag::decode(tags) != kObjectId); 436 ASSERT(SerializedHeaderTag::decode(tags) != kObjectId);
450 const intptr_t flags = tags & 0xff; 437 const intptr_t flags = tags & 0xff;
451 Write<int8_t>(static_cast<int8_t>(flags)); 438 Write<int8_t>(static_cast<int8_t>(flags));
452 } 439 }
453 440
454 // Write out a buffer of bytes. 441 // Write out a buffer of bytes.
455 void WriteBytes(const uint8_t* addr, intptr_t len) { 442 void WriteBytes(const uint8_t* addr, intptr_t len) {
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 private: 647 private:
661 SnapshotWriter* writer_; 648 SnapshotWriter* writer_;
662 bool as_references_; 649 bool as_references_;
663 650
664 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); 651 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor);
665 }; 652 };
666 653
667 } // namespace dart 654 } // namespace dart
668 655
669 #endif // VM_SNAPSHOT_H_ 656 #endif // VM_SNAPSHOT_H_
OLDNEW
« runtime/vm/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