| 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 private: | 88 private: |
| 89 Script::Type type_; | 89 Script::Type type_; |
| 90 FixedArray* cache_; | 90 FixedArray* cache_; |
| 91 DISALLOW_COPY_AND_ASSIGN(SourceCodeCache); | 91 DISALLOW_COPY_AND_ASSIGN(SourceCodeCache); |
| 92 }; | 92 }; |
| 93 | 93 |
| 94 static SourceCodeCache natives_cache(Script::TYPE_NATIVE); | 94 static SourceCodeCache natives_cache(Script::TYPE_NATIVE); |
| 95 static SourceCodeCache extensions_cache(Script::TYPE_EXTENSION); | 95 static SourceCodeCache extensions_cache(Script::TYPE_EXTENSION); |
| 96 // This is for delete, not delete[]. | 96 // This is for delete, not delete[]. |
| 97 static List<char*>* delete_these_non_arrays_on_tear_down = NULL; | 97 static List<char*>* delete_these_non_arrays_on_tear_down = NULL; |
| 98 // This is for delete[] |
| 99 static List<char*>* delete_these_arrays_on_tear_down = NULL; |
| 98 | 100 |
| 99 | 101 |
| 100 NativesExternalStringResource::NativesExternalStringResource(const char* source) | 102 NativesExternalStringResource::NativesExternalStringResource(const char* source) |
| 101 : data_(source), length_(StrLength(source)) { | 103 : data_(source), length_(StrLength(source)) { |
| 102 if (delete_these_non_arrays_on_tear_down == NULL) { | 104 if (delete_these_non_arrays_on_tear_down == NULL) { |
| 103 delete_these_non_arrays_on_tear_down = new List<char*>(2); | 105 delete_these_non_arrays_on_tear_down = new List<char*>(2); |
| 104 } | 106 } |
| 105 // The resources are small objects and we only make a fixed number of | 107 // The resources are small objects and we only make a fixed number of |
| 106 // them, but let's clean them up on exit for neatness. | 108 // them, but let's clean them up on exit for neatness. |
| 107 delete_these_non_arrays_on_tear_down-> | 109 delete_these_non_arrays_on_tear_down-> |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 natives_cache.Add(name, fun); | 145 natives_cache.Add(name, fun); |
| 144 } | 146 } |
| 145 | 147 |
| 146 | 148 |
| 147 void Bootstrapper::Initialize(bool create_heap_objects) { | 149 void Bootstrapper::Initialize(bool create_heap_objects) { |
| 148 natives_cache.Initialize(create_heap_objects); | 150 natives_cache.Initialize(create_heap_objects); |
| 149 extensions_cache.Initialize(create_heap_objects); | 151 extensions_cache.Initialize(create_heap_objects); |
| 150 } | 152 } |
| 151 | 153 |
| 152 | 154 |
| 155 char* Bootstrapper::AllocateAutoDeletedArray(int bytes) { |
| 156 char* memory = new char[bytes]; |
| 157 if (memory != NULL) { |
| 158 if (delete_these_arrays_on_tear_down == NULL) { |
| 159 delete_these_arrays_on_tear_down = new List<char*>(2); |
| 160 } |
| 161 delete_these_arrays_on_tear_down->Add(memory); |
| 162 } |
| 163 return memory; |
| 164 } |
| 165 |
| 166 |
| 153 void Bootstrapper::TearDown() { | 167 void Bootstrapper::TearDown() { |
| 154 if (delete_these_non_arrays_on_tear_down != NULL) { | 168 if (delete_these_non_arrays_on_tear_down != NULL) { |
| 155 int len = delete_these_non_arrays_on_tear_down->length(); | 169 int len = delete_these_non_arrays_on_tear_down->length(); |
| 156 ASSERT(len < 20); // Don't use this mechanism for unbounded allocations. | 170 ASSERT(len < 20); // Don't use this mechanism for unbounded allocations. |
| 157 for (int i = 0; i < len; i++) { | 171 for (int i = 0; i < len; i++) { |
| 158 delete delete_these_non_arrays_on_tear_down->at(i); | 172 delete delete_these_non_arrays_on_tear_down->at(i); |
| 173 delete_these_non_arrays_on_tear_down->at(i) = NULL; |
| 159 } | 174 } |
| 160 delete delete_these_non_arrays_on_tear_down; | 175 delete delete_these_non_arrays_on_tear_down; |
| 161 delete_these_non_arrays_on_tear_down = NULL; | 176 delete_these_non_arrays_on_tear_down = NULL; |
| 162 } | 177 } |
| 163 | 178 |
| 179 if (delete_these_arrays_on_tear_down != NULL) { |
| 180 int len = delete_these_arrays_on_tear_down->length(); |
| 181 ASSERT(len < 1000); // Don't use this mechanism for unbounded allocations. |
| 182 for (int i = 0; i < len; i++) { |
| 183 delete[] delete_these_arrays_on_tear_down->at(i); |
| 184 delete_these_arrays_on_tear_down->at(i) = NULL; |
| 185 } |
| 186 delete delete_these_arrays_on_tear_down; |
| 187 delete_these_arrays_on_tear_down = NULL; |
| 188 } |
| 189 |
| 164 natives_cache.Initialize(false); // Yes, symmetrical | 190 natives_cache.Initialize(false); // Yes, symmetrical |
| 165 extensions_cache.Initialize(false); | 191 extensions_cache.Initialize(false); |
| 166 } | 192 } |
| 167 | 193 |
| 168 | 194 |
| 169 // Pending fixups are code positions that refer to builtin code | 195 // Pending fixups are code positions that refer to builtin code |
| 170 // objects that were not available at the time the code was generated. | 196 // objects that were not available at the time the code was generated. |
| 171 // The pending list is processed whenever an environment has been | 197 // The pending list is processed whenever an environment has been |
| 172 // created. | 198 // created. |
| 173 class PendingFixups : public AllStatic { | 199 class PendingFixups : public AllStatic { |
| (...skipping 1470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1644 } | 1670 } |
| 1645 | 1671 |
| 1646 | 1672 |
| 1647 // Restore statics that are thread local. | 1673 // Restore statics that are thread local. |
| 1648 char* Genesis::RestoreState(char* from) { | 1674 char* Genesis::RestoreState(char* from) { |
| 1649 current_ = *reinterpret_cast<Genesis**>(from); | 1675 current_ = *reinterpret_cast<Genesis**>(from); |
| 1650 return from + sizeof(current_); | 1676 return from + sizeof(current_); |
| 1651 } | 1677 } |
| 1652 | 1678 |
| 1653 } } // namespace v8::internal | 1679 } } // namespace v8::internal |
| OLD | NEW |