ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1 | // Copyright 2006-2008 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #include "v8.h" |
| 29 | |
| 30 | #include "bootstrapper.h" |
| 31 | #include "debug.h" |
| 32 | #include "serialize.h" |
| 33 | #include "stub-cache.h" |
| 34 | |
| 35 | namespace v8 { namespace internal { |
| 36 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 37 | bool V8::has_been_setup_ = false; |
| 38 | bool V8::has_been_disposed_ = false; |
| 39 | |
| 40 | bool V8::Initialize(Deserializer *des) { |
| 41 | bool create_heap_objects = des == NULL; |
| 42 | if (HasBeenDisposed()) return false; |
| 43 | if (HasBeenSetup()) return true; |
| 44 | has_been_setup_ = true; |
| 45 | #ifdef DEBUG |
| 46 | // The initialization process does not handle memory exhaustion. |
| 47 | DisallowAllocationFailure disallow_allocation_failure; |
| 48 | #endif |
| 49 | |
| 50 | // Enable logging before setting up the heap |
| 51 | Logger::Setup(); |
| 52 | if (des) des->GetLog(); |
| 53 | |
| 54 | // Setup the CPU support. |
| 55 | CPU::Setup(); |
| 56 | |
| 57 | // Setup the platform OS support. |
| 58 | OS::Setup(); |
| 59 | |
| 60 | // Setup the object heap |
| 61 | ASSERT(!Heap::HasBeenSetup()); |
| 62 | if (!Heap::Setup(create_heap_objects)) { |
| 63 | has_been_setup_ = false; |
| 64 | return false; |
| 65 | } |
| 66 | |
| 67 | // Initialize other runtime facilities |
| 68 | Bootstrapper::Initialize(create_heap_objects); |
| 69 | Builtins::Setup(create_heap_objects); |
| 70 | Top::Initialize(); |
| 71 | |
| 72 | if (FLAG_preemption) { |
| 73 | v8::Locker locker; |
| 74 | v8::Locker::StartPreemption(100); |
| 75 | } |
| 76 | |
| 77 | Debug::Setup(create_heap_objects); |
| 78 | StubCache::Initialize(create_heap_objects); |
| 79 | |
| 80 | // If we are deserializing, read the state into the now-empty heap. |
| 81 | if (des != NULL) { |
| 82 | des->Deserialize(); |
| 83 | StubCache::Clear(); |
| 84 | } |
| 85 | |
| 86 | return true; |
| 87 | } |
| 88 | |
| 89 | |
| 90 | void V8::TearDown() { |
| 91 | if (HasBeenDisposed()) return; |
| 92 | if (!HasBeenSetup()) return; |
| 93 | |
| 94 | if (FLAG_preemption) { |
| 95 | v8::Locker locker; |
| 96 | v8::Locker::StopPreemption(); |
| 97 | } |
| 98 | |
| 99 | Builtins::TearDown(); |
| 100 | Bootstrapper::TearDown(); |
| 101 | |
kasper.lund | af4734f | 2008-07-28 12:50:18 +0000 | [diff] [blame] | 102 | Top::TearDown(); |
| 103 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 104 | Heap::TearDown(); |
| 105 | Logger::TearDown(); |
| 106 | |
| 107 | has_been_setup_ = false; |
| 108 | has_been_disposed_ = true; |
| 109 | } |
| 110 | |
| 111 | } } // namespace v8::internal |