Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Side by Side Diff: src/zone.cc

Issue 2493002: - Remove [static] from methods in Zone and associated helpers. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/isolates/
Patch Set: '' Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 16 matching lines...) Expand all
27 27
28 #include "v8.h" 28 #include "v8.h"
29 29
30 #include "zone-inl.h" 30 #include "zone-inl.h"
31 #include "splay-tree-inl.h" 31 #include "splay-tree-inl.h"
32 32
33 namespace v8 { 33 namespace v8 {
34 namespace internal { 34 namespace internal {
35 35
36 36
37 Address Zone::position_ = 0; 37 int ZoneScope::nesting_ = 0;
38 Address Zone::limit_ = 0;
39 int Zone::zone_excess_limit_ = 256 * MB;
40 int Zone::segment_bytes_allocated_ = 0;
41 38
42 bool AssertNoZoneAllocation::allow_allocation_ = true; 39 Zone::Zone()
40 : zone_excess_limit_(256 * MB),
41 segment_bytes_allocated_(0),
42 position_(0),
43 limit_(0) {
44 }
43 45
44 int ZoneScope::nesting_ = 0; 46
47 ZoneScope::~ZoneScope() {
48 if (ShouldDeleteOnExit()) ZONE->DeleteAll();
49 --nesting_;
50 }
51
45 52
46 // Segments represent chunks of memory: They have starting address 53 // Segments represent chunks of memory: They have starting address
47 // (encoded in the this pointer) and a size in bytes. Segments are 54 // (encoded in the this pointer) and a size in bytes. Segments are
48 // chained together forming a LIFO structure with the newest segment 55 // chained together forming a LIFO structure with the newest segment
49 // available as Segment::head(). Segments are allocated using malloc() 56 // available as Segment::head(). Segments are allocated using malloc()
50 // and de-allocated using free(). 57 // and de-allocated using free().
51 58
52 class Segment { 59 class Segment {
53 public: 60 public:
54 Segment* next() const { return next_; } 61 Segment* next() const { return next_; }
55 void clear_next() { next_ = NULL; } 62 void clear_next() { next_ = NULL; }
56 63
57 int size() const { return size_; } 64 int size() const { return size_; }
58 int capacity() const { return size_ - sizeof(Segment); } 65 int capacity() const { return size_ - sizeof(Segment); }
59 66
60 Address start() const { return address(sizeof(Segment)); } 67 Address start() const { return address(sizeof(Segment)); }
61 Address end() const { return address(size_); } 68 Address end() const { return address(size_); }
62 69
63 static Segment* head() { return head_; } 70 static Segment* head() { return head_; }
64 static void set_head(Segment* head) { head_ = head; } 71 static void set_head(Segment* head) { head_ = head; }
65 72
66 // Creates a new segment, sets it size, and pushes it to the front 73 // Creates a new segment, sets it size, and pushes it to the front
67 // of the segment chain. Returns the new segment. 74 // of the segment chain. Returns the new segment.
68 static Segment* New(int size) { 75 static Segment* New(int size) {
69 Segment* result = reinterpret_cast<Segment*>(Malloced::New(size)); 76 Segment* result = reinterpret_cast<Segment*>(Malloced::New(size));
70 Zone::adjust_segment_bytes_allocated(size); 77 ZONE->adjust_segment_bytes_allocated(size);
71 if (result != NULL) { 78 if (result != NULL) {
72 result->next_ = head_; 79 result->next_ = head_;
73 result->size_ = size; 80 result->size_ = size;
74 head_ = result; 81 head_ = result;
75 } 82 }
76 return result; 83 return result;
77 } 84 }
78 85
79 // Deletes the given segment. Does not touch the segment chain. 86 // Deletes the given segment. Does not touch the segment chain.
80 static void Delete(Segment* segment, int size) { 87 static void Delete(Segment* segment, int size) {
81 Zone::adjust_segment_bytes_allocated(-size); 88 ZONE->adjust_segment_bytes_allocated(-size);
82 Malloced::Delete(segment); 89 Malloced::Delete(segment);
83 } 90 }
84 91
85 static int bytes_allocated() { return bytes_allocated_; } 92 static int bytes_allocated() { return bytes_allocated_; }
86 93
87 private: 94 private:
88 // Computes the address of the nth byte in this segment. 95 // Computes the address of the nth byte in this segment.
89 Address address(int n) const { 96 Address address(int n) const {
90 return Address(this) + n; 97 return Address(this) + n;
91 } 98 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 // Recompute 'top' and 'limit' based on the new segment. 192 // Recompute 'top' and 'limit' based on the new segment.
186 Address result = RoundUp(segment->start(), kAlignment); 193 Address result = RoundUp(segment->start(), kAlignment);
187 position_ = result + size; 194 position_ = result + size;
188 limit_ = segment->end(); 195 limit_ = segment->end();
189 ASSERT(position_ <= limit_); 196 ASSERT(position_ <= limit_);
190 return result; 197 return result;
191 } 198 }
192 199
193 200
194 } } // namespace v8::internal 201 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698