Chromium Code Reviews

Side by Side Diff: src/objects.h

Issue 101413006: Implement in-heap backing store for typed arrays. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Platform ports Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
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 368 matching lines...)
379 /* Object::IsExternalArray(). */ \ 379 /* Object::IsExternalArray(). */ \
380 V(EXTERNAL_BYTE_ARRAY_TYPE) \ 380 V(EXTERNAL_BYTE_ARRAY_TYPE) \
381 V(EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE) \ 381 V(EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE) \
382 V(EXTERNAL_SHORT_ARRAY_TYPE) \ 382 V(EXTERNAL_SHORT_ARRAY_TYPE) \
383 V(EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE) \ 383 V(EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE) \
384 V(EXTERNAL_INT_ARRAY_TYPE) \ 384 V(EXTERNAL_INT_ARRAY_TYPE) \
385 V(EXTERNAL_UNSIGNED_INT_ARRAY_TYPE) \ 385 V(EXTERNAL_UNSIGNED_INT_ARRAY_TYPE) \
386 V(EXTERNAL_FLOAT_ARRAY_TYPE) \ 386 V(EXTERNAL_FLOAT_ARRAY_TYPE) \
387 V(EXTERNAL_DOUBLE_ARRAY_TYPE) \ 387 V(EXTERNAL_DOUBLE_ARRAY_TYPE) \
388 V(EXTERNAL_PIXEL_ARRAY_TYPE) \ 388 V(EXTERNAL_PIXEL_ARRAY_TYPE) \
389 \
390 V(FIXED_INT8_ARRAY_TYPE) \
391 V(FIXED_UINT8_ARRAY_TYPE) \
392 V(FIXED_INT16_ARRAY_TYPE) \
393 V(FIXED_UINT16_ARRAY_TYPE) \
394 V(FIXED_INT32_ARRAY_TYPE) \
395 V(FIXED_UINT32_ARRAY_TYPE) \
396 V(FIXED_FLOAT32_ARRAY_TYPE) \
397 V(FIXED_FLOAT64_ARRAY_TYPE) \
398 V(FIXED_UINT8_CLAMPED_ARRAY_TYPE) \
399 \
389 V(FILLER_TYPE) \ 400 V(FILLER_TYPE) \
390 \ 401 \
391 V(DECLARED_ACCESSOR_DESCRIPTOR_TYPE) \ 402 V(DECLARED_ACCESSOR_DESCRIPTOR_TYPE) \
392 V(DECLARED_ACCESSOR_INFO_TYPE) \ 403 V(DECLARED_ACCESSOR_INFO_TYPE) \
393 V(EXECUTABLE_ACCESSOR_INFO_TYPE) \ 404 V(EXECUTABLE_ACCESSOR_INFO_TYPE) \
394 V(ACCESSOR_PAIR_TYPE) \ 405 V(ACCESSOR_PAIR_TYPE) \
395 V(ACCESS_CHECK_INFO_TYPE) \ 406 V(ACCESS_CHECK_INFO_TYPE) \
396 V(INTERCEPTOR_INFO_TYPE) \ 407 V(INTERCEPTOR_INFO_TYPE) \
397 V(CALL_HANDLER_INFO_TYPE) \ 408 V(CALL_HANDLER_INFO_TYPE) \
398 V(FUNCTION_TEMPLATE_INFO_TYPE) \ 409 V(FUNCTION_TEMPLATE_INFO_TYPE) \
(...skipping 314 matching lines...)
713 FREE_SPACE_TYPE, 724 FREE_SPACE_TYPE,
714 EXTERNAL_BYTE_ARRAY_TYPE, // FIRST_EXTERNAL_ARRAY_TYPE 725 EXTERNAL_BYTE_ARRAY_TYPE, // FIRST_EXTERNAL_ARRAY_TYPE
715 EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE, 726 EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE,
716 EXTERNAL_SHORT_ARRAY_TYPE, 727 EXTERNAL_SHORT_ARRAY_TYPE,
717 EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE, 728 EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE,
718 EXTERNAL_INT_ARRAY_TYPE, 729 EXTERNAL_INT_ARRAY_TYPE,
719 EXTERNAL_UNSIGNED_INT_ARRAY_TYPE, 730 EXTERNAL_UNSIGNED_INT_ARRAY_TYPE,
720 EXTERNAL_FLOAT_ARRAY_TYPE, 731 EXTERNAL_FLOAT_ARRAY_TYPE,
721 EXTERNAL_DOUBLE_ARRAY_TYPE, 732 EXTERNAL_DOUBLE_ARRAY_TYPE,
722 EXTERNAL_PIXEL_ARRAY_TYPE, // LAST_EXTERNAL_ARRAY_TYPE 733 EXTERNAL_PIXEL_ARRAY_TYPE, // LAST_EXTERNAL_ARRAY_TYPE
734
735 FIXED_INT8_ARRAY_TYPE, // FIRST_FIXED_TYPED_ARRAY_TYPE
736 FIXED_UINT8_ARRAY_TYPE,
737 FIXED_INT16_ARRAY_TYPE,
738 FIXED_UINT16_ARRAY_TYPE,
739 FIXED_INT32_ARRAY_TYPE,
740 FIXED_UINT32_ARRAY_TYPE,
741 FIXED_FLOAT32_ARRAY_TYPE,
742 FIXED_FLOAT64_ARRAY_TYPE,
743 FIXED_UINT8_CLAMPED_ARRAY_TYPE, // LAST_FIXED_TYPED_ARRAY_TYPE
744
723 FIXED_DOUBLE_ARRAY_TYPE, 745 FIXED_DOUBLE_ARRAY_TYPE,
724 FILLER_TYPE, // LAST_DATA_TYPE 746 FILLER_TYPE, // LAST_DATA_TYPE
725 747
726 // Structs. 748 // Structs.
727 DECLARED_ACCESSOR_DESCRIPTOR_TYPE, 749 DECLARED_ACCESSOR_DESCRIPTOR_TYPE,
728 DECLARED_ACCESSOR_INFO_TYPE, 750 DECLARED_ACCESSOR_INFO_TYPE,
729 EXECUTABLE_ACCESSOR_INFO_TYPE, 751 EXECUTABLE_ACCESSOR_INFO_TYPE,
730 ACCESSOR_PAIR_TYPE, 752 ACCESSOR_PAIR_TYPE,
731 ACCESS_CHECK_INFO_TYPE, 753 ACCESS_CHECK_INFO_TYPE,
732 INTERCEPTOR_INFO_TYPE, 754 INTERCEPTOR_INFO_TYPE,
(...skipping 57 matching lines...)
790 FIRST_TYPE = 0x0, 812 FIRST_TYPE = 0x0,
791 LAST_TYPE = JS_FUNCTION_TYPE, 813 LAST_TYPE = JS_FUNCTION_TYPE,
792 FIRST_NAME_TYPE = FIRST_TYPE, 814 FIRST_NAME_TYPE = FIRST_TYPE,
793 LAST_NAME_TYPE = SYMBOL_TYPE, 815 LAST_NAME_TYPE = SYMBOL_TYPE,
794 FIRST_UNIQUE_NAME_TYPE = INTERNALIZED_STRING_TYPE, 816 FIRST_UNIQUE_NAME_TYPE = INTERNALIZED_STRING_TYPE,
795 LAST_UNIQUE_NAME_TYPE = SYMBOL_TYPE, 817 LAST_UNIQUE_NAME_TYPE = SYMBOL_TYPE,
796 FIRST_NONSTRING_TYPE = SYMBOL_TYPE, 818 FIRST_NONSTRING_TYPE = SYMBOL_TYPE,
797 // Boundaries for testing for an external array. 819 // Boundaries for testing for an external array.
798 FIRST_EXTERNAL_ARRAY_TYPE = EXTERNAL_BYTE_ARRAY_TYPE, 820 FIRST_EXTERNAL_ARRAY_TYPE = EXTERNAL_BYTE_ARRAY_TYPE,
799 LAST_EXTERNAL_ARRAY_TYPE = EXTERNAL_PIXEL_ARRAY_TYPE, 821 LAST_EXTERNAL_ARRAY_TYPE = EXTERNAL_PIXEL_ARRAY_TYPE,
822 // Boundaries for testing for a fixed typed array.
823 FIRST_FIXED_TYPED_ARRAY_TYPE = FIXED_INT8_ARRAY_TYPE,
824 LAST_FIXED_TYPED_ARRAY_TYPE = FIXED_UINT8_CLAMPED_ARRAY_TYPE,
800 // Boundary for promotion to old data space/old pointer space. 825 // Boundary for promotion to old data space/old pointer space.
801 LAST_DATA_TYPE = FILLER_TYPE, 826 LAST_DATA_TYPE = FILLER_TYPE,
802 // Boundary for objects represented as JSReceiver (i.e. JSObject or JSProxy). 827 // Boundary for objects represented as JSReceiver (i.e. JSObject or JSProxy).
803 // Note that there is no range for JSObject or JSProxy, since their subtypes 828 // Note that there is no range for JSObject or JSProxy, since their subtypes
804 // are not continuous in this enum! The enum ranges instead reflect the 829 // are not continuous in this enum! The enum ranges instead reflect the
805 // external class names, where proxies are treated as either ordinary objects, 830 // external class names, where proxies are treated as either ordinary objects,
806 // or functions. 831 // or functions.
807 FIRST_JS_RECEIVER_TYPE = JS_FUNCTION_PROXY_TYPE, 832 FIRST_JS_RECEIVER_TYPE = JS_FUNCTION_PROXY_TYPE,
808 LAST_JS_RECEIVER_TYPE = LAST_TYPE, 833 LAST_JS_RECEIVER_TYPE = LAST_TYPE,
809 // Boundaries for testing the types represented as JSObject 834 // Boundaries for testing the types represented as JSObject
(...skipping 169 matching lines...)
979 V(ExternalArray) \ 1004 V(ExternalArray) \
980 V(ExternalByteArray) \ 1005 V(ExternalByteArray) \
981 V(ExternalUnsignedByteArray) \ 1006 V(ExternalUnsignedByteArray) \
982 V(ExternalShortArray) \ 1007 V(ExternalShortArray) \
983 V(ExternalUnsignedShortArray) \ 1008 V(ExternalUnsignedShortArray) \
984 V(ExternalIntArray) \ 1009 V(ExternalIntArray) \
985 V(ExternalUnsignedIntArray) \ 1010 V(ExternalUnsignedIntArray) \
986 V(ExternalFloatArray) \ 1011 V(ExternalFloatArray) \
987 V(ExternalDoubleArray) \ 1012 V(ExternalDoubleArray) \
988 V(ExternalPixelArray) \ 1013 V(ExternalPixelArray) \
1014 V(FixedTypedArrayBase) \
1015 V(FixedUint8Array) \
1016 V(FixedInt8Array) \
1017 V(FixedUint16Array) \
1018 V(FixedInt16Array) \
1019 V(FixedUint32Array) \
1020 V(FixedInt32Array) \
1021 V(FixedFloat32Array) \
1022 V(FixedFloat64Array) \
1023 V(FixedUint8ClampedArray) \
989 V(ByteArray) \ 1024 V(ByteArray) \
990 V(FreeSpace) \ 1025 V(FreeSpace) \
991 V(JSReceiver) \ 1026 V(JSReceiver) \
992 V(JSObject) \ 1027 V(JSObject) \
993 V(JSContextExtensionObject) \ 1028 V(JSContextExtensionObject) \
994 V(JSGeneratorObject) \ 1029 V(JSGeneratorObject) \
995 V(JSModule) \ 1030 V(JSModule) \
996 V(Map) \ 1031 V(Map) \
997 V(DescriptorArray) \ 1032 V(DescriptorArray) \
998 V(TransitionArray) \ 1033 V(TransitionArray) \
(...skipping 1100 matching lines...)
2099 // Returns true if an object has any of the fast elements kinds. 2134 // Returns true if an object has any of the fast elements kinds.
2100 inline bool HasFastElements(); 2135 inline bool HasFastElements();
2101 // Returns true if an object has elements of FAST_DOUBLE_ELEMENTS 2136 // Returns true if an object has elements of FAST_DOUBLE_ELEMENTS
2102 // ElementsKind. 2137 // ElementsKind.
2103 inline bool HasFastDoubleElements(); 2138 inline bool HasFastDoubleElements();
2104 // Returns true if an object has elements of FAST_HOLEY_*_ELEMENTS 2139 // Returns true if an object has elements of FAST_HOLEY_*_ELEMENTS
2105 // ElementsKind. 2140 // ElementsKind.
2106 inline bool HasFastHoleyElements(); 2141 inline bool HasFastHoleyElements();
2107 inline bool HasNonStrictArgumentsElements(); 2142 inline bool HasNonStrictArgumentsElements();
2108 inline bool HasDictionaryElements(); 2143 inline bool HasDictionaryElements();
2144
2109 inline bool HasExternalPixelElements(); 2145 inline bool HasExternalPixelElements();
2110 inline bool HasExternalArrayElements(); 2146 inline bool HasExternalArrayElements();
2111 inline bool HasExternalByteElements(); 2147 inline bool HasExternalByteElements();
2112 inline bool HasExternalUnsignedByteElements(); 2148 inline bool HasExternalUnsignedByteElements();
2113 inline bool HasExternalShortElements(); 2149 inline bool HasExternalShortElements();
2114 inline bool HasExternalUnsignedShortElements(); 2150 inline bool HasExternalUnsignedShortElements();
2115 inline bool HasExternalIntElements(); 2151 inline bool HasExternalIntElements();
2116 inline bool HasExternalUnsignedIntElements(); 2152 inline bool HasExternalUnsignedIntElements();
2117 inline bool HasExternalFloatElements(); 2153 inline bool HasExternalFloatElements();
2118 inline bool HasExternalDoubleElements(); 2154 inline bool HasExternalDoubleElements();
2155
2156 inline bool HasFixedTypedArrayElements();
2157
2119 bool HasFastArgumentsElements(); 2158 bool HasFastArgumentsElements();
2120 bool HasDictionaryArgumentsElements(); 2159 bool HasDictionaryArgumentsElements();
2121 inline SeededNumberDictionary* element_dictionary(); // Gets slow elements. 2160 inline SeededNumberDictionary* element_dictionary(); // Gets slow elements.
2122 2161
2123 inline void set_map_and_elements( 2162 inline void set_map_and_elements(
2124 Map* map, 2163 Map* map,
2125 FixedArrayBase* value, 2164 FixedArrayBase* value,
2126 WriteBarrierMode mode = UPDATE_WRITE_BARRIER); 2165 WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
2127 2166
2128 // Requires: HasFastElements(). 2167 // Requires: HasFastElements().
(...skipping 2689 matching lines...)
4818 4857
4819 // Dispatched behavior. 4858 // Dispatched behavior.
4820 DECLARE_PRINTER(ExternalDoubleArray) 4859 DECLARE_PRINTER(ExternalDoubleArray)
4821 DECLARE_VERIFIER(ExternalDoubleArray) 4860 DECLARE_VERIFIER(ExternalDoubleArray)
4822 4861
4823 private: 4862 private:
4824 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalDoubleArray); 4863 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalDoubleArray);
4825 }; 4864 };
4826 4865
4827 4866
4867 class FixedTypedArrayBase: public FixedArrayBase {
4868 public:
4869 // Casting:
4870 static inline FixedTypedArrayBase* cast(Object* obj);
4871
4872 static const int kDataOffset = kHeaderSize;
4873
4874 inline int size();
4875
4876 private:
4877 DISALLOW_IMPLICIT_CONSTRUCTORS(FixedTypedArrayBase);
4878 };
4879
4880
4881 template <class Traits>
4882 class FixedTypedArray: public FixedTypedArrayBase {
4883 public:
4884 typedef typename Traits::ElementType ElementType;
4885 static const InstanceType kInstanceType = Traits::kInstanceType;
4886
4887 // Casting:
4888 static inline FixedTypedArray<Traits>* cast(Object* obj);
4889
4890 static inline int SizeFor(int length) {
4891 return kDataOffset + length * sizeof(ElementType);
4892 }
4893
4894 inline ElementType get_scalar(int index);
4895 MUST_USE_RESULT inline MaybeObject* get(int index);
4896 inline void set(int index, ElementType value);
4897
4898 // This accessor applies the correct conversion from Smi, HeapNumber
4899 // and undefined.
4900 MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value);
4901
4902 static Handle<Object> SetValue(Handle<FixedTypedArray<Traits> > array,
4903 uint32_t index,
4904 Handle<Object> value);
4905
4906 DECLARE_PRINTER(FixedTypedArray)
4907 DECLARE_VERIFIER(FixedTypedArray)
4908
4909 private:
4910 DISALLOW_IMPLICIT_CONSTRUCTORS(FixedTypedArray);
4911 };
4912
4913 #define FIXED_TYPED_ARRAY_TRAITS(Type, type, TYPE, elementType) \
4914 class Type##ArrayTraits { \
4915 public: \
4916 typedef elementType ElementType; \
4917 static const InstanceType kInstanceType = FIXED_##TYPE##_ARRAY_TYPE; \
4918 static const char* Designator() { return #type " array"; } \
4919 static inline MaybeObject* ToObject(Heap* heap, elementType scalar); \
4920 static elementType defaultValue() { return 0; } \
4921 }; \
4922 \
4923 typedef FixedTypedArray<Type##ArrayTraits> Fixed##Type##Array;
4924
4925 FIXED_TYPED_ARRAY_TRAITS(Uint8, uint8, UINT8, uint8_t)
4926 FIXED_TYPED_ARRAY_TRAITS(Int8, int8, INT8, int8_t)
4927 FIXED_TYPED_ARRAY_TRAITS(Uint16, uint16, UINT16, uint16_t)
4928 FIXED_TYPED_ARRAY_TRAITS(Int16, int16, INT16, int16_t)
4929 FIXED_TYPED_ARRAY_TRAITS(Uint32, uint32, UINT32, uint32_t)
4930 FIXED_TYPED_ARRAY_TRAITS(Int32, int32, INT32, int32_t)
4931 FIXED_TYPED_ARRAY_TRAITS(Float32, float32, FLOAT32, float)
4932 FIXED_TYPED_ARRAY_TRAITS(Float64, float64, FLOAT64, double)
4933 FIXED_TYPED_ARRAY_TRAITS(Uint8Clamped, uint8_clamped, UINT8_CLAMPED, uint8_t)
4934
4935 #undef FIXED_TYPED_ARRAY_TRAITS
4936
4828 // DeoptimizationInputData is a fixed array used to hold the deoptimization 4937 // DeoptimizationInputData is a fixed array used to hold the deoptimization
4829 // data for code generated by the Hydrogen/Lithium compiler. It also 4938 // data for code generated by the Hydrogen/Lithium compiler. It also
4830 // contains information about functions that were inlined. If N different 4939 // contains information about functions that were inlined. If N different
4831 // functions were inlined then first N elements of the literal array will 4940 // functions were inlined then first N elements of the literal array will
4832 // contain these functions. 4941 // contain these functions.
4833 // 4942 //
4834 // It can be empty. 4943 // It can be empty.
4835 class DeoptimizationInputData: public FixedArray { 4944 class DeoptimizationInputData: public FixedArray {
4836 public: 4945 public:
4837 // Layout description. Indices in the array. 4946 // Layout description. Indices in the array.
(...skipping 986 matching lines...)
5824 } 5933 }
5825 5934
5826 inline bool has_non_strict_arguments_elements() { 5935 inline bool has_non_strict_arguments_elements() {
5827 return elements_kind() == NON_STRICT_ARGUMENTS_ELEMENTS; 5936 return elements_kind() == NON_STRICT_ARGUMENTS_ELEMENTS;
5828 } 5937 }
5829 5938
5830 inline bool has_external_array_elements() { 5939 inline bool has_external_array_elements() {
5831 return IsExternalArrayElementsKind(elements_kind()); 5940 return IsExternalArrayElementsKind(elements_kind());
5832 } 5941 }
5833 5942
5943 inline bool has_fixed_typed_array_elements() {
5944 return IsFixedTypedArrayElementsKind(elements_kind());
5945 }
5946
5834 inline bool has_dictionary_elements() { 5947 inline bool has_dictionary_elements() {
5835 return IsDictionaryElementsKind(elements_kind()); 5948 return IsDictionaryElementsKind(elements_kind());
5836 } 5949 }
5837 5950
5838 inline bool has_slow_elements_kind() { 5951 inline bool has_slow_elements_kind() {
5839 return elements_kind() == DICTIONARY_ELEMENTS 5952 return elements_kind() == DICTIONARY_ELEMENTS
5840 || elements_kind() == NON_STRICT_ARGUMENTS_ELEMENTS; 5953 || elements_kind() == NON_STRICT_ARGUMENTS_ELEMENTS;
5841 } 5954 }
5842 5955
5843 static bool IsValidElementsTransition(ElementsKind from_kind, 5956 static bool IsValidElementsTransition(ElementsKind from_kind,
(...skipping 4783 matching lines...)
10627 } else { 10740 } else {
10628 value &= ~(1 << bit_position); 10741 value &= ~(1 << bit_position);
10629 } 10742 }
10630 return value; 10743 return value;
10631 } 10744 }
10632 }; 10745 };
10633 10746
10634 } } // namespace v8::internal 10747 } } // namespace v8::internal
10635 10748
10636 #endif // V8_OBJECTS_H_ 10749 #endif // V8_OBJECTS_H_
OLDNEW

Powered by Google App Engine