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

Side by Side Diff: src/api.cc

Issue 2040813005: [snapshot] remove metadata field. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: addressed nit Created 4 years, 6 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
« no previous file with comments | « include/v8.h ('k') | src/snapshot/snapshot.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 i::PrintF("Executing custom snapshot script %s took %0.3f ms\n", name, 378 i::PrintF("Executing custom snapshot script %s took %0.3f ms\n", name,
379 timer.Elapsed().InMillisecondsF()); 379 timer.Elapsed().InMillisecondsF());
380 } 380 }
381 timer.Stop(); 381 timer.Stop();
382 CHECK(!try_catch.HasCaught()); 382 CHECK(!try_catch.HasCaught());
383 return true; 383 return true;
384 } 384 }
385 385
386 StartupData SerializeIsolateAndContext( 386 StartupData SerializeIsolateAndContext(
387 Isolate* isolate, Persistent<Context>* context, 387 Isolate* isolate, Persistent<Context>* context,
388 i::Snapshot::Metadata metadata,
389 i::StartupSerializer::FunctionCodeHandling function_code_handling) { 388 i::StartupSerializer::FunctionCodeHandling function_code_handling) {
390 if (context->IsEmpty()) return {NULL, 0}; 389 if (context->IsEmpty()) return {NULL, 0};
391 390
392 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); 391 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
393 392
394 // If we don't do this then we end up with a stray root pointing at the 393 // If we don't do this then we end up with a stray root pointing at the
395 // context even after we have disposed of the context. 394 // context even after we have disposed of the context.
396 internal_isolate->heap()->CollectAllAvailableGarbage("mksnapshot"); 395 internal_isolate->heap()->CollectAllAvailableGarbage("mksnapshot");
397 396
398 // GC may have cleared weak cells, so compact any WeakFixedArrays 397 // GC may have cleared weak cells, so compact any WeakFixedArrays
(...skipping 22 matching lines...) Expand all
421 i::SnapshotByteSink snapshot_sink; 420 i::SnapshotByteSink snapshot_sink;
422 i::StartupSerializer ser(internal_isolate, &snapshot_sink, 421 i::StartupSerializer ser(internal_isolate, &snapshot_sink,
423 function_code_handling); 422 function_code_handling);
424 ser.SerializeStrongReferences(); 423 ser.SerializeStrongReferences();
425 424
426 i::SnapshotByteSink context_sink; 425 i::SnapshotByteSink context_sink;
427 i::PartialSerializer context_ser(internal_isolate, &ser, &context_sink); 426 i::PartialSerializer context_ser(internal_isolate, &ser, &context_sink);
428 context_ser.Serialize(&raw_context); 427 context_ser.Serialize(&raw_context);
429 ser.SerializeWeakReferencesAndDeferred(); 428 ser.SerializeWeakReferencesAndDeferred();
430 429
431 return i::Snapshot::CreateSnapshotBlob(ser, context_ser, metadata); 430 return i::Snapshot::CreateSnapshotBlob(ser, context_ser);
432 } 431 }
433 432
434 } // namespace 433 } // namespace
435 434
436 StartupData V8::CreateSnapshotDataBlob(const char* embedded_source) { 435 StartupData V8::CreateSnapshotDataBlob(const char* embedded_source) {
437 // Create a new isolate and a new context from scratch, optionally run 436 // Create a new isolate and a new context from scratch, optionally run
438 // a script to embed, and serialize to create a snapshot blob. 437 // a script to embed, and serialize to create a snapshot blob.
439 StartupData result = {NULL, 0}; 438 StartupData result = {NULL, 0};
440 439
441 base::ElapsedTimer timer; 440 base::ElapsedTimer timer;
(...skipping 11 matching lines...) Expand all
453 { 452 {
454 HandleScope handle_scope(isolate); 453 HandleScope handle_scope(isolate);
455 Local<Context> new_context = Context::New(isolate); 454 Local<Context> new_context = Context::New(isolate);
456 context.Reset(isolate, new_context); 455 context.Reset(isolate, new_context);
457 if (embedded_source != NULL && 456 if (embedded_source != NULL &&
458 !RunExtraCode(isolate, new_context, embedded_source, "<embedded>")) { 457 !RunExtraCode(isolate, new_context, embedded_source, "<embedded>")) {
459 context.Reset(); 458 context.Reset();
460 } 459 }
461 } 460 }
462 461
463 i::Snapshot::Metadata metadata;
464 metadata.set_embeds_script(embedded_source != NULL);
465
466 result = SerializeIsolateAndContext( 462 result = SerializeIsolateAndContext(
467 isolate, &context, metadata, i::StartupSerializer::CLEAR_FUNCTION_CODE); 463 isolate, &context, i::StartupSerializer::CLEAR_FUNCTION_CODE);
468 DCHECK(context.IsEmpty()); 464 DCHECK(context.IsEmpty());
469 } 465 }
470 isolate->Dispose(); 466 isolate->Dispose();
471 467
472 if (i::FLAG_profile_deserialization) { 468 if (i::FLAG_profile_deserialization) {
473 i::PrintF("Creating snapshot took %0.3f ms\n", 469 i::PrintF("Creating snapshot took %0.3f ms\n",
474 timer.Elapsed().InMillisecondsF()); 470 timer.Elapsed().InMillisecondsF());
475 } 471 }
476 timer.Stop(); 472 timer.Stop();
477 return result; 473 return result;
(...skipping 30 matching lines...) Expand all
508 Local<Context> new_context = Context::New(isolate); 504 Local<Context> new_context = Context::New(isolate);
509 success = RunExtraCode(isolate, new_context, warmup_source, "<warm-up>"); 505 success = RunExtraCode(isolate, new_context, warmup_source, "<warm-up>");
510 } 506 }
511 if (success) { 507 if (success) {
512 HandleScope handle_scope(isolate); 508 HandleScope handle_scope(isolate);
513 isolate->ContextDisposedNotification(false); 509 isolate->ContextDisposedNotification(false);
514 Local<Context> new_context = Context::New(isolate); 510 Local<Context> new_context = Context::New(isolate);
515 context.Reset(isolate, new_context); 511 context.Reset(isolate, new_context);
516 } 512 }
517 513
518 i::Snapshot::Metadata metadata;
519 metadata.set_embeds_script(i::Snapshot::EmbedsScript(internal_isolate));
520
521 result = SerializeIsolateAndContext( 514 result = SerializeIsolateAndContext(
522 isolate, &context, metadata, i::StartupSerializer::KEEP_FUNCTION_CODE); 515 isolate, &context, i::StartupSerializer::KEEP_FUNCTION_CODE);
523 DCHECK(context.IsEmpty()); 516 DCHECK(context.IsEmpty());
524 } 517 }
525 isolate->Dispose(); 518 isolate->Dispose();
526 519
527 if (i::FLAG_profile_deserialization) { 520 if (i::FLAG_profile_deserialization) {
528 i::PrintF("Warming up snapshot took %0.3f ms\n", 521 i::PrintF("Warming up snapshot took %0.3f ms\n",
529 timer.Elapsed().InMillisecondsF()); 522 timer.Elapsed().InMillisecondsF());
530 } 523 }
531 timer.Stop(); 524 timer.Stop();
532 return result; 525 return result;
(...skipping 6734 matching lines...) Expand 10 before | Expand all | Expand 10 after
7267 } 7260 }
7268 7261
7269 if (params.add_histogram_sample_callback) { 7262 if (params.add_histogram_sample_callback) {
7270 v8_isolate->SetAddHistogramSampleFunction( 7263 v8_isolate->SetAddHistogramSampleFunction(
7271 params.add_histogram_sample_callback); 7264 params.add_histogram_sample_callback);
7272 } 7265 }
7273 SetResourceConstraints(isolate, params.constraints); 7266 SetResourceConstraints(isolate, params.constraints);
7274 // TODO(jochen): Once we got rid of Isolate::Current(), we can remove this. 7267 // TODO(jochen): Once we got rid of Isolate::Current(), we can remove this.
7275 Isolate::Scope isolate_scope(v8_isolate); 7268 Isolate::Scope isolate_scope(v8_isolate);
7276 if (params.entry_hook || !i::Snapshot::Initialize(isolate)) { 7269 if (params.entry_hook || !i::Snapshot::Initialize(isolate)) {
7277 // If the isolate has a function entry hook, it needs to re-build all its
7278 // code stubs with entry hooks embedded, so don't deserialize a snapshot.
7279 if (i::Snapshot::EmbedsScript(isolate)) {
7280 // If the snapshot embeds a script, we cannot initialize the isolate
7281 // without the snapshot as a fallback. This is unlikely to happen though.
7282 V8_Fatal(__FILE__, __LINE__,
7283 "Initializing isolate from custom startup snapshot failed");
7284 }
7285 isolate->Init(NULL); 7270 isolate->Init(NULL);
7286 } 7271 }
7287 return v8_isolate; 7272 return v8_isolate;
7288 } 7273 }
7289 7274
7290 7275
7291 void Isolate::Dispose() { 7276 void Isolate::Dispose() {
7292 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); 7277 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
7293 if (!Utils::ApiCheck(!isolate->IsInUse(), 7278 if (!Utils::ApiCheck(!isolate->IsInUse(),
7294 "v8::Isolate::Dispose()", 7279 "v8::Isolate::Dispose()",
(...skipping 1529 matching lines...) Expand 10 before | Expand all | Expand 10 after
8824 Address callback_address = 8809 Address callback_address =
8825 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 8810 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
8826 VMState<EXTERNAL> state(isolate); 8811 VMState<EXTERNAL> state(isolate);
8827 ExternalCallbackScope call_scope(isolate, callback_address); 8812 ExternalCallbackScope call_scope(isolate, callback_address);
8828 callback(info); 8813 callback(info);
8829 } 8814 }
8830 8815
8831 8816
8832 } // namespace internal 8817 } // namespace internal
8833 } // namespace v8 8818 } // namespace v8
OLDNEW
« no previous file with comments | « include/v8.h ('k') | src/snapshot/snapshot.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698