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 #include "src/snapshot/code-serializer.h" | 5 #include "src/snapshot/code-serializer.h" |
6 | 6 |
7 #include "src/code-stubs.h" | 7 #include "src/code-stubs.h" |
8 #include "src/log.h" | 8 #include "src/log.h" |
9 #include "src/macro-assembler.h" | 9 #include "src/macro-assembler.h" |
10 #include "src/snapshot/deserializer.h" | 10 #include "src/snapshot/deserializer.h" |
11 #include "src/version.h" | 11 #include "src/version.h" |
12 | 12 |
13 namespace v8 { | 13 namespace v8 { |
14 namespace internal { | 14 namespace internal { |
15 | 15 |
16 ScriptData* CodeSerializer::Serialize(Isolate* isolate, | 16 ScriptData* CodeSerializer::Serialize(Isolate* isolate, |
17 Handle<SharedFunctionInfo> info, | 17 Handle<SharedFunctionInfo> info, |
18 Handle<String> source) { | 18 Handle<String> source) { |
19 base::ElapsedTimer timer; | 19 base::ElapsedTimer timer; |
20 if (FLAG_profile_deserialization) timer.Start(); | 20 if (FLAG_profile_deserialization) timer.Start(); |
21 if (FLAG_trace_serializer) { | 21 if (FLAG_trace_serializer) { |
22 PrintF("[Serializing from"); | 22 PrintF("[Serializing from"); |
23 Object* script = info->script(); | 23 Object* script = info->script(); |
24 if (script->IsScript()) Script::cast(script)->name()->ShortPrint(); | 24 if (script->IsScript()) Script::cast(script)->name()->ShortPrint(); |
25 PrintF("]\n"); | 25 PrintF("]\n"); |
26 } | 26 } |
27 | 27 |
28 // Serialize code object. | 28 // Serialize code object. |
29 SnapshotByteSink sink(info->code()->CodeSize() * 2); | 29 CodeSerializer cs(isolate, *source); |
30 CodeSerializer cs(isolate, &sink, *source); | |
31 DisallowHeapAllocation no_gc; | 30 DisallowHeapAllocation no_gc; |
32 Object** location = Handle<Object>::cast(info).location(); | 31 Object** location = Handle<Object>::cast(info).location(); |
33 cs.VisitPointer(location); | 32 cs.VisitPointer(location); |
34 cs.SerializeDeferredObjects(); | 33 cs.SerializeDeferredObjects(); |
35 cs.Pad(); | 34 cs.Pad(); |
36 | 35 |
37 SerializedCodeData data(sink.data(), &cs); | 36 SerializedCodeData data(cs.sink()->data(), &cs); |
38 ScriptData* script_data = data.GetScriptData(); | 37 ScriptData* script_data = data.GetScriptData(); |
39 | 38 |
40 if (FLAG_profile_deserialization) { | 39 if (FLAG_profile_deserialization) { |
41 double ms = timer.Elapsed().InMillisecondsF(); | 40 double ms = timer.Elapsed().InMillisecondsF(); |
42 int length = script_data->length(); | 41 int length = script_data->length(); |
43 PrintF("[Serializing to %d bytes took %0.3f ms]\n", length, ms); | 42 PrintF("[Serializing to %d bytes took %0.3f ms]\n", length, ms); |
44 } | 43 } |
45 | 44 |
46 return script_data; | 45 return script_data; |
47 } | 46 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 // We expect no instantiated function objects or contexts. | 97 // We expect no instantiated function objects or contexts. |
99 CHECK(!obj->IsJSFunction() && !obj->IsContext()); | 98 CHECK(!obj->IsJSFunction() && !obj->IsContext()); |
100 | 99 |
101 SerializeGeneric(obj, how_to_code, where_to_point); | 100 SerializeGeneric(obj, how_to_code, where_to_point); |
102 } | 101 } |
103 | 102 |
104 void CodeSerializer::SerializeGeneric(HeapObject* heap_object, | 103 void CodeSerializer::SerializeGeneric(HeapObject* heap_object, |
105 HowToCode how_to_code, | 104 HowToCode how_to_code, |
106 WhereToPoint where_to_point) { | 105 WhereToPoint where_to_point) { |
107 // Object has not yet been serialized. Serialize it here. | 106 // Object has not yet been serialized. Serialize it here. |
108 ObjectSerializer serializer(this, heap_object, sink_, how_to_code, | 107 ObjectSerializer serializer(this, heap_object, &sink_, how_to_code, |
109 where_to_point); | 108 where_to_point); |
110 serializer.Serialize(); | 109 serializer.Serialize(); |
111 } | 110 } |
112 | 111 |
113 void CodeSerializer::SerializeBuiltin(int builtin_index, HowToCode how_to_code, | 112 void CodeSerializer::SerializeBuiltin(int builtin_index, HowToCode how_to_code, |
114 WhereToPoint where_to_point) { | 113 WhereToPoint where_to_point) { |
115 DCHECK((how_to_code == kPlain && where_to_point == kStartOfObject) || | 114 DCHECK((how_to_code == kPlain && where_to_point == kStartOfObject) || |
116 (how_to_code == kPlain && where_to_point == kInnerPointer) || | 115 (how_to_code == kPlain && where_to_point == kInnerPointer) || |
117 (how_to_code == kFromCode && where_to_point == kInnerPointer)); | 116 (how_to_code == kFromCode && where_to_point == kInnerPointer)); |
118 DCHECK_LT(builtin_index, Builtins::builtin_count); | 117 DCHECK_LT(builtin_index, Builtins::builtin_count); |
119 DCHECK_LE(0, builtin_index); | 118 DCHECK_LE(0, builtin_index); |
120 | 119 |
121 if (FLAG_trace_serializer) { | 120 if (FLAG_trace_serializer) { |
122 PrintF(" Encoding builtin: %s\n", | 121 PrintF(" Encoding builtin: %s\n", |
123 isolate()->builtins()->name(builtin_index)); | 122 isolate()->builtins()->name(builtin_index)); |
124 } | 123 } |
125 | 124 |
126 sink_->Put(kBuiltin + how_to_code + where_to_point, "Builtin"); | 125 sink_.Put(kBuiltin + how_to_code + where_to_point, "Builtin"); |
127 sink_->PutInt(builtin_index, "builtin_index"); | 126 sink_.PutInt(builtin_index, "builtin_index"); |
128 } | 127 } |
129 | 128 |
130 void CodeSerializer::SerializeCodeStub(Code* code_stub, HowToCode how_to_code, | 129 void CodeSerializer::SerializeCodeStub(Code* code_stub, HowToCode how_to_code, |
131 WhereToPoint where_to_point) { | 130 WhereToPoint where_to_point) { |
132 // We only arrive here if we have not encountered this code stub before. | 131 // We only arrive here if we have not encountered this code stub before. |
133 DCHECK(!reference_map()->Lookup(code_stub).is_valid()); | 132 DCHECK(!reference_map()->Lookup(code_stub).is_valid()); |
134 uint32_t stub_key = code_stub->stub_key(); | 133 uint32_t stub_key = code_stub->stub_key(); |
135 DCHECK(CodeStub::MajorKeyFromKey(stub_key) != CodeStub::NoCache); | 134 DCHECK(CodeStub::MajorKeyFromKey(stub_key) != CodeStub::NoCache); |
136 DCHECK(!CodeStub::GetCode(isolate(), stub_key).is_null()); | 135 DCHECK(!CodeStub::GetCode(isolate(), stub_key).is_null()); |
137 stub_keys_.Add(stub_key); | 136 stub_keys_.Add(stub_key); |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 SanityCheckResult r = scd->SanityCheck(isolate, source); | 354 SanityCheckResult r = scd->SanityCheck(isolate, source); |
356 if (r == CHECK_SUCCESS) return scd; | 355 if (r == CHECK_SUCCESS) return scd; |
357 cached_data->Reject(); | 356 cached_data->Reject(); |
358 source->GetIsolate()->counters()->code_cache_reject_reason()->AddSample(r); | 357 source->GetIsolate()->counters()->code_cache_reject_reason()->AddSample(r); |
359 delete scd; | 358 delete scd; |
360 return NULL; | 359 return NULL; |
361 } | 360 } |
362 | 361 |
363 } // namespace internal | 362 } // namespace internal |
364 } // namespace v8 | 363 } // namespace v8 |
OLD | NEW |