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" |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 34 | #include "oprofile-agent.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 35 | |
| 36 | namespace v8 { namespace internal { |
| 37 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 38 | bool V8::has_been_setup_ = false; |
| 39 | bool V8::has_been_disposed_ = false; |
| 40 | |
| 41 | bool V8::Initialize(Deserializer *des) { |
| 42 | bool create_heap_objects = des == NULL; |
| 43 | if (HasBeenDisposed()) return false; |
| 44 | if (HasBeenSetup()) return true; |
| 45 | has_been_setup_ = true; |
| 46 | #ifdef DEBUG |
| 47 | // The initialization process does not handle memory exhaustion. |
| 48 | DisallowAllocationFailure disallow_allocation_failure; |
| 49 | #endif |
| 50 | |
| 51 | // Enable logging before setting up the heap |
| 52 | Logger::Setup(); |
| 53 | if (des) des->GetLog(); |
| 54 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 55 | // Setup the platform OS support. |
| 56 | OS::Setup(); |
| 57 | |
| 58 | // Setup the object heap |
| 59 | ASSERT(!Heap::HasBeenSetup()); |
| 60 | if (!Heap::Setup(create_heap_objects)) { |
| 61 | has_been_setup_ = false; |
| 62 | return false; |
| 63 | } |
| 64 | |
| 65 | // Initialize other runtime facilities |
| 66 | Bootstrapper::Initialize(create_heap_objects); |
| 67 | Builtins::Setup(create_heap_objects); |
| 68 | Top::Initialize(); |
| 69 | |
| 70 | if (FLAG_preemption) { |
| 71 | v8::Locker locker; |
| 72 | v8::Locker::StartPreemption(100); |
| 73 | } |
| 74 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 75 | #ifdef ENABLE_DEBUGGER_SUPPORT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 76 | Debug::Setup(create_heap_objects); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 77 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 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 | |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 86 | // Setup the CPU support. Must be done after heap setup and after |
| 87 | // any deserialization because we have to have the initial heap |
| 88 | // objects in place for creating the code object used for probing. |
| 89 | CPU::Setup(); |
| 90 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 91 | OProfileAgent::Initialize(); |
| 92 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 93 | return true; |
| 94 | } |
| 95 | |
| 96 | |
| 97 | void V8::TearDown() { |
| 98 | if (HasBeenDisposed()) return; |
| 99 | if (!HasBeenSetup()) return; |
| 100 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 101 | OProfileAgent::TearDown(); |
| 102 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 103 | if (FLAG_preemption) { |
| 104 | v8::Locker locker; |
| 105 | v8::Locker::StopPreemption(); |
| 106 | } |
| 107 | |
| 108 | Builtins::TearDown(); |
| 109 | Bootstrapper::TearDown(); |
| 110 | |
kasper.lund | af4734f | 2008-07-28 12:50:18 +0000 | [diff] [blame] | 111 | Top::TearDown(); |
| 112 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 113 | Heap::TearDown(); |
| 114 | Logger::TearDown(); |
| 115 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 116 | has_been_setup_ = false; |
| 117 | has_been_disposed_ = true; |
| 118 | } |
| 119 | |
| 120 | } } // namespace v8::internal |