Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(873)

Side by Side Diff: src/deoptimizer.cc

Issue 11566011: Use MemoryChunk-based allocation for deoptimization entry code (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 7 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 eager_deoptimization_entry_code_ = new VirtualMemory();
48 lazy_deoptimization_entry_code_ = new VirtualMemory(deopt_table_size); 48 lazy_deoptimization_entry_code_ = new VirtualMemory();
49 MemoryAllocator* allocator = Isolate::Current()->memory_allocator();
50 eager_deoptimization_entry_start_ = allocator->ReserveChunk(deopt_table_size,
danno 2012/12/28 11:58:37 Please don't store into a member variable and chan
haitao.feng 2012/12/28 15:04:54 In this CL, I am using eager_deoptimization_entry_
51 EXECUTABLE,
52 eager_deoptimization_entry_code_);
53 if (eager_deoptimization_entry_start_ == NULL) {
54 V8::FatalProcessOutOfMemory("Not enough memory for deoptimization table");
55 }
56 eager_deoptimization_entry_start_ +=
57 MemoryAllocator::CodePageAreaStartOffset();
58 lazy_deoptimization_entry_start_ = allocator->ReserveChunk(deopt_table_size,
59 EXECUTABLE,
60 lazy_deoptimization_entry_code_);
61 if (lazy_deoptimization_entry_start_ == NULL) {
62 V8::FatalProcessOutOfMemory("Not enough memory for deoptimization table");
63 }
64 lazy_deoptimization_entry_start_ +=
65 MemoryAllocator::CodePageAreaStartOffset();
66 eager_deoptimization_chunk_ = NULL;
67 lazy_deoptimization_chunk_ = NULL;
49 current_ = NULL; 68 current_ = NULL;
50 deoptimizing_code_list_ = NULL; 69 deoptimizing_code_list_ = NULL;
51 #ifdef ENABLE_DEBUGGER_SUPPORT 70 #ifdef ENABLE_DEBUGGER_SUPPORT
52 deoptimized_frame_info_ = NULL; 71 deoptimized_frame_info_ = NULL;
53 #endif 72 #endif
54 } 73 }
55 74
56 75
57 DeoptimizerData::~DeoptimizerData() { 76 DeoptimizerData::~DeoptimizerData() {
58 delete eager_deoptimization_entry_code_; 77 delete eager_deoptimization_entry_code_;
danno 2012/12/28 11:58:37 These must be destructed _after_ the memory chunks
haitao.feng 2012/12/28 15:04:54 When a trunk is returned, the trunk will take cont
danno 2012/12/28 15:38:10 I don't know what you mean by "trunk". The more I
59 eager_deoptimization_entry_code_ = NULL; 78 eager_deoptimization_entry_code_ = NULL;
60 delete lazy_deoptimization_entry_code_; 79 delete lazy_deoptimization_entry_code_;
61 lazy_deoptimization_entry_code_ = NULL; 80 lazy_deoptimization_entry_code_ = NULL;
81 if (eager_deoptimization_chunk_ != NULL) {
82 Isolate::Current()->memory_allocator()->Free(
83 eager_deoptimization_chunk_);
84 eager_deoptimization_chunk_ = NULL;
85 }
86 if (lazy_deoptimization_chunk_ != NULL) {
87 Isolate::Current()->memory_allocator()->Free(
88 lazy_deoptimization_chunk_);
89 lazy_deoptimization_chunk_ = NULL;
90 }
62 91
63 DeoptimizingCodeListNode* current = deoptimizing_code_list_; 92 DeoptimizingCodeListNode* current = deoptimizing_code_list_;
64 while (current != NULL) { 93 while (current != NULL) {
65 DeoptimizingCodeListNode* prev = current; 94 DeoptimizingCodeListNode* prev = current;
66 current = current->next(); 95 current = current->next();
67 delete prev; 96 delete prev;
68 } 97 }
69 deoptimizing_code_list_ = NULL; 98 deoptimizing_code_list_ = NULL;
70 } 99 }
71 100
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 output_ = NULL; 639 output_ = NULL;
611 ASSERT(!HEAP->allow_allocation(true)); 640 ASSERT(!HEAP->allow_allocation(true));
612 } 641 }
613 642
614 643
615 Address Deoptimizer::GetDeoptimizationEntry(int id, 644 Address Deoptimizer::GetDeoptimizationEntry(int id,
616 BailoutType type, 645 BailoutType type,
617 GetEntryMode mode) { 646 GetEntryMode mode) {
618 ASSERT(id >= 0); 647 ASSERT(id >= 0);
619 if (id >= kMaxNumberOfEntries) return NULL; 648 if (id >= kMaxNumberOfEntries) return NULL;
620 VirtualMemory* base = NULL; 649 Address base = NULL;
621 if (mode == ENSURE_ENTRY_CODE) { 650 if (mode == ENSURE_ENTRY_CODE) {
622 EnsureCodeForDeoptimizationEntry(type, id); 651 EnsureCodeForDeoptimizationEntry(type, id);
623 } else { 652 } else {
624 ASSERT(mode == CALCULATE_ENTRY_ADDRESS); 653 ASSERT(mode == CALCULATE_ENTRY_ADDRESS);
625 } 654 }
626 DeoptimizerData* data = Isolate::Current()->deoptimizer_data(); 655 DeoptimizerData* data = Isolate::Current()->deoptimizer_data();
627 if (type == EAGER) { 656 if (type == EAGER) {
628 base = data->eager_deoptimization_entry_code_; 657 base = data->eager_deoptimization_entry_start_;
629 } else { 658 } else {
630 base = data->lazy_deoptimization_entry_code_; 659 base = data->lazy_deoptimization_entry_start_;
631 } 660 }
632 return 661 return
633 static_cast<Address>(base->address()) + (id * table_entry_size_); 662 base + (id * table_entry_size_);
634 } 663 }
635 664
636 665
637 int Deoptimizer::GetDeoptimizationId(Address addr, BailoutType type) { 666 int Deoptimizer::GetDeoptimizationId(Address addr, BailoutType type) {
638 VirtualMemory* base = NULL; 667 Address base = NULL;
639 DeoptimizerData* data = Isolate::Current()->deoptimizer_data(); 668 DeoptimizerData* data = Isolate::Current()->deoptimizer_data();
640 if (type == EAGER) { 669 if (type == EAGER) {
641 base = data->eager_deoptimization_entry_code_; 670 base = data->eager_deoptimization_entry_start_;
642 } else { 671 } else {
643 base = data->lazy_deoptimization_entry_code_; 672 base = data->lazy_deoptimization_entry_start_;
644 } 673 }
645 Address base_casted = reinterpret_cast<Address>(base->address());
646 if (base == NULL || 674 if (base == NULL ||
647 addr < base->address() || 675 addr < base ||
648 addr >= base_casted + (kMaxNumberOfEntries * table_entry_size_)) { 676 addr >= base + (kMaxNumberOfEntries * table_entry_size_)) {
649 return kNotDeoptimizationEntry; 677 return kNotDeoptimizationEntry;
650 } 678 }
651 ASSERT_EQ(0, 679 ASSERT_EQ(0,
652 static_cast<int>(addr - base_casted) % table_entry_size_); 680 static_cast<int>(addr - base) % table_entry_size_);
653 return static_cast<int>(addr - base_casted) / table_entry_size_; 681 return static_cast<int>(addr - base) / table_entry_size_;
654 } 682 }
655 683
656 684
657 int Deoptimizer::GetOutputInfo(DeoptimizationOutputData* data, 685 int Deoptimizer::GetOutputInfo(DeoptimizationOutputData* data,
658 BailoutId id, 686 BailoutId id,
659 SharedFunctionInfo* shared) { 687 SharedFunctionInfo* shared) {
660 // TODO(kasperl): For now, we do a simple linear search for the PC 688 // 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 689 // offset associated with the given node id. This should probably be
662 // changed to a binary search. 690 // changed to a binary search.
663 int length = data->DeoptPoints(); 691 int length = data->DeoptPoints();
(...skipping 903 matching lines...) Expand 10 before | Expand all | Expand 10 after
1567 masm.set_emit_debug_code(false); 1595 masm.set_emit_debug_code(false);
1568 GenerateDeoptimizationEntries(&masm, entry_count, type); 1596 GenerateDeoptimizationEntries(&masm, entry_count, type);
1569 CodeDesc desc; 1597 CodeDesc desc;
1570 masm.GetCode(&desc); 1598 masm.GetCode(&desc);
1571 1599
1572 VirtualMemory* memory = type == EAGER 1600 VirtualMemory* memory = type == EAGER
1573 ? data->eager_deoptimization_entry_code_ 1601 ? data->eager_deoptimization_entry_code_
1574 : data->lazy_deoptimization_entry_code_; 1602 : data->lazy_deoptimization_entry_code_;
1575 size_t table_size = Deoptimizer::GetMaxDeoptTableSize(); 1603 size_t table_size = Deoptimizer::GetMaxDeoptTableSize();
1576 ASSERT(static_cast<int>(table_size) >= desc.instr_size); 1604 ASSERT(static_cast<int>(table_size) >= desc.instr_size);
1577 memory->Commit(memory->address(), table_size, true); 1605
1578 memcpy(memory->address(), desc.buffer, desc.instr_size); 1606 MemoryAllocator* allocator = Isolate::Current()->memory_allocator();
1579 CPU::FlushICache(memory->address(), desc.instr_size); 1607 MemoryChunk** chunk = type == EAGER
danno 2012/12/28 11:58:37 Can you please not use the conditional operator he
1608 ? &data->eager_deoptimization_chunk_
1609 : &data->lazy_deoptimization_chunk_;
1610 if (*chunk == NULL) {
danno 2012/12/28 11:58:37 I don't think this is right. If the deopt table gr
haitao.feng 2012/12/28 15:04:54 If I read the codes right, table_size is Deoptimiz
1611 *chunk = allocator->CommitChunk(table_size, EXECUTABLE, memory, NULL);
1612 if (*chunk == NULL) {
1613 V8::FatalProcessOutOfMemory("Not enough memory for deoptimization table");
1614 }
1615 }
1616 memcpy((*chunk)->area_start(), desc.buffer, desc.instr_size);
1617 CPU::FlushICache((*chunk)->area_start(), desc.instr_size);
1580 1618
1581 if (type == EAGER) { 1619 if (type == EAGER) {
1582 data->eager_deoptimization_entry_code_entries_ = entry_count; 1620 data->eager_deoptimization_entry_code_entries_ = entry_count;
1583 } else { 1621 } else {
1584 data->lazy_deoptimization_entry_code_entries_ = entry_count; 1622 data->lazy_deoptimization_entry_code_entries_ = entry_count;
1585 } 1623 }
1586 } 1624 }
1587 1625
1588 1626
1589 void Deoptimizer::ReplaceCodeForRelatedFunctions(JSFunction* function, 1627 void Deoptimizer::ReplaceCodeForRelatedFunctions(JSFunction* function,
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
2111 2149
2112 void DeoptimizedFrameInfo::Iterate(ObjectVisitor* v) { 2150 void DeoptimizedFrameInfo::Iterate(ObjectVisitor* v) {
2113 v->VisitPointer(BitCast<Object**>(&function_)); 2151 v->VisitPointer(BitCast<Object**>(&function_));
2114 v->VisitPointers(parameters_, parameters_ + parameters_count_); 2152 v->VisitPointers(parameters_, parameters_ + parameters_count_);
2115 v->VisitPointers(expression_stack_, expression_stack_ + expression_count_); 2153 v->VisitPointers(expression_stack_, expression_stack_ + expression_count_);
2116 } 2154 }
2117 2155
2118 #endif // ENABLE_DEBUGGER_SUPPORT 2156 #endif // ENABLE_DEBUGGER_SUPPORT
2119 2157
2120 } } // namespace v8::internal 2158 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698