| OLD | NEW |
| 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 3007 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3018 | 3018 |
| 3019 void Map::ClearCodeCache() { | 3019 void Map::ClearCodeCache() { |
| 3020 // No write barrier is needed since empty_fixed_array is not in new space. | 3020 // No write barrier is needed since empty_fixed_array is not in new space. |
| 3021 // Please note this function is used during marking: | 3021 // Please note this function is used during marking: |
| 3022 // - MarkCompactCollector::MarkUnmarkedObject | 3022 // - MarkCompactCollector::MarkUnmarkedObject |
| 3023 ASSERT(!Heap::InNewSpace(Heap::raw_unchecked_empty_fixed_array())); | 3023 ASSERT(!Heap::InNewSpace(Heap::raw_unchecked_empty_fixed_array())); |
| 3024 WRITE_FIELD(this, kCodeCacheOffset, Heap::raw_unchecked_empty_fixed_array()); | 3024 WRITE_FIELD(this, kCodeCacheOffset, Heap::raw_unchecked_empty_fixed_array()); |
| 3025 } | 3025 } |
| 3026 | 3026 |
| 3027 | 3027 |
| 3028 void JSArray::Resize(int required_size) { |
| 3029 ASSERT(HasFastElements()); |
| 3030 int current_length = Smi::cast(this->length())->value(); |
| 3031 Array* elts = elements(); |
| 3032 if (required_size < current_length) { |
| 3033 // Set length before potentially expanding. If a new backing array is |
| 3034 // allocated, we will only copy the data below the new length. |
| 3035 this->set_length(Smi::FromInt(required_size)); |
| 3036 } |
| 3037 const int kArraySizeThatFitsComfortablyInNewSpace = 128; |
| 3038 if (elts->length() < required_size) { |
| 3039 // Doubling in size would be overkill, but leave some slack to avoid |
| 3040 // constantly growing. |
| 3041 Expand(required_size + (required_size >> 3)); |
| 3042 // It's a performance benefit to keep a frequently used array in new-space. |
| 3043 } else if (!Heap::InNewSpace(elts) && |
| 3044 required_size < kArraySizeThatFitsComfortablyInNewSpace) { |
| 3045 // Expand will allocate a new backing store in new space even if the size |
| 3046 // we asked for isn't larger than what we had before. |
| 3047 Expand(required_size); |
| 3048 } else { |
| 3049 // Using same backing store. |
| 3050 if (current_length > required_size) { |
| 3051 for (int i = required_size; i < current_length; i++) { |
| 3052 FixedArray::cast(elts)->set_the_hole(i); |
| 3053 } |
| 3054 return; |
| 3055 } |
| 3056 } |
| 3057 } |
| 3058 |
| 3059 |
| 3028 void JSArray::EnsureSize(int required_size) { | 3060 void JSArray::EnsureSize(int required_size) { |
| 3029 ASSERT(HasFastElements()); | 3061 ASSERT(HasFastElements()); |
| 3030 Array* elts = elements(); | 3062 Array* elts = elements(); |
| 3031 const int kArraySizeThatFitsComfortablyInNewSpace = 128; | 3063 const int kArraySizeThatFitsComfortablyInNewSpace = 128; |
| 3032 if (elts->length() < required_size) { | 3064 if (elts->length() < required_size) { |
| 3033 // Doubling in size would be overkill, but leave some slack to avoid | 3065 // Doubling in size would be overkill, but leave some slack to avoid |
| 3034 // constantly growing. | 3066 // constantly growing. |
| 3035 Expand(required_size + (required_size >> 3)); | 3067 Expand(required_size + (required_size >> 3)); |
| 3036 // It's a performance benefit to keep a frequently used array in new-space. | 3068 // It's a performance benefit to keep a frequently used array in new-space. |
| 3037 } else if (!Heap::new_space()->Contains(elts) && | 3069 } else if (!Heap::new_space()->Contains(elts) && |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3077 #undef WRITE_INT_FIELD | 3109 #undef WRITE_INT_FIELD |
| 3078 #undef READ_SHORT_FIELD | 3110 #undef READ_SHORT_FIELD |
| 3079 #undef WRITE_SHORT_FIELD | 3111 #undef WRITE_SHORT_FIELD |
| 3080 #undef READ_BYTE_FIELD | 3112 #undef READ_BYTE_FIELD |
| 3081 #undef WRITE_BYTE_FIELD | 3113 #undef WRITE_BYTE_FIELD |
| 3082 | 3114 |
| 3083 | 3115 |
| 3084 } } // namespace v8::internal | 3116 } } // namespace v8::internal |
| 3085 | 3117 |
| 3086 #endif // V8_OBJECTS_INL_H_ | 3118 #endif // V8_OBJECTS_INL_H_ |
| OLD | NEW |