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

Side by Side Diff: src/write-buffer.cc

Issue 5985012: Rename write buffers to store buffers. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/gc/
Patch Set: Created 9 years, 11 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
« no previous file with comments | « src/write-buffer.h ('k') | src/write-buffer-inl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2010 the V8 project authors. All rights reserved.
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 #include "v8-counters.h"
29 #include "write-buffer.h"
30 #include "write-buffer-inl.h"
31
32 namespace v8 {
33 namespace internal {
34
35 Address* WriteBuffer::start_ = NULL;
36 Address* WriteBuffer::limit_ = NULL;
37 uintptr_t* WriteBuffer::hash_map_1_ = NULL;
38 uintptr_t* WriteBuffer::hash_map_2_ = NULL;
39 VirtualMemory* WriteBuffer::virtual_memory_ = NULL;
40
41 void WriteBuffer::Setup() {
42 virtual_memory_ = new VirtualMemory(kWriteBufferSize * 3);
43 uintptr_t start_as_int =
44 reinterpret_cast<uintptr_t>(virtual_memory_->address());
45 start_ =
46 reinterpret_cast<Address*>(RoundUp(start_as_int, kWriteBufferSize * 2));
47 limit_ = start_ + (kWriteBufferSize / sizeof(*start_));
48
49 ASSERT(reinterpret_cast<Address>(start_) >= virtual_memory_->address());
50 ASSERT(reinterpret_cast<Address>(limit_) >= virtual_memory_->address());
51 Address* vm_limit = reinterpret_cast<Address*>(
52 reinterpret_cast<char*>(virtual_memory_->address()) +
53 virtual_memory_->size());
54 ASSERT(start_ <= vm_limit);
55 ASSERT(limit_ <= vm_limit);
56 USE(vm_limit);
57 ASSERT((reinterpret_cast<uintptr_t>(limit_) & kWriteBufferOverflowBit) != 0);
58 ASSERT((reinterpret_cast<uintptr_t>(limit_ - 1) & kWriteBufferOverflowBit) ==
59 0);
60
61 virtual_memory_->Commit(reinterpret_cast<Address>(start_),
62 kWriteBufferSize,
63 false); // Not executable.
64 Heap::public_set_write_buffer_top(start_);
65
66 hash_map_1_ = new uintptr_t[kHashMapLength];
67 hash_map_2_ = new uintptr_t[kHashMapLength];
68 }
69
70
71 void WriteBuffer::TearDown() {
72 delete virtual_memory_;
73 delete[] hash_map_1_;
74 delete[] hash_map_2_;
75 start_ = limit_ = NULL;
76 Heap::public_set_write_buffer_top(start_);
77 }
78
79
80 void WriteBuffer::Compact() {
81 memset(reinterpret_cast<void*>(hash_map_1_),
82 0,
83 sizeof(uintptr_t) * kHashMapLength);
84 memset(reinterpret_cast<void*>(hash_map_2_),
85 0,
86 sizeof(uintptr_t) * kHashMapLength);
87 Address* top = reinterpret_cast<Address*>(Heap::write_buffer_top());
88 Address* stop = top;
89 ASSERT(top <= limit_);
90 top = start_;
91 // Goes through the addresses in the write buffer attempting to remove
92 // duplicates. In the interest of speed this is a lossy operation. Some
93 // duplicates will remain. We have two hash tables with different hash
94 // functions to reduce the number of unnecessary clashes.
95 for (Address* current = start_; current < stop; current++) {
96 uintptr_t int_addr = reinterpret_cast<uintptr_t>(*current);
97 // Shift out the last bits including any tags.
98 int_addr >>= kPointerSizeLog2;
99 int hash1 =
100 ((int_addr ^ (int_addr >> kHashMapLengthLog2)) & (kHashMapLength - 1));
101 if (hash_map_1_[hash1] == int_addr) continue;
102 int hash2 =
103 ((int_addr - (int_addr >> kHashMapLengthLog2)) & (kHashMapLength - 1));
104 hash2 ^= hash2 >> (kHashMapLengthLog2 * 2);
105 if (hash_map_2_[hash2] == int_addr) continue;
106 if (hash_map_1_[hash1] == 0) {
107 hash_map_1_[hash1] = int_addr;
108 } else if (hash_map_2_[hash2] == 0) {
109 hash_map_2_[hash2] = int_addr;
110 } else {
111 // Rather than slowing down we just throw away some entries. This will
112 // cause some duplicates to remain undetected.
113 hash_map_1_[hash1] = int_addr;
114 hash_map_2_[hash2] = 0;
115 }
116 ASSERT(top <= current);
117 ASSERT(top <= limit_);
118 *top++ = reinterpret_cast<Address>(int_addr << kPointerSizeLog2);
119 }
120 Counters::write_buffer_compactions.Increment();
121 if (limit_ - top < top - start_) {
122 // Compression did not free up at least half.
123 // TODO(gc): Set an interrupt to do a GC on the next back edge.
124 // TODO(gc): Allocate the rest of new space to force a GC on the next
125 // allocation.
126 if (limit_ - top < (top - start_) >> 1) {
127 // Compression did not free up at least one quarter.
128 // TODO(gc): Set a flag to scan all of memory.
129 top = start_;
130 Counters::write_buffer_overflows.Increment();
131 }
132 }
133 Heap::public_set_write_buffer_top(top);
134 }
135
136 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/write-buffer.h ('k') | src/write-buffer-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698