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

Side by Side Diff: src/bootstrapper.cc

Issue 1425693006: Store RNG state on function context. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 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
« no previous file with comments | « no previous file | src/js/math.js » ('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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/bootstrapper.h" 5 #include "src/bootstrapper.h"
6 6
7 #include "src/accessors.h" 7 #include "src/accessors.h"
8 #include "src/api-natives.h" 8 #include "src/api-natives.h"
9 #include "src/base/utils/random-number-generator.h"
10 #include "src/code-stubs.h" 9 #include "src/code-stubs.h"
11 #include "src/extensions/externalize-string-extension.h" 10 #include "src/extensions/externalize-string-extension.h"
12 #include "src/extensions/free-buffer-extension.h" 11 #include "src/extensions/free-buffer-extension.h"
13 #include "src/extensions/gc-extension.h" 12 #include "src/extensions/gc-extension.h"
14 #include "src/extensions/statistics-extension.h" 13 #include "src/extensions/statistics-extension.h"
15 #include "src/extensions/trigger-failure-extension.h" 14 #include "src/extensions/trigger-failure-extension.h"
16 #include "src/heap/heap.h" 15 #include "src/heap/heap.h"
17 #include "src/isolate-inl.h" 16 #include "src/isolate-inl.h"
18 #include "src/snapshot/natives.h" 17 #include "src/snapshot/natives.h"
19 #include "src/snapshot/snapshot.h" 18 #include "src/snapshot/snapshot.h"
(...skipping 1783 matching lines...) Expand 10 before | Expand all | Expand 10 after
1803 } 1802 }
1804 JSArrayBuffer::Setup(buffer, isolate, is_external, *data, byte_length, 1803 JSArrayBuffer::Setup(buffer, isolate, is_external, *data, byte_length,
1805 SharedFlag::kNotShared); 1804 SharedFlag::kNotShared);
1806 return isolate->factory()->NewJSTypedArray(type, buffer, 0, num_elements, 1805 return isolate->factory()->NewJSTypedArray(type, buffer, 0, num_elements,
1807 TENURED); 1806 TENURED);
1808 } 1807 }
1809 1808
1810 1809
1811 bool Genesis::InitializeBuiltinTypedArrays() { 1810 bool Genesis::InitializeBuiltinTypedArrays() {
1812 HandleScope scope(isolate()); 1811 HandleScope scope(isolate());
1813 Handle<JSTypedArray> rng_state; 1812 const size_t num_elements = 2;
1814 Handle<JSTypedArray> rempio2result; 1813 double* data = NULL;
1815 1814 Handle<JSTypedArray> rempio2result =
1816 { 1815 CreateTypedArray(isolate(), kExternalFloat64Array, num_elements, &data);
1817 // Seed the per-context RNG using the per-isolate RNG. 1816 for (size_t i = 0; i < num_elements; i++) data[i] = 0;
1818 const size_t num_elements = 2;
1819 const size_t num_bytes = num_elements * sizeof(uint32_t);
1820 uint32_t* state = NULL;
1821 rng_state =
1822 CreateTypedArray(isolate(), kExternalUint32Array, num_elements, &state);
1823 do {
1824 isolate()->random_number_generator()->NextBytes(state, num_bytes);
1825 } while (state[0] == 0 || state[1] == 0);
1826 }
1827
1828 { // Initialize a result array for rempio2 calculation
1829 const size_t num_elements = 2;
1830 double* data = NULL;
1831 rempio2result =
1832 CreateTypedArray(isolate(), kExternalFloat64Array, num_elements, &data);
1833 for (size_t i = 0; i < num_elements; i++) data[i] = 0;
1834 }
1835 1817
1836 Handle<JSObject> utils = 1818 Handle<JSObject> utils =
1837 Handle<JSObject>::cast(isolate()->natives_utils_object()); 1819 Handle<JSObject>::cast(isolate()->natives_utils_object());
1838 Handle<String> name_string = isolate()->factory()->NewStringFromAsciiChecked( 1820 Handle<String> name_string = isolate()->factory()->NewStringFromAsciiChecked(
1839 "InitializeBuiltinTypedArrays"); 1821 "InitializeBuiltinTypedArrays");
1840 Handle<Object> fun = JSObject::GetDataProperty(utils, name_string); 1822 Handle<Object> fun = JSObject::GetDataProperty(utils, name_string);
1841 Handle<Object> receiver = isolate()->factory()->undefined_value(); 1823 Handle<Object> receiver = isolate()->factory()->undefined_value();
1842 Handle<Object> args[] = {utils, rng_state, rempio2result}; 1824 Handle<Object> args[] = {utils, rempio2result};
1843 return !Execution::Call(isolate(), fun, receiver, arraysize(args), args) 1825 return !Execution::Call(isolate(), fun, receiver, arraysize(args), args)
1844 .is_null(); 1826 .is_null();
1845 } 1827 }
1846 1828
1847 1829
1848 void Genesis::ConfigureUtilsObject(ContextType context_type) { 1830 void Genesis::ConfigureUtilsObject(ContextType context_type) {
1849 switch (context_type) { 1831 switch (context_type) {
1850 // We still need the utils object to find debug functions. 1832 // We still need the utils object to find debug functions.
1851 case DEBUG_CONTEXT: 1833 case DEBUG_CONTEXT:
1852 return; 1834 return;
(...skipping 1503 matching lines...) Expand 10 before | Expand all | Expand 10 after
3356 } 3338 }
3357 3339
3358 3340
3359 // Called when the top-level V8 mutex is destroyed. 3341 // Called when the top-level V8 mutex is destroyed.
3360 void Bootstrapper::FreeThreadResources() { 3342 void Bootstrapper::FreeThreadResources() {
3361 DCHECK(!IsActive()); 3343 DCHECK(!IsActive());
3362 } 3344 }
3363 3345
3364 } // namespace internal 3346 } // namespace internal
3365 } // namespace v8 3347 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/js/math.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698