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

Side by Side Diff: src/v8.cc

Issue 5188006: Push version 2.5.7 to trunk.... (Closed) Base URL: http://v8.googlecode.com/svn/trunk/
Patch Set: Created 10 years, 1 month 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/v8.h ('k') | src/v8globals.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 26 matching lines...) Expand all
37 #include "log.h" 37 #include "log.h"
38 38
39 namespace v8 { 39 namespace v8 {
40 namespace internal { 40 namespace internal {
41 41
42 bool V8::is_running_ = false; 42 bool V8::is_running_ = false;
43 bool V8::has_been_setup_ = false; 43 bool V8::has_been_setup_ = false;
44 bool V8::has_been_disposed_ = false; 44 bool V8::has_been_disposed_ = false;
45 bool V8::has_fatal_error_ = false; 45 bool V8::has_fatal_error_ = false;
46 46
47
47 bool V8::Initialize(Deserializer* des) { 48 bool V8::Initialize(Deserializer* des) {
48 bool create_heap_objects = des == NULL; 49 bool create_heap_objects = des == NULL;
49 if (has_been_disposed_ || has_fatal_error_) return false; 50 if (has_been_disposed_ || has_fatal_error_) return false;
50 if (IsRunning()) return true; 51 if (IsRunning()) return true;
51 52
52 is_running_ = true; 53 is_running_ = true;
53 has_been_setup_ = true; 54 has_been_setup_ = true;
54 has_fatal_error_ = false; 55 has_fatal_error_ = false;
55 has_been_disposed_ = false; 56 has_been_disposed_ = false;
56 #ifdef DEBUG 57 #ifdef DEBUG
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 170
170 171
171 static uint32_t random_seed() { 172 static uint32_t random_seed() {
172 if (FLAG_random_seed == 0) { 173 if (FLAG_random_seed == 0) {
173 return random(); 174 return random();
174 } 175 }
175 return FLAG_random_seed; 176 return FLAG_random_seed;
176 } 177 }
177 178
178 179
179 uint32_t V8::Random() { 180 typedef struct {
180 // Random number generator using George Marsaglia's MWC algorithm. 181 uint32_t hi;
181 static uint32_t hi = 0; 182 uint32_t lo;
182 static uint32_t lo = 0; 183 } random_state;
183 184
185
186 // Random number generator using George Marsaglia's MWC algorithm.
187 static uint32_t random_base(random_state *state) {
184 // Initialize seed using the system random(). If one of the seeds 188 // Initialize seed using the system random(). If one of the seeds
185 // should ever become zero again, or if random() returns zero, we 189 // should ever become zero again, or if random() returns zero, we
186 // avoid getting stuck with zero bits in hi or lo by re-initializing 190 // avoid getting stuck with zero bits in hi or lo by re-initializing
187 // them on demand. 191 // them on demand.
188 if (hi == 0) hi = random_seed(); 192 if (state->hi == 0) state->hi = random_seed();
189 if (lo == 0) lo = random_seed(); 193 if (state->lo == 0) state->lo = random_seed();
190 194
191 // Mix the bits. 195 // Mix the bits.
192 hi = 36969 * (hi & 0xFFFF) + (hi >> 16); 196 state->hi = 36969 * (state->hi & 0xFFFF) + (state->hi >> 16);
193 lo = 18273 * (lo & 0xFFFF) + (lo >> 16); 197 state->lo = 18273 * (state->lo & 0xFFFF) + (state->lo >> 16);
194 return (hi << 16) + (lo & 0xFFFF); 198 return (state->hi << 16) + (state->lo & 0xFFFF);
199 }
200
201
202 // Used by JavaScript APIs
203 uint32_t V8::Random() {
204 static random_state state = {0, 0};
205 return random_base(&state);
206 }
207
208
209 // Used internally by the JIT and memory allocator for security
210 // purposes. So, we keep a different state to prevent informations
211 // leaks that could be used in an exploit.
212 uint32_t V8::RandomPrivate() {
213 static random_state state = {0, 0};
214 return random_base(&state);
195 } 215 }
196 216
197 217
198 bool V8::IdleNotification() { 218 bool V8::IdleNotification() {
199 // Returning true tells the caller that there is no need to call 219 // Returning true tells the caller that there is no need to call
200 // IdleNotification again. 220 // IdleNotification again.
201 if (!FLAG_use_idle_notification) return true; 221 if (!FLAG_use_idle_notification) return true;
202 222
203 // Tell the heap that it may want to adjust. 223 // Tell the heap that it may want to adjust.
204 return Heap::IdleNotification(); 224 return Heap::IdleNotification();
(...skipping 18 matching lines...) Expand all
223 // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)). 243 // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)).
224 const double binary_million = 1048576.0; 244 const double binary_million = 1048576.0;
225 r->double_value = binary_million; 245 r->double_value = binary_million;
226 r->uint64_t_value |= random_bits; 246 r->uint64_t_value |= random_bits;
227 r->double_value -= binary_million; 247 r->double_value -= binary_million;
228 248
229 return heap_number; 249 return heap_number;
230 } 250 }
231 251
232 } } // namespace v8::internal 252 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/v8.h ('k') | src/v8globals.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698