説明を見る。00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef V8_EXECUTION_H_
00029 #define V8_EXECUTION_H_
00030
00031 namespace v8 { namespace internal {
00032
00033
00034
00035 enum InterruptFlag {
00036 INTERRUPT = 1 << 0,
00037 DEBUGBREAK = 1 << 1,
00038 PREEMPT = 1 << 2
00039 };
00040
00041 class Execution : public AllStatic {
00042 public:
00043
00044
00045
00046
00047
00048
00049
00050 static Handle<Object> Call(Handle<JSFunction> func,
00051 Handle<Object> receiver,
00052 int argc,
00053 Object*** args,
00054 bool* pending_exception);
00055
00056
00057
00058
00059
00060
00061
00062
00063 static Handle<Object> New(Handle<JSFunction> func,
00064 int argc,
00065 Object*** args,
00066 bool* pending_exception);
00067
00068
00069
00070
00071
00072 static Handle<Object> TryCall(Handle<JSFunction> func,
00073 Handle<Object> receiver,
00074 int argc,
00075 Object*** args,
00076 bool* caught_exception);
00077
00078
00079 static Handle<Object> ToBoolean(Handle<Object> obj);
00080
00081
00082 static Handle<Object> ToNumber(Handle<Object> obj, bool* exc);
00083
00084
00085 static Handle<Object> ToInteger(Handle<Object> obj, bool* exc);
00086
00087
00088 static Handle<Object> ToInt32(Handle<Object> obj, bool* exc);
00089
00090
00091 static Handle<Object> ToUint32(Handle<Object> obj, bool* exc);
00092
00093
00094 static Handle<Object> ToString(Handle<Object> obj, bool* exc);
00095
00096
00097 static Handle<Object> ToDetailString(Handle<Object> obj, bool* exc);
00098
00099
00100 static Handle<Object> ToObject(Handle<Object> obj, bool* exc);
00101
00102
00103 static Handle<Object> NewDate(double time, bool* exc);
00104
00105
00106 static Handle<Object> CharAt(Handle<String> str, uint32_t index);
00107
00108 static Handle<Object> GetFunctionFor();
00109 static Handle<JSFunction> InstantiateFunction(
00110 Handle<FunctionTemplateInfo> data, bool* exc);
00111 static Handle<JSObject> InstantiateObject(Handle<ObjectTemplateInfo> data,
00112 bool* exc);
00113 static void ConfigureInstance(Handle<Object> instance,
00114 Handle<Object> data,
00115 bool* exc);
00116 static Handle<String> GetStackTraceLine(Handle<Object> recv,
00117 Handle<JSFunction> fun,
00118 Handle<Object> pos,
00119 Handle<Object> is_global);
00120
00121
00122
00123 static Handle<Object> GetFunctionDelegate(Handle<Object> object);
00124 };
00125
00126
00127 class ExecutionAccess;
00128
00129
00130
00131
00132 class StackGuard BASE_EMBEDDED {
00133 public:
00134 StackGuard();
00135
00136 ~StackGuard();
00137
00138 static void SetStackLimit(uintptr_t limit);
00139
00140 static Address address_of_jslimit() {
00141 return reinterpret_cast<Address>(&thread_local_.jslimit_);
00142 }
00143
00144
00145 static char* ArchiveStackGuard(char* to);
00146 static char* RestoreStackGuard(char* from);
00147 static int ArchiveSpacePerThread();
00148
00149 static bool IsStackOverflow();
00150 static bool IsPreempted();
00151 static void Preempt();
00152 static bool IsInterrupted();
00153 static void Interrupt();
00154 static bool IsDebugBreak();
00155 static void DebugBreak();
00156 static void Continue(InterruptFlag after_what);
00157
00158 private:
00159
00160 static bool IsSet(const ExecutionAccess& lock);
00161
00162
00163
00164
00165 static uintptr_t climit() {
00166 return thread_local_.climit_;
00167 }
00168
00169
00170 static void set_limits(uintptr_t value, const ExecutionAccess& lock) {
00171 thread_local_.jslimit_ = value;
00172 thread_local_.climit_ = value;
00173 }
00174
00175
00176
00177 static void reset_limits(const ExecutionAccess& lock) {
00178 if (thread_local_.nesting_ == 0) {
00179
00180 set_limits(kIllegalLimit, lock);
00181 } else {
00182 thread_local_.jslimit_ = thread_local_.initial_jslimit_;
00183 thread_local_.climit_ = thread_local_.initial_climit_;
00184 }
00185 }
00186
00187
00188 static void EnableInterrupts();
00189 static void DisableInterrupts();
00190
00191 static const uintptr_t kLimitSize = 512 * KB;
00192 static const uintptr_t kInterruptLimit = 0xfffffffe;
00193 static const uintptr_t kIllegalLimit = 0xffffffff;
00194
00195 class ThreadLocal {
00196 public:
00197 ThreadLocal()
00198 : initial_jslimit_(kIllegalLimit),
00199 jslimit_(kIllegalLimit),
00200 initial_climit_(kIllegalLimit),
00201 climit_(kIllegalLimit),
00202 nesting_(0),
00203 postpone_interrupts_nesting_(0),
00204 interrupt_flags_(0) {}
00205 uintptr_t initial_jslimit_;
00206 uintptr_t jslimit_;
00207 uintptr_t initial_climit_;
00208 uintptr_t climit_;
00209 int nesting_;
00210 int postpone_interrupts_nesting_;
00211 int interrupt_flags_;
00212 };
00213
00214 static ThreadLocal thread_local_;
00215
00216 friend class StackLimitCheck;
00217 friend class PostponeInterruptsScope;
00218 };
00219
00220
00221
00222 class StackLimitCheck BASE_EMBEDDED {
00223 public:
00224 bool HasOverflowed() const {
00225 return reinterpret_cast<uintptr_t>(this) < StackGuard::climit();
00226 }
00227 };
00228
00229
00230
00231
00232
00233
00234 class PostponeInterruptsScope BASE_EMBEDDED {
00235 public:
00236 PostponeInterruptsScope() {
00237 StackGuard::thread_local_.postpone_interrupts_nesting_++;
00238 StackGuard::DisableInterrupts();
00239 }
00240
00241 ~PostponeInterruptsScope() {
00242 if (--StackGuard::thread_local_.postpone_interrupts_nesting_ == 0) {
00243 StackGuard::EnableInterrupts();
00244 }
00245 }
00246 };
00247
00248
00249 class GCExtension : public v8::Extension {
00250 public:
00251 GCExtension() : v8::Extension("v8/gc", kSource) {}
00252 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
00253 v8::Handle<v8::String> name);
00254 static v8::Handle<v8::Value> GC(const v8::Arguments& args);
00255 private:
00256 static const char* kSource;
00257 };
00258
00259
00260 } }
00261
00262 #endif // V8_EXECUTION_H_