| 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 18 matching lines...) Expand all Loading... |
| 29 #define V8_ZONE_INL_H_ | 29 #define V8_ZONE_INL_H_ |
| 30 | 30 |
| 31 #include "zone.h" | 31 #include "zone.h" |
| 32 #include "v8-counters.h" | 32 #include "v8-counters.h" |
| 33 | 33 |
| 34 namespace v8 { | 34 namespace v8 { |
| 35 namespace internal { | 35 namespace internal { |
| 36 | 36 |
| 37 | 37 |
| 38 inline void* Zone::New(int size) { | 38 inline void* Zone::New(int size) { |
| 39 ASSERT(AssertNoZoneAllocation::allow_allocation()); | 39 ZoneData& zone_data = v8_context()->zone_data_; |
| 40 ASSERT(ZoneScope::nesting() > 0); | 40 ASSERT(AssertNoZoneAllocation::allow_allocation(zone_data)); |
| 41 ASSERT(ZoneScope::nesting(zone_data) > 0); |
| 41 // Round up the requested size to fit the alignment. | 42 // Round up the requested size to fit the alignment. |
| 42 size = RoundUp(size, kAlignment); | 43 size = RoundUp(size, kAlignment); |
| 43 | 44 |
| 44 // Check if the requested size is available without expanding. | 45 // Check if the requested size is available without expanding. |
| 45 Address result = position_; | 46 Address result = zone_data.position_; |
| 46 if ((position_ += size) > limit_) result = NewExpand(size); | 47 if ((zone_data.position_ += size) > zone_data.limit_) |
| 48 result = NewExpand(size); |
| 47 | 49 |
| 48 // Check that the result has the proper alignment and return it. | 50 // Check that the result has the proper alignment and return it. |
| 49 ASSERT(IsAddressAligned(result, kAlignment, 0)); | 51 ASSERT(IsAddressAligned(result, kAlignment, 0)); |
| 50 return reinterpret_cast<void*>(result); | 52 return reinterpret_cast<void*>(result); |
| 51 } | 53 } |
| 52 | 54 |
| 53 | 55 |
| 54 template <typename T> | 56 template <typename T> |
| 55 T* Zone::NewArray(int length) { | 57 T* Zone::NewArray(int length) { |
| 56 return static_cast<T*>(Zone::New(length * sizeof(T))); | 58 return static_cast<T*>(Zone::New(length * sizeof(T))); |
| 57 } | 59 } |
| 58 | 60 |
| 59 | 61 |
| 60 bool Zone::excess_allocation() { | 62 bool Zone::excess_allocation() { |
| 61 return segment_bytes_allocated_ > zone_excess_limit_; | 63 ZoneData& zone_data = v8_context()->zone_data_; |
| 64 return zone_data.segment_bytes_allocated_ > zone_data.zone_excess_limit_; |
| 62 } | 65 } |
| 63 | 66 |
| 64 | 67 |
| 65 void Zone::adjust_segment_bytes_allocated(int delta) { | 68 void Zone::adjust_segment_bytes_allocated(int delta) { |
| 66 segment_bytes_allocated_ += delta; | 69 V8Context* const v8context = v8_context(); |
| 67 Counters::zone_segment_bytes.Set(segment_bytes_allocated_); | 70 ZoneData& zone_data = v8context->zone_data_; |
| 71 zone_data.segment_bytes_allocated_ += delta; |
| 72 COUNTER(zone_segment_bytes).Set(zone_data.segment_bytes_allocated_); |
| 68 } | 73 } |
| 69 | 74 |
| 70 | 75 |
| 71 template <typename C> | 76 template <typename C> |
| 72 bool ZoneSplayTree<C>::Insert(const Key& key, Locator* locator) { | 77 bool ZoneSplayTree<C>::Insert(const Key& key, Locator* locator) { |
| 73 if (is_empty()) { | 78 if (is_empty()) { |
| 74 // If the tree is empty, insert the new node. | 79 // If the tree is empty, insert the new node. |
| 75 root_ = new Node(key, C::kNoValue); | 80 root_ = new Node(key, C::kNoValue); |
| 76 } else { | 81 } else { |
| 77 // Splay on the key to move the last node on the search path | 82 // Splay on the key to move the last node on the search path |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 callback->Call(node->key(), node->value()); | 293 callback->Call(node->key(), node->value()); |
| 289 nodes_to_visit.Add(node->left()); | 294 nodes_to_visit.Add(node->left()); |
| 290 nodes_to_visit.Add(node->right()); | 295 nodes_to_visit.Add(node->right()); |
| 291 } | 296 } |
| 292 } | 297 } |
| 293 | 298 |
| 294 | 299 |
| 295 } } // namespace v8::internal | 300 } } // namespace v8::internal |
| 296 | 301 |
| 297 #endif // V8_ZONE_INL_H_ | 302 #endif // V8_ZONE_INL_H_ |
| OLD | NEW |