OLD | NEW |
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 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 840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
851 accept_ = new EndNode(EndNode::ACCEPT); | 851 accept_ = new EndNode(EndNode::ACCEPT); |
852 ASSERT(next_register_ - 1 <= RegExpMacroAssembler::kMaxRegister); | 852 ASSERT(next_register_ - 1 <= RegExpMacroAssembler::kMaxRegister); |
853 } | 853 } |
854 | 854 |
855 | 855 |
856 RegExpEngine::CompilationResult RegExpCompiler::Assemble( | 856 RegExpEngine::CompilationResult RegExpCompiler::Assemble( |
857 RegExpMacroAssembler* macro_assembler, | 857 RegExpMacroAssembler* macro_assembler, |
858 RegExpNode* start, | 858 RegExpNode* start, |
859 int capture_count, | 859 int capture_count, |
860 Handle<String> pattern) { | 860 Handle<String> pattern) { |
| 861 Heap* heap = pattern->GetHeap(); |
| 862 |
| 863 bool use_slow_safe_regexp_compiler = false; |
| 864 if (heap->total_regexp_code_generated() > |
| 865 RegExpImpl::kRegWxpCompiledLimit && |
| 866 heap->isolate()->memory_allocator()->SizeExecutable() > |
| 867 RegExpImpl::kRegExpExecutableMemoryLimit) { |
| 868 use_slow_safe_regexp_compiler = true; |
| 869 } |
| 870 |
| 871 macro_assembler->set_slow_safe(use_slow_safe_regexp_compiler); |
| 872 |
861 #ifdef DEBUG | 873 #ifdef DEBUG |
862 if (FLAG_trace_regexp_assembler) | 874 if (FLAG_trace_regexp_assembler) |
863 macro_assembler_ = new RegExpMacroAssemblerTracer(macro_assembler); | 875 macro_assembler_ = new RegExpMacroAssemblerTracer(macro_assembler); |
864 else | 876 else |
865 #endif | 877 #endif |
866 macro_assembler_ = macro_assembler; | 878 macro_assembler_ = macro_assembler; |
| 879 |
867 List <RegExpNode*> work_list(0); | 880 List <RegExpNode*> work_list(0); |
868 work_list_ = &work_list; | 881 work_list_ = &work_list; |
869 Label fail; | 882 Label fail; |
870 macro_assembler_->PushBacktrack(&fail); | 883 macro_assembler_->PushBacktrack(&fail); |
871 Trace new_trace; | 884 Trace new_trace; |
872 start->Emit(this, &new_trace); | 885 start->Emit(this, &new_trace); |
873 macro_assembler_->Bind(&fail); | 886 macro_assembler_->Bind(&fail); |
874 macro_assembler_->Fail(); | 887 macro_assembler_->Fail(); |
875 while (!work_list.is_empty()) { | 888 while (!work_list.is_empty()) { |
876 work_list.RemoveLast()->Emit(this, &new_trace); | 889 work_list.RemoveLast()->Emit(this, &new_trace); |
877 } | 890 } |
878 if (reg_exp_too_big_) return IrregexpRegExpTooBig(); | 891 if (reg_exp_too_big_) return IrregexpRegExpTooBig(); |
879 | 892 |
880 Handle<Object> code = macro_assembler_->GetCode(pattern); | 893 Handle<HeapObject> code = macro_assembler_->GetCode(pattern); |
| 894 heap->IncreaseTotalRegexpCodeGenerated(code->Size()); |
881 work_list_ = NULL; | 895 work_list_ = NULL; |
882 #ifdef DEBUG | 896 #ifdef DEBUG |
883 if (FLAG_print_code) { | 897 if (FLAG_print_code) { |
884 Handle<Code>::cast(code)->Disassemble(*pattern->ToCString()); | 898 Handle<Code>::cast(code)->Disassemble(*pattern->ToCString()); |
885 } | 899 } |
886 if (FLAG_trace_regexp_assembler) { | 900 if (FLAG_trace_regexp_assembler) { |
887 delete macro_assembler_; | 901 delete macro_assembler_; |
888 } | 902 } |
889 #endif | 903 #endif |
890 return RegExpEngine::CompilationResult(*code, next_register_); | 904 return RegExpEngine::CompilationResult(*code, next_register_); |
(...skipping 4471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5362 } | 5376 } |
5363 | 5377 |
5364 return compiler.Assemble(¯o_assembler, | 5378 return compiler.Assemble(¯o_assembler, |
5365 node, | 5379 node, |
5366 data->capture_count, | 5380 data->capture_count, |
5367 pattern); | 5381 pattern); |
5368 } | 5382 } |
5369 | 5383 |
5370 | 5384 |
5371 }} // namespace v8::internal | 5385 }} // namespace v8::internal |
OLD | NEW |