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

Unified Diff: src/bootstrapper.cc

Issue 80513004: Revert 17963, 17962 and 17955: Random number generator in JS changes (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Remove Yang's changes, too Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/assembler.cc ('k') | src/contexts.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/bootstrapper.cc
diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc
index dc64f171cad97ae99aa784f5540e01f8d6f7708a..bc52fa858feedd970e686368cae17f47eb445e0c 100644
--- a/src/bootstrapper.cc
+++ b/src/bootstrapper.cc
@@ -40,7 +40,6 @@
#include "objects-visiting.h"
#include "platform.h"
#include "snapshot.h"
-#include "trig-table.h"
#include "extensions/externalize-string-extension.h"
#include "extensions/gc-extension.h"
#include "extensions/statistics-extension.h"
@@ -1309,6 +1308,10 @@ void Genesis::InitializeGlobal(Handle<GlobalObject> inner_global,
// Initialize the embedder data slot.
Handle<FixedArray> embedder_data = factory->NewFixedArray(2);
native_context()->set_embedder_data(*embedder_data);
+
+ // Allocate the random seed slot.
+ Handle<ByteArray> random_seed = factory->NewByteArray(kRandomStateSize);
+ native_context()->set_random_seed(*random_seed);
}
@@ -2632,71 +2635,13 @@ Genesis::Genesis(Isolate* isolate,
InitializeExperimentalGlobal();
if (!InstallExperimentalNatives()) return;
- // We can't (de-)serialize typed arrays currently, but we are lucky: The state
- // of the random number generator and the trigonometric lookup tables needs no
- // initialization during snapshot creation time.
- uint32_t* state = NULL;
- if (!Serializer::enabled()) {
- // Initially seed the per-context random number generator using the
- // per-isolate random number generator.
- const int num_elems = 2;
- state = new uint32_t[num_elems];
- const int num_bytes = num_elems * sizeof(*state);
-
- do {
- isolate->random_number_generator()->NextBytes(state, num_bytes);
- } while (state[0] == 0 || state[1] == 0);
-
- v8::Local<v8::ArrayBuffer> buffer = v8::ArrayBuffer::New(state, num_bytes);
- v8::Local<v8::Uint32Array> ta = v8::Uint32Array::New(buffer, 0, num_elems);
- Handle<JSBuiltinsObject> builtins(native_context()->builtins());
- ForceSetProperty(builtins,
- factory()->InternalizeOneByteString(
- STATIC_ASCII_VECTOR("rngstate")),
- Utils::OpenHandle(*ta),
- NONE);
-
- // Initialize trigonometric lookup tables and constants.
- const int table_num_bytes = TrigonometricLookupTable::table_num_bytes();
- v8::Local<v8::ArrayBuffer> sin_buffer = v8::ArrayBuffer::New(
- TrigonometricLookupTable::sin_table(), table_num_bytes);
- v8::Local<v8::ArrayBuffer> cos_buffer = v8::ArrayBuffer::New(
- TrigonometricLookupTable::cos_x_interval_table(), table_num_bytes);
- v8::Local<v8::Float64Array> sin_table = v8::Float64Array::New(
- sin_buffer, 0, TrigonometricLookupTable::table_size());
- v8::Local<v8::Float64Array> cos_table = v8::Float64Array::New(
- cos_buffer, 0, TrigonometricLookupTable::table_size());
-
- ForceSetProperty(builtins,
- factory()->InternalizeOneByteString(
- STATIC_ASCII_VECTOR("kSinTable")),
- Utils::OpenHandle(*sin_table),
- NONE);
- ForceSetProperty(builtins,
- factory()->InternalizeOneByteString(
- STATIC_ASCII_VECTOR("kCosXIntervalTable")),
- Utils::OpenHandle(*cos_table),
- NONE);
- ForceSetProperty(builtins,
- factory()->InternalizeOneByteString(
- STATIC_ASCII_VECTOR("kSamples")),
- factory()->NewHeapNumber(
- TrigonometricLookupTable::samples()),
- NONE);
- ForceSetProperty(builtins,
- factory()->InternalizeOneByteString(
- STATIC_ASCII_VECTOR("kIndexConvert")),
- factory()->NewHeapNumber(
- TrigonometricLookupTable::samples_over_pi_half()),
- NONE);
- }
- // TODO(svenpanne) We have to delete the state when the context dies, so we
- // remember it in the context (encoded as a Smi, our usual technique for
- // aligned pointers) and do the cleanup in
- // WeakListVisitor<Context>::VisitPhantomObject(). This hack can go away when
- // we have a way to allocate the backing store of typed arrays on the heap.
- ASSERT(reinterpret_cast<Smi*>(state)->IsSmi());
- native_context()->set_random_state(reinterpret_cast<Smi*>(state));
+ // Initially seed the per-context random number generator
+ // using the per-isolate random number generator.
+ uint32_t* state = reinterpret_cast<uint32_t*>(
+ native_context()->random_seed()->GetDataStartAddress());
+ do {
+ isolate->random_number_generator()->NextBytes(state, kRandomStateSize);
+ } while (state[0] == 0 || state[1] == 0);
result_ = native_context();
}
« no previous file with comments | « src/assembler.cc ('k') | src/contexts.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698