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

Side by Side Diff: src/heap.cc

Issue 8098: - Added conditional write barrier to object accessors.... (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
« no previous file with comments | « src/dateparser.cc ('k') | src/jsregexp.cc » ('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 1224 matching lines...) Expand 10 before | Expand all | Expand 10 after
1235 return String::cast(number_string_cache_->get(hash * 2 + 1)); 1235 return String::cast(number_string_cache_->get(hash * 2 + 1));
1236 } 1236 }
1237 return undefined_value(); 1237 return undefined_value();
1238 } 1238 }
1239 1239
1240 1240
1241 void Heap::SetNumberStringCache(Object* number, String* string) { 1241 void Heap::SetNumberStringCache(Object* number, String* string) {
1242 int hash; 1242 int hash;
1243 if (number->IsSmi()) { 1243 if (number->IsSmi()) {
1244 hash = smi_get_hash(Smi::cast(number)); 1244 hash = smi_get_hash(Smi::cast(number));
1245 number_string_cache_->set(hash * 2, number, FixedArray::SKIP_WRITE_BARRIER); 1245 number_string_cache_->set(hash * 2, number, SKIP_WRITE_BARRIER);
1246 } else { 1246 } else {
1247 hash = double_get_hash(number->Number()); 1247 hash = double_get_hash(number->Number());
1248 number_string_cache_->set(hash * 2, number); 1248 number_string_cache_->set(hash * 2, number);
1249 } 1249 }
1250 number_string_cache_->set(hash * 2 + 1, string); 1250 number_string_cache_->set(hash * 2 + 1, string);
1251 } 1251 }
1252 1252
1253 1253
1254 Object* Heap::SmiOrNumberFromDouble(double value, 1254 Object* Heap::SmiOrNumberFromDouble(double value,
1255 bool new_object, 1255 bool new_object,
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
1648 Object* Heap::AllocateArgumentsObject(Object* callee, int length) { 1648 Object* Heap::AllocateArgumentsObject(Object* callee, int length) {
1649 // To get fast allocation and map sharing for arguments objects we 1649 // To get fast allocation and map sharing for arguments objects we
1650 // allocate them based on an arguments boilerplate. 1650 // allocate them based on an arguments boilerplate.
1651 1651
1652 // This calls Copy directly rather than using Heap::AllocateRaw so we 1652 // This calls Copy directly rather than using Heap::AllocateRaw so we
1653 // duplicate the check here. 1653 // duplicate the check here.
1654 ASSERT(allocation_allowed_ && gc_state_ == NOT_IN_GC); 1654 ASSERT(allocation_allowed_ && gc_state_ == NOT_IN_GC);
1655 1655
1656 JSObject* boilerplate = 1656 JSObject* boilerplate =
1657 Top::context()->global_context()->arguments_boilerplate(); 1657 Top::context()->global_context()->arguments_boilerplate();
1658 Object* result = CopyJSObject(boilerplate); 1658
1659 // Make the clone.
1660 Map* map = boilerplate->map();
1661 int object_size = map->instance_size();
1662 Object* result = new_space_.AllocateRaw(object_size);
1659 if (result->IsFailure()) return result; 1663 if (result->IsFailure()) return result;
1664 ASSERT(Heap::InNewSpace(result));
1660 1665
1661 Object* obj = JSObject::cast(result)->properties(); 1666 // Copy the content.
1662 FixedArray::cast(obj)->set(arguments_callee_index, callee); 1667 CopyBlock(reinterpret_cast<Object**>(HeapObject::cast(result)->address()),
1663 FixedArray::cast(obj)->set(arguments_length_index, Smi::FromInt(length)); 1668 reinterpret_cast<Object**>(boilerplate->address()),
1669 object_size);
1664 1670
1665 // Allocate the fixed array. 1671 // Set the two properties.
1666 obj = Heap::AllocateFixedArray(length); 1672 JSObject::cast(result)->InObjectPropertyAtPut(arguments_callee_index,
1667 if (obj->IsFailure()) return obj; 1673 callee,
1668 JSObject::cast(result)->set_elements(FixedArray::cast(obj)); 1674 SKIP_WRITE_BARRIER);
1675 JSObject::cast(result)->InObjectPropertyAtPut(arguments_length_index,
1676 Smi::FromInt(length),
1677 SKIP_WRITE_BARRIER);
1678
1679 // Allocate the elements if needed.
1680 if (length > 0) {
1681 // Allocate the fixed array.
1682 Object* obj = Heap::AllocateFixedArray(length);
1683 if (obj->IsFailure()) return obj;
1684 JSObject::cast(result)->set_elements(FixedArray::cast(obj));
1685 }
1669 1686
1670 // Check the state of the object 1687 // Check the state of the object
1671 ASSERT(JSObject::cast(result)->HasFastProperties()); 1688 ASSERT(JSObject::cast(result)->HasFastProperties());
1672 ASSERT(JSObject::cast(result)->HasFastElements()); 1689 ASSERT(JSObject::cast(result)->HasFastElements());
1673 1690
1674 return result; 1691 return result;
1675 } 1692 }
1676 1693
1677 1694
1678 Object* Heap::AllocateInitialMap(JSFunction* fun) { 1695 Object* Heap::AllocateInitialMap(JSFunction* fun) {
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
2104 HeapObject* dst = HeapObject::cast(obj); 2121 HeapObject* dst = HeapObject::cast(obj);
2105 CopyBlock(reinterpret_cast<Object**>(dst->address()), 2122 CopyBlock(reinterpret_cast<Object**>(dst->address()),
2106 reinterpret_cast<Object**>(src->address()), 2123 reinterpret_cast<Object**>(src->address()),
2107 FixedArray::SizeFor(len)); 2124 FixedArray::SizeFor(len));
2108 return obj; 2125 return obj;
2109 } 2126 }
2110 HeapObject::cast(obj)->set_map(src->map()); 2127 HeapObject::cast(obj)->set_map(src->map());
2111 FixedArray* result = FixedArray::cast(obj); 2128 FixedArray* result = FixedArray::cast(obj);
2112 result->set_length(len); 2129 result->set_length(len);
2113 // Copy the content 2130 // Copy the content
2114 FixedArray::WriteBarrierMode mode = result->GetWriteBarrierMode(); 2131 WriteBarrierMode mode = result->GetWriteBarrierMode();
2115 for (int i = 0; i < len; i++) result->set(i, src->get(i), mode); 2132 for (int i = 0; i < len; i++) result->set(i, src->get(i), mode);
2116 return result; 2133 return result;
2117 } 2134 }
2118 2135
2119 2136
2120 Object* Heap::AllocateFixedArray(int length) { 2137 Object* Heap::AllocateFixedArray(int length) {
2121 Object* result = AllocateRawFixedArray(length); 2138 Object* result = AllocateRawFixedArray(length);
2122 if (!result->IsFailure()) { 2139 if (!result->IsFailure()) {
2123 // Initialize header. 2140 // Initialize header.
2124 reinterpret_cast<Array*>(result)->set_map(fixed_array_map()); 2141 reinterpret_cast<Array*>(result)->set_map(fixed_array_map());
2125 FixedArray* array = FixedArray::cast(result); 2142 FixedArray* array = FixedArray::cast(result);
2126 array->set_length(length); 2143 array->set_length(length);
2144 Object* value = undefined_value();
2127 // Initialize body. 2145 // Initialize body.
2128 for (int index = 0; index < length; index++) array->set_undefined(index); 2146 for (int index = 0; index < length; index++) {
2147 array->set(index, value, SKIP_WRITE_BARRIER);
2148 }
2129 } 2149 }
2130 return result; 2150 return result;
2131 } 2151 }
2132 2152
2133 2153
2134 Object* Heap::AllocateFixedArray(int length, PretenureFlag pretenure) { 2154 Object* Heap::AllocateFixedArray(int length, PretenureFlag pretenure) {
2135 ASSERT(empty_fixed_array()->IsFixedArray()); 2155 ASSERT(empty_fixed_array()->IsFixedArray());
2136 if (length == 0) return empty_fixed_array(); 2156 if (length == 0) return empty_fixed_array();
2137 2157
2138 int size = FixedArray::SizeFor(length); 2158 int size = FixedArray::SizeFor(length);
2139 Object* result; 2159 Object* result;
2140 if (size > MaxHeapObjectSize()) { 2160 if (size > MaxHeapObjectSize()) {
2141 result = lo_space_->AllocateRawFixedArray(size); 2161 result = lo_space_->AllocateRawFixedArray(size);
2142 } else { 2162 } else {
2143 AllocationSpace space = 2163 AllocationSpace space =
2144 (pretenure == TENURED) ? OLD_POINTER_SPACE : NEW_SPACE; 2164 (pretenure == TENURED) ? OLD_POINTER_SPACE : NEW_SPACE;
2145 result = AllocateRaw(size, space); 2165 result = AllocateRaw(size, space);
2146 } 2166 }
2147 if (result->IsFailure()) return result; 2167 if (result->IsFailure()) return result;
2148 2168
2149 // Initialize the object. 2169 // Initialize the object.
2150 reinterpret_cast<Array*>(result)->set_map(fixed_array_map()); 2170 reinterpret_cast<Array*>(result)->set_map(fixed_array_map());
2151 FixedArray* array = FixedArray::cast(result); 2171 FixedArray* array = FixedArray::cast(result);
2152 array->set_length(length); 2172 array->set_length(length);
2153 for (int index = 0; index < length; index++) array->set_undefined(index); 2173 Object* value = undefined_value();
2174 for (int index = 0; index < length; index++) {
2175 array->set(index, value, SKIP_WRITE_BARRIER);
2176 }
2154 return array; 2177 return array;
2155 } 2178 }
2156 2179
2157 2180
2158 Object* Heap::AllocateFixedArrayWithHoles(int length) { 2181 Object* Heap::AllocateFixedArrayWithHoles(int length) {
2159 if (length == 0) return empty_fixed_array(); 2182 if (length == 0) return empty_fixed_array();
2160 Object* result = AllocateRawFixedArray(length); 2183 Object* result = AllocateRawFixedArray(length);
2161 if (!result->IsFailure()) { 2184 if (!result->IsFailure()) {
2162 // Initialize header. 2185 // Initialize header.
2163 reinterpret_cast<Array*>(result)->set_map(fixed_array_map()); 2186 reinterpret_cast<Array*>(result)->set_map(fixed_array_map());
2164 FixedArray* array = FixedArray::cast(result); 2187 FixedArray* array = FixedArray::cast(result);
2165 array->set_length(length); 2188 array->set_length(length);
2166 // Initialize body. 2189 // Initialize body.
2167 for (int index = 0; index < length; index++) array->set_the_hole(index); 2190 Object* value = the_hole_value();
2191 for (int index = 0; index < length; index++) {
2192 array->set(index, value, SKIP_WRITE_BARRIER);
2193 }
2168 } 2194 }
2169 return result; 2195 return result;
2170 } 2196 }
2171 2197
2172 2198
2173 Object* Heap::AllocateHashTable(int length) { 2199 Object* Heap::AllocateHashTable(int length) {
2174 Object* result = Heap::AllocateFixedArray(length); 2200 Object* result = Heap::AllocateFixedArray(length);
2175 if (result->IsFailure()) return result; 2201 if (result->IsFailure()) return result;
2176 reinterpret_cast<Array*>(result)->set_map(hash_table_map()); 2202 reinterpret_cast<Array*>(result)->set_map(hash_table_map());
2177 ASSERT(result->IsDictionary()); 2203 ASSERT(result->IsDictionary());
(...skipping 991 matching lines...) Expand 10 before | Expand all | Expand 10 after
3169 #ifdef DEBUG 3195 #ifdef DEBUG
3170 bool Heap::GarbageCollectionGreedyCheck() { 3196 bool Heap::GarbageCollectionGreedyCheck() {
3171 ASSERT(FLAG_gc_greedy); 3197 ASSERT(FLAG_gc_greedy);
3172 if (Bootstrapper::IsActive()) return true; 3198 if (Bootstrapper::IsActive()) return true;
3173 if (disallow_allocation_failure()) return true; 3199 if (disallow_allocation_failure()) return true;
3174 return CollectGarbage(0, NEW_SPACE); 3200 return CollectGarbage(0, NEW_SPACE);
3175 } 3201 }
3176 #endif 3202 #endif
3177 3203
3178 } } // namespace v8::internal 3204 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/dateparser.cc ('k') | src/jsregexp.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698