| 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 #ifndef VM_ZONE_H_ |    5 #ifndef VM_ZONE_H_ | 
|    6 #define VM_ZONE_H_ |    6 #define VM_ZONE_H_ | 
|    7  |    7  | 
|    8 #include "platform/utils.h" |    8 #include "platform/utils.h" | 
|    9 #include "vm/allocation.h" |    9 #include "vm/allocation.h" | 
|   10 #include "vm/handles.h" |   10 #include "vm/handles.h" | 
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   84   class Segment; |   84   class Segment; | 
|   85  |   85  | 
|   86   // The current head segment; may be NULL. |   86   // The current head segment; may be NULL. | 
|   87   Segment* head_; |   87   Segment* head_; | 
|   88  |   88  | 
|   89   // List of large segments allocated in this zone; may be NULL. |   89   // List of large segments allocated in this zone; may be NULL. | 
|   90   Segment* large_segments_; |   90   Segment* large_segments_; | 
|   91  |   91  | 
|   92   friend class Zone; |   92   friend class Zone; | 
|   93   friend class ApiZone; |   93   friend class ApiZone; | 
 |   94   template<typename T, typename B> friend class BaseGrowableArray; | 
|   94   DISALLOW_COPY_AND_ASSIGN(BaseZone); |   95   DISALLOW_COPY_AND_ASSIGN(BaseZone); | 
|   95 }; |   96 }; | 
|   96  |   97  | 
|   97  |   98  | 
|   98 class Zone : public StackResource { |   99 class Zone : public StackResource { | 
|   99  public: |  100  public: | 
|  100   // Create an empty zone and set is at the current zone for the Isolate. |  101   // Create an empty zone and set is at the current zone for the Isolate. | 
|  101   explicit Zone(Isolate* isolate); |  102   explicit Zone(Isolate* isolate); | 
|  102  |  103  | 
|  103   // Delete all memory associated with the zone. |  104   // Delete all memory associated with the zone. | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
|  120   // Make a copy of the string in the zone allocated area. |  121   // Make a copy of the string in the zone allocated area. | 
|  121   char* MakeCopyOfString(const char* str) { |  122   char* MakeCopyOfString(const char* str) { | 
|  122     return zone_.MakeCopyOfString(str); |  123     return zone_.MakeCopyOfString(str); | 
|  123   } |  124   } | 
|  124  |  125  | 
|  125   VMHandles* handles() { return &handles_; } |  126   VMHandles* handles() { return &handles_; } | 
|  126  |  127  | 
|  127   void VisitObjectPointers(ObjectPointerVisitor* visitor); |  128   void VisitObjectPointers(ObjectPointerVisitor* visitor); | 
|  128  |  129  | 
|  129  private: |  130  private: | 
 |  131   BaseZone* GetBaseZone() { return &zone_; } | 
 |  132  | 
|  130   BaseZone zone_; |  133   BaseZone zone_; | 
|  131  |  134  | 
|  132   // Structure for managing handles allocation. |  135   // Structure for managing handles allocation. | 
|  133   VMHandles handles_; |  136   VMHandles handles_; | 
|  134  |  137  | 
|  135   // Used for chaining zones in order to allow unwinding of stacks. |  138   // Used for chaining zones in order to allow unwinding of stacks. | 
|  136   Zone* previous_; |  139   Zone* previous_; | 
 |  140  | 
 |  141   template<typename T> friend class GrowableArray; | 
 |  142   template<typename T> friend class ZoneGrowableArray; | 
 |  143  | 
|  137   DISALLOW_IMPLICIT_CONSTRUCTORS(Zone); |  144   DISALLOW_IMPLICIT_CONSTRUCTORS(Zone); | 
|  138 }; |  145 }; | 
|  139  |  146  | 
|  140  |  147  | 
|  141 inline uword BaseZone::Allocate(intptr_t size) { |  148 inline uword BaseZone::Allocate(intptr_t size) { | 
|  142   ASSERT(size >= 0); |  149   ASSERT(size >= 0); | 
|  143  |  150  | 
|  144   // Round up the requested size to fit the alignment. |  151   // Round up the requested size to fit the alignment. | 
|  145   size = Utils::RoundUp(size, kAlignment); |  152   size = Utils::RoundUp(size, kAlignment); | 
|  146  |  153  | 
|  147   // Check if the requested size is available without expanding. |  154   // Check if the requested size is available without expanding. | 
|  148   uword result; |  155   uword result; | 
|  149   intptr_t free_size = (limit_ - position_); |  156   intptr_t free_size = (limit_ - position_); | 
|  150   if (free_size >= size) { |  157   if (free_size >= size) { | 
|  151     result = position_; |  158     result = position_; | 
|  152     position_ += size; |  159     position_ += size; | 
|  153   } else { |  160   } else { | 
|  154     result = AllocateExpand(size); |  161     result = AllocateExpand(size); | 
|  155   } |  162   } | 
|  156  |  163  | 
|  157   // Check that the result has the proper alignment and return it. |  164   // Check that the result has the proper alignment and return it. | 
|  158   ASSERT(Utils::IsAligned(result, kAlignment)); |  165   ASSERT(Utils::IsAligned(result, kAlignment)); | 
|  159   return result; |  166   return result; | 
|  160 } |  167 } | 
|  161  |  168  | 
|  162 }  // namespace dart |  169 }  // namespace dart | 
|  163  |  170  | 
|  164 #endif  // VM_ZONE_H_ |  171 #endif  // VM_ZONE_H_ | 
| OLD | NEW |