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

Side by Side Diff: src/bootstrapper.cc

Issue 68723002: Implement Math.random() purely in JavaScript. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Comments only 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/assembler.cc ('k') | src/contexts.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 1290 matching lines...) Expand 10 before | Expand all | Expand 10 after
1301 native_context()->set_call_as_constructor_delegate(*delegate); 1301 native_context()->set_call_as_constructor_delegate(*delegate);
1302 delegate->shared()->DontAdaptArguments(); 1302 delegate->shared()->DontAdaptArguments();
1303 } 1303 }
1304 1304
1305 // Initialize the out of memory slot. 1305 // Initialize the out of memory slot.
1306 native_context()->set_out_of_memory(heap->false_value()); 1306 native_context()->set_out_of_memory(heap->false_value());
1307 1307
1308 // Initialize the embedder data slot. 1308 // Initialize the embedder data slot.
1309 Handle<FixedArray> embedder_data = factory->NewFixedArray(2); 1309 Handle<FixedArray> embedder_data = factory->NewFixedArray(2);
1310 native_context()->set_embedder_data(*embedder_data); 1310 native_context()->set_embedder_data(*embedder_data);
1311
1312 // Allocate the random seed slot.
1313 Handle<ByteArray> random_seed = factory->NewByteArray(kRandomStateSize);
1314 native_context()->set_random_seed(*random_seed);
1315 } 1311 }
1316 1312
1317 1313
1318 Handle<JSFunction> Genesis::InstallTypedArray( 1314 Handle<JSFunction> Genesis::InstallTypedArray(
1319 const char* name, ElementsKind elementsKind) { 1315 const char* name, ElementsKind elementsKind) {
1320 Handle<JSObject> global = Handle<JSObject>(native_context()->global_object()); 1316 Handle<JSObject> global = Handle<JSObject>(native_context()->global_object());
1321 Handle<JSFunction> result = InstallFunction(global, name, JS_TYPED_ARRAY_TYPE, 1317 Handle<JSFunction> result = InstallFunction(global, name, JS_TYPED_ARRAY_TYPE,
1322 JSTypedArray::kSize, isolate()->initial_object_prototype(), 1318 JSTypedArray::kSize, isolate()->initial_object_prototype(),
1323 Builtins::kIllegal, false, true); 1319 Builtins::kIllegal, false, true);
1324 1320
(...skipping 1303 matching lines...) Expand 10 before | Expand all | Expand 10 after
2628 MakeFunctionInstancePrototypeWritable(); 2624 MakeFunctionInstancePrototypeWritable();
2629 2625
2630 if (!ConfigureGlobalObjects(global_template)) return; 2626 if (!ConfigureGlobalObjects(global_template)) return;
2631 isolate->counters()->contexts_created_from_scratch()->Increment(); 2627 isolate->counters()->contexts_created_from_scratch()->Increment();
2632 } 2628 }
2633 2629
2634 // Initialize experimental globals and install experimental natives. 2630 // Initialize experimental globals and install experimental natives.
2635 InitializeExperimentalGlobal(); 2631 InitializeExperimentalGlobal();
2636 if (!InstallExperimentalNatives()) return; 2632 if (!InstallExperimentalNatives()) return;
2637 2633
2638 // Initially seed the per-context random number generator 2634 // We can't (de-)serialize typed arrays currently, but we are lucky: The state
2639 // using the per-isolate random number generator. 2635 // of the random number generator needs no initialization during snapshot
2640 uint32_t* state = reinterpret_cast<uint32_t*>( 2636 // creation time.
2641 native_context()->random_seed()->GetDataStartAddress()); 2637 if (!Serializer::enabled()) {
2642 do { 2638 // Initially seed the per-context random number generator using the
2643 isolate->random_number_generator()->NextBytes(state, kRandomStateSize); 2639 // per-isolate random number generator.
2644 } while (state[0] == 0 || state[1] == 0); 2640 const int num_elems = 2;
2641 uint32_t* state = new uint32_t[num_elems];
2642 const int num_bytes = num_elems * sizeof(*state);
2643 // We have to delete the state when the context dies, so we remember it in
2644 // the context (encoded as a Smi, our usual technique for aligned pointers)
2645 // and do the cleanup in WeakListVisitor<Context>::VisitPhantomObject().
2646 // This hack can go away when we have a way to allocate the backing store of
2647 // typed arrays on the heap.
2648 native_context()->set_random_state(reinterpret_cast<Smi*>(state));
2649 ASSERT(native_context()->random_state()->IsSmi());
2650
2651 do {
2652 isolate->random_number_generator()->NextBytes(state, num_bytes);
2653 } while (state[0] == 0 || state[1] == 0);
2654
2655 v8::Local<v8::ArrayBuffer> buffer = v8::ArrayBuffer::New(state, num_bytes);
2656 v8::Local<v8::Uint32Array> ta = v8::Uint32Array::New(buffer, 0, num_elems);
2657 Handle<JSBuiltinsObject> builtins(native_context()->builtins());
2658 ForceSetProperty(builtins,
2659 factory()->InternalizeOneByteString(
2660 STATIC_ASCII_VECTOR("rngstate")),
2661 Utils::OpenHandle(*ta),
2662 NONE);
2663 }
2645 2664
2646 result_ = native_context(); 2665 result_ = native_context();
2647 } 2666 }
2648 2667
2649 2668
2650 // Support for thread preemption. 2669 // Support for thread preemption.
2651 2670
2652 // Reserve space for statics needing saving and restoring. 2671 // Reserve space for statics needing saving and restoring.
2653 int Bootstrapper::ArchiveSpacePerThread() { 2672 int Bootstrapper::ArchiveSpacePerThread() {
2654 return sizeof(NestingCounterType); 2673 return sizeof(NestingCounterType);
(...skipping 14 matching lines...) Expand all
2669 return from + sizeof(NestingCounterType); 2688 return from + sizeof(NestingCounterType);
2670 } 2689 }
2671 2690
2672 2691
2673 // Called when the top-level V8 mutex is destroyed. 2692 // Called when the top-level V8 mutex is destroyed.
2674 void Bootstrapper::FreeThreadResources() { 2693 void Bootstrapper::FreeThreadResources() {
2675 ASSERT(!IsActive()); 2694 ASSERT(!IsActive());
2676 } 2695 }
2677 2696
2678 } } // namespace v8::internal 2697 } } // namespace v8::internal
OLDNEW
« 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