OLD | NEW |
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 22 matching lines...) Expand all Loading... |
33 #include "compiler.h" | 33 #include "compiler.h" |
34 #include "debug.h" | 34 #include "debug.h" |
35 #include "execution.h" | 35 #include "execution.h" |
36 #include "global-handles.h" | 36 #include "global-handles.h" |
37 #include "isolate-inl.h" | 37 #include "isolate-inl.h" |
38 #include "macro-assembler.h" | 38 #include "macro-assembler.h" |
39 #include "natives.h" | 39 #include "natives.h" |
40 #include "objects-visiting.h" | 40 #include "objects-visiting.h" |
41 #include "platform.h" | 41 #include "platform.h" |
42 #include "snapshot.h" | 42 #include "snapshot.h" |
43 #include "trig-table.h" | |
44 #include "extensions/externalize-string-extension.h" | 43 #include "extensions/externalize-string-extension.h" |
45 #include "extensions/gc-extension.h" | 44 #include "extensions/gc-extension.h" |
46 #include "extensions/statistics-extension.h" | 45 #include "extensions/statistics-extension.h" |
47 #include "code-stubs.h" | 46 #include "code-stubs.h" |
48 | 47 |
49 namespace v8 { | 48 namespace v8 { |
50 namespace internal { | 49 namespace internal { |
51 | 50 |
52 | 51 |
53 NativesExternalStringResource::NativesExternalStringResource( | 52 NativesExternalStringResource::NativesExternalStringResource( |
(...skipping 1248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1302 native_context()->set_call_as_constructor_delegate(*delegate); | 1301 native_context()->set_call_as_constructor_delegate(*delegate); |
1303 delegate->shared()->DontAdaptArguments(); | 1302 delegate->shared()->DontAdaptArguments(); |
1304 } | 1303 } |
1305 | 1304 |
1306 // Initialize the out of memory slot. | 1305 // Initialize the out of memory slot. |
1307 native_context()->set_out_of_memory(heap->false_value()); | 1306 native_context()->set_out_of_memory(heap->false_value()); |
1308 | 1307 |
1309 // Initialize the embedder data slot. | 1308 // Initialize the embedder data slot. |
1310 Handle<FixedArray> embedder_data = factory->NewFixedArray(2); | 1309 Handle<FixedArray> embedder_data = factory->NewFixedArray(2); |
1311 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); |
1312 } | 1315 } |
1313 | 1316 |
1314 | 1317 |
1315 Handle<JSFunction> Genesis::InstallTypedArray( | 1318 Handle<JSFunction> Genesis::InstallTypedArray( |
1316 const char* name, ElementsKind elementsKind) { | 1319 const char* name, ElementsKind elementsKind) { |
1317 Handle<JSObject> global = Handle<JSObject>(native_context()->global_object()); | 1320 Handle<JSObject> global = Handle<JSObject>(native_context()->global_object()); |
1318 Handle<JSFunction> result = InstallFunction(global, name, JS_TYPED_ARRAY_TYPE, | 1321 Handle<JSFunction> result = InstallFunction(global, name, JS_TYPED_ARRAY_TYPE, |
1319 JSTypedArray::kSize, isolate()->initial_object_prototype(), | 1322 JSTypedArray::kSize, isolate()->initial_object_prototype(), |
1320 Builtins::kIllegal, false, true); | 1323 Builtins::kIllegal, false, true); |
1321 | 1324 |
(...skipping 1303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2625 MakeFunctionInstancePrototypeWritable(); | 2628 MakeFunctionInstancePrototypeWritable(); |
2626 | 2629 |
2627 if (!ConfigureGlobalObjects(global_template)) return; | 2630 if (!ConfigureGlobalObjects(global_template)) return; |
2628 isolate->counters()->contexts_created_from_scratch()->Increment(); | 2631 isolate->counters()->contexts_created_from_scratch()->Increment(); |
2629 } | 2632 } |
2630 | 2633 |
2631 // Initialize experimental globals and install experimental natives. | 2634 // Initialize experimental globals and install experimental natives. |
2632 InitializeExperimentalGlobal(); | 2635 InitializeExperimentalGlobal(); |
2633 if (!InstallExperimentalNatives()) return; | 2636 if (!InstallExperimentalNatives()) return; |
2634 | 2637 |
2635 // We can't (de-)serialize typed arrays currently, but we are lucky: The state | 2638 // Initially seed the per-context random number generator |
2636 // of the random number generator and the trigonometric lookup tables needs no | 2639 // using the per-isolate random number generator. |
2637 // initialization during snapshot creation time. | 2640 uint32_t* state = reinterpret_cast<uint32_t*>( |
2638 uint32_t* state = NULL; | 2641 native_context()->random_seed()->GetDataStartAddress()); |
2639 if (!Serializer::enabled()) { | 2642 do { |
2640 // Initially seed the per-context random number generator using the | 2643 isolate->random_number_generator()->NextBytes(state, kRandomStateSize); |
2641 // per-isolate random number generator. | 2644 } while (state[0] == 0 || state[1] == 0); |
2642 const int num_elems = 2; | |
2643 state = new uint32_t[num_elems]; | |
2644 const int num_bytes = num_elems * sizeof(*state); | |
2645 | |
2646 do { | |
2647 isolate->random_number_generator()->NextBytes(state, num_bytes); | |
2648 } while (state[0] == 0 || state[1] == 0); | |
2649 | |
2650 v8::Local<v8::ArrayBuffer> buffer = v8::ArrayBuffer::New(state, num_bytes); | |
2651 v8::Local<v8::Uint32Array> ta = v8::Uint32Array::New(buffer, 0, num_elems); | |
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 | |
2659 // Initialize trigonometric lookup tables and constants. | |
2660 const int table_num_bytes = TrigonometricLookupTable::table_num_bytes(); | |
2661 v8::Local<v8::ArrayBuffer> sin_buffer = v8::ArrayBuffer::New( | |
2662 TrigonometricLookupTable::sin_table(), table_num_bytes); | |
2663 v8::Local<v8::ArrayBuffer> cos_buffer = v8::ArrayBuffer::New( | |
2664 TrigonometricLookupTable::cos_x_interval_table(), table_num_bytes); | |
2665 v8::Local<v8::Float64Array> sin_table = v8::Float64Array::New( | |
2666 sin_buffer, 0, TrigonometricLookupTable::table_size()); | |
2667 v8::Local<v8::Float64Array> cos_table = v8::Float64Array::New( | |
2668 cos_buffer, 0, TrigonometricLookupTable::table_size()); | |
2669 | |
2670 ForceSetProperty(builtins, | |
2671 factory()->InternalizeOneByteString( | |
2672 STATIC_ASCII_VECTOR("kSinTable")), | |
2673 Utils::OpenHandle(*sin_table), | |
2674 NONE); | |
2675 ForceSetProperty(builtins, | |
2676 factory()->InternalizeOneByteString( | |
2677 STATIC_ASCII_VECTOR("kCosXIntervalTable")), | |
2678 Utils::OpenHandle(*cos_table), | |
2679 NONE); | |
2680 ForceSetProperty(builtins, | |
2681 factory()->InternalizeOneByteString( | |
2682 STATIC_ASCII_VECTOR("kSamples")), | |
2683 factory()->NewHeapNumber( | |
2684 TrigonometricLookupTable::samples()), | |
2685 NONE); | |
2686 ForceSetProperty(builtins, | |
2687 factory()->InternalizeOneByteString( | |
2688 STATIC_ASCII_VECTOR("kIndexConvert")), | |
2689 factory()->NewHeapNumber( | |
2690 TrigonometricLookupTable::samples_over_pi_half()), | |
2691 NONE); | |
2692 } | |
2693 // TODO(svenpanne) We have to delete the state when the context dies, so we | |
2694 // remember it in the context (encoded as a Smi, our usual technique for | |
2695 // aligned pointers) and do the cleanup in | |
2696 // WeakListVisitor<Context>::VisitPhantomObject(). This hack can go away when | |
2697 // we have a way to allocate the backing store of typed arrays on the heap. | |
2698 ASSERT(reinterpret_cast<Smi*>(state)->IsSmi()); | |
2699 native_context()->set_random_state(reinterpret_cast<Smi*>(state)); | |
2700 | 2645 |
2701 result_ = native_context(); | 2646 result_ = native_context(); |
2702 } | 2647 } |
2703 | 2648 |
2704 | 2649 |
2705 // Support for thread preemption. | 2650 // Support for thread preemption. |
2706 | 2651 |
2707 // Reserve space for statics needing saving and restoring. | 2652 // Reserve space for statics needing saving and restoring. |
2708 int Bootstrapper::ArchiveSpacePerThread() { | 2653 int Bootstrapper::ArchiveSpacePerThread() { |
2709 return sizeof(NestingCounterType); | 2654 return sizeof(NestingCounterType); |
(...skipping 14 matching lines...) Expand all Loading... |
2724 return from + sizeof(NestingCounterType); | 2669 return from + sizeof(NestingCounterType); |
2725 } | 2670 } |
2726 | 2671 |
2727 | 2672 |
2728 // Called when the top-level V8 mutex is destroyed. | 2673 // Called when the top-level V8 mutex is destroyed. |
2729 void Bootstrapper::FreeThreadResources() { | 2674 void Bootstrapper::FreeThreadResources() { |
2730 ASSERT(!IsActive()); | 2675 ASSERT(!IsActive()); |
2731 } | 2676 } |
2732 | 2677 |
2733 } } // namespace v8::internal | 2678 } } // namespace v8::internal |
OLD | NEW |