1fab1498f2f42726c7de46c3ed560d56dd072a8b3rossberg@chromium.org// Copyright 2012 the V8 project authors. All rights reserved.
23484964a86451e86dcf04be9bd8c0d76ee04f081rossberg@chromium.org// Use of this source code is governed by a BSD-style license that can be
33484964a86451e86dcf04be9bd8c0d76ee04f081rossberg@chromium.org// found in the LICENSE file.
4ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
5ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org#ifndef V8_ISOLATE_H_
6ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org#define V8_ISOLATE_H_
7ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
8196eb601290dc49c3754da728dc58700dff2de1bmachenbach@chromium.org#include "include/v8-debug.h"
9196eb601290dc49c3754da728dc58700dff2de1bmachenbach@chromium.org#include "src/allocation.h"
10196eb601290dc49c3754da728dc58700dff2de1bmachenbach@chromium.org#include "src/assert-scope.h"
111e2d50cf3d94ff48285da107b7a9da1ad0fc873dmachenbach@chromium.org#include "src/base/atomicops.h"
12196eb601290dc49c3754da728dc58700dff2de1bmachenbach@chromium.org#include "src/builtins.h"
13196eb601290dc49c3754da728dc58700dff2de1bmachenbach@chromium.org#include "src/contexts.h"
144b0feeef5d01dbc2948080b4f69daa37e1083461machenbach@chromium.org#include "src/date.h"
15196eb601290dc49c3754da728dc58700dff2de1bmachenbach@chromium.org#include "src/execution.h"
16196eb601290dc49c3754da728dc58700dff2de1bmachenbach@chromium.org#include "src/frames.h"
17196eb601290dc49c3754da728dc58700dff2de1bmachenbach@chromium.org#include "src/global-handles.h"
18196eb601290dc49c3754da728dc58700dff2de1bmachenbach@chromium.org#include "src/handles.h"
19196eb601290dc49c3754da728dc58700dff2de1bmachenbach@chromium.org#include "src/hashmap.h"
203e3d253bd8018d7627422bf55a5c7bb7e7d6ad7emachenbach@chromium.org#include "src/heap/heap.h"
21196eb601290dc49c3754da728dc58700dff2de1bmachenbach@chromium.org#include "src/optimizing-compiler-thread.h"
22196eb601290dc49c3754da728dc58700dff2de1bmachenbach@chromium.org#include "src/regexp-stack.h"
23196eb601290dc49c3754da728dc58700dff2de1bmachenbach@chromium.org#include "src/runtime.h"
244b0feeef5d01dbc2948080b4f69daa37e1083461machenbach@chromium.org#include "src/runtime-profiler.h"
25196eb601290dc49c3754da728dc58700dff2de1bmachenbach@chromium.org#include "src/zone.h"
26ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
27ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgnamespace v8 {
285de0074a922429f5e0ec2cf140c2d2989bf88140yangguo@chromium.org
295de0074a922429f5e0ec2cf140c2d2989bf88140yangguo@chromium.orgnamespace base {
305de0074a922429f5e0ec2cf140c2d2989bf88140yangguo@chromium.orgclass RandomNumberGenerator;
315de0074a922429f5e0ec2cf140c2d2989bf88140yangguo@chromium.org}
325de0074a922429f5e0ec2cf140c2d2989bf88140yangguo@chromium.org
33ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgnamespace internal {
34ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
35ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgclass Bootstrapper;
369aaa825cf89e1bcfece269a453300ebf4a26d64dmachenbach@chromium.orgclass CallInterfaceDescriptorData;
37ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgclass CodeGenerator;
38ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgclass CodeRange;
39e20e19efeef112c26d0e63b1e5118e695b42d855machenbach@chromium.orgclass CodeStubDescriptor;
40e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.orgclass CodeTracer;
41ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgclass CompilationCache;
4257a54ace4b6b45d5d6a7ff38d88ee9990d47f5e2machenbach@chromium.orgclass ConsStringIteratorOp;
43ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgclass ContextSlotCache;
44ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgclass Counters;
45ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgclass CpuFeatures;
46ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgclass CpuProfiler;
47ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgclass DeoptimizerData;
48ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgclass Deserializer;
49ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgclass EmptyStatement;
50c73d55b355913690124f3ee70c344035431cdd3ayangguo@chromium.orgclass ExternalCallbackScope;
51ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgclass ExternalReferenceTable;
52ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgclass Factory;
53ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgclass FunctionInfoListener;
54ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgclass HandleScopeImplementer;
55ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgclass HeapProfiler;
56750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.orgclass HStatistics;
57750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.orgclass HTracer;
58ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgclass InlineRuntimeFunctionsTable;
59c3b670ff19220959730d7886892bc4beb95d2ebaerik.corry@gmail.comclass InnerPointerToCodeCache;
6057a54ace4b6b45d5d6a7ff38d88ee9990d47f5e2machenbach@chromium.orgclass MaterializedObjectStore;
615924917d324a643d00a8aefee030bd4acea0de0bmachenbach@chromium.orgclass CodeAgingHelper;
62ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgclass RegExpStack;
63ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgclass SaveContext;
64ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgclass StringTracker;
65ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgclass StubCache;
66e3b8d0fe80e858c990832db1233c069f8b8cd5c9mstarzinger@chromium.orgclass SweeperThread;
67ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgclass ThreadManager;
68ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgclass ThreadState;
69ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgclass ThreadVisitor;  // Defined in v8threads.h
7057a54ace4b6b45d5d6a7ff38d88ee9990d47f5e2machenbach@chromium.orgclass UnicodeCache;
71ca29dd85fa02449d17188f5a6ff9a7cdf2ad9680danno@chromium.orgtemplate <StateTag Tag> class VMState;
72ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
73ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org// 'void function pointer', used to roundtrip the
74ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org// ExternalReference::ExternalReferenceRedirector since we can not include
75ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org// assembler.h, where it is defined, here.
76ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgtypedef void* ExternalReferenceRedirectorPointer();
77ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
78ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
79ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgclass Debug;
80ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgclass Debugger;
815e57059e20217fd540b60c237d326414afe2171emachenbach@chromium.orgclass PromiseOnStack;
82ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
8393a47f4837f2137c8d8349250fd8e91da3108126jkummerow@chromium.org#if !defined(__arm__) && V8_TARGET_ARCH_ARM || \
84fa0c3c69b9d632e5730bdd9c745c375beef5e54dmachenbach@chromium.org    !defined(__aarch64__) && V8_TARGET_ARCH_ARM64 || \
8512e05e8fde625d746b998a15049e8487c43a3b17machenbach@chromium.org    !defined(__mips__) && V8_TARGET_ARCH_MIPS || \
8612e05e8fde625d746b998a15049e8487c43a3b17machenbach@chromium.org    !defined(__mips__) && V8_TARGET_ARCH_MIPS64
87ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgclass Redirection;
88ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgclass Simulator;
89ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org#endif
90ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
917516f05132429850aa326421ed3e25f23b4c071blrn@chromium.org
92ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org// Static indirection table for handles to constants.  If a frame
93ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org// element represents a constant, the data contains an index into
94ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org// this table of handles to the actual constants.
95ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org// Static indirection table for handles to constants.  If a Result
96ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org// represents a constant, the data contains an index into this table
97ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org// of handles to the actual constants.
98ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgtypedef ZoneList<Handle<Object> > ZoneObjectList;
99ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1008496027a525ad457b6d5729faf41f29100a27264machenbach@chromium.org#define RETURN_FAILURE_IF_SCHEDULED_EXCEPTION(isolate)    \
101fab1498f2f42726c7de46c3ed560d56dd072a8b3rossberg@chromium.org  do {                                                    \
102fab1498f2f42726c7de46c3ed560d56dd072a8b3rossberg@chromium.org    Isolate* __isolate__ = (isolate);                     \
103fab1498f2f42726c7de46c3ed560d56dd072a8b3rossberg@chromium.org    if (__isolate__->has_scheduled_exception()) {         \
104fab1498f2f42726c7de46c3ed560d56dd072a8b3rossberg@chromium.org      return __isolate__->PromoteScheduledException();    \
105fab1498f2f42726c7de46c3ed560d56dd072a8b3rossberg@chromium.org    }                                                     \
106fab1498f2f42726c7de46c3ed560d56dd072a8b3rossberg@chromium.org  } while (false)
107ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
108255043f8054e713a64509c707cfabadd42344683machenbach@chromium.org// Macros for MaybeHandle.
109255043f8054e713a64509c707cfabadd42344683machenbach@chromium.org
110eb81c479217278e101fc47fd29872a7e68f02402machenbach@chromium.org#define RETURN_VALUE_IF_SCHEDULED_EXCEPTION(isolate, value) \
111eb81c479217278e101fc47fd29872a7e68f02402machenbach@chromium.org  do {                                                      \
112eb81c479217278e101fc47fd29872a7e68f02402machenbach@chromium.org    Isolate* __isolate__ = (isolate);                       \
113eb81c479217278e101fc47fd29872a7e68f02402machenbach@chromium.org    if (__isolate__->has_scheduled_exception()) {           \
114eb81c479217278e101fc47fd29872a7e68f02402machenbach@chromium.org      __isolate__->PromoteScheduledException();             \
115eb81c479217278e101fc47fd29872a7e68f02402machenbach@chromium.org      return value;                                         \
116eb81c479217278e101fc47fd29872a7e68f02402machenbach@chromium.org    }                                                       \
117255043f8054e713a64509c707cfabadd42344683machenbach@chromium.org  } while (false)
118255043f8054e713a64509c707cfabadd42344683machenbach@chromium.org
119eb81c479217278e101fc47fd29872a7e68f02402machenbach@chromium.org#define RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, T) \
120eb81c479217278e101fc47fd29872a7e68f02402machenbach@chromium.org  RETURN_VALUE_IF_SCHEDULED_EXCEPTION(isolate, MaybeHandle<T>())
121eb81c479217278e101fc47fd29872a7e68f02402machenbach@chromium.org
122255043f8054e713a64509c707cfabadd42344683machenbach@chromium.org#define ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, dst, call, value)  \
123255043f8054e713a64509c707cfabadd42344683machenbach@chromium.org  do {                                                               \
124255043f8054e713a64509c707cfabadd42344683machenbach@chromium.org    if (!(call).ToHandle(&dst)) {                                    \
125e3c177a423baa3c30225c4e422b6f6c76d38b951machenbach@chromium.org      DCHECK((isolate)->has_pending_exception());                    \
126255043f8054e713a64509c707cfabadd42344683machenbach@chromium.org      return value;                                                  \
127255043f8054e713a64509c707cfabadd42344683machenbach@chromium.org    }                                                                \
128255043f8054e713a64509c707cfabadd42344683machenbach@chromium.org  } while (false)
129255043f8054e713a64509c707cfabadd42344683machenbach@chromium.org
130255043f8054e713a64509c707cfabadd42344683machenbach@chromium.org#define ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, dst, call)  \
131a77ec9c2cf67e5b9c707fe42f33574526fed189amachenbach@chromium.org  ASSIGN_RETURN_ON_EXCEPTION_VALUE(                             \
132a77ec9c2cf67e5b9c707fe42f33574526fed189amachenbach@chromium.org      isolate, dst, call, isolate->heap()->exception())
133255043f8054e713a64509c707cfabadd42344683machenbach@chromium.org
134255043f8054e713a64509c707cfabadd42344683machenbach@chromium.org#define ASSIGN_RETURN_ON_EXCEPTION(isolate, dst, call, T)  \
135255043f8054e713a64509c707cfabadd42344683machenbach@chromium.org  ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, dst, call, MaybeHandle<T>())
136255043f8054e713a64509c707cfabadd42344683machenbach@chromium.org
137ada3a6017e603965f87fa34f6e2fa60379e8d697machenbach@chromium.org#define THROW_NEW_ERROR(isolate, call, T)                                    \
138ada3a6017e603965f87fa34f6e2fa60379e8d697machenbach@chromium.org  do {                                                                       \
139ada3a6017e603965f87fa34f6e2fa60379e8d697machenbach@chromium.org    Handle<Object> __error__;                                                \
140ada3a6017e603965f87fa34f6e2fa60379e8d697machenbach@chromium.org    ASSIGN_RETURN_ON_EXCEPTION(isolate, __error__, isolate->factory()->call, \
141ada3a6017e603965f87fa34f6e2fa60379e8d697machenbach@chromium.org                               T);                                           \
142ada3a6017e603965f87fa34f6e2fa60379e8d697machenbach@chromium.org    return isolate->Throw<T>(__error__);                                     \
143ada3a6017e603965f87fa34f6e2fa60379e8d697machenbach@chromium.org  } while (false)
144ada3a6017e603965f87fa34f6e2fa60379e8d697machenbach@chromium.org
145ada3a6017e603965f87fa34f6e2fa60379e8d697machenbach@chromium.org#define THROW_NEW_ERROR_RETURN_FAILURE(isolate, call)             \
146ada3a6017e603965f87fa34f6e2fa60379e8d697machenbach@chromium.org  do {                                                            \
147ada3a6017e603965f87fa34f6e2fa60379e8d697machenbach@chromium.org    Handle<Object> __error__;                                     \
148ada3a6017e603965f87fa34f6e2fa60379e8d697machenbach@chromium.org    ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, __error__,        \
149ada3a6017e603965f87fa34f6e2fa60379e8d697machenbach@chromium.org                                       isolate->factory()->call); \
150ada3a6017e603965f87fa34f6e2fa60379e8d697machenbach@chromium.org    return isolate->Throw(*__error__);                            \
151ada3a6017e603965f87fa34f6e2fa60379e8d697machenbach@chromium.org  } while (false)
152ada3a6017e603965f87fa34f6e2fa60379e8d697machenbach@chromium.org
1538f8fe81d7a9cced7a0d30e56124c0428d1a6d229machenbach@chromium.org#define RETURN_ON_EXCEPTION_VALUE(isolate, call, value)            \
154255043f8054e713a64509c707cfabadd42344683machenbach@chromium.org  do {                                                             \
155255043f8054e713a64509c707cfabadd42344683machenbach@chromium.org    if ((call).is_null()) {                                        \
156e3c177a423baa3c30225c4e422b6f6c76d38b951machenbach@chromium.org      DCHECK((isolate)->has_pending_exception());                  \
157255043f8054e713a64509c707cfabadd42344683machenbach@chromium.org      return value;                                                \
158255043f8054e713a64509c707cfabadd42344683machenbach@chromium.org    }                                                              \
159255043f8054e713a64509c707cfabadd42344683machenbach@chromium.org  } while (false)
160255043f8054e713a64509c707cfabadd42344683machenbach@chromium.org
161255043f8054e713a64509c707cfabadd42344683machenbach@chromium.org#define RETURN_FAILURE_ON_EXCEPTION(isolate, call)  \
162a77ec9c2cf67e5b9c707fe42f33574526fed189amachenbach@chromium.org  RETURN_ON_EXCEPTION_VALUE(isolate, call, isolate->heap()->exception())
163255043f8054e713a64509c707cfabadd42344683machenbach@chromium.org
164255043f8054e713a64509c707cfabadd42344683machenbach@chromium.org#define RETURN_ON_EXCEPTION(isolate, call, T)  \
1658f8fe81d7a9cced7a0d30e56124c0428d1a6d229machenbach@chromium.org  RETURN_ON_EXCEPTION_VALUE(isolate, call, MaybeHandle<T>())
166255043f8054e713a64509c707cfabadd42344683machenbach@chromium.org
167255043f8054e713a64509c707cfabadd42344683machenbach@chromium.org
16883e168294456ca2f02db421a635f7d5f5d023966kmillikin@chromium.org#define FOR_EACH_ISOLATE_ADDRESS_NAME(C)                \
16983e168294456ca2f02db421a635f7d5f5d023966kmillikin@chromium.org  C(Handler, handler)                                   \
17083e168294456ca2f02db421a635f7d5f5d023966kmillikin@chromium.org  C(CEntryFP, c_entry_fp)                               \
17183e168294456ca2f02db421a635f7d5f5d023966kmillikin@chromium.org  C(Context, context)                                   \
17283e168294456ca2f02db421a635f7d5f5d023966kmillikin@chromium.org  C(PendingException, pending_exception)                \
17383e168294456ca2f02db421a635f7d5f5d023966kmillikin@chromium.org  C(ExternalCaughtException, external_caught_exception) \
17483e168294456ca2f02db421a635f7d5f5d023966kmillikin@chromium.org  C(JSEntrySP, js_entry_sp)
175ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
176ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
177a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org// Platform-independent, reliable thread identifier.
178a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.orgclass ThreadId {
179a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org public:
180a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org  // Creates an invalid ThreadId.
181a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org  ThreadId() : id_(kInvalidId) {}
182a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org
183a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org  // Returns ThreadId for current thread.
184a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org  static ThreadId Current() { return ThreadId(GetCurrentThreadId()); }
185a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org
186a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org  // Returns invalid ThreadId (guaranteed not to be equal to any thread).
187a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org  static ThreadId Invalid() { return ThreadId(kInvalidId); }
188a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org
189a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org  // Compares ThreadIds for equality.
190a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org  INLINE(bool Equals(const ThreadId& other) const) {
191a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org    return id_ == other.id_;
192a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org  }
193a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org
194a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org  // Checks whether this ThreadId refers to any thread.
195a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org  INLINE(bool IsValid() const) {
196a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org    return id_ != kInvalidId;
197a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org  }
198a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org
199a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org  // Converts ThreadId to an integer representation
200a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org  // (required for public API: V8::V8::GetCurrentThreadId).
201a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org  int ToInteger() const { return id_; }
202a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org
203a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org  // Converts ThreadId to an integer representation
204a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org  // (required for public API: V8::V8::TerminateExecution).
205a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org  static ThreadId FromInteger(int id) { return ThreadId(id); }
206a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org
207a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org private:
208a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org  static const int kInvalidId = -1;
209a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org
210a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org  explicit ThreadId(int id) : id_(id) {}
211a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org
212a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org  static int AllocateThreadId();
213a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org
214a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org  static int GetCurrentThreadId();
215a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org
216a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org  int id_;
217a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org
2181e2d50cf3d94ff48285da107b7a9da1ad0fc873dmachenbach@chromium.org  static base::Atomic32 highest_thread_id_;
219a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org
220a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org  friend class Isolate;
221a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org};
222a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org
223a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org
224f5a24546072ecdbbd6372c85c42157e01e913561titzer@chromium.org#define FIELD_ACCESSOR(type, name)                 \
225f5a24546072ecdbbd6372c85c42157e01e913561titzer@chromium.org  inline void set_##name(type v) { name##_ = v; }  \
226f5a24546072ecdbbd6372c85c42157e01e913561titzer@chromium.org  inline type name() const { return name##_; }
227f5a24546072ecdbbd6372c85c42157e01e913561titzer@chromium.org
228f5a24546072ecdbbd6372c85c42157e01e913561titzer@chromium.org
229ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgclass ThreadLocalTop BASE_EMBEDDED {
230ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org public:
2315523ec3bee8180775e7a6fff2b57c04ef707ad3bvitalyr@chromium.org  // Does early low-level initialization that does not depend on the
2325523ec3bee8180775e7a6fff2b57c04ef707ad3bvitalyr@chromium.org  // isolate being present.
2335523ec3bee8180775e7a6fff2b57c04ef707ad3bvitalyr@chromium.org  ThreadLocalTop();
2345523ec3bee8180775e7a6fff2b57c04ef707ad3bvitalyr@chromium.org
235ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // Initialize the thread data.
236ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  void Initialize();
237ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
238ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // Get the top C++ try catch handler or NULL if none are registered.
239ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  //
2406a4d394882dba70a85567fb90ffd4f428a9eb170machenbach@chromium.org  // This method is not guaranteed to return an address that can be
241ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // used for comparison with addresses into the JS stack.  If such an
242ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // address is needed, use try_catch_handler_address.
2436a4d394882dba70a85567fb90ffd4f428a9eb170machenbach@chromium.org  FIELD_ACCESSOR(v8::TryCatch*, try_catch_handler)
244ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
245ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // Get the address of the top C++ try catch handler or NULL if
246ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // none are registered.
247ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  //
248ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // This method always returns an address that can be compared to
249ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // pointers into the JavaScript stack.  When running on actual
250ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // hardware, try_catch_handler_address and TryCatchHandler return
251ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // the same pointer.  When running on a simulator with a separate JS
252ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // stack, try_catch_handler_address returns a JS stack address that
253ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // corresponds to the place on the JS stack where the C++ handler
254ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // would have been if the stack were not separate.
2556a4d394882dba70a85567fb90ffd4f428a9eb170machenbach@chromium.org  Address try_catch_handler_address() {
2566a4d394882dba70a85567fb90ffd4f428a9eb170machenbach@chromium.org    return reinterpret_cast<Address>(
2576a4d394882dba70a85567fb90ffd4f428a9eb170machenbach@chromium.org        v8::TryCatch::JSStackComparableAddress(try_catch_handler()));
2586a4d394882dba70a85567fb90ffd4f428a9eb170machenbach@chromium.org  }
259ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
2605e57059e20217fd540b60c237d326414afe2171emachenbach@chromium.org  void Free();
261ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
2621c09276ce2ac5214e81ca554360b9f101187893blrn@chromium.org  Isolate* isolate_;
263ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // The context where the current execution method is created and for variable
264ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // lookups.
265ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  Context* context_;
266a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org  ThreadId thread_id_;
2679e41f9ecf5042292a9efcb36e264b37621199553machenbach@chromium.org  Object* pending_exception_;
268ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  bool has_pending_message_;
26993a47f4837f2137c8d8349250fd8e91da3108126jkummerow@chromium.org  bool rethrowing_message_;
270ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  Object* pending_message_obj_;
27193a47f4837f2137c8d8349250fd8e91da3108126jkummerow@chromium.org  Object* pending_message_script_;
272ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  int pending_message_start_pos_;
273ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  int pending_message_end_pos_;
274ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // Use a separate value for scheduled exceptions to preserve the
275ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // invariants that hold about pending_exception.  We may want to
276ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // unify them later.
2779e41f9ecf5042292a9efcb36e264b37621199553machenbach@chromium.org  Object* scheduled_exception_;
278ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  bool external_caught_exception_;
279ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  SaveContext* save_context_;
280ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  v8::TryCatch* catcher_;
281ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
282ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // Stack.
283ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  Address c_entry_fp_;  // the frame pointer of the top c entry frame
284ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  Address handler_;   // try-blocks are chained through the stack
285ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
2865e57059e20217fd540b60c237d326414afe2171emachenbach@chromium.org  // Throwing an exception may cause a Promise rejection.  For this purpose
2875e57059e20217fd540b60c237d326414afe2171emachenbach@chromium.org  // we keep track of a stack of nested promises and the corresponding
2885e57059e20217fd540b60c237d326414afe2171emachenbach@chromium.org  // try-catch handlers.
2895e57059e20217fd540b60c237d326414afe2171emachenbach@chromium.org  PromiseOnStack* promise_on_stack_;
2905e57059e20217fd540b60c237d326414afe2171emachenbach@chromium.org
291ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org#ifdef USE_SIMULATOR
292ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  Simulator* simulator_;
293ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org#endif
294ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
2952efb900e7350b14be905abdeab077f3a64c583cfulan@chromium.org  Address js_entry_sp_;  // the stack pointer of the bottom JS entry frame
296c73d55b355913690124f3ee70c344035431cdd3ayangguo@chromium.org  // the external callback we're currently in
297c73d55b355913690124f3ee70c344035431cdd3ayangguo@chromium.org  ExternalCallbackScope* external_callback_scope_;
298ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  StateTag current_vm_state_;
299ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
300ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // Generated code scratch locations.
301ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  int32_t formal_count_;
302ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
303ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // Call back function to report unsafe JS accesses.
304ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  v8::FailedAccessCheckCallback failed_access_check_callback_;
305ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
306394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com  // Head of the list of live LookupResults.
307394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com  LookupResult* top_lookup_result_;
308394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com
309ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org private:
3105523ec3bee8180775e7a6fff2b57c04ef707ad3bvitalyr@chromium.org  void InitializeInternal();
3115523ec3bee8180775e7a6fff2b57c04ef707ad3bvitalyr@chromium.org
3126a4d394882dba70a85567fb90ffd4f428a9eb170machenbach@chromium.org  v8::TryCatch* try_catch_handler_;
313ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org};
314ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
315ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
3166b6df382019a622ba20133e47bbe2e6f323b013bdslomov@chromium.org#if V8_TARGET_ARCH_ARM && !defined(__arm__) || \
317fa0c3c69b9d632e5730bdd9c745c375beef5e54dmachenbach@chromium.org    V8_TARGET_ARCH_ARM64 && !defined(__aarch64__) || \
31812e05e8fde625d746b998a15049e8487c43a3b17machenbach@chromium.org    V8_TARGET_ARCH_MIPS && !defined(__mips__) || \
31912e05e8fde625d746b998a15049e8487c43a3b17machenbach@chromium.org    V8_TARGET_ARCH_MIPS64 && !defined(__mips__)
3206b6df382019a622ba20133e47bbe2e6f323b013bdslomov@chromium.org
3216b6df382019a622ba20133e47bbe2e6f323b013bdslomov@chromium.org#define ISOLATE_INIT_SIMULATOR_LIST(V)                                         \
3226b6df382019a622ba20133e47bbe2e6f323b013bdslomov@chromium.org  V(bool, simulator_initialized, false)                                        \
3236b6df382019a622ba20133e47bbe2e6f323b013bdslomov@chromium.org  V(HashMap*, simulator_i_cache, NULL)                                         \
3246b6df382019a622ba20133e47bbe2e6f323b013bdslomov@chromium.org  V(Redirection*, simulator_redirection, NULL)
3256b6df382019a622ba20133e47bbe2e6f323b013bdslomov@chromium.org#else
3266b6df382019a622ba20133e47bbe2e6f323b013bdslomov@chromium.org
3276b6df382019a622ba20133e47bbe2e6f323b013bdslomov@chromium.org#define ISOLATE_INIT_SIMULATOR_LIST(V)
3286b6df382019a622ba20133e47bbe2e6f323b013bdslomov@chromium.org
3296b6df382019a622ba20133e47bbe2e6f323b013bdslomov@chromium.org#endif
3306b6df382019a622ba20133e47bbe2e6f323b013bdslomov@chromium.org
3316b6df382019a622ba20133e47bbe2e6f323b013bdslomov@chromium.org
332ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org#ifdef DEBUG
333ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
334ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org#define ISOLATE_INIT_DEBUG_ARRAY_LIST(V)                                       \
335ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  V(CommentStatistic, paged_space_comments_statistics,                         \
3366b6df382019a622ba20133e47bbe2e6f323b013bdslomov@chromium.org      CommentStatistic::kMaxComments + 1)                                      \
3376b6df382019a622ba20133e47bbe2e6f323b013bdslomov@chromium.org  V(int, code_kind_statistics, Code::NUMBER_OF_KINDS)
338ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org#else
339ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
340ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org#define ISOLATE_INIT_DEBUG_ARRAY_LIST(V)
341ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
342ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org#endif
343ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
344ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org#define ISOLATE_INIT_ARRAY_LIST(V)                                             \
345ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  /* SerializerDeserializer state. */                                          \
346355cfd19c23ac613f2738a40e356ea48297f7d5eyangguo@chromium.org  V(int32_t, jsregexp_static_offsets_vector, kJSRegexpStaticOffsetsVectorSize) \
347ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  V(int, bad_char_shift_table, kUC16AlphabetSize)                              \
348ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  V(int, good_suffix_shift_table, (kBMMaxShift + 1))                           \
349ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  V(int, suffix_table, (kBMMaxShift + 1))                                      \
3504f693d6b99ffdbc05e5e211e08ed5039e13279d2ricow@chromium.org  V(uint32_t, private_random_seed, 2)                                          \
351ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  ISOLATE_INIT_DEBUG_ARRAY_LIST(V)
352ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
3537ff7607c2315ea91e4d13330ce14125e4bb4851amachenbach@chromium.orgtypedef List<HeapObject*> DebugObjectCache;
354ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
355ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org#define ISOLATE_INIT_LIST(V)                                                   \
356ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  /* SerializerDeserializer state. */                                          \
357ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  V(int, serialize_partial_snapshot_cache_length, 0)                           \
3585a11aaf63fdb7843c9b116fdb84ee35b0a980ea6yangguo@chromium.org  V(int, serialize_partial_snapshot_cache_capacity, 0)                         \
3595a11aaf63fdb7843c9b116fdb84ee35b0a980ea6yangguo@chromium.org  V(Object**, serialize_partial_snapshot_cache, NULL)                          \
360ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  /* Assembler state. */                                                       \
361ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  V(FatalErrorCallback, exception_behavior, NULL)                              \
362ca2f2040e0e1a10df95bec18e69499f85f4c1316machenbach@chromium.org  V(LogEventCallback, event_logger, NULL)                                      \
363fb144a0716afe7ab8bf245f2391a9e53b3db3c89fschneider@chromium.org  V(AllowCodeGenerationFromStringsCallback, allow_code_gen_callback, NULL)     \
364ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  /* To distinguish the function templates, so that we can find them in the */ \
36546839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org  /* function cache of the native context. */                                  \
366ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  V(int, next_serial_number, 0)                                                \
367ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  V(ExternalReferenceRedirectorPointer*, external_reference_redirector, NULL)  \
368ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  /* Part of the state of liveedit. */                                         \
369ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  V(FunctionInfoListener*, active_function_info_listener, NULL)                \
370ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  /* State for Relocatable. */                                                 \
371ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  V(Relocatable*, relocatable_top, NULL)                                       \
372ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  V(DebugObjectCache*, string_stream_debug_object_cache, NULL)                 \
373ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  V(Object*, string_stream_current_security_token, NULL)                       \
374ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  /* Serializer state. */                                                      \
375ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  V(ExternalReferenceTable*, external_reference_table, NULL)                   \
37654ae5fb0902b9e1b89c178fa5a7ba4e1a74daa41machenbach@chromium.org  V(int, pending_microtask_count, 0)                                           \
377f5a24546072ecdbbd6372c85c42157e01e913561titzer@chromium.org  V(bool, autorun_microtasks, true)                                            \
378750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org  V(HStatistics*, hstatistics, NULL)                                           \
3797d299ad4dc0ca26e0017b190b48362ad71328ce4machenbach@chromium.org  V(HStatistics*, tstatistics, NULL)                                           \
380750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org  V(HTracer*, htracer, NULL)                                                   \
381e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org  V(CodeTracer*, code_tracer, NULL)                                            \
3826b6df382019a622ba20133e47bbe2e6f323b013bdslomov@chromium.org  V(bool, fp_stubs_generated, false)                                           \
3836b6df382019a622ba20133e47bbe2e6f323b013bdslomov@chromium.org  V(int, max_available_threads, 0)                                             \
3845697144afb43181fed170b81c194fe1cc0fce3b6machenbach@chromium.org  V(uint32_t, per_isolate_assert_data, 0xFFFFFFFFu)                            \
3853c3c8d733702cb2b41471efa5eead1faf5b5711bmachenbach@chromium.org  V(InterruptCallback, api_interrupt_callback, NULL)                           \
3863c3c8d733702cb2b41471efa5eead1faf5b5711bmachenbach@chromium.org  V(void*, api_interrupt_callback_data, NULL)                                  \
387865f51ff8c94f86f4c97636d70addc0f29e79674machenbach@chromium.org  ISOLATE_INIT_SIMULATOR_LIST(V)
388ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
389f5a24546072ecdbbd6372c85c42157e01e913561titzer@chromium.org#define THREAD_LOCAL_TOP_ACCESSOR(type, name)                        \
390f5a24546072ecdbbd6372c85c42157e01e913561titzer@chromium.org  inline void set_##name(type v) { thread_local_top_.name##_ = v; }  \
391f5a24546072ecdbbd6372c85c42157e01e913561titzer@chromium.org  inline type name() const { return thread_local_top_.name##_; }
392f5a24546072ecdbbd6372c85c42157e01e913561titzer@chromium.org
393f5a24546072ecdbbd6372c85c42157e01e913561titzer@chromium.org
394ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgclass Isolate {
395ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // These forward declarations are required to make the friend declarations in
396ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // PerIsolateThreadData work on some older versions of gcc.
397ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  class ThreadDataTable;
398ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  class EntryStackItem;
399ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org public:
400ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  ~Isolate();
401ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
402ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // A thread has a PerIsolateThreadData instance for each isolate that it has
403ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // entered. That instance is allocated when the isolate is initially entered
404ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // and reused on subsequent entries.
405ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  class PerIsolateThreadData {
406ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org   public:
407ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    PerIsolateThreadData(Isolate* isolate, ThreadId thread_id)
408ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org        : isolate_(isolate),
409ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org          thread_id_(thread_id),
410ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org          stack_limit_(0),
411ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org          thread_state_(NULL),
41293a47f4837f2137c8d8349250fd8e91da3108126jkummerow@chromium.org#if !defined(__arm__) && V8_TARGET_ARCH_ARM || \
413fa0c3c69b9d632e5730bdd9c745c375beef5e54dmachenbach@chromium.org    !defined(__aarch64__) && V8_TARGET_ARCH_ARM64 || \
41412e05e8fde625d746b998a15049e8487c43a3b17machenbach@chromium.org    !defined(__mips__) && V8_TARGET_ARCH_MIPS || \
41512e05e8fde625d746b998a15049e8487c43a3b17machenbach@chromium.org    !defined(__mips__) && V8_TARGET_ARCH_MIPS64
416ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org          simulator_(NULL),
417ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org#endif
418ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org          next_(NULL),
419ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org          prev_(NULL) { }
420f5a24546072ecdbbd6372c85c42157e01e913561titzer@chromium.org    ~PerIsolateThreadData();
421ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    Isolate* isolate() const { return isolate_; }
422ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    ThreadId thread_id() const { return thread_id_; }
423f5a24546072ecdbbd6372c85c42157e01e913561titzer@chromium.org
424f5a24546072ecdbbd6372c85c42157e01e913561titzer@chromium.org    FIELD_ACCESSOR(uintptr_t, stack_limit)
425f5a24546072ecdbbd6372c85c42157e01e913561titzer@chromium.org    FIELD_ACCESSOR(ThreadState*, thread_state)
426ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
42793a47f4837f2137c8d8349250fd8e91da3108126jkummerow@chromium.org#if !defined(__arm__) && V8_TARGET_ARCH_ARM || \
428fa0c3c69b9d632e5730bdd9c745c375beef5e54dmachenbach@chromium.org    !defined(__aarch64__) && V8_TARGET_ARCH_ARM64 || \
42912e05e8fde625d746b998a15049e8487c43a3b17machenbach@chromium.org    !defined(__mips__) && V8_TARGET_ARCH_MIPS || \
43012e05e8fde625d746b998a15049e8487c43a3b17machenbach@chromium.org    !defined(__mips__) && V8_TARGET_ARCH_MIPS64
431f5a24546072ecdbbd6372c85c42157e01e913561titzer@chromium.org    FIELD_ACCESSOR(Simulator*, simulator)
432ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org#endif
433ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
434ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    bool Matches(Isolate* isolate, ThreadId thread_id) const {
435a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org      return isolate_ == isolate && thread_id_.Equals(thread_id);
436ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    }
437ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
438ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org   private:
439ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    Isolate* isolate_;
440ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    ThreadId thread_id_;
441ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    uintptr_t stack_limit_;
442ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    ThreadState* thread_state_;
443ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
44493a47f4837f2137c8d8349250fd8e91da3108126jkummerow@chromium.org#if !defined(__arm__) && V8_TARGET_ARCH_ARM || \
445fa0c3c69b9d632e5730bdd9c745c375beef5e54dmachenbach@chromium.org    !defined(__aarch64__) && V8_TARGET_ARCH_ARM64 || \
44612e05e8fde625d746b998a15049e8487c43a3b17machenbach@chromium.org    !defined(__mips__) && V8_TARGET_ARCH_MIPS || \
44712e05e8fde625d746b998a15049e8487c43a3b17machenbach@chromium.org    !defined(__mips__) && V8_TARGET_ARCH_MIPS64
448ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    Simulator* simulator_;
449ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org#endif
450ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
451ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    PerIsolateThreadData* next_;
452ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    PerIsolateThreadData* prev_;
453ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
454ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    friend class Isolate;
455ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    friend class ThreadDataTable;
456ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    friend class EntryStackItem;
457ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
458ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    DISALLOW_COPY_AND_ASSIGN(PerIsolateThreadData);
459ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  };
460ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
461ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
462ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  enum AddressId {
46383e168294456ca2f02db421a635f7d5f5d023966kmillikin@chromium.org#define DECLARE_ENUM(CamelName, hacker_name) k##CamelName##Address,
46483e168294456ca2f02db421a635f7d5f5d023966kmillikin@chromium.org    FOR_EACH_ISOLATE_ADDRESS_NAME(DECLARE_ENUM)
465efdb9d70bddd496ceb6a281dadcc065efbce37a1yangguo@chromium.org#undef DECLARE_ENUM
46683e168294456ca2f02db421a635f7d5f5d023966kmillikin@chromium.org    kIsolateAddressCount
467ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  };
468ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
469a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.org  static void InitializeOncePerProcess();
470a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.org
471ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // Returns the PerIsolateThreadData for the current thread (or NULL if one is
472ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // not currently set).
473ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  static PerIsolateThreadData* CurrentPerIsolateThreadData() {
474ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    return reinterpret_cast<PerIsolateThreadData*>(
4755de0074a922429f5e0ec2cf140c2d2989bf88140yangguo@chromium.org        base::Thread::GetThreadLocal(per_isolate_thread_data_key_));
476ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
477ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
478ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // Returns the isolate inside which the current thread is running.
479ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  INLINE(static Isolate* Current()) {
4807979bbb1df2eaff193e85d44c8da1ffa1525b7fcfschneider@chromium.org    Isolate* isolate = reinterpret_cast<Isolate*>(
4815de0074a922429f5e0ec2cf140c2d2989bf88140yangguo@chromium.org        base::Thread::GetExistingThreadLocal(isolate_key_));
482e3c177a423baa3c30225c4e422b6f6c76d38b951machenbach@chromium.org    DCHECK(isolate != NULL);
483ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    return isolate;
484ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
485ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
486ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  INLINE(static Isolate* UncheckedCurrent()) {
487f15d0cdbef11a212e108432465f014a7d3c3aa12machenbach@chromium.org    return reinterpret_cast<Isolate*>(
488f15d0cdbef11a212e108432465f014a7d3c3aa12machenbach@chromium.org        base::Thread::GetThreadLocal(isolate_key_));
489f15d0cdbef11a212e108432465f014a7d3c3aa12machenbach@chromium.org  }
490f15d0cdbef11a212e108432465f014a7d3c3aa12machenbach@chromium.org
491f15d0cdbef11a212e108432465f014a7d3c3aa12machenbach@chromium.org  // Like UncheckedCurrent, but skips the check that |isolate_key_| was
492f15d0cdbef11a212e108432465f014a7d3c3aa12machenbach@chromium.org  // initialized. Callers have to ensure that themselves.
493f15d0cdbef11a212e108432465f014a7d3c3aa12machenbach@chromium.org  INLINE(static Isolate* UnsafeCurrent()) {
4945de0074a922429f5e0ec2cf140c2d2989bf88140yangguo@chromium.org    return reinterpret_cast<Isolate*>(
4955de0074a922429f5e0ec2cf140c2d2989bf88140yangguo@chromium.org        base::Thread::GetThreadLocal(isolate_key_));
496ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
497ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
4987c2628c3f0353f0558760c3ca442f934263ea766kmillikin@chromium.org  // Usually called by Init(), but can be called early e.g. to allow
4997c2628c3f0353f0558760c3ca442f934263ea766kmillikin@chromium.org  // testing components that require logging but not the whole
5007c2628c3f0353f0558760c3ca442f934263ea766kmillikin@chromium.org  // isolate.
5017c2628c3f0353f0558760c3ca442f934263ea766kmillikin@chromium.org  //
5027c2628c3f0353f0558760c3ca442f934263ea766kmillikin@chromium.org  // Safe to call more than once.
5037c2628c3f0353f0558760c3ca442f934263ea766kmillikin@chromium.org  void InitializeLoggingAndCounters();
5047c2628c3f0353f0558760c3ca442f934263ea766kmillikin@chromium.org
505ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  bool Init(Deserializer* des);
506ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
507ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  bool IsInitialized() { return state_ == INITIALIZED; }
508ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
509ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // True if at least one thread Enter'ed this isolate.
510ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  bool IsInUse() { return entry_stack_ != NULL; }
511ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
512ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // Destroys the non-default isolates.
513ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // Sets default isolate into "has_been_disposed" state rather then destroying,
514ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // for legacy API reasons.
515ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  void TearDown();
516ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
5177c3372bc426136cb79479c1b59d1770f5528882ahpayer@chromium.org  static void GlobalTearDown();
5187c3372bc426136cb79479c1b59d1770f5528882ahpayer@chromium.org
5191c09276ce2ac5214e81ca554360b9f101187893blrn@chromium.org  // Find the PerThread for this particular (isolate, thread) combination
5201c09276ce2ac5214e81ca554360b9f101187893blrn@chromium.org  // If one does not yet exist, return null.
5211c09276ce2ac5214e81ca554360b9f101187893blrn@chromium.org  PerIsolateThreadData* FindPerThreadDataForThisThread();
5221c09276ce2ac5214e81ca554360b9f101187893blrn@chromium.org
523e27d617298263725e8a48c2aa14029759b952623mstarzinger@chromium.org  // Find the PerThread for given (isolate, thread) combination
524e27d617298263725e8a48c2aa14029759b952623mstarzinger@chromium.org  // If one does not yet exist, return null.
525e27d617298263725e8a48c2aa14029759b952623mstarzinger@chromium.org  PerIsolateThreadData* FindPerThreadDataForThread(ThreadId thread_id);
526e27d617298263725e8a48c2aa14029759b952623mstarzinger@chromium.org
527ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // Returns the key used to store the pointer to the current isolate.
528ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // Used internally for V8 threads that do not execute JavaScript but still
529ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // are part of the domain of an isolate (like the context switcher).
5305de0074a922429f5e0ec2cf140c2d2989bf88140yangguo@chromium.org  static base::Thread::LocalStorageKey isolate_key() {
5318c0a43f09f145d9fc6f969d559873018176eeb6adanno@chromium.org    return isolate_key_;
5328c0a43f09f145d9fc6f969d559873018176eeb6adanno@chromium.org  }
533ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
534ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // Returns the key used to store process-wide thread IDs.
5355de0074a922429f5e0ec2cf140c2d2989bf88140yangguo@chromium.org  static base::Thread::LocalStorageKey thread_id_key() {
5368c0a43f09f145d9fc6f969d559873018176eeb6adanno@chromium.org    return thread_id_key_;
5378c0a43f09f145d9fc6f969d559873018176eeb6adanno@chromium.org  }
5381456e708d277e725ca42a03463af16fe471c9210jkummerow@chromium.org
5395de0074a922429f5e0ec2cf140c2d2989bf88140yangguo@chromium.org  static base::Thread::LocalStorageKey per_isolate_thread_data_key();
540ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
541ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // Mutex for serializing access to break control structures.
5425de0074a922429f5e0ec2cf140c2d2989bf88140yangguo@chromium.org  base::RecursiveMutex* break_access() { return &break_access_; }
543ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
544ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  Address get_address_from_id(AddressId id);
545ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
546ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // Access to top context (where the current function object was created).
547ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  Context* context() { return thread_local_top_.context_; }
548ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  void set_context(Context* context) {
549e3c177a423baa3c30225c4e422b6f6c76d38b951machenbach@chromium.org    DCHECK(context == NULL || context->IsContext());
550ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    thread_local_top_.context_ = context;
551ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
552ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  Context** context_address() { return &thread_local_top_.context_; }
553ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
554f5a24546072ecdbbd6372c85c42157e01e913561titzer@chromium.org  THREAD_LOCAL_TOP_ACCESSOR(SaveContext*, save_context)
555ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
556ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // Access to current thread id.
557f5a24546072ecdbbd6372c85c42157e01e913561titzer@chromium.org  THREAD_LOCAL_TOP_ACCESSOR(ThreadId, thread_id)
558ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
559ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // Interface to pending exception.
5609e41f9ecf5042292a9efcb36e264b37621199553machenbach@chromium.org  Object* pending_exception() {
561e3c177a423baa3c30225c4e422b6f6c76d38b951machenbach@chromium.org    DCHECK(has_pending_exception());
562e3c177a423baa3c30225c4e422b6f6c76d38b951machenbach@chromium.org    DCHECK(!thread_local_top_.pending_exception_->IsException());
563ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    return thread_local_top_.pending_exception_;
564ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
565f5a24546072ecdbbd6372c85c42157e01e913561titzer@chromium.org
566a77ec9c2cf67e5b9c707fe42f33574526fed189amachenbach@chromium.org  void set_pending_exception(Object* exception_obj) {
567e3c177a423baa3c30225c4e422b6f6c76d38b951machenbach@chromium.org    DCHECK(!exception_obj->IsException());
568a77ec9c2cf67e5b9c707fe42f33574526fed189amachenbach@chromium.org    thread_local_top_.pending_exception_ = exception_obj;
569ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
570f5a24546072ecdbbd6372c85c42157e01e913561titzer@chromium.org
571ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  void clear_pending_exception() {
572e3c177a423baa3c30225c4e422b6f6c76d38b951machenbach@chromium.org    DCHECK(!thread_local_top_.pending_exception_->IsException());
573ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    thread_local_top_.pending_exception_ = heap_.the_hole_value();
574ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
575f5a24546072ecdbbd6372c85c42157e01e913561titzer@chromium.org
5769e41f9ecf5042292a9efcb36e264b37621199553machenbach@chromium.org  Object** pending_exception_address() {
577ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    return &thread_local_top_.pending_exception_;
578ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
579f5a24546072ecdbbd6372c85c42157e01e913561titzer@chromium.org
580ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  bool has_pending_exception() {
581e3c177a423baa3c30225c4e422b6f6c76d38b951machenbach@chromium.org    DCHECK(!thread_local_top_.pending_exception_->IsException());
582ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    return !thread_local_top_.pending_exception_->IsTheHole();
583ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
584f5a24546072ecdbbd6372c85c42157e01e913561titzer@chromium.org
585f5a24546072ecdbbd6372c85c42157e01e913561titzer@chromium.org  THREAD_LOCAL_TOP_ACCESSOR(bool, external_caught_exception)
586f5a24546072ecdbbd6372c85c42157e01e913561titzer@chromium.org
587ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  void clear_pending_message() {
588ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    thread_local_top_.has_pending_message_ = false;
589ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    thread_local_top_.pending_message_obj_ = heap_.the_hole_value();
59093a47f4837f2137c8d8349250fd8e91da3108126jkummerow@chromium.org    thread_local_top_.pending_message_script_ = heap_.the_hole_value();
591ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
592ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  v8::TryCatch* try_catch_handler() {
5936a4d394882dba70a85567fb90ffd4f428a9eb170machenbach@chromium.org    return thread_local_top_.try_catch_handler();
594ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
595ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  Address try_catch_handler_address() {
596ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    return thread_local_top_.try_catch_handler_address();
597ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
598ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  bool* external_caught_exception_address() {
599ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    return &thread_local_top_.external_caught_exception_;
600ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
601f5a24546072ecdbbd6372c85c42157e01e913561titzer@chromium.org
602f5a24546072ecdbbd6372c85c42157e01e913561titzer@chromium.org  THREAD_LOCAL_TOP_ACCESSOR(v8::TryCatch*, catcher)
603ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
6049e41f9ecf5042292a9efcb36e264b37621199553machenbach@chromium.org  Object** scheduled_exception_address() {
605ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    return &thread_local_top_.scheduled_exception_;
606ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
6077028c05c1c71b9d5c5fe1bca01f2461d17a2dda7mmassi@chromium.org
6087028c05c1c71b9d5c5fe1bca01f2461d17a2dda7mmassi@chromium.org  Address pending_message_obj_address() {
6097028c05c1c71b9d5c5fe1bca01f2461d17a2dda7mmassi@chromium.org    return reinterpret_cast<Address>(&thread_local_top_.pending_message_obj_);
6107028c05c1c71b9d5c5fe1bca01f2461d17a2dda7mmassi@chromium.org  }
6117028c05c1c71b9d5c5fe1bca01f2461d17a2dda7mmassi@chromium.org
6127028c05c1c71b9d5c5fe1bca01f2461d17a2dda7mmassi@chromium.org  Address has_pending_message_address() {
6137028c05c1c71b9d5c5fe1bca01f2461d17a2dda7mmassi@chromium.org    return reinterpret_cast<Address>(&thread_local_top_.has_pending_message_);
6147028c05c1c71b9d5c5fe1bca01f2461d17a2dda7mmassi@chromium.org  }
6157028c05c1c71b9d5c5fe1bca01f2461d17a2dda7mmassi@chromium.org
6167028c05c1c71b9d5c5fe1bca01f2461d17a2dda7mmassi@chromium.org  Address pending_message_script_address() {
6177028c05c1c71b9d5c5fe1bca01f2461d17a2dda7mmassi@chromium.org    return reinterpret_cast<Address>(
6187028c05c1c71b9d5c5fe1bca01f2461d17a2dda7mmassi@chromium.org        &thread_local_top_.pending_message_script_);
6197028c05c1c71b9d5c5fe1bca01f2461d17a2dda7mmassi@chromium.org  }
6207028c05c1c71b9d5c5fe1bca01f2461d17a2dda7mmassi@chromium.org
6219e41f9ecf5042292a9efcb36e264b37621199553machenbach@chromium.org  Object* scheduled_exception() {
622e3c177a423baa3c30225c4e422b6f6c76d38b951machenbach@chromium.org    DCHECK(has_scheduled_exception());
623e3c177a423baa3c30225c4e422b6f6c76d38b951machenbach@chromium.org    DCHECK(!thread_local_top_.scheduled_exception_->IsException());
624ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    return thread_local_top_.scheduled_exception_;
625ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
626ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  bool has_scheduled_exception() {
627e3c177a423baa3c30225c4e422b6f6c76d38b951machenbach@chromium.org    DCHECK(!thread_local_top_.scheduled_exception_->IsException());
6286d786c9805481bd13ecb29c3155540f2f32950e1svenpanne@chromium.org    return thread_local_top_.scheduled_exception_ != heap_.the_hole_value();
629ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
630ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  void clear_scheduled_exception() {
631e3c177a423baa3c30225c4e422b6f6c76d38b951machenbach@chromium.org    DCHECK(!thread_local_top_.scheduled_exception_->IsException());
632ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    thread_local_top_.scheduled_exception_ = heap_.the_hole_value();
633ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
634ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
635fd703f3d69389b9129ab38adb1caeb2be7a21ecfmachenbach@chromium.org  bool HasExternalTryCatch();
636fd703f3d69389b9129ab38adb1caeb2be7a21ecfmachenbach@chromium.org  bool IsFinallyOnTop();
637ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
6389e41f9ecf5042292a9efcb36e264b37621199553machenbach@chromium.org  bool is_catchable_by_javascript(Object* exception) {
639a221880197f38ff22d942851060daffa5d036bdfmachenbach@chromium.org    return exception != heap()->termination_exception();
640ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
641ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
6425a11aaf63fdb7843c9b116fdb84ee35b0a980ea6yangguo@chromium.org  // Serializer.
6435a11aaf63fdb7843c9b116fdb84ee35b0a980ea6yangguo@chromium.org  void PushToPartialSnapshotCache(Object* obj);
6445a11aaf63fdb7843c9b116fdb84ee35b0a980ea6yangguo@chromium.org
645ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // JS execution stack (see frames.h).
646ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  static Address c_entry_fp(ThreadLocalTop* thread) {
647ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    return thread->c_entry_fp_;
648ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
649ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  static Address handler(ThreadLocalTop* thread) { return thread->handler_; }
650ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
651ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  inline Address* c_entry_fp_address() {
652ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    return &thread_local_top_.c_entry_fp_;
653ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
654ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  inline Address* handler_address() { return &thread_local_top_.handler_; }
655ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
656594006017e46d82ed7146611dc12c20e3c509c7ddanno@chromium.org  // Bottom JS entry.
657594006017e46d82ed7146611dc12c20e3c509c7ddanno@chromium.org  Address js_entry_sp() {
658594006017e46d82ed7146611dc12c20e3c509c7ddanno@chromium.org    return thread_local_top_.js_entry_sp_;
659ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
660ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  inline Address* js_entry_sp_address() {
661ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    return &thread_local_top_.js_entry_sp_;
662ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
663ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
664ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // Generated code scratch locations.
665ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  void* formal_count_address() { return &thread_local_top_.formal_count_; }
666ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
667ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // Returns the global object of the current context. It could be
6682efb900e7350b14be905abdeab077f3a64c583cfulan@chromium.org  // a builtin object, or a JS global object.
66946839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org  Handle<GlobalObject> global_object() {
67046839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org    return Handle<GlobalObject>(context()->global_object());
671ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
672ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
673ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // Returns the global proxy object of the current context.
67458a725587734a6889c689668fd01f0157ed749a6machenbach@chromium.org  JSObject* global_proxy() {
675ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    return context()->global_proxy();
676ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
677ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
678ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  Handle<JSBuiltinsObject> js_builtins_object() {
679ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    return Handle<JSBuiltinsObject>(thread_local_top_.context_->builtins());
680ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
681ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
682ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  static int ArchiveSpacePerThread() { return sizeof(ThreadLocalTop); }
683ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  void FreeThreadResources() { thread_local_top_.Free(); }
684ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
685ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // This method is called by the api after operations that may throw
686ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // exceptions.  If an exception was thrown and not handled by an external
687ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // handler the exception is scheduled to be rethrown when we return to running
688ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // JavaScript code.  If an exception is scheduled true is returned.
689ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  bool OptionalRescheduleException(bool is_bottom_call);
690ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
6915e57059e20217fd540b60c237d326414afe2171emachenbach@chromium.org  // Push and pop a promise and the current try-catch handler.
6925e57059e20217fd540b60c237d326414afe2171emachenbach@chromium.org  void PushPromise(Handle<JSObject> promise);
6935e57059e20217fd540b60c237d326414afe2171emachenbach@chromium.org  void PopPromise();
6945e57059e20217fd540b60c237d326414afe2171emachenbach@chromium.org  Handle<Object> GetPromiseOnStackOnThrow();
6955e57059e20217fd540b60c237d326414afe2171emachenbach@chromium.org
69644bc7080a85cc25bff3b9b77cd53f7beffab711bkarlklose@chromium.org  class ExceptionScope {
69744bc7080a85cc25bff3b9b77cd53f7beffab711bkarlklose@chromium.org   public:
69844bc7080a85cc25bff3b9b77cd53f7beffab711bkarlklose@chromium.org    explicit ExceptionScope(Isolate* isolate) :
699a86d416fb652b1936026eee315eccd4f17ca1002machenbach@chromium.org      // Scope currently can only be used for regular exceptions,
700a86d416fb652b1936026eee315eccd4f17ca1002machenbach@chromium.org      // not termination exception.
70144bc7080a85cc25bff3b9b77cd53f7beffab711bkarlklose@chromium.org      isolate_(isolate),
7029e41f9ecf5042292a9efcb36e264b37621199553machenbach@chromium.org      pending_exception_(isolate_->pending_exception(), isolate_),
70344bc7080a85cc25bff3b9b77cd53f7beffab711bkarlklose@chromium.org      catcher_(isolate_->catcher())
70444bc7080a85cc25bff3b9b77cd53f7beffab711bkarlklose@chromium.org    { }
70544bc7080a85cc25bff3b9b77cd53f7beffab711bkarlklose@chromium.org
70644bc7080a85cc25bff3b9b77cd53f7beffab711bkarlklose@chromium.org    ~ExceptionScope() {
70744bc7080a85cc25bff3b9b77cd53f7beffab711bkarlklose@chromium.org      isolate_->set_catcher(catcher_);
70844bc7080a85cc25bff3b9b77cd53f7beffab711bkarlklose@chromium.org      isolate_->set_pending_exception(*pending_exception_);
70944bc7080a85cc25bff3b9b77cd53f7beffab711bkarlklose@chromium.org    }
71044bc7080a85cc25bff3b9b77cd53f7beffab711bkarlklose@chromium.org
71144bc7080a85cc25bff3b9b77cd53f7beffab711bkarlklose@chromium.org   private:
71244bc7080a85cc25bff3b9b77cd53f7beffab711bkarlklose@chromium.org    Isolate* isolate_;
71344bc7080a85cc25bff3b9b77cd53f7beffab711bkarlklose@chromium.org    Handle<Object> pending_exception_;
71444bc7080a85cc25bff3b9b77cd53f7beffab711bkarlklose@chromium.org    v8::TryCatch* catcher_;
71544bc7080a85cc25bff3b9b77cd53f7beffab711bkarlklose@chromium.org  };
71644bc7080a85cc25bff3b9b77cd53f7beffab711bkarlklose@chromium.org
717ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  void SetCaptureStackTraceForUncaughtExceptions(
718ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org      bool capture,
719ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org      int frame_limit,
720ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org      StackTrace::StackTraceOptions options);
721ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
722ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  void PrintCurrentStackTrace(FILE* out);
723ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  void PrintStack(StringStream* accumulator);
724bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org  void PrintStack(FILE* out);
725ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  Handle<String> StackTraceString();
72667255bead6b3c379ed821d8371271e34779602cajkummerow@chromium.org  NO_INLINE(void PushStackTraceAndDie(unsigned int magic,
72767255bead6b3c379ed821d8371271e34779602cajkummerow@chromium.org                                      Object* object,
72867255bead6b3c379ed821d8371271e34779602cajkummerow@chromium.org                                      Map* map,
72967255bead6b3c379ed821d8371271e34779602cajkummerow@chromium.org                                      unsigned int magic2));
730ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  Handle<JSArray> CaptureCurrentStackTrace(
731ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org      int frame_limit,
732ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org      StackTrace::StackTraceOptions options);
733d0bddc653152f270a27fe32d5d7b0f5c0fa3b00cmachenbach@chromium.org  Handle<Object> CaptureSimpleStackTrace(Handle<JSObject> error_object,
734d0bddc653152f270a27fe32d5d7b0f5c0fa3b00cmachenbach@chromium.org                                         Handle<Object> caller);
735eeb44b681a16e45f1415dfacff0ba3dba9de5d8cyangguo@chromium.org  void CaptureAndSetDetailedStackTrace(Handle<JSObject> error_object);
736d0bddc653152f270a27fe32d5d7b0f5c0fa3b00cmachenbach@chromium.org  void CaptureAndSetSimpleStackTrace(Handle<JSObject> error_object,
737d0bddc653152f270a27fe32d5d7b0f5c0fa3b00cmachenbach@chromium.org                                     Handle<Object> caller);
738ab7dad4f999df008b590c74c2fe3d2e2c67ef7ffjkummerow@chromium.org
739ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // Returns if the top context may access the given global object. If
740ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // the result is false, the pending exception is guaranteed to be
741ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // set.
742fb7a7c4ffde9a4d060f5f989371e2ce964ee5831jkummerow@chromium.org
743c2e08d7d6b03e672e13fc3bf274a292009decce6machenbach@chromium.org  bool MayNamedAccess(Handle<JSObject> receiver,
744c2e08d7d6b03e672e13fc3bf274a292009decce6machenbach@chromium.org                      Handle<Object> key,
745ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org                      v8::AccessType type);
746c2e08d7d6b03e672e13fc3bf274a292009decce6machenbach@chromium.org  bool MayIndexedAccess(Handle<JSObject> receiver,
747ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org                        uint32_t index,
748ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org                        v8::AccessType type);
749ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
750ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  void SetFailedAccessCheckCallback(v8::FailedAccessCheckCallback callback);
751c2e08d7d6b03e672e13fc3bf274a292009decce6machenbach@chromium.org  void ReportFailedAccessCheck(Handle<JSObject> receiver, v8::AccessType type);
752ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
753ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // Exception throwing support. The caller should use the result
754ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // of Throw() as its return value.
755a77ec9c2cf67e5b9c707fe42f33574526fed189amachenbach@chromium.org  Object* Throw(Object* exception, MessageLocation* location = NULL);
756255043f8054e713a64509c707cfabadd42344683machenbach@chromium.org
757255043f8054e713a64509c707cfabadd42344683machenbach@chromium.org  template <typename T>
758255043f8054e713a64509c707cfabadd42344683machenbach@chromium.org  MUST_USE_RESULT MaybeHandle<T> Throw(Handle<Object> exception,
759255043f8054e713a64509c707cfabadd42344683machenbach@chromium.org                                       MessageLocation* location = NULL) {
760255043f8054e713a64509c707cfabadd42344683machenbach@chromium.org    Throw(*exception, location);
761255043f8054e713a64509c707cfabadd42344683machenbach@chromium.org    return MaybeHandle<T>();
762255043f8054e713a64509c707cfabadd42344683machenbach@chromium.org  }
763255043f8054e713a64509c707cfabadd42344683machenbach@chromium.org
764ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // Re-throw an exception.  This involves no error reporting since
765ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // error reporting was handled when the exception was thrown
766ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // originally.
767a77ec9c2cf67e5b9c707fe42f33574526fed189amachenbach@chromium.org  Object* ReThrow(Object* exception);
768ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  void ScheduleThrow(Object* exception);
76993a47f4837f2137c8d8349250fd8e91da3108126jkummerow@chromium.org  // Re-set pending message, script and positions reported to the TryCatch
77093a47f4837f2137c8d8349250fd8e91da3108126jkummerow@chromium.org  // back to the TLS for re-use when rethrowing.
77193a47f4837f2137c8d8349250fd8e91da3108126jkummerow@chromium.org  void RestorePendingMessageFromTryCatch(v8::TryCatch* handler);
772474e8b19cf12dc057572a8543864dd6586ee0a65machenbach@chromium.org  // Un-schedule an exception that was caught by a TryCatch handler.
773474e8b19cf12dc057572a8543864dd6586ee0a65machenbach@chromium.org  void CancelScheduledExceptionFromTryCatch(v8::TryCatch* handler);
774ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  void ReportPendingMessages();
77549a44674c6935d62c3e776dfbf896b7f6f34228ammassi@chromium.org  // Return pending location if any or unfilled structure.
77649a44674c6935d62c3e776dfbf896b7f6f34228ammassi@chromium.org  MessageLocation GetMessageLocation();
777a77ec9c2cf67e5b9c707fe42f33574526fed189amachenbach@chromium.org  Object* ThrowIllegalOperation();
778ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
779ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // Promote a scheduled exception to pending. Asserts has_scheduled_exception.
780a77ec9c2cf67e5b9c707fe42f33574526fed189amachenbach@chromium.org  Object* PromoteScheduledException();
781ab7dad4f999df008b590c74c2fe3d2e2c67ef7ffjkummerow@chromium.org  void DoThrow(Object* exception, MessageLocation* location);
782ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // Checks if exception should be reported and finds out if it's
783ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // caught externally.
784ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  bool ShouldReportException(bool* can_be_caught_externally,
785ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org                             bool catchable_by_javascript);
786ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
787ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // Attempts to compute the current source location, storing the
788ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // result in the target out parameter.
789ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  void ComputeLocation(MessageLocation* target);
790ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
791ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // Out of resource exception helpers.
792a77ec9c2cf67e5b9c707fe42f33574526fed189amachenbach@chromium.org  Object* StackOverflow();
793a77ec9c2cf67e5b9c707fe42f33574526fed189amachenbach@chromium.org  Object* TerminateExecution();
79432d7dbafe29be06cec1edd36c31fbe2865c799f4ulan@chromium.org  void CancelTerminateExecution();
795ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
7963c3c8d733702cb2b41471efa5eead1faf5b5711bmachenbach@chromium.org  void InvokeApiInterruptCallback();
7973c3c8d733702cb2b41471efa5eead1faf5b5711bmachenbach@chromium.org
798ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // Administration
799ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  void Iterate(ObjectVisitor* v);
800ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  void Iterate(ObjectVisitor* v, ThreadLocalTop* t);
801ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  char* Iterate(ObjectVisitor* v, char* t);
802ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  void IterateThread(ThreadVisitor* v, char* t);
803ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
804ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
805355cfd19c23ac613f2738a40e356ea48297f7d5eyangguo@chromium.org  // Returns the current native and global context.
80646839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org  Handle<Context> native_context();
807355cfd19c23ac613f2738a40e356ea48297f7d5eyangguo@chromium.org  Handle<Context> global_context();
808ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
80946839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org  // Returns the native context of the calling JavaScript code.  That
81046839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org  // is, the native context of the top-most JavaScript frame.
81146839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org  Handle<Context> GetCallingNativeContext();
812ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
813ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  void RegisterTryCatchHandler(v8::TryCatch* that);
814ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  void UnregisterTryCatchHandler(v8::TryCatch* that);
815ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
816ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  char* ArchiveThread(char* to);
817ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  char* RestoreThread(char* from);
818ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
819ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  static const char* const kStackOverflowMessage;
820ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
821ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  static const int kUC16AlphabetSize = 256;  // See StringSearchBase.
822ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  static const int kBMMaxShift = 250;        // See StringSearchBase.
823ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
824ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // Accessors.
825ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org#define GLOBAL_ACCESSOR(type, name, initialvalue)                       \
826ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  inline type name() const {                                            \
827e3c177a423baa3c30225c4e422b6f6c76d38b951machenbach@chromium.org    DCHECK(OFFSET_OF(Isolate, name##_) == name##_debug_offset_);        \
828ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    return name##_;                                                     \
829ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }                                                                     \
830ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  inline void set_##name(type value) {                                  \
831e3c177a423baa3c30225c4e422b6f6c76d38b951machenbach@chromium.org    DCHECK(OFFSET_OF(Isolate, name##_) == name##_debug_offset_);        \
832ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    name##_ = value;                                                    \
833ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
834ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  ISOLATE_INIT_LIST(GLOBAL_ACCESSOR)
835ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org#undef GLOBAL_ACCESSOR
836ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
837ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org#define GLOBAL_ARRAY_ACCESSOR(type, name, length)                       \
838ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  inline type* name() {                                                 \
839e3c177a423baa3c30225c4e422b6f6c76d38b951machenbach@chromium.org    DCHECK(OFFSET_OF(Isolate, name##_) == name##_debug_offset_);        \
840ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    return &(name##_)[0];                                               \
841ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
842ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  ISOLATE_INIT_ARRAY_LIST(GLOBAL_ARRAY_ACCESSOR)
843ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org#undef GLOBAL_ARRAY_ACCESSOR
844ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
84509d7ab5aba54ebac170eac755664c45eefb0be7dulan@chromium.org#define NATIVE_CONTEXT_FIELD_ACCESSOR(index, type, name)            \
84609d7ab5aba54ebac170eac755664c45eefb0be7dulan@chromium.org  Handle<type> name() {                                             \
84758a725587734a6889c689668fd01f0157ed749a6machenbach@chromium.org    return Handle<type>(native_context()->name(), this);            \
848906e2fb760f52fe6e75b744b1ea42576ea5b2c29ulan@chromium.org  }                                                                 \
849906e2fb760f52fe6e75b744b1ea42576ea5b2c29ulan@chromium.org  bool is_##name(type* value) {                                     \
85058a725587734a6889c689668fd01f0157ed749a6machenbach@chromium.org    return native_context()->is_##name(value);                      \
851ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
85246839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org  NATIVE_CONTEXT_FIELDS(NATIVE_CONTEXT_FIELD_ACCESSOR)
85346839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org#undef NATIVE_CONTEXT_FIELD_ACCESSOR
854ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
855ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  Bootstrapper* bootstrapper() { return bootstrapper_; }
8567c2628c3f0353f0558760c3ca442f934263ea766kmillikin@chromium.org  Counters* counters() {
8577c2628c3f0353f0558760c3ca442f934263ea766kmillikin@chromium.org    // Call InitializeLoggingAndCounters() if logging is needed before
8587c2628c3f0353f0558760c3ca442f934263ea766kmillikin@chromium.org    // the isolate is fully initialized.
859e3c177a423baa3c30225c4e422b6f6c76d38b951machenbach@chromium.org    DCHECK(counters_ != NULL);
8607c2628c3f0353f0558760c3ca442f934263ea766kmillikin@chromium.org    return counters_;
8617c2628c3f0353f0558760c3ca442f934263ea766kmillikin@chromium.org  }
862ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  CodeRange* code_range() { return code_range_; }
863ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  RuntimeProfiler* runtime_profiler() { return runtime_profiler_; }
864ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  CompilationCache* compilation_cache() { return compilation_cache_; }
8657c2628c3f0353f0558760c3ca442f934263ea766kmillikin@chromium.org  Logger* logger() {
8667c2628c3f0353f0558760c3ca442f934263ea766kmillikin@chromium.org    // Call InitializeLoggingAndCounters() if logging is needed before
8677c2628c3f0353f0558760c3ca442f934263ea766kmillikin@chromium.org    // the isolate is fully initialized.
868e3c177a423baa3c30225c4e422b6f6c76d38b951machenbach@chromium.org    DCHECK(logger_ != NULL);
8697c2628c3f0353f0558760c3ca442f934263ea766kmillikin@chromium.org    return logger_;
8707c2628c3f0353f0558760c3ca442f934263ea766kmillikin@chromium.org  }
871ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  StackGuard* stack_guard() { return &stack_guard_; }
872ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  Heap* heap() { return &heap_; }
8737c2628c3f0353f0558760c3ca442f934263ea766kmillikin@chromium.org  StatsTable* stats_table();
874ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  StubCache* stub_cache() { return stub_cache_; }
8755924917d324a643d00a8aefee030bd4acea0de0bmachenbach@chromium.org  CodeAgingHelper* code_aging_helper() { return code_aging_helper_; }
876ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  DeoptimizerData* deoptimizer_data() { return deoptimizer_data_; }
877ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  ThreadLocalTop* thread_local_top() { return &thread_local_top_; }
87857a54ace4b6b45d5d6a7ff38d88ee9990d47f5e2machenbach@chromium.org  MaterializedObjectStore* materialized_object_store() {
87957a54ace4b6b45d5d6a7ff38d88ee9990d47f5e2machenbach@chromium.org    return materialized_object_store_;
88057a54ace4b6b45d5d6a7ff38d88ee9990d47f5e2machenbach@chromium.org  }
881ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
882ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  MemoryAllocator* memory_allocator() {
883ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    return memory_allocator_;
884ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
885ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
886ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  KeyedLookupCache* keyed_lookup_cache() {
887ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    return keyed_lookup_cache_;
888ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
889ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
890ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  ContextSlotCache* context_slot_cache() {
891ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    return context_slot_cache_;
892ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
893ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
894ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  DescriptorLookupCache* descriptor_lookup_cache() {
895ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    return descriptor_lookup_cache_;
896ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
897ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
89826ca35cc4ec47151d9c6d3890b0f052fc79cb8afmachenbach@chromium.org  HandleScopeData* handle_scope_data() { return &handle_scope_data_; }
89926ca35cc4ec47151d9c6d3890b0f052fc79cb8afmachenbach@chromium.org
900ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  HandleScopeImplementer* handle_scope_implementer() {
901e3c177a423baa3c30225c4e422b6f6c76d38b951machenbach@chromium.org    DCHECK(handle_scope_implementer_);
902ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    return handle_scope_implementer_;
903ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
904c1789eecd43bf9c5497636592bf14fa754d04c89machenbach@chromium.org  Zone* runtime_zone() { return &runtime_zone_; }
905ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
906a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org  UnicodeCache* unicode_cache() {
907a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org    return unicode_cache_;
908ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
909ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
910c3b670ff19220959730d7886892bc4beb95d2ebaerik.corry@gmail.com  InnerPointerToCodeCache* inner_pointer_to_code_cache() {
911c3b670ff19220959730d7886892bc4beb95d2ebaerik.corry@gmail.com    return inner_pointer_to_code_cache_;
912c3b670ff19220959730d7886892bc4beb95d2ebaerik.corry@gmail.com  }
913ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
9144cd70b470729dd5850dd4120a350f01363d16837yangguo@chromium.org  ConsStringIteratorOp* write_iterator() { return write_iterator_; }
915ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
916ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  GlobalHandles* global_handles() { return global_handles_; }
917ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
918594006017e46d82ed7146611dc12c20e3c509c7ddanno@chromium.org  EternalHandles* eternal_handles() { return eternal_handles_; }
919594006017e46d82ed7146611dc12c20e3c509c7ddanno@chromium.org
920ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  ThreadManager* thread_manager() { return thread_manager_; }
921ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
922ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  StringTracker* string_tracker() { return string_tracker_; }
923ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
924ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  unibrow::Mapping<unibrow::Ecma262UnCanonicalize>* jsregexp_uncanonicalize() {
925ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    return &jsregexp_uncanonicalize_;
926ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
927ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
928ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  unibrow::Mapping<unibrow::CanonicalizationRange>* jsregexp_canonrange() {
929ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    return &jsregexp_canonrange_;
930ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
931ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
9324cd70b470729dd5850dd4120a350f01363d16837yangguo@chromium.org  ConsStringIteratorOp* objects_string_compare_iterator_a() {
9334cd70b470729dd5850dd4120a350f01363d16837yangguo@chromium.org    return &objects_string_compare_iterator_a_;
934ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
935ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
9364cd70b470729dd5850dd4120a350f01363d16837yangguo@chromium.org  ConsStringIteratorOp* objects_string_compare_iterator_b() {
9374cd70b470729dd5850dd4120a350f01363d16837yangguo@chromium.org    return &objects_string_compare_iterator_b_;
938ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
939ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
9404cd70b470729dd5850dd4120a350f01363d16837yangguo@chromium.org  StaticResource<ConsStringIteratorOp>* objects_string_iterator() {
9414cd70b470729dd5850dd4120a350f01363d16837yangguo@chromium.org    return &objects_string_iterator_;
942ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
943ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
944ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  RuntimeState* runtime_state() { return &runtime_state_; }
945ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
946ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  Builtins* builtins() { return &builtins_; }
947ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
94827bf28851c1fa362a3f7c709871c21dcc9c23ce7ricow@chromium.org  void NotifyExtensionInstalled() {
94927bf28851c1fa362a3f7c709871c21dcc9c23ce7ricow@chromium.org    has_installed_extensions_ = true;
95027bf28851c1fa362a3f7c709871c21dcc9c23ce7ricow@chromium.org  }
95127bf28851c1fa362a3f7c709871c21dcc9c23ce7ricow@chromium.org
95227bf28851c1fa362a3f7c709871c21dcc9c23ce7ricow@chromium.org  bool has_installed_extensions() { return has_installed_extensions_; }
95327bf28851c1fa362a3f7c709871c21dcc9c23ce7ricow@chromium.org
954ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  unibrow::Mapping<unibrow::Ecma262Canonicalize>*
955ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org      regexp_macro_assembler_canonicalize() {
956ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    return &regexp_macro_assembler_canonicalize_;
957ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
958ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
959ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  RegExpStack* regexp_stack() { return regexp_stack_; }
960ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
961ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  unibrow::Mapping<unibrow::Ecma262Canonicalize>*
962ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org      interp_canonicalize_mapping() {
963ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    return &interp_canonicalize_mapping_;
964ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
965ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
966af6f699b0be532b73bc2f6c9e1cf40a57fa7e234machenbach@chromium.org  Debug* debug() { return debug_; }
967ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
9683847bd5ff857259e945a01d75fdb383e2351d166erik.corry@gmail.com  inline bool DebuggerHasBreakPoints();
9693847bd5ff857259e945a01d75fdb383e2351d166erik.corry@gmail.com
970f705b5034dc5bc422ac1019b591469a7d0534772mstarzinger@chromium.org  CpuProfiler* cpu_profiler() const { return cpu_profiler_; }
971f705b5034dc5bc422ac1019b591469a7d0534772mstarzinger@chromium.org  HeapProfiler* heap_profiler() const { return heap_profiler_; }
972f705b5034dc5bc422ac1019b591469a7d0534772mstarzinger@chromium.org
973ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org#ifdef DEBUG
974ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  HistogramInfo* heap_histograms() { return heap_histograms_; }
975ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
976ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  JSObject::SpillInformation* js_spill_information() {
977ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    return &js_spill_information_;
978ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
979ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org#endif
980ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
981ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  Factory* factory() { return reinterpret_cast<Factory*>(this); }
982ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
98315613d0b07bac19e341905ff374c930420b3b9c8mstarzinger@chromium.org  static const int kJSRegexpStaticOffsetsVectorSize = 128;
984ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
985f5a24546072ecdbbd6372c85c42157e01e913561titzer@chromium.org  THREAD_LOCAL_TOP_ACCESSOR(ExternalCallbackScope*, external_callback_scope)
986ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
987f5a24546072ecdbbd6372c85c42157e01e913561titzer@chromium.org  THREAD_LOCAL_TOP_ACCESSOR(StateTag, current_vm_state)
988ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
9897ff7607c2315ea91e4d13330ce14125e4bb4851amachenbach@chromium.org  void SetData(uint32_t slot, void* data) {
990e3c177a423baa3c30225c4e422b6f6c76d38b951machenbach@chromium.org    DCHECK(slot < Internals::kNumIsolateDataSlots);
9917ff7607c2315ea91e4d13330ce14125e4bb4851amachenbach@chromium.org    embedder_data_[slot] = data;
9927ff7607c2315ea91e4d13330ce14125e4bb4851amachenbach@chromium.org  }
9937ff7607c2315ea91e4d13330ce14125e4bb4851amachenbach@chromium.org  void* GetData(uint32_t slot) {
994e3c177a423baa3c30225c4e422b6f6c76d38b951machenbach@chromium.org    DCHECK(slot < Internals::kNumIsolateDataSlots);
9957ff7607c2315ea91e4d13330ce14125e4bb4851amachenbach@chromium.org    return embedder_data_[slot];
9967ff7607c2315ea91e4d13330ce14125e4bb4851amachenbach@chromium.org  }
997ea91cc579ade536e3a08498a8157921dd4f533d1ager@chromium.org
998f5a24546072ecdbbd6372c85c42157e01e913561titzer@chromium.org  THREAD_LOCAL_TOP_ACCESSOR(LookupResult*, top_lookup_result)
999394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com
1000fb547e07aef43e02715c5d6c1530e84bb3cbba02machenbach@chromium.org  void enable_serializer() {
1001fb547e07aef43e02715c5d6c1530e84bb3cbba02machenbach@chromium.org    // The serializer can only be enabled before the isolate init.
1002e3c177a423baa3c30225c4e422b6f6c76d38b951machenbach@chromium.org    DCHECK(state_ != INITIALIZED);
1003fb547e07aef43e02715c5d6c1530e84bb3cbba02machenbach@chromium.org    serializer_enabled_ = true;
1004fb547e07aef43e02715c5d6c1530e84bb3cbba02machenbach@chromium.org  }
1005fb547e07aef43e02715c5d6c1530e84bb3cbba02machenbach@chromium.org
1006fb547e07aef43e02715c5d6c1530e84bb3cbba02machenbach@chromium.org  bool serializer_enabled() const { return serializer_enabled_; }
1007fb547e07aef43e02715c5d6c1530e84bb3cbba02machenbach@chromium.org
1008e900018c7a2a695fde788911564da37535c7e736mstarzinger@chromium.org  bool IsDead() { return has_fatal_error_; }
1009e900018c7a2a695fde788911564da37535c7e736mstarzinger@chromium.org  void SignalFatalError() { has_fatal_error_ = true; }
1010e900018c7a2a695fde788911564da37535c7e736mstarzinger@chromium.org
1011fb547e07aef43e02715c5d6c1530e84bb3cbba02machenbach@chromium.org  bool use_crankshaft() const;
1012e900018c7a2a695fde788911564da37535c7e736mstarzinger@chromium.org
10131510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org  bool initialized_from_snapshot() { return initialized_from_snapshot_; }
10141510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org
1015994edf6a113fb3651536b60073df05a72a95f77erossberg@chromium.org  double time_millis_since_init() {
10165de0074a922429f5e0ec2cf140c2d2989bf88140yangguo@chromium.org    return base::OS::TimeCurrentMillis() - time_millis_at_init_;
1017994edf6a113fb3651536b60073df05a72a95f77erossberg@chromium.org  }
1018994edf6a113fb3651536b60073df05a72a95f77erossberg@chromium.org
10194efbdb18fa3063085682c44cc77cf5254cb3d75dsvenpanne@chromium.org  DateCache* date_cache() {
10204efbdb18fa3063085682c44cc77cf5254cb3d75dsvenpanne@chromium.org    return date_cache_;
10214efbdb18fa3063085682c44cc77cf5254cb3d75dsvenpanne@chromium.org  }
10224efbdb18fa3063085682c44cc77cf5254cb3d75dsvenpanne@chromium.org
10234efbdb18fa3063085682c44cc77cf5254cb3d75dsvenpanne@chromium.org  void set_date_cache(DateCache* date_cache) {
10244efbdb18fa3063085682c44cc77cf5254cb3d75dsvenpanne@chromium.org    if (date_cache != date_cache_) {
10254efbdb18fa3063085682c44cc77cf5254cb3d75dsvenpanne@chromium.org      delete date_cache_;
10264efbdb18fa3063085682c44cc77cf5254cb3d75dsvenpanne@chromium.org    }
10274efbdb18fa3063085682c44cc77cf5254cb3d75dsvenpanne@chromium.org    date_cache_ = date_cache;
10284efbdb18fa3063085682c44cc77cf5254cb3d75dsvenpanne@chromium.org  }
10294efbdb18fa3063085682c44cc77cf5254cb3d75dsvenpanne@chromium.org
1030906e2fb760f52fe6e75b744b1ea42576ea5b2c29ulan@chromium.org  Map* get_initial_js_array_map(ElementsKind kind);
1031906e2fb760f52fe6e75b744b1ea42576ea5b2c29ulan@chromium.org
1032906e2fb760f52fe6e75b744b1ea42576ea5b2c29ulan@chromium.org  bool IsFastArrayConstructorPrototypeChainIntact();
1033906e2fb760f52fe6e75b744b1ea42576ea5b2c29ulan@chromium.org
10349aaa825cf89e1bcfece269a453300ebf4a26d64dmachenbach@chromium.org  CallInterfaceDescriptorData* call_descriptor_data(int index);
103526ca35cc4ec47151d9c6d3890b0f052fc79cb8afmachenbach@chromium.org
1036304cc33f8259ef467e8e3c79f448d0bae0e8cd85yangguo@chromium.org  void IterateDeferredHandles(ObjectVisitor* visitor);
1037304cc33f8259ef467e8e3c79f448d0bae0e8cd85yangguo@chromium.org  void LinkDeferredHandles(DeferredHandles* deferred_handles);
1038304cc33f8259ef467e8e3c79f448d0bae0e8cd85yangguo@chromium.org  void UnlinkDeferredHandles(DeferredHandles* deferred_handles);
1039304cc33f8259ef467e8e3c79f448d0bae0e8cd85yangguo@chromium.org
104032d7dbafe29be06cec1edd36c31fbe2865c799f4ulan@chromium.org#ifdef DEBUG
104132d7dbafe29be06cec1edd36c31fbe2865c799f4ulan@chromium.org  bool IsDeferredHandle(Object** location);
104232d7dbafe29be06cec1edd36c31fbe2865c799f4ulan@chromium.org#endif  // DEBUG
104332d7dbafe29be06cec1edd36c31fbe2865c799f4ulan@chromium.org
10449af454f6b1c6a921ac79ba0b9a979c73adb2ca1emachenbach@chromium.org  bool concurrent_recompilation_enabled() {
10459af454f6b1c6a921ac79ba0b9a979c73adb2ca1emachenbach@chromium.org    // Thread is only available with flag enabled.
1046e3c177a423baa3c30225c4e422b6f6c76d38b951machenbach@chromium.org    DCHECK(optimizing_compiler_thread_ == NULL ||
10479af454f6b1c6a921ac79ba0b9a979c73adb2ca1emachenbach@chromium.org           FLAG_concurrent_recompilation);
10489af454f6b1c6a921ac79ba0b9a979c73adb2ca1emachenbach@chromium.org    return optimizing_compiler_thread_ != NULL;
10499af454f6b1c6a921ac79ba0b9a979c73adb2ca1emachenbach@chromium.org  }
10509af454f6b1c6a921ac79ba0b9a979c73adb2ca1emachenbach@chromium.org
10519af454f6b1c6a921ac79ba0b9a979c73adb2ca1emachenbach@chromium.org  bool concurrent_osr_enabled() const {
10529af454f6b1c6a921ac79ba0b9a979c73adb2ca1emachenbach@chromium.org    // Thread is only available with flag enabled.
1053e3c177a423baa3c30225c4e422b6f6c76d38b951machenbach@chromium.org    DCHECK(optimizing_compiler_thread_ == NULL ||
10549af454f6b1c6a921ac79ba0b9a979c73adb2ca1emachenbach@chromium.org           FLAG_concurrent_recompilation);
10559af454f6b1c6a921ac79ba0b9a979c73adb2ca1emachenbach@chromium.org    return optimizing_compiler_thread_ != NULL && FLAG_concurrent_osr;
10569af454f6b1c6a921ac79ba0b9a979c73adb2ca1emachenbach@chromium.org  }
10579af454f6b1c6a921ac79ba0b9a979c73adb2ca1emachenbach@chromium.org
1058304cc33f8259ef467e8e3c79f448d0bae0e8cd85yangguo@chromium.org  OptimizingCompilerThread* optimizing_compiler_thread() {
10598e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.org    return optimizing_compiler_thread_;
1060304cc33f8259ef467e8e3c79f448d0bae0e8cd85yangguo@chromium.org  }
1061304cc33f8259ef467e8e3c79f448d0bae0e8cd85yangguo@chromium.org
10629af454f6b1c6a921ac79ba0b9a979c73adb2ca1emachenbach@chromium.org  int num_sweeper_threads() const {
10639af454f6b1c6a921ac79ba0b9a979c73adb2ca1emachenbach@chromium.org    return num_sweeper_threads_;
10649af454f6b1c6a921ac79ba0b9a979c73adb2ca1emachenbach@chromium.org  }
106546a2a51ad190697e0f62c3060ce02a9de5820a07yangguo@chromium.org
1066e3b8d0fe80e858c990832db1233c069f8b8cd5c9mstarzinger@chromium.org  SweeperThread** sweeper_threads() {
1067e3b8d0fe80e858c990832db1233c069f8b8cd5c9mstarzinger@chromium.org    return sweeper_thread_;
1068e3b8d0fe80e858c990832db1233c069f8b8cd5c9mstarzinger@chromium.org  }
1069e3b8d0fe80e858c990832db1233c069f8b8cd5c9mstarzinger@chromium.org
10701510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org  int id() const { return static_cast<int>(id_); }
10711510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org
1072750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org  HStatistics* GetHStatistics();
10737d299ad4dc0ca26e0017b190b48362ad71328ce4machenbach@chromium.org  HStatistics* GetTStatistics();
1074750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org  HTracer* GetHTracer();
1075e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org  CodeTracer* GetCodeTracer();
1076750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org
10771510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org  FunctionEntryHook function_entry_hook() { return function_entry_hook_; }
10781510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org  void set_function_entry_hook(FunctionEntryHook function_entry_hook) {
10791510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org    function_entry_hook_ = function_entry_hook;
10801510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org  }
10811510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org
1082ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  void* stress_deopt_count_address() { return &stress_deopt_count_; }
1083ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
10845de0074a922429f5e0ec2cf140c2d2989bf88140yangguo@chromium.org  inline base::RandomNumberGenerator* random_number_generator();
1085c5d4971574b7a205fa0e788d8121dc79485e5e67hpayer@chromium.org
1086ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  // Given an address occupied by a live code object, return that object.
1087ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  Object* FindCodeObject(Address a);
1088ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
1089f5a24546072ecdbbd6372c85c42157e01e913561titzer@chromium.org  int NextOptimizationId() {
1090f5a24546072ecdbbd6372c85c42157e01e913561titzer@chromium.org    int id = next_optimization_id_++;
1091f5a24546072ecdbbd6372c85c42157e01e913561titzer@chromium.org    if (!Smi::IsValid(next_optimization_id_)) {
1092f5a24546072ecdbbd6372c85c42157e01e913561titzer@chromium.org      next_optimization_id_ = 0;
1093f5a24546072ecdbbd6372c85c42157e01e913561titzer@chromium.org    }
1094f5a24546072ecdbbd6372c85c42157e01e913561titzer@chromium.org    return id;
1095f5a24546072ecdbbd6372c85c42157e01e913561titzer@chromium.org  }
1096f5a24546072ecdbbd6372c85c42157e01e913561titzer@chromium.org
1097a221880197f38ff22d942851060daffa5d036bdfmachenbach@chromium.org  // Get (and lazily initialize) the registry for per-isolate symbols.
1098a221880197f38ff22d942851060daffa5d036bdfmachenbach@chromium.org  Handle<JSObject> GetSymbolRegistry();
1099a221880197f38ff22d942851060daffa5d036bdfmachenbach@chromium.org
1100865f51ff8c94f86f4c97636d70addc0f29e79674machenbach@chromium.org  void AddCallCompletedCallback(CallCompletedCallback callback);
1101865f51ff8c94f86f4c97636d70addc0f29e79674machenbach@chromium.org  void RemoveCallCompletedCallback(CallCompletedCallback callback);
1102865f51ff8c94f86f4c97636d70addc0f29e79674machenbach@chromium.org  void FireCallCompletedCallback();
1103865f51ff8c94f86f4c97636d70addc0f29e79674machenbach@chromium.org
110438de99aae2d4efc5796aa6935c1648447ec32fc8machenbach@chromium.org  void EnqueueMicrotask(Handle<Object> microtask);
1105c8e8806f9e54a027d667425f1bb1b28cf9cbb6f7machenbach@chromium.org  void RunMicrotasks();
1106c8e8806f9e54a027d667425f1bb1b28cf9cbb6f7machenbach@chromium.org
1107975b940441085887fc02bebf8877d5ec97e1e06cmachenbach@chromium.org  void SetUseCounterCallback(v8::Isolate::UseCounterCallback callback);
1108975b940441085887fc02bebf8877d5ec97e1e06cmachenbach@chromium.org  void CountUsage(v8::Isolate::UseCounterFeature feature);
1109975b940441085887fc02bebf8877d5ec97e1e06cmachenbach@chromium.org
1110a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.org  static Isolate* NewForTesting() { return new Isolate(); }
111198d807af7db2de0653f82ec1f9639782d5ae5195jochen@chromium.org
1112a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.org private:
1113ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  Isolate();
1114ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
11151456e708d277e725ca42a03463af16fe471c9210jkummerow@chromium.org  friend struct GlobalState;
11161456e708d277e725ca42a03463af16fe471c9210jkummerow@chromium.org  friend struct InitializeGlobalState;
11171456e708d277e725ca42a03463af16fe471c9210jkummerow@chromium.org
1118efdb9d70bddd496ceb6a281dadcc065efbce37a1yangguo@chromium.org  enum State {
1119efdb9d70bddd496ceb6a281dadcc065efbce37a1yangguo@chromium.org    UNINITIALIZED,    // Some components may not have been allocated.
1120efdb9d70bddd496ceb6a281dadcc065efbce37a1yangguo@chromium.org    INITIALIZED       // All components are fully initialized.
1121efdb9d70bddd496ceb6a281dadcc065efbce37a1yangguo@chromium.org  };
1122efdb9d70bddd496ceb6a281dadcc065efbce37a1yangguo@chromium.org
1123efdb9d70bddd496ceb6a281dadcc065efbce37a1yangguo@chromium.org  // These fields are accessed through the API, offsets must be kept in sync
1124efdb9d70bddd496ceb6a281dadcc065efbce37a1yangguo@chromium.org  // with v8::internal::Internals (in include/v8.h) constants. This is also
1125efdb9d70bddd496ceb6a281dadcc065efbce37a1yangguo@chromium.org  // verified in Isolate::Init() using runtime checks.
11267ff7607c2315ea91e4d13330ce14125e4bb4851amachenbach@chromium.org  void* embedder_data_[Internals::kNumIsolateDataSlots];
1127efdb9d70bddd496ceb6a281dadcc065efbce37a1yangguo@chromium.org  Heap heap_;
11287ff7607c2315ea91e4d13330ce14125e4bb4851amachenbach@chromium.org  State state_;  // Will be padded to kApiPointerSize.
1129efdb9d70bddd496ceb6a281dadcc065efbce37a1yangguo@chromium.org
1130ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // The per-process lock should be acquired before the ThreadDataTable is
1131ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // modified.
1132ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  class ThreadDataTable {
1133ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org   public:
1134ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    ThreadDataTable();
1135ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    ~ThreadDataTable();
1136ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1137ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    PerIsolateThreadData* Lookup(Isolate* isolate, ThreadId thread_id);
1138ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    void Insert(PerIsolateThreadData* data);
1139ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    void Remove(PerIsolateThreadData* data);
1140e297f5973a8a9ff0d9945da3f1e2d8a6230c294djkummerow@chromium.org    void RemoveAllThreads(Isolate* isolate);
1141ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1142ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org   private:
1143ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    PerIsolateThreadData* list_;
1144ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  };
1145ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1146ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // These items form a stack synchronously with threads Enter'ing and Exit'ing
1147ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // the Isolate. The top of the stack points to a thread which is currently
1148ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // running the Isolate. When the stack is empty, the Isolate is considered
1149ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // not entered by any thread and can be Disposed.
1150ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // If the same thread enters the Isolate more then once, the entry_count_
1151ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // is incremented rather then a new item pushed to the stack.
1152ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  class EntryStackItem {
1153ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org   public:
1154ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    EntryStackItem(PerIsolateThreadData* previous_thread_data,
1155ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org                   Isolate* previous_isolate,
1156ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org                   EntryStackItem* previous_item)
1157ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org        : entry_count(1),
1158ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org          previous_thread_data(previous_thread_data),
1159ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org          previous_isolate(previous_isolate),
1160ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org          previous_item(previous_item) { }
1161ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1162ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    int entry_count;
1163ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    PerIsolateThreadData* previous_thread_data;
1164ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    Isolate* previous_isolate;
1165ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    EntryStackItem* previous_item;
1166ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
116705ed9ddc6ff3a1ab3983c50d378cddfa257869b6jkummerow@chromium.org   private:
1168ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    DISALLOW_COPY_AND_ASSIGN(EntryStackItem);
1169ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  };
1170ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1171a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.org  static base::LazyMutex thread_data_table_mutex_;
11728c0a43f09f145d9fc6f969d559873018176eeb6adanno@chromium.org
11735de0074a922429f5e0ec2cf140c2d2989bf88140yangguo@chromium.org  static base::Thread::LocalStorageKey per_isolate_thread_data_key_;
11745de0074a922429f5e0ec2cf140c2d2989bf88140yangguo@chromium.org  static base::Thread::LocalStorageKey isolate_key_;
11755de0074a922429f5e0ec2cf140c2d2989bf88140yangguo@chromium.org  static base::Thread::LocalStorageKey thread_id_key_;
11768c0a43f09f145d9fc6f969d559873018176eeb6adanno@chromium.org  static ThreadDataTable* thread_data_table_;
11778c0a43f09f145d9fc6f969d559873018176eeb6adanno@chromium.org
1178750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org  // A global counter for all generated Isolates, might overflow.
11791e2d50cf3d94ff48285da107b7a9da1ad0fc873dmachenbach@chromium.org  static base::Atomic32 isolate_counter_;
1180750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org
1181ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  void Deinit();
1182ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1183ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  static void SetIsolateThreadLocals(Isolate* isolate,
1184ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org                                     PerIsolateThreadData* data);
1185ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1186ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // Find the PerThread for this particular (isolate, thread) combination.
1187ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // If one does not yet exist, allocate a new one.
1188ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  PerIsolateThreadData* FindOrAllocatePerThreadDataForThisThread();
1189ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1190ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // Initializes the current thread to run this Isolate.
1191ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // Not thread-safe. Multiple threads should not Enter/Exit the same isolate
1192ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // at the same time, this should be prevented using external locking.
1193ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  void Enter();
1194ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1195ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // Exits the current thread. The previosuly entered Isolate is restored
1196ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // for the thread.
1197ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // Not thread-safe. Multiple threads should not Enter/Exit the same isolate
1198ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // at the same time, this should be prevented using external locking.
1199ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  void Exit();
1200ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1201ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  void InitializeThreadLocal();
1202ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1203ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  void MarkCompactPrologue(bool is_compacting,
1204ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org                           ThreadLocalTop* archived_thread_data);
1205ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  void MarkCompactEpilogue(bool is_compacting,
1206ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org                           ThreadLocalTop* archived_thread_data);
1207ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1208ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  void FillCache();
1209ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1210fd703f3d69389b9129ab38adb1caeb2be7a21ecfmachenbach@chromium.org  // Propagate pending exception message to the v8::TryCatch.
1211fd703f3d69389b9129ab38adb1caeb2be7a21ecfmachenbach@chromium.org  // If there is no external try-catch or message was successfully propagated,
1212fd703f3d69389b9129ab38adb1caeb2be7a21ecfmachenbach@chromium.org  // then return true.
1213fd703f3d69389b9129ab38adb1caeb2be7a21ecfmachenbach@chromium.org  bool PropagatePendingExceptionToExternalTryCatch();
121444bc7080a85cc25bff3b9b77cd53f7beffab711bkarlklose@chromium.org
1215ab7dad4f999df008b590c74c2fe3d2e2c67ef7ffjkummerow@chromium.org  // Traverse prototype chain to find out whether the object is derived from
1216ab7dad4f999df008b590c74c2fe3d2e2c67ef7ffjkummerow@chromium.org  // the Error object.
1217ab7dad4f999df008b590c74c2fe3d2e2c67ef7ffjkummerow@chromium.org  bool IsErrorObject(Handle<Object> obj);
1218ab7dad4f999df008b590c74c2fe3d2e2c67ef7ffjkummerow@chromium.org
12191e2d50cf3d94ff48285da107b7a9da1ad0fc873dmachenbach@chromium.org  base::Atomic32 id_;
1220efdb9d70bddd496ceb6a281dadcc065efbce37a1yangguo@chromium.org  EntryStackItem* entry_stack_;
1221ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  int stack_trace_nesting_level_;
1222ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  StringStream* incomplete_message_;
122383e168294456ca2f02db421a635f7d5f5d023966kmillikin@chromium.org  Address isolate_addresses_[kIsolateAddressCount + 1];  // NOLINT
1224ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  Bootstrapper* bootstrapper_;
1225ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  RuntimeProfiler* runtime_profiler_;
1226ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  CompilationCache* compilation_cache_;
1227ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  Counters* counters_;
1228ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  CodeRange* code_range_;
12295de0074a922429f5e0ec2cf140c2d2989bf88140yangguo@chromium.org  base::RecursiveMutex break_access_;
12301e2d50cf3d94ff48285da107b7a9da1ad0fc873dmachenbach@chromium.org  base::Atomic32 debugger_initialized_;
1231ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  Logger* logger_;
1232ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  StackGuard stack_guard_;
1233ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  StatsTable* stats_table_;
1234ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  StubCache* stub_cache_;
12355924917d324a643d00a8aefee030bd4acea0de0bmachenbach@chromium.org  CodeAgingHelper* code_aging_helper_;
1236ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  DeoptimizerData* deoptimizer_data_;
123757a54ace4b6b45d5d6a7ff38d88ee9990d47f5e2machenbach@chromium.org  MaterializedObjectStore* materialized_object_store_;
1238ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  ThreadLocalTop thread_local_top_;
1239ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  bool capture_stack_trace_for_uncaught_exceptions_;
1240ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  int stack_trace_for_uncaught_exceptions_frame_limit_;
1241ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  StackTrace::StackTraceOptions stack_trace_for_uncaught_exceptions_options_;
1242ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  MemoryAllocator* memory_allocator_;
1243ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  KeyedLookupCache* keyed_lookup_cache_;
1244ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  ContextSlotCache* context_slot_cache_;
1245ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  DescriptorLookupCache* descriptor_lookup_cache_;
124626ca35cc4ec47151d9c6d3890b0f052fc79cb8afmachenbach@chromium.org  HandleScopeData handle_scope_data_;
1247ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  HandleScopeImplementer* handle_scope_implementer_;
1248a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org  UnicodeCache* unicode_cache_;
1249c1789eecd43bf9c5497636592bf14fa754d04c89machenbach@chromium.org  Zone runtime_zone_;
1250c3b670ff19220959730d7886892bc4beb95d2ebaerik.corry@gmail.com  InnerPointerToCodeCache* inner_pointer_to_code_cache_;
12514cd70b470729dd5850dd4120a350f01363d16837yangguo@chromium.org  ConsStringIteratorOp* write_iterator_;
1252ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  GlobalHandles* global_handles_;
1253594006017e46d82ed7146611dc12c20e3c509c7ddanno@chromium.org  EternalHandles* eternal_handles_;
1254ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  ThreadManager* thread_manager_;
1255ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  RuntimeState runtime_state_;
1256ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  Builtins builtins_;
125727bf28851c1fa362a3f7c709871c21dcc9c23ce7ricow@chromium.org  bool has_installed_extensions_;
1258ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  StringTracker* string_tracker_;
1259ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  unibrow::Mapping<unibrow::Ecma262UnCanonicalize> jsregexp_uncanonicalize_;
1260ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  unibrow::Mapping<unibrow::CanonicalizationRange> jsregexp_canonrange_;
12614cd70b470729dd5850dd4120a350f01363d16837yangguo@chromium.org  ConsStringIteratorOp objects_string_compare_iterator_a_;
12624cd70b470729dd5850dd4120a350f01363d16837yangguo@chromium.org  ConsStringIteratorOp objects_string_compare_iterator_b_;
12634cd70b470729dd5850dd4120a350f01363d16837yangguo@chromium.org  StaticResource<ConsStringIteratorOp> objects_string_iterator_;
1264ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  unibrow::Mapping<unibrow::Ecma262Canonicalize>
1265ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org      regexp_macro_assembler_canonicalize_;
1266ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  RegExpStack* regexp_stack_;
12674efbdb18fa3063085682c44cc77cf5254cb3d75dsvenpanne@chromium.org  DateCache* date_cache_;
1268ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  unibrow::Mapping<unibrow::Ecma262Canonicalize> interp_canonicalize_mapping_;
12699aaa825cf89e1bcfece269a453300ebf4a26d64dmachenbach@chromium.org  CallInterfaceDescriptorData* call_descriptor_data_;
12705de0074a922429f5e0ec2cf140c2d2989bf88140yangguo@chromium.org  base::RandomNumberGenerator* random_number_generator_;
1271ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1272fb547e07aef43e02715c5d6c1530e84bb3cbba02machenbach@chromium.org  // Whether the isolate has been created for snapshotting.
1273fb547e07aef43e02715c5d6c1530e84bb3cbba02machenbach@chromium.org  bool serializer_enabled_;
1274fb547e07aef43e02715c5d6c1530e84bb3cbba02machenbach@chromium.org
1275e900018c7a2a695fde788911564da37535c7e736mstarzinger@chromium.org  // True if fatal error has been signaled for this isolate.
1276e900018c7a2a695fde788911564da37535c7e736mstarzinger@chromium.org  bool has_fatal_error_;
1277e900018c7a2a695fde788911564da37535c7e736mstarzinger@chromium.org
12781510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org  // True if this isolate was initialized from a snapshot.
12791510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org  bool initialized_from_snapshot_;
12801510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org
1281994edf6a113fb3651536b60073df05a72a95f77erossberg@chromium.org  // Time stamp at initialization.
1282994edf6a113fb3651536b60073df05a72a95f77erossberg@chromium.org  double time_millis_at_init_;
1283994edf6a113fb3651536b60073df05a72a95f77erossberg@chromium.org
1284ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org#ifdef DEBUG
1285ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // A static array of histogram info for each type.
1286ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  HistogramInfo heap_histograms_[LAST_TYPE + 1];
1287ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  JSObject::SpillInformation js_spill_information_;
1288ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org#endif
1289ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1290ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  Debug* debug_;
1291f705b5034dc5bc422ac1019b591469a7d0534772mstarzinger@chromium.org  CpuProfiler* cpu_profiler_;
1292f705b5034dc5bc422ac1019b591469a7d0534772mstarzinger@chromium.org  HeapProfiler* heap_profiler_;
12931510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org  FunctionEntryHook function_entry_hook_;
1294ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1295ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org#define GLOBAL_BACKING_STORE(type, name, initialvalue)                         \
1296ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  type name##_;
1297ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  ISOLATE_INIT_LIST(GLOBAL_BACKING_STORE)
1298ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org#undef GLOBAL_BACKING_STORE
1299ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1300ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org#define GLOBAL_ARRAY_BACKING_STORE(type, name, length)                         \
1301ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  type name##_[length];
1302ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  ISOLATE_INIT_ARRAY_LIST(GLOBAL_ARRAY_BACKING_STORE)
1303ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org#undef GLOBAL_ARRAY_BACKING_STORE
1304ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1305ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org#ifdef DEBUG
1306ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // This class is huge and has a number of fields controlled by
1307ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // preprocessor defines. Make sure the offsets of these fields agree
1308ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // between compilation units.
1309ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org#define ISOLATE_FIELD_OFFSET(type, name, ignored)                              \
1310ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  static const intptr_t name##_debug_offset_;
1311ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET)
1312ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET)
1313ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org#undef ISOLATE_FIELD_OFFSET
1314ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org#endif
1315ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1316304cc33f8259ef467e8e3c79f448d0bae0e8cd85yangguo@chromium.org  DeferredHandles* deferred_handles_head_;
13178e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.org  OptimizingCompilerThread* optimizing_compiler_thread_;
1318e3b8d0fe80e858c990832db1233c069f8b8cd5c9mstarzinger@chromium.org  SweeperThread** sweeper_thread_;
13199af454f6b1c6a921ac79ba0b9a979c73adb2ca1emachenbach@chromium.org  int num_sweeper_threads_;
13209af454f6b1c6a921ac79ba0b9a979c73adb2ca1emachenbach@chromium.org
1321ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  // Counts deopt points if deopt_every_n_times is enabled.
1322ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  unsigned int stress_deopt_count_;
1323ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
1324f5a24546072ecdbbd6372c85c42157e01e913561titzer@chromium.org  int next_optimization_id_;
1325f5a24546072ecdbbd6372c85c42157e01e913561titzer@chromium.org
1326865f51ff8c94f86f4c97636d70addc0f29e79674machenbach@chromium.org  // List of callbacks when a Call completes.
1327865f51ff8c94f86f4c97636d70addc0f29e79674machenbach@chromium.org  List<CallCompletedCallback> call_completed_callbacks_;
1328865f51ff8c94f86f4c97636d70addc0f29e79674machenbach@chromium.org
1329975b940441085887fc02bebf8877d5ec97e1e06cmachenbach@chromium.org  v8::Isolate::UseCounterCallback use_counter_callback_;
1330975b940441085887fc02bebf8877d5ec97e1e06cmachenbach@chromium.org
1331ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  friend class ExecutionAccess;
1332304cc33f8259ef467e8e3c79f448d0bae0e8cd85yangguo@chromium.org  friend class HandleScopeImplementer;
1333ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  friend class IsolateInitializer;
1334304cc33f8259ef467e8e3c79f448d0bae0e8cd85yangguo@chromium.org  friend class OptimizingCompilerThread;
1335e3b8d0fe80e858c990832db1233c069f8b8cd5c9mstarzinger@chromium.org  friend class SweeperThread;
13361c09276ce2ac5214e81ca554360b9f101187893blrn@chromium.org  friend class ThreadManager;
13371c09276ce2ac5214e81ca554360b9f101187893blrn@chromium.org  friend class Simulator;
13381c09276ce2ac5214e81ca554360b9f101187893blrn@chromium.org  friend class StackGuard;
1339a9aa5fa8ae2a2b43a94e6462ded2cd51445e9ee3ager@chromium.org  friend class ThreadId;
13407c2628c3f0353f0558760c3ca442f934263ea766kmillikin@chromium.org  friend class TestMemoryAllocatorScope;
1341068ea0a6ea115c058d1d9798029bd7fa1eaaa955mstarzinger@chromium.org  friend class TestCodeRangeScope;
1342ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  friend class v8::Isolate;
1343ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  friend class v8::Locker;
13441c09276ce2ac5214e81ca554360b9f101187893blrn@chromium.org  friend class v8::Unlocker;
1345ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1346ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  DISALLOW_COPY_AND_ASSIGN(Isolate);
1347ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org};
1348ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1349ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1350f5a24546072ecdbbd6372c85c42157e01e913561titzer@chromium.org#undef FIELD_ACCESSOR
1351f5a24546072ecdbbd6372c85c42157e01e913561titzer@chromium.org#undef THREAD_LOCAL_TOP_ACCESSOR
1352f5a24546072ecdbbd6372c85c42157e01e913561titzer@chromium.org
1353f5a24546072ecdbbd6372c85c42157e01e913561titzer@chromium.org
13545e57059e20217fd540b60c237d326414afe2171emachenbach@chromium.orgclass PromiseOnStack {
13555e57059e20217fd540b60c237d326414afe2171emachenbach@chromium.org public:
13565e57059e20217fd540b60c237d326414afe2171emachenbach@chromium.org  PromiseOnStack(StackHandler* handler, Handle<JSObject> promise,
13575e57059e20217fd540b60c237d326414afe2171emachenbach@chromium.org                 PromiseOnStack* prev)
13585e57059e20217fd540b60c237d326414afe2171emachenbach@chromium.org      : handler_(handler), promise_(promise), prev_(prev) {}
13595e57059e20217fd540b60c237d326414afe2171emachenbach@chromium.org  StackHandler* handler() { return handler_; }
13605e57059e20217fd540b60c237d326414afe2171emachenbach@chromium.org  Handle<JSObject> promise() { return promise_; }
13615e57059e20217fd540b60c237d326414afe2171emachenbach@chromium.org  PromiseOnStack* prev() { return prev_; }
13625e57059e20217fd540b60c237d326414afe2171emachenbach@chromium.org
13635e57059e20217fd540b60c237d326414afe2171emachenbach@chromium.org private:
13645e57059e20217fd540b60c237d326414afe2171emachenbach@chromium.org  StackHandler* handler_;
13655e57059e20217fd540b60c237d326414afe2171emachenbach@chromium.org  Handle<JSObject> promise_;
13665e57059e20217fd540b60c237d326414afe2171emachenbach@chromium.org  PromiseOnStack* prev_;
13675e57059e20217fd540b60c237d326414afe2171emachenbach@chromium.org};
13685e57059e20217fd540b60c237d326414afe2171emachenbach@chromium.org
13695e57059e20217fd540b60c237d326414afe2171emachenbach@chromium.org
1370ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org// If the GCC version is 4.1.x or 4.2.x an additional field is added to the
1371ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org// class as a work around for a bug in the generated code found with these
1372ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org// versions of GCC. See V8 issue 122 for details.
1373ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgclass SaveContext BASE_EMBEDDED {
1374ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org public:
1375c3b670ff19220959730d7886892bc4beb95d2ebaerik.corry@gmail.com  inline explicit SaveContext(Isolate* isolate);
1376ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1377ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  ~SaveContext() {
13783d00d0a753cf5e5091f883517e6612ece769f999jkummerow@chromium.org    isolate_->set_context(context_.is_null() ? NULL : *context_);
13793d00d0a753cf5e5091f883517e6612ece769f999jkummerow@chromium.org    isolate_->set_save_context(prev_);
1380ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
1381ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1382ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  Handle<Context> context() { return context_; }
1383ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  SaveContext* prev() { return prev_; }
1384ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1385ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // Returns true if this save context is below a given JavaScript frame.
1386c3b37129d6387b2db313f9100256d2d5f60dd9a8jkummerow@chromium.org  bool IsBelowFrame(JavaScriptFrame* frame) {
1387c3b37129d6387b2db313f9100256d2d5f60dd9a8jkummerow@chromium.org    return (c_entry_fp_ == 0) || (c_entry_fp_ > frame->sp());
1388ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
1389ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1390ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org private:
13913d00d0a753cf5e5091f883517e6612ece769f999jkummerow@chromium.org  Isolate* isolate_;
1392ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  Handle<Context> context_;
1393ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  SaveContext* prev_;
1394c3b37129d6387b2db313f9100256d2d5f60dd9a8jkummerow@chromium.org  Address c_entry_fp_;
1395ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org};
1396ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1397ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1398ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgclass AssertNoContextChange BASE_EMBEDDED {
1399ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org#ifdef DEBUG
1400ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org public:
1401fb7a7c4ffde9a4d060f5f989371e2ce964ee5831jkummerow@chromium.org  explicit AssertNoContextChange(Isolate* isolate)
1402fb7a7c4ffde9a4d060f5f989371e2ce964ee5831jkummerow@chromium.org    : isolate_(isolate),
1403fb7a7c4ffde9a4d060f5f989371e2ce964ee5831jkummerow@chromium.org      context_(isolate->context(), isolate) { }
1404dc94e19484d1700cb0ec22365444223e49a3ac1ejkummerow@chromium.org  ~AssertNoContextChange() {
1405e3c177a423baa3c30225c4e422b6f6c76d38b951machenbach@chromium.org    DCHECK(isolate_->context() == *context_);
1406dc94e19484d1700cb0ec22365444223e49a3ac1ejkummerow@chromium.org  }
1407dc94e19484d1700cb0ec22365444223e49a3ac1ejkummerow@chromium.org
1408dc94e19484d1700cb0ec22365444223e49a3ac1ejkummerow@chromium.org private:
1409e97852de34e44a479f092bd2449134e707cd9cf1dslomov@chromium.org  Isolate* isolate_;
1410dc94e19484d1700cb0ec22365444223e49a3ac1ejkummerow@chromium.org  Handle<Context> context_;
1411dc94e19484d1700cb0ec22365444223e49a3ac1ejkummerow@chromium.org#else
1412dc94e19484d1700cb0ec22365444223e49a3ac1ejkummerow@chromium.org public:
1413fb7a7c4ffde9a4d060f5f989371e2ce964ee5831jkummerow@chromium.org  explicit AssertNoContextChange(Isolate* isolate) { }
1414ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org#endif
1415ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org};
1416ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1417ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1418ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgclass ExecutionAccess BASE_EMBEDDED {
1419ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org public:
1420ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  explicit ExecutionAccess(Isolate* isolate) : isolate_(isolate) {
1421ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    Lock(isolate);
1422ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
1423ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  ~ExecutionAccess() { Unlock(isolate_); }
1424ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1425dc94e19484d1700cb0ec22365444223e49a3ac1ejkummerow@chromium.org  static void Lock(Isolate* isolate) { isolate->break_access()->Lock(); }
1426dc94e19484d1700cb0ec22365444223e49a3ac1ejkummerow@chromium.org  static void Unlock(Isolate* isolate) { isolate->break_access()->Unlock(); }
1427ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1428ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  static bool TryLock(Isolate* isolate) {
1429dc94e19484d1700cb0ec22365444223e49a3ac1ejkummerow@chromium.org    return isolate->break_access()->TryLock();
1430ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
1431ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1432ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org private:
1433ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  Isolate* isolate_;
1434ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org};
1435ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1436ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
14373ee7a7ed19002e4a0efbf6cdb2a201f21763a80adanno@chromium.org// Support for checking for stack-overflows.
1438ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgclass StackLimitCheck BASE_EMBEDDED {
1439ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org public:
1440ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  explicit StackLimitCheck(Isolate* isolate) : isolate_(isolate) { }
1441ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
14423ee7a7ed19002e4a0efbf6cdb2a201f21763a80adanno@chromium.org  // Use this to check for stack-overflows in C++ code.
14433ee7a7ed19002e4a0efbf6cdb2a201f21763a80adanno@chromium.org  inline bool HasOverflowed() const {
1444ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    StackGuard* stack_guard = isolate_->stack_guard();
1445d0bddc653152f270a27fe32d5d7b0f5c0fa3b00cmachenbach@chromium.org    return GetCurrentStackPosition() < stack_guard->real_climit();
1446ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
14473ee7a7ed19002e4a0efbf6cdb2a201f21763a80adanno@chromium.org
14483ee7a7ed19002e4a0efbf6cdb2a201f21763a80adanno@chromium.org  // Use this to check for stack-overflow when entering runtime from JS code.
14493ee7a7ed19002e4a0efbf6cdb2a201f21763a80adanno@chromium.org  bool JsHasOverflowed() const;
14503ee7a7ed19002e4a0efbf6cdb2a201f21763a80adanno@chromium.org
1451ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org private:
1452ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  Isolate* isolate_;
1453ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org};
1454ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1455ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1456ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org// Support for temporarily postponing interrupts. When the outermost
1457ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org// postpone scope is left the interrupts will be re-enabled and any
1458ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org// interrupts that occurred while in the scope will be taken into
1459ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org// account.
1460ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgclass PostponeInterruptsScope BASE_EMBEDDED {
1461ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org public:
1462d0bddc653152f270a27fe32d5d7b0f5c0fa3b00cmachenbach@chromium.org  PostponeInterruptsScope(Isolate* isolate,
1463d0bddc653152f270a27fe32d5d7b0f5c0fa3b00cmachenbach@chromium.org                          int intercept_mask = StackGuard::ALL_INTERRUPTS)
1464d0bddc653152f270a27fe32d5d7b0f5c0fa3b00cmachenbach@chromium.org      : stack_guard_(isolate->stack_guard()),
1465d0bddc653152f270a27fe32d5d7b0f5c0fa3b00cmachenbach@chromium.org        intercept_mask_(intercept_mask),
1466d0bddc653152f270a27fe32d5d7b0f5c0fa3b00cmachenbach@chromium.org        intercepted_flags_(0) {
1467d0bddc653152f270a27fe32d5d7b0f5c0fa3b00cmachenbach@chromium.org    stack_guard_->PushPostponeInterruptsScope(this);
1468ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
1469ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1470ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  ~PostponeInterruptsScope() {
1471d0bddc653152f270a27fe32d5d7b0f5c0fa3b00cmachenbach@chromium.org    stack_guard_->PopPostponeInterruptsScope();
1472ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  }
1473d0bddc653152f270a27fe32d5d7b0f5c0fa3b00cmachenbach@chromium.org
1474d0bddc653152f270a27fe32d5d7b0f5c0fa3b00cmachenbach@chromium.org  // Find the bottom-most scope that intercepts this interrupt.
1475d0bddc653152f270a27fe32d5d7b0f5c0fa3b00cmachenbach@chromium.org  // Return whether the interrupt has been intercepted.
1476d0bddc653152f270a27fe32d5d7b0f5c0fa3b00cmachenbach@chromium.org  bool Intercept(StackGuard::InterruptFlag flag);
1477d0bddc653152f270a27fe32d5d7b0f5c0fa3b00cmachenbach@chromium.org
1478ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org private:
1479ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  StackGuard* stack_guard_;
1480d0bddc653152f270a27fe32d5d7b0f5c0fa3b00cmachenbach@chromium.org  int intercept_mask_;
1481d0bddc653152f270a27fe32d5d7b0f5c0fa3b00cmachenbach@chromium.org  int intercepted_flags_;
1482d0bddc653152f270a27fe32d5d7b0f5c0fa3b00cmachenbach@chromium.org  PostponeInterruptsScope* prev_;
1483d0bddc653152f270a27fe32d5d7b0f5c0fa3b00cmachenbach@chromium.org
1484d0bddc653152f270a27fe32d5d7b0f5c0fa3b00cmachenbach@chromium.org  friend class StackGuard;
1485ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org};
1486ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1487ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1488ada3a6017e603965f87fa34f6e2fa60379e8d697machenbach@chromium.orgclass CodeTracer FINAL : public Malloced {
1489e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org public:
1490e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org  explicit CodeTracer(int isolate_id)
1491e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org      : file_(NULL),
1492e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org        scope_depth_(0) {
1493e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org    if (!ShouldRedirect()) {
1494e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org      file_ = stdout;
1495e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org      return;
1496e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org    }
1497e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org
1498e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org    if (FLAG_redirect_code_traces_to == NULL) {
149970ec1a2160dd946b9578d04d97d631a6d4ab4f8cbmeurer@chromium.org      SNPrintF(filename_,
150070ec1a2160dd946b9578d04d97d631a6d4ab4f8cbmeurer@chromium.org               "code-%d-%d.asm",
15015de0074a922429f5e0ec2cf140c2d2989bf88140yangguo@chromium.org               base::OS::GetCurrentProcessId(),
150270ec1a2160dd946b9578d04d97d631a6d4ab4f8cbmeurer@chromium.org               isolate_id);
1503e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org    } else {
150470ec1a2160dd946b9578d04d97d631a6d4ab4f8cbmeurer@chromium.org      StrNCpy(filename_, FLAG_redirect_code_traces_to, filename_.length());
1505e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org    }
1506e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org
1507e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org    WriteChars(filename_.start(), "", 0, false);
1508e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org  }
1509e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org
1510e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org  class Scope {
1511e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org   public:
1512e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org    explicit Scope(CodeTracer* tracer) : tracer_(tracer) { tracer->OpenFile(); }
1513e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org    ~Scope() { tracer_->CloseFile();  }
1514e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org
1515e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org    FILE* file() const { return tracer_->file(); }
1516e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org
1517e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org   private:
1518e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org    CodeTracer* tracer_;
1519e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org  };
1520e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org
1521e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org  void OpenFile() {
1522e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org    if (!ShouldRedirect()) {
1523e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org      return;
1524e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org    }
1525e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org
1526e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org    if (file_ == NULL) {
15275de0074a922429f5e0ec2cf140c2d2989bf88140yangguo@chromium.org      file_ = base::OS::FOpen(filename_.start(), "a");
1528e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org    }
1529e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org
1530e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org    scope_depth_++;
1531e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org  }
1532e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org
1533e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org  void CloseFile() {
1534e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org    if (!ShouldRedirect()) {
1535e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org      return;
1536e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org    }
1537e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org
1538e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org    if (--scope_depth_ == 0) {
1539e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org      fclose(file_);
1540e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org      file_ = NULL;
1541e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org    }
1542e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org  }
1543e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org
1544e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org  FILE* file() const { return file_; }
1545e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org
1546e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org private:
1547e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org  static bool ShouldRedirect() {
1548e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org    return FLAG_redirect_code_traces;
1549e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org  }
1550e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org
1551e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org  EmbeddedVector<char, 128> filename_;
1552e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org  FILE* file_;
1553e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org  int scope_depth_;
1554e8412be858dc48afaec4959e42c5932f71a7f29bmachenbach@chromium.org};
1555ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1556ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org} }  // namespace v8::internal
1557ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1558ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org#endif  // V8_ISOLATE_H_
1559