OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/api.h" | 5 #include "src/api.h" |
6 | 6 |
7 #include <string.h> // For memcpy, strlen. | 7 #include <string.h> // For memcpy, strlen. |
8 #ifdef V8_USE_ADDRESS_SANITIZER | 8 #ifdef V8_USE_ADDRESS_SANITIZER |
9 #include <sanitizer/asan_interface.h> | 9 #include <sanitizer/asan_interface.h> |
10 #endif // V8_USE_ADDRESS_SANITIZER | 10 #endif // V8_USE_ADDRESS_SANITIZER |
11 #include <cmath> // For isnan. | 11 #include <cmath> // For isnan. |
12 #include "include/v8-debug.h" | 12 #include "include/v8-debug.h" |
13 #include "include/v8-profiler.h" | 13 #include "include/v8-profiler.h" |
14 #include "include/v8-testing.h" | 14 #include "include/v8-testing.h" |
15 #include "src/assert-scope.h" | 15 #include "src/assert-scope.h" |
16 #include "src/background-parsing-task.h" | 16 #include "src/background-parsing-task.h" |
17 #include "src/base/functional.h" | 17 #include "src/base/functional.h" |
18 #include "src/base/platform/platform.h" | 18 #include "src/base/platform/platform.h" |
19 #include "src/base/platform/time.h" | 19 #include "src/base/platform/time.h" |
20 #include "src/base/utils/random-number-generator.h" | 20 #include "src/base/utils/random-number-generator.h" |
21 #include "src/bootstrapper.h" | 21 #include "src/bootstrapper.h" |
22 #include "src/code-stubs.h" | 22 #include "src/code-stubs.h" |
23 #include "src/compiler.h" | 23 #include "src/compiler.h" |
24 #include "src/conversions-inl.h" | 24 #include "src/conversions-inl.h" |
25 #include "src/counters.h" | 25 #include "src/counters.h" |
26 #include "src/cpu-profiler.h" | 26 #include "src/cpu-profiler.h" |
27 #include "src/debug.h" | 27 #include "src/debug.h" |
28 #include "src/deoptimizer.h" | 28 #include "src/deoptimizer.h" |
29 #include "src/execution.h" | 29 #include "src/execution.h" |
| 30 #include "src/full-codegen.h" |
30 #include "src/global-handles.h" | 31 #include "src/global-handles.h" |
31 #include "src/heap-profiler.h" | 32 #include "src/heap-profiler.h" |
32 #include "src/heap-snapshot-generator-inl.h" | 33 #include "src/heap-snapshot-generator-inl.h" |
33 #include "src/icu_util.h" | 34 #include "src/icu_util.h" |
34 #include "src/json-parser.h" | 35 #include "src/json-parser.h" |
35 #include "src/messages.h" | 36 #include "src/messages.h" |
36 #include "src/natives.h" | 37 #include "src/natives.h" |
37 #include "src/parser.h" | 38 #include "src/parser.h" |
38 #include "src/profile-generator-inl.h" | 39 #include "src/profile-generator-inl.h" |
39 #include "src/property.h" | 40 #include "src/property.h" |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 if (try_catch.HasCaught()) return false; | 214 if (try_catch.HasCaught()) return false; |
214 ScriptOrigin origin(String::NewFromUtf8(isolate, "<embedded script>")); | 215 ScriptOrigin origin(String::NewFromUtf8(isolate, "<embedded script>")); |
215 ScriptCompiler::Source source(source_string, origin); | 216 ScriptCompiler::Source source(source_string, origin); |
216 Local<Script> script = ScriptCompiler::Compile(isolate, &source); | 217 Local<Script> script = ScriptCompiler::Compile(isolate, &source); |
217 if (try_catch.HasCaught()) return false; | 218 if (try_catch.HasCaught()) return false; |
218 script->Run(); | 219 script->Run(); |
219 return !try_catch.HasCaught(); | 220 return !try_catch.HasCaught(); |
220 } | 221 } |
221 | 222 |
222 | 223 |
| 224 void CheckDefaultReservationSizes(const i::StartupSerializer& startup_ser, |
| 225 const i::PartialSerializer& context_ser) { |
| 226 #ifdef DEBUG |
| 227 i::List<i::SerializedData::Reservation> startup_reservations; |
| 228 i::List<i::SerializedData::Reservation> context_reservations; |
| 229 startup_ser.EncodeReservations(&startup_reservations); |
| 230 context_ser.EncodeReservations(&context_reservations); |
| 231 for (int space = 0; space < i::Serializer::kNumberOfSpaces; space++) { |
| 232 // Exactly one chunk per space. |
| 233 CHECK(startup_reservations[space].is_last()); |
| 234 CHECK(startup_reservations[space].is_last()); |
| 235 uint32_t sum = startup_reservations[space].chunk_size() + |
| 236 context_reservations[space].chunk_size(); |
| 237 uint32_t limit = 0; |
| 238 const int constant_pool_delta = i::FLAG_enable_ool_constant_pool ? 48 : 0; |
| 239 switch (space) { |
| 240 case i::NEW_SPACE: |
| 241 limit = 3 * i::kPointerSize; |
| 242 break; |
| 243 case i::OLD_POINTER_SPACE: |
| 244 limit = (128 + constant_pool_delta) * i::kPointerSize * i::KB; |
| 245 break; |
| 246 case i::OLD_DATA_SPACE: |
| 247 limit = 192 * i::KB; |
| 248 break; |
| 249 case i::MAP_SPACE: |
| 250 limit = 16 * i::kPointerSize * i::KB; |
| 251 break; |
| 252 case i::CELL_SPACE: |
| 253 limit = 16 * i::kPointerSize * i::KB; |
| 254 break; |
| 255 case i::PROPERTY_CELL_SPACE: |
| 256 limit = 8 * i::kPointerSize * i::KB; |
| 257 break; |
| 258 case i::CODE_SPACE: |
| 259 limit = RoundUp((480 - constant_pool_delta) * i::KB * |
| 260 i::FullCodeGenerator::kBootCodeSizeMultiplier / 100, |
| 261 i::kPointerSize); |
| 262 break; |
| 263 default: |
| 264 break; |
| 265 } |
| 266 CHECK_LE(sum, limit); |
| 267 } |
| 268 #endif // DEBUG |
| 269 } |
| 270 |
| 271 |
223 StartupData V8::CreateSnapshotDataBlob(char* custom_source) { | 272 StartupData V8::CreateSnapshotDataBlob(char* custom_source) { |
224 Isolate::CreateParams params; | 273 Isolate::CreateParams params; |
225 params.enable_serializer = true; | 274 params.enable_serializer = true; |
226 Isolate* isolate = v8::Isolate::New(params); | 275 Isolate* isolate = v8::Isolate::New(params); |
227 StartupData result = {NULL, 0}; | 276 StartupData result = {NULL, 0}; |
228 { | 277 { |
229 Isolate::Scope isolate_scope(isolate); | 278 Isolate::Scope isolate_scope(isolate); |
230 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); | 279 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
231 Persistent<Context> context; | 280 Persistent<Context> context; |
232 i::Snapshot::Metadata metadata; | 281 i::Snapshot::Metadata metadata; |
(...skipping 26 matching lines...) Expand all Loading... |
259 ser.SerializeStrongReferences(); | 308 ser.SerializeStrongReferences(); |
260 | 309 |
261 i::SnapshotByteSink context_sink; | 310 i::SnapshotByteSink context_sink; |
262 i::PartialSerializer context_ser(internal_isolate, &ser, &context_sink); | 311 i::PartialSerializer context_ser(internal_isolate, &ser, &context_sink); |
263 context_ser.Serialize(&raw_context); | 312 context_ser.Serialize(&raw_context); |
264 ser.SerializeWeakReferences(); | 313 ser.SerializeWeakReferences(); |
265 | 314 |
266 i::SnapshotData sd(snapshot_sink, ser); | 315 i::SnapshotData sd(snapshot_sink, ser); |
267 i::SnapshotData csd(context_sink, context_ser); | 316 i::SnapshotData csd(context_sink, context_ser); |
268 | 317 |
| 318 if (custom_source == NULL) CheckDefaultReservationSizes(ser, context_ser); |
| 319 |
269 result = i::Snapshot::CreateSnapshotBlob(sd.RawData(), csd.RawData(), | 320 result = i::Snapshot::CreateSnapshotBlob(sd.RawData(), csd.RawData(), |
270 metadata); | 321 metadata); |
271 } | 322 } |
272 } | 323 } |
273 isolate->Dispose(); | 324 isolate->Dispose(); |
274 return result; | 325 return result; |
275 } | 326 } |
276 | 327 |
277 | 328 |
278 void V8::SetFlagsFromString(const char* str, int length) { | 329 void V8::SetFlagsFromString(const char* str, int length) { |
(...skipping 7326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7605 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 7656 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
7606 Address callback_address = | 7657 Address callback_address = |
7607 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 7658 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
7608 VMState<EXTERNAL> state(isolate); | 7659 VMState<EXTERNAL> state(isolate); |
7609 ExternalCallbackScope call_scope(isolate, callback_address); | 7660 ExternalCallbackScope call_scope(isolate, callback_address); |
7610 callback(info); | 7661 callback(info); |
7611 } | 7662 } |
7612 | 7663 |
7613 | 7664 |
7614 } } // namespace v8::internal | 7665 } } // namespace v8::internal |
OLD | NEW |