| 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" |
| 11 #include "src/code-factory.h" | 11 #include "src/code-factory.h" |
| 12 #include "src/codegen.h" | 12 #include "src/codegen.h" |
| 13 #include "src/compiler.h" | 13 #include "src/compiler.h" |
| 14 #include "src/debug/debug.h" | 14 #include "src/debug/debug.h" |
| 15 #include "src/debug/liveedit.h" | 15 #include "src/debug/liveedit.h" |
| 16 #include "src/frames-inl.h" | 16 #include "src/frames-inl.h" |
| 17 #include "src/globals.h" | 17 #include "src/globals.h" |
| 18 #include "src/isolate-inl.h" | 18 #include "src/isolate-inl.h" |
| 19 #include "src/macro-assembler.h" | 19 #include "src/macro-assembler.h" |
| 20 #include "src/snapshot/snapshot.h" | 20 #include "src/snapshot/snapshot.h" |
| 21 #include "src/tracing/trace-event.h" | 21 #include "src/tracing/trace-event.h" |
| 22 | 22 |
| 23 namespace v8 { | 23 namespace v8 { |
| 24 namespace internal { | 24 namespace internal { |
| 25 | 25 |
| 26 #define __ ACCESS_MASM(masm()) | 26 #define __ ACCESS_MASM(masm()) |
| 27 | 27 |
| 28 bool FullCodeGenerator::MakeCode(CompilationInfo* info) { | 28 class FullCodegenCompilationJob final : public CompilationJob { |
| 29 public: |
| 30 explicit FullCodegenCompilationJob(CompilationInfo* info) |
| 31 : CompilationJob(info, "Full-Codegen") {} |
| 32 |
| 33 CompilationJob::Status PrepareJobImpl() final { return SUCCEEDED; } |
| 34 |
| 35 CompilationJob::Status ExecuteJobImpl() final { return SUCCEEDED; } |
| 36 |
| 37 CompilationJob::Status FinalizeJobImpl() final { |
| 38 return FullCodeGenerator::MakeCode(info(), stack_limit()) ? SUCCEEDED |
| 39 : FAILED; |
| 40 } |
| 41 }; |
| 42 |
| 43 // static |
| 44 CompilationJob* FullCodeGenerator::NewCompilationJob(CompilationInfo* info) { |
| 45 return new FullCodegenCompilationJob(info); |
| 46 } |
| 47 |
| 48 // static |
| 49 bool FullCodeGenerator::MakeCode(CompilationInfo* info, uintptr_t stack_limit) { |
| 29 Isolate* isolate = info->isolate(); | 50 Isolate* isolate = info->isolate(); |
| 30 | 51 |
| 31 DCHECK(!FLAG_minimal); | 52 DCHECK(!FLAG_minimal); |
| 32 RuntimeCallTimerScope runtimeTimer(isolate, | 53 RuntimeCallTimerScope runtimeTimer(isolate, |
| 33 &RuntimeCallStats::CompileFullCode); | 54 &RuntimeCallStats::CompileFullCode); |
| 34 TimerEventScope<TimerEventCompileFullCode> timer(info->isolate()); | 55 TimerEventScope<TimerEventCompileFullCode> timer(info->isolate()); |
| 35 TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_SCOPED( | 56 TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_SCOPED( |
| 36 isolate, &tracing::TraceEventStatsTable::CompileFullCode); | 57 isolate, &tracing::TraceEventStatsTable::CompileFullCode); |
| 37 | 58 |
| 38 Handle<Script> script = info->script(); | 59 Handle<Script> script = info->script(); |
| 39 if (!script->IsUndefined(isolate) && | 60 if (!script->IsUndefined(isolate) && |
| 40 !script->source()->IsUndefined(isolate)) { | 61 !script->source()->IsUndefined(isolate)) { |
| 41 int len = String::cast(script->source())->length(); | 62 int len = String::cast(script->source())->length(); |
| 42 isolate->counters()->total_full_codegen_source_size()->Increment(len); | 63 isolate->counters()->total_full_codegen_source_size()->Increment(len); |
| 43 } | 64 } |
| 44 CodeGenerator::MakeCodePrologue(info, "full"); | 65 CodeGenerator::MakeCodePrologue(info, "full"); |
| 45 const int kInitialBufferSize = 4 * KB; | 66 const int kInitialBufferSize = 4 * KB; |
| 46 MacroAssembler masm(info->isolate(), NULL, kInitialBufferSize, | 67 MacroAssembler masm(info->isolate(), NULL, kInitialBufferSize, |
| 47 CodeObjectRequired::kYes); | 68 CodeObjectRequired::kYes); |
| 48 if (info->will_serialize()) masm.enable_serializer(); | 69 if (info->will_serialize()) masm.enable_serializer(); |
| 49 | 70 |
| 50 FullCodeGenerator cgen(&masm, info); | 71 FullCodeGenerator cgen(&masm, info, stack_limit); |
| 51 cgen.Generate(); | 72 cgen.Generate(); |
| 52 if (cgen.HasStackOverflow()) { | 73 if (cgen.HasStackOverflow()) { |
| 53 DCHECK(!isolate->has_pending_exception()); | 74 DCHECK(!isolate->has_pending_exception()); |
| 54 return false; | 75 return false; |
| 55 } | 76 } |
| 56 unsigned table_offset = cgen.EmitBackEdgeTable(); | 77 unsigned table_offset = cgen.EmitBackEdgeTable(); |
| 57 | 78 |
| 58 Handle<Code> code = | 79 Handle<Code> code = |
| 59 CodeGenerator::MakeCodeEpilogue(&masm, nullptr, info, masm.CodeObject()); | 80 CodeGenerator::MakeCodeEpilogue(&masm, nullptr, info, masm.CodeObject()); |
| 60 cgen.PopulateDeoptimizationData(code); | 81 cgen.PopulateDeoptimizationData(code); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 !FastCloneShallowObjectStub::IsSupported(expr); | 171 !FastCloneShallowObjectStub::IsSupported(expr); |
| 151 } | 172 } |
| 152 | 173 |
| 153 | 174 |
| 154 bool FullCodeGenerator::MustCreateArrayLiteralWithRuntime( | 175 bool FullCodeGenerator::MustCreateArrayLiteralWithRuntime( |
| 155 ArrayLiteral* expr) const { | 176 ArrayLiteral* expr) const { |
| 156 return expr->depth() > 1 || | 177 return expr->depth() > 1 || |
| 157 expr->values()->length() > JSArray::kInitialMaxFastElementArray; | 178 expr->values()->length() > JSArray::kInitialMaxFastElementArray; |
| 158 } | 179 } |
| 159 | 180 |
| 160 | 181 void FullCodeGenerator::Initialize(uintptr_t stack_limit) { |
| 161 void FullCodeGenerator::Initialize() { | 182 InitializeAstVisitor(stack_limit); |
| 162 InitializeAstVisitor(info_->isolate()); | |
| 163 masm_->set_emit_debug_code(FLAG_debug_code); | 183 masm_->set_emit_debug_code(FLAG_debug_code); |
| 164 masm_->set_predictable_code_size(true); | 184 masm_->set_predictable_code_size(true); |
| 165 } | 185 } |
| 166 | 186 |
| 167 void FullCodeGenerator::PrepareForBailout(Expression* node, | 187 void FullCodeGenerator::PrepareForBailout(Expression* node, |
| 168 BailoutState state) { | 188 BailoutState state) { |
| 169 PrepareForBailoutForId(node->id(), state); | 189 PrepareForBailoutForId(node->id(), state); |
| 170 } | 190 } |
| 171 | 191 |
| 172 void FullCodeGenerator::CallLoadIC(TypeFeedbackId id) { | 192 void FullCodeGenerator::CallLoadIC(TypeFeedbackId id) { |
| (...skipping 1765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1938 return var->scope()->is_nonlinear() || | 1958 return var->scope()->is_nonlinear() || |
| 1939 var->initializer_position() >= proxy->position(); | 1959 var->initializer_position() >= proxy->position(); |
| 1940 } | 1960 } |
| 1941 | 1961 |
| 1942 | 1962 |
| 1943 #undef __ | 1963 #undef __ |
| 1944 | 1964 |
| 1945 | 1965 |
| 1946 } // namespace internal | 1966 } // namespace internal |
| 1947 } // namespace v8 | 1967 } // namespace v8 |
| OLD | NEW |