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

Side by Side Diff: src/bootstrapper.cc

Issue 82763005: Reland "Implement Math.random() purely in JavaScript" plus fixes. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Added assertion Created 7 years 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 1291 matching lines...) Expand 10 before | Expand all | Expand 10 after
1302 native_context()->set_call_as_constructor_delegate(*delegate); 1302 native_context()->set_call_as_constructor_delegate(*delegate);
1303 delegate->shared()->DontAdaptArguments(); 1303 delegate->shared()->DontAdaptArguments();
1304 } 1304 }
1305 1305
1306 // Initialize the out of memory slot. 1306 // Initialize the out of memory slot.
1307 native_context()->set_out_of_memory(heap->false_value()); 1307 native_context()->set_out_of_memory(heap->false_value());
1308 1308
1309 // Initialize the embedder data slot. 1309 // Initialize the embedder data slot.
1310 Handle<FixedArray> embedder_data = factory->NewFixedArray(2); 1310 Handle<FixedArray> embedder_data = factory->NewFixedArray(2);
1311 native_context()->set_embedder_data(*embedder_data); 1311 native_context()->set_embedder_data(*embedder_data);
1312
1313 // Allocate the random seed slot.
1314 Handle<ByteArray> random_seed = factory->NewByteArray(kRandomStateSize);
1315 native_context()->set_random_seed(*random_seed);
1316 } 1312 }
1317 1313
1318 1314
1319 Handle<JSFunction> Genesis::InstallTypedArray( 1315 Handle<JSFunction> Genesis::InstallTypedArray(
1320 const char* name, ElementsKind elementsKind) { 1316 const char* name, ElementsKind elementsKind) {
1321 Handle<JSObject> global = Handle<JSObject>(native_context()->global_object()); 1317 Handle<JSObject> global = Handle<JSObject>(native_context()->global_object());
1322 Handle<JSFunction> result = InstallFunction(global, name, JS_TYPED_ARRAY_TYPE, 1318 Handle<JSFunction> result = InstallFunction(global, name, JS_TYPED_ARRAY_TYPE,
1323 JSTypedArray::kSize, isolate()->initial_object_prototype(), 1319 JSTypedArray::kSize, isolate()->initial_object_prototype(),
1324 Builtins::kIllegal, false, true); 1320 Builtins::kIllegal, false, true);
1325 1321
(...skipping 1303 matching lines...) Expand 10 before | Expand all | Expand 10 after
2629 MakeFunctionInstancePrototypeWritable(); 2625 MakeFunctionInstancePrototypeWritable();
2630 2626
2631 if (!ConfigureGlobalObjects(global_template)) return; 2627 if (!ConfigureGlobalObjects(global_template)) return;
2632 isolate->counters()->contexts_created_from_scratch()->Increment(); 2628 isolate->counters()->contexts_created_from_scratch()->Increment();
2633 } 2629 }
2634 2630
2635 // Initialize experimental globals and install experimental natives. 2631 // Initialize experimental globals and install experimental natives.
2636 InitializeExperimentalGlobal(); 2632 InitializeExperimentalGlobal();
2637 if (!InstallExperimentalNatives()) return; 2633 if (!InstallExperimentalNatives()) return;
2638 2634
2635 // We can't (de-)serialize typed arrays currently, but we are lucky: The state
2636 // of the random number generator needs no initialization during snapshot
2637 // creation time and we don't need trigonometric functions then.
2639 if (!Serializer::enabled()) { 2638 if (!Serializer::enabled()) {
2639 // Initially seed the per-context random number generator using the
2640 // per-isolate random number generator.
2641 const int num_elems = 2;
2642 const int num_bytes = num_elems * sizeof(uint32_t);
2643 uint32_t* state = reinterpret_cast<uint32_t*>(malloc(num_bytes));
2644
2645 do {
2646 isolate->random_number_generator()->NextBytes(state, num_bytes);
2647 } while (state[0] == 0 || state[1] == 0);
2648
2649 v8::Local<v8::ArrayBuffer> buffer = v8::ArrayBuffer::New(state, num_bytes);
2650 Utils::OpenHandle(*buffer)->set_should_be_freed(true);
2651 v8::Local<v8::Uint32Array> ta = v8::Uint32Array::New(buffer, 0, num_elems);
2640 Handle<JSBuiltinsObject> builtins(native_context()->builtins()); 2652 Handle<JSBuiltinsObject> builtins(native_context()->builtins());
2653 ForceSetProperty(builtins,
2654 factory()->InternalizeOneByteString(
2655 STATIC_ASCII_VECTOR("rngstate")),
2656 Utils::OpenHandle(*ta),
2657 NONE);
2658
2641 // Initialize trigonometric lookup tables and constants. 2659 // Initialize trigonometric lookup tables and constants.
2642 // The snapshot cannot contain typed arrays, and we don't need it to.
2643 const int table_num_bytes = TrigonometricLookupTable::table_num_bytes(); 2660 const int table_num_bytes = TrigonometricLookupTable::table_num_bytes();
2644 v8::Local<v8::ArrayBuffer> sin_buffer = v8::ArrayBuffer::New( 2661 v8::Local<v8::ArrayBuffer> sin_buffer = v8::ArrayBuffer::New(
2645 TrigonometricLookupTable::sin_table(), table_num_bytes); 2662 TrigonometricLookupTable::sin_table(), table_num_bytes);
2646 v8::Local<v8::ArrayBuffer> cos_buffer = v8::ArrayBuffer::New( 2663 v8::Local<v8::ArrayBuffer> cos_buffer = v8::ArrayBuffer::New(
2647 TrigonometricLookupTable::cos_x_interval_table(), table_num_bytes); 2664 TrigonometricLookupTable::cos_x_interval_table(), table_num_bytes);
2648 v8::Local<v8::Float64Array> sin_table = v8::Float64Array::New( 2665 v8::Local<v8::Float64Array> sin_table = v8::Float64Array::New(
2649 sin_buffer, 0, TrigonometricLookupTable::table_size()); 2666 sin_buffer, 0, TrigonometricLookupTable::table_size());
2650 v8::Local<v8::Float64Array> cos_table = v8::Float64Array::New( 2667 v8::Local<v8::Float64Array> cos_table = v8::Float64Array::New(
2651 cos_buffer, 0, TrigonometricLookupTable::table_size()); 2668 cos_buffer, 0, TrigonometricLookupTable::table_size());
2652 2669
(...skipping 14 matching lines...) Expand all
2667 TrigonometricLookupTable::samples()), 2684 TrigonometricLookupTable::samples()),
2668 NONE); 2685 NONE);
2669 ForceSetProperty(builtins, 2686 ForceSetProperty(builtins,
2670 factory()->InternalizeOneByteString( 2687 factory()->InternalizeOneByteString(
2671 STATIC_ASCII_VECTOR("kIndexConvert")), 2688 STATIC_ASCII_VECTOR("kIndexConvert")),
2672 factory()->NewHeapNumber( 2689 factory()->NewHeapNumber(
2673 TrigonometricLookupTable::samples_over_pi_half()), 2690 TrigonometricLookupTable::samples_over_pi_half()),
2674 NONE); 2691 NONE);
2675 } 2692 }
2676 2693
2677 // Initially seed the per-context random number generator
2678 // using the per-isolate random number generator.
2679 uint32_t* state = reinterpret_cast<uint32_t*>(
2680 native_context()->random_seed()->GetDataStartAddress());
2681 do {
2682 isolate->random_number_generator()->NextBytes(state, kRandomStateSize);
2683 } while (state[0] == 0 || state[1] == 0);
2684
2685 result_ = native_context(); 2694 result_ = native_context();
2686 } 2695 }
2687 2696
2688 2697
2689 // Support for thread preemption. 2698 // Support for thread preemption.
2690 2699
2691 // Reserve space for statics needing saving and restoring. 2700 // Reserve space for statics needing saving and restoring.
2692 int Bootstrapper::ArchiveSpacePerThread() { 2701 int Bootstrapper::ArchiveSpacePerThread() {
2693 return sizeof(NestingCounterType); 2702 return sizeof(NestingCounterType);
2694 } 2703 }
(...skipping 13 matching lines...) Expand all
2708 return from + sizeof(NestingCounterType); 2717 return from + sizeof(NestingCounterType);
2709 } 2718 }
2710 2719
2711 2720
2712 // Called when the top-level V8 mutex is destroyed. 2721 // Called when the top-level V8 mutex is destroyed.
2713 void Bootstrapper::FreeThreadResources() { 2722 void Bootstrapper::FreeThreadResources() {
2714 ASSERT(!IsActive()); 2723 ASSERT(!IsActive());
2715 } 2724 }
2716 2725
2717 } } // namespace v8::internal 2726 } } // 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