blob: 5893a2f80ebbe97178e199a127049d53ae4eac77 [file] [log] [blame]
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001// Copyright 2006-2008 the V8 project authors. All rights reserved.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002// 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.orga74f0da2008-12-03 16:05:52 +000032#include "v8-counters.h"
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000033
kasperl@chromium.org71affb52009-05-26 05:44:31 +000034namespace v8 {
35namespace internal {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000036
37
38inline void* Zone::New(int size) {
39 ASSERT(AssertNoZoneAllocation::allow_allocation());
ager@chromium.orga74f0da2008-12-03 16:05:52 +000040 ASSERT(ZoneScope::nesting() > 0);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000041 // 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.org41826e72009-03-30 13:30:57 +000054template <typename T>
55T* Zone::NewArray(int length) {
56 return static_cast<T*>(Zone::New(length * sizeof(T)));
57}
58
59
ager@chromium.orga74f0da2008-12-03 16:05:52 +000060bool Zone::excess_allocation() {
61 return segment_bytes_allocated_ > zone_excess_limit_;
62}
63
64
65void 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.orgce5e87b2010-03-10 10:24:18 +000071template <typename Config>
72ZoneSplayTree<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.org0b6db592009-07-30 14:48:31 +000077}
78
79
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000080} } // namespace v8::internal
81
82#endif // V8_ZONE_INL_H_