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 2616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2627 isolate->counters()->contexts_created_from_scratch()->Increment(); | 2627 isolate->counters()->contexts_created_from_scratch()->Increment(); |
2628 } | 2628 } |
2629 | 2629 |
2630 // Initialize experimental globals and install experimental natives. | 2630 // Initialize experimental globals and install experimental natives. |
2631 InitializeExperimentalGlobal(); | 2631 InitializeExperimentalGlobal(); |
2632 if (!InstallExperimentalNatives()) return; | 2632 if (!InstallExperimentalNatives()) return; |
2633 | 2633 |
2634 // We can't (de-)serialize typed arrays currently, but we are lucky: The state | 2634 // 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 | 2635 // of the random number generator needs no initialization during snapshot |
2636 // creation time. | 2636 // creation time. |
| 2637 uint32_t* state = NULL; |
2637 if (!Serializer::enabled()) { | 2638 if (!Serializer::enabled()) { |
2638 // Initially seed the per-context random number generator using the | 2639 // Initially seed the per-context random number generator using the |
2639 // per-isolate random number generator. | 2640 // per-isolate random number generator. |
2640 const int num_elems = 2; | 2641 const int num_elems = 2; |
2641 uint32_t* state = new uint32_t[num_elems]; | 2642 state = new uint32_t[num_elems]; |
2642 const int num_bytes = num_elems * sizeof(*state); | 2643 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 | 2644 |
2651 do { | 2645 do { |
2652 isolate->random_number_generator()->NextBytes(state, num_bytes); | 2646 isolate->random_number_generator()->NextBytes(state, num_bytes); |
2653 } while (state[0] == 0 || state[1] == 0); | 2647 } while (state[0] == 0 || state[1] == 0); |
2654 | 2648 |
2655 v8::Local<v8::ArrayBuffer> buffer = v8::ArrayBuffer::New(state, num_bytes); | 2649 v8::Local<v8::ArrayBuffer> buffer = v8::ArrayBuffer::New(state, num_bytes); |
2656 v8::Local<v8::Uint32Array> ta = v8::Uint32Array::New(buffer, 0, num_elems); | 2650 v8::Local<v8::Uint32Array> ta = v8::Uint32Array::New(buffer, 0, num_elems); |
2657 Handle<JSBuiltinsObject> builtins(native_context()->builtins()); | 2651 Handle<JSBuiltinsObject> builtins(native_context()->builtins()); |
2658 ForceSetProperty(builtins, | 2652 ForceSetProperty(builtins, |
2659 factory()->InternalizeOneByteString( | 2653 factory()->InternalizeOneByteString( |
2660 STATIC_ASCII_VECTOR("rngstate")), | 2654 STATIC_ASCII_VECTOR("rngstate")), |
2661 Utils::OpenHandle(*ta), | 2655 Utils::OpenHandle(*ta), |
2662 NONE); | 2656 NONE); |
2663 } | 2657 } |
| 2658 // 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 |
| 2660 // aligned pointers) and do the cleanup in |
| 2661 // 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. |
| 2663 ASSERT(reinterpret_cast<Smi*>(state)->IsSmi()); |
| 2664 native_context()->set_random_state(reinterpret_cast<Smi*>(state)); |
2664 | 2665 |
2665 result_ = native_context(); | 2666 result_ = native_context(); |
2666 } | 2667 } |
2667 | 2668 |
2668 | 2669 |
2669 // Support for thread preemption. | 2670 // Support for thread preemption. |
2670 | 2671 |
2671 // Reserve space for statics needing saving and restoring. | 2672 // Reserve space for statics needing saving and restoring. |
2672 int Bootstrapper::ArchiveSpacePerThread() { | 2673 int Bootstrapper::ArchiveSpacePerThread() { |
2673 return sizeof(NestingCounterType); | 2674 return sizeof(NestingCounterType); |
(...skipping 14 matching lines...) Expand all Loading... |
2688 return from + sizeof(NestingCounterType); | 2689 return from + sizeof(NestingCounterType); |
2689 } | 2690 } |
2690 | 2691 |
2691 | 2692 |
2692 // Called when the top-level V8 mutex is destroyed. | 2693 // Called when the top-level V8 mutex is destroyed. |
2693 void Bootstrapper::FreeThreadResources() { | 2694 void Bootstrapper::FreeThreadResources() { |
2694 ASSERT(!IsActive()); | 2695 ASSERT(!IsActive()); |
2695 } | 2696 } |
2696 | 2697 |
2697 } } // namespace v8::internal | 2698 } } // namespace v8::internal |
OLD | NEW |