| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 } | 249 } |
| 250 | 250 |
| 251 | 251 |
| 252 Handle<String> Parser::LookupSymbol(int symbol_id) { | 252 Handle<String> Parser::LookupSymbol(int symbol_id) { |
| 253 // Length of symbol cache is the number of identified symbols. | 253 // Length of symbol cache is the number of identified symbols. |
| 254 // If we are larger than that, or negative, it's not a cached symbol. | 254 // If we are larger than that, or negative, it's not a cached symbol. |
| 255 // This might also happen if there is no preparser symbol data, even | 255 // This might also happen if there is no preparser symbol data, even |
| 256 // if there is some preparser data. | 256 // if there is some preparser data. |
| 257 if (static_cast<unsigned>(symbol_id) | 257 if (static_cast<unsigned>(symbol_id) |
| 258 >= static_cast<unsigned>(symbol_cache_.length())) { | 258 >= static_cast<unsigned>(symbol_cache_.length())) { |
| 259 if (scanner().is_literal_ascii()) { | 259 return scanner().GetLiteralSymbol(); |
| 260 return isolate()->factory()->InternalizeOneByteString( | |
| 261 Vector<const uint8_t>::cast(scanner().literal_ascii_string())); | |
| 262 } else { | |
| 263 return isolate()->factory()->InternalizeTwoByteString( | |
| 264 scanner().literal_utf16_string()); | |
| 265 } | |
| 266 } | 260 } |
| 267 return LookupCachedSymbol(symbol_id); | 261 return LookupCachedSymbol(symbol_id); |
| 268 } | 262 } |
| 269 | 263 |
| 270 | 264 |
| 271 Handle<String> Parser::LookupCachedSymbol(int symbol_id) { | 265 Handle<String> Parser::LookupCachedSymbol(int symbol_id) { |
| 272 // Make sure the cache is large enough to hold the symbol identifier. | 266 // Make sure the cache is large enough to hold the symbol identifier. |
| 273 if (symbol_cache_.length() <= symbol_id) { | 267 if (symbol_cache_.length() <= symbol_id) { |
| 274 // Increase length to index + 1. | 268 // Increase length to index + 1. |
| 275 symbol_cache_.AddBlock(Handle<String>::null(), | 269 symbol_cache_.AddBlock(Handle<String>::null(), |
| 276 symbol_id + 1 - symbol_cache_.length(), zone()); | 270 symbol_id + 1 - symbol_cache_.length(), zone()); |
| 277 } | 271 } |
| 278 Handle<String> result = symbol_cache_.at(symbol_id); | 272 Handle<String> result = symbol_cache_.at(symbol_id); |
| 279 if (result.is_null()) { | 273 if (result.is_null()) { |
| 280 if (scanner().is_literal_ascii()) { | 274 result = scanner().GetLiteralSymbol(); |
| 281 result = isolate()->factory()->InternalizeOneByteString( | |
| 282 Vector<const uint8_t>::cast(scanner().literal_ascii_string())); | |
| 283 } else { | |
| 284 result = isolate()->factory()->InternalizeTwoByteString( | |
| 285 scanner().literal_utf16_string()); | |
| 286 } | |
| 287 symbol_cache_.at(symbol_id) = result; | 275 symbol_cache_.at(symbol_id) = result; |
| 288 return result; | 276 return result; |
| 289 } | 277 } |
| 290 isolate()->counters()->total_preparse_symbols_skipped()->Increment(); | 278 isolate()->counters()->total_preparse_symbols_skipped()->Increment(); |
| 291 return result; | 279 return result; |
| 292 } | 280 } |
| 293 | 281 |
| 294 | 282 |
| 295 FunctionEntry ScriptDataImpl::GetFunctionEntry(int start) { | 283 FunctionEntry ScriptDataImpl::GetFunctionEntry(int start) { |
| 296 // The current pre-data entry must be a FunctionEntry with the given | 284 // The current pre-data entry must be a FunctionEntry with the given |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 HistogramTimerScope timer_scope(isolate()->counters()->parse(), true); | 557 HistogramTimerScope timer_scope(isolate()->counters()->parse(), true); |
| 570 Handle<String> source(String::cast(script_->source())); | 558 Handle<String> source(String::cast(script_->source())); |
| 571 isolate()->counters()->total_parse_size()->Increment(source->length()); | 559 isolate()->counters()->total_parse_size()->Increment(source->length()); |
| 572 ElapsedTimer timer; | 560 ElapsedTimer timer; |
| 573 if (FLAG_trace_parse) { | 561 if (FLAG_trace_parse) { |
| 574 timer.Start(); | 562 timer.Start(); |
| 575 } | 563 } |
| 576 fni_ = new(zone()) FuncNameInferrer(isolate(), zone()); | 564 fni_ = new(zone()) FuncNameInferrer(isolate(), zone()); |
| 577 | 565 |
| 578 // Initialize parser state. | 566 // Initialize parser state. |
| 579 FlattenString(source); | 567 source = FlattenGetString(source); |
| 580 FunctionLiteral* result; | 568 FunctionLiteral* result; |
| 581 if (source->IsTwoByteRepresentation()) { | 569 if (source->IsTwoByteRepresentation()) { |
| 582 delete reusable_preparser_; | 570 delete reusable_preparser_; |
| 583 delete scanner_; | 571 delete scanner_; |
| 584 scanner_ = new ExperimentalScanner<uint16_t>(source, isolate()); | 572 scanner_ = new ExperimentalScanner<uint16_t>(source, isolate()); |
| 585 } else { | 573 } else { |
| 586 delete reusable_preparser_; | 574 delete reusable_preparser_; |
| 587 delete scanner_; | 575 delete scanner_; |
| 588 scanner_ = new ExperimentalScanner<uint8_t>(source, isolate()); | 576 scanner_ = new ExperimentalScanner<uint8_t>(source, isolate()); |
| 589 } | 577 } |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 | 688 |
| 701 FunctionLiteral* Parser::ParseLazy() { | 689 FunctionLiteral* Parser::ParseLazy() { |
| 702 HistogramTimerScope timer_scope(isolate()->counters()->parse_lazy()); | 690 HistogramTimerScope timer_scope(isolate()->counters()->parse_lazy()); |
| 703 Handle<String> source(String::cast(script_->source())); | 691 Handle<String> source(String::cast(script_->source())); |
| 704 isolate()->counters()->total_parse_size()->Increment(source->length()); | 692 isolate()->counters()->total_parse_size()->Increment(source->length()); |
| 705 ElapsedTimer timer; | 693 ElapsedTimer timer; |
| 706 if (FLAG_trace_parse) { | 694 if (FLAG_trace_parse) { |
| 707 timer.Start(); | 695 timer.Start(); |
| 708 } | 696 } |
| 709 // Initialize parser state. | 697 // Initialize parser state. |
| 710 FlattenString(source); | |
| 711 Handle<SharedFunctionInfo> shared_info = info()->shared_info(); | 698 Handle<SharedFunctionInfo> shared_info = info()->shared_info(); |
| 712 FunctionLiteral* result = ParseLazy( | 699 FunctionLiteral* result = ParseLazy( |
| 713 source, shared_info->start_position(), shared_info->end_position()); | 700 source, shared_info->start_position(), shared_info->end_position()); |
| 714 if (FLAG_trace_parse && result != NULL) { | 701 if (FLAG_trace_parse && result != NULL) { |
| 715 double ms = timer.Elapsed().InMillisecondsF(); | 702 double ms = timer.Elapsed().InMillisecondsF(); |
| 716 SmartArrayPointer<char> name_chars = result->debug_name()->ToCString(); | 703 SmartArrayPointer<char> name_chars = result->debug_name()->ToCString(); |
| 717 PrintF("[parsing function: %s - took %0.3f ms]\n", name_chars.get(), ms); | 704 PrintF("[parsing function: %s - took %0.3f ms]\n", name_chars.get(), ms); |
| 718 } | 705 } |
| 719 return result; | 706 return result; |
| 720 } | 707 } |
| 721 | 708 |
| 722 | 709 |
| 723 FunctionLiteral* Parser::ParseLazy(Handle<String> source, int start, int end) { | 710 FunctionLiteral* Parser::ParseLazy(Handle<String> source, int start, int end) { |
| 711 source = FlattenGetString(source); |
| 724 delete reusable_preparser_; | 712 delete reusable_preparser_; |
| 725 delete scanner_; | 713 delete scanner_; |
| 726 if (source->IsTwoByteRepresentation()) { | 714 if (source->IsTwoByteRepresentation()) { |
| 727 scanner_ = new ExperimentalScanner<uint16_t>(source, isolate()); | 715 scanner_ = new ExperimentalScanner<uint16_t>(source, isolate()); |
| 728 } else { | 716 } else { |
| 729 scanner_ = new ExperimentalScanner<uint8_t>(source, isolate()); | 717 scanner_ = new ExperimentalScanner<uint8_t>(source, isolate()); |
| 730 } | 718 } |
| 731 SetScannerFlags(); | 719 SetScannerFlags(); |
| 732 // We don't need to Init() if we immediately SeekForward. | 720 // We don't need to Init() if we immediately SeekForward. |
| 733 scanner_->SeekForward(start); | 721 scanner_->SeekForward(start); |
| (...skipping 4873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5607 return result; | 5595 return result; |
| 5608 } | 5596 } |
| 5609 | 5597 |
| 5610 | 5598 |
| 5611 // Create a ScannerBase for the preparser to use as input, and preparse the | 5599 // Create a ScannerBase for the preparser to use as input, and preparse the |
| 5612 // source. | 5600 // source. |
| 5613 ScriptDataImpl* PreParserApi::PreParse(Isolate* isolate, | 5601 ScriptDataImpl* PreParserApi::PreParse(Isolate* isolate, |
| 5614 Handle<String> source) { | 5602 Handle<String> source) { |
| 5615 CompleteParserRecorder recorder; | 5603 CompleteParserRecorder recorder; |
| 5616 HistogramTimerScope timer(isolate->counters()->pre_parse()); | 5604 HistogramTimerScope timer(isolate->counters()->pre_parse()); |
| 5605 source = FlattenGetString(source); |
| 5617 ScannerBase* scanner = NULL; | 5606 ScannerBase* scanner = NULL; |
| 5618 if (source->IsTwoByteRepresentation()) { | 5607 if (source->IsTwoByteRepresentation()) { |
| 5619 scanner = new ExperimentalScanner<uint16_t>(source, isolate); | 5608 scanner = new ExperimentalScanner<uint16_t>(source, isolate); |
| 5620 } else { | 5609 } else { |
| 5621 scanner = new ExperimentalScanner<uint8_t>(source, isolate); | 5610 scanner = new ExperimentalScanner<uint8_t>(source, isolate); |
| 5622 } | 5611 } |
| 5623 intptr_t stack_limit = isolate->stack_guard()->real_climit(); | 5612 intptr_t stack_limit = isolate->stack_guard()->real_climit(); |
| 5624 PreParser preparser(scanner, &recorder, stack_limit); | 5613 PreParser preparser(scanner, &recorder, stack_limit); |
| 5625 preparser.set_allow_lazy(true); | 5614 preparser.set_allow_lazy(true); |
| 5626 preparser.set_allow_generators(FLAG_harmony_generators); | 5615 preparser.set_allow_generators(FLAG_harmony_generators); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5699 } | 5688 } |
| 5700 | 5689 |
| 5701 | 5690 |
| 5702 void Parser::SetScannerFlags() { | 5691 void Parser::SetScannerFlags() { |
| 5703 scanner_->SetHarmonyScoping(allow_harmony_scoping_); | 5692 scanner_->SetHarmonyScoping(allow_harmony_scoping_); |
| 5704 scanner_->SetHarmonyModules(allow_harmony_modules_); | 5693 scanner_->SetHarmonyModules(allow_harmony_modules_); |
| 5705 scanner_->SetHarmonyNumericLiterals(allow_harmony_numeric_literals_); | 5694 scanner_->SetHarmonyNumericLiterals(allow_harmony_numeric_literals_); |
| 5706 } | 5695 } |
| 5707 | 5696 |
| 5708 } } // namespace v8::internal | 5697 } } // namespace v8::internal |
| OLD | NEW |