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

Side by Side Diff: src/v8.cc

Issue 8162014: Moved random generator state to global context. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 2 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/x64/full-codegen-x64.cc » ('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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 return (state[0] << 14) + (state[1] & 0x3FFFF); 134 return (state[0] << 14) + (state[1] & 0x3FFFF);
135 } 135 }
136 136
137 137
138 void V8::SetEntropySource(EntropySource source) { 138 void V8::SetEntropySource(EntropySource source) {
139 entropy_source = source; 139 entropy_source = source;
140 } 140 }
141 141
142 142
143 // Used by JavaScript APIs 143 // Used by JavaScript APIs
144 uint32_t V8::Random(Isolate* isolate) { 144 uint32_t V8::Random(Context* context) {
145 ASSERT(isolate == Isolate::Current()); 145 ASSERT(context->IsGlobalContext());
146 return random_base(isolate->random_seed()); 146 ByteArray* seed = context->random_seed();
147 return random_base(reinterpret_cast<uint32_t*>(seed->GetDataStartAddress()));
147 } 148 }
148 149
149 150
150 // Used internally by the JIT and memory allocator for security 151 // Used internally by the JIT and memory allocator for security
151 // purposes. So, we keep a different state to prevent informations 152 // purposes. So, we keep a different state to prevent informations
152 // leaks that could be used in an exploit. 153 // leaks that could be used in an exploit.
153 uint32_t V8::RandomPrivate(Isolate* isolate) { 154 uint32_t V8::RandomPrivate(Isolate* isolate) {
154 ASSERT(isolate == Isolate::Current()); 155 ASSERT(isolate == Isolate::Current());
155 return random_base(isolate->private_random_seed()); 156 return random_base(isolate->private_random_seed());
156 } 157 }
157 158
158 159
159 bool V8::IdleNotification() { 160 bool V8::IdleNotification() {
160 // Returning true tells the caller that there is no need to call 161 // Returning true tells the caller that there is no need to call
161 // IdleNotification again. 162 // IdleNotification again.
162 if (!FLAG_use_idle_notification) return true; 163 if (!FLAG_use_idle_notification) return true;
163 164
164 // Tell the heap that it may want to adjust. 165 // Tell the heap that it may want to adjust.
165 return HEAP->IdleNotification(); 166 return HEAP->IdleNotification();
166 } 167 }
167 168
168 169
169 // Use a union type to avoid type-aliasing optimizations in GCC. 170 // Use a union type to avoid type-aliasing optimizations in GCC.
170 typedef union { 171 typedef union {
171 double double_value; 172 double double_value;
172 uint64_t uint64_t_value; 173 uint64_t uint64_t_value;
173 } double_int_union; 174 } double_int_union;
174 175
175 176
176 Object* V8::FillHeapNumberWithRandom(Object* heap_number, Isolate* isolate) { 177 Object* V8::FillHeapNumberWithRandom(Object* heap_number,
177 uint64_t random_bits = Random(isolate); 178 Context* context) {
179 uint64_t random_bits = Random(context);
178 // Make a double* from address (heap_number + sizeof(double)). 180 // Make a double* from address (heap_number + sizeof(double)).
179 double_int_union* r = reinterpret_cast<double_int_union*>( 181 double_int_union* r = reinterpret_cast<double_int_union*>(
180 reinterpret_cast<char*>(heap_number) + 182 reinterpret_cast<char*>(heap_number) +
181 HeapNumber::kValueOffset - kHeapObjectTag); 183 HeapNumber::kValueOffset - kHeapObjectTag);
182 // Convert 32 random bits to 0.(32 random bits) in a double 184 // Convert 32 random bits to 0.(32 random bits) in a double
183 // by computing: 185 // by computing:
184 // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)). 186 // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)).
185 const double binary_million = 1048576.0; 187 const double binary_million = 1048576.0;
186 r->double_value = binary_million; 188 r->double_value = binary_million;
187 r->uint64_t_value |= random_bits; 189 r->uint64_t_value |= random_bits;
(...skipping 24 matching lines...) Expand all
212 214
213 RuntimeProfiler::GlobalSetup(); 215 RuntimeProfiler::GlobalSetup();
214 216
215 // Peephole optimization might interfere with deoptimization. 217 // Peephole optimization might interfere with deoptimization.
216 FLAG_peephole_optimization = !use_crankshaft_; 218 FLAG_peephole_optimization = !use_crankshaft_;
217 219
218 ElementsAccessor::InitializeOncePerProcess(); 220 ElementsAccessor::InitializeOncePerProcess();
219 } 221 }
220 222
221 } } // namespace v8::internal 223 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/v8.h ('k') | src/x64/full-codegen-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698