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 2411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2422 public: | 2422 public: |
2423 // Returns true for both shared empty_descriptor_array and for smis, which the | 2423 // Returns true for both shared empty_descriptor_array and for smis, which the |
2424 // map uses to encode additional bit fields when the descriptor array is not | 2424 // map uses to encode additional bit fields when the descriptor array is not |
2425 // yet used. | 2425 // yet used. |
2426 inline bool IsEmpty(); | 2426 inline bool IsEmpty(); |
2427 | 2427 |
2428 // Returns the number of descriptors in the array. | 2428 // Returns the number of descriptors in the array. |
2429 int number_of_descriptors() { | 2429 int number_of_descriptors() { |
2430 ASSERT(length() > kFirstIndex || IsEmpty()); | 2430 ASSERT(length() > kFirstIndex || IsEmpty()); |
2431 int len = length(); | 2431 int len = length(); |
2432 return len <= kFirstIndex ? 0 : len - kFirstIndex; | 2432 return len <= kFirstIndex ? 0 : (len - kFirstIndex) / kDescriptorSize; |
2433 } | 2433 } |
2434 | 2434 |
2435 int NextEnumerationIndex() { | 2435 int NextEnumerationIndex() { |
2436 if (IsEmpty()) return PropertyDetails::kInitialIndex; | 2436 if (IsEmpty()) return PropertyDetails::kInitialIndex; |
2437 Object* obj = get(kEnumerationIndexIndex); | 2437 Object* obj = get(kEnumerationIndexIndex); |
2438 if (obj->IsSmi()) { | 2438 if (obj->IsSmi()) { |
2439 return Smi::cast(obj)->value(); | 2439 return Smi::cast(obj)->value(); |
2440 } else { | 2440 } else { |
2441 Object* index = FixedArray::cast(obj)->get(kEnumCacheBridgeEnumIndex); | 2441 Object* index = FixedArray::cast(obj)->get(kEnumCacheBridgeEnumIndex); |
2442 return Smi::cast(index)->value(); | 2442 return Smi::cast(index)->value(); |
2443 } | 2443 } |
2444 } | 2444 } |
2445 | 2445 |
2446 // Set next enumeration index and flush any enum cache. | 2446 // Set next enumeration index and flush any enum cache. |
2447 void SetNextEnumerationIndex(int value) { | 2447 void SetNextEnumerationIndex(int value) { |
2448 if (!IsEmpty()) { | 2448 if (!IsEmpty()) { |
2449 set(kEnumerationIndexIndex, Smi::FromInt(value)); | 2449 set(kEnumerationIndexIndex, Smi::FromInt(value)); |
2450 } | 2450 } |
2451 } | 2451 } |
2452 bool HasEnumCache() { | 2452 bool HasEnumCache() { |
2453 return !IsEmpty() && !get(kEnumerationIndexIndex)->IsSmi(); | 2453 return !IsEmpty() && !get(kEnumerationIndexIndex)->IsSmi(); |
2454 } | 2454 } |
2455 | 2455 |
2456 Object* GetEnumCache() { | 2456 Object* GetEnumCache() { |
2457 ASSERT(HasEnumCache()); | 2457 ASSERT(HasEnumCache()); |
2458 FixedArray* bridge = FixedArray::cast(get(kEnumerationIndexIndex)); | 2458 FixedArray* bridge = FixedArray::cast(get(kEnumerationIndexIndex)); |
2459 return bridge->get(kEnumCacheBridgeCacheIndex); | 2459 return bridge->get(kEnumCacheBridgeCacheIndex); |
2460 } | 2460 } |
2461 | 2461 |
2462 Object** GetEnumCacheSlot() { | |
2463 ASSERT(HasEnumCache()); | |
2464 return HeapObject::RawField(reinterpret_cast<HeapObject*>(this), | |
2465 kEnumerationIndexOffset); | |
2466 } | |
2467 | |
2462 // TODO(1399): It should be possible to make room for bit_field3 in the map | 2468 // TODO(1399): It should be possible to make room for bit_field3 in the map |
2463 // without overloading the instance descriptors field in the map | 2469 // without overloading the instance descriptors field in the map |
2464 // (and storing it in the DescriptorArray when the map has one). | 2470 // (and storing it in the DescriptorArray when the map has one). |
2465 inline int bit_field3_storage(); | 2471 inline int bit_field3_storage(); |
2466 inline void set_bit_field3_storage(int value); | 2472 inline void set_bit_field3_storage(int value); |
2467 | 2473 |
2468 // Initialize or change the enum cache, | 2474 // Initialize or change the enum cache, |
2469 // using the supplied storage for the small "bridge". | 2475 // using the supplied storage for the small "bridge". |
2470 void SetEnumCache(FixedArray* bridge_storage, | 2476 void SetEnumCache(FixedArray* bridge_storage, |
2471 FixedArray* new_cache, | 2477 FixedArray* new_cache, |
2472 Object* new_index_cache); | 2478 Object* new_index_cache); |
2473 | 2479 |
2474 // Accessors for fetching instance descriptor at descriptor number. | 2480 // Accessors for fetching instance descriptor at descriptor number. |
2475 inline String* GetKey(int descriptor_number); | 2481 inline String* GetKey(int descriptor_number); |
2482 inline Object** GetKeySlot(int descriptor_number); | |
2476 inline Object* GetValue(int descriptor_number); | 2483 inline Object* GetValue(int descriptor_number); |
2484 inline Object** GetValueSlot(int descriptor_number); | |
2485 inline void SetNullValueUnchecked(int descriptor_number, Heap* heap); | |
2477 inline PropertyDetails GetDetails(int descriptor_number); | 2486 inline PropertyDetails GetDetails(int descriptor_number); |
2487 inline void SetDetailsUnchecked(int descriptor_number, Smi* value); | |
2488 | |
2489 inline Object* RawGetValue(int descriptor_number); | |
2490 inline PropertyDetails RawGetDetails(int descriptor_number); | |
2491 | |
2478 inline PropertyType GetType(int descriptor_number); | 2492 inline PropertyType GetType(int descriptor_number); |
2479 inline int GetFieldIndex(int descriptor_number); | 2493 inline int GetFieldIndex(int descriptor_number); |
2480 inline JSFunction* GetConstantFunction(int descriptor_number); | 2494 inline JSFunction* GetConstantFunction(int descriptor_number); |
2481 inline Object* GetCallbacksObject(int descriptor_number); | 2495 inline Object* GetCallbacksObject(int descriptor_number); |
2482 inline AccessorDescriptor* GetCallbacks(int descriptor_number); | 2496 inline AccessorDescriptor* GetCallbacks(int descriptor_number); |
2483 inline bool IsProperty(int descriptor_number); | 2497 inline bool IsProperty(int descriptor_number); |
2484 inline bool IsTransitionOnly(int descriptor_number); | 2498 inline bool IsTransitionOnly(int descriptor_number); |
2485 inline bool IsNullDescriptor(int descriptor_number); | 2499 inline bool IsNullDescriptor(int descriptor_number); |
2486 | 2500 |
2501 // WhitenessWitness is used to prove that a specific descriptor array is white | |
2502 // (unmarked), so potentially unique heap objects can be freely assigned | |
2503 // without potentially causing memory leaks. A witness is always | |
2504 // stack-allocated right after creating a descriptor array. By allocating a wi tness, | |
Florian Schneider
2012/05/22 16:53:09
Long line.
| |
2505 // incremental marking is globally disabled. The witness is then passed along | |
2506 // wherever needed to statically prove that the descriptor array is known to | |
2507 // be white. | |
2487 class WhitenessWitness { | 2508 class WhitenessWitness { |
2488 public: | 2509 public: |
2489 inline explicit WhitenessWitness(DescriptorArray* array); | 2510 inline explicit WhitenessWitness(DescriptorArray* array); |
2490 inline ~WhitenessWitness(); | 2511 inline ~WhitenessWitness(); |
2491 | 2512 |
2492 private: | 2513 private: |
2493 IncrementalMarking* marking_; | 2514 IncrementalMarking* marking_; |
2494 }; | 2515 }; |
2495 | 2516 |
2496 // Accessor for complete descriptor. | 2517 // Accessor for complete descriptor. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2560 // empty descriptor array object if number_of_descriptors is 0. | 2581 // empty descriptor array object if number_of_descriptors is 0. |
2561 MUST_USE_RESULT static MaybeObject* Allocate(int number_of_descriptors); | 2582 MUST_USE_RESULT static MaybeObject* Allocate(int number_of_descriptors); |
2562 | 2583 |
2563 // Casting. | 2584 // Casting. |
2564 static inline DescriptorArray* cast(Object* obj); | 2585 static inline DescriptorArray* cast(Object* obj); |
2565 | 2586 |
2566 // Constant for denoting key was not found. | 2587 // Constant for denoting key was not found. |
2567 static const int kNotFound = -1; | 2588 static const int kNotFound = -1; |
2568 | 2589 |
2569 static const int kBitField3StorageIndex = 0; | 2590 static const int kBitField3StorageIndex = 0; |
2570 static const int kContentArrayIndex = 1; | 2591 static const int kEnumerationIndexIndex = 1; |
2571 static const int kEnumerationIndexIndex = 2; | 2592 static const int kFirstIndex = 2; |
2572 static const int kFirstIndex = 3; | |
2573 | 2593 |
2574 // The length of the "bridge" to the enum cache. | 2594 // The length of the "bridge" to the enum cache. |
2575 static const int kEnumCacheBridgeLength = 3; | 2595 static const int kEnumCacheBridgeLength = 3; |
2576 static const int kEnumCacheBridgeEnumIndex = 0; | 2596 static const int kEnumCacheBridgeEnumIndex = 0; |
2577 static const int kEnumCacheBridgeCacheIndex = 1; | 2597 static const int kEnumCacheBridgeCacheIndex = 1; |
2578 static const int kEnumCacheBridgeIndicesCacheIndex = 2; | 2598 static const int kEnumCacheBridgeIndicesCacheIndex = 2; |
2579 | 2599 |
2580 // Layout description. | 2600 // Layout description. |
2581 static const int kBitField3StorageOffset = FixedArray::kHeaderSize; | 2601 static const int kBitField3StorageOffset = FixedArray::kHeaderSize; |
2582 static const int kContentArrayOffset = kBitField3StorageOffset + kPointerSize; | 2602 static const int kEnumerationIndexOffset = kBitField3StorageOffset + |
2583 static const int kEnumerationIndexOffset = kContentArrayOffset + kPointerSize; | 2603 kPointerSize; |
2584 static const int kFirstOffset = kEnumerationIndexOffset + kPointerSize; | 2604 static const int kFirstOffset = kEnumerationIndexOffset + kPointerSize; |
2585 | 2605 |
2586 // Layout description for the bridge array. | 2606 // Layout description for the bridge array. |
2587 static const int kEnumCacheBridgeEnumOffset = FixedArray::kHeaderSize; | 2607 static const int kEnumCacheBridgeEnumOffset = FixedArray::kHeaderSize; |
2588 static const int kEnumCacheBridgeCacheOffset = | 2608 static const int kEnumCacheBridgeCacheOffset = |
2589 kEnumCacheBridgeEnumOffset + kPointerSize; | 2609 kEnumCacheBridgeEnumOffset + kPointerSize; |
2590 | 2610 |
2611 // Layout of descriptor. | |
2612 static const int kDescriptorSize = 3; | |
Florian Schneider
2012/05/22 16:53:09
Maybe sort the constants for the layout by increas
| |
2613 static const int kDescriptorKey = 0; | |
2614 static const int kDescriptorDetails = 1; | |
2615 static const int kDescriptorValue = 2; | |
2616 | |
2591 #ifdef OBJECT_PRINT | 2617 #ifdef OBJECT_PRINT |
2592 // Print all the descriptors. | 2618 // Print all the descriptors. |
2593 inline void PrintDescriptors() { | 2619 inline void PrintDescriptors() { |
2594 PrintDescriptors(stdout); | 2620 PrintDescriptors(stdout); |
2595 } | 2621 } |
2596 void PrintDescriptors(FILE* out); | 2622 void PrintDescriptors(FILE* out); |
2597 #endif | 2623 #endif |
2598 | 2624 |
2599 #ifdef DEBUG | 2625 #ifdef DEBUG |
2600 // Is the descriptor array sorted and without duplicates? | 2626 // Is the descriptor array sorted and without duplicates? |
(...skipping 20 matching lines...) Expand all Loading... | |
2621 inline PropertyType type() { return descs_->GetType(index_); } | 2647 inline PropertyType type() { return descs_->GetType(index_); } |
2622 inline Object* GetCallbackObject() { return descs_->GetValue(index_); } | 2648 inline Object* GetCallbackObject() { return descs_->GetValue(index_); } |
2623 | 2649 |
2624 private: | 2650 private: |
2625 DescriptorArray* descs_; | 2651 DescriptorArray* descs_; |
2626 int index_; | 2652 int index_; |
2627 }; | 2653 }; |
2628 | 2654 |
2629 // Conversion from descriptor number to array indices. | 2655 // Conversion from descriptor number to array indices. |
2630 static int ToKeyIndex(int descriptor_number) { | 2656 static int ToKeyIndex(int descriptor_number) { |
2631 return descriptor_number+kFirstIndex; | 2657 return kFirstIndex + |
2658 (descriptor_number * kDescriptorSize) + | |
2659 kDescriptorKey; | |
2632 } | 2660 } |
2633 | 2661 |
2634 static int ToDetailsIndex(int descriptor_number) { | 2662 static int ToDetailsIndex(int descriptor_number) { |
2635 return (descriptor_number << 1) + 1; | 2663 return kFirstIndex + |
2664 (descriptor_number * kDescriptorSize) + | |
2665 kDescriptorDetails; | |
2636 } | 2666 } |
2637 | 2667 |
2638 static int ToValueIndex(int descriptor_number) { | 2668 static int ToValueIndex(int descriptor_number) { |
2639 return descriptor_number << 1; | 2669 return kFirstIndex + |
2670 (descriptor_number * kDescriptorSize) + | |
2671 kDescriptorValue; | |
2640 } | 2672 } |
2641 | 2673 |
2642 // Swap operation on FixedArray without using write barriers. | 2674 // Swap operation on FixedArray without using write barriers. |
2643 static inline void NoIncrementalWriteBarrierSwap( | 2675 static inline void NoIncrementalWriteBarrierSwap( |
2644 FixedArray* array, int first, int second); | 2676 FixedArray* array, int first, int second); |
2645 | 2677 |
2646 // Swap descriptor first and second. | 2678 // Swap descriptor first and second. |
2647 inline void NoIncrementalWriteBarrierSwapDescriptors( | 2679 inline void NoIncrementalWriteBarrierSwapDescriptors( |
2648 int first, int second); | 2680 int first, int second); |
2649 | 2681 |
2650 FixedArray* GetContentArray() { | |
2651 return FixedArray::cast(get(kContentArrayIndex)); | |
2652 } | |
2653 DISALLOW_IMPLICIT_CONSTRUCTORS(DescriptorArray); | 2682 DISALLOW_IMPLICIT_CONSTRUCTORS(DescriptorArray); |
2654 }; | 2683 }; |
2655 | 2684 |
2656 | 2685 |
2657 // HashTable is a subclass of FixedArray that implements a hash table | 2686 // HashTable is a subclass of FixedArray that implements a hash table |
2658 // that uses open addressing and quadratic probing. | 2687 // that uses open addressing and quadratic probing. |
2659 // | 2688 // |
2660 // In order for the quadratic probing to work, elements that have not | 2689 // In order for the quadratic probing to work, elements that have not |
2661 // yet been used and elements that have been deleted are | 2690 // yet been used and elements that have been deleted are |
2662 // distinguished. Probing continues when deleted elements are | 2691 // distinguished. Probing continues when deleted elements are |
(...skipping 5984 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8647 } else { | 8676 } else { |
8648 value &= ~(1 << bit_position); | 8677 value &= ~(1 << bit_position); |
8649 } | 8678 } |
8650 return value; | 8679 return value; |
8651 } | 8680 } |
8652 }; | 8681 }; |
8653 | 8682 |
8654 } } // namespace v8::internal | 8683 } } // namespace v8::internal |
8655 | 8684 |
8656 #endif // V8_OBJECTS_H_ | 8685 #endif // V8_OBJECTS_H_ |
OLD | NEW |