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

Side by Side Diff: src/v8.cc

Issue 7348008: Merge up to 8597 to experimental/gc from the bleeding edge. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/gc/
Patch Set: '' Created 9 years, 5 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/v8.h ('k') | src/v8-counters.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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 ASSERT(isolate->IsDefaultIsolate()); 94 ASSERT(isolate->IsDefaultIsolate());
95 95
96 if (!has_been_setup_ || has_been_disposed_) return; 96 if (!has_been_setup_ || has_been_disposed_) return;
97 isolate->TearDown(); 97 isolate->TearDown();
98 98
99 is_running_ = false; 99 is_running_ = false;
100 has_been_disposed_ = true; 100 has_been_disposed_ = true;
101 } 101 }
102 102
103 103
104 static uint32_t random_seed() { 104 static void seed_random(uint32_t* state) {
105 if (FLAG_random_seed == 0) { 105 for (int i = 0; i < 2; ++i) {
106 return random(); 106 state[i] = FLAG_random_seed;
107 while (state[i] == 0) {
108 state[i] = random();
109 }
107 } 110 }
108 return FLAG_random_seed;
109 } 111 }
110 112
111 113
112 typedef struct { 114 // Random number generator using George Marsaglia's MWC algorithm.
113 uint32_t hi; 115 static uint32_t random_base(uint32_t* state) {
114 uint32_t lo; 116 // Initialize seed using the system random().
115 } random_state; 117 // No non-zero seed will ever become zero again.
118 if (state[0] == 0) seed_random(state);
116 119
120 // Mix the bits. Never replaces state[i] with 0 if it is nonzero.
121 state[0] = 18273 * (state[0] & 0xFFFF) + (state[0] >> 16);
122 state[1] = 36969 * (state[1] & 0xFFFF) + (state[1] >> 16);
117 123
118 // Random number generator using George Marsaglia's MWC algorithm. 124 return (state[0] << 14) + (state[1] & 0x3FFFF);
119 static uint32_t random_base(random_state *state) {
120 // Initialize seed using the system random(). If one of the seeds
121 // should ever become zero again, or if random() returns zero, we
122 // avoid getting stuck with zero bits in hi or lo by re-initializing
123 // them on demand.
124 if (state->hi == 0) state->hi = random_seed();
125 if (state->lo == 0) state->lo = random_seed();
126
127 // Mix the bits.
128 state->hi = 36969 * (state->hi & 0xFFFF) + (state->hi >> 16);
129 state->lo = 18273 * (state->lo & 0xFFFF) + (state->lo >> 16);
130 return (state->hi << 16) + (state->lo & 0xFFFF);
131 } 125 }
132 126
133 127
134 // Used by JavaScript APIs 128 // Used by JavaScript APIs
135 uint32_t V8::Random(Isolate* isolate) { 129 uint32_t V8::Random(Isolate* isolate) {
136 ASSERT(isolate == Isolate::Current()); 130 ASSERT(isolate == Isolate::Current());
137 // TODO(isolates): move lo and hi to isolate 131 return random_base(isolate->random_seed());
138 static random_state state = {0, 0};
139 return random_base(&state);
140 } 132 }
141 133
142 134
143 // Used internally by the JIT and memory allocator for security 135 // Used internally by the JIT and memory allocator for security
144 // purposes. So, we keep a different state to prevent informations 136 // purposes. So, we keep a different state to prevent informations
145 // leaks that could be used in an exploit. 137 // leaks that could be used in an exploit.
146 uint32_t V8::RandomPrivate(Isolate* isolate) { 138 uint32_t V8::RandomPrivate(Isolate* isolate) {
147 ASSERT(isolate == Isolate::Current()); 139 ASSERT(isolate == Isolate::Current());
148 // TODO(isolates): move lo and hi to isolate 140 return random_base(isolate->private_random_seed());
149 static random_state state = {0, 0};
150 return random_base(&state);
151 } 141 }
152 142
153 143
154 bool V8::IdleNotification() { 144 bool V8::IdleNotification() {
155 // Returning true tells the caller that there is no need to call 145 // Returning true tells the caller that there is no need to call
156 // IdleNotification again. 146 // IdleNotification again.
157 if (!FLAG_use_idle_notification) return true; 147 if (!FLAG_use_idle_notification) return true;
158 148
159 // Tell the heap that it may want to adjust. 149 // Tell the heap that it may want to adjust.
160 return HEAP->IdleNotification(); 150 return HEAP->IdleNotification();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 use_crankshaft_ = false; 195 use_crankshaft_ = false;
206 } 196 }
207 197
208 RuntimeProfiler::GlobalSetup(); 198 RuntimeProfiler::GlobalSetup();
209 199
210 // Peephole optimization might interfere with deoptimization. 200 // Peephole optimization might interfere with deoptimization.
211 FLAG_peephole_optimization = !use_crankshaft_; 201 FLAG_peephole_optimization = !use_crankshaft_;
212 } 202 }
213 203
214 } } // namespace v8::internal 204 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/v8.h ('k') | src/v8-counters.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698