| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 && HeapObject::cast(this)->map()->instance_type() == BYTE_ARRAY_TYPE; | 353 && HeapObject::cast(this)->map()->instance_type() == BYTE_ARRAY_TYPE; |
| 354 } | 354 } |
| 355 | 355 |
| 356 | 356 |
| 357 bool Object::IsPixelArray() { | 357 bool Object::IsPixelArray() { |
| 358 return Object::IsHeapObject() && | 358 return Object::IsHeapObject() && |
| 359 HeapObject::cast(this)->map()->instance_type() == PIXEL_ARRAY_TYPE; | 359 HeapObject::cast(this)->map()->instance_type() == PIXEL_ARRAY_TYPE; |
| 360 } | 360 } |
| 361 | 361 |
| 362 | 362 |
| 363 bool Object::IsExternalArray() { |
| 364 if (!Object::IsHeapObject()) |
| 365 return false; |
| 366 InstanceType instance_type = |
| 367 HeapObject::cast(this)->map()->instance_type(); |
| 368 return (instance_type >= EXTERNAL_BYTE_ARRAY_TYPE && |
| 369 instance_type <= EXTERNAL_FLOAT_ARRAY_TYPE); |
| 370 } |
| 371 |
| 372 |
| 373 bool Object::IsExternalByteArray() { |
| 374 return Object::IsHeapObject() && |
| 375 HeapObject::cast(this)->map()->instance_type() == |
| 376 EXTERNAL_BYTE_ARRAY_TYPE; |
| 377 } |
| 378 |
| 379 |
| 380 bool Object::IsExternalUnsignedByteArray() { |
| 381 return Object::IsHeapObject() && |
| 382 HeapObject::cast(this)->map()->instance_type() == |
| 383 EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE; |
| 384 } |
| 385 |
| 386 |
| 387 bool Object::IsExternalShortArray() { |
| 388 return Object::IsHeapObject() && |
| 389 HeapObject::cast(this)->map()->instance_type() == |
| 390 EXTERNAL_SHORT_ARRAY_TYPE; |
| 391 } |
| 392 |
| 393 |
| 394 bool Object::IsExternalUnsignedShortArray() { |
| 395 return Object::IsHeapObject() && |
| 396 HeapObject::cast(this)->map()->instance_type() == |
| 397 EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE; |
| 398 } |
| 399 |
| 400 |
| 401 bool Object::IsExternalIntArray() { |
| 402 return Object::IsHeapObject() && |
| 403 HeapObject::cast(this)->map()->instance_type() == |
| 404 EXTERNAL_INT_ARRAY_TYPE; |
| 405 } |
| 406 |
| 407 |
| 408 bool Object::IsExternalUnsignedIntArray() { |
| 409 return Object::IsHeapObject() && |
| 410 HeapObject::cast(this)->map()->instance_type() == |
| 411 EXTERNAL_UNSIGNED_INT_ARRAY_TYPE; |
| 412 } |
| 413 |
| 414 |
| 415 bool Object::IsExternalFloatArray() { |
| 416 return Object::IsHeapObject() && |
| 417 HeapObject::cast(this)->map()->instance_type() == |
| 418 EXTERNAL_FLOAT_ARRAY_TYPE; |
| 419 } |
| 420 |
| 421 |
| 363 bool Object::IsFailure() { | 422 bool Object::IsFailure() { |
| 364 return HAS_FAILURE_TAG(this); | 423 return HAS_FAILURE_TAG(this); |
| 365 } | 424 } |
| 366 | 425 |
| 367 | 426 |
| 368 bool Object::IsRetryAfterGC() { | 427 bool Object::IsRetryAfterGC() { |
| 369 return HAS_FAILURE_TAG(this) | 428 return HAS_FAILURE_TAG(this) |
| 370 && Failure::cast(this)->type() == Failure::RETRY_AFTER_GC; | 429 && Failure::cast(this)->type() == Failure::RETRY_AFTER_GC; |
| 371 } | 430 } |
| 372 | 431 |
| (...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1077 WRITE_DOUBLE_FIELD(this, kValueOffset, value); | 1136 WRITE_DOUBLE_FIELD(this, kValueOffset, value); |
| 1078 } | 1137 } |
| 1079 | 1138 |
| 1080 | 1139 |
| 1081 ACCESSORS(JSObject, properties, FixedArray, kPropertiesOffset) | 1140 ACCESSORS(JSObject, properties, FixedArray, kPropertiesOffset) |
| 1082 | 1141 |
| 1083 | 1142 |
| 1084 Array* JSObject::elements() { | 1143 Array* JSObject::elements() { |
| 1085 Object* array = READ_FIELD(this, kElementsOffset); | 1144 Object* array = READ_FIELD(this, kElementsOffset); |
| 1086 // In the assert below Dictionary is covered under FixedArray. | 1145 // In the assert below Dictionary is covered under FixedArray. |
| 1087 ASSERT(array->IsFixedArray() || array->IsPixelArray()); | 1146 ASSERT(array->IsFixedArray() || array->IsPixelArray() || |
| 1147 array->IsExternalArray()); |
| 1088 return reinterpret_cast<Array*>(array); | 1148 return reinterpret_cast<Array*>(array); |
| 1089 } | 1149 } |
| 1090 | 1150 |
| 1091 | 1151 |
| 1092 void JSObject::set_elements(Array* value, WriteBarrierMode mode) { | 1152 void JSObject::set_elements(Array* value, WriteBarrierMode mode) { |
| 1093 // In the assert below Dictionary is covered under FixedArray. | 1153 // In the assert below Dictionary is covered under FixedArray. |
| 1094 ASSERT(value->IsFixedArray() || value->IsPixelArray()); | 1154 ASSERT(value->IsFixedArray() || value->IsPixelArray() || |
| 1155 value->IsExternalArray()); |
| 1095 WRITE_FIELD(this, kElementsOffset, value); | 1156 WRITE_FIELD(this, kElementsOffset, value); |
| 1096 CONDITIONAL_WRITE_BARRIER(this, kElementsOffset, mode); | 1157 CONDITIONAL_WRITE_BARRIER(this, kElementsOffset, mode); |
| 1097 } | 1158 } |
| 1098 | 1159 |
| 1099 | 1160 |
| 1100 void JSObject::initialize_properties() { | 1161 void JSObject::initialize_properties() { |
| 1101 ASSERT(!Heap::InNewSpace(Heap::empty_fixed_array())); | 1162 ASSERT(!Heap::InNewSpace(Heap::empty_fixed_array())); |
| 1102 WRITE_FIELD(this, kPropertiesOffset, Heap::empty_fixed_array()); | 1163 WRITE_FIELD(this, kPropertiesOffset, Heap::empty_fixed_array()); |
| 1103 } | 1164 } |
| 1104 | 1165 |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1547 CAST_ACCESSOR(GlobalObject) | 1608 CAST_ACCESSOR(GlobalObject) |
| 1548 CAST_ACCESSOR(JSGlobalProxy) | 1609 CAST_ACCESSOR(JSGlobalProxy) |
| 1549 CAST_ACCESSOR(JSGlobalObject) | 1610 CAST_ACCESSOR(JSGlobalObject) |
| 1550 CAST_ACCESSOR(JSBuiltinsObject) | 1611 CAST_ACCESSOR(JSBuiltinsObject) |
| 1551 CAST_ACCESSOR(Code) | 1612 CAST_ACCESSOR(Code) |
| 1552 CAST_ACCESSOR(JSArray) | 1613 CAST_ACCESSOR(JSArray) |
| 1553 CAST_ACCESSOR(JSRegExp) | 1614 CAST_ACCESSOR(JSRegExp) |
| 1554 CAST_ACCESSOR(Proxy) | 1615 CAST_ACCESSOR(Proxy) |
| 1555 CAST_ACCESSOR(ByteArray) | 1616 CAST_ACCESSOR(ByteArray) |
| 1556 CAST_ACCESSOR(PixelArray) | 1617 CAST_ACCESSOR(PixelArray) |
| 1618 CAST_ACCESSOR(ExternalArray) |
| 1619 CAST_ACCESSOR(ExternalByteArray) |
| 1620 CAST_ACCESSOR(ExternalUnsignedByteArray) |
| 1621 CAST_ACCESSOR(ExternalShortArray) |
| 1622 CAST_ACCESSOR(ExternalUnsignedShortArray) |
| 1623 CAST_ACCESSOR(ExternalIntArray) |
| 1624 CAST_ACCESSOR(ExternalUnsignedIntArray) |
| 1625 CAST_ACCESSOR(ExternalFloatArray) |
| 1557 CAST_ACCESSOR(Struct) | 1626 CAST_ACCESSOR(Struct) |
| 1558 | 1627 |
| 1559 | 1628 |
| 1560 #define MAKE_STRUCT_CAST(NAME, Name, name) CAST_ACCESSOR(Name) | 1629 #define MAKE_STRUCT_CAST(NAME, Name, name) CAST_ACCESSOR(Name) |
| 1561 STRUCT_LIST(MAKE_STRUCT_CAST) | 1630 STRUCT_LIST(MAKE_STRUCT_CAST) |
| 1562 #undef MAKE_STRUCT_CAST | 1631 #undef MAKE_STRUCT_CAST |
| 1563 | 1632 |
| 1564 | 1633 |
| 1565 template <typename Shape, typename Key> | 1634 template <typename Shape, typename Key> |
| 1566 HashTable<Shape, Key>* HashTable<Shape, Key>::cast(Object* obj) { | 1635 HashTable<Shape, Key>* HashTable<Shape, Key>::cast(Object* obj) { |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1931 } | 2000 } |
| 1932 | 2001 |
| 1933 | 2002 |
| 1934 void PixelArray::set(int index, uint8_t value) { | 2003 void PixelArray::set(int index, uint8_t value) { |
| 1935 ASSERT((index >= 0) && (index < this->length())); | 2004 ASSERT((index >= 0) && (index < this->length())); |
| 1936 uint8_t* ptr = external_pointer(); | 2005 uint8_t* ptr = external_pointer(); |
| 1937 ptr[index] = value; | 2006 ptr[index] = value; |
| 1938 } | 2007 } |
| 1939 | 2008 |
| 1940 | 2009 |
| 2010 void* ExternalArray::external_pointer() { |
| 2011 intptr_t ptr = READ_INTPTR_FIELD(this, kExternalPointerOffset); |
| 2012 return reinterpret_cast<void*>(ptr); |
| 2013 } |
| 2014 |
| 2015 |
| 2016 void ExternalArray::set_external_pointer(void* value, WriteBarrierMode mode) { |
| 2017 intptr_t ptr = reinterpret_cast<intptr_t>(value); |
| 2018 WRITE_INTPTR_FIELD(this, kExternalPointerOffset, ptr); |
| 2019 } |
| 2020 |
| 2021 |
| 2022 int8_t ExternalByteArray::get(int index) { |
| 2023 ASSERT((index >= 0) && (index < this->length())); |
| 2024 int8_t* ptr = static_cast<int8_t*>(external_pointer()); |
| 2025 return ptr[index]; |
| 2026 } |
| 2027 |
| 2028 |
| 2029 void ExternalByteArray::set(int index, int8_t value) { |
| 2030 ASSERT((index >= 0) && (index < this->length())); |
| 2031 int8_t* ptr = static_cast<int8_t*>(external_pointer()); |
| 2032 ptr[index] = value; |
| 2033 } |
| 2034 |
| 2035 |
| 2036 uint8_t ExternalUnsignedByteArray::get(int index) { |
| 2037 ASSERT((index >= 0) && (index < this->length())); |
| 2038 uint8_t* ptr = static_cast<uint8_t*>(external_pointer()); |
| 2039 return ptr[index]; |
| 2040 } |
| 2041 |
| 2042 |
| 2043 void ExternalUnsignedByteArray::set(int index, uint8_t value) { |
| 2044 ASSERT((index >= 0) && (index < this->length())); |
| 2045 uint8_t* ptr = static_cast<uint8_t*>(external_pointer()); |
| 2046 ptr[index] = value; |
| 2047 } |
| 2048 |
| 2049 |
| 2050 int16_t ExternalShortArray::get(int index) { |
| 2051 ASSERT((index >= 0) && (index < this->length())); |
| 2052 int16_t* ptr = static_cast<int16_t*>(external_pointer()); |
| 2053 return ptr[index]; |
| 2054 } |
| 2055 |
| 2056 |
| 2057 void ExternalShortArray::set(int index, int16_t value) { |
| 2058 ASSERT((index >= 0) && (index < this->length())); |
| 2059 int16_t* ptr = static_cast<int16_t*>(external_pointer()); |
| 2060 ptr[index] = value; |
| 2061 } |
| 2062 |
| 2063 |
| 2064 uint16_t ExternalUnsignedShortArray::get(int index) { |
| 2065 ASSERT((index >= 0) && (index < this->length())); |
| 2066 uint16_t* ptr = static_cast<uint16_t*>(external_pointer()); |
| 2067 return ptr[index]; |
| 2068 } |
| 2069 |
| 2070 |
| 2071 void ExternalUnsignedShortArray::set(int index, uint16_t value) { |
| 2072 ASSERT((index >= 0) && (index < this->length())); |
| 2073 uint16_t* ptr = static_cast<uint16_t*>(external_pointer()); |
| 2074 ptr[index] = value; |
| 2075 } |
| 2076 |
| 2077 |
| 2078 int32_t ExternalIntArray::get(int index) { |
| 2079 ASSERT((index >= 0) && (index < this->length())); |
| 2080 int32_t* ptr = static_cast<int32_t*>(external_pointer()); |
| 2081 return ptr[index]; |
| 2082 } |
| 2083 |
| 2084 |
| 2085 void ExternalIntArray::set(int index, int32_t value) { |
| 2086 ASSERT((index >= 0) && (index < this->length())); |
| 2087 int32_t* ptr = static_cast<int32_t*>(external_pointer()); |
| 2088 ptr[index] = value; |
| 2089 } |
| 2090 |
| 2091 |
| 2092 uint32_t ExternalUnsignedIntArray::get(int index) { |
| 2093 ASSERT((index >= 0) && (index < this->length())); |
| 2094 uint32_t* ptr = static_cast<uint32_t*>(external_pointer()); |
| 2095 return ptr[index]; |
| 2096 } |
| 2097 |
| 2098 |
| 2099 void ExternalUnsignedIntArray::set(int index, uint32_t value) { |
| 2100 ASSERT((index >= 0) && (index < this->length())); |
| 2101 uint32_t* ptr = static_cast<uint32_t*>(external_pointer()); |
| 2102 ptr[index] = value; |
| 2103 } |
| 2104 |
| 2105 |
| 2106 float ExternalFloatArray::get(int index) { |
| 2107 ASSERT((index >= 0) && (index < this->length())); |
| 2108 float* ptr = static_cast<float*>(external_pointer()); |
| 2109 return ptr[index]; |
| 2110 } |
| 2111 |
| 2112 |
| 2113 void ExternalFloatArray::set(int index, float value) { |
| 2114 ASSERT((index >= 0) && (index < this->length())); |
| 2115 float* ptr = static_cast<float*>(external_pointer()); |
| 2116 ptr[index] = value; |
| 2117 } |
| 2118 |
| 2119 |
| 1941 int Map::instance_size() { | 2120 int Map::instance_size() { |
| 1942 return READ_BYTE_FIELD(this, kInstanceSizeOffset) << kPointerSizeLog2; | 2121 return READ_BYTE_FIELD(this, kInstanceSizeOffset) << kPointerSizeLog2; |
| 1943 } | 2122 } |
| 1944 | 2123 |
| 1945 | 2124 |
| 1946 int Map::inobject_properties() { | 2125 int Map::inobject_properties() { |
| 1947 return READ_BYTE_FIELD(this, kInObjectPropertiesOffset); | 2126 return READ_BYTE_FIELD(this, kInObjectPropertiesOffset); |
| 1948 } | 2127 } |
| 1949 | 2128 |
| 1950 | 2129 |
| (...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2639 JSObject::ElementsKind JSObject::GetElementsKind() { | 2818 JSObject::ElementsKind JSObject::GetElementsKind() { |
| 2640 Array* array = elements(); | 2819 Array* array = elements(); |
| 2641 if (array->IsFixedArray()) { | 2820 if (array->IsFixedArray()) { |
| 2642 // FAST_ELEMENTS or DICTIONARY_ELEMENTS are both stored in a FixedArray. | 2821 // FAST_ELEMENTS or DICTIONARY_ELEMENTS are both stored in a FixedArray. |
| 2643 if (array->map() == Heap::fixed_array_map()) { | 2822 if (array->map() == Heap::fixed_array_map()) { |
| 2644 return FAST_ELEMENTS; | 2823 return FAST_ELEMENTS; |
| 2645 } | 2824 } |
| 2646 ASSERT(array->IsDictionary()); | 2825 ASSERT(array->IsDictionary()); |
| 2647 return DICTIONARY_ELEMENTS; | 2826 return DICTIONARY_ELEMENTS; |
| 2648 } | 2827 } |
| 2828 if (array->IsExternalArray()) { |
| 2829 switch (array->map()->instance_type()) { |
| 2830 case EXTERNAL_BYTE_ARRAY_TYPE: |
| 2831 return EXTERNAL_BYTE_ELEMENTS; |
| 2832 case EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE: |
| 2833 return EXTERNAL_UNSIGNED_BYTE_ELEMENTS; |
| 2834 case EXTERNAL_SHORT_ARRAY_TYPE: |
| 2835 return EXTERNAL_SHORT_ELEMENTS; |
| 2836 case EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE: |
| 2837 return EXTERNAL_UNSIGNED_SHORT_ELEMENTS; |
| 2838 case EXTERNAL_INT_ARRAY_TYPE: |
| 2839 return EXTERNAL_INT_ELEMENTS; |
| 2840 case EXTERNAL_UNSIGNED_INT_ARRAY_TYPE: |
| 2841 return EXTERNAL_UNSIGNED_INT_ELEMENTS; |
| 2842 default: |
| 2843 ASSERT(array->map()->instance_type() == EXTERNAL_FLOAT_ARRAY_TYPE); |
| 2844 return EXTERNAL_FLOAT_ELEMENTS; |
| 2845 } |
| 2846 } |
| 2649 ASSERT(array->IsPixelArray()); | 2847 ASSERT(array->IsPixelArray()); |
| 2650 return PIXEL_ELEMENTS; | 2848 return PIXEL_ELEMENTS; |
| 2651 } | 2849 } |
| 2652 | 2850 |
| 2653 | 2851 |
| 2654 bool JSObject::HasFastElements() { | 2852 bool JSObject::HasFastElements() { |
| 2655 return GetElementsKind() == FAST_ELEMENTS; | 2853 return GetElementsKind() == FAST_ELEMENTS; |
| 2656 } | 2854 } |
| 2657 | 2855 |
| 2658 | 2856 |
| 2659 bool JSObject::HasDictionaryElements() { | 2857 bool JSObject::HasDictionaryElements() { |
| 2660 return GetElementsKind() == DICTIONARY_ELEMENTS; | 2858 return GetElementsKind() == DICTIONARY_ELEMENTS; |
| 2661 } | 2859 } |
| 2662 | 2860 |
| 2663 | 2861 |
| 2664 bool JSObject::HasPixelElements() { | 2862 bool JSObject::HasPixelElements() { |
| 2665 return GetElementsKind() == PIXEL_ELEMENTS; | 2863 return GetElementsKind() == PIXEL_ELEMENTS; |
| 2666 } | 2864 } |
| 2667 | 2865 |
| 2668 | 2866 |
| 2867 bool JSObject::HasExternalArrayElements() { |
| 2868 return (HasExternalByteElements() || |
| 2869 HasExternalUnsignedByteElements() || |
| 2870 HasExternalShortElements() || |
| 2871 HasExternalUnsignedShortElements() || |
| 2872 HasExternalIntElements() || |
| 2873 HasExternalUnsignedIntElements() || |
| 2874 HasExternalFloatElements()); |
| 2875 } |
| 2876 |
| 2877 |
| 2878 bool JSObject::HasExternalByteElements() { |
| 2879 return GetElementsKind() == EXTERNAL_BYTE_ELEMENTS; |
| 2880 } |
| 2881 |
| 2882 |
| 2883 bool JSObject::HasExternalUnsignedByteElements() { |
| 2884 return GetElementsKind() == EXTERNAL_UNSIGNED_BYTE_ELEMENTS; |
| 2885 } |
| 2886 |
| 2887 |
| 2888 bool JSObject::HasExternalShortElements() { |
| 2889 return GetElementsKind() == EXTERNAL_SHORT_ELEMENTS; |
| 2890 } |
| 2891 |
| 2892 |
| 2893 bool JSObject::HasExternalUnsignedShortElements() { |
| 2894 return GetElementsKind() == EXTERNAL_UNSIGNED_SHORT_ELEMENTS; |
| 2895 } |
| 2896 |
| 2897 |
| 2898 bool JSObject::HasExternalIntElements() { |
| 2899 return GetElementsKind() == EXTERNAL_INT_ELEMENTS; |
| 2900 } |
| 2901 |
| 2902 |
| 2903 bool JSObject::HasExternalUnsignedIntElements() { |
| 2904 return GetElementsKind() == EXTERNAL_UNSIGNED_INT_ELEMENTS; |
| 2905 } |
| 2906 |
| 2907 |
| 2908 bool JSObject::HasExternalFloatElements() { |
| 2909 return GetElementsKind() == EXTERNAL_FLOAT_ELEMENTS; |
| 2910 } |
| 2911 |
| 2912 |
| 2669 bool JSObject::HasNamedInterceptor() { | 2913 bool JSObject::HasNamedInterceptor() { |
| 2670 return map()->has_named_interceptor(); | 2914 return map()->has_named_interceptor(); |
| 2671 } | 2915 } |
| 2672 | 2916 |
| 2673 | 2917 |
| 2674 bool JSObject::HasIndexedInterceptor() { | 2918 bool JSObject::HasIndexedInterceptor() { |
| 2675 return map()->has_indexed_interceptor(); | 2919 return map()->has_indexed_interceptor(); |
| 2676 } | 2920 } |
| 2677 | 2921 |
| 2678 | 2922 |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2889 #undef WRITE_INT_FIELD | 3133 #undef WRITE_INT_FIELD |
| 2890 #undef READ_SHORT_FIELD | 3134 #undef READ_SHORT_FIELD |
| 2891 #undef WRITE_SHORT_FIELD | 3135 #undef WRITE_SHORT_FIELD |
| 2892 #undef READ_BYTE_FIELD | 3136 #undef READ_BYTE_FIELD |
| 2893 #undef WRITE_BYTE_FIELD | 3137 #undef WRITE_BYTE_FIELD |
| 2894 | 3138 |
| 2895 | 3139 |
| 2896 } } // namespace v8::internal | 3140 } } // namespace v8::internal |
| 2897 | 3141 |
| 2898 #endif // V8_OBJECTS_INL_H_ | 3142 #endif // V8_OBJECTS_INL_H_ |
| OLD | NEW |