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/compiler.h" | 5 #include "src/compiler.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "src/ast/ast-numbering.h" | 9 #include "src/ast/ast-numbering.h" |
10 #include "src/ast/prettyprinter.h" | 10 #include "src/ast/prettyprinter.h" |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 | 190 |
191 | 191 |
192 // Primitive functions are unlikely to be picked up by the stack-walking | 192 // Primitive functions are unlikely to be picked up by the stack-walking |
193 // profiler, so they trigger their own optimization when they're called | 193 // profiler, so they trigger their own optimization when they're called |
194 // for the SharedFunctionInfo::kCallsUntilPrimitiveOptimization-th time. | 194 // for the SharedFunctionInfo::kCallsUntilPrimitiveOptimization-th time. |
195 bool CompilationInfo::ShouldSelfOptimize() { | 195 bool CompilationInfo::ShouldSelfOptimize() { |
196 return FLAG_crankshaft && | 196 return FLAG_crankshaft && |
197 !(literal()->flags() & AstProperties::kDontSelfOptimize) && | 197 !(literal()->flags() & AstProperties::kDontSelfOptimize) && |
198 !literal()->dont_optimize() && | 198 !literal()->dont_optimize() && |
199 literal()->scope()->AllowsLazyCompilation() && | 199 literal()->scope()->AllowsLazyCompilation() && |
200 (!has_shared_info() || !shared_info()->optimization_disabled()); | 200 !shared_info()->optimization_disabled(); |
201 } | 201 } |
202 | 202 |
203 | 203 |
204 bool CompilationInfo::has_simple_parameters() { | 204 bool CompilationInfo::has_simple_parameters() { |
205 return scope()->has_simple_parameters(); | 205 return scope()->has_simple_parameters(); |
206 } | 206 } |
207 | 207 |
208 | 208 |
209 int CompilationInfo::TraceInlinedFunction(Handle<SharedFunctionInfo> shared, | 209 int CompilationInfo::TraceInlinedFunction(Handle<SharedFunctionInfo> shared, |
210 SourcePosition position, | 210 SourcePosition position, |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 ? String::cast(script->name()) | 470 ? String::cast(script->name()) |
471 : info->isolate()->heap()->empty_string(); | 471 : info->isolate()->heap()->empty_string(); |
472 Logger::LogEventsAndTags log_tag = Logger::ToNativeByScript(tag, *script); | 472 Logger::LogEventsAndTags log_tag = Logger::ToNativeByScript(tag, *script); |
473 PROFILE(info->isolate(), | 473 PROFILE(info->isolate(), |
474 CodeCreateEvent(log_tag, *abstract_code, *shared, info, script_name, | 474 CodeCreateEvent(log_tag, *abstract_code, *shared, info, script_name, |
475 line_num, column_num)); | 475 line_num, column_num)); |
476 } | 476 } |
477 } | 477 } |
478 | 478 |
479 void EnsureFeedbackVector(CompilationInfo* info) { | 479 void EnsureFeedbackVector(CompilationInfo* info) { |
480 if (!info->has_shared_info()) return; | 480 DCHECK(info->has_shared_info()); |
481 | 481 |
482 // If no type feedback vector exists, we create one now. At this point the | 482 // If no type feedback vector exists, we create one now. At this point the |
483 // AstNumbering pass has already run. Note the snapshot can contain outdated | 483 // AstNumbering pass has already run. Note the snapshot can contain outdated |
484 // vectors for a different configuration, hence we also recreate a new vector | 484 // vectors for a different configuration, hence we also recreate a new vector |
485 // when the function is not compiled (i.e. no code was serialized). | 485 // when the function is not compiled (i.e. no code was serialized). |
486 if (info->shared_info()->feedback_vector()->is_empty() || | 486 if (info->shared_info()->feedback_vector()->is_empty() || |
487 !info->shared_info()->is_compiled()) { | 487 !info->shared_info()->is_compiled()) { |
488 Handle<TypeFeedbackMetadata> feedback_metadata = TypeFeedbackMetadata::New( | 488 Handle<TypeFeedbackMetadata> feedback_metadata = TypeFeedbackMetadata::New( |
489 info->isolate(), info->literal()->feedback_vector_spec()); | 489 info->isolate(), info->literal()->feedback_vector_spec()); |
490 Handle<TypeFeedbackVector> feedback_vector = | 490 Handle<TypeFeedbackVector> feedback_vector = |
491 TypeFeedbackVector::New(info->isolate(), feedback_metadata); | 491 TypeFeedbackVector::New(info->isolate(), feedback_metadata); |
492 info->shared_info()->set_feedback_vector(*feedback_vector); | 492 info->shared_info()->set_feedback_vector(*feedback_vector); |
493 } | 493 } |
494 | 494 |
495 // It's very important that recompiles do not alter the structure of the type | 495 // It's very important that recompiles do not alter the structure of the type |
496 // feedback vector. Verify that the structure fits the function literal. | 496 // feedback vector. Verify that the structure fits the function literal. |
497 CHECK(!info->shared_info()->feedback_vector()->metadata()->SpecDiffersFrom( | 497 CHECK(!info->shared_info()->feedback_vector()->metadata()->SpecDiffersFrom( |
498 info->literal()->feedback_vector_spec())); | 498 info->literal()->feedback_vector_spec())); |
499 } | 499 } |
500 | 500 |
501 bool UseIgnition(CompilationInfo* info) { | 501 bool UseIgnition(CompilationInfo* info) { |
502 // We only get here without a shared function info is when compiling a script | |
503 // for live edit. We cannot (yet) use Ignition to compile for live edit. | |
504 if (!info->has_shared_info()) { | |
505 DCHECK(info->isolate()->debug()->live_edit_enabled()); | |
506 return false; | |
507 } | |
508 | |
509 if (info->shared_info()->is_generator() && !FLAG_ignition_generators) { | 502 if (info->shared_info()->is_generator() && !FLAG_ignition_generators) { |
510 return false; | 503 return false; |
511 } | 504 } |
512 | 505 |
513 // Checks whether top level functions should be passed by the filter. | 506 // Checks whether top level functions should be passed by the filter. |
514 if (info->shared_info()->is_toplevel()) { | 507 if (info->shared_info()->is_toplevel()) { |
515 Vector<const char> filter = CStrVector(FLAG_ignition_filter); | 508 Vector<const char> filter = CStrVector(FLAG_ignition_filter); |
516 return (filter.length() == 0) || (filter.length() == 1 && filter[0] == '*'); | 509 return (filter.length() == 0) || (filter.length() == 1 && filter[0] == '*'); |
517 } | 510 } |
518 | 511 |
(...skipping 945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1464 } | 1457 } |
1465 | 1458 |
1466 | 1459 |
1467 Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfo( | 1460 Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfo( |
1468 FunctionLiteral* literal, Handle<Script> script, | 1461 FunctionLiteral* literal, Handle<Script> script, |
1469 CompilationInfo* outer_info) { | 1462 CompilationInfo* outer_info) { |
1470 // Precondition: code has been parsed and scopes have been analyzed. | 1463 // Precondition: code has been parsed and scopes have been analyzed. |
1471 Isolate* isolate = outer_info->isolate(); | 1464 Isolate* isolate = outer_info->isolate(); |
1472 MaybeHandle<SharedFunctionInfo> maybe_existing; | 1465 MaybeHandle<SharedFunctionInfo> maybe_existing; |
1473 | 1466 |
1474 // The only reason we ever get here without having a shared function info for | |
1475 // the outer function, is when we are compiling for live edit. That is also | |
1476 // the case in which we want to re-generate all inner shared function info | |
1477 // objects by just assuming the top-most one has not been compiled yet. | |
1478 DCHECK_IMPLIES(!outer_info->has_shared_info(), | |
1479 isolate->debug()->live_edit_enabled()); | |
1480 bool outer_function_was_never_compiled = | |
1481 !outer_info->has_shared_info() || | |
1482 outer_info->shared_info()->never_compiled(); | |
1483 | |
1484 // Find any previously allocated shared function info for the given literal. | 1467 // Find any previously allocated shared function info for the given literal. |
1485 if (outer_function_was_never_compiled) { | 1468 if (outer_info->shared_info()->never_compiled()) { |
1486 // On the first compile, there are no existing shared function info for | 1469 // On the first compile, there are no existing shared function info for |
1487 // inner functions yet, so do not try to find them. All bets are off for | 1470 // inner functions yet, so do not try to find them. All bets are off for |
1488 // live edit though. | 1471 // live edit though. |
1489 SLOW_DCHECK(script->FindSharedFunctionInfo(literal).is_null() || | 1472 SLOW_DCHECK(script->FindSharedFunctionInfo(literal).is_null() || |
1490 isolate->debug()->live_edit_enabled()); | 1473 isolate->debug()->live_edit_enabled()); |
1491 } else { | 1474 } else { |
1492 maybe_existing = script->FindSharedFunctionInfo(literal); | 1475 maybe_existing = script->FindSharedFunctionInfo(literal); |
1493 } | 1476 } |
1494 | 1477 |
1495 // We found an existing shared function info. If it's already compiled, | 1478 // We found an existing shared function info. If it's already compiled, |
(...skipping 10 matching lines...) Expand all Loading... |
1506 | 1489 |
1507 // Allocate a shared function info object. | 1490 // Allocate a shared function info object. |
1508 Handle<SharedFunctionInfo> result; | 1491 Handle<SharedFunctionInfo> result; |
1509 if (!maybe_existing.ToHandle(&result)) { | 1492 if (!maybe_existing.ToHandle(&result)) { |
1510 result = NewSharedFunctionInfoForLiteral(isolate, literal, script); | 1493 result = NewSharedFunctionInfoForLiteral(isolate, literal, script); |
1511 result->set_is_toplevel(false); | 1494 result->set_is_toplevel(false); |
1512 | 1495 |
1513 // If the outer function has been compiled before, we cannot be sure that | 1496 // If the outer function has been compiled before, we cannot be sure that |
1514 // shared function info for this function literal has been created for the | 1497 // shared function info for this function literal has been created for the |
1515 // first time. It may have already been compiled previously. | 1498 // first time. It may have already been compiled previously. |
1516 result->set_never_compiled(outer_function_was_never_compiled); | 1499 result->set_never_compiled(outer_info->shared_info()->never_compiled()); |
1517 } | 1500 } |
1518 | 1501 |
1519 Zone zone(isolate->allocator()); | 1502 Zone zone(isolate->allocator()); |
1520 ParseInfo parse_info(&zone, script); | 1503 ParseInfo parse_info(&zone, script); |
1521 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); | 1504 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); |
1522 parse_info.set_literal(literal); | 1505 parse_info.set_literal(literal); |
1523 parse_info.set_shared_info(result); | 1506 parse_info.set_shared_info(result); |
1524 parse_info.set_scope(literal->scope()); | 1507 parse_info.set_scope(literal->scope()); |
1525 parse_info.set_language_mode(literal->scope()->language_mode()); | 1508 parse_info.set_language_mode(literal->scope()->language_mode()); |
1526 if (outer_info->will_serialize()) info.PrepareForSerializing(); | 1509 if (outer_info->will_serialize()) info.PrepareForSerializing(); |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1703 MaybeHandle<Code> code; | 1686 MaybeHandle<Code> code; |
1704 if (cached.code != nullptr) code = handle(cached.code); | 1687 if (cached.code != nullptr) code = handle(cached.code); |
1705 Handle<Context> native_context(function->context()->native_context()); | 1688 Handle<Context> native_context(function->context()->native_context()); |
1706 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, | 1689 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, |
1707 literals, BailoutId::None()); | 1690 literals, BailoutId::None()); |
1708 } | 1691 } |
1709 } | 1692 } |
1710 | 1693 |
1711 } // namespace internal | 1694 } // namespace internal |
1712 } // namespace v8 | 1695 } // namespace v8 |
OLD | NEW |