| OLD | NEW |
| 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 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 // Compile the code. | 378 // Compile the code. |
| 379 Handle<Code> code = MakeCode(Handle<Context>::null(), info); | 379 Handle<Code> code = MakeCode(Handle<Context>::null(), info); |
| 380 | 380 |
| 381 // Check for stack-overflow exception. | 381 // Check for stack-overflow exception. |
| 382 if (code.is_null()) { | 382 if (code.is_null()) { |
| 383 Top::StackOverflow(); | 383 Top::StackOverflow(); |
| 384 return false; | 384 return false; |
| 385 } | 385 } |
| 386 | 386 |
| 387 #if defined ENABLE_LOGGING_AND_PROFILING || defined ENABLE_OPROFILE_AGENT | 387 #if defined ENABLE_LOGGING_AND_PROFILING || defined ENABLE_OPROFILE_AGENT |
| 388 // Log the code generation. If source information is available include script | 388 LogCodeCreateEvent(Logger::LAZY_COMPILE_TAG, |
| 389 // name and line number. Check explicit whether logging is enabled as finding | 389 name, |
| 390 // the line number is not for free. | 390 Handle<String>(shared->inferred_name()), |
| 391 if (Logger::is_logging() || OProfileAgent::is_enabled()) { | 391 start_position, |
| 392 Handle<String> func_name(name->length() > 0 ? | 392 info->script(), |
| 393 *name : shared->inferred_name()); | 393 code); |
| 394 Handle<Script> script = info->script(); | |
| 395 if (script->name()->IsString()) { | |
| 396 int line_num = GetScriptLineNumber(script, start_position) + 1; | |
| 397 LOG(CodeCreateEvent(Logger::LAZY_COMPILE_TAG, *code, *func_name, | |
| 398 String::cast(script->name()), line_num)); | |
| 399 OProfileAgent::CreateNativeCodeRegion(*func_name, | |
| 400 String::cast(script->name()), | |
| 401 line_num, | |
| 402 code->instruction_start(), | |
| 403 code->instruction_size()); | |
| 404 } else { | |
| 405 LOG(CodeCreateEvent(Logger::LAZY_COMPILE_TAG, *code, *func_name)); | |
| 406 OProfileAgent::CreateNativeCodeRegion(*func_name, | |
| 407 code->instruction_start(), | |
| 408 code->instruction_size()); | |
| 409 } | |
| 410 } | |
| 411 #endif | 394 #endif |
| 412 | 395 |
| 413 // Update the shared function info with the compiled code. | 396 // Update the shared function info with the compiled code. |
| 414 shared->set_code(*code); | 397 shared->set_code(*code); |
| 415 | 398 |
| 416 // Set the expected number of properties for instances. | 399 // Set the expected number of properties for instances. |
| 417 SetExpectedNofPropertiesFromEstimate(shared, lit->expected_property_count()); | 400 SetExpectedNofPropertiesFromEstimate(shared, lit->expected_property_count()); |
| 418 | 401 |
| 419 // Set the optimication hints after performing lazy compilation, as these are | 402 // Set the optimication hints after performing lazy compilation, as these are |
| 420 // not set when the function is set up as a lazily compiled function. | 403 // not set when the function is set up as a lazily compiled function. |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 code = CodeGenerator::MakeCode(&info); | 470 code = CodeGenerator::MakeCode(&info); |
| 488 } | 471 } |
| 489 | 472 |
| 490 // Check for stack-overflow exception. | 473 // Check for stack-overflow exception. |
| 491 if (code.is_null()) { | 474 if (code.is_null()) { |
| 492 caller->SetStackOverflow(); | 475 caller->SetStackOverflow(); |
| 493 return Handle<JSFunction>::null(); | 476 return Handle<JSFunction>::null(); |
| 494 } | 477 } |
| 495 | 478 |
| 496 // Function compilation complete. | 479 // Function compilation complete. |
| 497 LOG(CodeCreateEvent(Logger::FUNCTION_TAG, *code, *literal->name())); | |
| 498 | 480 |
| 499 #ifdef ENABLE_OPROFILE_AGENT | 481 #if defined ENABLE_LOGGING_AND_PROFILING || defined ENABLE_OPROFILE_AGENT |
| 500 OProfileAgent::CreateNativeCodeRegion(*literal->name(), | 482 LogCodeCreateEvent(Logger::FUNCTION_TAG, |
| 501 code->instruction_start(), | 483 literal->name(), |
| 502 code->instruction_size()); | 484 literal->inferred_name(), |
| 485 literal->start_position(), |
| 486 script, |
| 487 code); |
| 503 #endif | 488 #endif |
| 504 } | 489 } |
| 505 | 490 |
| 506 // Create a boilerplate function. | 491 // Create a boilerplate function. |
| 507 Handle<JSFunction> function = | 492 Handle<JSFunction> function = |
| 508 Factory::NewFunctionBoilerplate(literal->name(), | 493 Factory::NewFunctionBoilerplate(literal->name(), |
| 509 literal->materialized_literal_count(), | 494 literal->materialized_literal_count(), |
| 510 code); | 495 code); |
| 511 SetFunctionInfo(function, literal, false, script); | 496 SetFunctionInfo(function, literal, false, script); |
| 512 | 497 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 540 fun->shared()->set_is_expression(lit->is_expression()); | 525 fun->shared()->set_is_expression(lit->is_expression()); |
| 541 fun->shared()->set_is_toplevel(is_toplevel); | 526 fun->shared()->set_is_toplevel(is_toplevel); |
| 542 fun->shared()->set_inferred_name(*lit->inferred_name()); | 527 fun->shared()->set_inferred_name(*lit->inferred_name()); |
| 543 fun->shared()->SetThisPropertyAssignmentsInfo( | 528 fun->shared()->SetThisPropertyAssignmentsInfo( |
| 544 lit->has_only_simple_this_property_assignments(), | 529 lit->has_only_simple_this_property_assignments(), |
| 545 *lit->this_property_assignments()); | 530 *lit->this_property_assignments()); |
| 546 fun->shared()->set_try_full_codegen(lit->try_full_codegen()); | 531 fun->shared()->set_try_full_codegen(lit->try_full_codegen()); |
| 547 } | 532 } |
| 548 | 533 |
| 549 | 534 |
| 535 #if defined ENABLE_LOGGING_AND_PROFILING || defined ENABLE_OPROFILE_AGENT |
| 536 void Compiler::LogCodeCreateEvent(Logger::LogEventsAndTags tag, |
| 537 Handle<String> name, |
| 538 Handle<String> inferred_name, |
| 539 int start_position, |
| 540 Handle<Script> script, |
| 541 Handle<Code> code) { |
| 542 // Log the code generation. If source information is available |
| 543 // include script name and line number. Check explicitly whether |
| 544 // logging is enabled as finding the line number is not free. |
| 545 if (Logger::is_logging() || OProfileAgent::is_enabled()) { |
| 546 Handle<String> func_name(name->length() > 0 ? *name : *inferred_name); |
| 547 if (script->name()->IsString()) { |
| 548 int line_num = GetScriptLineNumber(script, start_position) + 1; |
| 549 LOG(CodeCreateEvent(tag, *code, *func_name, |
| 550 String::cast(script->name()), line_num)); |
| 551 OProfileAgent::CreateNativeCodeRegion(*func_name, |
| 552 String::cast(script->name()), |
| 553 line_num, |
| 554 code->instruction_start(), |
| 555 code->instruction_size()); |
| 556 } else { |
| 557 LOG(CodeCreateEvent(tag, *code, *func_name)); |
| 558 OProfileAgent::CreateNativeCodeRegion(*func_name, |
| 559 code->instruction_start(), |
| 560 code->instruction_size()); |
| 561 } |
| 562 } |
| 563 } |
| 564 #endif |
| 565 |
| 550 } } // namespace v8::internal | 566 } } // namespace v8::internal |
| OLD | NEW |