Index: src/isolate.cc |
diff --git a/src/isolate.cc b/src/isolate.cc |
index 824cc37118b6df9c64ff8b6edd3d066bf0777ea3..a1635321302c5e30c31b07ab4d8154edf5c224d0 100644 |
--- a/src/isolate.cc |
+++ b/src/isolate.cc |
@@ -168,6 +168,77 @@ void Isolate::PreallocatedMemoryThreadStop() { |
} |
+void Isolate::PreallocatedStorageInit(size_t size) { |
+ ASSERT(free_list_.next_ == &free_list_); |
+ ASSERT(free_list_.previous_ == &free_list_); |
+ PreallocatedStorage* free_chunk = |
+ reinterpret_cast<PreallocatedStorage*>(new char[size]); |
+ free_list_.next_ = free_list_.previous_ = free_chunk; |
+ free_chunk->next_ = free_chunk->previous_ = &free_list_; |
+ free_chunk->size_ = size - sizeof(PreallocatedStorage); |
+ preallocated_storage_preallocated_ = true; |
+} |
+ |
+ |
+void* Isolate::PreallocatedStorageNew(size_t size) { |
+ if (!preallocated_storage_preallocated_) { |
+ return FreeStoreAllocationPolicy::New(size); |
+ } |
+ ASSERT(free_list_.next_ != &free_list_); |
+ ASSERT(free_list_.previous_ != &free_list_); |
+ |
+ size = (size + kPointerSize - 1) & ~(kPointerSize - 1); |
+ // Search for exact fit. |
+ for (PreallocatedStorage* storage = free_list_.next_; |
+ storage != &free_list_; |
+ storage = storage->next_) { |
+ if (storage->size_ == size) { |
+ storage->Unlink(); |
+ storage->LinkTo(&in_use_list_); |
+ return reinterpret_cast<void*>(storage + 1); |
+ } |
+ } |
+ // Search for first fit. |
+ for (PreallocatedStorage* storage = free_list_.next_; |
+ storage != &free_list_; |
+ storage = storage->next_) { |
+ if (storage->size_ >= size + sizeof(PreallocatedStorage)) { |
+ storage->Unlink(); |
+ storage->LinkTo(&in_use_list_); |
+ PreallocatedStorage* left_over = |
+ reinterpret_cast<PreallocatedStorage*>( |
+ reinterpret_cast<char*>(storage + 1) + size); |
+ left_over->size_ = storage->size_ - size - sizeof(PreallocatedStorage); |
+ ASSERT(size + left_over->size_ + sizeof(PreallocatedStorage) == |
+ storage->size_); |
+ storage->size_ = size; |
+ left_over->LinkTo(&free_list_); |
+ return reinterpret_cast<void*>(storage + 1); |
+ } |
+ } |
+ // Allocation failure. |
+ ASSERT(false); |
+ return NULL; |
+} |
+ |
+ |
+// We don't attempt to coalesce. |
+void Isolate::PreallocatedStorageDelete(void* p) { |
+ if (p == NULL) { |
+ return; |
+ } |
+ if (!preallocated_storage_preallocated_) { |
+ FreeStoreAllocationPolicy::Delete(p); |
+ return; |
+ } |
+ PreallocatedStorage* storage = reinterpret_cast<PreallocatedStorage*>(p) - 1; |
+ ASSERT(storage->next_->previous_ == storage); |
+ ASSERT(storage->previous_->next_ == storage); |
+ storage->Unlink(); |
+ storage->LinkTo(&free_list_); |
+} |
+ |
+ |
Isolate* Isolate::default_isolate_ = NULL; |
Thread::LocalStorageKey Isolate::isolate_key_; |
Thread::LocalStorageKey Isolate::thread_id_key_; |
@@ -382,7 +453,8 @@ Isolate::Isolate() |
zone_.isolate_ = this; |
stack_guard_.isolate_ = this; |
-#if defined(V8_TARGET_ARCH_ARM) && !defined(__arm__) |
+#if defined(V8_TARGET_ARCH_ARM) && !defined(__arm__) || \ |
+ defined(V8_TARGET_ARCH_MIPS) && !defined(__mips__) |
simulator_initialized_ = false; |
simulator_i_cache_ = NULL; |
simulator_redirection_ = NULL; |
@@ -658,10 +730,8 @@ bool Isolate::Init(Deserializer* des) { |
// Initialize other runtime facilities |
#if defined(USE_SIMULATOR) |
-#if defined(V8_TARGET_ARCH_ARM) |
+#if defined(V8_TARGET_ARCH_ARM) || defined(V8_TARGET_ARCH_MIPS) |
Simulator::Initialize(); |
-#elif defined(V8_TARGET_ARCH_MIPS) |
- ::assembler::mips::Simulator::Initialize(); |
#endif |
#endif |