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 17 matching lines...) Expand all Loading... | |
28 #include "v8.h" | 28 #include "v8.h" |
29 | 29 |
30 #include "compiler.h" | 30 #include "compiler.h" |
31 | 31 |
32 #include "bootstrapper.h" | 32 #include "bootstrapper.h" |
33 #include "codegen.h" | 33 #include "codegen.h" |
34 #include "compilation-cache.h" | 34 #include "compilation-cache.h" |
35 #include "cpu-profiler.h" | 35 #include "cpu-profiler.h" |
36 #include "debug.h" | 36 #include "debug.h" |
37 #include "deoptimizer.h" | 37 #include "deoptimizer.h" |
38 #include "feedbackslots.h" | |
38 #include "full-codegen.h" | 39 #include "full-codegen.h" |
39 #include "gdb-jit.h" | 40 #include "gdb-jit.h" |
40 #include "typing.h" | 41 #include "typing.h" |
41 #include "hydrogen.h" | 42 #include "hydrogen.h" |
42 #include "isolate-inl.h" | 43 #include "isolate-inl.h" |
43 #include "lithium.h" | 44 #include "lithium.h" |
44 #include "liveedit.h" | 45 #include "liveedit.h" |
45 #include "parser.h" | 46 #include "parser.h" |
46 #include "rewriter.h" | 47 #include "rewriter.h" |
47 #include "runtime-profiler.h" | 48 #include "runtime-profiler.h" |
48 #include "scanner-character-streams.h" | 49 #include "scanner-character-streams.h" |
49 #include "scopeinfo.h" | 50 #include "scopeinfo.h" |
50 #include "scopes.h" | 51 #include "scopes.h" |
51 #include "vm-state-inl.h" | 52 #include "vm-state-inl.h" |
52 | 53 |
53 namespace v8 { | 54 namespace v8 { |
54 namespace internal { | 55 namespace internal { |
55 | 56 |
56 | 57 |
57 CompilationInfo::CompilationInfo(Handle<Script> script, | 58 CompilationInfo::CompilationInfo(Handle<Script> script, |
58 Zone* zone) | 59 Zone* zone) |
59 : flags_(LanguageModeField::encode(CLASSIC_MODE)), | 60 : flags_(LanguageModeField::encode(CLASSIC_MODE)), |
60 script_(script), | 61 script_(script), |
61 osr_ast_id_(BailoutId::None()), | 62 osr_ast_id_(BailoutId::None()), |
62 parameter_count_(0), | 63 parameter_count_(0), |
64 feedback_slots_(-1), | |
danno
2014/01/28 08:27:17
Don't you want to use kInvalidFeedbackSlot here an
| |
63 this_has_uses_(true) { | 65 this_has_uses_(true) { |
64 Initialize(script->GetIsolate(), BASE, zone); | 66 Initialize(script->GetIsolate(), BASE, zone); |
65 } | 67 } |
66 | 68 |
67 | 69 |
68 CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info, | 70 CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info, |
69 Zone* zone) | 71 Zone* zone) |
70 : flags_(LanguageModeField::encode(CLASSIC_MODE) | IsLazy::encode(true)), | 72 : flags_(LanguageModeField::encode(CLASSIC_MODE) | IsLazy::encode(true)), |
71 shared_info_(shared_info), | 73 shared_info_(shared_info), |
72 script_(Handle<Script>(Script::cast(shared_info->script()))), | 74 script_(Handle<Script>(Script::cast(shared_info->script()))), |
73 osr_ast_id_(BailoutId::None()), | 75 osr_ast_id_(BailoutId::None()), |
74 parameter_count_(0), | 76 parameter_count_(0), |
77 feedback_slots_(-1), | |
75 this_has_uses_(true) { | 78 this_has_uses_(true) { |
76 Initialize(script_->GetIsolate(), BASE, zone); | 79 Initialize(script_->GetIsolate(), BASE, zone); |
77 } | 80 } |
78 | 81 |
79 | 82 |
80 CompilationInfo::CompilationInfo(Handle<JSFunction> closure, | 83 CompilationInfo::CompilationInfo(Handle<JSFunction> closure, |
81 Zone* zone) | 84 Zone* zone) |
82 : flags_(LanguageModeField::encode(CLASSIC_MODE) | IsLazy::encode(true)), | 85 : flags_(LanguageModeField::encode(CLASSIC_MODE) | IsLazy::encode(true)), |
83 closure_(closure), | 86 closure_(closure), |
84 shared_info_(Handle<SharedFunctionInfo>(closure->shared())), | 87 shared_info_(Handle<SharedFunctionInfo>(closure->shared())), |
85 script_(Handle<Script>(Script::cast(shared_info_->script()))), | 88 script_(Handle<Script>(Script::cast(shared_info_->script()))), |
86 context_(closure->context()), | 89 context_(closure->context()), |
87 osr_ast_id_(BailoutId::None()), | 90 osr_ast_id_(BailoutId::None()), |
88 parameter_count_(0), | 91 parameter_count_(0), |
92 feedback_slots_(-1), | |
89 this_has_uses_(true) { | 93 this_has_uses_(true) { |
90 Initialize(script_->GetIsolate(), BASE, zone); | 94 Initialize(script_->GetIsolate(), BASE, zone); |
91 } | 95 } |
92 | 96 |
93 | 97 |
94 CompilationInfo::CompilationInfo(HydrogenCodeStub* stub, | 98 CompilationInfo::CompilationInfo(HydrogenCodeStub* stub, |
95 Isolate* isolate, | 99 Isolate* isolate, |
96 Zone* zone) | 100 Zone* zone) |
97 : flags_(LanguageModeField::encode(CLASSIC_MODE) | | 101 : flags_(LanguageModeField::encode(CLASSIC_MODE) | |
98 IsLazy::encode(true)), | 102 IsLazy::encode(true)), |
99 osr_ast_id_(BailoutId::None()), | 103 osr_ast_id_(BailoutId::None()), |
100 parameter_count_(0), | 104 parameter_count_(0), |
105 feedback_slots_(0), // Hydrogen code stubs don't have feedback slots | |
101 this_has_uses_(true) { | 106 this_has_uses_(true) { |
102 Initialize(isolate, STUB, zone); | 107 Initialize(isolate, STUB, zone); |
103 code_stub_ = stub; | 108 code_stub_ = stub; |
104 } | 109 } |
105 | 110 |
106 | 111 |
107 void CompilationInfo::Initialize(Isolate* isolate, | 112 void CompilationInfo::Initialize(Isolate* isolate, |
108 Mode mode, | 113 Mode mode, |
109 Zone* zone) { | 114 Zone* zone) { |
110 isolate_ = isolate; | 115 isolate_ = isolate; |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
358 ElapsedTimer timer; | 363 ElapsedTimer timer; |
359 if (FLAG_hydrogen_stats) { | 364 if (FLAG_hydrogen_stats) { |
360 timer.Start(); | 365 timer.Start(); |
361 } | 366 } |
362 CompilationInfoWithZone unoptimized(info()->shared_info()); | 367 CompilationInfoWithZone unoptimized(info()->shared_info()); |
363 // Note that we use the same AST that we will use for generating the | 368 // Note that we use the same AST that we will use for generating the |
364 // optimized code. | 369 // optimized code. |
365 unoptimized.SetFunction(info()->function()); | 370 unoptimized.SetFunction(info()->function()); |
366 unoptimized.SetScope(info()->scope()); | 371 unoptimized.SetScope(info()->scope()); |
367 unoptimized.SetContext(info()->context()); | 372 unoptimized.SetContext(info()->context()); |
373 FeedbackSlotAllocator::Run(&unoptimized); | |
368 if (should_recompile) unoptimized.EnableDeoptimizationSupport(); | 374 if (should_recompile) unoptimized.EnableDeoptimizationSupport(); |
369 bool succeeded = FullCodeGenerator::MakeCode(&unoptimized); | 375 bool succeeded = FullCodeGenerator::MakeCode(&unoptimized); |
370 if (should_recompile) { | 376 if (should_recompile) { |
371 if (!succeeded) return SetLastStatus(FAILED); | 377 if (!succeeded) return SetLastStatus(FAILED); |
372 Handle<SharedFunctionInfo> shared = info()->shared_info(); | 378 Handle<SharedFunctionInfo> shared = info()->shared_info(); |
373 shared->EnableDeoptimizationSupport(*unoptimized.code()); | 379 shared->EnableDeoptimizationSupport(*unoptimized.code()); |
374 // The existing unoptimized code was replaced with the new one. | 380 // The existing unoptimized code was replaced with the new one. |
375 Compiler::RecordFunctionCompilation( | 381 Compiler::RecordFunctionCompilation( |
376 Logger::LAZY_COMPILE_TAG, &unoptimized, shared); | 382 Logger::LAZY_COMPILE_TAG, &unoptimized, shared); |
377 } | 383 } |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
606 function_info->set_dont_cache(lit->flags()->Contains(kDontCache)); | 612 function_info->set_dont_cache(lit->flags()->Contains(kDontCache)); |
607 function_info->set_is_generator(lit->is_generator()); | 613 function_info->set_is_generator(lit->is_generator()); |
608 } | 614 } |
609 | 615 |
610 | 616 |
611 static bool CompileUnoptimizedCode(CompilationInfo* info) { | 617 static bool CompileUnoptimizedCode(CompilationInfo* info) { |
612 ASSERT(info->function() != NULL); | 618 ASSERT(info->function() != NULL); |
613 if (!Rewriter::Rewrite(info)) return false; | 619 if (!Rewriter::Rewrite(info)) return false; |
614 if (!Scope::Analyze(info)) return false; | 620 if (!Scope::Analyze(info)) return false; |
615 ASSERT(info->scope() != NULL); | 621 ASSERT(info->scope() != NULL); |
622 if (!FeedbackSlotAllocator::Run(info)) return false; | |
623 ASSERT(info->feedback_slots() >= 0); | |
616 | 624 |
617 if (!FullCodeGenerator::MakeCode(info)) { | 625 if (!FullCodeGenerator::MakeCode(info)) { |
618 Isolate* isolate = info->isolate(); | 626 Isolate* isolate = info->isolate(); |
619 if (!isolate->has_pending_exception()) isolate->StackOverflow(); | 627 if (!isolate->has_pending_exception()) isolate->StackOverflow(); |
620 return false; | 628 return false; |
621 } | 629 } |
622 return true; | 630 return true; |
623 } | 631 } |
624 | 632 |
625 | 633 |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1000 bool allow_lazy_without_ctx = literal->AllowsLazyCompilationWithoutContext(); | 1008 bool allow_lazy_without_ctx = literal->AllowsLazyCompilationWithoutContext(); |
1001 bool allow_lazy = literal->AllowsLazyCompilation() && | 1009 bool allow_lazy = literal->AllowsLazyCompilation() && |
1002 !DebuggerWantsEagerCompilation(&info, allow_lazy_without_ctx); | 1010 !DebuggerWantsEagerCompilation(&info, allow_lazy_without_ctx); |
1003 | 1011 |
1004 // Generate code | 1012 // Generate code |
1005 Handle<ScopeInfo> scope_info; | 1013 Handle<ScopeInfo> scope_info; |
1006 if (FLAG_lazy && allow_lazy && !literal->is_parenthesized()) { | 1014 if (FLAG_lazy && allow_lazy && !literal->is_parenthesized()) { |
1007 Handle<Code> code = isolate->builtins()->CompileUnoptimized(); | 1015 Handle<Code> code = isolate->builtins()->CompileUnoptimized(); |
1008 info.SetCode(code); | 1016 info.SetCode(code); |
1009 scope_info = Handle<ScopeInfo>(ScopeInfo::Empty(isolate)); | 1017 scope_info = Handle<ScopeInfo>(ScopeInfo::Empty(isolate)); |
1010 } else if (FullCodeGenerator::MakeCode(&info)) { | 1018 } else if (FeedbackSlotAllocator::Run(&info) && |
1019 FullCodeGenerator::MakeCode(&info)) { | |
1011 ASSERT(!info.code().is_null()); | 1020 ASSERT(!info.code().is_null()); |
1012 scope_info = ScopeInfo::Create(info.scope(), info.zone()); | 1021 scope_info = ScopeInfo::Create(info.scope(), info.zone()); |
1013 } else { | 1022 } else { |
1014 return Handle<SharedFunctionInfo>::null(); | 1023 return Handle<SharedFunctionInfo>::null(); |
1015 } | 1024 } |
1016 | 1025 |
1017 // Create a shared function info object. | 1026 // Create a shared function info object. |
1018 Handle<SharedFunctionInfo> result = | 1027 Handle<SharedFunctionInfo> result = |
1019 factory->NewSharedFunctionInfo(literal->name(), | 1028 factory->NewSharedFunctionInfo(literal->name(), |
1020 literal->materialized_literal_count(), | 1029 literal->materialized_literal_count(), |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1077 | 1086 |
1078 | 1087 |
1079 static bool CompileOptimizedPrologue(CompilationInfo* info) { | 1088 static bool CompileOptimizedPrologue(CompilationInfo* info) { |
1080 if (!Parser::Parse(info)) return false; | 1089 if (!Parser::Parse(info)) return false; |
1081 LanguageMode language_mode = info->function()->language_mode(); | 1090 LanguageMode language_mode = info->function()->language_mode(); |
1082 info->SetLanguageMode(language_mode); | 1091 info->SetLanguageMode(language_mode); |
1083 | 1092 |
1084 if (!Rewriter::Rewrite(info)) return false; | 1093 if (!Rewriter::Rewrite(info)) return false; |
1085 if (!Scope::Analyze(info)) return false; | 1094 if (!Scope::Analyze(info)) return false; |
1086 ASSERT(info->scope() != NULL); | 1095 ASSERT(info->scope() != NULL); |
1096 if (!FeedbackSlotAllocator::Run(info)) return false; | |
1097 ASSERT(info->feedback_slots() >= 0); | |
1087 return true; | 1098 return true; |
1088 } | 1099 } |
1089 | 1100 |
1090 | 1101 |
1091 static bool GetOptimizedCodeNow(CompilationInfo* info) { | 1102 static bool GetOptimizedCodeNow(CompilationInfo* info) { |
1092 if (!CompileOptimizedPrologue(info)) return false; | 1103 if (!CompileOptimizedPrologue(info)) return false; |
1093 | 1104 |
1094 Logger::TimerEventScope timer( | 1105 Logger::TimerEventScope timer( |
1095 info->isolate(), Logger::TimerEventScope::v8_recompile_synchronous); | 1106 info->isolate(), Logger::TimerEventScope::v8_recompile_synchronous); |
1096 | 1107 |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1291 AllowHandleDereference allow_deref; | 1302 AllowHandleDereference allow_deref; |
1292 bool tracing_on = info()->IsStub() | 1303 bool tracing_on = info()->IsStub() |
1293 ? FLAG_trace_hydrogen_stubs | 1304 ? FLAG_trace_hydrogen_stubs |
1294 : (FLAG_trace_hydrogen && | 1305 : (FLAG_trace_hydrogen && |
1295 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter)); | 1306 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter)); |
1296 return (tracing_on && | 1307 return (tracing_on && |
1297 OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL); | 1308 OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL); |
1298 } | 1309 } |
1299 | 1310 |
1300 } } // namespace v8::internal | 1311 } } // namespace v8::internal |
OLD | NEW |