ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1 | // Copyright 2006-2008 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #ifndef V8_ZONE_INL_H_ |
| 29 | #define V8_ZONE_INL_H_ |
| 30 | |
| 31 | #include "zone.h" |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 32 | #include "v8-counters.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 33 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 34 | namespace v8 { |
| 35 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 36 | |
| 37 | |
| 38 | inline void* Zone::New(int size) { |
| 39 | ASSERT(AssertNoZoneAllocation::allow_allocation()); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 40 | ASSERT(ZoneScope::nesting() > 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 41 | // Round up the requested size to fit the alignment. |
| 42 | size = RoundUp(size, kAlignment); |
| 43 | |
| 44 | // Check if the requested size is available without expanding. |
| 45 | Address result = position_; |
| 46 | if ((position_ += size) > limit_) result = NewExpand(size); |
| 47 | |
| 48 | // Check that the result has the proper alignment and return it. |
| 49 | ASSERT(IsAddressAligned(result, kAlignment, 0)); |
| 50 | return reinterpret_cast<void*>(result); |
| 51 | } |
| 52 | |
| 53 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 54 | template <typename T> |
| 55 | T* Zone::NewArray(int length) { |
| 56 | return static_cast<T*>(Zone::New(length * sizeof(T))); |
| 57 | } |
| 58 | |
| 59 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 60 | bool Zone::excess_allocation() { |
| 61 | return segment_bytes_allocated_ > zone_excess_limit_; |
| 62 | } |
| 63 | |
| 64 | |
| 65 | void Zone::adjust_segment_bytes_allocated(int delta) { |
| 66 | segment_bytes_allocated_ += delta; |
| 67 | Counters::zone_segment_bytes.Set(segment_bytes_allocated_); |
| 68 | } |
| 69 | |
| 70 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 71 | template <typename Config> |
| 72 | ZoneSplayTree<Config>::~ZoneSplayTree() { |
| 73 | // Reset the root to avoid unneeded iteration over all tree nodes |
| 74 | // in the destructor. For a zone-allocated tree, nodes will be |
| 75 | // freed by the Zone. |
| 76 | SplayTree<Config, ZoneListAllocationPolicy>::ResetRoot(); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 80 | } } // namespace v8::internal |
| 81 | |
| 82 | #endif // V8_ZONE_INL_H_ |