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

Side by Side Diff: src/objects-inl.h

Issue 7527001: Encapsulate element handling into a class keyed on ElementsKind (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: merge with tot Created 9 years, 4 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 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 17 matching lines...) Expand all
28 // Review notes: 28 // Review notes:
29 // 29 //
30 // - The use of macros in these inline functions may seem superfluous 30 // - The use of macros in these inline functions may seem superfluous
31 // but it is absolutely needed to make sure gcc generates optimal 31 // but it is absolutely needed to make sure gcc generates optimal
32 // code. gcc is not happy when attempting to inline too deep. 32 // code. gcc is not happy when attempting to inline too deep.
33 // 33 //
34 34
35 #ifndef V8_OBJECTS_INL_H_ 35 #ifndef V8_OBJECTS_INL_H_
36 #define V8_OBJECTS_INL_H_ 36 #define V8_OBJECTS_INL_H_
37 37
38 #include "elements.h"
38 #include "objects.h" 39 #include "objects.h"
39 #include "contexts.h" 40 #include "contexts.h"
40 #include "conversions-inl.h" 41 #include "conversions-inl.h"
41 #include "heap.h" 42 #include "heap.h"
42 #include "isolate.h" 43 #include "isolate.h"
43 #include "property.h" 44 #include "property.h"
44 #include "spaces.h" 45 #include "spaces.h"
45 #include "v8memory.h" 46 #include "v8memory.h"
46 47
47 namespace v8 { 48 namespace v8 {
(...skipping 1580 matching lines...) Expand 10 before | Expand all | Expand 10 after
1628 } 1629 }
1629 1630
1630 1631
1631 inline double FixedDoubleArray::canonical_not_the_hole_nan_as_double() { 1632 inline double FixedDoubleArray::canonical_not_the_hole_nan_as_double() {
1632 ASSERT(BitCast<uint64_t>(OS::nan_value()) != kHoleNanInt64); 1633 ASSERT(BitCast<uint64_t>(OS::nan_value()) != kHoleNanInt64);
1633 ASSERT((BitCast<uint64_t>(OS::nan_value()) >> 32) != kHoleNanUpper32); 1634 ASSERT((BitCast<uint64_t>(OS::nan_value()) >> 32) != kHoleNanUpper32);
1634 return OS::nan_value(); 1635 return OS::nan_value();
1635 } 1636 }
1636 1637
1637 1638
1638 double FixedDoubleArray::get(int index) { 1639 double FixedDoubleArray::get_scalar(int index) {
1639 ASSERT(map() != HEAP->fixed_cow_array_map() && 1640 ASSERT(map() != HEAP->fixed_cow_array_map() &&
1640 map() != HEAP->fixed_array_map()); 1641 map() != HEAP->fixed_array_map());
1641 ASSERT(index >= 0 && index < this->length()); 1642 ASSERT(index >= 0 && index < this->length());
1642 double result = READ_DOUBLE_FIELD(this, kHeaderSize + index * kDoubleSize); 1643 double result = READ_DOUBLE_FIELD(this, kHeaderSize + index * kDoubleSize);
1643 ASSERT(!is_the_hole_nan(result)); 1644 ASSERT(!is_the_hole_nan(result));
1644 return result; 1645 return result;
1645 } 1646 }
1646 1647
1647 1648
1649 MaybeObject* FixedDoubleArray::get(int index) {
1650 if (is_the_hole(index)) {
1651 return GetHeap()->the_hole_value();
1652 } else {
1653 return GetHeap()->NumberFromDouble(get_scalar(index));
1654 }
1655 }
1656
1657
1648 void FixedDoubleArray::set(int index, double value) { 1658 void FixedDoubleArray::set(int index, double value) {
1649 ASSERT(map() != HEAP->fixed_cow_array_map() && 1659 ASSERT(map() != HEAP->fixed_cow_array_map() &&
1650 map() != HEAP->fixed_array_map()); 1660 map() != HEAP->fixed_array_map());
1651 int offset = kHeaderSize + index * kDoubleSize; 1661 int offset = kHeaderSize + index * kDoubleSize;
1652 if (isnan(value)) value = canonical_not_the_hole_nan_as_double(); 1662 if (isnan(value)) value = canonical_not_the_hole_nan_as_double();
1653 WRITE_DOUBLE_FIELD(this, offset, value); 1663 WRITE_DOUBLE_FIELD(this, offset, value);
1654 } 1664 }
1655 1665
1656 1666
1657 void FixedDoubleArray::set_the_hole(int index) { 1667 void FixedDoubleArray::set_the_hole(int index) {
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after
2362 Address ByteArray::GetDataStartAddress() { 2372 Address ByteArray::GetDataStartAddress() {
2363 return reinterpret_cast<Address>(this) - kHeapObjectTag + kHeaderSize; 2373 return reinterpret_cast<Address>(this) - kHeapObjectTag + kHeaderSize;
2364 } 2374 }
2365 2375
2366 2376
2367 uint8_t* ExternalPixelArray::external_pixel_pointer() { 2377 uint8_t* ExternalPixelArray::external_pixel_pointer() {
2368 return reinterpret_cast<uint8_t*>(external_pointer()); 2378 return reinterpret_cast<uint8_t*>(external_pointer());
2369 } 2379 }
2370 2380
2371 2381
2372 uint8_t ExternalPixelArray::get(int index) { 2382 uint8_t ExternalPixelArray::get_scalar(int index) {
2373 ASSERT((index >= 0) && (index < this->length())); 2383 ASSERT((index >= 0) && (index < this->length()));
2374 uint8_t* ptr = external_pixel_pointer(); 2384 uint8_t* ptr = external_pixel_pointer();
2375 return ptr[index]; 2385 return ptr[index];
2376 } 2386 }
2377 2387
2378 2388
2389 MaybeObject* ExternalPixelArray::get(int index) {
2390 return Smi::FromInt(static_cast<int>(get_scalar(index)));
2391 }
2392
2393
2379 void ExternalPixelArray::set(int index, uint8_t value) { 2394 void ExternalPixelArray::set(int index, uint8_t value) {
2380 ASSERT((index >= 0) && (index < this->length())); 2395 ASSERT((index >= 0) && (index < this->length()));
2381 uint8_t* ptr = external_pixel_pointer(); 2396 uint8_t* ptr = external_pixel_pointer();
2382 ptr[index] = value; 2397 ptr[index] = value;
2383 } 2398 }
2384 2399
2385 2400
2386 void* ExternalArray::external_pointer() { 2401 void* ExternalArray::external_pointer() {
2387 intptr_t ptr = READ_INTPTR_FIELD(this, kExternalPointerOffset); 2402 intptr_t ptr = READ_INTPTR_FIELD(this, kExternalPointerOffset);
2388 return reinterpret_cast<void*>(ptr); 2403 return reinterpret_cast<void*>(ptr);
2389 } 2404 }
2390 2405
2391 2406
2392 void ExternalArray::set_external_pointer(void* value, WriteBarrierMode mode) { 2407 void ExternalArray::set_external_pointer(void* value, WriteBarrierMode mode) {
2393 intptr_t ptr = reinterpret_cast<intptr_t>(value); 2408 intptr_t ptr = reinterpret_cast<intptr_t>(value);
2394 WRITE_INTPTR_FIELD(this, kExternalPointerOffset, ptr); 2409 WRITE_INTPTR_FIELD(this, kExternalPointerOffset, ptr);
2395 } 2410 }
2396 2411
2397 2412
2398 int8_t ExternalByteArray::get(int index) { 2413 int8_t ExternalByteArray::get_scalar(int index) {
2399 ASSERT((index >= 0) && (index < this->length())); 2414 ASSERT((index >= 0) && (index < this->length()));
2400 int8_t* ptr = static_cast<int8_t*>(external_pointer()); 2415 int8_t* ptr = static_cast<int8_t*>(external_pointer());
2401 return ptr[index]; 2416 return ptr[index];
2402 } 2417 }
2403 2418
2404 2419
2420 MaybeObject* ExternalByteArray::get(int index) {
2421 return Smi::FromInt(static_cast<int>(get_scalar(index)));
2422 }
2423
2424
2405 void ExternalByteArray::set(int index, int8_t value) { 2425 void ExternalByteArray::set(int index, int8_t value) {
2406 ASSERT((index >= 0) && (index < this->length())); 2426 ASSERT((index >= 0) && (index < this->length()));
2407 int8_t* ptr = static_cast<int8_t*>(external_pointer()); 2427 int8_t* ptr = static_cast<int8_t*>(external_pointer());
2408 ptr[index] = value; 2428 ptr[index] = value;
2409 } 2429 }
2410 2430
2411 2431
2412 uint8_t ExternalUnsignedByteArray::get(int index) { 2432 uint8_t ExternalUnsignedByteArray::get_scalar(int index) {
2413 ASSERT((index >= 0) && (index < this->length())); 2433 ASSERT((index >= 0) && (index < this->length()));
2414 uint8_t* ptr = static_cast<uint8_t*>(external_pointer()); 2434 uint8_t* ptr = static_cast<uint8_t*>(external_pointer());
2415 return ptr[index]; 2435 return ptr[index];
2416 } 2436 }
2417 2437
2418 2438
2439 MaybeObject* ExternalUnsignedByteArray::get(int index) {
2440 return Smi::FromInt(static_cast<int>(get_scalar(index)));
2441 }
2442
2443
2419 void ExternalUnsignedByteArray::set(int index, uint8_t value) { 2444 void ExternalUnsignedByteArray::set(int index, uint8_t value) {
2420 ASSERT((index >= 0) && (index < this->length())); 2445 ASSERT((index >= 0) && (index < this->length()));
2421 uint8_t* ptr = static_cast<uint8_t*>(external_pointer()); 2446 uint8_t* ptr = static_cast<uint8_t*>(external_pointer());
2422 ptr[index] = value; 2447 ptr[index] = value;
2423 } 2448 }
2424 2449
2425 2450
2426 int16_t ExternalShortArray::get(int index) { 2451 int16_t ExternalShortArray::get_scalar(int index) {
2427 ASSERT((index >= 0) && (index < this->length())); 2452 ASSERT((index >= 0) && (index < this->length()));
2428 int16_t* ptr = static_cast<int16_t*>(external_pointer()); 2453 int16_t* ptr = static_cast<int16_t*>(external_pointer());
2429 return ptr[index]; 2454 return ptr[index];
2430 } 2455 }
2431 2456
2432 2457
2458 MaybeObject* ExternalShortArray::get(int index) {
2459 return Smi::FromInt(static_cast<int>(get_scalar(index)));
2460 }
2461
2462
2433 void ExternalShortArray::set(int index, int16_t value) { 2463 void ExternalShortArray::set(int index, int16_t value) {
2434 ASSERT((index >= 0) && (index < this->length())); 2464 ASSERT((index >= 0) && (index < this->length()));
2435 int16_t* ptr = static_cast<int16_t*>(external_pointer()); 2465 int16_t* ptr = static_cast<int16_t*>(external_pointer());
2436 ptr[index] = value; 2466 ptr[index] = value;
2437 } 2467 }
2438 2468
2439 2469
2440 uint16_t ExternalUnsignedShortArray::get(int index) { 2470 uint16_t ExternalUnsignedShortArray::get_scalar(int index) {
2441 ASSERT((index >= 0) && (index < this->length())); 2471 ASSERT((index >= 0) && (index < this->length()));
2442 uint16_t* ptr = static_cast<uint16_t*>(external_pointer()); 2472 uint16_t* ptr = static_cast<uint16_t*>(external_pointer());
2443 return ptr[index]; 2473 return ptr[index];
2444 } 2474 }
2445 2475
2446 2476
2477 MaybeObject* ExternalUnsignedShortArray::get(int index) {
2478 return Smi::FromInt(static_cast<int>(get_scalar(index)));
2479 }
2480
2481
2447 void ExternalUnsignedShortArray::set(int index, uint16_t value) { 2482 void ExternalUnsignedShortArray::set(int index, uint16_t value) {
2448 ASSERT((index >= 0) && (index < this->length())); 2483 ASSERT((index >= 0) && (index < this->length()));
2449 uint16_t* ptr = static_cast<uint16_t*>(external_pointer()); 2484 uint16_t* ptr = static_cast<uint16_t*>(external_pointer());
2450 ptr[index] = value; 2485 ptr[index] = value;
2451 } 2486 }
2452 2487
2453 2488
2454 int32_t ExternalIntArray::get(int index) { 2489 int32_t ExternalIntArray::get_scalar(int index) {
2455 ASSERT((index >= 0) && (index < this->length())); 2490 ASSERT((index >= 0) && (index < this->length()));
2456 int32_t* ptr = static_cast<int32_t*>(external_pointer()); 2491 int32_t* ptr = static_cast<int32_t*>(external_pointer());
2457 return ptr[index]; 2492 return ptr[index];
2458 } 2493 }
2459 2494
2460 2495
2496 MaybeObject* ExternalIntArray::get(int index) {
2497 return GetHeap()->NumberFromInt32(get_scalar(index));
2498 }
2499
2500
2461 void ExternalIntArray::set(int index, int32_t value) { 2501 void ExternalIntArray::set(int index, int32_t value) {
2462 ASSERT((index >= 0) && (index < this->length())); 2502 ASSERT((index >= 0) && (index < this->length()));
2463 int32_t* ptr = static_cast<int32_t*>(external_pointer()); 2503 int32_t* ptr = static_cast<int32_t*>(external_pointer());
2464 ptr[index] = value; 2504 ptr[index] = value;
2465 } 2505 }
2466 2506
2467 2507
2468 uint32_t ExternalUnsignedIntArray::get(int index) { 2508 uint32_t ExternalUnsignedIntArray::get_scalar(int index) {
2469 ASSERT((index >= 0) && (index < this->length())); 2509 ASSERT((index >= 0) && (index < this->length()));
2470 uint32_t* ptr = static_cast<uint32_t*>(external_pointer()); 2510 uint32_t* ptr = static_cast<uint32_t*>(external_pointer());
2471 return ptr[index]; 2511 return ptr[index];
2472 } 2512 }
2473 2513
2474 2514
2515 MaybeObject* ExternalUnsignedIntArray::get(int index) {
2516 return GetHeap()->NumberFromUint32(get_scalar(index));
2517 }
2518
2519
2475 void ExternalUnsignedIntArray::set(int index, uint32_t value) { 2520 void ExternalUnsignedIntArray::set(int index, uint32_t value) {
2476 ASSERT((index >= 0) && (index < this->length())); 2521 ASSERT((index >= 0) && (index < this->length()));
2477 uint32_t* ptr = static_cast<uint32_t*>(external_pointer()); 2522 uint32_t* ptr = static_cast<uint32_t*>(external_pointer());
2478 ptr[index] = value; 2523 ptr[index] = value;
2479 } 2524 }
2480 2525
2481 2526
2482 float ExternalFloatArray::get(int index) { 2527 float ExternalFloatArray::get_scalar(int index) {
2483 ASSERT((index >= 0) && (index < this->length())); 2528 ASSERT((index >= 0) && (index < this->length()));
2484 float* ptr = static_cast<float*>(external_pointer()); 2529 float* ptr = static_cast<float*>(external_pointer());
2485 return ptr[index]; 2530 return ptr[index];
2486 } 2531 }
2487 2532
2488 2533
2534 MaybeObject* ExternalFloatArray::get(int index) {
2535 return GetHeap()->NumberFromDouble(get_scalar(index));
2536 }
2537
2538
2489 void ExternalFloatArray::set(int index, float value) { 2539 void ExternalFloatArray::set(int index, float value) {
2490 ASSERT((index >= 0) && (index < this->length())); 2540 ASSERT((index >= 0) && (index < this->length()));
2491 float* ptr = static_cast<float*>(external_pointer()); 2541 float* ptr = static_cast<float*>(external_pointer());
2492 ptr[index] = value; 2542 ptr[index] = value;
2493 } 2543 }
2494 2544
2495 2545
2496 double ExternalDoubleArray::get(int index) { 2546 double ExternalDoubleArray::get_scalar(int index) {
2497 ASSERT((index >= 0) && (index < this->length())); 2547 ASSERT((index >= 0) && (index < this->length()));
2498 double* ptr = static_cast<double*>(external_pointer()); 2548 double* ptr = static_cast<double*>(external_pointer());
2499 return ptr[index]; 2549 return ptr[index];
2500 } 2550 }
2501 2551
2502 2552
2553 MaybeObject* ExternalDoubleArray::get(int index) {
2554 return GetHeap()->NumberFromDouble(get_scalar(index));
2555 }
2556
2557
2503 void ExternalDoubleArray::set(int index, double value) { 2558 void ExternalDoubleArray::set(int index, double value) {
2504 ASSERT((index >= 0) && (index < this->length())); 2559 ASSERT((index >= 0) && (index < this->length()));
2505 double* ptr = static_cast<double*>(external_pointer()); 2560 double* ptr = static_cast<double*>(external_pointer());
2506 ptr[index] = value; 2561 ptr[index] = value;
2507 } 2562 }
2508 2563
2509 2564
2510 int Map::visitor_id() { 2565 int Map::visitor_id() {
2511 return READ_BYTE_FIELD(this, kVisitorIdOffset); 2566 return READ_BYTE_FIELD(this, kVisitorIdOffset);
2512 } 2567 }
(...skipping 1461 matching lines...) Expand 10 before | Expand all | Expand 10 after
3974 (kind == FAST_DOUBLE_ELEMENTS && 4029 (kind == FAST_DOUBLE_ELEMENTS &&
3975 elements()->IsFixedDoubleArray()) || 4030 elements()->IsFixedDoubleArray()) ||
3976 (kind == DICTIONARY_ELEMENTS && 4031 (kind == DICTIONARY_ELEMENTS &&
3977 elements()->IsFixedArray() && 4032 elements()->IsFixedArray() &&
3978 elements()->IsDictionary()) || 4033 elements()->IsDictionary()) ||
3979 (kind > DICTIONARY_ELEMENTS)); 4034 (kind > DICTIONARY_ELEMENTS));
3980 return kind; 4035 return kind;
3981 } 4036 }
3982 4037
3983 4038
4039 ElementsAccessor* JSObject::GetElementsAccessor() {
4040 return ElementsAccessor::ForKind(GetElementsKind());
4041 }
4042
4043
3984 bool JSObject::HasFastElements() { 4044 bool JSObject::HasFastElements() {
3985 return GetElementsKind() == FAST_ELEMENTS; 4045 return GetElementsKind() == FAST_ELEMENTS;
3986 } 4046 }
3987 4047
3988 4048
3989 bool JSObject::HasFastDoubleElements() { 4049 bool JSObject::HasFastDoubleElements() {
3990 return GetElementsKind() == FAST_DOUBLE_ELEMENTS; 4050 return GetElementsKind() == FAST_DOUBLE_ELEMENTS;
3991 } 4051 }
3992 4052
3993 4053
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
4543 #undef WRITE_INT_FIELD 4603 #undef WRITE_INT_FIELD
4544 #undef READ_SHORT_FIELD 4604 #undef READ_SHORT_FIELD
4545 #undef WRITE_SHORT_FIELD 4605 #undef WRITE_SHORT_FIELD
4546 #undef READ_BYTE_FIELD 4606 #undef READ_BYTE_FIELD
4547 #undef WRITE_BYTE_FIELD 4607 #undef WRITE_BYTE_FIELD
4548 4608
4549 4609
4550 } } // namespace v8::internal 4610 } } // namespace v8::internal
4551 4611
4552 #endif // V8_OBJECTS_INL_H_ 4612 #endif // V8_OBJECTS_INL_H_
OLDNEW
« src/objects.cc ('K') | « src/objects-debug.cc ('k') | src/objects-printer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698