OLD | NEW |
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 Top::TearDown(); | 148 Top::TearDown(); |
149 | 149 |
150 Heap::TearDown(); | 150 Heap::TearDown(); |
151 Logger::TearDown(); | 151 Logger::TearDown(); |
152 | 152 |
153 is_running_ = false; | 153 is_running_ = false; |
154 has_been_disposed_ = true; | 154 has_been_disposed_ = true; |
155 } | 155 } |
156 | 156 |
157 | 157 |
| 158 static uint32_t random_seed() { |
| 159 if (FLAG_random_seed == 0) { |
| 160 return random(); |
| 161 } |
| 162 return FLAG_random_seed; |
| 163 } |
| 164 |
| 165 |
158 uint32_t V8::Random() { | 166 uint32_t V8::Random() { |
159 // Random number generator using George Marsaglia's MWC algorithm. | 167 // Random number generator using George Marsaglia's MWC algorithm. |
160 static uint32_t hi = 0; | 168 static uint32_t hi = 0; |
161 static uint32_t lo = 0; | 169 static uint32_t lo = 0; |
162 | 170 |
163 // Initialize seed using the system random(). If one of the seeds | 171 // Initialize seed using the system random(). If one of the seeds |
164 // should ever become zero again, or if random() returns zero, we | 172 // should ever become zero again, or if random() returns zero, we |
165 // avoid getting stuck with zero bits in hi or lo by re-initializing | 173 // avoid getting stuck with zero bits in hi or lo by re-initializing |
166 // them on demand. | 174 // them on demand. |
167 if (hi == 0) hi = random(); | 175 if (hi == 0) hi = random_seed(); |
168 if (lo == 0) lo = random(); | 176 if (lo == 0) lo = random_seed(); |
169 | 177 |
170 // Mix the bits. | 178 // Mix the bits. |
171 hi = 36969 * (hi & 0xFFFF) + (hi >> 16); | 179 hi = 36969 * (hi & 0xFFFF) + (hi >> 16); |
172 lo = 18273 * (lo & 0xFFFF) + (lo >> 16); | 180 lo = 18273 * (lo & 0xFFFF) + (lo >> 16); |
173 return (hi << 16) + (lo & 0xFFFF); | 181 return (hi << 16) + (lo & 0xFFFF); |
174 } | 182 } |
175 | 183 |
176 | 184 |
177 bool V8::IdleNotification() { | 185 bool V8::IdleNotification() { |
178 // Returning true tells the caller that there is no need to call | 186 // Returning true tells the caller that there is no need to call |
179 // IdleNotification again. | 187 // IdleNotification again. |
180 if (!FLAG_use_idle_notification) return true; | 188 if (!FLAG_use_idle_notification) return true; |
181 | 189 |
182 // Tell the heap that it may want to adjust. | 190 // Tell the heap that it may want to adjust. |
183 return Heap::IdleNotification(); | 191 return Heap::IdleNotification(); |
184 } | 192 } |
185 | 193 |
186 static const uint32_t kRandomPositiveSmiMax = 0x3fffffff; | 194 static const uint32_t kRandomPositiveSmiMax = 0x3fffffff; |
187 | 195 |
188 Smi* V8::RandomPositiveSmi() { | 196 Smi* V8::RandomPositiveSmi() { |
189 uint32_t random = Random(); | 197 uint32_t random = Random(); |
190 ASSERT(static_cast<uint32_t>(Smi::kMaxValue) >= kRandomPositiveSmiMax); | 198 ASSERT(static_cast<uint32_t>(Smi::kMaxValue) >= kRandomPositiveSmiMax); |
191 // kRandomPositiveSmiMax must match the value being divided | 199 // kRandomPositiveSmiMax must match the value being divided |
192 // by in math.js. | 200 // by in math.js. |
193 return Smi::FromInt(random & kRandomPositiveSmiMax); | 201 return Smi::FromInt(random & kRandomPositiveSmiMax); |
194 } | 202 } |
195 | 203 |
196 } } // namespace v8::internal | 204 } } // namespace v8::internal |
OLD | NEW |