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

Side by Side Diff: src/snapshot/code-serializer.h

Issue 2205973003: [wasm] Serialization/Deserialization of compiled module (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix silly bug Created 4 years, 4 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
OLDNEW
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 explicit CodeSerializer(Isolate* isolate, uint32_t source_hash)
17 : Serializer(isolate), source_hash_(source_hash) {}
18 ~CodeSerializer() override { OutputStatistics("CodeSerializer"); }
19
16 static ScriptData* Serialize(Isolate* isolate, 20 static ScriptData* Serialize(Isolate* isolate,
17 Handle<SharedFunctionInfo> info, 21 Handle<SharedFunctionInfo> info,
18 Handle<String> source); 22 Handle<String> source);
19 23
24 ScriptData* Serialize(Handle<HeapObject> obj);
25
20 MUST_USE_RESULT static MaybeHandle<SharedFunctionInfo> Deserialize( 26 MUST_USE_RESULT static MaybeHandle<SharedFunctionInfo> Deserialize(
21 Isolate* isolate, ScriptData* cached_data, Handle<String> source); 27 Isolate* isolate, ScriptData* cached_data, Handle<String> source);
22 28
23 String* source() const {
24 DCHECK(!AllowHeapAllocation::IsAllowed());
25 return source_;
26 }
27
28 const List<uint32_t>* stub_keys() const { return &stub_keys_; } 29 const List<uint32_t>* stub_keys() const { return &stub_keys_; }
29 30
31 uint32_t source_hash() const { return source_hash_; }
32
30 private: 33 private:
31 CodeSerializer(Isolate* isolate, String* source)
32 : Serializer(isolate), source_(source) {
33 reference_map_.AddAttachedReference(source);
34 }
35
36 ~CodeSerializer() override { OutputStatistics("CodeSerializer"); }
37
38 void SerializeObject(HeapObject* o, HowToCode how_to_code, 34 void SerializeObject(HeapObject* o, HowToCode how_to_code,
39 WhereToPoint where_to_point, int skip) override; 35 WhereToPoint where_to_point, int skip) override;
40 36
41 void SerializeBuiltin(int builtin_index, HowToCode how_to_code, 37 void SerializeBuiltin(int builtin_index, HowToCode how_to_code,
42 WhereToPoint where_to_point); 38 WhereToPoint where_to_point);
43 void SerializeCodeStub(Code* code_stub, HowToCode how_to_code, 39 void SerializeCodeStub(Code* code_stub, HowToCode how_to_code,
44 WhereToPoint where_to_point); 40 WhereToPoint where_to_point);
45 void SerializeGeneric(HeapObject* heap_object, HowToCode how_to_code, 41 void SerializeGeneric(HeapObject* heap_object, HowToCode how_to_code,
46 WhereToPoint where_to_point); 42 WhereToPoint where_to_point);
47 43
48 DisallowHeapAllocation no_gc_; 44 DisallowHeapAllocation no_gc_;
49 String* source_; 45 uint32_t source_hash_;
50 List<uint32_t> stub_keys_; 46 List<uint32_t> stub_keys_;
51 DISALLOW_COPY_AND_ASSIGN(CodeSerializer); 47 DISALLOW_COPY_AND_ASSIGN(CodeSerializer);
52 }; 48 };
53 49
50 enum SanityCheckResult {
Yang 2016/08/05 12:04:17 Can we keep this in SerializedCodeData? We can mak
Mircea Trofin 2016/08/05 15:01:29 Acknowledged.
Mircea Trofin 2016/08/06 00:31:39 Done.
51 CHECK_SUCCESS = 0,
52 MAGIC_NUMBER_MISMATCH = 1,
53 VERSION_MISMATCH = 2,
54 SOURCE_MISMATCH = 3,
55 CPU_FEATURES_MISMATCH = 4,
56 FLAGS_MISMATCH = 5,
57 CHECKSUM_MISMATCH = 6
58 };
59
54 // Wrapper around ScriptData to provide code-serializer-specific functionality. 60 // Wrapper around ScriptData to provide code-serializer-specific functionality.
55 class SerializedCodeData : public SerializedData { 61 class SerializedCodeData : public SerializedData {
56 public: 62 public:
57 // Used when consuming. 63 // Used when consuming.
58 static SerializedCodeData* FromCachedData(Isolate* isolate, 64 static const SerializedCodeData FromCachedData(
59 ScriptData* cached_data, 65 Isolate* isolate, ScriptData* cached_data, uint32_t expected_source_hash,
60 String* source); 66 SanityCheckResult* rejection_result);
61 67
62 // Used when producing. 68 // Used when producing.
63 SerializedCodeData(const List<byte>* payload, const CodeSerializer* cs); 69 SerializedCodeData(const List<byte>* payload, const CodeSerializer* cs);
64 70
65 // Return ScriptData object and relinquish ownership over it to the caller. 71 // Return ScriptData object and relinquish ownership over it to the caller.
66 ScriptData* GetScriptData(); 72 ScriptData* GetScriptData();
67 73
68 Vector<const Reservation> Reservations() const; 74 Vector<const Reservation> Reservations() const;
69 Vector<const byte> Payload() const; 75 Vector<const byte> Payload() const;
70 76
71 Vector<const uint32_t> CodeStubKeys() const; 77 Vector<const uint32_t> CodeStubKeys() const;
72 78
79 static uint32_t SourceHash(Handle<String> source);
80
73 private: 81 private:
74 explicit SerializedCodeData(ScriptData* data); 82 explicit SerializedCodeData(ScriptData* data);
83 SerializedCodeData(const byte* data, int size)
84 : SerializedData(const_cast<byte*>(data), size) {}
75 85
76 enum SanityCheckResult { 86 SanityCheckResult SanityCheck(Isolate* isolate,
77 CHECK_SUCCESS = 0, 87 uint32_t expected_source_hash) const;
78 MAGIC_NUMBER_MISMATCH = 1,
79 VERSION_MISMATCH = 2,
80 SOURCE_MISMATCH = 3,
81 CPU_FEATURES_MISMATCH = 4,
82 FLAGS_MISMATCH = 5,
83 CHECKSUM_MISMATCH = 6
84 };
85
86 SanityCheckResult SanityCheck(Isolate* isolate, String* source) const;
87
88 uint32_t SourceHash(String* source) const;
89
90 // The data header consists of uint32_t-sized entries: 88 // The data header consists of uint32_t-sized entries:
91 // [0] magic number and external reference count 89 // [0] magic number and external reference count
92 // [1] version hash 90 // [1] version hash
93 // [2] source hash 91 // [2] source hash
94 // [3] cpu features 92 // [3] cpu features
95 // [4] flag hash 93 // [4] flag hash
96 // [5] number of code stub keys 94 // [5] number of code stub keys
97 // [6] number of reservation size entries 95 // [6] number of reservation size entries
98 // [7] payload length 96 // [7] payload length
99 // [8] payload checksum part 1 97 // [8] payload checksum part 1
(...skipping 10 matching lines...) Expand all
110 static const int kPayloadLengthOffset = kNumCodeStubKeysOffset + kInt32Size; 108 static const int kPayloadLengthOffset = kNumCodeStubKeysOffset + kInt32Size;
111 static const int kChecksum1Offset = kPayloadLengthOffset + kInt32Size; 109 static const int kChecksum1Offset = kPayloadLengthOffset + kInt32Size;
112 static const int kChecksum2Offset = kChecksum1Offset + kInt32Size; 110 static const int kChecksum2Offset = kChecksum1Offset + kInt32Size;
113 static const int kHeaderSize = kChecksum2Offset + kInt32Size; 111 static const int kHeaderSize = kChecksum2Offset + kInt32Size;
114 }; 112 };
115 113
116 } // namespace internal 114 } // namespace internal
117 } // namespace v8 115 } // namespace v8
118 116
119 #endif // V8_SNAPSHOT_CODE_SERIALIZER_H_ 117 #endif // V8_SNAPSHOT_CODE_SERIALIZER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698