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

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, 6 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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 // Size of the snapshot. 388 // Size of the snapshot.
396 intptr_t BytesWritten() const { return stream_.bytes_written(); } 389 intptr_t BytesWritten() const { return stream_.bytes_written(); }
397 390
398 // Writes raw data to the stream (basic type). 391 // Writes raw data to the stream (basic type).
399 // sizeof(T) must be in {1,2,4,8}. 392 // sizeof(T) must be in {1,2,4,8}.
400 template <typename T> 393 template <typename T>
401 void Write(T value) { 394 void Write(T value) {
402 WriteStream::Raw<sizeof(T), T>::Write(&stream_, value); 395 WriteStream::Raw<sizeof(T), T>::Write(&stream_, value);
403 } 396 }
404 397
405 // Writes an intptr_t type value out.
406 void WriteIntptrValue(intptr_t value) {
407 ASSERT((value >= kMinInt32) && (value <= kMaxInt32));
408 Write<int64_t>(value);
409 }
410
411 void WriteRawPointerValue(intptr_t value) { 398 void WriteRawPointerValue(intptr_t value) {
412 Write<int64_t>(value); 399 Write<int64_t>(value);
413 } 400 }
414 401
415 // Write an object that is serialized as an Id (singleton in object store, 402 // Write an object that is serialized as an Id (singleton in object store,
416 // or an object that was already serialized before). 403 // or an object that was already serialized before).
417 void WriteIndexedObject(intptr_t object_id) { 404 void WriteIndexedObject(intptr_t object_id) {
418 ASSERT(object_id <= kMaxObjectId); 405 ASSERT(object_id <= kMaxObjectId);
419 intptr_t value = 0; 406 intptr_t value = 0;
420 value = SerializedHeaderTag::update(kObjectId, value); 407 value = SerializedHeaderTag::update(kObjectId, value);
421 value = SerializedHeaderData::update(object_id, value); 408 value = SerializedHeaderData::update(object_id, value);
422 WriteIntptrValue(value); 409 Write<int32_t>(value);
Ivan Posva 2014/06/26 09:02:04 Can't we just have a Write32 instead of having to
zra 2014/07/01 20:37:01 I can make this name change in a separate CL.
423 } 410 }
424 411
425 // Write a VM Isolateobject that is serialized as an Id. 412 // Write a VM Isolateobject that is serialized as an Id.
426 void WriteVMIsolateObject(intptr_t object_id) { 413 void WriteVMIsolateObject(intptr_t object_id) {
427 ASSERT(object_id <= kMaxObjectId); 414 ASSERT(object_id <= kMaxObjectId);
428 intptr_t value = 0; 415 intptr_t value = 0;
429 value = SerializedHeaderTag::update(kObjectId, value); 416 value = SerializedHeaderTag::update(kObjectId, value);
430 value = SerializedHeaderData::update(object_id, value); 417 value = SerializedHeaderData::update(object_id, value);
431 WriteIntptrValue(-value); // Write as a negative value. 418 Write<int32_t>(-value); // Write as a negative value.
432 } 419 }
433 420
434 // Write serialization header information for an object. 421 // Write serialization header information for an object.
435 void WriteInlinedObjectHeader(intptr_t id) { 422 void WriteInlinedObjectHeader(intptr_t id) {
436 ASSERT(id <= kMaxObjectId); 423 ASSERT(id <= kMaxObjectId);
437 intptr_t value = 0; 424 intptr_t value = 0;
438 value = SerializedHeaderTag::update(kInlined, value); 425 value = SerializedHeaderTag::update(kInlined, value);
439 value = SerializedHeaderData::update(id, value); 426 value = SerializedHeaderData::update(id, value);
440 WriteIntptrValue(value); 427 Write<int32_t>(value);
441 } 428 }
442 429
443 // Write out a buffer of bytes. 430 // Write out a buffer of bytes.
444 void WriteBytes(const uint8_t* addr, intptr_t len) { 431 void WriteBytes(const uint8_t* addr, intptr_t len) {
445 stream_.WriteBytes(addr, len); 432 stream_.WriteBytes(addr, len);
446 } 433 }
447 434
448 void WriteDouble(double value) { 435 void WriteDouble(double value) {
449 stream_.WriteBytes(reinterpret_cast<const uint8_t*>(&value), sizeof(value)); 436 stream_.WriteBytes(reinterpret_cast<const uint8_t*>(&value), sizeof(value));
450 } 437 }
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 private: 636 private:
650 SnapshotWriter* writer_; 637 SnapshotWriter* writer_;
651 bool as_references_; 638 bool as_references_;
652 639
653 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); 640 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor);
654 }; 641 };
655 642
656 } // namespace dart 643 } // namespace dart
657 644
658 #endif // VM_SNAPSHOT_H_ 645 #endif // VM_SNAPSHOT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698