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

Side by Side Diff: src/compiler.cc

Issue 8662037: Don't preparse large files to find boundaries of lazy functions. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Updated to match tip of bleeding edge Created 9 years 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | src/hydrogen.cc » ('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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 } 370 }
371 } 371 }
372 } 372 }
373 373
374 // Notify debugger 374 // Notify debugger
375 isolate->debugger()->OnBeforeCompile(script); 375 isolate->debugger()->OnBeforeCompile(script);
376 #endif 376 #endif
377 377
378 // Only allow non-global compiles for eval. 378 // Only allow non-global compiles for eval.
379 ASSERT(info->is_eval() || info->is_global()); 379 ASSERT(info->is_eval() || info->is_global());
380 380 ParsingFlags flags = kNoParsingFlags;
381 if (!ParserApi::Parse(info)) return Handle<SharedFunctionInfo>::null(); 381 if (info->pre_parse_data() != NULL ||
382 String::cast(script->source())->length() > FLAG_min_preparse_length) {
383 flags = kAllowLazy;
384 }
385 if (!ParserApi::Parse(info, flags)) {
386 return Handle<SharedFunctionInfo>::null();
387 }
382 388
383 // Measure how long it takes to do the compilation; only take the 389 // Measure how long it takes to do the compilation; only take the
384 // rest of the function into account to avoid overlap with the 390 // rest of the function into account to avoid overlap with the
385 // parsing statistics. 391 // parsing statistics.
386 HistogramTimer* rate = info->is_eval() 392 HistogramTimer* rate = info->is_eval()
387 ? info->isolate()->counters()->compile_eval() 393 ? info->isolate()->counters()->compile_eval()
388 : info->isolate()->counters()->compile(); 394 : info->isolate()->counters()->compile();
389 HistogramTimerScope timer(rate); 395 HistogramTimerScope timer(rate);
390 396
391 // Compile the code. 397 // Compile the code.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 452
447 return result; 453 return result;
448 } 454 }
449 455
450 456
451 Handle<SharedFunctionInfo> Compiler::Compile(Handle<String> source, 457 Handle<SharedFunctionInfo> Compiler::Compile(Handle<String> source,
452 Handle<Object> script_name, 458 Handle<Object> script_name,
453 int line_offset, 459 int line_offset,
454 int column_offset, 460 int column_offset,
455 v8::Extension* extension, 461 v8::Extension* extension,
456 ScriptDataImpl* input_pre_data, 462 ScriptDataImpl* pre_data,
457 Handle<Object> script_data, 463 Handle<Object> script_data,
458 NativesFlag natives) { 464 NativesFlag natives) {
459 Isolate* isolate = source->GetIsolate(); 465 Isolate* isolate = source->GetIsolate();
460 int source_length = source->length(); 466 int source_length = source->length();
461 isolate->counters()->total_load_size()->Increment(source_length); 467 isolate->counters()->total_load_size()->Increment(source_length);
462 isolate->counters()->total_compile_size()->Increment(source_length); 468 isolate->counters()->total_compile_size()->Increment(source_length);
463 469
464 // The VM is in the COMPILER state until exiting this function. 470 // The VM is in the COMPILER state until exiting this function.
465 VMState state(isolate, COMPILER); 471 VMState state(isolate, COMPILER);
466 472
(...skipping 10 matching lines...) Expand all
477 483
478 if (result.is_null()) { 484 if (result.is_null()) {
479 // No cache entry found. Do pre-parsing, if it makes sense, and compile 485 // No cache entry found. Do pre-parsing, if it makes sense, and compile
480 // the script. 486 // the script.
481 // Building preparse data that is only used immediately after is only a 487 // Building preparse data that is only used immediately after is only a
482 // saving if we might skip building the AST for lazily compiled functions. 488 // saving if we might skip building the AST for lazily compiled functions.
483 // I.e., preparse data isn't relevant when the lazy flag is off, and 489 // I.e., preparse data isn't relevant when the lazy flag is off, and
484 // for small sources, odds are that there aren't many functions 490 // for small sources, odds are that there aren't many functions
485 // that would be compiled lazily anyway, so we skip the preparse step 491 // that would be compiled lazily anyway, so we skip the preparse step
486 // in that case too. 492 // in that case too.
487 ScriptDataImpl* pre_data = input_pre_data;
488 int flags = kNoParsingFlags; 493 int flags = kNoParsingFlags;
489 if ((natives == NATIVES_CODE) || FLAG_allow_natives_syntax) { 494 if ((natives == NATIVES_CODE) || FLAG_allow_natives_syntax) {
490 flags |= kAllowNativesSyntax; 495 flags |= kAllowNativesSyntax;
491 } 496 }
492 if (natives != NATIVES_CODE && FLAG_harmony_scoping) { 497 if (natives != NATIVES_CODE && FLAG_harmony_scoping) {
493 flags |= kHarmonyScoping; 498 flags |= EXTENDED_MODE;
494 }
495 if (pre_data == NULL
496 && source_length >= FLAG_min_preparse_length) {
497 if (source->IsExternalTwoByteString()) {
498 ExternalTwoByteStringUC16CharacterStream stream(
499 Handle<ExternalTwoByteString>::cast(source), 0, source->length());
500 pre_data = ParserApi::PartialPreParse(&stream, extension, flags);
501 } else {
502 GenericStringUC16CharacterStream stream(source, 0, source->length());
503 pre_data = ParserApi::PartialPreParse(&stream, extension, flags);
504 }
505 } 499 }
506 500
507 // Create a script object describing the script to be compiled. 501 // Create a script object describing the script to be compiled.
508 Handle<Script> script = FACTORY->NewScript(source); 502 Handle<Script> script = FACTORY->NewScript(source);
509 if (natives == NATIVES_CODE) { 503 if (natives == NATIVES_CODE) {
510 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); 504 script->set_type(Smi::FromInt(Script::TYPE_NATIVE));
511 } 505 }
512 if (!script_name.is_null()) { 506 if (!script_name.is_null()) {
513 script->set_name(*script_name); 507 script->set_name(*script_name);
514 script->set_line_offset(Smi::FromInt(line_offset)); 508 script->set_line_offset(Smi::FromInt(line_offset));
515 script->set_column_offset(Smi::FromInt(column_offset)); 509 script->set_column_offset(Smi::FromInt(column_offset));
516 } 510 }
517 511
518 script->set_data(script_data.is_null() ? HEAP->undefined_value() 512 script->set_data(script_data.is_null() ? HEAP->undefined_value()
519 : *script_data); 513 : *script_data);
520 514
521 // Compile the function and add it to the cache. 515 // Compile the function and add it to the cache.
522 CompilationInfo info(script); 516 CompilationInfo info(script);
523 info.MarkAsGlobal(); 517 info.MarkAsGlobal();
524 info.SetExtension(extension); 518 info.SetExtension(extension);
525 info.SetPreParseData(pre_data); 519 info.SetPreParseData(pre_data);
526 result = MakeFunctionInfo(&info); 520 result = MakeFunctionInfo(&info);
527 if (extension == NULL && !result.is_null()) { 521 if (extension == NULL && !result.is_null()) {
528 compilation_cache->PutScript(source, result); 522 compilation_cache->PutScript(source, result);
529 } 523 }
530
531 // Get rid of the pre-parsing data (if necessary).
532 if (input_pre_data == NULL && pre_data != NULL) {
533 delete pre_data;
534 }
535 } 524 }
536 525
537 if (result.is_null()) isolate->ReportPendingMessages(); 526 if (result.is_null()) isolate->ReportPendingMessages();
538 return result; 527 return result;
539 } 528 }
540 529
541 530
542 Handle<SharedFunctionInfo> Compiler::CompileEval(Handle<String> source, 531 Handle<SharedFunctionInfo> Compiler::CompileEval(Handle<String> source,
543 Handle<Context> context, 532 Handle<Context> context,
544 bool is_global, 533 bool is_global,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 // The VM is in the COMPILER state until exiting this function. 586 // The VM is in the COMPILER state until exiting this function.
598 VMState state(isolate, COMPILER); 587 VMState state(isolate, COMPILER);
599 588
600 PostponeInterruptsScope postpone(isolate); 589 PostponeInterruptsScope postpone(isolate);
601 590
602 Handle<SharedFunctionInfo> shared = info->shared_info(); 591 Handle<SharedFunctionInfo> shared = info->shared_info();
603 int compiled_size = shared->end_position() - shared->start_position(); 592 int compiled_size = shared->end_position() - shared->start_position();
604 isolate->counters()->total_compile_size()->Increment(compiled_size); 593 isolate->counters()->total_compile_size()->Increment(compiled_size);
605 594
606 // Generate the AST for the lazily compiled function. 595 // Generate the AST for the lazily compiled function.
607 if (ParserApi::Parse(info)) { 596 if (ParserApi::Parse(info, kNoParsingFlags)) {
608 // Measure how long it takes to do the lazy compilation; only take the 597 // Measure how long it takes to do the lazy compilation; only take the
609 // rest of the function into account to avoid overlap with the lazy 598 // rest of the function into account to avoid overlap with the lazy
610 // parsing statistics. 599 // parsing statistics.
611 HistogramTimerScope timer(isolate->counters()->compile_lazy()); 600 HistogramTimerScope timer(isolate->counters()->compile_lazy());
612 601
613 // After parsing we know the function's language mode. Remember it. 602 // After parsing we know the function's language mode. Remember it.
614 LanguageMode language_mode = info->function()->language_mode(); 603 LanguageMode language_mode = info->function()->language_mode();
615 info->SetLanguageMode(language_mode); 604 info->SetLanguageMode(language_mode);
616 shared->set_language_mode(language_mode); 605 shared->set_language_mode(language_mode);
617 606
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 } 786 }
798 } 787 }
799 788
800 GDBJIT(AddCode(Handle<String>(shared->DebugName()), 789 GDBJIT(AddCode(Handle<String>(shared->DebugName()),
801 Handle<Script>(info->script()), 790 Handle<Script>(info->script()),
802 Handle<Code>(info->code()), 791 Handle<Code>(info->code()),
803 info)); 792 info));
804 } 793 }
805 794
806 } } // namespace v8::internal 795 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/hydrogen.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698