V8 Project
execution.h
Go to the documentation of this file.
1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_EXECUTION_H_
6 #define V8_EXECUTION_H_
7 
8 #include "src/handles.h"
9 
10 namespace v8 {
11 namespace internal {
12 
13 class Execution FINAL : public AllStatic {
14  public:
15  // Call a function, the caller supplies a receiver and an array
16  // of arguments. Arguments are Object* type. After function returns,
17  // pointers in 'args' might be invalid.
18  //
19  // *pending_exception tells whether the invoke resulted in
20  // a pending exception.
21  //
22  // When convert_receiver is set, and the receiver is not an object,
23  // and the function called is not in strict mode, receiver is converted to
24  // an object.
25  //
27  Isolate* isolate,
28  Handle<Object> callable,
29  Handle<Object> receiver,
30  int argc,
31  Handle<Object> argv[],
32  bool convert_receiver = false);
33 
34  // Construct object from function, the caller supplies an array of
35  // arguments. Arguments are Object* type. After function returns,
36  // pointers in 'args' might be invalid.
37  //
38  // *pending_exception tells whether the invoke resulted in
39  // a pending exception.
40  //
42  int argc,
43  Handle<Object> argv[]);
44 
45  // Call a function, just like Call(), but make sure to silently catch
46  // any thrown exceptions. The return value is either the result of
47  // calling the function (if caught exception is false) or the exception
48  // that occurred (if caught exception is true).
49  // In the exception case, exception_out holds the caught exceptions, unless
50  // it is a termination exception.
52  Handle<Object> receiver, int argc,
53  Handle<Object> argv[],
54  MaybeHandle<Object>* exception_out = NULL);
55 
56  // ECMA-262 9.3
58  Isolate* isolate, Handle<Object> obj);
59 
60  // ECMA-262 9.4
62  Isolate* isolate, Handle<Object> obj);
63 
64  // ECMA-262 9.5
66  Isolate* isolate, Handle<Object> obj);
67 
68  // ECMA-262 9.6
70  Isolate* isolate, Handle<Object> obj);
71 
72  // ECMA-262 9.8
74  Isolate* isolate, Handle<Object> obj);
75 
76  // ECMA-262 9.8
78  Isolate* isolate, Handle<Object> obj);
79 
80  // ECMA-262 9.9
82  Isolate* isolate, Handle<Object> obj);
83 
84  // Create a new date object from 'time'.
86  Isolate* isolate, double time);
87 
88  // Create a new regular expression object from 'pattern' and 'flags'.
91 
92  // Used to implement [] notation on strings (calls JS code)
94 
101  Isolate* isolate, Handle<Object> instance, Handle<Object> data);
103  Handle<JSFunction> fun,
104  Handle<Object> pos,
105  Handle<Object> is_global);
106 
107  // Get a function delegate (or undefined) for the given non-function
108  // object. Used for support calling objects as functions.
110  Handle<Object> object);
112  Isolate* isolate,
113  Handle<Object> object);
114 
115  // Get a function delegate (or undefined) for the given non-function
116  // object. Used for support calling objects as constructors.
118  Handle<Object> object);
120  Handle<Object> object);
121 };
122 
123 
124 class ExecutionAccess;
125 class PostponeInterruptsScope;
126 
127 
128 // StackGuard contains the handling of the limits that are used to limit the
129 // number of nested invocations of JavaScript and the stack size used in each
130 // invocation.
131 class StackGuard FINAL {
132  public:
133  // Pass the address beyond which the stack should not grow. The stack
134  // is assumed to grow downwards.
136 
137  // Threading support.
138  char* ArchiveStackGuard(char* to);
139  char* RestoreStackGuard(char* from);
140  static int ArchiveSpacePerThread() { return sizeof(ThreadLocal); }
142  // Sets up the default stack guard for this thread if it has not
143  // already been set up.
144  void InitThread(const ExecutionAccess& lock);
145  // Clears the stack guard for this thread so it does not look as if
146  // it has been set up.
147  void ClearThread(const ExecutionAccess& lock);
148 
149 #define INTERRUPT_LIST(V) \
150  V(DEBUGBREAK, DebugBreak, 0) \
151  V(DEBUGCOMMAND, DebugCommand, 1) \
152  V(TERMINATE_EXECUTION, TerminateExecution, 2) \
153  V(GC_REQUEST, GC, 3) \
154  V(INSTALL_CODE, InstallCode, 4) \
155  V(API_INTERRUPT, ApiInterrupt, 5) \
156  V(DEOPT_MARKED_ALLOCATION_SITES, DeoptMarkedAllocationSites, 6)
157 
158 #define V(NAME, Name, id) \
159  inline bool Check##Name() { return CheckInterrupt(NAME); } \
160  inline void Request##Name() { RequestInterrupt(NAME); } \
161  inline void Clear##Name() { ClearInterrupt(NAME); }
163 #undef V
164 
165  // Flag used to set the interrupt causes.
167  #define V(NAME, Name, id) NAME = (1 << id),
169  #undef V
170  #define V(NAME, Name, id) NAME |
171  ALL_INTERRUPTS = INTERRUPT_LIST(V) 0
172  #undef V
173  };
174 
175  // This provides an asynchronous read of the stack limits for the current
176  // thread. There are no locks protecting this, but it is assumed that you
177  // have the global V8 lock if you are using multiple V8 threads.
179  return thread_local_.climit_;
180  }
182  return thread_local_.real_climit_;
183  }
185  return thread_local_.jslimit_;
186  }
188  return thread_local_.real_jslimit_;
189  }
191  return reinterpret_cast<Address>(&thread_local_.jslimit_);
192  }
194  return reinterpret_cast<Address>(&thread_local_.real_jslimit_);
195  }
196 
197  // If the stack guard is triggered, but it is not an actual
198  // stack overflow, then handle the interruption accordingly.
200 
201  private:
203 
208 
209  // You should hold the ExecutionAccess lock when calling this method.
210  bool has_pending_interrupts(const ExecutionAccess& lock) {
211  return thread_local_.interrupt_flags_ != 0;
212  }
213 
214  // You should hold the ExecutionAccess lock when calling this method.
215  inline void set_interrupt_limits(const ExecutionAccess& lock);
216 
217  // Reset limits to actual values. For example after handling interrupt.
218  // You should hold the ExecutionAccess lock when calling this method.
219  inline void reset_limits(const ExecutionAccess& lock);
220 
221  // Enable or disable interrupts.
224 
225 #if V8_TARGET_ARCH_64_BIT
226  static const uintptr_t kInterruptLimit = V8_UINT64_C(0xfffffffffffffffe);
227  static const uintptr_t kIllegalLimit = V8_UINT64_C(0xfffffffffffffff8);
228 #else
229  static const uintptr_t kInterruptLimit = 0xfffffffe;
230  static const uintptr_t kIllegalLimit = 0xfffffff8;
231 #endif
232 
233  void PushPostponeInterruptsScope(PostponeInterruptsScope* scope);
235 
236  class ThreadLocal FINAL {
237  public:
238  ThreadLocal() { Clear(); }
239  // You should hold the ExecutionAccess lock when you call Initialize or
240  // Clear.
241  void Clear();
242 
243  // Returns true if the heap's stack limits should be set, false if not.
244  bool Initialize(Isolate* isolate);
245 
246  // The stack limit is split into a JavaScript and a C++ stack limit. These
247  // two are the same except when running on a simulator where the C++ and
248  // JavaScript stacks are separate. Each of the two stack limits have two
249  // values. The one eith the real_ prefix is the actual stack limit
250  // set for the VM. The one without the real_ prefix has the same value as
251  // the actual stack limit except when there is an interruption (e.g. debug
252  // break or preemption) in which case it is lowered to make stack checks
253  // fail. Both the generated code and the runtime system check against the
254  // one without the real_ prefix.
255  uintptr_t real_jslimit_; // Actual JavaScript stack limit set for the VM.
257  uintptr_t real_climit_; // Actual C++ stack limit set for the VM.
259 
260  PostponeInterruptsScope* postpone_interrupts_;
262  };
263 
264  // TODO(isolates): Technically this could be calculated directly from a
265  // pointer to StackGuard.
266  Isolate* isolate_;
267  ThreadLocal thread_local_;
268 
269  friend class Isolate;
270  friend class StackLimitCheck;
271  friend class PostponeInterruptsScope;
272 
274 };
275 
276 } } // namespace v8::internal
277 
278 #endif // V8_EXECUTION_H_
PostponeInterruptsScope * postpone_interrupts_
Definition: execution.h:260
bool Initialize(Isolate *isolate)
Source to read snapshot and builtins files from.
Definition: lithium-arm.h:372
Address address_of_jslimit()
Definition: execution.h:190
static MUST_USE_RESULT MaybeHandle< Object > ToInt32(Isolate *isolate, Handle< Object > obj)
char * ArchiveStackGuard(char *to)
void RequestInterrupt(InterruptFlag flag)
static MUST_USE_RESULT MaybeHandle< Object > ToInteger(Isolate *isolate, Handle< Object > obj)
static Handle< Object > GetFunctionDelegate(Isolate *isolate, Handle< Object > object)
static Handle< Object > GetFunctionFor()
static MUST_USE_RESULT MaybeHandle< JSRegExp > NewJSRegExp(Handle< String > pattern, Handle< String > flags)
uintptr_t jslimit()
Definition: execution.h:184
static MUST_USE_RESULT MaybeHandle< JSObject > InstantiateObject(Handle< ObjectTemplateInfo > data)
static MaybeHandle< Object > TryGetConstructorDelegate(Isolate *isolate, Handle< Object > object)
static MUST_USE_RESULT MaybeHandle< Object > ToString(Isolate *isolate, Handle< Object > obj)
void set_interrupt_limits(const ExecutionAccess &lock)
static Handle< Object > CharAt(Handle< String > str, uint32_t index)
bool CheckInterrupt(InterruptFlag flag)
static MUST_USE_RESULT MaybeHandle< Object > ToObject(Isolate *isolate, Handle< Object > obj)
static MUST_USE_RESULT MaybeHandle< Object > Call(Isolate *isolate, Handle< Object > callable, Handle< Object > receiver, int argc, Handle< Object > argv[], bool convert_receiver=false)
uintptr_t real_climit()
Definition: execution.h:181
void PushPostponeInterruptsScope(PostponeInterruptsScope *scope)
static MUST_USE_RESULT MaybeHandle< JSFunction > InstantiateFunction(Handle< FunctionTemplateInfo > data)
Address address_of_real_jslimit()
Definition: execution.h:193
uintptr_t real_jslimit()
Definition: execution.h:187
void reset_limits(const ExecutionAccess &lock)
bool has_pending_interrupts(const ExecutionAccess &lock)
Definition: execution.h:210
void ClearThread(const ExecutionAccess &lock)
void ClearInterrupt(InterruptFlag flag)
bool CheckAndClearInterrupt(InterruptFlag flag)
static Handle< Object > GetConstructorDelegate(Isolate *isolate, Handle< Object > object)
static MUST_USE_RESULT MaybeHandle< Object > ToNumber(Isolate *isolate, Handle< Object > obj)
void SetStackLimit(uintptr_t limit)
static Handle< String > GetStackTraceLine(Handle< Object > recv, Handle< JSFunction > fun, Handle< Object > pos, Handle< Object > is_global)
static MUST_USE_RESULT MaybeHandle< Object > ConfigureInstance(Isolate *isolate, Handle< Object > instance, Handle< Object > data)
static MUST_USE_RESULT MaybeHandle< Object > ToUint32(Isolate *isolate, Handle< Object > obj)
DISALLOW_COPY_AND_ASSIGN(StackGuard)
void PopPostponeInterruptsScope()
Object * HandleInterrupts()
char * RestoreStackGuard(char *from)
static MaybeHandle< Object > TryCall(Handle< JSFunction > func, Handle< Object > receiver, int argc, Handle< Object > argv[], MaybeHandle< Object > *exception_out=NULL)
static MUST_USE_RESULT MaybeHandle< Object > NewDate(Isolate *isolate, double time)
static int ArchiveSpacePerThread()
Definition: execution.h:140
void InitThread(const ExecutionAccess &lock)
ThreadLocal thread_local_
Definition: execution.h:267
uintptr_t climit()
Definition: execution.h:178
static MUST_USE_RESULT MaybeHandle< Object > New(Handle< JSFunction > func, int argc, Handle< Object > argv[])
static MUST_USE_RESULT MaybeHandle< Object > ToDetailString(Isolate *isolate, Handle< Object > obj)
static MUST_USE_RESULT MaybeHandle< Object > TryGetFunctionDelegate(Isolate *isolate, Handle< Object > object)
#define FINAL
#define INTERRUPT_LIST(V)
Definition: execution.h:149
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in only print modified registers Trace simulator debug messages Implied by trace sim abort randomize hashes to avoid predictable hash Fixed seed to use to hash property Print the time it takes to deserialize the snapshot A filename with extra code to be included in the A file to write the raw snapshot bytes to(mksnapshot only)") DEFINE_STRING(raw_context_file
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL
#define V8_UINT64_C(x)
Definition: macros.h:357
#define MUST_USE_RESULT
Definition: macros.h:266
byte * Address
Definition: globals.h:101
kFeedbackVectorOffset flag
Definition: objects-inl.h:5418
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20