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" |
43 #include "extensions/externalize-string-extension.h" | 44 #include "extensions/externalize-string-extension.h" |
44 #include "extensions/gc-extension.h" | 45 #include "extensions/gc-extension.h" |
45 #include "extensions/statistics-extension.h" | 46 #include "extensions/statistics-extension.h" |
46 #include "code-stubs.h" | 47 #include "code-stubs.h" |
47 | 48 |
48 namespace v8 { | 49 namespace v8 { |
49 namespace internal { | 50 namespace internal { |
50 | 51 |
51 | 52 |
52 NativesExternalStringResource::NativesExternalStringResource( | 53 NativesExternalStringResource::NativesExternalStringResource( |
(...skipping 2572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2625 | 2626 |
2626 if (!ConfigureGlobalObjects(global_template)) return; | 2627 if (!ConfigureGlobalObjects(global_template)) return; |
2627 isolate->counters()->contexts_created_from_scratch()->Increment(); | 2628 isolate->counters()->contexts_created_from_scratch()->Increment(); |
2628 } | 2629 } |
2629 | 2630 |
2630 // Initialize experimental globals and install experimental natives. | 2631 // Initialize experimental globals and install experimental natives. |
2631 InitializeExperimentalGlobal(); | 2632 InitializeExperimentalGlobal(); |
2632 if (!InstallExperimentalNatives()) return; | 2633 if (!InstallExperimentalNatives()) return; |
2633 | 2634 |
2634 // We can't (de-)serialize typed arrays currently, but we are lucky: The state | 2635 // We can't (de-)serialize typed arrays currently, but we are lucky: The state |
2635 // of the random number generator needs no initialization during snapshot | 2636 // of the random number generator and the trigonometric lookup tables needs no |
2636 // creation time. | 2637 // initialization during snapshot creation time. |
2637 uint32_t* state = NULL; | 2638 uint32_t* state = NULL; |
2638 if (!Serializer::enabled()) { | 2639 if (!Serializer::enabled()) { |
2639 // Initially seed the per-context random number generator using the | 2640 // Initially seed the per-context random number generator using the |
2640 // per-isolate random number generator. | 2641 // per-isolate random number generator. |
2641 const int num_elems = 2; | 2642 const int num_elems = 2; |
2642 state = new uint32_t[num_elems]; | 2643 state = new uint32_t[num_elems]; |
2643 const int num_bytes = num_elems * sizeof(*state); | 2644 const int num_bytes = num_elems * sizeof(*state); |
2644 | 2645 |
2645 do { | 2646 do { |
2646 isolate->random_number_generator()->NextBytes(state, num_bytes); | 2647 isolate->random_number_generator()->NextBytes(state, num_bytes); |
2647 } while (state[0] == 0 || state[1] == 0); | 2648 } while (state[0] == 0 || state[1] == 0); |
2648 | 2649 |
2649 v8::Local<v8::ArrayBuffer> buffer = v8::ArrayBuffer::New(state, num_bytes); | 2650 v8::Local<v8::ArrayBuffer> buffer = v8::ArrayBuffer::New(state, num_bytes); |
2650 v8::Local<v8::Uint32Array> ta = v8::Uint32Array::New(buffer, 0, num_elems); | 2651 v8::Local<v8::Uint32Array> ta = v8::Uint32Array::New(buffer, 0, num_elems); |
2651 Handle<JSBuiltinsObject> builtins(native_context()->builtins()); | 2652 Handle<JSBuiltinsObject> builtins(native_context()->builtins()); |
2652 ForceSetProperty(builtins, | 2653 ForceSetProperty(builtins, |
2653 factory()->InternalizeOneByteString( | 2654 factory()->InternalizeOneByteString( |
2654 STATIC_ASCII_VECTOR("rngstate")), | 2655 STATIC_ASCII_VECTOR("rngstate")), |
2655 Utils::OpenHandle(*ta), | 2656 Utils::OpenHandle(*ta), |
2656 NONE); | 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::kTableSize); |
| 2667 v8::Local<v8::Float64Array> cos_table = v8::Float64Array::New( |
| 2668 cos_buffer, 0, TrigonometricLookupTable::kTableSize); |
| 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::kSamples), |
| 2685 NONE); |
| 2686 ForceSetProperty(builtins, |
| 2687 factory()->InternalizeOneByteString( |
| 2688 STATIC_ASCII_VECTOR("kIndexConvert")), |
| 2689 factory()->NewHeapNumber( |
| 2690 TrigonometricLookupTable::kSamplesOverPiHalf), |
| 2691 NONE); |
2657 } | 2692 } |
2658 // TODO(svenpanne) We have to delete the state when the context dies, so we | 2693 // TODO(svenpanne) We have to delete the state when the context dies, so we |
2659 // remember it in the context (encoded as a Smi, our usual technique for | 2694 // remember it in the context (encoded as a Smi, our usual technique for |
2660 // aligned pointers) and do the cleanup in | 2695 // aligned pointers) and do the cleanup in |
2661 // WeakListVisitor<Context>::VisitPhantomObject(). This hack can go away when | 2696 // WeakListVisitor<Context>::VisitPhantomObject(). This hack can go away when |
2662 // we have a way to allocate the backing store of typed arrays on the heap. | 2697 // we have a way to allocate the backing store of typed arrays on the heap. |
2663 ASSERT(reinterpret_cast<Smi*>(state)->IsSmi()); | 2698 ASSERT(reinterpret_cast<Smi*>(state)->IsSmi()); |
2664 native_context()->set_random_state(reinterpret_cast<Smi*>(state)); | 2699 native_context()->set_random_state(reinterpret_cast<Smi*>(state)); |
2665 | 2700 |
2666 result_ = native_context(); | 2701 result_ = native_context(); |
(...skipping 22 matching lines...) Expand all Loading... |
2689 return from + sizeof(NestingCounterType); | 2724 return from + sizeof(NestingCounterType); |
2690 } | 2725 } |
2691 | 2726 |
2692 | 2727 |
2693 // Called when the top-level V8 mutex is destroyed. | 2728 // Called when the top-level V8 mutex is destroyed. |
2694 void Bootstrapper::FreeThreadResources() { | 2729 void Bootstrapper::FreeThreadResources() { |
2695 ASSERT(!IsActive()); | 2730 ASSERT(!IsActive()); |
2696 } | 2731 } |
2697 | 2732 |
2698 } } // namespace v8::internal | 2733 } } // namespace v8::internal |
OLD | NEW |