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

Side by Side Diff: src/heap.cc

Issue 760002: Minor refactorings to use some recently added methods. (Closed)
Patch Set: Created 10 years, 9 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
« no previous file with comments | « src/compilation-cache.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 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 2553 matching lines...) Expand 10 before | Expand all | Expand 10 after
2564 // If we're forced to always allocate, we use the general allocation 2564 // If we're forced to always allocate, we use the general allocation
2565 // functions which may leave us with an object in old space. 2565 // functions which may leave us with an object in old space.
2566 if (always_allocate()) { 2566 if (always_allocate()) {
2567 clone = AllocateRaw(object_size, NEW_SPACE, OLD_POINTER_SPACE); 2567 clone = AllocateRaw(object_size, NEW_SPACE, OLD_POINTER_SPACE);
2568 if (clone->IsFailure()) return clone; 2568 if (clone->IsFailure()) return clone;
2569 Address clone_address = HeapObject::cast(clone)->address(); 2569 Address clone_address = HeapObject::cast(clone)->address();
2570 CopyBlock(reinterpret_cast<Object**>(clone_address), 2570 CopyBlock(reinterpret_cast<Object**>(clone_address),
2571 reinterpret_cast<Object**>(source->address()), 2571 reinterpret_cast<Object**>(source->address()),
2572 object_size); 2572 object_size);
2573 // Update write barrier for all fields that lie beyond the header. 2573 // Update write barrier for all fields that lie beyond the header.
2574 for (int offset = JSObject::kHeaderSize; 2574 RecordWrites(clone_address,
2575 offset < object_size; 2575 JSObject::kHeaderSize,
2576 offset += kPointerSize) { 2576 object_size - JSObject::kHeaderSize);
2577 RecordWrite(clone_address, offset);
2578 }
2579 } else { 2577 } else {
2580 clone = new_space_.AllocateRaw(object_size); 2578 clone = new_space_.AllocateRaw(object_size);
2581 if (clone->IsFailure()) return clone; 2579 if (clone->IsFailure()) return clone;
2582 ASSERT(Heap::InNewSpace(clone)); 2580 ASSERT(Heap::InNewSpace(clone));
2583 // Since we know the clone is allocated in new space, we can copy 2581 // Since we know the clone is allocated in new space, we can copy
2584 // the contents without worrying about updating the write barrier. 2582 // the contents without worrying about updating the write barrier.
2585 CopyBlock(reinterpret_cast<Object**>(HeapObject::cast(clone)->address()), 2583 CopyBlock(reinterpret_cast<Object**>(HeapObject::cast(clone)->address()),
2586 reinterpret_cast<Object**>(source->address()), 2584 reinterpret_cast<Object**>(source->address()),
2587 object_size); 2585 object_size);
2588 } 2586 }
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
2899 2897
2900 Object* Heap::AllocateFixedArray(int length) { 2898 Object* Heap::AllocateFixedArray(int length) {
2901 ASSERT(length >= 0); 2899 ASSERT(length >= 0);
2902 if (length == 0) return empty_fixed_array(); 2900 if (length == 0) return empty_fixed_array();
2903 Object* result = AllocateRawFixedArray(length); 2901 Object* result = AllocateRawFixedArray(length);
2904 if (!result->IsFailure()) { 2902 if (!result->IsFailure()) {
2905 // Initialize header. 2903 // Initialize header.
2906 reinterpret_cast<Array*>(result)->set_map(fixed_array_map()); 2904 reinterpret_cast<Array*>(result)->set_map(fixed_array_map());
2907 FixedArray* array = FixedArray::cast(result); 2905 FixedArray* array = FixedArray::cast(result);
2908 array->set_length(length); 2906 array->set_length(length);
2909 Object* value = undefined_value();
2910 // Initialize body. 2907 // Initialize body.
2911 for (int index = 0; index < length; index++) { 2908 ASSERT(!Heap::InNewSpace(undefined_value()));
2912 ASSERT(!Heap::InNewSpace(value)); // value = undefined 2909 MemsetPointer(array->data_start(), undefined_value(), length);
2913 array->set(index, value, SKIP_WRITE_BARRIER);
2914 }
2915 } 2910 }
2916 return result; 2911 return result;
2917 } 2912 }
2918 2913
2919 2914
2920 Object* Heap::AllocateFixedArray(int length, PretenureFlag pretenure) { 2915 Object* Heap::AllocateFixedArray(int length, PretenureFlag pretenure) {
2921 ASSERT(length >= 0); 2916 ASSERT(length >= 0);
2922 ASSERT(empty_fixed_array()->IsFixedArray()); 2917 ASSERT(empty_fixed_array()->IsFixedArray());
2923 if (length < 0 || length > FixedArray::kMaxLength) { 2918 if (length < 0 || length > FixedArray::kMaxLength) {
2924 return Failure::OutOfMemoryException(); 2919 return Failure::OutOfMemoryException();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2956 } else { 2951 } else {
2957 ASSERT(space == LO_SPACE); 2952 ASSERT(space == LO_SPACE);
2958 result = lo_space_->AllocateRawFixedArray(size); 2953 result = lo_space_->AllocateRawFixedArray(size);
2959 } 2954 }
2960 if (result->IsFailure()) return result; 2955 if (result->IsFailure()) return result;
2961 2956
2962 // Initialize the object. 2957 // Initialize the object.
2963 reinterpret_cast<Array*>(result)->set_map(fixed_array_map()); 2958 reinterpret_cast<Array*>(result)->set_map(fixed_array_map());
2964 FixedArray* array = FixedArray::cast(result); 2959 FixedArray* array = FixedArray::cast(result);
2965 array->set_length(length); 2960 array->set_length(length);
2966 Object* value = undefined_value(); 2961 ASSERT(!Heap::InNewSpace(undefined_value()));
2967 for (int index = 0; index < length; index++) { 2962 MemsetPointer(array->data_start(), undefined_value(), length);
2968 ASSERT(!Heap::InNewSpace(value)); // value = undefined
2969 array->set(index, value, SKIP_WRITE_BARRIER);
2970 }
2971 return array; 2963 return array;
2972 } 2964 }
2973 2965
2974 2966
2975 Object* Heap::AllocateUninitializedFixedArray(int length) { 2967 Object* Heap::AllocateUninitializedFixedArray(int length) {
2976 if (length == 0) return empty_fixed_array(); 2968 if (length == 0) return empty_fixed_array();
2977 2969
2978 Object* obj = AllocateRawFixedArray(length); 2970 Object* obj = AllocateRawFixedArray(length);
2979 if (obj->IsFailure()) return obj; 2971 if (obj->IsFailure()) return obj;
2980 2972
2981 reinterpret_cast<FixedArray*>(obj)->set_map(fixed_array_map()); 2973 reinterpret_cast<FixedArray*>(obj)->set_map(fixed_array_map());
2982 FixedArray::cast(obj)->set_length(length); 2974 FixedArray::cast(obj)->set_length(length);
2983 return obj; 2975 return obj;
2984 } 2976 }
2985 2977
2986 2978
2987 Object* Heap::AllocateFixedArrayWithHoles(int length) { 2979 Object* Heap::AllocateFixedArrayWithHoles(int length) {
2988 if (length == 0) return empty_fixed_array(); 2980 if (length == 0) return empty_fixed_array();
2989 Object* result = AllocateRawFixedArray(length); 2981 Object* result = AllocateRawFixedArray(length);
2990 if (!result->IsFailure()) { 2982 if (!result->IsFailure()) {
2991 // Initialize header. 2983 // Initialize header.
2992 reinterpret_cast<Array*>(result)->set_map(fixed_array_map()); 2984 reinterpret_cast<Array*>(result)->set_map(fixed_array_map());
2993 FixedArray* array = FixedArray::cast(result); 2985 FixedArray* array = FixedArray::cast(result);
2994 array->set_length(length); 2986 array->set_length(length);
2995 // Initialize body. 2987 // Initialize body.
2996 ASSERT(!Heap::InNewSpace(the_hole_value())); 2988 ASSERT(!Heap::InNewSpace(the_hole_value()));
2997 MemsetPointer(HeapObject::RawField(array, FixedArray::kHeaderSize), 2989 MemsetPointer(array->data_start(), the_hole_value(), length);
2998 the_hole_value(),
2999 length);
3000 } 2990 }
3001 return result; 2991 return result;
3002 } 2992 }
3003 2993
3004 2994
3005 Object* Heap::AllocateHashTable(int length, PretenureFlag pretenure) { 2995 Object* Heap::AllocateHashTable(int length, PretenureFlag pretenure) {
3006 Object* result = Heap::AllocateFixedArray(length, pretenure); 2996 Object* result = Heap::AllocateFixedArray(length, pretenure);
3007 if (result->IsFailure()) return result; 2997 if (result->IsFailure()) return result;
3008 reinterpret_cast<Array*>(result)->set_map(hash_table_map()); 2998 reinterpret_cast<Array*>(result)->set_map(hash_table_map());
3009 ASSERT(result->IsHashTable()); 2999 ASSERT(result->IsHashTable());
(...skipping 1251 matching lines...) Expand 10 before | Expand all | Expand 10 after
4261 void ExternalStringTable::TearDown() { 4251 void ExternalStringTable::TearDown() {
4262 new_space_strings_.Free(); 4252 new_space_strings_.Free();
4263 old_space_strings_.Free(); 4253 old_space_strings_.Free();
4264 } 4254 }
4265 4255
4266 4256
4267 List<Object*> ExternalStringTable::new_space_strings_; 4257 List<Object*> ExternalStringTable::new_space_strings_;
4268 List<Object*> ExternalStringTable::old_space_strings_; 4258 List<Object*> ExternalStringTable::old_space_strings_;
4269 4259
4270 } } // namespace v8::internal 4260 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/compilation-cache.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698