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

Side by Side Diff: src/heap.cc

Issue 558041: RFC: Try to be much more careful with where we skip the write barrier by:... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 10 years, 10 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/globals.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 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 1711 matching lines...) Expand 10 before | Expand all | Expand 10 after
1722 } 1722 }
1723 return undefined_value(); 1723 return undefined_value();
1724 } 1724 }
1725 1725
1726 1726
1727 void Heap::SetNumberStringCache(Object* number, String* string) { 1727 void Heap::SetNumberStringCache(Object* number, String* string) {
1728 int hash; 1728 int hash;
1729 int mask = (number_string_cache()->length() >> 1) - 1; 1729 int mask = (number_string_cache()->length() >> 1) - 1;
1730 if (number->IsSmi()) { 1730 if (number->IsSmi()) {
1731 hash = smi_get_hash(Smi::cast(number)) & mask; 1731 hash = smi_get_hash(Smi::cast(number)) & mask;
1732 number_string_cache()->set(hash * 2, number, SKIP_WRITE_BARRIER); 1732 number_string_cache()->set(hash * 2, Smi::cast(number));
1733 } else { 1733 } else {
1734 hash = double_get_hash(number->Number()) & mask; 1734 hash = double_get_hash(number->Number()) & mask;
1735 number_string_cache()->set(hash * 2, number); 1735 number_string_cache()->set(hash * 2, number);
1736 } 1736 }
1737 number_string_cache()->set(hash * 2 + 1, string); 1737 number_string_cache()->set(hash * 2 + 1, string);
1738 } 1738 }
1739 1739
1740 1740
1741 Object* Heap::SmiOrNumberFromDouble(double value, 1741 Object* Heap::SmiOrNumberFromDouble(double value,
1742 bool new_object, 1742 bool new_object,
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
1979 String::WriteToFlat(first, dest, 0, first_length); 1979 String::WriteToFlat(first, dest, 0, first_length);
1980 String::WriteToFlat(second, dest + first_length, 0, second_length); 1980 String::WriteToFlat(second, dest + first_length, 0, second_length);
1981 return result; 1981 return result;
1982 } 1982 }
1983 } 1983 }
1984 1984
1985 Map* map = is_ascii ? cons_ascii_string_map() : cons_string_map(); 1985 Map* map = is_ascii ? cons_ascii_string_map() : cons_string_map();
1986 1986
1987 Object* result = Allocate(map, NEW_SPACE); 1987 Object* result = Allocate(map, NEW_SPACE);
1988 if (result->IsFailure()) return result; 1988 if (result->IsFailure()) return result;
1989
1990 AssertNoAllocation no_gc;
1989 ConsString* cons_string = ConsString::cast(result); 1991 ConsString* cons_string = ConsString::cast(result);
1990 WriteBarrierMode mode = cons_string->GetWriteBarrierMode(); 1992 WriteBarrierMode mode = cons_string->GetWriteBarrierMode(no_gc);
1991 cons_string->set_length(length); 1993 cons_string->set_length(length);
1992 cons_string->set_hash_field(String::kEmptyHashField); 1994 cons_string->set_hash_field(String::kEmptyHashField);
1993 cons_string->set_first(first, mode); 1995 cons_string->set_first(first, mode);
1994 cons_string->set_second(second, mode); 1996 cons_string->set_second(second, mode);
1995 return result; 1997 return result;
1996 } 1998 }
1997 1999
1998 2000
1999 Object* Heap::AllocateSubString(String* buffer, 2001 Object* Heap::AllocateSubString(String* buffer,
2000 int start, 2002 int start,
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
2278 2280
2279 Object* Heap::InitializeFunction(JSFunction* function, 2281 Object* Heap::InitializeFunction(JSFunction* function,
2280 SharedFunctionInfo* shared, 2282 SharedFunctionInfo* shared,
2281 Object* prototype) { 2283 Object* prototype) {
2282 ASSERT(!prototype->IsMap()); 2284 ASSERT(!prototype->IsMap());
2283 function->initialize_properties(); 2285 function->initialize_properties();
2284 function->initialize_elements(); 2286 function->initialize_elements();
2285 function->set_shared(shared); 2287 function->set_shared(shared);
2286 function->set_prototype_or_initial_map(prototype); 2288 function->set_prototype_or_initial_map(prototype);
2287 function->set_context(undefined_value()); 2289 function->set_context(undefined_value());
2288 function->set_literals(empty_fixed_array(), SKIP_WRITE_BARRIER); 2290 function->set_literals(empty_fixed_array());
2289 return function; 2291 return function;
2290 } 2292 }
2291 2293
2292 2294
2293 Object* Heap::AllocateFunctionPrototype(JSFunction* function) { 2295 Object* Heap::AllocateFunctionPrototype(JSFunction* function) {
2294 // Allocate the prototype. Make sure to use the object function 2296 // Allocate the prototype. Make sure to use the object function
2295 // from the function's context, since the function can be from a 2297 // from the function's context, since the function can be from a
2296 // different context. 2298 // different context.
2297 JSFunction* object_function = 2299 JSFunction* object_function =
2298 function->context()->global_context()->object_function(); 2300 function->context()->global_context()->object_function();
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after
2879 if (Heap::InNewSpace(obj)) { 2881 if (Heap::InNewSpace(obj)) {
2880 HeapObject* dst = HeapObject::cast(obj); 2882 HeapObject* dst = HeapObject::cast(obj);
2881 CopyBlock(reinterpret_cast<Object**>(dst->address()), 2883 CopyBlock(reinterpret_cast<Object**>(dst->address()),
2882 reinterpret_cast<Object**>(src->address()), 2884 reinterpret_cast<Object**>(src->address()),
2883 FixedArray::SizeFor(len)); 2885 FixedArray::SizeFor(len));
2884 return obj; 2886 return obj;
2885 } 2887 }
2886 HeapObject::cast(obj)->set_map(src->map()); 2888 HeapObject::cast(obj)->set_map(src->map());
2887 FixedArray* result = FixedArray::cast(obj); 2889 FixedArray* result = FixedArray::cast(obj);
2888 result->set_length(len); 2890 result->set_length(len);
2891
2889 // Copy the content 2892 // Copy the content
2890 WriteBarrierMode mode = result->GetWriteBarrierMode(); 2893 AssertNoAllocation no_gc;
2894 WriteBarrierMode mode = result->GetWriteBarrierMode(no_gc);
2891 for (int i = 0; i < len; i++) result->set(i, src->get(i), mode); 2895 for (int i = 0; i < len; i++) result->set(i, src->get(i), mode);
2892 return result; 2896 return result;
2893 } 2897 }
2894 2898
2895 2899
2896 Object* Heap::AllocateFixedArray(int length) { 2900 Object* Heap::AllocateFixedArray(int length) {
2897 ASSERT(length >= 0); 2901 ASSERT(length >= 0);
2898 if (length == 0) return empty_fixed_array(); 2902 if (length == 0) return empty_fixed_array();
2899 Object* result = AllocateRawFixedArray(length); 2903 Object* result = AllocateRawFixedArray(length);
2900 if (!result->IsFailure()) { 2904 if (!result->IsFailure()) {
2901 // Initialize header. 2905 // Initialize header.
2902 reinterpret_cast<Array*>(result)->set_map(fixed_array_map()); 2906 reinterpret_cast<Array*>(result)->set_map(fixed_array_map());
2903 FixedArray* array = FixedArray::cast(result); 2907 FixedArray* array = FixedArray::cast(result);
2904 array->set_length(length); 2908 array->set_length(length);
2905 Object* value = undefined_value(); 2909 Object* value = undefined_value();
2906 // Initialize body. 2910 // Initialize body.
2907 for (int index = 0; index < length; index++) { 2911 for (int index = 0; index < length; index++) {
2912 ASSERT(!Heap::InNewSpace(value)); // value = undefined
2908 array->set(index, value, SKIP_WRITE_BARRIER); 2913 array->set(index, value, SKIP_WRITE_BARRIER);
2909 } 2914 }
2910 } 2915 }
2911 return result; 2916 return result;
2912 } 2917 }
2913 2918
2914 2919
2915 Object* Heap::AllocateFixedArray(int length, PretenureFlag pretenure) { 2920 Object* Heap::AllocateFixedArray(int length, PretenureFlag pretenure) {
2916 ASSERT(length >= 0); 2921 ASSERT(length >= 0);
2917 ASSERT(empty_fixed_array()->IsFixedArray()); 2922 ASSERT(empty_fixed_array()->IsFixedArray());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2953 result = lo_space_->AllocateRawFixedArray(size); 2958 result = lo_space_->AllocateRawFixedArray(size);
2954 } 2959 }
2955 if (result->IsFailure()) return result; 2960 if (result->IsFailure()) return result;
2956 2961
2957 // Initialize the object. 2962 // Initialize the object.
2958 reinterpret_cast<Array*>(result)->set_map(fixed_array_map()); 2963 reinterpret_cast<Array*>(result)->set_map(fixed_array_map());
2959 FixedArray* array = FixedArray::cast(result); 2964 FixedArray* array = FixedArray::cast(result);
2960 array->set_length(length); 2965 array->set_length(length);
2961 Object* value = undefined_value(); 2966 Object* value = undefined_value();
2962 for (int index = 0; index < length; index++) { 2967 for (int index = 0; index < length; index++) {
2968 ASSERT(!Heap::InNewSpace(value)); // value = undefined
2963 array->set(index, value, SKIP_WRITE_BARRIER); 2969 array->set(index, value, SKIP_WRITE_BARRIER);
2964 } 2970 }
2965 return array; 2971 return array;
2966 } 2972 }
2967 2973
2968 2974
2969 Object* Heap::AllocateFixedArrayWithHoles(int length) { 2975 Object* Heap::AllocateFixedArrayWithHoles(int length) {
2970 if (length == 0) return empty_fixed_array(); 2976 if (length == 0) return empty_fixed_array();
2971 Object* result = AllocateRawFixedArray(length); 2977 Object* result = AllocateRawFixedArray(length);
2972 if (!result->IsFailure()) { 2978 if (!result->IsFailure()) {
2973 // Initialize header. 2979 // Initialize header.
2974 reinterpret_cast<Array*>(result)->set_map(fixed_array_map()); 2980 reinterpret_cast<Array*>(result)->set_map(fixed_array_map());
2975 FixedArray* array = FixedArray::cast(result); 2981 FixedArray* array = FixedArray::cast(result);
2976 array->set_length(length); 2982 array->set_length(length);
2977 // Initialize body. 2983 // Initialize body.
2978 Object* value = the_hole_value(); 2984 Object* value = the_hole_value();
2979 for (int index = 0; index < length; index++) { 2985 for (int index = 0; index < length; index++) {
2986 ASSERT(!Heap::InNewSpace(value)); // value = the hole
2980 array->set(index, value, SKIP_WRITE_BARRIER); 2987 array->set(index, value, SKIP_WRITE_BARRIER);
2981 } 2988 }
2982 } 2989 }
2983 return result; 2990 return result;
2984 } 2991 }
2985 2992
2986 2993
2987 Object* Heap::AllocateHashTable(int length) { 2994 Object* Heap::AllocateHashTable(int length) {
2988 Object* result = Heap::AllocateFixedArray(length); 2995 Object* result = Heap::AllocateFixedArray(length);
2989 if (result->IsFailure()) return result; 2996 if (result->IsFailure()) return result;
(...skipping 1225 matching lines...) Expand 10 before | Expand all | Expand 10 after
4215 void ExternalStringTable::TearDown() { 4222 void ExternalStringTable::TearDown() {
4216 new_space_strings_.Free(); 4223 new_space_strings_.Free();
4217 old_space_strings_.Free(); 4224 old_space_strings_.Free();
4218 } 4225 }
4219 4226
4220 4227
4221 List<Object*> ExternalStringTable::new_space_strings_; 4228 List<Object*> ExternalStringTable::new_space_strings_;
4222 List<Object*> ExternalStringTable::old_space_strings_; 4229 List<Object*> ExternalStringTable::old_space_strings_;
4223 4230
4224 } } // namespace v8::internal 4231 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/globals.h ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698