| 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 26 matching lines...) Expand all Loading... |
| 37 #include "prettyprinter.h" | 37 #include "prettyprinter.h" |
| 38 | 38 |
| 39 | 39 |
| 40 namespace v8 { | 40 namespace v8 { |
| 41 namespace internal { | 41 namespace internal { |
| 42 | 42 |
| 43 DeoptimizerData::DeoptimizerData() { | 43 DeoptimizerData::DeoptimizerData() { |
| 44 eager_deoptimization_entry_code_entries_ = -1; | 44 eager_deoptimization_entry_code_entries_ = -1; |
| 45 lazy_deoptimization_entry_code_entries_ = -1; | 45 lazy_deoptimization_entry_code_entries_ = -1; |
| 46 size_t deopt_table_size = Deoptimizer::GetMaxDeoptTableSize(); | 46 size_t deopt_table_size = Deoptimizer::GetMaxDeoptTableSize(); |
| 47 eager_deoptimization_entry_code_ = new VirtualMemory(deopt_table_size); | 47 MemoryAllocator* allocator = Isolate::Current()->memory_allocator(); |
| 48 lazy_deoptimization_entry_code_ = new VirtualMemory(deopt_table_size); | 48 size_t initial_commit_size = OS::CommitPageSize(); |
| 49 eager_deoptimization_entry_code_ = |
| 50 allocator->AllocateChunk(deopt_table_size, |
| 51 initial_commit_size, |
| 52 EXECUTABLE, |
| 53 NULL); |
| 54 lazy_deoptimization_entry_code_ = |
| 55 allocator->AllocateChunk(deopt_table_size, |
| 56 initial_commit_size, |
| 57 EXECUTABLE, |
| 58 NULL); |
| 49 current_ = NULL; | 59 current_ = NULL; |
| 50 deoptimizing_code_list_ = NULL; | 60 deoptimizing_code_list_ = NULL; |
| 51 #ifdef ENABLE_DEBUGGER_SUPPORT | 61 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 52 deoptimized_frame_info_ = NULL; | 62 deoptimized_frame_info_ = NULL; |
| 53 #endif | 63 #endif |
| 54 } | 64 } |
| 55 | 65 |
| 56 | 66 |
| 57 DeoptimizerData::~DeoptimizerData() { | 67 DeoptimizerData::~DeoptimizerData() { |
| 58 delete eager_deoptimization_entry_code_; | 68 Isolate::Current()->memory_allocator()->Free( |
| 69 eager_deoptimization_entry_code_); |
| 59 eager_deoptimization_entry_code_ = NULL; | 70 eager_deoptimization_entry_code_ = NULL; |
| 60 delete lazy_deoptimization_entry_code_; | 71 Isolate::Current()->memory_allocator()->Free( |
| 72 lazy_deoptimization_entry_code_); |
| 61 lazy_deoptimization_entry_code_ = NULL; | 73 lazy_deoptimization_entry_code_ = NULL; |
| 62 | 74 |
| 63 DeoptimizingCodeListNode* current = deoptimizing_code_list_; | 75 DeoptimizingCodeListNode* current = deoptimizing_code_list_; |
| 64 while (current != NULL) { | 76 while (current != NULL) { |
| 65 DeoptimizingCodeListNode* prev = current; | 77 DeoptimizingCodeListNode* prev = current; |
| 66 current = current->next(); | 78 current = current->next(); |
| 67 delete prev; | 79 delete prev; |
| 68 } | 80 } |
| 69 deoptimizing_code_list_ = NULL; | 81 deoptimizing_code_list_ = NULL; |
| 70 } | 82 } |
| (...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 output_ = NULL; | 622 output_ = NULL; |
| 611 ASSERT(!HEAP->allow_allocation(true)); | 623 ASSERT(!HEAP->allow_allocation(true)); |
| 612 } | 624 } |
| 613 | 625 |
| 614 | 626 |
| 615 Address Deoptimizer::GetDeoptimizationEntry(int id, | 627 Address Deoptimizer::GetDeoptimizationEntry(int id, |
| 616 BailoutType type, | 628 BailoutType type, |
| 617 GetEntryMode mode) { | 629 GetEntryMode mode) { |
| 618 ASSERT(id >= 0); | 630 ASSERT(id >= 0); |
| 619 if (id >= kMaxNumberOfEntries) return NULL; | 631 if (id >= kMaxNumberOfEntries) return NULL; |
| 620 VirtualMemory* base = NULL; | 632 MemoryChunk* base = NULL; |
| 621 if (mode == ENSURE_ENTRY_CODE) { | 633 if (mode == ENSURE_ENTRY_CODE) { |
| 622 EnsureCodeForDeoptimizationEntry(type, id); | 634 EnsureCodeForDeoptimizationEntry(type, id); |
| 623 } else { | 635 } else { |
| 624 ASSERT(mode == CALCULATE_ENTRY_ADDRESS); | 636 ASSERT(mode == CALCULATE_ENTRY_ADDRESS); |
| 625 } | 637 } |
| 626 DeoptimizerData* data = Isolate::Current()->deoptimizer_data(); | 638 DeoptimizerData* data = Isolate::Current()->deoptimizer_data(); |
| 627 if (type == EAGER) { | 639 if (type == EAGER) { |
| 628 base = data->eager_deoptimization_entry_code_; | 640 base = data->eager_deoptimization_entry_code_; |
| 629 } else { | 641 } else { |
| 630 base = data->lazy_deoptimization_entry_code_; | 642 base = data->lazy_deoptimization_entry_code_; |
| 631 } | 643 } |
| 632 return | 644 return base->area_start() + (id * table_entry_size_); |
| 633 static_cast<Address>(base->address()) + (id * table_entry_size_); | |
| 634 } | 645 } |
| 635 | 646 |
| 636 | 647 |
| 637 int Deoptimizer::GetDeoptimizationId(Address addr, BailoutType type) { | 648 int Deoptimizer::GetDeoptimizationId(Address addr, BailoutType type) { |
| 638 VirtualMemory* base = NULL; | 649 MemoryChunk* base = NULL; |
| 639 DeoptimizerData* data = Isolate::Current()->deoptimizer_data(); | 650 DeoptimizerData* data = Isolate::Current()->deoptimizer_data(); |
| 640 if (type == EAGER) { | 651 if (type == EAGER) { |
| 641 base = data->eager_deoptimization_entry_code_; | 652 base = data->eager_deoptimization_entry_code_; |
| 642 } else { | 653 } else { |
| 643 base = data->lazy_deoptimization_entry_code_; | 654 base = data->lazy_deoptimization_entry_code_; |
| 644 } | 655 } |
| 645 Address base_casted = reinterpret_cast<Address>(base->address()); | 656 Address start = base->area_start(); |
| 646 if (base == NULL || | 657 if (base == NULL || |
| 647 addr < base->address() || | 658 addr < start || |
| 648 addr >= base_casted + (kMaxNumberOfEntries * table_entry_size_)) { | 659 addr >= start + (kMaxNumberOfEntries * table_entry_size_)) { |
| 649 return kNotDeoptimizationEntry; | 660 return kNotDeoptimizationEntry; |
| 650 } | 661 } |
| 651 ASSERT_EQ(0, | 662 ASSERT_EQ(0, |
| 652 static_cast<int>(addr - base_casted) % table_entry_size_); | 663 static_cast<int>(addr - start) % table_entry_size_); |
| 653 return static_cast<int>(addr - base_casted) / table_entry_size_; | 664 return static_cast<int>(addr - start) / table_entry_size_; |
| 654 } | 665 } |
| 655 | 666 |
| 656 | 667 |
| 657 int Deoptimizer::GetOutputInfo(DeoptimizationOutputData* data, | 668 int Deoptimizer::GetOutputInfo(DeoptimizationOutputData* data, |
| 658 BailoutId id, | 669 BailoutId id, |
| 659 SharedFunctionInfo* shared) { | 670 SharedFunctionInfo* shared) { |
| 660 // TODO(kasperl): For now, we do a simple linear search for the PC | 671 // TODO(kasperl): For now, we do a simple linear search for the PC |
| 661 // offset associated with the given node id. This should probably be | 672 // offset associated with the given node id. This should probably be |
| 662 // changed to a binary search. | 673 // changed to a binary search. |
| 663 int length = data->DeoptPoints(); | 674 int length = data->DeoptPoints(); |
| (...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1562 entry_count = Max(entry_count, Deoptimizer::kMinNumberOfEntries); | 1573 entry_count = Max(entry_count, Deoptimizer::kMinNumberOfEntries); |
| 1563 while (max_entry_id >= entry_count) entry_count *= 2; | 1574 while (max_entry_id >= entry_count) entry_count *= 2; |
| 1564 ASSERT(entry_count <= Deoptimizer::kMaxNumberOfEntries); | 1575 ASSERT(entry_count <= Deoptimizer::kMaxNumberOfEntries); |
| 1565 | 1576 |
| 1566 MacroAssembler masm(Isolate::Current(), NULL, 16 * KB); | 1577 MacroAssembler masm(Isolate::Current(), NULL, 16 * KB); |
| 1567 masm.set_emit_debug_code(false); | 1578 masm.set_emit_debug_code(false); |
| 1568 GenerateDeoptimizationEntries(&masm, entry_count, type); | 1579 GenerateDeoptimizationEntries(&masm, entry_count, type); |
| 1569 CodeDesc desc; | 1580 CodeDesc desc; |
| 1570 masm.GetCode(&desc); | 1581 masm.GetCode(&desc); |
| 1571 | 1582 |
| 1572 VirtualMemory* memory = type == EAGER | 1583 MemoryChunk* chunk = type == EAGER |
| 1573 ? data->eager_deoptimization_entry_code_ | 1584 ? data->eager_deoptimization_entry_code_ |
| 1574 : data->lazy_deoptimization_entry_code_; | 1585 : data->lazy_deoptimization_entry_code_; |
| 1575 size_t table_size = Deoptimizer::GetMaxDeoptTableSize(); | 1586 size_t table_size = Deoptimizer::GetMaxDeoptTableSize(); |
| 1576 ASSERT(static_cast<int>(table_size) >= desc.instr_size); | 1587 ASSERT(static_cast<int>(table_size) >= desc.instr_size); |
| 1577 memory->Commit(memory->address(), table_size, true); | 1588 chunk->CommitBody(table_size, EXECUTABLE); |
| 1578 memcpy(memory->address(), desc.buffer, desc.instr_size); | 1589 memcpy(chunk->area_start(), desc.buffer, desc.instr_size); |
| 1579 CPU::FlushICache(memory->address(), desc.instr_size); | 1590 CPU::FlushICache(chunk->area_start(), desc.instr_size); |
| 1580 | 1591 |
| 1581 if (type == EAGER) { | 1592 if (type == EAGER) { |
| 1582 data->eager_deoptimization_entry_code_entries_ = entry_count; | 1593 data->eager_deoptimization_entry_code_entries_ = entry_count; |
| 1583 } else { | 1594 } else { |
| 1584 data->lazy_deoptimization_entry_code_entries_ = entry_count; | 1595 data->lazy_deoptimization_entry_code_entries_ = entry_count; |
| 1585 } | 1596 } |
| 1586 } | 1597 } |
| 1587 | 1598 |
| 1588 | 1599 |
| 1589 void Deoptimizer::ReplaceCodeForRelatedFunctions(JSFunction* function, | 1600 void Deoptimizer::ReplaceCodeForRelatedFunctions(JSFunction* function, |
| (...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2111 | 2122 |
| 2112 void DeoptimizedFrameInfo::Iterate(ObjectVisitor* v) { | 2123 void DeoptimizedFrameInfo::Iterate(ObjectVisitor* v) { |
| 2113 v->VisitPointer(BitCast<Object**>(&function_)); | 2124 v->VisitPointer(BitCast<Object**>(&function_)); |
| 2114 v->VisitPointers(parameters_, parameters_ + parameters_count_); | 2125 v->VisitPointers(parameters_, parameters_ + parameters_count_); |
| 2115 v->VisitPointers(expression_stack_, expression_stack_ + expression_count_); | 2126 v->VisitPointers(expression_stack_, expression_stack_ + expression_count_); |
| 2116 } | 2127 } |
| 2117 | 2128 |
| 2118 #endif // ENABLE_DEBUGGER_SUPPORT | 2129 #endif // ENABLE_DEBUGGER_SUPPORT |
| 2119 | 2130 |
| 2120 } } // namespace v8::internal | 2131 } } // namespace v8::internal |
| OLD | NEW |