| OLD | NEW |
| 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" |
| 11 #include "vm/datastream.h" | 11 #include "vm/datastream.h" |
| 12 #include "vm/globals.h" | 12 #include "vm/globals.h" |
| 13 #include "vm/growable_array.h" | 13 #include "vm/growable_array.h" |
| 14 #include "vm/isolate.h" | 14 #include "vm/isolate.h" |
| 15 #include "vm/visitor.h" | 15 #include "vm/visitor.h" |
| 16 | 16 |
| 17 namespace dart { | 17 namespace dart { |
| 18 | 18 |
| 19 // Forward declarations. | 19 // Forward declarations. |
| 20 class AbstractType; | 20 class AbstractType; |
| 21 class AbstractTypeArguments; | 21 class AbstractTypeArguments; |
| 22 class Array; | 22 class Array; |
| 23 class Class; | 23 class Class; |
| 24 class ClassTable; | 24 class ClassTable; |
| 25 class ExternalUint8Array; |
| 25 class GrowableObjectArray; | 26 class GrowableObjectArray; |
| 26 class Heap; | 27 class Heap; |
| 27 class Library; | 28 class Library; |
| 28 class Object; | 29 class Object; |
| 29 class ObjectStore; | 30 class ObjectStore; |
| 30 class RawAbstractTypeArguments; | 31 class RawAbstractTypeArguments; |
| 31 class RawApiError; | 32 class RawApiError; |
| 32 class RawArray; | 33 class RawArray; |
| 33 class RawBigint; | 34 class RawBigint; |
| 34 class RawClass; | 35 class RawClass; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 49 class RawPatchClass; | 50 class RawPatchClass; |
| 50 class RawScript; | 51 class RawScript; |
| 51 class RawSmi; | 52 class RawSmi; |
| 52 class RawTokenStream; | 53 class RawTokenStream; |
| 53 class RawType; | 54 class RawType; |
| 54 class RawTypeParameter; | 55 class RawTypeParameter; |
| 55 class RawTypeArguments; | 56 class RawTypeArguments; |
| 56 class RawTwoByteString; | 57 class RawTwoByteString; |
| 57 class RawUnresolvedClass; | 58 class RawUnresolvedClass; |
| 58 class String; | 59 class String; |
| 60 class TokenStream; |
| 59 | 61 |
| 60 // Serialized object header encoding is as follows: | 62 // Serialized object header encoding is as follows: |
| 61 // - Smi: the Smi value is written as is (last bit is not tagged). | 63 // - Smi: the Smi value is written as is (last bit is not tagged). |
| 62 // - VM object (from VM isolate): (object id in vm isolate | 0x3) | 64 // - VM object (from VM isolate): (object id in vm isolate | 0x3) |
| 63 // This valus is serialized as a negative number. | 65 // This valus is serialized as a negative number. |
| 64 // (note VM objects are never serialized they are expected to be found | 66 // (note VM objects are never serialized they are expected to be found |
| 65 // using ths unique ID assigned to them). | 67 // using ths unique ID assigned to them). |
| 66 // - Reference to object that has already been written: (object id | 0x3) | 68 // - Reference to object that has already been written: (object id | 0x3) |
| 67 // This valus is serialized as a positive number. | 69 // This valus is serialized as a positive number. |
| 68 // - Object that is seen for the first time (inlined in the stream): | 70 // - Object that is seen for the first time (inlined in the stream): |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 intptr_t ReadIntptrValue() { | 164 intptr_t ReadIntptrValue() { |
| 163 int64_t value = Read<int64_t>(); | 165 int64_t value = Read<int64_t>(); |
| 164 ASSERT((value <= kIntptrMax) && (value >= kIntptrMin)); | 166 ASSERT((value <= kIntptrMax) && (value >= kIntptrMin)); |
| 165 return value; | 167 return value; |
| 166 } | 168 } |
| 167 | 169 |
| 168 void ReadBytes(uint8_t* addr, intptr_t len) { | 170 void ReadBytes(uint8_t* addr, intptr_t len) { |
| 169 stream_.ReadBytes(addr, len); | 171 stream_.ReadBytes(addr, len); |
| 170 } | 172 } |
| 171 | 173 |
| 174 const uint8_t* CurrentBufferAddress() const { |
| 175 return stream_.AddressOfCurrentPosition(); |
| 176 } |
| 177 |
| 178 void Advance(intptr_t value) { |
| 179 stream_.Advance(value); |
| 180 } |
| 181 |
| 172 RawSmi* ReadAsSmi(); | 182 RawSmi* ReadAsSmi(); |
| 173 intptr_t ReadSmiValue(); | 183 intptr_t ReadSmiValue(); |
| 174 | 184 |
| 175 // Negative header value indicates VM isolate object id. | 185 // Negative header value indicates VM isolate object id. |
| 176 bool IsVMIsolateObject(intptr_t header_value) { return (header_value < 0); } | 186 bool IsVMIsolateObject(intptr_t header_value) { return (header_value < 0); } |
| 177 intptr_t GetVMIsolateObjectId(intptr_t header_val) { | 187 intptr_t GetVMIsolateObjectId(intptr_t header_val) { |
| 178 ASSERT(IsVMIsolateObject(header_val)); | 188 ASSERT(IsVMIsolateObject(header_val)); |
| 179 intptr_t value = -header_val; // Header is negative for VM isolate objects. | 189 intptr_t value = -header_val; // Header is negative for VM isolate objects. |
| 180 ASSERT(SerializedHeaderTag::decode(value) == kObjectId); | 190 ASSERT(SerializedHeaderTag::decode(value) == kObjectId); |
| 181 return SerializedHeaderData::decode(value); | 191 return SerializedHeaderData::decode(value); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 197 | 207 |
| 198 Isolate* isolate() const { return isolate_; } | 208 Isolate* isolate() const { return isolate_; } |
| 199 Heap* heap() const { return isolate_->heap(); } | 209 Heap* heap() const { return isolate_->heap(); } |
| 200 ObjectStore* object_store() const { return isolate_->object_store(); } | 210 ObjectStore* object_store() const { return isolate_->object_store(); } |
| 201 ClassTable* class_table() const { return isolate_->class_table(); } | 211 ClassTable* class_table() const { return isolate_->class_table(); } |
| 202 Object* ObjectHandle() { return &obj_; } | 212 Object* ObjectHandle() { return &obj_; } |
| 203 String* StringHandle() { return &str_; } | 213 String* StringHandle() { return &str_; } |
| 204 AbstractType* TypeHandle() { return &type_; } | 214 AbstractType* TypeHandle() { return &type_; } |
| 205 AbstractTypeArguments* TypeArgumentsHandle() { return &type_arguments_; } | 215 AbstractTypeArguments* TypeArgumentsHandle() { return &type_arguments_; } |
| 206 Array* TokensHandle() { return &tokens_; } | 216 Array* TokensHandle() { return &tokens_; } |
| 217 TokenStream* StreamHandle() { return &stream_; } |
| 218 ExternalUint8Array* DataHandle() { return &data_; } |
| 207 | 219 |
| 208 // Reads an object. | 220 // Reads an object. |
| 209 RawObject* ReadObject(); | 221 RawObject* ReadObject(); |
| 210 | 222 |
| 211 // Add object to backward references. | 223 // Add object to backward references. |
| 212 void AddBackRef(intptr_t id, Object* obj, DeserializeState state); | 224 void AddBackRef(intptr_t id, Object* obj, DeserializeState state); |
| 213 | 225 |
| 214 // Get an object from the backward references list. | 226 // Get an object from the backward references list. |
| 215 Object* GetBackRef(intptr_t id); | 227 Object* GetBackRef(intptr_t id); |
| 216 | 228 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 | 299 |
| 288 Snapshot::Kind kind_; // Indicates type of snapshot(full, script, message). | 300 Snapshot::Kind kind_; // Indicates type of snapshot(full, script, message). |
| 289 Isolate* isolate_; // Current isolate. | 301 Isolate* isolate_; // Current isolate. |
| 290 Class& cls_; // Temporary Class handle. | 302 Class& cls_; // Temporary Class handle. |
| 291 Object& obj_; // Temporary Object handle. | 303 Object& obj_; // Temporary Object handle. |
| 292 String& str_; // Temporary String handle. | 304 String& str_; // Temporary String handle. |
| 293 Library& library_; // Temporary library handle. | 305 Library& library_; // Temporary library handle. |
| 294 AbstractType& type_; // Temporary type handle. | 306 AbstractType& type_; // Temporary type handle. |
| 295 AbstractTypeArguments& type_arguments_; // Temporary type argument handle. | 307 AbstractTypeArguments& type_arguments_; // Temporary type argument handle. |
| 296 Array& tokens_; // Temporary tokens handle. | 308 Array& tokens_; // Temporary tokens handle. |
| 309 TokenStream& stream_; // Temporary token stream handle. |
| 310 ExternalUint8Array& data_; // Temporary stream data handle. |
| 297 GrowableArray<BackRefNode*> backward_references_; | 311 GrowableArray<BackRefNode*> backward_references_; |
| 298 | 312 |
| 299 friend class ApiError; | 313 friend class ApiError; |
| 300 friend class Array; | 314 friend class Array; |
| 301 friend class Class; | 315 friend class Class; |
| 302 friend class Context; | 316 friend class Context; |
| 303 friend class ContextScope; | 317 friend class ContextScope; |
| 304 friend class Field; | 318 friend class Field; |
| 305 friend class Function; | 319 friend class Function; |
| 306 friend class GrowableObjectArray; | 320 friend class GrowableObjectArray; |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 private: | 559 private: |
| 546 SnapshotWriter* writer_; | 560 SnapshotWriter* writer_; |
| 547 bool as_references_; | 561 bool as_references_; |
| 548 | 562 |
| 549 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); | 563 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); |
| 550 }; | 564 }; |
| 551 | 565 |
| 552 } // namespace dart | 566 } // namespace dart |
| 553 | 567 |
| 554 #endif // VM_SNAPSHOT_H_ | 568 #endif // VM_SNAPSHOT_H_ |
| OLD | NEW |