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

Side by Side Diff: src/safepoint-table.cc

Issue 6577036: [Isolates] Merge from bleeding_edge to isolates, revisions 6100-6300. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/isolates/
Patch Set: '' Created 9 years, 10 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
« no previous file with comments | « src/safepoint-table.h ('k') | src/scanner.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #include "v8.h"
29
28 #include "safepoint-table.h" 30 #include "safepoint-table.h"
31
29 #include "disasm.h" 32 #include "disasm.h"
33 #include "macro-assembler.h"
34 #include "zone-inl.h"
30 35
31 namespace v8 { 36 namespace v8 {
32 namespace internal { 37 namespace internal {
33 38
39
40 bool SafepointEntry::HasRegisters() const {
41 ASSERT(is_valid());
42 ASSERT(IsAligned(kNumSafepointRegisters, kBitsPerByte));
43 const int num_reg_bytes = kNumSafepointRegisters >> kBitsPerByteLog2;
44 for (int i = 0; i < num_reg_bytes; i++) {
45 if (bits_[i] != SafepointTable::kNoRegisters) return true;
46 }
47 return false;
48 }
49
50
51 bool SafepointEntry::HasRegisterAt(int reg_index) const {
52 ASSERT(is_valid());
53 ASSERT(reg_index >= 0 && reg_index < kNumSafepointRegisters);
54 int byte_index = reg_index >> kBitsPerByteLog2;
55 int bit_index = reg_index & (kBitsPerByte - 1);
56 return (bits_[byte_index] & (1 << bit_index)) != 0;
57 }
58
59
34 SafepointTable::SafepointTable(Code* code) { 60 SafepointTable::SafepointTable(Code* code) {
35 ASSERT(code->kind() == Code::OPTIMIZED_FUNCTION); 61 ASSERT(code->kind() == Code::OPTIMIZED_FUNCTION);
36 code_ = code; 62 code_ = code;
37 Address header = code->instruction_start() + code->safepoint_table_start(); 63 Address header = code->instruction_start() + code->safepoint_table_start();
38 length_ = Memory::uint32_at(header + kLengthOffset); 64 length_ = Memory::uint32_at(header + kLengthOffset);
39 entry_size_ = Memory::uint32_at(header + kEntrySizeOffset); 65 entry_size_ = Memory::uint32_at(header + kEntrySizeOffset);
40 pc_and_deoptimization_indexes_ = header + kHeaderSize; 66 pc_and_deoptimization_indexes_ = header + kHeaderSize;
41 entries_ = pc_and_deoptimization_indexes_ + 67 entries_ = pc_and_deoptimization_indexes_ +
42 (length_ * kPcAndDeoptimizationIndexSize); 68 (length_ * kPcAndDeoptimizationIndexSize);
43 ASSERT(entry_size_ > 0); 69 ASSERT(entry_size_ > 0);
44 ASSERT_EQ(DeoptimizationIndexField::max(), Safepoint::kNoDeoptimizationIndex); 70 ASSERT_EQ(SafepointEntry::DeoptimizationIndexField::max(),
71 Safepoint::kNoDeoptimizationIndex);
45 } 72 }
46 73
47 74
48 bool SafepointTable::HasRegisters(uint8_t* entry) { 75 SafepointEntry SafepointTable::FindEntry(Address pc) const {
49 ASSERT(IsAligned(kNumSafepointRegisters, kBitsPerByte)); 76 unsigned pc_offset = static_cast<unsigned>(pc - code_->instruction_start());
50 const int num_reg_bytes = kNumSafepointRegisters >> kBitsPerByteLog2; 77 for (unsigned i = 0; i < length(); i++) {
51 for (int i = 0; i < num_reg_bytes; i++) { 78 // TODO(kasperl): Replace the linear search with binary search.
52 if (entry[i] != kNoRegisters) return true; 79 if (GetPcOffset(i) == pc_offset) return GetEntry(i);
53 } 80 }
54 return false; 81 return SafepointEntry();
55 }
56
57
58 bool SafepointTable::HasRegisterAt(uint8_t* entry, int reg_index) {
59 ASSERT(reg_index >= 0 && reg_index < kNumSafepointRegisters);
60 int byte_index = reg_index >> kBitsPerByteLog2;
61 int bit_index = reg_index & (kBitsPerByte - 1);
62 return (entry[byte_index] & (1 << bit_index)) != 0;
63 } 82 }
64 83
65 84
66 void SafepointTable::PrintEntry(unsigned index) const { 85 void SafepointTable::PrintEntry(unsigned index) const {
67 disasm::NameConverter converter; 86 disasm::NameConverter converter;
68 uint8_t* entry = GetEntry(index); 87 SafepointEntry entry = GetEntry(index);
88 uint8_t* bits = entry.bits();
69 89
70 // Print the stack slot bits. 90 // Print the stack slot bits.
71 if (entry_size_ > 0) { 91 if (entry_size_ > 0) {
72 ASSERT(IsAligned(kNumSafepointRegisters, kBitsPerByte)); 92 ASSERT(IsAligned(kNumSafepointRegisters, kBitsPerByte));
73 const int first = kNumSafepointRegisters >> kBitsPerByteLog2; 93 const int first = kNumSafepointRegisters >> kBitsPerByteLog2;
74 int last = entry_size_ - 1; 94 int last = entry_size_ - 1;
75 for (int i = first; i < last; i++) PrintBits(entry[i], kBitsPerByte); 95 for (int i = first; i < last; i++) PrintBits(bits[i], kBitsPerByte);
76 int last_bits = code_->stack_slots() - ((last - first) * kBitsPerByte); 96 int last_bits = code_->stack_slots() - ((last - first) * kBitsPerByte);
77 PrintBits(entry[last], last_bits); 97 PrintBits(bits[last], last_bits);
78 98
79 // Print the registers (if any). 99 // Print the registers (if any).
80 if (!HasRegisters(entry)) return; 100 if (!entry.HasRegisters()) return;
81 for (int j = 0; j < kNumSafepointRegisters; j++) { 101 for (int j = 0; j < kNumSafepointRegisters; j++) {
82 if (HasRegisterAt(entry, j)) { 102 if (entry.HasRegisterAt(j)) {
83 PrintF(" | %s", converter.NameOfCPURegister(j)); 103 PrintF(" | %s", converter.NameOfCPURegister(j));
84 } 104 }
85 } 105 }
86 } 106 }
87 } 107 }
88 108
89 109
90 void SafepointTable::PrintBits(uint8_t byte, int digits) { 110 void SafepointTable::PrintBits(uint8_t byte, int digits) {
91 ASSERT(digits >= 0 && digits <= kBitsPerByte); 111 ASSERT(digits >= 0 && digits <= kBitsPerByte);
92 for (int i = 0; i < digits; i++) { 112 for (int i = 0; i < digits; i++) {
93 PrintF("%c", ((byte & (1 << i)) == 0) ? '0' : '1'); 113 PrintF("%c", ((byte & (1 << i)) == 0) ? '0' : '1');
94 } 114 }
95 } 115 }
96 116
97 117
118 void Safepoint::DefinePointerRegister(Register reg) {
119 registers_->Add(reg.code());
120 }
121
122
98 Safepoint SafepointTableBuilder::DefineSafepoint(Assembler* assembler, 123 Safepoint SafepointTableBuilder::DefineSafepoint(Assembler* assembler,
99 int deoptimization_index) { 124 int deoptimization_index) {
100 ASSERT(deoptimization_index != -1); 125 ASSERT(deoptimization_index != -1);
101 DeoptimizationInfo pc_and_deoptimization_index; 126 DeoptimizationInfo pc_and_deoptimization_index;
102 pc_and_deoptimization_index.pc = assembler->pc_offset(); 127 pc_and_deoptimization_index.pc = assembler->pc_offset();
103 pc_and_deoptimization_index.deoptimization_index = deoptimization_index; 128 pc_and_deoptimization_index.deoptimization_index = deoptimization_index;
104 pc_and_deoptimization_index.pc_after_gap = assembler->pc_offset(); 129 pc_and_deoptimization_index.pc_after_gap = assembler->pc_offset();
130 pc_and_deoptimization_index.arguments = 0;
105 deoptimization_info_.Add(pc_and_deoptimization_index); 131 deoptimization_info_.Add(pc_and_deoptimization_index);
106 indexes_.Add(new ZoneList<int>(8)); 132 indexes_.Add(new ZoneList<int>(8));
107 registers_.Add(NULL); 133 registers_.Add(NULL);
108 return Safepoint(indexes_.last(), registers_.last()); 134 return Safepoint(indexes_.last(), registers_.last());
109 } 135 }
110 136
111 137
112 Safepoint SafepointTableBuilder::DefineSafepointWithRegisters( 138 Safepoint SafepointTableBuilder::DefineSafepointWithRegisters(
113 Assembler* assembler, int arguments, int deoptimization_index) { 139 Assembler* assembler, int arguments, int deoptimization_index) {
114 ASSERT(deoptimization_index != -1); 140 ASSERT(deoptimization_index != -1);
115 ASSERT(arguments == 0); // Only case that works for now. 141 ASSERT(arguments >= 0);
116 DeoptimizationInfo pc_and_deoptimization_index; 142 DeoptimizationInfo pc_and_deoptimization_index;
117 pc_and_deoptimization_index.pc = assembler->pc_offset(); 143 pc_and_deoptimization_index.pc = assembler->pc_offset();
118 pc_and_deoptimization_index.deoptimization_index = deoptimization_index; 144 pc_and_deoptimization_index.deoptimization_index = deoptimization_index;
119 pc_and_deoptimization_index.pc_after_gap = assembler->pc_offset(); 145 pc_and_deoptimization_index.pc_after_gap = assembler->pc_offset();
146 pc_and_deoptimization_index.arguments = arguments;
120 deoptimization_info_.Add(pc_and_deoptimization_index); 147 deoptimization_info_.Add(pc_and_deoptimization_index);
121 indexes_.Add(new ZoneList<int>(8)); 148 indexes_.Add(new ZoneList<int>(8));
122 registers_.Add(new ZoneList<int>(4)); 149 registers_.Add(new ZoneList<int>(4));
123 return Safepoint(indexes_.last(), registers_.last()); 150 return Safepoint(indexes_.last(), registers_.last());
124 } 151 }
125 152
126 153
127 unsigned SafepointTableBuilder::GetCodeOffset() const { 154 unsigned SafepointTableBuilder::GetCodeOffset() const {
128 ASSERT(emitted_); 155 ASSERT(emitted_);
129 return offset_; 156 return offset_;
(...skipping 15 matching lines...) Expand all
145 172
146 // Emit the table header. 173 // Emit the table header.
147 int length = deoptimization_info_.length(); 174 int length = deoptimization_info_.length();
148 assembler->dd(length); 175 assembler->dd(length);
149 assembler->dd(bytes_per_entry); 176 assembler->dd(bytes_per_entry);
150 177
151 // Emit sorted table of pc offsets together with deoptimization indexes and 178 // Emit sorted table of pc offsets together with deoptimization indexes and
152 // pc after gap information. 179 // pc after gap information.
153 for (int i = 0; i < length; i++) { 180 for (int i = 0; i < length; i++) {
154 assembler->dd(deoptimization_info_[i].pc); 181 assembler->dd(deoptimization_info_[i].pc);
155 assembler->dd(EncodeDeoptimizationIndexAndGap(deoptimization_info_[i])); 182 assembler->dd(EncodeExceptPC(deoptimization_info_[i]));
156 } 183 }
157 184
158 // Emit table of bitmaps. 185 // Emit table of bitmaps.
159 ZoneList<uint8_t> bits(bytes_per_entry); 186 ZoneList<uint8_t> bits(bytes_per_entry);
160 for (int i = 0; i < length; i++) { 187 for (int i = 0; i < length; i++) {
161 ZoneList<int>* indexes = indexes_[i]; 188 ZoneList<int>* indexes = indexes_[i];
162 ZoneList<int>* registers = registers_[i]; 189 ZoneList<int>* registers = registers_[i];
163 bits.Clear(); 190 bits.Clear();
164 bits.AddBlock(0, bytes_per_entry); 191 bits.AddBlock(0, bytes_per_entry);
165 192
(...skipping 24 matching lines...) Expand all
190 217
191 // Emit the bitmap for the current entry. 218 // Emit the bitmap for the current entry.
192 for (int k = 0; k < bytes_per_entry; k++) { 219 for (int k = 0; k < bytes_per_entry; k++) {
193 assembler->db(bits[k]); 220 assembler->db(bits[k]);
194 } 221 }
195 } 222 }
196 emitted_ = true; 223 emitted_ = true;
197 } 224 }
198 225
199 226
200 uint32_t SafepointTableBuilder::EncodeDeoptimizationIndexAndGap( 227 uint32_t SafepointTableBuilder::EncodeExceptPC(const DeoptimizationInfo& info) {
201 DeoptimizationInfo info) {
202 unsigned index = info.deoptimization_index; 228 unsigned index = info.deoptimization_index;
203 unsigned gap_size = info.pc_after_gap - info.pc; 229 unsigned gap_size = info.pc_after_gap - info.pc;
204 uint32_t encoding = SafepointTable::DeoptimizationIndexField::encode(index); 230 uint32_t encoding = SafepointEntry::DeoptimizationIndexField::encode(index);
205 encoding |= SafepointTable::GapCodeSizeField::encode(gap_size); 231 encoding |= SafepointEntry::GapCodeSizeField::encode(gap_size);
232 encoding |= SafepointEntry::ArgumentsField::encode(info.arguments);
206 return encoding; 233 return encoding;
207 } 234 }
208 235
209 236
210 } } // namespace v8::internal 237 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/safepoint-table.h ('k') | src/scanner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698