| OLD | NEW | 
|---|
| 1 // Copyright (c) 2012, the Dart project authors.  Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors.  Please see the AUTHORS file | 
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a | 
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "vm/assembler.h" | 5 #include "vm/assembler.h" | 
| 6 | 6 | 
| 7 #include "platform/utils.h" | 7 #include "platform/utils.h" | 
| 8 #include "vm/cpu.h" | 8 #include "vm/cpu.h" | 
| 9 #include "vm/heap.h" | 9 #include "vm/heap.h" | 
| 10 #include "vm/memory_region.h" | 10 #include "vm/memory_region.h" | 
| 11 #include "vm/os.h" | 11 #include "vm/os.h" | 
| 12 #include "vm/zone.h" | 12 #include "vm/zone.h" | 
| 13 | 13 | 
| 14 namespace dart { | 14 namespace dart { | 
| 15 | 15 | 
| 16 static uword NewContents(int capacity) { | 16 static uword NewContents(intptr_t capacity) { | 
| 17   Zone* zone = Isolate::Current()->current_zone(); | 17   Zone* zone = Isolate::Current()->current_zone(); | 
| 18   uword result = zone->Allocate(capacity); | 18   uword result = zone->AllocUnsafe(capacity); | 
| 19 #if defined(DEBUG) | 19 #if defined(DEBUG) | 
| 20   // Initialize the buffer with kBreakPointInstruction to force a break | 20   // Initialize the buffer with kBreakPointInstruction to force a break | 
| 21   // point if we ever execute an uninitialized part of the code buffer. | 21   // point if we ever execute an uninitialized part of the code buffer. | 
| 22   Assembler::InitializeMemoryWithBreakpoints(result, capacity); | 22   Assembler::InitializeMemoryWithBreakpoints(result, capacity); | 
| 23 #endif | 23 #endif | 
| 24   return result; | 24   return result; | 
| 25 } | 25 } | 
| 26 | 26 | 
| 27 | 27 | 
| 28 #if defined(DEBUG) | 28 #if defined(DEBUG) | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
| 41   ASSERT(!buffer->HasEnsuredCapacity());  // Cannot nest. | 41   ASSERT(!buffer->HasEnsuredCapacity());  // Cannot nest. | 
| 42   buffer->has_ensured_capacity_ = true; | 42   buffer->has_ensured_capacity_ = true; | 
| 43 } | 43 } | 
| 44 | 44 | 
| 45 | 45 | 
| 46 AssemblerBuffer::EnsureCapacity::~EnsureCapacity() { | 46 AssemblerBuffer::EnsureCapacity::~EnsureCapacity() { | 
| 47   // Unmark the buffer, so we cannot emit after this. | 47   // Unmark the buffer, so we cannot emit after this. | 
| 48   buffer_->has_ensured_capacity_ = false; | 48   buffer_->has_ensured_capacity_ = false; | 
| 49   // Make sure the generated instruction doesn't take up more | 49   // Make sure the generated instruction doesn't take up more | 
| 50   // space than the minimum gap. | 50   // space than the minimum gap. | 
| 51   int delta = gap_ - ComputeGap(); | 51   intptr_t delta = gap_ - ComputeGap(); | 
| 52   ASSERT(delta <= kMinimumGap); | 52   ASSERT(delta <= kMinimumGap); | 
| 53 } | 53 } | 
| 54 #endif | 54 #endif | 
| 55 | 55 | 
| 56 | 56 | 
| 57 AssemblerBuffer::AssemblerBuffer() | 57 AssemblerBuffer::AssemblerBuffer() | 
| 58     : pointer_offsets_(new ZoneGrowableArray<int>(16)) { | 58     : pointer_offsets_(new ZoneGrowableArray<int>(16)) { | 
| 59   static const int kInitialBufferCapacity = 4 * KB; | 59   static const intptr_t kInitialBufferCapacity = 4 * KB; | 
| 60   contents_ = NewContents(kInitialBufferCapacity); | 60   contents_ = NewContents(kInitialBufferCapacity); | 
| 61   cursor_ = contents_; | 61   cursor_ = contents_; | 
| 62   limit_ = ComputeLimit(contents_, kInitialBufferCapacity); | 62   limit_ = ComputeLimit(contents_, kInitialBufferCapacity); | 
| 63   fixup_ = NULL; | 63   fixup_ = NULL; | 
| 64 #if defined(DEBUG) | 64 #if defined(DEBUG) | 
| 65   has_ensured_capacity_ = false; | 65   has_ensured_capacity_ = false; | 
| 66   fixups_processed_ = false; | 66   fixups_processed_ = false; | 
| 67 #endif | 67 #endif | 
| 68 | 68 | 
| 69   // Verify internal state. | 69   // Verify internal state. | 
| (...skipping 22 matching lines...) Expand all  Loading... | 
| 92 | 92 | 
| 93   // Process fixups in the instructions. | 93   // Process fixups in the instructions. | 
| 94   ProcessFixups(instructions); | 94   ProcessFixups(instructions); | 
| 95 #if defined(DEBUG) | 95 #if defined(DEBUG) | 
| 96   fixups_processed_ = true; | 96   fixups_processed_ = true; | 
| 97 #endif | 97 #endif | 
| 98 } | 98 } | 
| 99 | 99 | 
| 100 | 100 | 
| 101 void AssemblerBuffer::ExtendCapacity() { | 101 void AssemblerBuffer::ExtendCapacity() { | 
| 102   int old_size = Size(); | 102   intptr_t old_size = Size(); | 
| 103   int old_capacity = Capacity(); | 103   intptr_t old_capacity = Capacity(); | 
| 104   int new_capacity = Utils::Minimum(old_capacity * 2, old_capacity + 1 * MB); | 104   intptr_t new_capacity = | 
|  | 105       Utils::Minimum(old_capacity * 2, old_capacity + 1 * MB); | 
|  | 106   if (new_capacity < old_capacity) { | 
|  | 107     FATAL("Unexpected overflow in AssemblerBuffer::ExtendCapacity"); | 
|  | 108   } | 
| 105 | 109 | 
| 106   // Allocate the new data area and copy contents of the old one to it. | 110   // Allocate the new data area and copy contents of the old one to it. | 
| 107   uword new_contents = NewContents(new_capacity); | 111   uword new_contents = NewContents(new_capacity); | 
| 108   memmove(reinterpret_cast<void*>(new_contents), | 112   memmove(reinterpret_cast<void*>(new_contents), | 
| 109           reinterpret_cast<void*>(contents_), | 113           reinterpret_cast<void*>(contents_), | 
| 110           old_size); | 114           old_size); | 
| 111 | 115 | 
| 112   // Compute the relocation delta and switch to the new contents area. | 116   // Compute the relocation delta and switch to the new contents area. | 
| 113   intptr_t delta = new_contents - contents_; | 117   intptr_t delta = new_contents - contents_; | 
| 114   contents_ = new_contents; | 118   contents_ = new_contents; | 
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 175 | 179 | 
| 176 void Assembler::Unreachable(const char* message) { | 180 void Assembler::Unreachable(const char* message) { | 
| 177   const char* format = "Unreachable: %s"; | 181   const char* format = "Unreachable: %s"; | 
| 178   const intptr_t len = OS::SNPrint(NULL, 0, format, message); | 182   const intptr_t len = OS::SNPrint(NULL, 0, format, message); | 
| 179   char* buffer = reinterpret_cast<char*>(malloc(len + 1)); | 183   char* buffer = reinterpret_cast<char*>(malloc(len + 1)); | 
| 180   OS::SNPrint(buffer, len + 1, format, message); | 184   OS::SNPrint(buffer, len + 1, format, message); | 
| 181   Stop(buffer); | 185   Stop(buffer); | 
| 182 } | 186 } | 
| 183 | 187 | 
| 184 }  // namespace dart | 188 }  // namespace dart | 
| OLD | NEW | 
|---|