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

Side by Side Diff: src/compiler.cc

Issue 551189: Propagate receiver from initial call site to code generator. (Closed)
Patch Set: Created 10 years, 10 months 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
« src/compiler.h ('K') | « src/compiler.h ('k') | src/debug.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 29 matching lines...) Expand all
40 #include "usage-analyzer.h" 40 #include "usage-analyzer.h"
41 41
42 namespace v8 { 42 namespace v8 {
43 namespace internal { 43 namespace internal {
44 44
45 45
46 static Handle<Code> MakeCode(FunctionLiteral* literal, 46 static Handle<Code> MakeCode(FunctionLiteral* literal,
47 Handle<Script> script, 47 Handle<Script> script,
48 Handle<Context> context, 48 Handle<Context> context,
49 bool is_eval, 49 bool is_eval,
50 Handle<SharedFunctionInfo> shared) { 50 Handle<SharedFunctionInfo> shared,
51 Handle<Object> receiver) {
51 ASSERT(literal != NULL); 52 ASSERT(literal != NULL);
52 53
53 // Rewrite the AST by introducing .result assignments where needed. 54 // Rewrite the AST by introducing .result assignments where needed.
54 if (!Rewriter::Process(literal) || !AnalyzeVariableUsage(literal)) { 55 if (!Rewriter::Process(literal) || !AnalyzeVariableUsage(literal)) {
55 // Signal a stack overflow by returning a null handle. The stack 56 // Signal a stack overflow by returning a null handle. The stack
56 // overflow exception will be thrown by the caller. 57 // overflow exception will be thrown by the caller.
57 return Handle<Code>::null(); 58 return Handle<Code>::null();
58 } 59 }
59 60
60 { 61 {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 : (shared->is_toplevel() || shared->try_full_codegen()); 102 : (shared->is_toplevel() || shared->try_full_codegen());
102 103
103 if (FLAG_always_full_compiler || (FLAG_full_compiler && is_run_once)) { 104 if (FLAG_always_full_compiler || (FLAG_full_compiler && is_run_once)) {
104 FullCodeGenSyntaxChecker checker; 105 FullCodeGenSyntaxChecker checker;
105 checker.Check(literal); 106 checker.Check(literal);
106 if (checker.has_supported_syntax()) { 107 if (checker.has_supported_syntax()) {
107 return FullCodeGenerator::MakeCode(literal, script, is_eval); 108 return FullCodeGenerator::MakeCode(literal, script, is_eval);
108 } 109 }
109 } else if (FLAG_always_fast_compiler || 110 } else if (FLAG_always_fast_compiler ||
110 (FLAG_fast_compiler && !is_run_once)) { 111 (FLAG_fast_compiler && !is_run_once)) {
111 FastCodeGenSyntaxChecker checker; 112 FastCodeGenSyntaxChecker checker(receiver);
112 checker.Check(literal); 113 checker.Check(literal);
113 // Does not yet generate code. 114 // Does not yet generate code.
114 } 115 }
115 116
116 return CodeGenerator::MakeCode(literal, script, is_eval); 117 return CodeGenerator::MakeCode(literal, script, is_eval);
117 } 118 }
118 119
119 120
120 static bool IsValidJSON(FunctionLiteral* lit) { 121 static bool IsValidJSON(FunctionLiteral* lit) {
121 if (lit->body()->length() != 1) 122 if (lit->body()->length() != 1)
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 192
192 // Measure how long it takes to do the compilation; only take the 193 // Measure how long it takes to do the compilation; only take the
193 // rest of the function into account to avoid overlap with the 194 // rest of the function into account to avoid overlap with the
194 // parsing statistics. 195 // parsing statistics.
195 HistogramTimer* rate = is_eval 196 HistogramTimer* rate = is_eval
196 ? &Counters::compile_eval 197 ? &Counters::compile_eval
197 : &Counters::compile; 198 : &Counters::compile;
198 HistogramTimerScope timer(rate); 199 HistogramTimerScope timer(rate);
199 200
200 // Compile the code. 201 // Compile the code.
201 Handle<Code> code = MakeCode(lit, script, context, is_eval, 202 Handle<Code> code = MakeCode(lit,
202 Handle<SharedFunctionInfo>::null()); 203 script,
204 context,
205 is_eval,
206 Handle<SharedFunctionInfo>::null(),
207 Handle<Object>::null()); // No receiver.
203 208
204 // Check for stack-overflow exceptions. 209 // Check for stack-overflow exceptions.
205 if (code.is_null()) { 210 if (code.is_null()) {
206 Top::StackOverflow(); 211 Top::StackOverflow();
207 return Handle<JSFunction>::null(); 212 return Handle<JSFunction>::null();
208 } 213 }
209 214
210 #if defined ENABLE_LOGGING_AND_PROFILING || defined ENABLE_OPROFILE_AGENT 215 #if defined ENABLE_LOGGING_AND_PROFILING || defined ENABLE_OPROFILE_AGENT
211 // Log the code generation for the script. Check explicit whether logging is 216 // Log the code generation for the script. Check explicit whether logging is
212 // to avoid allocating when not required. 217 // to avoid allocating when not required.
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 // string again so we don't use the compilation cache. 359 // string again so we don't use the compilation cache.
355 CompilationCache::PutEval(source, context, is_global, result); 360 CompilationCache::PutEval(source, context, is_global, result);
356 } 361 }
357 } 362 }
358 363
359 return result; 364 return result;
360 } 365 }
361 366
362 367
363 bool Compiler::CompileLazy(Handle<SharedFunctionInfo> shared, 368 bool Compiler::CompileLazy(Handle<SharedFunctionInfo> shared,
369 Handle<Object> receiver,
364 int loop_nesting) { 370 int loop_nesting) {
365 CompilationZoneScope zone_scope(DELETE_ON_EXIT); 371 CompilationZoneScope zone_scope(DELETE_ON_EXIT);
366 372
367 // The VM is in the COMPILER state until exiting this function. 373 // The VM is in the COMPILER state until exiting this function.
368 VMState state(COMPILER); 374 VMState state(COMPILER);
369 375
370 PostponeInterruptsScope postpone; 376 PostponeInterruptsScope postpone;
371 377
372 // Compute name, source code and script data. 378 // Compute name, source code and script data.
373 Handle<String> name(String::cast(shared->name())); 379 Handle<String> name(String::cast(shared->name()));
(...skipping 19 matching lines...) Expand all
393 399
394 // Update the loop nesting in the function literal. 400 // Update the loop nesting in the function literal.
395 lit->set_loop_nesting(loop_nesting); 401 lit->set_loop_nesting(loop_nesting);
396 402
397 // Measure how long it takes to do the lazy compilation; only take 403 // Measure how long it takes to do the lazy compilation; only take
398 // the rest of the function into account to avoid overlap with the 404 // the rest of the function into account to avoid overlap with the
399 // lazy parsing statistics. 405 // lazy parsing statistics.
400 HistogramTimerScope timer(&Counters::compile_lazy); 406 HistogramTimerScope timer(&Counters::compile_lazy);
401 407
402 // Compile the code. 408 // Compile the code.
403 Handle<Code> code = MakeCode(lit, script, Handle<Context>::null(), false, 409 Handle<Code> code = MakeCode(lit,
404 shared); 410 script,
411 Handle<Context>::null(),
412 false,
413 shared,
414 receiver);
405 415
406 // Check for stack-overflow exception. 416 // Check for stack-overflow exception.
407 if (code.is_null()) { 417 if (code.is_null()) {
408 Top::StackOverflow(); 418 Top::StackOverflow();
409 return false; 419 return false;
410 } 420 }
411 421
412 #if defined ENABLE_LOGGING_AND_PROFILING || defined ENABLE_OPROFILE_AGENT 422 #if defined ENABLE_LOGGING_AND_PROFILING || defined ENABLE_OPROFILE_AGENT
413 // Log the code generation. If source information is available include script 423 // Log the code generation. If source information is available include script
414 // name and line number. Check explicit whether logging is enabled as finding 424 // name and line number. Check explicit whether logging is enabled as finding
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 FullCodeGenSyntaxChecker checker; 499 FullCodeGenSyntaxChecker checker;
490 checker.Check(literal); 500 checker.Check(literal);
491 if (checker.has_supported_syntax()) { 501 if (checker.has_supported_syntax()) {
492 code = FullCodeGenerator::MakeCode(literal, 502 code = FullCodeGenerator::MakeCode(literal,
493 script, 503 script,
494 false); // Not eval. 504 false); // Not eval.
495 is_compiled = true; 505 is_compiled = true;
496 } 506 }
497 } else if (FLAG_always_fast_compiler || 507 } else if (FLAG_always_fast_compiler ||
498 (FLAG_fast_compiler && !is_run_once)) { 508 (FLAG_fast_compiler && !is_run_once)) {
499 FastCodeGenSyntaxChecker checker; 509 // Since we are not lazily compiling we do not have a receiver to
510 // specialize for.
511 FastCodeGenSyntaxChecker checker(Handle<Object>::null());
500 checker.Check(literal); 512 checker.Check(literal);
501 // Generate no code. 513 // Generate no code.
502 } 514 }
503 515
504 if (!is_compiled) { 516 if (!is_compiled) {
505 // We fall back to the classic V8 code generator. 517 // We fall back to the classic V8 code generator.
506 code = CodeGenerator::MakeCode(literal, 518 code = CodeGenerator::MakeCode(literal,
507 script, 519 script,
508 false); // Not eval. 520 false); // Not eval.
509 } 521 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 fun->shared()->set_is_toplevel(is_toplevel); 574 fun->shared()->set_is_toplevel(is_toplevel);
563 fun->shared()->set_inferred_name(*lit->inferred_name()); 575 fun->shared()->set_inferred_name(*lit->inferred_name());
564 fun->shared()->SetThisPropertyAssignmentsInfo( 576 fun->shared()->SetThisPropertyAssignmentsInfo(
565 lit->has_only_simple_this_property_assignments(), 577 lit->has_only_simple_this_property_assignments(),
566 *lit->this_property_assignments()); 578 *lit->this_property_assignments());
567 fun->shared()->set_try_full_codegen(lit->try_full_codegen()); 579 fun->shared()->set_try_full_codegen(lit->try_full_codegen());
568 } 580 }
569 581
570 582
571 } } // namespace v8::internal 583 } } // namespace v8::internal
OLDNEW
« src/compiler.h ('K') | « src/compiler.h ('k') | src/debug.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698