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

Side by Side Diff: src/heap.cc

Issue 101413006: Implement in-heap backing store for typed arrays. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: GC fixes Created 6 years, 11 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/heap.h ('k') | src/heap-inl.h » ('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 2131 matching lines...) Expand 10 before | Expand all | Expand 10 after
2142 LoggingAndProfiling logging_and_profiling_mode> 2142 LoggingAndProfiling logging_and_profiling_mode>
2143 class ScavengingVisitor : public StaticVisitorBase { 2143 class ScavengingVisitor : public StaticVisitorBase {
2144 public: 2144 public:
2145 static void Initialize() { 2145 static void Initialize() {
2146 table_.Register(kVisitSeqOneByteString, &EvacuateSeqOneByteString); 2146 table_.Register(kVisitSeqOneByteString, &EvacuateSeqOneByteString);
2147 table_.Register(kVisitSeqTwoByteString, &EvacuateSeqTwoByteString); 2147 table_.Register(kVisitSeqTwoByteString, &EvacuateSeqTwoByteString);
2148 table_.Register(kVisitShortcutCandidate, &EvacuateShortcutCandidate); 2148 table_.Register(kVisitShortcutCandidate, &EvacuateShortcutCandidate);
2149 table_.Register(kVisitByteArray, &EvacuateByteArray); 2149 table_.Register(kVisitByteArray, &EvacuateByteArray);
2150 table_.Register(kVisitFixedArray, &EvacuateFixedArray); 2150 table_.Register(kVisitFixedArray, &EvacuateFixedArray);
2151 table_.Register(kVisitFixedDoubleArray, &EvacuateFixedDoubleArray); 2151 table_.Register(kVisitFixedDoubleArray, &EvacuateFixedDoubleArray);
2152 table_.Register(kVisitFixedTypedArray, &EvacuateFixedTypedArray);
2153 table_.Register(kVisitFixedFloat64Array, &EvacuateFixedFloat64Array);
2152 2154
2153 table_.Register(kVisitNativeContext, 2155 table_.Register(kVisitNativeContext,
2154 &ObjectEvacuationStrategy<POINTER_OBJECT>:: 2156 &ObjectEvacuationStrategy<POINTER_OBJECT>::
2155 template VisitSpecialized<Context::kSize>); 2157 template VisitSpecialized<Context::kSize>);
2156 2158
2157 table_.Register(kVisitConsString, 2159 table_.Register(kVisitConsString,
2158 &ObjectEvacuationStrategy<POINTER_OBJECT>:: 2160 &ObjectEvacuationStrategy<POINTER_OBJECT>::
2159 template VisitSpecialized<ConsString::kSize>); 2161 template VisitSpecialized<ConsString::kSize>);
2160 2162
2161 table_.Register(kVisitSlicedString, 2163 table_.Register(kVisitSlicedString,
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
2382 static inline void EvacuateFixedDoubleArray(Map* map, 2384 static inline void EvacuateFixedDoubleArray(Map* map,
2383 HeapObject** slot, 2385 HeapObject** slot,
2384 HeapObject* object) { 2386 HeapObject* object) {
2385 int length = reinterpret_cast<FixedDoubleArray*>(object)->length(); 2387 int length = reinterpret_cast<FixedDoubleArray*>(object)->length();
2386 int object_size = FixedDoubleArray::SizeFor(length); 2388 int object_size = FixedDoubleArray::SizeFor(length);
2387 EvacuateObject<DATA_OBJECT, kDoubleAlignment>( 2389 EvacuateObject<DATA_OBJECT, kDoubleAlignment>(
2388 map, slot, object, object_size); 2390 map, slot, object, object_size);
2389 } 2391 }
2390 2392
2391 2393
2394 static inline void EvacuateFixedTypedArray(Map* map,
2395 HeapObject** slot,
2396 HeapObject* object) {
2397 int object_size = reinterpret_cast<FixedTypedArrayBase*>(object)->size();
2398 EvacuateObject<DATA_OBJECT, kObjectAlignment>(
2399 map, slot, object, object_size);
2400 }
2401
2402
2403 static inline void EvacuateFixedFloat64Array(Map* map,
2404 HeapObject** slot,
2405 HeapObject* object) {
2406 int object_size = reinterpret_cast<FixedFloat64Array*>(object)->size();
2407 EvacuateObject<DATA_OBJECT, kDoubleAlignment>(
2408 map, slot, object, object_size);
2409 }
2410
2411
2392 static inline void EvacuateByteArray(Map* map, 2412 static inline void EvacuateByteArray(Map* map,
2393 HeapObject** slot, 2413 HeapObject** slot,
2394 HeapObject* object) { 2414 HeapObject* object) {
2395 int object_size = reinterpret_cast<ByteArray*>(object)->ByteArraySize(); 2415 int object_size = reinterpret_cast<ByteArray*>(object)->ByteArraySize();
2396 EvacuateObject<DATA_OBJECT, kObjectAlignment>( 2416 EvacuateObject<DATA_OBJECT, kObjectAlignment>(
2397 map, slot, object, object_size); 2417 map, slot, object, object_size);
2398 } 2418 }
2399 2419
2400 2420
2401 static inline void EvacuateSeqOneByteString(Map* map, 2421 static inline void EvacuateSeqOneByteString(Map* map,
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
2771 2791
2772 fixed_array_map()->set_prototype(null_value()); 2792 fixed_array_map()->set_prototype(null_value());
2773 fixed_array_map()->set_constructor(null_value()); 2793 fixed_array_map()->set_constructor(null_value());
2774 2794
2775 oddball_map()->set_prototype(null_value()); 2795 oddball_map()->set_prototype(null_value());
2776 oddball_map()->set_constructor(null_value()); 2796 oddball_map()->set_constructor(null_value());
2777 2797
2778 constant_pool_array_map()->set_prototype(null_value()); 2798 constant_pool_array_map()->set_prototype(null_value());
2779 constant_pool_array_map()->set_constructor(null_value()); 2799 constant_pool_array_map()->set_constructor(null_value());
2780 2800
2781 { MaybeObject* maybe_obj = 2801 { // Map allocation
2782 AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel); 2802 #define ALLOCATE_MAP(instance_type, size, field_name) \
2783 if (!maybe_obj->ToObject(&obj)) return false; 2803 { Map* map; \
2784 } 2804 if (!AllocateMap((instance_type), size)->To(&map)) return false; \
2785 set_fixed_cow_array_map(Map::cast(obj)); 2805 set_##field_name##_map(map); \
2786 ASSERT(fixed_array_map() != fixed_cow_array_map()); 2806 }
2787 2807
2788 { MaybeObject* maybe_obj = 2808 #define ALLOCATE_VARSIZE_MAP(instance_type, field_name) \
2789 AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel); 2809 ALLOCATE_MAP(instance_type, kVariableSizeSentinel, field_name)
2790 if (!maybe_obj->ToObject(&obj)) return false;
2791 }
2792 set_scope_info_map(Map::cast(obj));
2793 2810
2794 { MaybeObject* maybe_obj = AllocateMap(HEAP_NUMBER_TYPE, HeapNumber::kSize); 2811 ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, fixed_cow_array)
2795 if (!maybe_obj->ToObject(&obj)) return false; 2812 ASSERT(fixed_array_map() != fixed_cow_array_map());
2796 }
2797 set_heap_number_map(Map::cast(obj));
2798 2813
2799 { MaybeObject* maybe_obj = AllocateMap(SYMBOL_TYPE, Symbol::kSize); 2814 ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, scope_info)
2800 if (!maybe_obj->ToObject(&obj)) return false; 2815 ALLOCATE_MAP(HEAP_NUMBER_TYPE, HeapNumber::kSize, heap_number)
2801 } 2816 ALLOCATE_MAP(SYMBOL_TYPE, Symbol::kSize, symbol)
2802 set_symbol_map(Map::cast(obj)); 2817 ALLOCATE_MAP(FOREIGN_TYPE, Foreign::kSize, foreign)
2803 2818
2804 { MaybeObject* maybe_obj = AllocateMap(FOREIGN_TYPE, Foreign::kSize); 2819 for (unsigned i = 0; i < ARRAY_SIZE(string_type_table); i++) {
2805 if (!maybe_obj->ToObject(&obj)) return false; 2820 const StringTypeTable& entry = string_type_table[i];
2806 } 2821 { MaybeObject* maybe_obj = AllocateMap(entry.type, entry.size);
2807 set_foreign_map(Map::cast(obj)); 2822 if (!maybe_obj->ToObject(&obj)) return false;
2823 }
2824 roots_[entry.index] = Map::cast(obj);
2825 }
2808 2826
2809 for (unsigned i = 0; i < ARRAY_SIZE(string_type_table); i++) { 2827 ALLOCATE_VARSIZE_MAP(STRING_TYPE, undetectable_string)
2810 const StringTypeTable& entry = string_type_table[i]; 2828 undetectable_string_map()->set_is_undetectable();
2811 { MaybeObject* maybe_obj = AllocateMap(entry.type, entry.size); 2829
2812 if (!maybe_obj->ToObject(&obj)) return false; 2830 ALLOCATE_VARSIZE_MAP(ASCII_STRING_TYPE, undetectable_ascii_string);
2831 undetectable_ascii_string_map()->set_is_undetectable();
2832
2833 ALLOCATE_VARSIZE_MAP(FIXED_DOUBLE_ARRAY_TYPE, fixed_double_array)
2834 ALLOCATE_VARSIZE_MAP(BYTE_ARRAY_TYPE, byte_array)
2835 ALLOCATE_VARSIZE_MAP(FREE_SPACE_TYPE, free_space)
2836
2837 #define ALLOCATE_EXTERNAL_ARRAY_MAP(TYPE, type) \
2838 ALLOCATE_MAP(EXTERNAL_##TYPE##_ARRAY_TYPE, ExternalArray::kAlignedSize, \
2839 external_##type##_array)
2840
2841 ALLOCATE_EXTERNAL_ARRAY_MAP(PIXEL, pixel)
2842 ALLOCATE_EXTERNAL_ARRAY_MAP(BYTE, byte)
2843 ALLOCATE_EXTERNAL_ARRAY_MAP(UNSIGNED_BYTE, unsigned_byte)
2844 ALLOCATE_EXTERNAL_ARRAY_MAP(SHORT, short) // NOLINT
2845 ALLOCATE_EXTERNAL_ARRAY_MAP(UNSIGNED_SHORT, unsigned_short)
2846 ALLOCATE_EXTERNAL_ARRAY_MAP(INT, int)
2847 ALLOCATE_EXTERNAL_ARRAY_MAP(UNSIGNED_INT, unsigned_int)
2848 ALLOCATE_EXTERNAL_ARRAY_MAP(FLOAT, float)
2849 ALLOCATE_EXTERNAL_ARRAY_MAP(DOUBLE, double)
2850 #undef ALLOCATE_EXTERNAL_ARRAY_MAP
2851
2852 ALLOCATE_VARSIZE_MAP(FIXED_UINT8_ARRAY_TYPE, fixed_uint8_array)
2853 ALLOCATE_VARSIZE_MAP(FIXED_UINT8_CLAMPED_ARRAY_TYPE,
2854 fixed_uint8_clamped_array)
2855 ALLOCATE_VARSIZE_MAP(FIXED_INT8_ARRAY_TYPE, fixed_int8_array)
2856 ALLOCATE_VARSIZE_MAP(FIXED_UINT16_ARRAY_TYPE, fixed_uint16_array)
2857 ALLOCATE_VARSIZE_MAP(FIXED_INT16_ARRAY_TYPE, fixed_int16_array)
2858 ALLOCATE_VARSIZE_MAP(FIXED_UINT32_ARRAY_TYPE, fixed_uint32_array)
2859 ALLOCATE_VARSIZE_MAP(FIXED_INT32_ARRAY_TYPE, fixed_int32_array)
2860 ALLOCATE_VARSIZE_MAP(FIXED_FLOAT32_ARRAY_TYPE, fixed_float32_array)
2861 ALLOCATE_VARSIZE_MAP(FIXED_FLOAT64_ARRAY_TYPE, fixed_float64_array)
2862
2863 ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, non_strict_arguments_elements)
2864
2865 ALLOCATE_VARSIZE_MAP(CODE_TYPE, code)
2866
2867 ALLOCATE_MAP(CELL_TYPE, Cell::kSize, cell)
2868 ALLOCATE_MAP(PROPERTY_CELL_TYPE, PropertyCell::kSize, global_property_cell)
2869 ALLOCATE_MAP(FILLER_TYPE, kPointerSize, one_pointer_filler)
2870 ALLOCATE_MAP(FILLER_TYPE, 2 * kPointerSize, two_pointer_filler)
2871
2872
2873 for (unsigned i = 0; i < ARRAY_SIZE(struct_table); i++) {
2874 const StructTable& entry = struct_table[i];
2875 Map* map;
2876 if (!AllocateMap(entry.type, entry.size)->To(&map))
2877 return false;
2878 roots_[entry.index] = map;
2813 } 2879 }
2814 roots_[entry.index] = Map::cast(obj); 2880
2881 ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, hash_table)
2882
2883 ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, function_context)
2884 ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, catch_context)
2885 ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, with_context)
2886 ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, block_context)
2887 ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, module_context)
2888 ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, global_context)
2889
2890 ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, native_context)
2891 native_context_map()->set_dictionary_map(true);
2892 native_context_map()->set_visitor_id(
2893 StaticVisitorBase::kVisitNativeContext);
2894
2895 ALLOCATE_MAP(SHARED_FUNCTION_INFO_TYPE, SharedFunctionInfo::kAlignedSize,
2896 shared_function_info)
2897
2898 ALLOCATE_MAP(JS_MESSAGE_OBJECT_TYPE, JSMessageObject::kSize,
2899 message_object)
2900 ALLOCATE_MAP(JS_OBJECT_TYPE, JSObject::kHeaderSize + kPointerSize,
2901 external)
2902 external_map()->set_is_extensible(false);
2903 #undef ALLOCATE_VARSIZE_MAP
2904 #undef ALLOCATE_MAP
2815 } 2905 }
2816 2906
2817 { MaybeObject* maybe_obj = AllocateMap(STRING_TYPE, kVariableSizeSentinel); 2907 { // Empty arrays
2818 if (!maybe_obj->ToObject(&obj)) return false; 2908 { ByteArray* byte_array;
2909 if (!AllocateByteArray(0, TENURED)->To(&byte_array)) return false;
2910 set_empty_byte_array(byte_array);
2911 }
2912
2913 #define ALLOCATE_EMPTY_EXTERNAL_ARRAY(Type, type) \
2914 { ExternalArray* obj; \
2915 if (!AllocateEmptyExternalArray(kExternal##Type##Array)->To(&obj)) \
2916 return false; \
2917 set_empty_external_##type##_array(obj); \
2918 }
2919
2920 ALLOCATE_EMPTY_EXTERNAL_ARRAY(Byte, byte)
2921 ALLOCATE_EMPTY_EXTERNAL_ARRAY(UnsignedByte, unsigned_byte)
2922 ALLOCATE_EMPTY_EXTERNAL_ARRAY(Short, short) // NOLINT
2923 ALLOCATE_EMPTY_EXTERNAL_ARRAY(UnsignedShort, unsigned_short)
2924 ALLOCATE_EMPTY_EXTERNAL_ARRAY(Int, int)
2925 ALLOCATE_EMPTY_EXTERNAL_ARRAY(UnsignedInt, unsigned_int)
2926 ALLOCATE_EMPTY_EXTERNAL_ARRAY(Float, float)
2927 ALLOCATE_EMPTY_EXTERNAL_ARRAY(Double, double)
2928 ALLOCATE_EMPTY_EXTERNAL_ARRAY(Pixel, pixel)
2929 #undef ALLOCATE_EMPTY_EXTERNAL_ARRAY
2819 } 2930 }
2820 set_undetectable_string_map(Map::cast(obj));
2821 Map::cast(obj)->set_is_undetectable();
2822
2823 { MaybeObject* maybe_obj =
2824 AllocateMap(ASCII_STRING_TYPE, kVariableSizeSentinel);
2825 if (!maybe_obj->ToObject(&obj)) return false;
2826 }
2827 set_undetectable_ascii_string_map(Map::cast(obj));
2828 Map::cast(obj)->set_is_undetectable();
2829
2830 { MaybeObject* maybe_obj =
2831 AllocateMap(FIXED_DOUBLE_ARRAY_TYPE, kVariableSizeSentinel);
2832 if (!maybe_obj->ToObject(&obj)) return false;
2833 }
2834 set_fixed_double_array_map(Map::cast(obj));
2835
2836 { MaybeObject* maybe_obj =
2837 AllocateMap(BYTE_ARRAY_TYPE, kVariableSizeSentinel);
2838 if (!maybe_obj->ToObject(&obj)) return false;
2839 }
2840 set_byte_array_map(Map::cast(obj));
2841
2842 { MaybeObject* maybe_obj =
2843 AllocateMap(FREE_SPACE_TYPE, kVariableSizeSentinel);
2844 if (!maybe_obj->ToObject(&obj)) return false;
2845 }
2846 set_free_space_map(Map::cast(obj));
2847
2848 { MaybeObject* maybe_obj = AllocateByteArray(0, TENURED);
2849 if (!maybe_obj->ToObject(&obj)) return false;
2850 }
2851 set_empty_byte_array(ByteArray::cast(obj));
2852
2853 { MaybeObject* maybe_obj =
2854 AllocateMap(EXTERNAL_PIXEL_ARRAY_TYPE, ExternalArray::kAlignedSize);
2855 if (!maybe_obj->ToObject(&obj)) return false;
2856 }
2857 set_external_pixel_array_map(Map::cast(obj));
2858
2859 { MaybeObject* maybe_obj = AllocateMap(EXTERNAL_BYTE_ARRAY_TYPE,
2860 ExternalArray::kAlignedSize);
2861 if (!maybe_obj->ToObject(&obj)) return false;
2862 }
2863 set_external_byte_array_map(Map::cast(obj));
2864
2865 { MaybeObject* maybe_obj = AllocateMap(EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE,
2866 ExternalArray::kAlignedSize);
2867 if (!maybe_obj->ToObject(&obj)) return false;
2868 }
2869 set_external_unsigned_byte_array_map(Map::cast(obj));
2870
2871 { MaybeObject* maybe_obj = AllocateMap(EXTERNAL_SHORT_ARRAY_TYPE,
2872 ExternalArray::kAlignedSize);
2873 if (!maybe_obj->ToObject(&obj)) return false;
2874 }
2875 set_external_short_array_map(Map::cast(obj));
2876
2877 { MaybeObject* maybe_obj = AllocateMap(EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE,
2878 ExternalArray::kAlignedSize);
2879 if (!maybe_obj->ToObject(&obj)) return false;
2880 }
2881 set_external_unsigned_short_array_map(Map::cast(obj));
2882
2883 { MaybeObject* maybe_obj = AllocateMap(EXTERNAL_INT_ARRAY_TYPE,
2884 ExternalArray::kAlignedSize);
2885 if (!maybe_obj->ToObject(&obj)) return false;
2886 }
2887 set_external_int_array_map(Map::cast(obj));
2888
2889 { MaybeObject* maybe_obj = AllocateMap(EXTERNAL_UNSIGNED_INT_ARRAY_TYPE,
2890 ExternalArray::kAlignedSize);
2891 if (!maybe_obj->ToObject(&obj)) return false;
2892 }
2893 set_external_unsigned_int_array_map(Map::cast(obj));
2894
2895 { MaybeObject* maybe_obj = AllocateMap(EXTERNAL_FLOAT_ARRAY_TYPE,
2896 ExternalArray::kAlignedSize);
2897 if (!maybe_obj->ToObject(&obj)) return false;
2898 }
2899 set_external_float_array_map(Map::cast(obj));
2900
2901 { MaybeObject* maybe_obj =
2902 AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
2903 if (!maybe_obj->ToObject(&obj)) return false;
2904 }
2905 set_non_strict_arguments_elements_map(Map::cast(obj));
2906
2907 { MaybeObject* maybe_obj = AllocateMap(EXTERNAL_DOUBLE_ARRAY_TYPE,
2908 ExternalArray::kAlignedSize);
2909 if (!maybe_obj->ToObject(&obj)) return false;
2910 }
2911 set_external_double_array_map(Map::cast(obj));
2912
2913 { MaybeObject* maybe_obj = AllocateEmptyExternalArray(kExternalByteArray);
2914 if (!maybe_obj->ToObject(&obj)) return false;
2915 }
2916 set_empty_external_byte_array(ExternalArray::cast(obj));
2917
2918 { MaybeObject* maybe_obj =
2919 AllocateEmptyExternalArray(kExternalUnsignedByteArray);
2920 if (!maybe_obj->ToObject(&obj)) return false;
2921 }
2922 set_empty_external_unsigned_byte_array(ExternalArray::cast(obj));
2923
2924 { MaybeObject* maybe_obj = AllocateEmptyExternalArray(kExternalShortArray);
2925 if (!maybe_obj->ToObject(&obj)) return false;
2926 }
2927 set_empty_external_short_array(ExternalArray::cast(obj));
2928
2929 { MaybeObject* maybe_obj = AllocateEmptyExternalArray(
2930 kExternalUnsignedShortArray);
2931 if (!maybe_obj->ToObject(&obj)) return false;
2932 }
2933 set_empty_external_unsigned_short_array(ExternalArray::cast(obj));
2934
2935 { MaybeObject* maybe_obj = AllocateEmptyExternalArray(kExternalIntArray);
2936 if (!maybe_obj->ToObject(&obj)) return false;
2937 }
2938 set_empty_external_int_array(ExternalArray::cast(obj));
2939
2940 { MaybeObject* maybe_obj =
2941 AllocateEmptyExternalArray(kExternalUnsignedIntArray);
2942 if (!maybe_obj->ToObject(&obj)) return false;
2943 }
2944 set_empty_external_unsigned_int_array(ExternalArray::cast(obj));
2945
2946 { MaybeObject* maybe_obj = AllocateEmptyExternalArray(kExternalFloatArray);
2947 if (!maybe_obj->ToObject(&obj)) return false;
2948 }
2949 set_empty_external_float_array(ExternalArray::cast(obj));
2950
2951 { MaybeObject* maybe_obj = AllocateEmptyExternalArray(kExternalDoubleArray);
2952 if (!maybe_obj->ToObject(&obj)) return false;
2953 }
2954 set_empty_external_double_array(ExternalArray::cast(obj));
2955
2956 { MaybeObject* maybe_obj = AllocateEmptyExternalArray(kExternalPixelArray);
2957 if (!maybe_obj->ToObject(&obj)) return false;
2958 }
2959 set_empty_external_pixel_array(ExternalArray::cast(obj));
2960
2961 { MaybeObject* maybe_obj = AllocateMap(CODE_TYPE, kVariableSizeSentinel);
2962 if (!maybe_obj->ToObject(&obj)) return false;
2963 }
2964 set_code_map(Map::cast(obj));
2965
2966 { MaybeObject* maybe_obj = AllocateMap(CELL_TYPE, Cell::kSize);
2967 if (!maybe_obj->ToObject(&obj)) return false;
2968 }
2969 set_cell_map(Map::cast(obj));
2970
2971 { MaybeObject* maybe_obj = AllocateMap(PROPERTY_CELL_TYPE,
2972 PropertyCell::kSize);
2973 if (!maybe_obj->ToObject(&obj)) return false;
2974 }
2975 set_global_property_cell_map(Map::cast(obj));
2976
2977 { MaybeObject* maybe_obj = AllocateMap(FILLER_TYPE, kPointerSize);
2978 if (!maybe_obj->ToObject(&obj)) return false;
2979 }
2980 set_one_pointer_filler_map(Map::cast(obj));
2981
2982 { MaybeObject* maybe_obj = AllocateMap(FILLER_TYPE, 2 * kPointerSize);
2983 if (!maybe_obj->ToObject(&obj)) return false;
2984 }
2985 set_two_pointer_filler_map(Map::cast(obj));
2986
2987 for (unsigned i = 0; i < ARRAY_SIZE(struct_table); i++) {
2988 const StructTable& entry = struct_table[i];
2989 { MaybeObject* maybe_obj = AllocateMap(entry.type, entry.size);
2990 if (!maybe_obj->ToObject(&obj)) return false;
2991 }
2992 roots_[entry.index] = Map::cast(obj);
2993 }
2994
2995 { MaybeObject* maybe_obj =
2996 AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
2997 if (!maybe_obj->ToObject(&obj)) return false;
2998 }
2999 set_hash_table_map(Map::cast(obj));
3000
3001 { MaybeObject* maybe_obj =
3002 AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
3003 if (!maybe_obj->ToObject(&obj)) return false;
3004 }
3005 set_function_context_map(Map::cast(obj));
3006
3007 { MaybeObject* maybe_obj =
3008 AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
3009 if (!maybe_obj->ToObject(&obj)) return false;
3010 }
3011 set_catch_context_map(Map::cast(obj));
3012
3013 { MaybeObject* maybe_obj =
3014 AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
3015 if (!maybe_obj->ToObject(&obj)) return false;
3016 }
3017 set_with_context_map(Map::cast(obj));
3018
3019 { MaybeObject* maybe_obj =
3020 AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
3021 if (!maybe_obj->ToObject(&obj)) return false;
3022 }
3023 set_block_context_map(Map::cast(obj));
3024
3025 { MaybeObject* maybe_obj =
3026 AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
3027 if (!maybe_obj->ToObject(&obj)) return false;
3028 }
3029 set_module_context_map(Map::cast(obj));
3030
3031 { MaybeObject* maybe_obj =
3032 AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
3033 if (!maybe_obj->ToObject(&obj)) return false;
3034 }
3035 set_global_context_map(Map::cast(obj));
3036
3037 { MaybeObject* maybe_obj =
3038 AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
3039 if (!maybe_obj->ToObject(&obj)) return false;
3040 }
3041 Map* native_context_map = Map::cast(obj);
3042 native_context_map->set_dictionary_map(true);
3043 native_context_map->set_visitor_id(StaticVisitorBase::kVisitNativeContext);
3044 set_native_context_map(native_context_map);
3045
3046 { MaybeObject* maybe_obj = AllocateMap(SHARED_FUNCTION_INFO_TYPE,
3047 SharedFunctionInfo::kAlignedSize);
3048 if (!maybe_obj->ToObject(&obj)) return false;
3049 }
3050 set_shared_function_info_map(Map::cast(obj));
3051
3052 { MaybeObject* maybe_obj = AllocateMap(JS_MESSAGE_OBJECT_TYPE,
3053 JSMessageObject::kSize);
3054 if (!maybe_obj->ToObject(&obj)) return false;
3055 }
3056 set_message_object_map(Map::cast(obj));
3057
3058 Map* external_map;
3059 { MaybeObject* maybe_obj =
3060 AllocateMap(JS_OBJECT_TYPE, JSObject::kHeaderSize + kPointerSize);
3061 if (!maybe_obj->To(&external_map)) return false;
3062 }
3063 external_map->set_is_extensible(false);
3064 set_external_map(external_map);
3065
3066 ASSERT(!InNewSpace(empty_fixed_array())); 2931 ASSERT(!InNewSpace(empty_fixed_array()));
3067 return true; 2932 return true;
3068 } 2933 }
3069 2934
3070 2935
3071 MaybeObject* Heap::AllocateHeapNumber(double value, PretenureFlag pretenure) { 2936 MaybeObject* Heap::AllocateHeapNumber(double value, PretenureFlag pretenure) {
3072 // Statically ensure that it is safe to allocate heap numbers in paged 2937 // Statically ensure that it is safe to allocate heap numbers in paged
3073 // spaces. 2938 // spaces.
3074 int size = HeapNumber::kSize; 2939 int size = HeapNumber::kSize;
3075 STATIC_ASSERT(HeapNumber::kSize <= Page::kNonCodeObjectAreaSize); 2940 STATIC_ASSERT(HeapNumber::kSize <= Page::kNonCodeObjectAreaSize);
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after
3764 return kExternalDoubleArrayMapRootIndex; 3629 return kExternalDoubleArrayMapRootIndex;
3765 case kExternalPixelArray: 3630 case kExternalPixelArray:
3766 return kExternalPixelArrayMapRootIndex; 3631 return kExternalPixelArrayMapRootIndex;
3767 default: 3632 default:
3768 UNREACHABLE(); 3633 UNREACHABLE();
3769 return kUndefinedValueRootIndex; 3634 return kUndefinedValueRootIndex;
3770 } 3635 }
3771 } 3636 }
3772 3637
3773 3638
3639 Map* Heap::MapForFixedTypedArray(ExternalArrayType array_type) {
3640 return Map::cast(roots_[RootIndexForFixedTypedArray(array_type)]);
3641 }
3642
3643
3644 Heap::RootListIndex Heap::RootIndexForFixedTypedArray(
3645 ExternalArrayType array_type) {
3646 switch (array_type) {
3647 case kExternalByteArray:
3648 return kFixedInt8ArrayMapRootIndex;
3649 case kExternalUnsignedByteArray:
3650 return kFixedUint8ArrayMapRootIndex;
3651 case kExternalShortArray:
3652 return kFixedInt16ArrayMapRootIndex;
3653 case kExternalUnsignedShortArray:
3654 return kFixedUint16ArrayMapRootIndex;
3655 case kExternalIntArray:
3656 return kFixedInt32ArrayMapRootIndex;
3657 case kExternalUnsignedIntArray:
3658 return kFixedUint32ArrayMapRootIndex;
3659 case kExternalFloatArray:
3660 return kFixedFloat32ArrayMapRootIndex;
3661 case kExternalDoubleArray:
3662 return kFixedFloat64ArrayMapRootIndex;
3663 case kExternalPixelArray:
3664 return kFixedUint8ClampedArrayMapRootIndex;
3665 default:
3666 UNREACHABLE();
3667 return kUndefinedValueRootIndex;
3668 }
3669 }
3670
3671
3774 Heap::RootListIndex Heap::RootIndexForEmptyExternalArray( 3672 Heap::RootListIndex Heap::RootIndexForEmptyExternalArray(
3775 ElementsKind elementsKind) { 3673 ElementsKind elementsKind) {
3776 switch (elementsKind) { 3674 switch (elementsKind) {
3777 case EXTERNAL_BYTE_ELEMENTS: 3675 case EXTERNAL_BYTE_ELEMENTS:
3778 return kEmptyExternalByteArrayRootIndex; 3676 return kEmptyExternalByteArrayRootIndex;
3779 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: 3677 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS:
3780 return kEmptyExternalUnsignedByteArrayRootIndex; 3678 return kEmptyExternalUnsignedByteArrayRootIndex;
3781 case EXTERNAL_SHORT_ELEMENTS: 3679 case EXTERNAL_SHORT_ELEMENTS:
3782 return kEmptyExternalShortArrayRootIndex; 3680 return kEmptyExternalShortArrayRootIndex;
3783 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: 3681 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS:
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
4022 3920
4023 reinterpret_cast<ExternalArray*>(result)->set_map_no_write_barrier( 3921 reinterpret_cast<ExternalArray*>(result)->set_map_no_write_barrier(
4024 MapForExternalArrayType(array_type)); 3922 MapForExternalArrayType(array_type));
4025 reinterpret_cast<ExternalArray*>(result)->set_length(length); 3923 reinterpret_cast<ExternalArray*>(result)->set_length(length);
4026 reinterpret_cast<ExternalArray*>(result)->set_external_pointer( 3924 reinterpret_cast<ExternalArray*>(result)->set_external_pointer(
4027 external_pointer); 3925 external_pointer);
4028 3926
4029 return result; 3927 return result;
4030 } 3928 }
4031 3929
3930 static void ForFixedTypedArray(ExternalArrayType array_type,
3931 int* element_size,
3932 ElementsKind* element_kind) {
3933 switch (array_type) {
3934 case kExternalUnsignedByteArray:
3935 *element_size = 1;
3936 *element_kind = UINT8_ELEMENTS;
3937 return;
3938 case kExternalByteArray:
3939 *element_size = 1;
3940 *element_kind = INT8_ELEMENTS;
3941 return;
3942 case kExternalUnsignedShortArray:
3943 *element_size = 2;
3944 *element_kind = UINT16_ELEMENTS;
3945 return;
3946 case kExternalShortArray:
3947 *element_size = 2;
3948 *element_kind = INT16_ELEMENTS;
3949 return;
3950 case kExternalUnsignedIntArray:
3951 *element_size = 4;
3952 *element_kind = UINT32_ELEMENTS;
3953 return;
3954 case kExternalIntArray:
3955 *element_size = 4;
3956 *element_kind = INT32_ELEMENTS;
3957 return;
3958 case kExternalFloatArray:
3959 *element_size = 4;
3960 *element_kind = FLOAT32_ELEMENTS;
3961 return;
3962 case kExternalDoubleArray:
3963 *element_size = 8;
3964 *element_kind = FLOAT64_ELEMENTS;
3965 return;
3966 case kExternalPixelArray:
3967 *element_size = 1;
3968 *element_kind = UINT8_CLAMPED_ELEMENTS;
3969 return;
3970 default:
3971 *element_size = 0; // Bogus
3972 *element_kind = UINT8_ELEMENTS; // Bogus
3973 UNREACHABLE();
3974 }
3975 }
3976
3977
3978 MaybeObject* Heap::AllocateFixedTypedArray(int length,
3979 ExternalArrayType array_type,
3980 PretenureFlag pretenure) {
3981 int element_size;
3982 ElementsKind elements_kind;
3983 ForFixedTypedArray(array_type, &element_size, &elements_kind);
3984 int size = OBJECT_POINTER_ALIGN(
3985 length * element_size + FixedTypedArrayBase::kDataOffset);
3986 #ifndef V8_HOST_ARCH_64_BIT
3987 if (array_type == kExternalDoubleArray) {
3988 size += kPointerSize;
3989 }
3990 #endif
3991 AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, pretenure);
3992
3993 HeapObject* object;
3994 MaybeObject* maybe_object = AllocateRaw(size, space, OLD_DATA_SPACE);
3995 if (!maybe_object->To(&object)) return maybe_object;
3996
3997 if (array_type == kExternalDoubleArray) {
3998 object = EnsureDoubleAligned(this, object, size);
3999 }
4000
4001 FixedTypedArrayBase* elements =
4002 reinterpret_cast<FixedTypedArrayBase*>(object);
4003 elements->set_map(MapForFixedTypedArray(array_type));
4004 elements->set_length(length);
4005 return elements;
4006 }
4007
4032 4008
4033 MaybeObject* Heap::CreateCode(const CodeDesc& desc, 4009 MaybeObject* Heap::CreateCode(const CodeDesc& desc,
4034 Code::Flags flags, 4010 Code::Flags flags,
4035 Handle<Object> self_reference, 4011 Handle<Object> self_reference,
4036 bool immovable, 4012 bool immovable,
4037 bool crankshafted, 4013 bool crankshafted,
4038 int prologue_offset) { 4014 int prologue_offset) {
4039 // Allocate ByteArray before the Code object, so that we do not risk 4015 // Allocate ByteArray before the Code object, so that we do not risk
4040 // leaving uninitialized Code object (and breaking the heap). 4016 // leaving uninitialized Code object (and breaking the heap).
4041 ByteArray* reloc_info; 4017 ByteArray* reloc_info;
(...skipping 2773 matching lines...) Expand 10 before | Expand all | Expand 10 after
6815 } 6791 }
6816 6792
6817 6793
6818 void Heap::EnsureWeakObjectToCodeTable() { 6794 void Heap::EnsureWeakObjectToCodeTable() {
6819 if (!weak_object_to_code_table()->IsHashTable()) { 6795 if (!weak_object_to_code_table()->IsHashTable()) {
6820 set_weak_object_to_code_table(*isolate()->factory()->NewWeakHashTable(16)); 6796 set_weak_object_to_code_table(*isolate()->factory()->NewWeakHashTable(16));
6821 } 6797 }
6822 } 6798 }
6823 6799
6824 6800
6801 void Heap::FatalProcessOutOfMemory(const char* location, bool take_snapshot) {
6802 v8::internal::V8::FatalProcessOutOfMemory(location, take_snapshot);
6803 }
6804
6825 #ifdef DEBUG 6805 #ifdef DEBUG
6826 6806
6827 class PrintHandleVisitor: public ObjectVisitor { 6807 class PrintHandleVisitor: public ObjectVisitor {
6828 public: 6808 public:
6829 void VisitPointers(Object** start, Object** end) { 6809 void VisitPointers(Object** start, Object** end) {
6830 for (Object** p = start; p < end; p++) 6810 for (Object** p = start; p < end; p++)
6831 PrintF(" handle %p to %p\n", 6811 PrintF(" handle %p to %p\n",
6832 reinterpret_cast<void*>(p), 6812 reinterpret_cast<void*>(p),
6833 reinterpret_cast<void*>(*p)); 6813 reinterpret_cast<void*>(*p));
6834 } 6814 }
(...skipping 965 matching lines...) Expand 10 before | Expand all | Expand 10 after
7800 static_cast<int>(object_sizes_last_time_[index])); 7780 static_cast<int>(object_sizes_last_time_[index]));
7801 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) 7781 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT)
7802 #undef ADJUST_LAST_TIME_OBJECT_COUNT 7782 #undef ADJUST_LAST_TIME_OBJECT_COUNT
7803 7783
7804 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); 7784 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_));
7805 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); 7785 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_));
7806 ClearObjectStats(); 7786 ClearObjectStats();
7807 } 7787 }
7808 7788
7809 } } // namespace v8::internal 7789 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/heap.h ('k') | src/heap-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698