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

Side by Side Diff: src/objects.h

Issue 10916336: Preallocate space in descriptor arrays. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: u Created 8 years, 3 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/factory.cc ('k') | src/objects.cc » ('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 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 2473 matching lines...) Expand 10 before | Expand all | Expand 10 after
2484 2484
2485 // Returns true for both shared empty_descriptor_array and for smis, which the 2485 // Returns true for both shared empty_descriptor_array and for smis, which the
2486 // map uses to encode additional bit fields when the descriptor array is not 2486 // map uses to encode additional bit fields when the descriptor array is not
2487 // yet used. 2487 // yet used.
2488 inline bool IsEmpty(); 2488 inline bool IsEmpty();
2489 2489
2490 // Returns the number of descriptors in the array. 2490 // Returns the number of descriptors in the array.
2491 int number_of_descriptors() { 2491 int number_of_descriptors() {
2492 ASSERT(length() >= kFirstIndex || IsEmpty()); 2492 ASSERT(length() >= kFirstIndex || IsEmpty());
2493 int len = length(); 2493 int len = length();
2494 return len <= kFirstIndex ? 0 : (len - kFirstIndex) / kDescriptorSize; 2494 return len == 0 ? 0 : Smi::cast(get(kDescriptorLengthIndex))->value();
2495 } 2495 }
2496 2496
2497 int number_of_descriptors_storage() {
2498 int len = length();
2499 return len == 0 ? 0 : (len - kFirstIndex) / kDescriptorSize;
2500 }
2501
2502 int NumberOfSlackDescriptors() {
2503 return number_of_descriptors_storage() - number_of_descriptors();
2504 }
2505
2506 inline void SetNumberOfDescriptors(int number_of_descriptors);
2497 inline int number_of_entries() { return number_of_descriptors(); } 2507 inline int number_of_entries() { return number_of_descriptors(); }
2498 2508
2499 bool HasEnumCache() { 2509 bool HasEnumCache() {
2500 return !IsEmpty() && !get(kEnumCacheIndex)->IsSmi(); 2510 return !IsEmpty() && !get(kEnumCacheIndex)->IsSmi();
2501 } 2511 }
2502 2512
2503 void CopyEnumCacheFrom(DescriptorArray* array) { 2513 void CopyEnumCacheFrom(DescriptorArray* array) {
2504 set(kEnumCacheIndex, array->get(kEnumCacheIndex)); 2514 set(kEnumCacheIndex, array->get(kEnumCacheIndex));
2505 } 2515 }
2506 2516
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2538 2548
2539 inline String* GetSortedKey(int descriptor_number); 2549 inline String* GetSortedKey(int descriptor_number);
2540 inline int GetSortedKeyIndex(int descriptor_number); 2550 inline int GetSortedKeyIndex(int descriptor_number);
2541 inline void SetSortedKey(int pointer, int descriptor_number); 2551 inline void SetSortedKey(int pointer, int descriptor_number);
2542 2552
2543 // Accessor for complete descriptor. 2553 // Accessor for complete descriptor.
2544 inline void Get(int descriptor_number, Descriptor* desc); 2554 inline void Get(int descriptor_number, Descriptor* desc);
2545 inline void Set(int descriptor_number, 2555 inline void Set(int descriptor_number,
2546 Descriptor* desc, 2556 Descriptor* desc,
2547 const WhitenessWitness&); 2557 const WhitenessWitness&);
2558 inline void Set(int descriptor_number, Descriptor* desc);
2559 inline void EraseDescriptor(Heap* heap, int descriptor_number);
2548 2560
2549 // Append automatically sets the enumeration index. This should only be used 2561 // Append automatically sets the enumeration index. This should only be used
2550 // to add descriptors in bulk at the end, followed by sorting the descriptor 2562 // to add descriptors in bulk at the end, followed by sorting the descriptor
2551 // array. 2563 // array.
2552 inline void Append(Descriptor* desc, 2564 inline void Append(Descriptor* desc, const WhitenessWitness&);
2553 const WhitenessWitness&, 2565 inline void Append(Descriptor* desc);
2554 int number_of_set_descriptors);
2555 2566
2556 // Transfer a complete descriptor from the src descriptor array to this 2567 // Transfer a complete descriptor from the src descriptor array to this
2557 // descriptor array. 2568 // descriptor array.
2558 void CopyFrom(int dst_index, 2569 void CopyFrom(int dst_index,
2559 DescriptorArray* src, 2570 DescriptorArray* src,
2560 int src_index, 2571 int src_index,
2561 const WhitenessWitness&); 2572 const WhitenessWitness&);
2562 2573
2563 MUST_USE_RESULT MaybeObject* CopyUpTo(int enumeration_index); 2574 MUST_USE_RESULT MaybeObject* CopyUpTo(int enumeration_index);
2564 2575
2565 // Sort the instance descriptors by the hash codes of their keys. 2576 // Sort the instance descriptors by the hash codes of their keys.
2566 void Sort(); 2577 void Sort();
2567 2578
2568 // Search the instance descriptors for given name. 2579 // Search the instance descriptors for given name.
2569 INLINE(int Search(String* name, int number_of_own_descriptors)); 2580 INLINE(int Search(String* name, int number_of_own_descriptors));
2570 2581
2571 // As the above, but uses DescriptorLookupCache and updates it when 2582 // As the above, but uses DescriptorLookupCache and updates it when
2572 // necessary. 2583 // necessary.
2573 INLINE(int SearchWithCache(String* name, Map* map)); 2584 INLINE(int SearchWithCache(String* name, Map* map));
2574 2585
2575 // Allocates a DescriptorArray, but returns the singleton 2586 // Allocates a DescriptorArray, but returns the singleton
2576 // empty descriptor array object if number_of_descriptors is 0. 2587 // empty descriptor array object if number_of_descriptors is 0.
2577 MUST_USE_RESULT static MaybeObject* Allocate(int number_of_descriptors); 2588 MUST_USE_RESULT static MaybeObject* Allocate(int number_of_descriptors,
2589 int slack = 0);
2578 2590
2579 // Casting. 2591 // Casting.
2580 static inline DescriptorArray* cast(Object* obj); 2592 static inline DescriptorArray* cast(Object* obj);
2581 2593
2582 // Constant for denoting key was not found. 2594 // Constant for denoting key was not found.
2583 static const int kNotFound = -1; 2595 static const int kNotFound = -1;
2584 2596
2585 static const int kEnumCacheIndex = 0; 2597 static const int kDescriptorLengthIndex = 0;
2586 static const int kFirstIndex = 1; 2598 static const int kEnumCacheIndex = 1;
2599 static const int kFirstIndex = 2;
2587 2600
2588 // The length of the "bridge" to the enum cache. 2601 // The length of the "bridge" to the enum cache.
2589 static const int kEnumCacheBridgeLength = 2; 2602 static const int kEnumCacheBridgeLength = 2;
2590 static const int kEnumCacheBridgeCacheIndex = 0; 2603 static const int kEnumCacheBridgeCacheIndex = 0;
2591 static const int kEnumCacheBridgeIndicesCacheIndex = 1; 2604 static const int kEnumCacheBridgeIndicesCacheIndex = 1;
2592 2605
2593 // Layout description. 2606 // Layout description.
2594 static const int kEnumCacheOffset = FixedArray::kHeaderSize; 2607 static const int kDescriptorLengthOffset = FixedArray::kHeaderSize;
2608 static const int kEnumCacheOffset = kDescriptorLengthOffset + kPointerSize;
2595 static const int kFirstOffset = kEnumCacheOffset + kPointerSize; 2609 static const int kFirstOffset = kEnumCacheOffset + kPointerSize;
2596 2610
2597 // Layout description for the bridge array. 2611 // Layout description for the bridge array.
2598 static const int kEnumCacheBridgeCacheOffset = FixedArray::kHeaderSize; 2612 static const int kEnumCacheBridgeCacheOffset = FixedArray::kHeaderSize;
2599 2613
2600 // Layout of descriptor. 2614 // Layout of descriptor.
2601 static const int kDescriptorKey = 0; 2615 static const int kDescriptorKey = 0;
2602 static const int kDescriptorDetails = 1; 2616 static const int kDescriptorDetails = 1;
2603 static const int kDescriptorValue = 2; 2617 static const int kDescriptorValue = 2;
2604 static const int kDescriptorSize = 3; 2618 static const int kDescriptorSize = 3;
(...skipping 2410 matching lines...) Expand 10 before | Expand all | Expand 10 after
5015 inline void ClearCodeCache(Heap* heap); 5029 inline void ClearCodeCache(Heap* heap);
5016 5030
5017 // Update code cache. 5031 // Update code cache.
5018 static void UpdateCodeCache(Handle<Map> map, 5032 static void UpdateCodeCache(Handle<Map> map,
5019 Handle<String> name, 5033 Handle<String> name,
5020 Handle<Code> code); 5034 Handle<Code> code);
5021 MUST_USE_RESULT MaybeObject* UpdateCodeCache(String* name, Code* code); 5035 MUST_USE_RESULT MaybeObject* UpdateCodeCache(String* name, Code* code);
5022 5036
5023 // Extend the descriptor array of the map with the list of descriptors. 5037 // Extend the descriptor array of the map with the list of descriptors.
5024 // In case of duplicates, the latest descriptor is used. 5038 // In case of duplicates, the latest descriptor is used.
5025 static void CopyAppendCallbackDescriptors(Handle<Map> map, 5039 static void AppendCallbackDescriptors(Handle<Map> map,
5026 Handle<Object> descriptors); 5040 Handle<Object> descriptors);
5041
5042 static void EnsureDescriptorSlack(Handle<Map> map, int slack);
5027 5043
5028 // Returns the found code or undefined if absent. 5044 // Returns the found code or undefined if absent.
5029 Object* FindInCodeCache(String* name, Code::Flags flags); 5045 Object* FindInCodeCache(String* name, Code::Flags flags);
5030 5046
5031 // Returns the non-negative index of the code object if it is in the 5047 // Returns the non-negative index of the code object if it is in the
5032 // cache and -1 otherwise. 5048 // cache and -1 otherwise.
5033 int IndexInCodeCache(Object* name, Code* code); 5049 int IndexInCodeCache(Object* name, Code* code);
5034 5050
5035 // Removes a code object from the code cache at the given index. 5051 // Removes a code object from the code cache at the given index.
5036 void RemoveFromCodeCache(String* name, Code* code, int index); 5052 void RemoveFromCodeCache(String* name, Code* code, int index);
(...skipping 3950 matching lines...) Expand 10 before | Expand all | Expand 10 after
8987 } else { 9003 } else {
8988 value &= ~(1 << bit_position); 9004 value &= ~(1 << bit_position);
8989 } 9005 }
8990 return value; 9006 return value;
8991 } 9007 }
8992 }; 9008 };
8993 9009
8994 } } // namespace v8::internal 9010 } } // namespace v8::internal
8995 9011
8996 #endif // V8_OBJECTS_H_ 9012 #endif // V8_OBJECTS_H_
OLDNEW
« no previous file with comments | « src/factory.cc ('k') | src/objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698