OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 } | 338 } |
339 unsigned table_offset = cgen.EmitBackEdgeTable(); | 339 unsigned table_offset = cgen.EmitBackEdgeTable(); |
340 | 340 |
341 Code::Flags flags = Code::ComputeFlags(Code::FUNCTION); | 341 Code::Flags flags = Code::ComputeFlags(Code::FUNCTION); |
342 Handle<Code> code = CodeGenerator::MakeCodeEpilogue(&masm, flags, info); | 342 Handle<Code> code = CodeGenerator::MakeCodeEpilogue(&masm, flags, info); |
343 code->set_optimizable(info->IsOptimizable() && | 343 code->set_optimizable(info->IsOptimizable() && |
344 !info->function()->dont_optimize() && | 344 !info->function()->dont_optimize() && |
345 info->function()->scope()->AllowsLazyCompilation()); | 345 info->function()->scope()->AllowsLazyCompilation()); |
346 cgen.PopulateDeoptimizationData(code); | 346 cgen.PopulateDeoptimizationData(code); |
347 cgen.PopulateTypeFeedbackInfo(code); | 347 cgen.PopulateTypeFeedbackInfo(code); |
348 cgen.PopulateTypeFeedbackCells(code); | |
349 code->set_has_deoptimization_support(info->HasDeoptimizationSupport()); | 348 code->set_has_deoptimization_support(info->HasDeoptimizationSupport()); |
350 code->set_handler_table(*cgen.handler_table()); | 349 code->set_handler_table(*cgen.handler_table()); |
351 #ifdef ENABLE_DEBUGGER_SUPPORT | 350 #ifdef ENABLE_DEBUGGER_SUPPORT |
352 code->set_compiled_optimizable(info->IsOptimizable()); | 351 code->set_compiled_optimizable(info->IsOptimizable()); |
353 #endif // ENABLE_DEBUGGER_SUPPORT | 352 #endif // ENABLE_DEBUGGER_SUPPORT |
354 code->set_allow_osr_at_loop_nesting_level(0); | 353 code->set_allow_osr_at_loop_nesting_level(0); |
355 code->set_profiler_ticks(0); | 354 code->set_profiler_ticks(0); |
356 code->set_back_edge_table_offset(table_offset); | 355 code->set_back_edge_table_offset(table_offset); |
357 code->set_back_edges_patched_for_osr(false); | 356 code->set_back_edges_patched_for_osr(false); |
358 CodeGenerator::PrintCode(code, info); | 357 CodeGenerator::PrintCode(code, info); |
(...skipping 21 matching lines...) Expand all Loading... |
380 __ dd(length); | 379 __ dd(length); |
381 for (unsigned i = 0; i < length; ++i) { | 380 for (unsigned i = 0; i < length; ++i) { |
382 __ dd(back_edges_[i].id.ToInt()); | 381 __ dd(back_edges_[i].id.ToInt()); |
383 __ dd(back_edges_[i].pc); | 382 __ dd(back_edges_[i].pc); |
384 __ dd(back_edges_[i].loop_depth); | 383 __ dd(back_edges_[i].loop_depth); |
385 } | 384 } |
386 return offset; | 385 return offset; |
387 } | 386 } |
388 | 387 |
389 | 388 |
| 389 void FullCodeGenerator::InitializeFeedbackVector() { |
| 390 int length = info_->function()->slot_count(); |
| 391 ASSERT_EQ(isolate()->heap()->the_hole_value(), |
| 392 *TypeFeedbackInfo::UninitializedSentinel(isolate())); |
| 393 feedback_vector_ = isolate()->factory()->NewFixedArrayWithHoles(length, |
| 394 TENURED); |
| 395 } |
| 396 |
| 397 |
390 void FullCodeGenerator::PopulateDeoptimizationData(Handle<Code> code) { | 398 void FullCodeGenerator::PopulateDeoptimizationData(Handle<Code> code) { |
391 // Fill in the deoptimization information. | 399 // Fill in the deoptimization information. |
392 ASSERT(info_->HasDeoptimizationSupport() || bailout_entries_.is_empty()); | 400 ASSERT(info_->HasDeoptimizationSupport() || bailout_entries_.is_empty()); |
393 if (!info_->HasDeoptimizationSupport()) return; | 401 if (!info_->HasDeoptimizationSupport()) return; |
394 int length = bailout_entries_.length(); | 402 int length = bailout_entries_.length(); |
395 Handle<DeoptimizationOutputData> data = isolate()->factory()-> | 403 Handle<DeoptimizationOutputData> data = isolate()->factory()-> |
396 NewDeoptimizationOutputData(length, TENURED); | 404 NewDeoptimizationOutputData(length, TENURED); |
397 for (int i = 0; i < length; i++) { | 405 for (int i = 0; i < length; i++) { |
398 data->SetAstId(i, bailout_entries_[i].id); | 406 data->SetAstId(i, bailout_entries_[i].id); |
399 data->SetPcAndState(i, Smi::FromInt(bailout_entries_[i].pc_and_state)); | 407 data->SetPcAndState(i, Smi::FromInt(bailout_entries_[i].pc_and_state)); |
400 } | 408 } |
401 code->set_deoptimization_data(*data); | 409 code->set_deoptimization_data(*data); |
402 } | 410 } |
403 | 411 |
404 | 412 |
405 void FullCodeGenerator::PopulateTypeFeedbackInfo(Handle<Code> code) { | 413 void FullCodeGenerator::PopulateTypeFeedbackInfo(Handle<Code> code) { |
406 Handle<TypeFeedbackInfo> info = isolate()->factory()->NewTypeFeedbackInfo(); | 414 Handle<TypeFeedbackInfo> info = isolate()->factory()->NewTypeFeedbackInfo(); |
407 info->set_ic_total_count(ic_total_count_); | 415 info->set_ic_total_count(ic_total_count_); |
| 416 info->set_feedback_vector(*FeedbackVector()); |
408 ASSERT(!isolate()->heap()->InNewSpace(*info)); | 417 ASSERT(!isolate()->heap()->InNewSpace(*info)); |
409 code->set_type_feedback_info(*info); | 418 code->set_type_feedback_info(*info); |
410 } | 419 } |
411 | 420 |
412 | 421 |
413 void FullCodeGenerator::Initialize() { | 422 void FullCodeGenerator::Initialize() { |
414 // The generation of debug code must match between the snapshot code and the | 423 // The generation of debug code must match between the snapshot code and the |
415 // code that is generated later. This is assumed by the debugger when it is | 424 // code that is generated later. This is assumed by the debugger when it is |
416 // calculating PC offsets after generating a debug version of code. Therefore | 425 // calculating PC offsets after generating a debug version of code. Therefore |
417 // we disable the production of debug code in the full compiler if we are | 426 // we disable the production of debug code in the full compiler if we are |
418 // either generating a snapshot or we booted from a snapshot. | 427 // either generating a snapshot or we booted from a snapshot. |
419 generate_debug_code_ = FLAG_debug_code && | 428 generate_debug_code_ = FLAG_debug_code && |
420 !Serializer::enabled() && | 429 !Serializer::enabled() && |
421 !Snapshot::HaveASnapshotToStartFrom(); | 430 !Snapshot::HaveASnapshotToStartFrom(); |
422 masm_->set_emit_debug_code(generate_debug_code_); | 431 masm_->set_emit_debug_code(generate_debug_code_); |
423 masm_->set_predictable_code_size(true); | 432 masm_->set_predictable_code_size(true); |
424 InitializeAstVisitor(info_->zone()); | 433 InitializeAstVisitor(info_->zone()); |
425 } | 434 } |
426 | 435 |
427 | 436 |
428 void FullCodeGenerator::PopulateTypeFeedbackCells(Handle<Code> code) { | |
429 if (type_feedback_cells_.is_empty()) return; | |
430 int length = type_feedback_cells_.length(); | |
431 int array_size = TypeFeedbackCells::LengthOfFixedArray(length); | |
432 Handle<TypeFeedbackCells> cache = Handle<TypeFeedbackCells>::cast( | |
433 isolate()->factory()->NewFixedArray(array_size, TENURED)); | |
434 for (int i = 0; i < length; i++) { | |
435 cache->SetAstId(i, type_feedback_cells_[i].ast_id); | |
436 cache->SetCell(i, *type_feedback_cells_[i].cell); | |
437 } | |
438 TypeFeedbackInfo::cast(code->type_feedback_info())->set_type_feedback_cells( | |
439 *cache); | |
440 } | |
441 | |
442 | |
443 void FullCodeGenerator::PrepareForBailout(Expression* node, State state) { | 437 void FullCodeGenerator::PrepareForBailout(Expression* node, State state) { |
444 PrepareForBailoutForId(node->id(), state); | 438 PrepareForBailoutForId(node->id(), state); |
445 } | 439 } |
446 | 440 |
447 | 441 |
448 void FullCodeGenerator::CallLoadIC(ContextualMode contextual_mode, | 442 void FullCodeGenerator::CallLoadIC(ContextualMode contextual_mode, |
449 TypeFeedbackId id) { | 443 TypeFeedbackId id) { |
450 ExtraICState extra_state = LoadIC::ComputeExtraICState(contextual_mode); | 444 ExtraICState extra_state = LoadIC::ComputeExtraICState(contextual_mode); |
451 Handle<Code> ic = LoadIC::initialize_stub(isolate(), extra_state); | 445 Handle<Code> ic = LoadIC::initialize_stub(isolate(), extra_state); |
452 CallIC(ic, contextual_mode, id); | 446 CallIC(ic, contextual_mode, id); |
(...skipping 30 matching lines...) Expand all Loading... |
483 unsigned pc_and_state = | 477 unsigned pc_and_state = |
484 StateField::encode(state) | PcField::encode(masm_->pc_offset()); | 478 StateField::encode(state) | PcField::encode(masm_->pc_offset()); |
485 ASSERT(Smi::IsValid(pc_and_state)); | 479 ASSERT(Smi::IsValid(pc_and_state)); |
486 BailoutEntry entry = { id, pc_and_state }; | 480 BailoutEntry entry = { id, pc_and_state }; |
487 ASSERT(!prepared_bailout_ids_.Contains(id.ToInt())); | 481 ASSERT(!prepared_bailout_ids_.Contains(id.ToInt())); |
488 prepared_bailout_ids_.Add(id.ToInt(), zone()); | 482 prepared_bailout_ids_.Add(id.ToInt(), zone()); |
489 bailout_entries_.Add(entry, zone()); | 483 bailout_entries_.Add(entry, zone()); |
490 } | 484 } |
491 | 485 |
492 | 486 |
493 void FullCodeGenerator::RecordTypeFeedbackCell( | |
494 TypeFeedbackId id, Handle<Cell> cell) { | |
495 TypeFeedbackCellEntry entry = { id, cell }; | |
496 type_feedback_cells_.Add(entry, zone()); | |
497 } | |
498 | |
499 | |
500 void FullCodeGenerator::RecordBackEdge(BailoutId ast_id) { | 487 void FullCodeGenerator::RecordBackEdge(BailoutId ast_id) { |
501 // The pc offset does not need to be encoded and packed together with a state. | 488 // The pc offset does not need to be encoded and packed together with a state. |
502 ASSERT(masm_->pc_offset() > 0); | 489 ASSERT(masm_->pc_offset() > 0); |
503 ASSERT(loop_depth() > 0); | 490 ASSERT(loop_depth() > 0); |
504 uint8_t depth = Min(loop_depth(), Code::kMaxLoopNestingMarker); | 491 uint8_t depth = Min(loop_depth(), Code::kMaxLoopNestingMarker); |
505 BackEdgeEntry entry = | 492 BackEdgeEntry entry = |
506 { ast_id, static_cast<unsigned>(masm_->pc_offset()), depth }; | 493 { ast_id, static_cast<unsigned>(masm_->pc_offset()), depth }; |
507 back_edges_.Add(entry, zone()); | 494 back_edges_.Add(entry, zone()); |
508 } | 495 } |
509 | 496 |
(...skipping 1231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1741 } | 1728 } |
1742 return true; | 1729 return true; |
1743 } | 1730 } |
1744 #endif // DEBUG | 1731 #endif // DEBUG |
1745 | 1732 |
1746 | 1733 |
1747 #undef __ | 1734 #undef __ |
1748 | 1735 |
1749 | 1736 |
1750 } } // namespace v8::internal | 1737 } } // namespace v8::internal |
OLD | NEW |