blob: cc1673e13fe826d164615993f48152c044e16849 [file] [log] [blame]
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001// Copyright 2006-2008 the V8 project authors. All rights reserved.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002// 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//
29// Top include for all V8 .cc files.
30//
31
32#ifndef V8_V8_H_
33#define V8_V8_H_
34
mads.s.ager31e71382008-08-13 09:32:07 +000035#if defined(GOOGLE3)
36// Google3 special flag handling.
37#if defined(DEBUG) && defined(NDEBUG)
38// If both are defined in Google3, then we are building an optimized v8 with
39// assertions enabled.
40#undef NDEBUG
ager@chromium.org3bf7b912008-11-17 09:09:45 +000041#elif !defined(DEBUG) && !defined(NDEBUG)
42// If neither is defined in Google3, then we are building a debug v8. Mark it
43// as such.
44#define DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000045#endif
mads.s.ager31e71382008-08-13 09:32:07 +000046#endif // defined(GOOGLE3)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000047
48// V8 only uses DEBUG, but included external files
49// may use NDEBUG - make sure they are consistent.
50#if defined(DEBUG) && defined(NDEBUG)
51#error both DEBUG and NDEBUG are set
52#endif
53
54// Basic includes
v8.team.kasperl727e9952008-09-02 14:56:44 +000055#include "../include/v8.h"
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +000056#include "v8globals.h"
ager@chromium.orgbeb25712010-11-29 08:02:25 +000057#include "v8checks.h"
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000058#include "allocation.h"
whesse@chromium.orgf0ac72d2010-11-08 12:47:26 +000059#include "v8utils.h"
kasperl@chromium.orgb9123622008-09-17 14:05:56 +000060#include "flags.h"
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000061
62// Objects & heap
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000063#include "objects-inl.h"
64#include "spaces-inl.h"
65#include "heap-inl.h"
ager@chromium.org3e875802009-06-29 08:26:34 +000066#include "log-inl.h"
lrn@chromium.org25156de2010-04-06 13:10:27 +000067#include "cpu-profiler-inl.h"
ager@chromium.orgce5e87b2010-03-10 10:24:18 +000068#include "handles-inl.h"
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000069
kasperl@chromium.org71affb52009-05-26 05:44:31 +000070namespace v8 {
71namespace internal {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000072
ager@chromium.orgc4c92722009-11-18 14:12:51 +000073class Deserializer;
74
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000075class V8 : public AllStatic {
76 public:
77 // Global actions.
78
ager@chromium.orgeadaf222009-06-16 09:43:10 +000079 // If Initialize is called with des == NULL, the initial state is
80 // created from scratch. If a non-null Deserializer is given, the
81 // initial state is created by reading the deserialized data into an
82 // empty heap.
ager@chromium.orgc4c92722009-11-18 14:12:51 +000083 static bool Initialize(Deserializer* des);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000084 static void TearDown();
kasperl@chromium.org71affb52009-05-26 05:44:31 +000085 static bool IsRunning() { return is_running_; }
kasperl@chromium.orga5551262010-12-07 12:49:48 +000086 static bool UseCrankshaft() { return use_crankshaft_; }
87 static void DisableCrankshaft() { use_crankshaft_ = false; }
kasperl@chromium.org71affb52009-05-26 05:44:31 +000088 // To be dead you have to have lived
89 static bool IsDead() { return has_fatal_error_ || has_been_disposed_; }
90 static void SetFatalError();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000091
92 // Report process out of memory. Implementation found in api.cc.
lrn@chromium.orgc4e51ac2010-08-09 09:47:21 +000093 static void FatalProcessOutOfMemory(const char* location,
94 bool take_snapshot = false);
ager@chromium.orgeadaf222009-06-16 09:43:10 +000095
96 // Random number generation support. Not cryptographically safe.
97 static uint32_t Random();
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +000098 // We use random numbers internally in memory allocation and in the
99 // compilers for security. In order to prevent information leaks we
100 // use a separate random state for internal random number
101 // generation.
102 static uint32_t RandomPrivate();
ager@chromium.org357bf652010-04-12 11:30:10 +0000103 static Object* FillHeapNumberWithRandom(Object* heap_number);
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000104
ager@chromium.orgadd848f2009-08-13 12:44:13 +0000105 // Idle notification directly from the API.
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000106 static bool IdleNotification();
ager@chromium.orgadd848f2009-08-13 12:44:13 +0000107
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000108 private:
kasperl@chromium.org71affb52009-05-26 05:44:31 +0000109 // True if engine is currently running
110 static bool is_running_;
111 // True if V8 has ever been run
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000112 static bool has_been_setup_;
kasperl@chromium.org71affb52009-05-26 05:44:31 +0000113 // True if error has been signaled for current engine
114 // (reset to false if engine is restarted)
115 static bool has_fatal_error_;
116 // True if engine has been shut down
117 // (reset if engine is restarted)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000118 static bool has_been_disposed_;
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000119 // True if we are using the crankshaft optimizing compiler.
120 static bool use_crankshaft_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000121};
122
123} } // namespace v8::internal
124
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000125namespace i = v8::internal;
126
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000127#endif // V8_V8_H_