| OLD | NEW |
| 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 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 } | 368 } |
| 369 } | 369 } |
| 370 } | 370 } |
| 371 | 371 |
| 372 // Notify debugger | 372 // Notify debugger |
| 373 isolate->debugger()->OnBeforeCompile(script); | 373 isolate->debugger()->OnBeforeCompile(script); |
| 374 #endif | 374 #endif |
| 375 | 375 |
| 376 // Only allow non-global compiles for eval. | 376 // Only allow non-global compiles for eval. |
| 377 ASSERT(info->is_eval() || info->is_global()); | 377 ASSERT(info->is_eval() || info->is_global()); |
| 378 | 378 ParsingFlags flags = kNoParsingFlags; |
| 379 if (!ParserApi::Parse(info)) return Handle<SharedFunctionInfo>::null(); | 379 if (info->pre_parse_data() != NULL || |
| 380 String::cast(script->source())->length() > FLAG_min_preparse_length) { |
| 381 flags = kAllowLazy; |
| 382 } |
| 383 if (!ParserApi::Parse(info, flags)) { |
| 384 return Handle<SharedFunctionInfo>::null(); |
| 385 } |
| 380 | 386 |
| 381 // Measure how long it takes to do the compilation; only take the | 387 // Measure how long it takes to do the compilation; only take the |
| 382 // rest of the function into account to avoid overlap with the | 388 // rest of the function into account to avoid overlap with the |
| 383 // parsing statistics. | 389 // parsing statistics. |
| 384 HistogramTimer* rate = info->is_eval() | 390 HistogramTimer* rate = info->is_eval() |
| 385 ? info->isolate()->counters()->compile_eval() | 391 ? info->isolate()->counters()->compile_eval() |
| 386 : info->isolate()->counters()->compile(); | 392 : info->isolate()->counters()->compile(); |
| 387 HistogramTimerScope timer(rate); | 393 HistogramTimerScope timer(rate); |
| 388 | 394 |
| 389 // Compile the code. | 395 // Compile the code. |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 | 450 |
| 445 return result; | 451 return result; |
| 446 } | 452 } |
| 447 | 453 |
| 448 | 454 |
| 449 Handle<SharedFunctionInfo> Compiler::Compile(Handle<String> source, | 455 Handle<SharedFunctionInfo> Compiler::Compile(Handle<String> source, |
| 450 Handle<Object> script_name, | 456 Handle<Object> script_name, |
| 451 int line_offset, | 457 int line_offset, |
| 452 int column_offset, | 458 int column_offset, |
| 453 v8::Extension* extension, | 459 v8::Extension* extension, |
| 454 ScriptDataImpl* input_pre_data, | 460 ScriptDataImpl* pre_data, |
| 455 Handle<Object> script_data, | 461 Handle<Object> script_data, |
| 456 NativesFlag natives) { | 462 NativesFlag natives) { |
| 457 Isolate* isolate = source->GetIsolate(); | 463 Isolate* isolate = source->GetIsolate(); |
| 458 int source_length = source->length(); | 464 int source_length = source->length(); |
| 459 isolate->counters()->total_load_size()->Increment(source_length); | 465 isolate->counters()->total_load_size()->Increment(source_length); |
| 460 isolate->counters()->total_compile_size()->Increment(source_length); | 466 isolate->counters()->total_compile_size()->Increment(source_length); |
| 461 | 467 |
| 462 // The VM is in the COMPILER state until exiting this function. | 468 // The VM is in the COMPILER state until exiting this function. |
| 463 VMState state(isolate, COMPILER); | 469 VMState state(isolate, COMPILER); |
| 464 | 470 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 475 | 481 |
| 476 if (result.is_null()) { | 482 if (result.is_null()) { |
| 477 // No cache entry found. Do pre-parsing, if it makes sense, and compile | 483 // No cache entry found. Do pre-parsing, if it makes sense, and compile |
| 478 // the script. | 484 // the script. |
| 479 // Building preparse data that is only used immediately after is only a | 485 // Building preparse data that is only used immediately after is only a |
| 480 // saving if we might skip building the AST for lazily compiled functions. | 486 // saving if we might skip building the AST for lazily compiled functions. |
| 481 // I.e., preparse data isn't relevant when the lazy flag is off, and | 487 // I.e., preparse data isn't relevant when the lazy flag is off, and |
| 482 // for small sources, odds are that there aren't many functions | 488 // for small sources, odds are that there aren't many functions |
| 483 // that would be compiled lazily anyway, so we skip the preparse step | 489 // that would be compiled lazily anyway, so we skip the preparse step |
| 484 // in that case too. | 490 // in that case too. |
| 485 ScriptDataImpl* pre_data = input_pre_data; | |
| 486 int flags = kNoParsingFlags; | 491 int flags = kNoParsingFlags; |
| 487 if ((natives == NATIVES_CODE) || FLAG_allow_natives_syntax) { | 492 if ((natives == NATIVES_CODE) || FLAG_allow_natives_syntax) { |
| 488 flags |= kAllowNativesSyntax; | 493 flags |= kAllowNativesSyntax; |
| 489 } | 494 } |
| 490 if (natives != NATIVES_CODE && FLAG_harmony_scoping) { | 495 if (natives != NATIVES_CODE && FLAG_harmony_scoping) { |
| 491 flags |= kHarmonyScoping; | 496 flags |= kHarmonyScoping; |
| 492 } | 497 } |
| 493 if (pre_data == NULL | |
| 494 && source_length >= FLAG_min_preparse_length) { | |
| 495 if (source->IsExternalTwoByteString()) { | |
| 496 ExternalTwoByteStringUC16CharacterStream stream( | |
| 497 Handle<ExternalTwoByteString>::cast(source), 0, source->length()); | |
| 498 pre_data = ParserApi::PartialPreParse(&stream, extension, flags); | |
| 499 } else { | |
| 500 GenericStringUC16CharacterStream stream(source, 0, source->length()); | |
| 501 pre_data = ParserApi::PartialPreParse(&stream, extension, flags); | |
| 502 } | |
| 503 } | |
| 504 | 498 |
| 505 // Create a script object describing the script to be compiled. | 499 // Create a script object describing the script to be compiled. |
| 506 Handle<Script> script = FACTORY->NewScript(source); | 500 Handle<Script> script = FACTORY->NewScript(source); |
| 507 if (natives == NATIVES_CODE) { | 501 if (natives == NATIVES_CODE) { |
| 508 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); | 502 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); |
| 509 } | 503 } |
| 510 if (!script_name.is_null()) { | 504 if (!script_name.is_null()) { |
| 511 script->set_name(*script_name); | 505 script->set_name(*script_name); |
| 512 script->set_line_offset(Smi::FromInt(line_offset)); | 506 script->set_line_offset(Smi::FromInt(line_offset)); |
| 513 script->set_column_offset(Smi::FromInt(column_offset)); | 507 script->set_column_offset(Smi::FromInt(column_offset)); |
| 514 } | 508 } |
| 515 | 509 |
| 516 script->set_data(script_data.is_null() ? HEAP->undefined_value() | 510 script->set_data(script_data.is_null() ? HEAP->undefined_value() |
| 517 : *script_data); | 511 : *script_data); |
| 518 | 512 |
| 519 // Compile the function and add it to the cache. | 513 // Compile the function and add it to the cache. |
| 520 CompilationInfo info(script); | 514 CompilationInfo info(script); |
| 521 info.MarkAsGlobal(); | 515 info.MarkAsGlobal(); |
| 522 info.SetExtension(extension); | 516 info.SetExtension(extension); |
| 523 info.SetPreParseData(pre_data); | 517 info.SetPreParseData(pre_data); |
| 524 result = MakeFunctionInfo(&info); | 518 result = MakeFunctionInfo(&info); |
| 525 if (extension == NULL && !result.is_null()) { | 519 if (extension == NULL && !result.is_null()) { |
| 526 compilation_cache->PutScript(source, result); | 520 compilation_cache->PutScript(source, result); |
| 527 } | 521 } |
| 528 | |
| 529 // Get rid of the pre-parsing data (if necessary). | |
| 530 if (input_pre_data == NULL && pre_data != NULL) { | |
| 531 delete pre_data; | |
| 532 } | |
| 533 } | 522 } |
| 534 | 523 |
| 535 if (result.is_null()) isolate->ReportPendingMessages(); | 524 if (result.is_null()) isolate->ReportPendingMessages(); |
| 536 return result; | 525 return result; |
| 537 } | 526 } |
| 538 | 527 |
| 539 | 528 |
| 540 Handle<SharedFunctionInfo> Compiler::CompileEval(Handle<String> source, | 529 Handle<SharedFunctionInfo> Compiler::CompileEval(Handle<String> source, |
| 541 Handle<Context> context, | 530 Handle<Context> context, |
| 542 bool is_global, | 531 bool is_global, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 // The VM is in the COMPILER state until exiting this function. | 581 // The VM is in the COMPILER state until exiting this function. |
| 593 VMState state(isolate, COMPILER); | 582 VMState state(isolate, COMPILER); |
| 594 | 583 |
| 595 PostponeInterruptsScope postpone(isolate); | 584 PostponeInterruptsScope postpone(isolate); |
| 596 | 585 |
| 597 Handle<SharedFunctionInfo> shared = info->shared_info(); | 586 Handle<SharedFunctionInfo> shared = info->shared_info(); |
| 598 int compiled_size = shared->end_position() - shared->start_position(); | 587 int compiled_size = shared->end_position() - shared->start_position(); |
| 599 isolate->counters()->total_compile_size()->Increment(compiled_size); | 588 isolate->counters()->total_compile_size()->Increment(compiled_size); |
| 600 | 589 |
| 601 // Generate the AST for the lazily compiled function. | 590 // Generate the AST for the lazily compiled function. |
| 602 if (ParserApi::Parse(info)) { | 591 if (ParserApi::Parse(info, kNoParsingFlags)) { |
| 603 // Measure how long it takes to do the lazy compilation; only take the | 592 // Measure how long it takes to do the lazy compilation; only take the |
| 604 // rest of the function into account to avoid overlap with the lazy | 593 // rest of the function into account to avoid overlap with the lazy |
| 605 // parsing statistics. | 594 // parsing statistics. |
| 606 HistogramTimerScope timer(isolate->counters()->compile_lazy()); | 595 HistogramTimerScope timer(isolate->counters()->compile_lazy()); |
| 607 | 596 |
| 608 // After parsing we know function's strict mode. Remember it. | 597 // After parsing we know function's strict mode. Remember it. |
| 609 StrictModeFlag strict_mode = info->function()->strict_mode_flag(); | 598 StrictModeFlag strict_mode = info->function()->strict_mode_flag(); |
| 610 ASSERT(info->strict_mode_flag() == kNonStrictMode || | 599 ASSERT(info->strict_mode_flag() == kNonStrictMode || |
| 611 info->strict_mode_flag() == strict_mode); | 600 info->strict_mode_flag() == strict_mode); |
| 612 ASSERT(shared->strict_mode_flag() == kNonStrictMode || | 601 ASSERT(shared->strict_mode_flag() == kNonStrictMode || |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 } | 785 } |
| 797 } | 786 } |
| 798 | 787 |
| 799 GDBJIT(AddCode(Handle<String>(shared->DebugName()), | 788 GDBJIT(AddCode(Handle<String>(shared->DebugName()), |
| 800 Handle<Script>(info->script()), | 789 Handle<Script>(info->script()), |
| 801 Handle<Code>(info->code()), | 790 Handle<Code>(info->code()), |
| 802 info)); | 791 info)); |
| 803 } | 792 } |
| 804 | 793 |
| 805 } } // namespace v8::internal | 794 } } // namespace v8::internal |
| OLD | NEW |