| 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 | 290 |
| 290 FullCodeGenerator cgen(&masm); | 291 FullCodeGenerator cgen(&masm); |
| 291 cgen.Generate(info); | 292 cgen.Generate(info); |
| 292 if (cgen.HasStackOverflow()) { | 293 if (cgen.HasStackOverflow()) { |
| 293 ASSERT(!Isolate::Current()->has_pending_exception()); | 294 ASSERT(!isolate->has_pending_exception()); |
| 294 return false; | 295 return false; |
| 295 } | 296 } |
| 296 unsigned table_offset = cgen.EmitStackCheckTable(); | 297 unsigned table_offset = cgen.EmitStackCheckTable(); |
| 297 | 298 |
| 298 Code::Flags flags = Code::ComputeFlags(Code::FUNCTION, NOT_IN_LOOP); | 299 Code::Flags flags = Code::ComputeFlags(Code::FUNCTION, NOT_IN_LOOP); |
| 299 Handle<Code> code = CodeGenerator::MakeCodeEpilogue(&masm, flags, info); | 300 Handle<Code> code = CodeGenerator::MakeCodeEpilogue(&masm, flags, info); |
| 300 code->set_optimizable(info->IsOptimizable()); | 301 code->set_optimizable(info->IsOptimizable()); |
| 301 cgen.PopulateDeoptimizationData(code); | 302 cgen.PopulateDeoptimizationData(code); |
| 302 code->set_has_deoptimization_support(info->HasDeoptimizationSupport()); | 303 code->set_has_deoptimization_support(info->HasDeoptimizationSupport()); |
| 303 code->set_allow_osr_at_loop_nesting_level(0); | 304 code->set_allow_osr_at_loop_nesting_level(0); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 325 return offset; | 326 return offset; |
| 326 } | 327 } |
| 327 | 328 |
| 328 | 329 |
| 329 void FullCodeGenerator::PopulateDeoptimizationData(Handle<Code> code) { | 330 void FullCodeGenerator::PopulateDeoptimizationData(Handle<Code> code) { |
| 330 // Fill in the deoptimization information. | 331 // Fill in the deoptimization information. |
| 331 ASSERT(info_->HasDeoptimizationSupport() || bailout_entries_.is_empty()); | 332 ASSERT(info_->HasDeoptimizationSupport() || bailout_entries_.is_empty()); |
| 332 if (!info_->HasDeoptimizationSupport()) return; | 333 if (!info_->HasDeoptimizationSupport()) return; |
| 333 int length = bailout_entries_.length(); | 334 int length = bailout_entries_.length(); |
| 334 Handle<DeoptimizationOutputData> data = | 335 Handle<DeoptimizationOutputData> data = |
| 335 Isolate::Current()->factory()-> | 336 isolate()->factory()-> |
| 336 NewDeoptimizationOutputData(length, TENURED); | 337 NewDeoptimizationOutputData(length, TENURED); |
| 337 for (int i = 0; i < length; i++) { | 338 for (int i = 0; i < length; i++) { |
| 338 data->SetAstId(i, Smi::FromInt(bailout_entries_[i].id)); | 339 data->SetAstId(i, Smi::FromInt(bailout_entries_[i].id)); |
| 339 data->SetPcAndState(i, Smi::FromInt(bailout_entries_[i].pc_and_state)); | 340 data->SetPcAndState(i, Smi::FromInt(bailout_entries_[i].pc_and_state)); |
| 340 } | 341 } |
| 341 code->set_deoptimization_data(*data); | 342 code->set_deoptimization_data(*data); |
| 342 } | 343 } |
| 343 | 344 |
| 344 | 345 |
| 345 void FullCodeGenerator::PrepareForBailout(AstNode* node, State state) { | 346 void FullCodeGenerator::PrepareForBailout(AstNode* node, State state) { |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 VisitDeclaration(decl); | 529 VisitDeclaration(decl); |
| 529 } else { | 530 } else { |
| 530 // Count global variables and functions for later processing | 531 // Count global variables and functions for later processing |
| 531 globals++; | 532 globals++; |
| 532 } | 533 } |
| 533 } | 534 } |
| 534 | 535 |
| 535 // Compute array of global variable and function declarations. | 536 // Compute array of global variable and function declarations. |
| 536 // Do nothing in case of no declared global functions or variables. | 537 // Do nothing in case of no declared global functions or variables. |
| 537 if (globals > 0) { | 538 if (globals > 0) { |
| 538 Handle<FixedArray> array = FACTORY->NewFixedArray(2 * globals, TENURED); | 539 Handle<FixedArray> array = |
| 540 isolate()->factory()->NewFixedArray(2 * globals, TENURED); |
| 539 for (int j = 0, i = 0; i < length; i++) { | 541 for (int j = 0, i = 0; i < length; i++) { |
| 540 Declaration* decl = declarations->at(i); | 542 Declaration* decl = declarations->at(i); |
| 541 Variable* var = decl->proxy()->var(); | 543 Variable* var = decl->proxy()->var(); |
| 542 Slot* slot = var->AsSlot(); | 544 Slot* slot = var->AsSlot(); |
| 543 | 545 |
| 544 if ((slot == NULL || slot->type() != Slot::LOOKUP) && var->is_global()) { | 546 if ((slot == NULL || slot->type() != Slot::LOOKUP) && var->is_global()) { |
| 545 array->set(j++, *(var->name())); | 547 array->set(j++, *(var->name())); |
| 546 if (decl->fun() == NULL) { | 548 if (decl->fun() == NULL) { |
| 547 if (var->mode() == Variable::CONST) { | 549 if (var->mode() == Variable::CONST) { |
| 548 // In case this is const property use the hole. | 550 // In case this is const property use the hole. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 579 void FullCodeGenerator::SetReturnPosition(FunctionLiteral* fun) { | 581 void FullCodeGenerator::SetReturnPosition(FunctionLiteral* fun) { |
| 580 if (FLAG_debug_info) { | 582 if (FLAG_debug_info) { |
| 581 CodeGenerator::RecordPositions(masm_, fun->end_position() - 1); | 583 CodeGenerator::RecordPositions(masm_, fun->end_position() - 1); |
| 582 } | 584 } |
| 583 } | 585 } |
| 584 | 586 |
| 585 | 587 |
| 586 void FullCodeGenerator::SetStatementPosition(Statement* stmt) { | 588 void FullCodeGenerator::SetStatementPosition(Statement* stmt) { |
| 587 if (FLAG_debug_info) { | 589 if (FLAG_debug_info) { |
| 588 #ifdef ENABLE_DEBUGGER_SUPPORT | 590 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 589 if (!Isolate::Current()->debugger()->IsDebuggerActive()) { | 591 if (!isolate()->debugger()->IsDebuggerActive()) { |
| 590 CodeGenerator::RecordPositions(masm_, stmt->statement_pos()); | 592 CodeGenerator::RecordPositions(masm_, stmt->statement_pos()); |
| 591 } else { | 593 } else { |
| 592 // Check if the statement will be breakable without adding a debug break | 594 // Check if the statement will be breakable without adding a debug break |
| 593 // slot. | 595 // slot. |
| 594 BreakableStatementChecker checker; | 596 BreakableStatementChecker checker; |
| 595 checker.Check(stmt); | 597 checker.Check(stmt); |
| 596 // Record the statement position right here if the statement is not | 598 // Record the statement position right here if the statement is not |
| 597 // breakable. For breakable statements the actual recording of the | 599 // breakable. For breakable statements the actual recording of the |
| 598 // position will be postponed to the breakable code (typically an IC). | 600 // position will be postponed to the breakable code (typically an IC). |
| 599 bool position_recorded = CodeGenerator::RecordPositions( | 601 bool position_recorded = CodeGenerator::RecordPositions( |
| 600 masm_, stmt->statement_pos(), !checker.is_breakable()); | 602 masm_, stmt->statement_pos(), !checker.is_breakable()); |
| 601 // If the position recording did record a new position generate a debug | 603 // If the position recording did record a new position generate a debug |
| 602 // break slot to make the statement breakable. | 604 // break slot to make the statement breakable. |
| 603 if (position_recorded) { | 605 if (position_recorded) { |
| 604 Debug::GenerateSlot(masm_); | 606 Debug::GenerateSlot(masm_); |
| 605 } | 607 } |
| 606 } | 608 } |
| 607 #else | 609 #else |
| 608 CodeGenerator::RecordPositions(masm_, stmt->statement_pos()); | 610 CodeGenerator::RecordPositions(masm_, stmt->statement_pos()); |
| 609 #endif | 611 #endif |
| 610 } | 612 } |
| 611 } | 613 } |
| 612 | 614 |
| 613 | 615 |
| 614 void FullCodeGenerator::SetExpressionPosition(Expression* expr, int pos) { | 616 void FullCodeGenerator::SetExpressionPosition(Expression* expr, int pos) { |
| 615 if (FLAG_debug_info) { | 617 if (FLAG_debug_info) { |
| 616 #ifdef ENABLE_DEBUGGER_SUPPORT | 618 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 617 if (!Isolate::Current()->debugger()->IsDebuggerActive()) { | 619 if (!isolate()->debugger()->IsDebuggerActive()) { |
| 618 CodeGenerator::RecordPositions(masm_, pos); | 620 CodeGenerator::RecordPositions(masm_, pos); |
| 619 } else { | 621 } else { |
| 620 // Check if the expression will be breakable without adding a debug break | 622 // Check if the expression will be breakable without adding a debug break |
| 621 // slot. | 623 // slot. |
| 622 BreakableStatementChecker checker; | 624 BreakableStatementChecker checker; |
| 623 checker.Check(expr); | 625 checker.Check(expr); |
| 624 // Record a statement position right here if the expression is not | 626 // Record a statement position right here if the expression is not |
| 625 // breakable. For breakable expressions the actual recording of the | 627 // breakable. For breakable expressions the actual recording of the |
| 626 // position will be postponed to the breakable code (typically an IC). | 628 // position will be postponed to the breakable code (typically an IC). |
| 627 // NOTE this will record a statement position for something which might | 629 // NOTE this will record a statement position for something which might |
| (...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1349 __ Drop(stack_depth); | 1351 __ Drop(stack_depth); |
| 1350 __ PopTryHandler(); | 1352 __ PopTryHandler(); |
| 1351 return 0; | 1353 return 0; |
| 1352 } | 1354 } |
| 1353 | 1355 |
| 1354 | 1356 |
| 1355 #undef __ | 1357 #undef __ |
| 1356 | 1358 |
| 1357 | 1359 |
| 1358 } } // namespace v8::internal | 1360 } } // namespace v8::internal |
| OLD | NEW |