| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/full-codegen/full-codegen.h" | 5 #include "src/full-codegen/full-codegen.h" |
| 6 | 6 |
| 7 #include "src/ast/ast-numbering.h" | 7 #include "src/ast/ast-numbering.h" |
| 8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
| 9 #include "src/ast/prettyprinter.h" | 9 #include "src/ast/prettyprinter.h" |
| 10 #include "src/ast/scopes.h" | 10 #include "src/ast/scopes.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "src/snapshot/snapshot.h" | 21 #include "src/snapshot/snapshot.h" |
| 22 #include "src/tracing/trace-event.h" | 22 #include "src/tracing/trace-event.h" |
| 23 | 23 |
| 24 namespace v8 { | 24 namespace v8 { |
| 25 namespace internal { | 25 namespace internal { |
| 26 | 26 |
| 27 #define __ ACCESS_MASM(masm()) | 27 #define __ ACCESS_MASM(masm()) |
| 28 | 28 |
| 29 class FullCodegenCompilationJob final : public CompilationJob { | 29 class FullCodegenCompilationJob final : public CompilationJob { |
| 30 public: | 30 public: |
| 31 FullCodegenCompilationJob(CompilationInfo* info, LazyCompilationMode mode) | 31 explicit FullCodegenCompilationJob(CompilationInfo* info) |
| 32 : CompilationJob(info->isolate(), info, "Full-Codegen"), mode_(mode) {} | 32 : CompilationJob(info->isolate(), info, "Full-Codegen") {} |
| 33 | 33 |
| 34 bool can_execute_on_background_thread() const override { return false; } | 34 bool can_execute_on_background_thread() const override { return false; } |
| 35 | 35 |
| 36 CompilationJob::Status PrepareJobImpl() final { return SUCCEEDED; } | 36 CompilationJob::Status PrepareJobImpl() final { return SUCCEEDED; } |
| 37 | 37 |
| 38 CompilationJob::Status ExecuteJobImpl() final { | 38 CompilationJob::Status ExecuteJobImpl() final { |
| 39 DCHECK(ThreadId::Current().Equals(isolate()->thread_id())); | 39 DCHECK(ThreadId::Current().Equals(isolate()->thread_id())); |
| 40 return FullCodeGenerator::MakeCode(info(), stack_limit(), mode_) ? SUCCEEDED | 40 return FullCodeGenerator::MakeCode(info(), stack_limit()) ? SUCCEEDED |
| 41 : FAILED; | 41 : FAILED; |
| 42 } | 42 } |
| 43 | 43 |
| 44 CompilationJob::Status FinalizeJobImpl() final { return SUCCEEDED; } | 44 CompilationJob::Status FinalizeJobImpl() final { return SUCCEEDED; } |
| 45 | 45 |
| 46 private: | 46 private: |
| 47 LazyCompilationMode mode_; | |
| 48 | |
| 49 DISALLOW_COPY_AND_ASSIGN(FullCodegenCompilationJob); | 47 DISALLOW_COPY_AND_ASSIGN(FullCodegenCompilationJob); |
| 50 }; | 48 }; |
| 51 | 49 |
| 52 FullCodeGenerator::FullCodeGenerator(MacroAssembler* masm, | 50 FullCodeGenerator::FullCodeGenerator(MacroAssembler* masm, |
| 53 CompilationInfo* info, | 51 CompilationInfo* info, |
| 54 uintptr_t stack_limit, | 52 uintptr_t stack_limit) |
| 55 LazyCompilationMode mode) | |
| 56 : masm_(masm), | 53 : masm_(masm), |
| 57 info_(info), | 54 info_(info), |
| 58 isolate_(info->isolate()), | 55 isolate_(info->isolate()), |
| 59 compilation_mode_(mode), | |
| 60 zone_(info->zone()), | 56 zone_(info->zone()), |
| 61 scope_(info->scope()), | 57 scope_(info->scope()), |
| 62 nesting_stack_(NULL), | 58 nesting_stack_(NULL), |
| 63 loop_depth_(0), | 59 loop_depth_(0), |
| 64 operand_stack_depth_(0), | 60 operand_stack_depth_(0), |
| 65 globals_(NULL), | 61 globals_(NULL), |
| 66 context_(NULL), | 62 context_(NULL), |
| 67 bailout_entries_(info->HasDeoptimizationSupport() | 63 bailout_entries_(info->HasDeoptimizationSupport() |
| 68 ? info->literal()->ast_node_count() | 64 ? info->literal()->ast_node_count() |
| 69 : 0, | 65 : 0, |
| 70 info->zone()), | 66 info->zone()), |
| 71 back_edges_(2, info->zone()), | 67 back_edges_(2, info->zone()), |
| 72 source_position_table_builder_(info->zone(), | 68 source_position_table_builder_(info->zone(), |
| 73 info->SourcePositionRecordingMode()), | 69 info->SourcePositionRecordingMode()), |
| 74 ic_total_count_(0) { | 70 ic_total_count_(0) { |
| 75 DCHECK(!info->IsStub()); | 71 DCHECK(!info->IsStub()); |
| 76 Initialize(stack_limit); | 72 Initialize(stack_limit); |
| 77 } | 73 } |
| 78 | 74 |
| 79 // static | 75 // static |
| 80 CompilationJob* FullCodeGenerator::NewCompilationJob(CompilationInfo* info, | 76 CompilationJob* FullCodeGenerator::NewCompilationJob(CompilationInfo* info) { |
| 81 LazyCompilationMode mode) { | 77 return new FullCodegenCompilationJob(info); |
| 82 return new FullCodegenCompilationJob(info, mode); | |
| 83 } | 78 } |
| 84 | 79 |
| 85 // static | 80 // static |
| 86 bool FullCodeGenerator::MakeCode(CompilationInfo* info) { | 81 bool FullCodeGenerator::MakeCode(CompilationInfo* info) { |
| 87 return MakeCode(info, info->isolate()->stack_guard()->real_climit(), | 82 return MakeCode(info, info->isolate()->stack_guard()->real_climit()); |
| 88 LazyCompilationMode::kIfRequested); | |
| 89 } | 83 } |
| 90 | 84 |
| 91 // static | 85 // static |
| 92 bool FullCodeGenerator::MakeCode(CompilationInfo* info, uintptr_t stack_limit, | 86 bool FullCodeGenerator::MakeCode(CompilationInfo* info, uintptr_t stack_limit) { |
| 93 LazyCompilationMode mode) { | |
| 94 Isolate* isolate = info->isolate(); | 87 Isolate* isolate = info->isolate(); |
| 95 | 88 |
| 96 DCHECK(!info->shared_info()->must_use_ignition_turbo()); | 89 DCHECK(!info->shared_info()->must_use_ignition_turbo()); |
| 97 DCHECK(!FLAG_minimal); | 90 DCHECK(!FLAG_minimal); |
| 98 RuntimeCallTimerScope runtimeTimer(isolate, | 91 RuntimeCallTimerScope runtimeTimer(isolate, |
| 99 &RuntimeCallStats::CompileFullCode); | 92 &RuntimeCallStats::CompileFullCode); |
| 100 TimerEventScope<TimerEventCompileFullCode> timer(info->isolate()); | 93 TimerEventScope<TimerEventCompileFullCode> timer(info->isolate()); |
| 101 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.CompileFullCode"); | 94 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.CompileFullCode"); |
| 102 | 95 |
| 103 Handle<Script> script = info->script(); | 96 Handle<Script> script = info->script(); |
| 104 if (!script->IsUndefined(isolate) && | 97 if (!script->IsUndefined(isolate) && |
| 105 !script->source()->IsUndefined(isolate)) { | 98 !script->source()->IsUndefined(isolate)) { |
| 106 int len = String::cast(script->source())->length(); | 99 int len = String::cast(script->source())->length(); |
| 107 isolate->counters()->total_full_codegen_source_size()->Increment(len); | 100 isolate->counters()->total_full_codegen_source_size()->Increment(len); |
| 108 } | 101 } |
| 109 CodeGenerator::MakeCodePrologue(info, "full"); | 102 CodeGenerator::MakeCodePrologue(info, "full"); |
| 110 const int kInitialBufferSize = 4 * KB; | 103 const int kInitialBufferSize = 4 * KB; |
| 111 MacroAssembler masm(info->isolate(), NULL, kInitialBufferSize, | 104 MacroAssembler masm(info->isolate(), NULL, kInitialBufferSize, |
| 112 CodeObjectRequired::kYes); | 105 CodeObjectRequired::kYes); |
| 113 if (info->will_serialize()) masm.enable_serializer(); | 106 if (info->will_serialize()) masm.enable_serializer(); |
| 114 | 107 |
| 115 FullCodeGenerator cgen(&masm, info, stack_limit, mode); | 108 FullCodeGenerator cgen(&masm, info, stack_limit); |
| 116 cgen.Generate(); | 109 cgen.Generate(); |
| 117 if (cgen.HasStackOverflow()) { | 110 if (cgen.HasStackOverflow()) { |
| 118 DCHECK(!isolate->has_pending_exception()); | 111 DCHECK(!isolate->has_pending_exception()); |
| 119 return false; | 112 return false; |
| 120 } | 113 } |
| 121 unsigned table_offset = cgen.EmitBackEdgeTable(); | 114 unsigned table_offset = cgen.EmitBackEdgeTable(); |
| 122 | 115 |
| 123 Handle<Code> code = | 116 Handle<Code> code = |
| 124 CodeGenerator::MakeCodeEpilogue(&masm, nullptr, info, masm.CodeObject()); | 117 CodeGenerator::MakeCodeEpilogue(&masm, nullptr, info, masm.CodeObject()); |
| 125 cgen.PopulateDeoptimizationData(code); | 118 cgen.PopulateDeoptimizationData(code); |
| (...skipping 1160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1286 Comment cmnt(masm_, "[ Literal"); | 1279 Comment cmnt(masm_, "[ Literal"); |
| 1287 context()->Plug(expr->value()); | 1280 context()->Plug(expr->value()); |
| 1288 } | 1281 } |
| 1289 | 1282 |
| 1290 | 1283 |
| 1291 void FullCodeGenerator::VisitFunctionLiteral(FunctionLiteral* expr) { | 1284 void FullCodeGenerator::VisitFunctionLiteral(FunctionLiteral* expr) { |
| 1292 Comment cmnt(masm_, "[ FunctionLiteral"); | 1285 Comment cmnt(masm_, "[ FunctionLiteral"); |
| 1293 | 1286 |
| 1294 // Build the function boilerplate and instantiate it. | 1287 // Build the function boilerplate and instantiate it. |
| 1295 Handle<SharedFunctionInfo> function_info = | 1288 Handle<SharedFunctionInfo> function_info = |
| 1296 Compiler::GetSharedFunctionInfo(expr, script(), info_, compilation_mode_); | 1289 Compiler::GetSharedFunctionInfo(expr, script(), info_); |
| 1297 if (function_info.is_null()) { | 1290 if (function_info.is_null()) { |
| 1298 SetStackOverflow(); | 1291 SetStackOverflow(); |
| 1299 return; | 1292 return; |
| 1300 } | 1293 } |
| 1301 EmitNewClosure(function_info, expr->LiteralFeedbackSlot(), expr->pretenure()); | 1294 EmitNewClosure(function_info, expr->LiteralFeedbackSlot(), expr->pretenure()); |
| 1302 } | 1295 } |
| 1303 | 1296 |
| 1304 | 1297 |
| 1305 void FullCodeGenerator::VisitClassLiteral(ClassLiteral* lit) { | 1298 void FullCodeGenerator::VisitClassLiteral(ClassLiteral* lit) { |
| 1306 // Unsupported | 1299 // Unsupported |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1610 return info_->has_simple_parameters(); | 1603 return info_->has_simple_parameters(); |
| 1611 } | 1604 } |
| 1612 | 1605 |
| 1613 FunctionLiteral* FullCodeGenerator::literal() const { return info_->literal(); } | 1606 FunctionLiteral* FullCodeGenerator::literal() const { return info_->literal(); } |
| 1614 | 1607 |
| 1615 #undef __ | 1608 #undef __ |
| 1616 | 1609 |
| 1617 | 1610 |
| 1618 } // namespace internal | 1611 } // namespace internal |
| 1619 } // namespace v8 | 1612 } // namespace v8 |
| OLD | NEW |