| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 14 matching lines...) Expand all Loading... |
| 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" | 28 #include "v8.h" |
| 29 | 29 |
| 30 #if defined(V8_TARGET_ARCH_IA32) | 30 #if defined(V8_TARGET_ARCH_IA32) |
| 31 | 31 |
| 32 #include "bootstrapper.h" | 32 #include "bootstrapper.h" |
| 33 #include "codegen.h" | 33 #include "codegen.h" |
| 34 #include "debug.h" | 34 #include "debug.h" |
| 35 #include "macro-assembler-ia32-inl.h" | |
| 36 #include "runtime.h" | 35 #include "runtime.h" |
| 37 #include "serialize.h" | 36 #include "serialize.h" |
| 38 | 37 |
| 39 namespace v8 { | 38 namespace v8 { |
| 40 namespace internal { | 39 namespace internal { |
| 41 | 40 |
| 42 // ------------------------------------------------------------------------- | 41 // ------------------------------------------------------------------------- |
| 43 // MacroAssembler implementation. | 42 // MacroAssembler implementation. |
| 44 | 43 |
| 45 MacroAssembler::MacroAssembler(Isolate* arg_isolate, void* buffer, int size) | 44 MacroAssembler::MacroAssembler(Isolate* arg_isolate, void* buffer, int size) |
| (...skipping 2196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2242 CodePatcher::~CodePatcher() { | 2241 CodePatcher::~CodePatcher() { |
| 2243 // Indicate that code has changed. | 2242 // Indicate that code has changed. |
| 2244 CPU::FlushICache(address_, size_); | 2243 CPU::FlushICache(address_, size_); |
| 2245 | 2244 |
| 2246 // Check that the code was patched as expected. | 2245 // Check that the code was patched as expected. |
| 2247 ASSERT(masm_.pc_ == address_ + size_); | 2246 ASSERT(masm_.pc_ == address_ + size_); |
| 2248 ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); | 2247 ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); |
| 2249 } | 2248 } |
| 2250 | 2249 |
| 2251 | 2250 |
| 2251 void MacroAssembler::CheckPageFlag( |
| 2252 Register object, |
| 2253 Register scratch, |
| 2254 MemoryChunk::MemoryChunkFlags flag, |
| 2255 Condition cc, |
| 2256 Label* condition_met, |
| 2257 Label::Distance condition_met_near) { |
| 2258 ASSERT(cc == zero || cc == not_zero); |
| 2259 if (scratch.is(object)) { |
| 2260 and_(scratch, Immediate(~Page::kPageAlignmentMask)); |
| 2261 } else { |
| 2262 mov(scratch, Immediate(~Page::kPageAlignmentMask)); |
| 2263 and_(scratch, Operand(object)); |
| 2264 } |
| 2265 if (flag < kBitsPerByte) { |
| 2266 test_b(Operand(scratch, MemoryChunk::kFlagsOffset), |
| 2267 static_cast<uint8_t>(1u << flag)); |
| 2268 } else { |
| 2269 test(Operand(scratch, MemoryChunk::kFlagsOffset), Immediate(1 << flag)); |
| 2270 } |
| 2271 j(cc, condition_met, condition_met_near); |
| 2272 } |
| 2273 |
| 2274 |
| 2275 void MacroAssembler::IsBlack(Register object, |
| 2276 Register scratch0, |
| 2277 Register scratch1, |
| 2278 Label* is_black, |
| 2279 Label::Distance is_black_near) { |
| 2280 HasColour(object, scratch0, scratch1, |
| 2281 is_black, is_black_near, |
| 2282 1, 0); // kBlackBitPattern. |
| 2283 ASSERT(strcmp(Marking::kBlackBitPattern, "10") == 0); |
| 2284 } |
| 2285 |
| 2286 |
| 2287 void MacroAssembler::HasColour(Register object, |
| 2288 Register bitmap_scratch, |
| 2289 Register mask_scratch, |
| 2290 Label* has_colour, |
| 2291 Label::Distance has_colour_distance, |
| 2292 int first_bit, |
| 2293 int second_bit) { |
| 2294 ASSERT(!Aliasing(object, bitmap_scratch, mask_scratch, ecx)); |
| 2295 |
| 2296 MarkBits(object, bitmap_scratch, mask_scratch); |
| 2297 |
| 2298 Label other_colour, word_boundary; |
| 2299 test(mask_scratch, Operand(bitmap_scratch, MemoryChunk::kHeaderSize)); |
| 2300 j(first_bit == 1 ? zero : not_zero, &other_colour, Label::kNear); |
| 2301 add(mask_scratch, Operand(mask_scratch)); // Shift left 1 by adding. |
| 2302 j(zero, &word_boundary, Label::kNear); |
| 2303 test(mask_scratch, Operand(bitmap_scratch, MemoryChunk::kHeaderSize)); |
| 2304 j(second_bit == 1 ? not_zero : zero, has_colour, has_colour_distance); |
| 2305 jmp(&other_colour, Label::kNear); |
| 2306 |
| 2307 bind(&word_boundary); |
| 2308 test_b(Operand(bitmap_scratch, MemoryChunk::kHeaderSize + kPointerSize), 1); |
| 2309 |
| 2310 j(second_bit == 1 ? not_zero : zero, has_colour, has_colour_distance); |
| 2311 bind(&other_colour); |
| 2312 } |
| 2313 |
| 2314 |
| 2315 void MacroAssembler::IsDataObject(Register value, |
| 2316 Register scratch, |
| 2317 Label* not_data_object, |
| 2318 Label::Distance not_data_object_distance, |
| 2319 bool in_new_space) { |
| 2320 if (in_new_space) { |
| 2321 Label is_data_object; |
| 2322 mov(scratch, FieldOperand(value, HeapObject::kMapOffset)); |
| 2323 cmp(scratch, FACTORY->heap_number_map()); |
| 2324 j(equal, &is_data_object, Label::kNear); |
| 2325 ASSERT(kConsStringTag == 1 && kIsConsStringMask == 1); |
| 2326 ASSERT(kNotStringTag == 0x80 && kIsNotStringMask == 0x80); |
| 2327 // If it's a string and it's not a cons string then it's an object that |
| 2328 // doesn't need scanning. |
| 2329 test_b(FieldOperand(scratch, Map::kInstanceTypeOffset), |
| 2330 kIsConsStringMask | kIsNotStringMask); |
| 2331 // Jump if we need to mark it grey and push it. |
| 2332 j(not_zero, not_data_object, not_data_object_distance); |
| 2333 bind(&is_data_object); |
| 2334 } else { |
| 2335 mov(scratch, Operand(value)); |
| 2336 and_(scratch, ~Page::kPageAlignmentMask); |
| 2337 test_b(Operand(scratch, MemoryChunk::kFlagsOffset), |
| 2338 1 << MemoryChunk::CONTAINS_ONLY_DATA); |
| 2339 // Jump if we need to mark it grey and push it. |
| 2340 j(zero, not_data_object, not_data_object_distance); |
| 2341 } |
| 2342 } |
| 2343 |
| 2344 |
| 2345 void MacroAssembler::MarkBits(Register addr_reg, |
| 2346 Register bitmap_reg, |
| 2347 Register mask_reg) { |
| 2348 ASSERT(!Aliasing(addr_reg, bitmap_reg, mask_reg, ecx)); |
| 2349 mov(bitmap_reg, Operand(addr_reg)); |
| 2350 and_(bitmap_reg, ~Page::kPageAlignmentMask); |
| 2351 mov(ecx, Operand(addr_reg)); |
| 2352 shr(ecx, Bitmap::kBitsPerCellLog2); |
| 2353 and_(ecx, |
| 2354 (Page::kPageAlignmentMask >> Bitmap::kBitsPerCellLog2) & |
| 2355 ~(kPointerSize - 1)); |
| 2356 |
| 2357 add(bitmap_reg, Operand(ecx)); |
| 2358 mov(ecx, Operand(addr_reg)); |
| 2359 shr(ecx, kPointerSizeLog2); |
| 2360 and_(ecx, (1 << Bitmap::kBitsPerCellLog2) - 1); |
| 2361 mov(mask_reg, Immediate(1)); |
| 2362 shl_cl(mask_reg); |
| 2363 } |
| 2364 |
| 2365 |
| 2366 void MacroAssembler::EnsureNotWhite( |
| 2367 Register value, |
| 2368 Register bitmap_scratch, |
| 2369 Register mask_scratch, |
| 2370 Label* value_is_white_and_not_data, |
| 2371 Label::Distance distance, |
| 2372 bool in_new_space) { |
| 2373 ASSERT(!Aliasing(value, bitmap_scratch, mask_scratch, ecx)); |
| 2374 MarkBits(value, bitmap_scratch, mask_scratch); |
| 2375 |
| 2376 // If the value is black or grey we don't need to do anything. |
| 2377 ASSERT(strcmp(Marking::kWhiteBitPattern, "00") == 0); |
| 2378 ASSERT(strcmp(Marking::kBlackBitPattern, "10") == 0); |
| 2379 ASSERT(strcmp(Marking::kGreyBitPattern, "11") == 0); |
| 2380 ASSERT(strcmp(Marking::kImpossibleBitPattern, "01") == 0); |
| 2381 |
| 2382 Label done; |
| 2383 |
| 2384 // Since both black and grey have a 1 in the first position and white does |
| 2385 // not have a 1 there we only need to check one bit. |
| 2386 test(mask_scratch, Operand(bitmap_scratch, MemoryChunk::kHeaderSize)); |
| 2387 j(not_zero, &done, Label::kNear); |
| 2388 |
| 2389 if (FLAG_debug_code) { |
| 2390 // Check for impossible bit pattern. |
| 2391 Label ok; |
| 2392 push(mask_scratch); |
| 2393 // shl. May overflow making the check conservative. |
| 2394 add(mask_scratch, Operand(mask_scratch)); |
| 2395 test(mask_scratch, Operand(bitmap_scratch, MemoryChunk::kHeaderSize)); |
| 2396 j(zero, &ok, Label::kNear); |
| 2397 int3(); |
| 2398 bind(&ok); |
| 2399 pop(mask_scratch); |
| 2400 } |
| 2401 |
| 2402 // Value is white. We check whether it is data that doesn't need scanning. |
| 2403 IsDataObject(value, ecx, value_is_white_and_not_data, distance, in_new_space); |
| 2404 |
| 2405 // Value is a data object, and it is white. Mark it black. Since we know |
| 2406 // that the object is white we can make it black by flipping one bit. |
| 2407 or_(Operand(bitmap_scratch, MemoryChunk::kHeaderSize), mask_scratch); |
| 2408 bind(&done); |
| 2409 } |
| 2410 |
| 2252 } } // namespace v8::internal | 2411 } } // namespace v8::internal |
| 2253 | 2412 |
| 2254 #endif // V8_TARGET_ARCH_IA32 | 2413 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |