OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/api.h" | 8 #include "src/api.h" |
9 #include "src/base/bits.h" | 9 #include "src/base/bits.h" |
10 #include "src/base/once.h" | 10 #include "src/base/once.h" |
(...skipping 2962 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2973 | 2973 |
2974 { // Create a separate external one byte string map for native sources. | 2974 { // Create a separate external one byte string map for native sources. |
2975 AllocationResult allocation = AllocateMap(EXTERNAL_ONE_BYTE_STRING_TYPE, | 2975 AllocationResult allocation = AllocateMap(EXTERNAL_ONE_BYTE_STRING_TYPE, |
2976 ExternalOneByteString::kSize); | 2976 ExternalOneByteString::kSize); |
2977 if (!allocation.To(&obj)) return false; | 2977 if (!allocation.To(&obj)) return false; |
2978 set_native_source_string_map(Map::cast(obj)); | 2978 set_native_source_string_map(Map::cast(obj)); |
2979 } | 2979 } |
2980 | 2980 |
2981 ALLOCATE_VARSIZE_MAP(FIXED_DOUBLE_ARRAY_TYPE, fixed_double_array) | 2981 ALLOCATE_VARSIZE_MAP(FIXED_DOUBLE_ARRAY_TYPE, fixed_double_array) |
2982 ALLOCATE_VARSIZE_MAP(BYTE_ARRAY_TYPE, byte_array) | 2982 ALLOCATE_VARSIZE_MAP(BYTE_ARRAY_TYPE, byte_array) |
| 2983 ALLOCATE_VARSIZE_MAP(BYTECODE_ARRAY_TYPE, bytecode_array) |
2983 ALLOCATE_VARSIZE_MAP(FREE_SPACE_TYPE, free_space) | 2984 ALLOCATE_VARSIZE_MAP(FREE_SPACE_TYPE, free_space) |
2984 | 2985 |
2985 #define ALLOCATE_EXTERNAL_ARRAY_MAP(Type, type, TYPE, ctype, size) \ | 2986 #define ALLOCATE_EXTERNAL_ARRAY_MAP(Type, type, TYPE, ctype, size) \ |
2986 ALLOCATE_MAP(EXTERNAL_##TYPE##_ARRAY_TYPE, ExternalArray::kSize, \ | 2987 ALLOCATE_MAP(EXTERNAL_##TYPE##_ARRAY_TYPE, ExternalArray::kSize, \ |
2987 external_##type##_array) | 2988 external_##type##_array) |
2988 | 2989 |
2989 TYPED_ARRAYS(ALLOCATE_EXTERNAL_ARRAY_MAP) | 2990 TYPED_ARRAYS(ALLOCATE_EXTERNAL_ARRAY_MAP) |
2990 #undef ALLOCATE_EXTERNAL_ARRAY_MAP | 2991 #undef ALLOCATE_EXTERNAL_ARRAY_MAP |
2991 | 2992 |
2992 #define ALLOCATE_FIXED_TYPED_ARRAY_MAP(Type, type, TYPE, ctype, size) \ | 2993 #define ALLOCATE_FIXED_TYPED_ARRAY_MAP(Type, type, TYPE, ctype, size) \ |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3037 external_map()->set_is_extensible(false); | 3038 external_map()->set_is_extensible(false); |
3038 #undef ALLOCATE_VARSIZE_MAP | 3039 #undef ALLOCATE_VARSIZE_MAP |
3039 #undef ALLOCATE_MAP | 3040 #undef ALLOCATE_MAP |
3040 } | 3041 } |
3041 | 3042 |
3042 { // Empty arrays | 3043 { // Empty arrays |
3043 { | 3044 { |
3044 ByteArray* byte_array; | 3045 ByteArray* byte_array; |
3045 if (!AllocateByteArray(0, TENURED).To(&byte_array)) return false; | 3046 if (!AllocateByteArray(0, TENURED).To(&byte_array)) return false; |
3046 set_empty_byte_array(byte_array); | 3047 set_empty_byte_array(byte_array); |
| 3048 |
| 3049 BytecodeArray* bytecode_array; |
| 3050 if (!AllocateBytecodeArray(0, nullptr).To(&bytecode_array)) { |
| 3051 return false; |
| 3052 } |
| 3053 set_empty_bytecode_array(bytecode_array); |
3047 } | 3054 } |
3048 | 3055 |
3049 #define ALLOCATE_EMPTY_EXTERNAL_ARRAY(Type, type, TYPE, ctype, size) \ | 3056 #define ALLOCATE_EMPTY_EXTERNAL_ARRAY(Type, type, TYPE, ctype, size) \ |
3050 { \ | 3057 { \ |
3051 ExternalArray* obj; \ | 3058 ExternalArray* obj; \ |
3052 if (!AllocateEmptyExternalArray(kExternal##Type##Array).To(&obj)) \ | 3059 if (!AllocateEmptyExternalArray(kExternal##Type##Array).To(&obj)) \ |
3053 return false; \ | 3060 return false; \ |
3054 set_empty_external_##type##_array(obj); \ | 3061 set_empty_external_##type##_array(obj); \ |
3055 } | 3062 } |
3056 | 3063 |
(...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3782 AllocationResult allocation = AllocateRaw(size, space, OLD_SPACE); | 3789 AllocationResult allocation = AllocateRaw(size, space, OLD_SPACE); |
3783 if (!allocation.To(&result)) return allocation; | 3790 if (!allocation.To(&result)) return allocation; |
3784 } | 3791 } |
3785 | 3792 |
3786 result->set_map_no_write_barrier(byte_array_map()); | 3793 result->set_map_no_write_barrier(byte_array_map()); |
3787 ByteArray::cast(result)->set_length(length); | 3794 ByteArray::cast(result)->set_length(length); |
3788 return result; | 3795 return result; |
3789 } | 3796 } |
3790 | 3797 |
3791 | 3798 |
| 3799 AllocationResult Heap::AllocateBytecodeArray(int length, |
| 3800 const byte* const raw_bytecodes) { |
| 3801 if (length < 0 || length > BytecodeArray::kMaxLength) { |
| 3802 v8::internal::Heap::FatalProcessOutOfMemory("invalid array length", true); |
| 3803 } |
| 3804 |
| 3805 int size = BytecodeArray::SizeFor(length); |
| 3806 HeapObject* result; |
| 3807 { |
| 3808 AllocationResult allocation = AllocateRaw(size, OLD_SPACE, OLD_SPACE); |
| 3809 if (!allocation.To(&result)) return allocation; |
| 3810 } |
| 3811 |
| 3812 BytecodeArray* instance = BytecodeArray::cast(result); |
| 3813 instance->set_length(length); |
| 3814 CopyBytes(instance->GetDataStartAddress(), raw_bytecodes, length); |
| 3815 result->set_map_no_write_barrier(bytecode_array_map()); |
| 3816 return result; |
| 3817 } |
| 3818 |
| 3819 |
3792 void Heap::CreateFillerObjectAt(Address addr, int size) { | 3820 void Heap::CreateFillerObjectAt(Address addr, int size) { |
3793 if (size == 0) return; | 3821 if (size == 0) return; |
3794 HeapObject* filler = HeapObject::FromAddress(addr); | 3822 HeapObject* filler = HeapObject::FromAddress(addr); |
3795 if (size == kPointerSize) { | 3823 if (size == kPointerSize) { |
3796 filler->set_map_no_write_barrier(raw_unchecked_one_pointer_filler_map()); | 3824 filler->set_map_no_write_barrier(raw_unchecked_one_pointer_filler_map()); |
3797 } else if (size == 2 * kPointerSize) { | 3825 } else if (size == 2 * kPointerSize) { |
3798 filler->set_map_no_write_barrier(raw_unchecked_two_pointer_filler_map()); | 3826 filler->set_map_no_write_barrier(raw_unchecked_two_pointer_filler_map()); |
3799 } else { | 3827 } else { |
3800 filler->set_map_no_write_barrier(raw_unchecked_free_space_map()); | 3828 filler->set_map_no_write_barrier(raw_unchecked_free_space_map()); |
3801 FreeSpace::cast(filler)->nobarrier_set_size(size); | 3829 FreeSpace::cast(filler)->nobarrier_set_size(size); |
(...skipping 3084 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6886 *object_type = "CODE_TYPE"; \ | 6914 *object_type = "CODE_TYPE"; \ |
6887 *object_sub_type = "CODE_AGE/" #name; \ | 6915 *object_sub_type = "CODE_AGE/" #name; \ |
6888 return true; | 6916 return true; |
6889 CODE_AGE_LIST_COMPLETE(COMPARE_AND_RETURN_NAME) | 6917 CODE_AGE_LIST_COMPLETE(COMPARE_AND_RETURN_NAME) |
6890 #undef COMPARE_AND_RETURN_NAME | 6918 #undef COMPARE_AND_RETURN_NAME |
6891 } | 6919 } |
6892 return false; | 6920 return false; |
6893 } | 6921 } |
6894 } // namespace internal | 6922 } // namespace internal |
6895 } // namespace v8 | 6923 } // namespace v8 |
OLD | NEW |