Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(365)

Side by Side Diff: src/compiler.cc

Issue 360011: Obey the flag --lazy in the toplevel code generator.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/compiler.h ('k') | src/fast-codegen.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 the V8 project authors. All rights reserved. 1 // Copyright 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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 } 251 }
252 #endif 252 #endif
253 253
254 // Allocate function. 254 // Allocate function.
255 Handle<JSFunction> fun = 255 Handle<JSFunction> fun =
256 Factory::NewFunctionBoilerplate(lit->name(), 256 Factory::NewFunctionBoilerplate(lit->name(),
257 lit->materialized_literal_count(), 257 lit->materialized_literal_count(),
258 code); 258 code);
259 259
260 ASSERT_EQ(RelocInfo::kNoPosition, lit->function_token_position()); 260 ASSERT_EQ(RelocInfo::kNoPosition, lit->function_token_position());
261 CodeGenerator::SetFunctionInfo(fun, lit, true, script); 261 Compiler::SetFunctionInfo(fun, lit, true, script);
262 262
263 // Hint to the runtime system used when allocating space for initial 263 // Hint to the runtime system used when allocating space for initial
264 // property space by setting the expected number of properties for 264 // property space by setting the expected number of properties for
265 // the instances of the function. 265 // the instances of the function.
266 SetExpectedNofPropertiesFromEstimate(fun, lit->expected_property_count()); 266 SetExpectedNofPropertiesFromEstimate(fun, lit->expected_property_count());
267 267
268 #ifdef ENABLE_DEBUGGER_SUPPORT 268 #ifdef ENABLE_DEBUGGER_SUPPORT
269 // Notify debugger 269 // Notify debugger
270 Debugger::OnAfterCompile(script, fun); 270 Debugger::OnAfterCompile(script, fun);
271 #endif 271 #endif
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 lit->has_only_this_property_assignments(), 468 lit->has_only_this_property_assignments(),
469 lit->has_only_simple_this_property_assignments(), 469 lit->has_only_simple_this_property_assignments(),
470 *lit->this_property_assignments()); 470 *lit->this_property_assignments());
471 471
472 // Check the function has compiled code. 472 // Check the function has compiled code.
473 ASSERT(shared->is_compiled()); 473 ASSERT(shared->is_compiled());
474 return true; 474 return true;
475 } 475 }
476 476
477 477
478 Handle<JSFunction> Compiler::BuildBoilerplate(FunctionLiteral* literal,
479 Handle<Script> script,
480 AstVisitor* caller) {
481 #ifdef DEBUG
482 // We should not try to compile the same function literal more than
483 // once.
484 literal->mark_as_compiled();
485 #endif
486
487 // Determine if the function can be lazily compiled. This is
488 // necessary to allow some of our builtin JS files to be lazily
489 // compiled. These builtins cannot be handled lazily by the parser,
490 // since we have to know if a function uses the special natives
491 // syntax, which is something the parser records.
492 bool allow_lazy = literal->AllowsLazyCompilation();
493
494 // Generate code
495 Handle<Code> code;
496 if (FLAG_lazy && allow_lazy) {
497 code = ComputeLazyCompile(literal->num_parameters());
498 } else {
499 // The bodies of function literals have not yet been visited by
500 // the AST optimizer/analyzer.
501 if (!Rewriter::Optimize(literal)) {
502 return Handle<JSFunction>::null();
503 }
504
505 // Generate code and return it.
506 if (FLAG_fast_compiler && literal->try_fast_codegen()) {
507 CodeGenSelector selector;
508 CodeGenSelector::CodeGenTag code_gen = selector.Select(literal);
509 if (code_gen == CodeGenSelector::FAST) {
510 code = FastCodeGenerator::MakeCode(literal,
511 script,
512 false); // Not eval.
513 }
514 ASSERT(code_gen == CodeGenSelector::NORMAL);
515 } else {
516 code = CodeGenerator::MakeCode(literal,
517 script,
518 false); // Not eval.
519 }
520
521 // Check for stack-overflow exception.
522 if (code.is_null()) {
523 caller->SetStackOverflow();
524 return Handle<JSFunction>::null();
525 }
526
527 // Function compilation complete.
528 LOG(CodeCreateEvent(Logger::FUNCTION_TAG, *code, *literal->name()));
529
530 #ifdef ENABLE_OPROFILE_AGENT
531 OProfileAgent::CreateNativeCodeRegion(*node->name(),
532 code->instruction_start(),
533 code->instruction_size());
534 #endif
535 }
536
537 // Create a boilerplate function.
538 Handle<JSFunction> function =
539 Factory::NewFunctionBoilerplate(literal->name(),
540 literal->materialized_literal_count(),
541 code);
542 SetFunctionInfo(function, literal, false, script);
543
544 #ifdef ENABLE_DEBUGGER_SUPPORT
545 // Notify debugger that a new function has been added.
546 Debugger::OnNewFunction(function);
547 #endif
548
549 // Set the expected number of properties for instances and return
550 // the resulting function.
551 SetExpectedNofPropertiesFromEstimate(function,
552 literal->expected_property_count());
553 return function;
554 }
555
556
557 // Sets the function info on a function.
558 // The start_position points to the first '(' character after the function name
559 // in the full script source. When counting characters in the script source the
560 // the first character is number 0 (not 1).
561 void Compiler::SetFunctionInfo(Handle<JSFunction> fun,
562 FunctionLiteral* lit,
563 bool is_toplevel,
564 Handle<Script> script) {
565 fun->shared()->set_length(lit->num_parameters());
566 fun->shared()->set_formal_parameter_count(lit->num_parameters());
567 fun->shared()->set_script(*script);
568 fun->shared()->set_function_token_position(lit->function_token_position());
569 fun->shared()->set_start_position(lit->start_position());
570 fun->shared()->set_end_position(lit->end_position());
571 fun->shared()->set_is_expression(lit->is_expression());
572 fun->shared()->set_is_toplevel(is_toplevel);
573 fun->shared()->set_inferred_name(*lit->inferred_name());
574 fun->shared()->SetThisPropertyAssignmentsInfo(
575 lit->has_only_this_property_assignments(),
576 lit->has_only_simple_this_property_assignments(),
577 *lit->this_property_assignments());
578 fun->shared()->set_try_fast_codegen(lit->try_fast_codegen());
579 }
580
581
478 CodeGenSelector::CodeGenTag CodeGenSelector::Select(FunctionLiteral* fun) { 582 CodeGenSelector::CodeGenTag CodeGenSelector::Select(FunctionLiteral* fun) {
479 Scope* scope = fun->scope(); 583 Scope* scope = fun->scope();
480 if (scope->num_heap_slots() != 0) { 584 if (scope->num_heap_slots() != 0) {
481 if (FLAG_trace_bailout) PrintF("function has context slots\n"); 585 if (FLAG_trace_bailout) PrintF("function has context slots\n");
482 return NORMAL; 586 return NORMAL;
483 } 587 }
484 if (scope->arguments() != NULL) { 588 if (scope->arguments() != NULL) {
485 if (FLAG_trace_bailout) PrintF("function uses 'arguments'\n"); 589 if (FLAG_trace_bailout) PrintF("function uses 'arguments'\n");
486 return NORMAL; 590 return NORMAL;
487 } 591 }
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
977 1081
978 void CodeGenSelector::VisitThisFunction(ThisFunction* expr) { 1082 void CodeGenSelector::VisitThisFunction(ThisFunction* expr) {
979 BAILOUT("ThisFunction"); 1083 BAILOUT("ThisFunction");
980 } 1084 }
981 1085
982 #undef BAILOUT 1086 #undef BAILOUT
983 #undef CHECK_BAILOUT 1087 #undef CHECK_BAILOUT
984 1088
985 1089
986 } } // namespace v8::internal 1090 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/compiler.h ('k') | src/fast-codegen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698