| 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/zone.h" | 5 #include "vm/zone.h" |
| 6 | 6 |
| 7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
| 8 #include "platform/utils.h" | 8 #include "platform/utils.h" |
| 9 #include "vm/flags.h" | 9 #include "vm/flags.h" |
| 10 #include "vm/handles_impl.h" | 10 #include "vm/handles_impl.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 static Segment* New(intptr_t size, Segment* next); | 28 static Segment* New(intptr_t size, Segment* next); |
| 29 static void DeleteSegmentList(Segment* segment); | 29 static void DeleteSegmentList(Segment* segment); |
| 30 | 30 |
| 31 private: | 31 private: |
| 32 Segment* next_; | 32 Segment* next_; |
| 33 intptr_t size_; | 33 intptr_t size_; |
| 34 | 34 |
| 35 // Computes the address of the nth byte in this segment. | 35 // Computes the address of the nth byte in this segment. |
| 36 uword address(int n) { return reinterpret_cast<uword>(this) + n; } | 36 uword address(int n) { return reinterpret_cast<uword>(this) + n; } |
| 37 | 37 |
| 38 static void Delete(Segment* segment) { delete[] segment; } | 38 static void Delete(Segment* segment) { free(segment); } |
| 39 | 39 |
| 40 DISALLOW_IMPLICIT_CONSTRUCTORS(Segment); | 40 DISALLOW_IMPLICIT_CONSTRUCTORS(Segment); |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 | 43 |
| 44 void Zone::Segment::DeleteSegmentList(Segment* head) { | 44 void Zone::Segment::DeleteSegmentList(Segment* head) { |
| 45 Segment* current = head; | 45 Segment* current = head; |
| 46 while (current != NULL) { | 46 while (current != NULL) { |
| 47 Segment* next = current->next(); | 47 Segment* next = current->next(); |
| 48 #ifdef DEBUG | 48 #ifdef DEBUG |
| 49 // Zap the entire current segment (including the header). | 49 // Zap the entire current segment (including the header). |
| 50 memset(current, kZapDeletedByte, current->size()); | 50 memset(current, kZapDeletedByte, current->size()); |
| 51 #endif | 51 #endif |
| 52 Segment::Delete(current); | 52 Segment::Delete(current); |
| 53 current = next; | 53 current = next; |
| 54 } | 54 } |
| 55 } | 55 } |
| 56 | 56 |
| 57 | 57 |
| 58 Zone::Segment* Zone::Segment::New(intptr_t size, Zone::Segment* next) { | 58 Zone::Segment* Zone::Segment::New(intptr_t size, Zone::Segment* next) { |
| 59 ASSERT(size >= 0); | 59 ASSERT(size >= 0); |
| 60 Segment* result = reinterpret_cast<Segment*>(new uint8_t[size]); | 60 Segment* result = reinterpret_cast<Segment*>(malloc(size)); |
| 61 if (result == NULL) { |
| 62 FATAL("Out of memory.\n"); |
| 63 } |
| 61 ASSERT(Utils::IsAligned(result->start(), Zone::kAlignment)); | 64 ASSERT(Utils::IsAligned(result->start(), Zone::kAlignment)); |
| 62 if (result != NULL) { | |
| 63 #ifdef DEBUG | 65 #ifdef DEBUG |
| 64 // Zap the entire allocated segment (including the header). | 66 // Zap the entire allocated segment (including the header). |
| 65 memset(result, kZapUninitializedByte, size); | 67 memset(result, kZapUninitializedByte, size); |
| 66 #endif | 68 #endif |
| 67 result->next_ = next; | 69 result->next_ = next; |
| 68 result->size_ = size; | 70 result->size_ = size; |
| 69 } | |
| 70 return result; | 71 return result; |
| 71 } | 72 } |
| 72 | 73 |
| 73 | 74 |
| 74 void Zone::DeleteAll() { | 75 void Zone::DeleteAll() { |
| 75 // Traverse the chained list of segments, zapping (in debug mode) | 76 // Traverse the chained list of segments, zapping (in debug mode) |
| 76 // and freeing every zone segment. | 77 // and freeing every zone segment. |
| 77 if (head_ != NULL) { | 78 if (head_ != NULL) { |
| 78 Segment::DeleteSegmentList(head_); | 79 Segment::DeleteSegmentList(head_); |
| 79 } | 80 } |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 return buffer; | 228 return buffer; |
| 228 } | 229 } |
| 229 | 230 |
| 230 | 231 |
| 231 char* Zone::VPrint(const char* format, va_list args) { | 232 char* Zone::VPrint(const char* format, va_list args) { |
| 232 return OS::VSCreate(this, format, args); | 233 return OS::VSCreate(this, format, args); |
| 233 } | 234 } |
| 234 | 235 |
| 235 | 236 |
| 236 } // namespace dart | 237 } // namespace dart |
| OLD | NEW |