OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_SNAPSHOT_CODE_SERIALIZER_H_ | 5 #ifndef V8_SNAPSHOT_CODE_SERIALIZER_H_ |
6 #define V8_SNAPSHOT_CODE_SERIALIZER_H_ | 6 #define V8_SNAPSHOT_CODE_SERIALIZER_H_ |
7 | 7 |
8 #include "src/parsing/preparse-data.h" | 8 #include "src/parsing/preparse-data.h" |
9 #include "src/snapshot/serializer.h" | 9 #include "src/snapshot/serializer.h" |
10 | 10 |
11 namespace v8 { | 11 namespace v8 { |
12 namespace internal { | 12 namespace internal { |
13 | 13 |
14 class CodeSerializer : public Serializer { | 14 class CodeSerializer : public Serializer { |
15 public: | 15 public: |
16 static ScriptData* Serialize(Isolate* isolate, | 16 static ScriptData* Serialize(Isolate* isolate, |
17 Handle<SharedFunctionInfo> info, | 17 Handle<SharedFunctionInfo> info, |
18 Handle<String> source); | 18 Handle<String> source); |
19 | 19 |
20 MUST_USE_RESULT static MaybeHandle<SharedFunctionInfo> Deserialize( | 20 MUST_USE_RESULT static MaybeHandle<SharedFunctionInfo> Deserialize( |
21 Isolate* isolate, ScriptData* cached_data, Handle<String> source); | 21 Isolate* isolate, ScriptData* cached_data, Handle<String> source); |
22 | 22 |
23 static const int kSourceObjectIndex = 0; | |
24 STATIC_ASSERT(kSourceObjectReference == kSourceObjectIndex); | |
25 | |
26 static const int kCodeStubsBaseIndex = 1; | |
27 | |
28 String* source() const { | 23 String* source() const { |
29 DCHECK(!AllowHeapAllocation::IsAllowed()); | 24 DCHECK(!AllowHeapAllocation::IsAllowed()); |
30 return source_; | 25 return source_; |
31 } | 26 } |
32 | 27 |
33 const List<uint32_t>* stub_keys() const { return &stub_keys_; } | 28 const List<uint32_t>* stub_keys() const { return &stub_keys_; } |
34 | 29 |
35 private: | 30 private: |
36 CodeSerializer(Isolate* isolate, SnapshotByteSink* sink, String* source) | 31 CodeSerializer(Isolate* isolate, SnapshotByteSink* sink, String* source) |
37 : Serializer(isolate, sink), source_(source) { | 32 : Serializer(isolate, sink), source_(source) { |
38 back_reference_map_.AddSourceString(source); | 33 reference_map_.AddAttachedReference(source); |
39 } | 34 } |
40 | 35 |
41 ~CodeSerializer() override { OutputStatistics("CodeSerializer"); } | 36 ~CodeSerializer() override { OutputStatistics("CodeSerializer"); } |
42 | 37 |
43 void SerializeObject(HeapObject* o, HowToCode how_to_code, | 38 void SerializeObject(HeapObject* o, HowToCode how_to_code, |
44 WhereToPoint where_to_point, int skip) override; | 39 WhereToPoint where_to_point, int skip) override; |
45 | 40 |
46 void SerializeBuiltin(int builtin_index, HowToCode how_to_code, | 41 void SerializeBuiltin(int builtin_index, HowToCode how_to_code, |
47 WhereToPoint where_to_point); | 42 WhereToPoint where_to_point); |
48 void SerializeCodeStub(uint32_t stub_key, HowToCode how_to_code, | 43 void SerializeCodeStub(Code* code_stub, HowToCode how_to_code, |
49 WhereToPoint where_to_point); | 44 WhereToPoint where_to_point); |
50 void SerializeGeneric(HeapObject* heap_object, HowToCode how_to_code, | 45 void SerializeGeneric(HeapObject* heap_object, HowToCode how_to_code, |
51 WhereToPoint where_to_point); | 46 WhereToPoint where_to_point); |
52 int AddCodeStubKey(uint32_t stub_key); | |
53 | 47 |
54 DisallowHeapAllocation no_gc_; | 48 DisallowHeapAllocation no_gc_; |
55 String* source_; | 49 String* source_; |
56 List<uint32_t> stub_keys_; | 50 List<uint32_t> stub_keys_; |
57 DISALLOW_COPY_AND_ASSIGN(CodeSerializer); | 51 DISALLOW_COPY_AND_ASSIGN(CodeSerializer); |
58 }; | 52 }; |
59 | 53 |
60 // Wrapper around ScriptData to provide code-serializer-specific functionality. | 54 // Wrapper around ScriptData to provide code-serializer-specific functionality. |
61 class SerializedCodeData : public SerializedData { | 55 class SerializedCodeData : public SerializedData { |
62 public: | 56 public: |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 static const int kPayloadLengthOffset = kNumCodeStubKeysOffset + kInt32Size; | 110 static const int kPayloadLengthOffset = kNumCodeStubKeysOffset + kInt32Size; |
117 static const int kChecksum1Offset = kPayloadLengthOffset + kInt32Size; | 111 static const int kChecksum1Offset = kPayloadLengthOffset + kInt32Size; |
118 static const int kChecksum2Offset = kChecksum1Offset + kInt32Size; | 112 static const int kChecksum2Offset = kChecksum1Offset + kInt32Size; |
119 static const int kHeaderSize = kChecksum2Offset + kInt32Size; | 113 static const int kHeaderSize = kChecksum2Offset + kInt32Size; |
120 }; | 114 }; |
121 | 115 |
122 } // namespace internal | 116 } // namespace internal |
123 } // namespace v8 | 117 } // namespace v8 |
124 | 118 |
125 #endif // V8_SNAPSHOT_CODE_SERIALIZER_H_ | 119 #endif // V8_SNAPSHOT_CODE_SERIALIZER_H_ |
OLD | NEW |