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

Side by Side Diff: src/heap.cc

Issue 7516: - Optimized copying of FixedArray. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 12 years, 2 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
« src/heap.h ('K') | « src/heap.h ('k') | src/objects.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 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 2016 matching lines...) Expand 10 before | Expand all | Expand 10 after
2027 int size = FixedArray::SizeFor(0); 2027 int size = FixedArray::SizeFor(0);
2028 Object* result = AllocateRaw(size, OLD_DATA_SPACE); 2028 Object* result = AllocateRaw(size, OLD_DATA_SPACE);
2029 if (result->IsFailure()) return result; 2029 if (result->IsFailure()) return result;
2030 // Initialize the object. 2030 // Initialize the object.
2031 reinterpret_cast<Array*>(result)->set_map(fixed_array_map()); 2031 reinterpret_cast<Array*>(result)->set_map(fixed_array_map());
2032 reinterpret_cast<Array*>(result)->set_length(0); 2032 reinterpret_cast<Array*>(result)->set_length(0);
2033 return result; 2033 return result;
2034 } 2034 }
2035 2035
2036 2036
2037 Object* Heap::AllocateRawFixedArray(int length) {
2038 // Allocate the raw data for a fixed array.
2039 int size = FixedArray::SizeFor(length);
2040 return (size > MaxHeapObjectSize())
2041 ? lo_space_->AllocateRawFixedArray(size)
2042 : new_space_.AllocateRaw(size);
2043 }
2044
2045
2046 Object* Heap::CopyFixedArray(FixedArray* src) {
2047 int len = src->length();
2048 Object* obj = Heap::AllocateRawFixedArray(len);
2049 if (obj->IsFailure()) return obj;
2050 HeapObject::cast(obj)->set_map(src->map());
2051 FixedArray* result = FixedArray::cast(obj);
2052 result->set_length(len);
2053 FixedArray::WriteBarrierMode mode = result->GetWriteBarrierMode();
2054 // Copy the content
2055 for (int i = 0; i < len; i++) result->set(i, src->get(i), mode);
2056 return result;
2057 }
2058
2059
2060 Object* Heap::AllocateFixedArray(int length) {
2061 Object* result = AllocateRawFixedArray(length);
2062 if (!result->IsFailure()) {
2063 // Initialize header.
2064 reinterpret_cast<Array*>(result)->set_map(fixed_array_map());
2065 FixedArray* array = FixedArray::cast(result);
2066 array->set_length(length);
2067 // Initialize body.
2068 for (int index = 0; index < length; index++) array->set_undefined(index);
2069 }
2070 return result;
2071 }
2072
2073
2037 Object* Heap::AllocateFixedArray(int length, PretenureFlag pretenure) { 2074 Object* Heap::AllocateFixedArray(int length, PretenureFlag pretenure) {
2038 ASSERT(empty_fixed_array()->IsFixedArray()); 2075 ASSERT(empty_fixed_array()->IsFixedArray());
2039 if (length == 0) return empty_fixed_array(); 2076 if (length == 0) return empty_fixed_array();
2040 2077
2041 int size = FixedArray::SizeFor(length); 2078 int size = FixedArray::SizeFor(length);
2042 Object* result; 2079 Object* result;
2043 if (size > MaxHeapObjectSize()) { 2080 if (size > MaxHeapObjectSize()) {
2044 result = lo_space_->AllocateRawFixedArray(size); 2081 result = lo_space_->AllocateRawFixedArray(size);
2045 } else { 2082 } else {
2046 AllocationSpace space = 2083 AllocationSpace space =
2047 (pretenure == TENURED) ? OLD_POINTER_SPACE : NEW_SPACE; 2084 (pretenure == TENURED) ? OLD_POINTER_SPACE : NEW_SPACE;
2048 result = AllocateRaw(size, space); 2085 result = AllocateRaw(size, space);
2049 } 2086 }
2050 if (result->IsFailure()) return result; 2087 if (result->IsFailure()) return result;
2051 2088
2052 // Initialize the object. 2089 // Initialize the object.
2053 reinterpret_cast<Array*>(result)->set_map(fixed_array_map()); 2090 reinterpret_cast<Array*>(result)->set_map(fixed_array_map());
2054 FixedArray* array = FixedArray::cast(result); 2091 FixedArray* array = FixedArray::cast(result);
2055 array->set_length(length); 2092 array->set_length(length);
2056 for (int index = 0; index < length; index++) array->set_undefined(index); 2093 for (int index = 0; index < length; index++) array->set_undefined(index);
2057 return array; 2094 return array;
2058 } 2095 }
2059 2096
2060 2097
2061 Object* Heap::AllocateFixedArrayWithHoles(int length) { 2098 Object* Heap::AllocateFixedArrayWithHoles(int length) {
2062 if (length == 0) return empty_fixed_array(); 2099 if (length == 0) return empty_fixed_array();
2063 int size = FixedArray::SizeFor(length); 2100 Object* result = AllocateRawFixedArray(length);
2064 Object* result = size > MaxHeapObjectSize() 2101 if (!result->IsFailure()) {
2065 ? lo_space_->AllocateRawFixedArray(size) 2102 // Initialize header.
2066 : AllocateRaw(size, NEW_SPACE); 2103 reinterpret_cast<Array*>(result)->set_map(fixed_array_map());
2067 if (result->IsFailure()) return result; 2104 FixedArray* array = FixedArray::cast(result);
2068 2105 array->set_length(length);
2069 // Initialize the object. 2106 // Initialize body.
2070 reinterpret_cast<Array*>(result)->set_map(fixed_array_map()); 2107 for (int index = 0; index < length; index++) array->set_the_hole(index);
2071 FixedArray* array = FixedArray::cast(result); 2108 }
2072 array->set_length(length); 2109 return result;
2073 for (int index = 0; index < length; index++) array->set_the_hole(index);
2074 return array;
2075 } 2110 }
2076 2111
2077 2112
2078 Object* Heap::AllocateHashTable(int length) { 2113 Object* Heap::AllocateHashTable(int length) {
2079 Object* result = Heap::AllocateFixedArray(length); 2114 Object* result = Heap::AllocateFixedArray(length);
2080 if (result->IsFailure()) return result; 2115 if (result->IsFailure()) return result;
2081 reinterpret_cast<Array*>(result)->set_map(hash_table_map()); 2116 reinterpret_cast<Array*>(result)->set_map(hash_table_map());
2082 ASSERT(result->IsDictionary()); 2117 ASSERT(result->IsDictionary());
2083 return result; 2118 return result;
2084 } 2119 }
(...skipping 980 matching lines...) Expand 10 before | Expand all | Expand 10 after
3065 return "Scavenge"; 3100 return "Scavenge";
3066 case MARK_COMPACTOR: 3101 case MARK_COMPACTOR:
3067 return MarkCompactCollector::HasCompacted() ? "Mark-compact" 3102 return MarkCompactCollector::HasCompacted() ? "Mark-compact"
3068 : "Mark-sweep"; 3103 : "Mark-sweep";
3069 } 3104 }
3070 return "Unknown GC"; 3105 return "Unknown GC";
3071 } 3106 }
3072 3107
3073 3108
3074 } } // namespace v8::internal 3109 } } // namespace v8::internal
OLDNEW
« src/heap.h ('K') | « src/heap.h ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698