OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_ZONE_ZONE_SEGMENT_H_ | 5 #ifndef V8_ZONE_ZONE_SEGMENT_H_ |
6 #define V8_ZONE_ZONE_SEGMENT_H_ | 6 #define V8_ZONE_ZONE_SEGMENT_H_ |
7 | 7 |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 // Segments represent chunks of memory: They have starting address | 10 // Segments represent chunks of memory: They have starting address |
11 // (encoded in the this pointer) and a size in bytes. Segments are | 11 // (encoded in the this pointer) and a size in bytes. Segments are |
12 // chained together forming a LIFO structure with the newest segment | 12 // chained together forming a LIFO structure with the newest segment |
13 // available as segment_head_. Segments are allocated using malloc() | 13 // available as segment_head_. Segments are allocated using malloc() |
14 // and de-allocated using free(). | 14 // and de-allocated using free(). |
15 namespace v8 { | 15 namespace v8 { |
16 namespace internal { | 16 namespace internal { |
17 | 17 |
18 // Forward declaration | 18 // Forward declaration |
19 class Zone; | 19 class Zone; |
20 | 20 |
21 class Segment { | 21 class Segment { |
22 public: | 22 public: |
23 void Initialize(Segment* next, size_t size, Zone* zone) { | 23 void Initialize(size_t size) { size_ = size; } |
24 next_ = next; | |
25 size_ = size; | |
26 zone_ = zone; | |
27 } | |
28 | 24 |
29 Zone* zone() const { return zone_; } | 25 Zone* zone() const { return zone_; } |
30 void set_zone(Zone* const zone) { zone_ = zone; } | 26 void set_zone(Zone* const zone) { zone_ = zone; } |
31 | 27 |
32 Segment* next() const { return next_; } | 28 Segment* next() const { return next_; } |
33 void set_next(Segment* const next) { next_ = next; } | 29 void set_next(Segment* const next) { next_ = next; } |
34 | 30 |
35 size_t size() const { return size_; } | 31 size_t size() const { return size_; } |
36 size_t capacity() const { return size_ - sizeof(Segment); } | 32 size_t capacity() const { return size_ - sizeof(Segment); } |
37 | 33 |
38 Address start() const { return address(sizeof(Segment)); } | 34 Address start() const { return address(sizeof(Segment)); } |
39 Address end() const { return address(size_); } | 35 Address end() const { return address(size_); } |
40 | 36 |
41 // Zap the contents of the segment (but not the header). | 37 // Zap the contents of the segment (but not the header). |
42 void ZapContents(); | 38 void ZapContents(); |
43 // Zaps the header and makes the segment unusable this way. | 39 // Zaps the header and makes the segment unusable this way. |
44 void ZapHeader(); | 40 void ZapHeader(); |
45 | 41 |
46 private: | 42 private: |
47 #ifdef DEBUG | 43 #ifdef DEBUG |
48 // Constant byte value used for zapping dead memory in debug mode. | 44 // Constant byte value used for zapping dead memory in debug mode. |
49 static const unsigned char kZapDeadByte = 0xcd; | 45 static const unsigned char kZapDeadByte = 0xcd; |
50 #endif | 46 #endif |
| 47 |
51 // Computes the address of the nth byte in this segment. | 48 // Computes the address of the nth byte in this segment. |
52 Address address(size_t n) const { return Address(this) + n; } | 49 Address address(size_t n) const { return Address(this) + n; } |
53 | 50 |
54 Zone* zone_; | 51 Zone* zone_; |
55 Segment* next_; | 52 Segment* next_; |
56 size_t size_; | 53 size_t size_; |
57 }; | 54 }; |
58 } // namespace internal | 55 } // namespace internal |
59 } // namespace v8 | 56 } // namespace v8 |
60 | 57 |
61 #endif // V8_ZONE_ZONE_SEGMENT_H_ | 58 #endif // V8_ZONE_ZONE_SEGMENT_H_ |
OLD | NEW |