OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 } | 268 } |
269 | 269 |
270 | 270 |
271 void BreakableStatementChecker::VisitThisFunction(ThisFunction* expr) { | 271 void BreakableStatementChecker::VisitThisFunction(ThisFunction* expr) { |
272 } | 272 } |
273 | 273 |
274 | 274 |
275 #define __ ACCESS_MASM(masm()) | 275 #define __ ACCESS_MASM(masm()) |
276 | 276 |
277 bool FullCodeGenerator::MakeCode(CompilationInfo* info) { | 277 bool FullCodeGenerator::MakeCode(CompilationInfo* info) { |
| 278 Isolate* isolate = Isolate::Current(); |
278 Handle<Script> script = info->script(); | 279 Handle<Script> script = info->script(); |
279 if (!script->IsUndefined() && !script->source()->IsUndefined()) { | 280 if (!script->IsUndefined() && !script->source()->IsUndefined()) { |
280 int len = String::cast(script->source())->length(); | 281 int len = String::cast(script->source())->length(); |
281 Counters::total_full_codegen_source_size.Increment(len); | 282 isolate->counters()->total_full_codegen_source_size()->Increment(len); |
282 } | 283 } |
283 if (FLAG_trace_codegen) { | 284 if (FLAG_trace_codegen) { |
284 PrintF("Full Compiler - "); | 285 PrintF("Full Compiler - "); |
285 } | 286 } |
286 CodeGenerator::MakeCodePrologue(info); | 287 CodeGenerator::MakeCodePrologue(info); |
287 const int kInitialBufferSize = 4 * KB; | 288 const int kInitialBufferSize = 4 * KB; |
288 MacroAssembler masm(NULL, kInitialBufferSize); | 289 MacroAssembler masm(NULL, kInitialBufferSize); |
289 #ifdef ENABLE_GDB_JIT_INTERFACE | 290 #ifdef ENABLE_GDB_JIT_INTERFACE |
290 masm.positions_recorder()->StartGDBJITLineInfoRecording(); | 291 masm.positions_recorder()->StartGDBJITLineInfoRecording(); |
291 #endif | 292 #endif |
292 | 293 |
293 FullCodeGenerator cgen(&masm); | 294 FullCodeGenerator cgen(&masm); |
294 cgen.Generate(info); | 295 cgen.Generate(info); |
295 if (cgen.HasStackOverflow()) { | 296 if (cgen.HasStackOverflow()) { |
296 ASSERT(!Top::has_pending_exception()); | 297 ASSERT(!isolate->has_pending_exception()); |
297 return false; | 298 return false; |
298 } | 299 } |
299 unsigned table_offset = cgen.EmitStackCheckTable(); | 300 unsigned table_offset = cgen.EmitStackCheckTable(); |
300 | 301 |
301 Code::Flags flags = Code::ComputeFlags(Code::FUNCTION, NOT_IN_LOOP); | 302 Code::Flags flags = Code::ComputeFlags(Code::FUNCTION, NOT_IN_LOOP); |
302 Handle<Code> code = CodeGenerator::MakeCodeEpilogue(&masm, flags, info); | 303 Handle<Code> code = CodeGenerator::MakeCodeEpilogue(&masm, flags, info); |
303 code->set_optimizable(info->IsOptimizable()); | 304 code->set_optimizable(info->IsOptimizable()); |
304 cgen.PopulateDeoptimizationData(code); | 305 cgen.PopulateDeoptimizationData(code); |
305 code->set_has_deoptimization_support(info->HasDeoptimizationSupport()); | 306 code->set_has_deoptimization_support(info->HasDeoptimizationSupport()); |
306 code->set_allow_osr_at_loop_nesting_level(0); | 307 code->set_allow_osr_at_loop_nesting_level(0); |
(...skipping 29 matching lines...) Expand all Loading... |
336 return offset; | 337 return offset; |
337 } | 338 } |
338 | 339 |
339 | 340 |
340 void FullCodeGenerator::PopulateDeoptimizationData(Handle<Code> code) { | 341 void FullCodeGenerator::PopulateDeoptimizationData(Handle<Code> code) { |
341 // Fill in the deoptimization information. | 342 // Fill in the deoptimization information. |
342 ASSERT(info_->HasDeoptimizationSupport() || bailout_entries_.is_empty()); | 343 ASSERT(info_->HasDeoptimizationSupport() || bailout_entries_.is_empty()); |
343 if (!info_->HasDeoptimizationSupport()) return; | 344 if (!info_->HasDeoptimizationSupport()) return; |
344 int length = bailout_entries_.length(); | 345 int length = bailout_entries_.length(); |
345 Handle<DeoptimizationOutputData> data = | 346 Handle<DeoptimizationOutputData> data = |
346 Factory::NewDeoptimizationOutputData(length, TENURED); | 347 isolate()->factory()-> |
| 348 NewDeoptimizationOutputData(length, TENURED); |
347 for (int i = 0; i < length; i++) { | 349 for (int i = 0; i < length; i++) { |
348 data->SetAstId(i, Smi::FromInt(bailout_entries_[i].id)); | 350 data->SetAstId(i, Smi::FromInt(bailout_entries_[i].id)); |
349 data->SetPcAndState(i, Smi::FromInt(bailout_entries_[i].pc_and_state)); | 351 data->SetPcAndState(i, Smi::FromInt(bailout_entries_[i].pc_and_state)); |
350 } | 352 } |
351 code->set_deoptimization_data(*data); | 353 code->set_deoptimization_data(*data); |
352 } | 354 } |
353 | 355 |
354 | 356 |
355 void FullCodeGenerator::PrepareForBailout(AstNode* node, State state) { | 357 void FullCodeGenerator::PrepareForBailout(AstNode* node, State state) { |
356 PrepareForBailoutForId(node->id(), state); | 358 PrepareForBailoutForId(node->id(), state); |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 VisitDeclaration(decl); | 540 VisitDeclaration(decl); |
539 } else { | 541 } else { |
540 // Count global variables and functions for later processing | 542 // Count global variables and functions for later processing |
541 globals++; | 543 globals++; |
542 } | 544 } |
543 } | 545 } |
544 | 546 |
545 // Compute array of global variable and function declarations. | 547 // Compute array of global variable and function declarations. |
546 // Do nothing in case of no declared global functions or variables. | 548 // Do nothing in case of no declared global functions or variables. |
547 if (globals > 0) { | 549 if (globals > 0) { |
548 Handle<FixedArray> array = Factory::NewFixedArray(2 * globals, TENURED); | 550 Handle<FixedArray> array = |
| 551 isolate()->factory()->NewFixedArray(2 * globals, TENURED); |
549 for (int j = 0, i = 0; i < length; i++) { | 552 for (int j = 0, i = 0; i < length; i++) { |
550 Declaration* decl = declarations->at(i); | 553 Declaration* decl = declarations->at(i); |
551 Variable* var = decl->proxy()->var(); | 554 Variable* var = decl->proxy()->var(); |
552 Slot* slot = var->AsSlot(); | 555 Slot* slot = var->AsSlot(); |
553 | 556 |
554 if ((slot == NULL || slot->type() != Slot::LOOKUP) && var->is_global()) { | 557 if ((slot == NULL || slot->type() != Slot::LOOKUP) && var->is_global()) { |
555 array->set(j++, *(var->name())); | 558 array->set(j++, *(var->name())); |
556 if (decl->fun() == NULL) { | 559 if (decl->fun() == NULL) { |
557 if (var->mode() == Variable::CONST) { | 560 if (var->mode() == Variable::CONST) { |
558 // In case this is const property use the hole. | 561 // In case this is const property use the hole. |
(...skipping 30 matching lines...) Expand all Loading... |
589 void FullCodeGenerator::SetReturnPosition(FunctionLiteral* fun) { | 592 void FullCodeGenerator::SetReturnPosition(FunctionLiteral* fun) { |
590 if (FLAG_debug_info) { | 593 if (FLAG_debug_info) { |
591 CodeGenerator::RecordPositions(masm_, fun->end_position() - 1); | 594 CodeGenerator::RecordPositions(masm_, fun->end_position() - 1); |
592 } | 595 } |
593 } | 596 } |
594 | 597 |
595 | 598 |
596 void FullCodeGenerator::SetStatementPosition(Statement* stmt) { | 599 void FullCodeGenerator::SetStatementPosition(Statement* stmt) { |
597 if (FLAG_debug_info) { | 600 if (FLAG_debug_info) { |
598 #ifdef ENABLE_DEBUGGER_SUPPORT | 601 #ifdef ENABLE_DEBUGGER_SUPPORT |
599 if (!Debugger::IsDebuggerActive()) { | 602 if (!isolate()->debugger()->IsDebuggerActive()) { |
600 CodeGenerator::RecordPositions(masm_, stmt->statement_pos()); | 603 CodeGenerator::RecordPositions(masm_, stmt->statement_pos()); |
601 } else { | 604 } else { |
602 // Check if the statement will be breakable without adding a debug break | 605 // Check if the statement will be breakable without adding a debug break |
603 // slot. | 606 // slot. |
604 BreakableStatementChecker checker; | 607 BreakableStatementChecker checker; |
605 checker.Check(stmt); | 608 checker.Check(stmt); |
606 // Record the statement position right here if the statement is not | 609 // Record the statement position right here if the statement is not |
607 // breakable. For breakable statements the actual recording of the | 610 // breakable. For breakable statements the actual recording of the |
608 // position will be postponed to the breakable code (typically an IC). | 611 // position will be postponed to the breakable code (typically an IC). |
609 bool position_recorded = CodeGenerator::RecordPositions( | 612 bool position_recorded = CodeGenerator::RecordPositions( |
610 masm_, stmt->statement_pos(), !checker.is_breakable()); | 613 masm_, stmt->statement_pos(), !checker.is_breakable()); |
611 // If the position recording did record a new position generate a debug | 614 // If the position recording did record a new position generate a debug |
612 // break slot to make the statement breakable. | 615 // break slot to make the statement breakable. |
613 if (position_recorded) { | 616 if (position_recorded) { |
614 Debug::GenerateSlot(masm_); | 617 Debug::GenerateSlot(masm_); |
615 } | 618 } |
616 } | 619 } |
617 #else | 620 #else |
618 CodeGenerator::RecordPositions(masm_, stmt->statement_pos()); | 621 CodeGenerator::RecordPositions(masm_, stmt->statement_pos()); |
619 #endif | 622 #endif |
620 } | 623 } |
621 } | 624 } |
622 | 625 |
623 | 626 |
624 void FullCodeGenerator::SetExpressionPosition(Expression* expr, int pos) { | 627 void FullCodeGenerator::SetExpressionPosition(Expression* expr, int pos) { |
625 if (FLAG_debug_info) { | 628 if (FLAG_debug_info) { |
626 #ifdef ENABLE_DEBUGGER_SUPPORT | 629 #ifdef ENABLE_DEBUGGER_SUPPORT |
627 if (!Debugger::IsDebuggerActive()) { | 630 if (!isolate()->debugger()->IsDebuggerActive()) { |
628 CodeGenerator::RecordPositions(masm_, pos); | 631 CodeGenerator::RecordPositions(masm_, pos); |
629 } else { | 632 } else { |
630 // Check if the expression will be breakable without adding a debug break | 633 // Check if the expression will be breakable without adding a debug break |
631 // slot. | 634 // slot. |
632 BreakableStatementChecker checker; | 635 BreakableStatementChecker checker; |
633 checker.Check(expr); | 636 checker.Check(expr); |
634 // Record a statement position right here if the expression is not | 637 // Record a statement position right here if the expression is not |
635 // breakable. For breakable expressions the actual recording of the | 638 // breakable. For breakable expressions the actual recording of the |
636 // position will be postponed to the breakable code (typically an IC). | 639 // position will be postponed to the breakable code (typically an IC). |
637 // NOTE this will record a statement position for something which might | 640 // NOTE this will record a statement position for something which might |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 ASSERT(lookup_index >= 0); | 690 ASSERT(lookup_index >= 0); |
688 ASSERT(static_cast<size_t>(lookup_index) < | 691 ASSERT(static_cast<size_t>(lookup_index) < |
689 ARRAY_SIZE(kInlineFunctionGenerators)); | 692 ARRAY_SIZE(kInlineFunctionGenerators)); |
690 return kInlineFunctionGenerators[lookup_index]; | 693 return kInlineFunctionGenerators[lookup_index]; |
691 } | 694 } |
692 | 695 |
693 | 696 |
694 void FullCodeGenerator::EmitInlineRuntimeCall(CallRuntime* node) { | 697 void FullCodeGenerator::EmitInlineRuntimeCall(CallRuntime* node) { |
695 ZoneList<Expression*>* args = node->arguments(); | 698 ZoneList<Expression*>* args = node->arguments(); |
696 Handle<String> name = node->name(); | 699 Handle<String> name = node->name(); |
697 Runtime::Function* function = node->function(); | 700 const Runtime::Function* function = node->function(); |
698 ASSERT(function != NULL); | 701 ASSERT(function != NULL); |
699 ASSERT(function->intrinsic_type == Runtime::INLINE); | 702 ASSERT(function->intrinsic_type == Runtime::INLINE); |
700 InlineFunctionGenerator generator = | 703 InlineFunctionGenerator generator = |
701 FindInlineFunctionGenerator(function->function_id); | 704 FindInlineFunctionGenerator(function->function_id); |
702 ((*this).*(generator))(args); | 705 ((*this).*(generator))(args); |
703 } | 706 } |
704 | 707 |
705 | 708 |
706 void FullCodeGenerator::VisitBinaryOperation(BinaryOperation* expr) { | 709 void FullCodeGenerator::VisitBinaryOperation(BinaryOperation* expr) { |
707 Comment cmnt(masm_, "[ BinaryOperation"); | 710 Comment cmnt(masm_, "[ BinaryOperation"); |
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1373 __ Drop(stack_depth); | 1376 __ Drop(stack_depth); |
1374 __ PopTryHandler(); | 1377 __ PopTryHandler(); |
1375 return 0; | 1378 return 0; |
1376 } | 1379 } |
1377 | 1380 |
1378 | 1381 |
1379 #undef __ | 1382 #undef __ |
1380 | 1383 |
1381 | 1384 |
1382 } } // namespace v8::internal | 1385 } } // namespace v8::internal |
OLD | NEW |