OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 24 matching lines...) Expand all Loading... |
35 #include "debug.h" | 35 #include "debug.h" |
36 #include "runtime-profiler.h" | 36 #include "runtime-profiler.h" |
37 #include "simulator.h" | 37 #include "simulator.h" |
38 #include "v8threads.h" | 38 #include "v8threads.h" |
39 #include "vm-state-inl.h" | 39 #include "vm-state-inl.h" |
40 | 40 |
41 namespace v8 { | 41 namespace v8 { |
42 namespace internal { | 42 namespace internal { |
43 | 43 |
44 | 44 |
| 45 StackGuard::StackGuard() |
| 46 : isolate_(NULL) { |
| 47 } |
| 48 |
| 49 |
| 50 void StackGuard::set_interrupt_limits(const ExecutionAccess& lock) { |
| 51 ASSERT(isolate_ != NULL); |
| 52 // Ignore attempts to interrupt when interrupts are postponed. |
| 53 if (should_postpone_interrupts(lock)) return; |
| 54 thread_local_.jslimit_ = kInterruptLimit; |
| 55 thread_local_.climit_ = kInterruptLimit; |
| 56 isolate_->heap()->SetStackLimits(); |
| 57 } |
| 58 |
| 59 |
| 60 void StackGuard::reset_limits(const ExecutionAccess& lock) { |
| 61 ASSERT(isolate_ != NULL); |
| 62 thread_local_.jslimit_ = thread_local_.real_jslimit_; |
| 63 thread_local_.climit_ = thread_local_.real_climit_; |
| 64 isolate_->heap()->SetStackLimits(); |
| 65 } |
| 66 |
| 67 |
45 static Handle<Object> Invoke(bool construct, | 68 static Handle<Object> Invoke(bool construct, |
46 Handle<JSFunction> func, | 69 Handle<JSFunction> func, |
47 Handle<Object> receiver, | 70 Handle<Object> receiver, |
48 int argc, | 71 int argc, |
49 Object*** args, | 72 Object*** args, |
50 bool* has_pending_exception) { | 73 bool* has_pending_exception) { |
| 74 Isolate* isolate = func->GetIsolate(); |
| 75 |
51 // Entering JavaScript. | 76 // Entering JavaScript. |
52 VMState state(JS); | 77 VMState state(isolate, JS); |
53 | 78 |
54 // Placeholder for return value. | 79 // Placeholder for return value. |
55 MaybeObject* value = reinterpret_cast<Object*>(kZapValue); | 80 MaybeObject* value = reinterpret_cast<Object*>(kZapValue); |
56 | 81 |
57 typedef Object* (*JSEntryFunction)( | 82 typedef Object* (*JSEntryFunction)( |
58 byte* entry, | 83 byte* entry, |
59 Object* function, | 84 Object* function, |
60 Object* receiver, | 85 Object* receiver, |
61 int argc, | 86 int argc, |
62 Object*** args); | 87 Object*** args); |
(...skipping 15 matching lines...) Expand all Loading... |
78 receiver = Handle<JSObject>(global->global_receiver()); | 103 receiver = Handle<JSObject>(global->global_receiver()); |
79 } | 104 } |
80 | 105 |
81 // Make sure that the global object of the context we're about to | 106 // Make sure that the global object of the context we're about to |
82 // make the current one is indeed a global object. | 107 // make the current one is indeed a global object. |
83 ASSERT(func->context()->global()->IsGlobalObject()); | 108 ASSERT(func->context()->global()->IsGlobalObject()); |
84 | 109 |
85 { | 110 { |
86 // Save and restore context around invocation and block the | 111 // Save and restore context around invocation and block the |
87 // allocation of handles without explicit handle scopes. | 112 // allocation of handles without explicit handle scopes. |
88 SaveContext save; | 113 SaveContext save(isolate); |
89 NoHandleAllocation na; | 114 NoHandleAllocation na; |
90 JSEntryFunction entry = FUNCTION_CAST<JSEntryFunction>(code->entry()); | 115 JSEntryFunction entry = FUNCTION_CAST<JSEntryFunction>(code->entry()); |
91 | 116 |
92 // Call the function through the right JS entry stub. | 117 // Call the function through the right JS entry stub. |
93 byte* entry_address = func->code()->entry(); | 118 byte* entry_address = func->code()->entry(); |
94 JSFunction* function = *func; | 119 JSFunction* function = *func; |
95 Object* receiver_pointer = *receiver; | 120 Object* receiver_pointer = *receiver; |
96 value = CALL_GENERATED_CODE(entry, entry_address, function, | 121 value = CALL_GENERATED_CODE(entry, entry_address, function, |
97 receiver_pointer, argc, args); | 122 receiver_pointer, argc, args); |
98 } | 123 } |
99 | 124 |
100 #ifdef DEBUG | 125 #ifdef DEBUG |
101 value->Verify(); | 126 value->Verify(); |
102 #endif | 127 #endif |
103 | 128 |
104 // Update the pending exception flag and return the value. | 129 // Update the pending exception flag and return the value. |
105 *has_pending_exception = value->IsException(); | 130 *has_pending_exception = value->IsException(); |
106 ASSERT(*has_pending_exception == Top::has_pending_exception()); | 131 ASSERT(*has_pending_exception == Isolate::Current()->has_pending_exception()); |
107 if (*has_pending_exception) { | 132 if (*has_pending_exception) { |
108 Top::ReportPendingMessages(); | 133 isolate->ReportPendingMessages(); |
109 if (Top::pending_exception() == Failure::OutOfMemoryException()) { | 134 if (isolate->pending_exception() == Failure::OutOfMemoryException()) { |
110 if (!HandleScopeImplementer::instance()->ignore_out_of_memory()) { | 135 if (!isolate->handle_scope_implementer()->ignore_out_of_memory()) { |
111 V8::FatalProcessOutOfMemory("JS", true); | 136 V8::FatalProcessOutOfMemory("JS", true); |
112 } | 137 } |
113 } | 138 } |
114 return Handle<Object>(); | 139 return Handle<Object>(); |
115 } else { | 140 } else { |
116 Top::clear_pending_message(); | 141 isolate->clear_pending_message(); |
117 } | 142 } |
118 | 143 |
119 return Handle<Object>(value->ToObjectUnchecked()); | 144 return Handle<Object>(value->ToObjectUnchecked(), isolate); |
120 } | 145 } |
121 | 146 |
122 | 147 |
123 Handle<Object> Execution::Call(Handle<JSFunction> func, | 148 Handle<Object> Execution::Call(Handle<JSFunction> func, |
124 Handle<Object> receiver, | 149 Handle<Object> receiver, |
125 int argc, | 150 int argc, |
126 Object*** args, | 151 Object*** args, |
127 bool* pending_exception) { | 152 bool* pending_exception) { |
128 return Invoke(false, func, receiver, argc, args, pending_exception); | 153 return Invoke(false, func, receiver, argc, args, pending_exception); |
129 } | 154 } |
130 | 155 |
131 | 156 |
132 Handle<Object> Execution::New(Handle<JSFunction> func, int argc, | 157 Handle<Object> Execution::New(Handle<JSFunction> func, int argc, |
133 Object*** args, bool* pending_exception) { | 158 Object*** args, bool* pending_exception) { |
134 return Invoke(true, func, Top::global(), argc, args, pending_exception); | 159 return Invoke(true, func, Isolate::Current()->global(), argc, args, |
| 160 pending_exception); |
135 } | 161 } |
136 | 162 |
137 | 163 |
138 Handle<Object> Execution::TryCall(Handle<JSFunction> func, | 164 Handle<Object> Execution::TryCall(Handle<JSFunction> func, |
139 Handle<Object> receiver, | 165 Handle<Object> receiver, |
140 int argc, | 166 int argc, |
141 Object*** args, | 167 Object*** args, |
142 bool* caught_exception) { | 168 bool* caught_exception) { |
143 // Enter a try-block while executing the JavaScript code. To avoid | 169 // Enter a try-block while executing the JavaScript code. To avoid |
144 // duplicate error printing it must be non-verbose. Also, to avoid | 170 // duplicate error printing it must be non-verbose. Also, to avoid |
145 // creating message objects during stack overflow we shouldn't | 171 // creating message objects during stack overflow we shouldn't |
146 // capture messages. | 172 // capture messages. |
147 v8::TryCatch catcher; | 173 v8::TryCatch catcher; |
148 catcher.SetVerbose(false); | 174 catcher.SetVerbose(false); |
149 catcher.SetCaptureMessage(false); | 175 catcher.SetCaptureMessage(false); |
150 | 176 |
151 Handle<Object> result = Invoke(false, func, receiver, argc, args, | 177 Handle<Object> result = Invoke(false, func, receiver, argc, args, |
152 caught_exception); | 178 caught_exception); |
153 | 179 |
154 if (*caught_exception) { | 180 if (*caught_exception) { |
155 ASSERT(catcher.HasCaught()); | 181 ASSERT(catcher.HasCaught()); |
156 ASSERT(Top::has_pending_exception()); | 182 Isolate* isolate = Isolate::Current(); |
157 ASSERT(Top::external_caught_exception()); | 183 ASSERT(isolate->has_pending_exception()); |
158 if (Top::pending_exception() == Heap::termination_exception()) { | 184 ASSERT(isolate->external_caught_exception()); |
159 result = Factory::termination_exception(); | 185 if (isolate->pending_exception() == |
| 186 isolate->heap()->termination_exception()) { |
| 187 result = isolate->factory()->termination_exception(); |
160 } else { | 188 } else { |
161 result = v8::Utils::OpenHandle(*catcher.Exception()); | 189 result = v8::Utils::OpenHandle(*catcher.Exception()); |
162 } | 190 } |
163 Top::OptionalRescheduleException(true); | 191 isolate->OptionalRescheduleException(true); |
164 } | 192 } |
165 | 193 |
166 ASSERT(!Top::has_pending_exception()); | 194 ASSERT(!Isolate::Current()->has_pending_exception()); |
167 ASSERT(!Top::external_caught_exception()); | 195 ASSERT(!Isolate::Current()->external_caught_exception()); |
168 return result; | 196 return result; |
169 } | 197 } |
170 | 198 |
171 | 199 |
172 Handle<Object> Execution::GetFunctionDelegate(Handle<Object> object) { | 200 Handle<Object> Execution::GetFunctionDelegate(Handle<Object> object) { |
173 ASSERT(!object->IsJSFunction()); | 201 ASSERT(!object->IsJSFunction()); |
174 | 202 |
175 // If you return a function from here, it will be called when an | 203 // If you return a function from here, it will be called when an |
176 // attempt is made to call the given object as a function. | 204 // attempt is made to call the given object as a function. |
177 | 205 |
178 // Regular expressions can be called as functions in both Firefox | 206 // Regular expressions can be called as functions in both Firefox |
179 // and Safari so we allow it too. | 207 // and Safari so we allow it too. |
180 if (object->IsJSRegExp()) { | 208 if (object->IsJSRegExp()) { |
181 Handle<String> exec = Factory::exec_symbol(); | 209 Handle<String> exec = FACTORY->exec_symbol(); |
182 // TODO(lrn): Bug 617. We should use the default function here, not the | 210 // TODO(lrn): Bug 617. We should use the default function here, not the |
183 // one on the RegExp object. | 211 // one on the RegExp object. |
184 Object* exec_function; | 212 Object* exec_function; |
185 { MaybeObject* maybe_exec_function = object->GetProperty(*exec); | 213 { MaybeObject* maybe_exec_function = object->GetProperty(*exec); |
186 // This can lose an exception, but the alternative is to put a failure | 214 // This can lose an exception, but the alternative is to put a failure |
187 // object in a handle, which is not GC safe. | 215 // object in a handle, which is not GC safe. |
188 if (!maybe_exec_function->ToObject(&exec_function)) { | 216 if (!maybe_exec_function->ToObject(&exec_function)) { |
189 return Factory::undefined_value(); | 217 return FACTORY->undefined_value(); |
190 } | 218 } |
191 } | 219 } |
192 return Handle<Object>(exec_function); | 220 return Handle<Object>(exec_function); |
193 } | 221 } |
194 | 222 |
195 // Objects created through the API can have an instance-call handler | 223 // Objects created through the API can have an instance-call handler |
196 // that should be used when calling the object as a function. | 224 // that should be used when calling the object as a function. |
197 if (object->IsHeapObject() && | 225 if (object->IsHeapObject() && |
198 HeapObject::cast(*object)->map()->has_instance_call_handler()) { | 226 HeapObject::cast(*object)->map()->has_instance_call_handler()) { |
199 return Handle<JSFunction>( | 227 return Handle<JSFunction>( |
200 Top::global_context()->call_as_function_delegate()); | 228 Isolate::Current()->global_context()->call_as_function_delegate()); |
201 } | 229 } |
202 | 230 |
203 return Factory::undefined_value(); | 231 return FACTORY->undefined_value(); |
204 } | 232 } |
205 | 233 |
206 | 234 |
207 Handle<Object> Execution::GetConstructorDelegate(Handle<Object> object) { | 235 Handle<Object> Execution::GetConstructorDelegate(Handle<Object> object) { |
208 ASSERT(!object->IsJSFunction()); | 236 ASSERT(!object->IsJSFunction()); |
209 | 237 |
210 // If you return a function from here, it will be called when an | 238 // If you return a function from here, it will be called when an |
211 // attempt is made to call the given object as a constructor. | 239 // attempt is made to call the given object as a constructor. |
212 | 240 |
213 // Objects created through the API can have an instance-call handler | 241 // Objects created through the API can have an instance-call handler |
214 // that should be used when calling the object as a function. | 242 // that should be used when calling the object as a function. |
215 if (object->IsHeapObject() && | 243 if (object->IsHeapObject() && |
216 HeapObject::cast(*object)->map()->has_instance_call_handler()) { | 244 HeapObject::cast(*object)->map()->has_instance_call_handler()) { |
217 return Handle<JSFunction>( | 245 return Handle<JSFunction>( |
218 Top::global_context()->call_as_constructor_delegate()); | 246 Isolate::Current()->global_context()->call_as_constructor_delegate()); |
219 } | 247 } |
220 | 248 |
221 return Factory::undefined_value(); | 249 return FACTORY->undefined_value(); |
222 } | 250 } |
223 | 251 |
224 | 252 |
225 // Static state for stack guards. | |
226 StackGuard::ThreadLocal StackGuard::thread_local_; | |
227 | |
228 | |
229 bool StackGuard::IsStackOverflow() { | 253 bool StackGuard::IsStackOverflow() { |
230 ExecutionAccess access; | 254 ExecutionAccess access(isolate_); |
231 return (thread_local_.jslimit_ != kInterruptLimit && | 255 return (thread_local_.jslimit_ != kInterruptLimit && |
232 thread_local_.climit_ != kInterruptLimit); | 256 thread_local_.climit_ != kInterruptLimit); |
233 } | 257 } |
234 | 258 |
235 | 259 |
236 void StackGuard::EnableInterrupts() { | 260 void StackGuard::EnableInterrupts() { |
237 ExecutionAccess access; | 261 ExecutionAccess access(isolate_); |
238 if (has_pending_interrupts(access)) { | 262 if (has_pending_interrupts(access)) { |
239 set_interrupt_limits(access); | 263 set_interrupt_limits(access); |
240 } | 264 } |
241 } | 265 } |
242 | 266 |
243 | 267 |
244 void StackGuard::SetStackLimit(uintptr_t limit) { | 268 void StackGuard::SetStackLimit(uintptr_t limit) { |
245 ExecutionAccess access; | 269 ExecutionAccess access(isolate_); |
246 // If the current limits are special (eg due to a pending interrupt) then | 270 // If the current limits are special (eg due to a pending interrupt) then |
247 // leave them alone. | 271 // leave them alone. |
248 uintptr_t jslimit = SimulatorStack::JsLimitFromCLimit(limit); | 272 uintptr_t jslimit = SimulatorStack::JsLimitFromCLimit(limit); |
249 if (thread_local_.jslimit_ == thread_local_.real_jslimit_) { | 273 if (thread_local_.jslimit_ == thread_local_.real_jslimit_) { |
250 thread_local_.jslimit_ = jslimit; | 274 thread_local_.jslimit_ = jslimit; |
251 } | 275 } |
252 if (thread_local_.climit_ == thread_local_.real_climit_) { | 276 if (thread_local_.climit_ == thread_local_.real_climit_) { |
253 thread_local_.climit_ = limit; | 277 thread_local_.climit_ = limit; |
254 } | 278 } |
255 thread_local_.real_climit_ = limit; | 279 thread_local_.real_climit_ = limit; |
256 thread_local_.real_jslimit_ = jslimit; | 280 thread_local_.real_jslimit_ = jslimit; |
257 } | 281 } |
258 | 282 |
259 | 283 |
260 void StackGuard::DisableInterrupts() { | 284 void StackGuard::DisableInterrupts() { |
261 ExecutionAccess access; | 285 ExecutionAccess access(isolate_); |
262 reset_limits(access); | 286 reset_limits(access); |
263 } | 287 } |
264 | 288 |
265 | 289 |
266 bool StackGuard::IsInterrupted() { | 290 bool StackGuard::IsInterrupted() { |
267 ExecutionAccess access; | 291 ExecutionAccess access(isolate_); |
268 return thread_local_.interrupt_flags_ & INTERRUPT; | 292 return thread_local_.interrupt_flags_ & INTERRUPT; |
269 } | 293 } |
270 | 294 |
271 | 295 |
272 void StackGuard::Interrupt() { | 296 void StackGuard::Interrupt() { |
273 ExecutionAccess access; | 297 ExecutionAccess access(isolate_); |
274 thread_local_.interrupt_flags_ |= INTERRUPT; | 298 thread_local_.interrupt_flags_ |= INTERRUPT; |
275 set_interrupt_limits(access); | 299 set_interrupt_limits(access); |
276 } | 300 } |
277 | 301 |
278 | 302 |
279 bool StackGuard::IsPreempted() { | 303 bool StackGuard::IsPreempted() { |
280 ExecutionAccess access; | 304 ExecutionAccess access(isolate_); |
281 return thread_local_.interrupt_flags_ & PREEMPT; | 305 return thread_local_.interrupt_flags_ & PREEMPT; |
282 } | 306 } |
283 | 307 |
284 | 308 |
285 void StackGuard::Preempt() { | 309 void StackGuard::Preempt() { |
286 ExecutionAccess access; | 310 ExecutionAccess access(isolate_); |
287 thread_local_.interrupt_flags_ |= PREEMPT; | 311 thread_local_.interrupt_flags_ |= PREEMPT; |
288 set_interrupt_limits(access); | 312 set_interrupt_limits(access); |
289 } | 313 } |
290 | 314 |
291 | 315 |
292 bool StackGuard::IsTerminateExecution() { | 316 bool StackGuard::IsTerminateExecution() { |
293 ExecutionAccess access; | 317 ExecutionAccess access(isolate_); |
294 return thread_local_.interrupt_flags_ & TERMINATE; | 318 return thread_local_.interrupt_flags_ & TERMINATE; |
295 } | 319 } |
296 | 320 |
297 | 321 |
298 void StackGuard::TerminateExecution() { | 322 void StackGuard::TerminateExecution() { |
299 ExecutionAccess access; | 323 ExecutionAccess access(isolate_); |
300 thread_local_.interrupt_flags_ |= TERMINATE; | 324 thread_local_.interrupt_flags_ |= TERMINATE; |
301 set_interrupt_limits(access); | 325 set_interrupt_limits(access); |
302 } | 326 } |
303 | 327 |
304 | 328 |
305 bool StackGuard::IsRuntimeProfilerTick() { | 329 bool StackGuard::IsRuntimeProfilerTick() { |
306 ExecutionAccess access; | 330 ExecutionAccess access(isolate_); |
307 return thread_local_.interrupt_flags_ & RUNTIME_PROFILER_TICK; | 331 return thread_local_.interrupt_flags_ & RUNTIME_PROFILER_TICK; |
308 } | 332 } |
309 | 333 |
310 | 334 |
311 void StackGuard::RequestRuntimeProfilerTick() { | 335 void StackGuard::RequestRuntimeProfilerTick() { |
312 // Ignore calls if we're not optimizing or if we can't get the lock. | 336 // Ignore calls if we're not optimizing or if we can't get the lock. |
313 if (FLAG_opt && ExecutionAccess::TryLock()) { | 337 if (FLAG_opt && ExecutionAccess::TryLock(isolate_)) { |
314 thread_local_.interrupt_flags_ |= RUNTIME_PROFILER_TICK; | 338 thread_local_.interrupt_flags_ |= RUNTIME_PROFILER_TICK; |
315 if (thread_local_.postpone_interrupts_nesting_ == 0) { | 339 if (thread_local_.postpone_interrupts_nesting_ == 0) { |
316 thread_local_.jslimit_ = thread_local_.climit_ = kInterruptLimit; | 340 thread_local_.jslimit_ = thread_local_.climit_ = kInterruptLimit; |
317 Heap::SetStackLimits(); | 341 isolate_->heap()->SetStackLimits(); |
318 } | 342 } |
319 ExecutionAccess::Unlock(); | 343 ExecutionAccess::Unlock(isolate_); |
320 } | 344 } |
321 } | 345 } |
322 | 346 |
323 | 347 |
324 #ifdef ENABLE_DEBUGGER_SUPPORT | 348 #ifdef ENABLE_DEBUGGER_SUPPORT |
325 bool StackGuard::IsDebugBreak() { | 349 bool StackGuard::IsDebugBreak() { |
326 ExecutionAccess access; | 350 ExecutionAccess access(isolate_); |
327 return thread_local_.interrupt_flags_ & DEBUGBREAK; | 351 return thread_local_.interrupt_flags_ & DEBUGBREAK; |
328 } | 352 } |
329 | 353 |
330 | 354 |
331 void StackGuard::DebugBreak() { | 355 void StackGuard::DebugBreak() { |
332 ExecutionAccess access; | 356 ExecutionAccess access(isolate_); |
333 thread_local_.interrupt_flags_ |= DEBUGBREAK; | 357 thread_local_.interrupt_flags_ |= DEBUGBREAK; |
334 set_interrupt_limits(access); | 358 set_interrupt_limits(access); |
335 } | 359 } |
336 | 360 |
337 | 361 |
338 bool StackGuard::IsDebugCommand() { | 362 bool StackGuard::IsDebugCommand() { |
339 ExecutionAccess access; | 363 ExecutionAccess access(isolate_); |
340 return thread_local_.interrupt_flags_ & DEBUGCOMMAND; | 364 return thread_local_.interrupt_flags_ & DEBUGCOMMAND; |
341 } | 365 } |
342 | 366 |
343 | 367 |
344 void StackGuard::DebugCommand() { | 368 void StackGuard::DebugCommand() { |
345 if (FLAG_debugger_auto_break) { | 369 if (FLAG_debugger_auto_break) { |
346 ExecutionAccess access; | 370 ExecutionAccess access(isolate_); |
347 thread_local_.interrupt_flags_ |= DEBUGCOMMAND; | 371 thread_local_.interrupt_flags_ |= DEBUGCOMMAND; |
348 set_interrupt_limits(access); | 372 set_interrupt_limits(access); |
349 } | 373 } |
350 } | 374 } |
351 #endif | 375 #endif |
352 | 376 |
353 void StackGuard::Continue(InterruptFlag after_what) { | 377 void StackGuard::Continue(InterruptFlag after_what) { |
354 ExecutionAccess access; | 378 ExecutionAccess access(isolate_); |
355 thread_local_.interrupt_flags_ &= ~static_cast<int>(after_what); | 379 thread_local_.interrupt_flags_ &= ~static_cast<int>(after_what); |
356 if (!should_postpone_interrupts(access) && !has_pending_interrupts(access)) { | 380 if (!should_postpone_interrupts(access) && !has_pending_interrupts(access)) { |
357 reset_limits(access); | 381 reset_limits(access); |
358 } | 382 } |
359 } | 383 } |
360 | 384 |
361 | 385 |
362 int StackGuard::ArchiveSpacePerThread() { | |
363 return sizeof(ThreadLocal); | |
364 } | |
365 | |
366 | |
367 char* StackGuard::ArchiveStackGuard(char* to) { | 386 char* StackGuard::ArchiveStackGuard(char* to) { |
368 ExecutionAccess access; | 387 ExecutionAccess access(isolate_); |
369 memcpy(to, reinterpret_cast<char*>(&thread_local_), sizeof(ThreadLocal)); | 388 memcpy(to, reinterpret_cast<char*>(&thread_local_), sizeof(ThreadLocal)); |
370 ThreadLocal blank; | 389 ThreadLocal blank; |
| 390 |
| 391 // Set the stack limits using the old thread_local_. |
| 392 // TODO(isolates): This was the old semantics of constructing a ThreadLocal |
| 393 // (as the ctor called SetStackLimits, which looked at the |
| 394 // current thread_local_ from StackGuard)-- but is this |
| 395 // really what was intended? |
| 396 isolate_->heap()->SetStackLimits(); |
371 thread_local_ = blank; | 397 thread_local_ = blank; |
| 398 |
372 return to + sizeof(ThreadLocal); | 399 return to + sizeof(ThreadLocal); |
373 } | 400 } |
374 | 401 |
375 | 402 |
376 char* StackGuard::RestoreStackGuard(char* from) { | 403 char* StackGuard::RestoreStackGuard(char* from) { |
377 ExecutionAccess access; | 404 ExecutionAccess access(isolate_); |
378 memcpy(reinterpret_cast<char*>(&thread_local_), from, sizeof(ThreadLocal)); | 405 memcpy(reinterpret_cast<char*>(&thread_local_), from, sizeof(ThreadLocal)); |
379 Heap::SetStackLimits(); | 406 isolate_->heap()->SetStackLimits(); |
380 return from + sizeof(ThreadLocal); | 407 return from + sizeof(ThreadLocal); |
381 } | 408 } |
382 | 409 |
383 | 410 |
384 static internal::Thread::LocalStorageKey stack_limit_key = | |
385 internal::Thread::CreateThreadLocalKey(); | |
386 | |
387 | |
388 void StackGuard::FreeThreadResources() { | 411 void StackGuard::FreeThreadResources() { |
389 Thread::SetThreadLocal( | 412 Isolate::CurrentPerIsolateThreadData()->set_stack_limit( |
390 stack_limit_key, | 413 thread_local_.real_climit_); |
391 reinterpret_cast<void*>(thread_local_.real_climit_)); | |
392 } | 414 } |
393 | 415 |
394 | 416 |
395 void StackGuard::ThreadLocal::Clear() { | 417 void StackGuard::ThreadLocal::Clear() { |
396 real_jslimit_ = kIllegalLimit; | 418 real_jslimit_ = kIllegalLimit; |
397 jslimit_ = kIllegalLimit; | 419 jslimit_ = kIllegalLimit; |
398 real_climit_ = kIllegalLimit; | 420 real_climit_ = kIllegalLimit; |
399 climit_ = kIllegalLimit; | 421 climit_ = kIllegalLimit; |
400 nesting_ = 0; | 422 nesting_ = 0; |
401 postpone_interrupts_nesting_ = 0; | 423 postpone_interrupts_nesting_ = 0; |
402 interrupt_flags_ = 0; | 424 interrupt_flags_ = 0; |
403 Heap::SetStackLimits(); | |
404 } | 425 } |
405 | 426 |
406 | 427 |
407 void StackGuard::ThreadLocal::Initialize() { | 428 bool StackGuard::ThreadLocal::Initialize() { |
| 429 bool should_set_stack_limits = false; |
408 if (real_climit_ == kIllegalLimit) { | 430 if (real_climit_ == kIllegalLimit) { |
409 // Takes the address of the limit variable in order to find out where | 431 // Takes the address of the limit variable in order to find out where |
410 // the top of stack is right now. | 432 // the top of stack is right now. |
411 const uintptr_t kLimitSize = FLAG_stack_size * KB; | 433 const uintptr_t kLimitSize = FLAG_stack_size * KB; |
412 uintptr_t limit = reinterpret_cast<uintptr_t>(&limit) - kLimitSize; | 434 uintptr_t limit = reinterpret_cast<uintptr_t>(&limit) - kLimitSize; |
413 ASSERT(reinterpret_cast<uintptr_t>(&limit) > kLimitSize); | 435 ASSERT(reinterpret_cast<uintptr_t>(&limit) > kLimitSize); |
414 real_jslimit_ = SimulatorStack::JsLimitFromCLimit(limit); | 436 real_jslimit_ = SimulatorStack::JsLimitFromCLimit(limit); |
415 jslimit_ = SimulatorStack::JsLimitFromCLimit(limit); | 437 jslimit_ = SimulatorStack::JsLimitFromCLimit(limit); |
416 real_climit_ = limit; | 438 real_climit_ = limit; |
417 climit_ = limit; | 439 climit_ = limit; |
418 Heap::SetStackLimits(); | 440 should_set_stack_limits = true; |
419 } | 441 } |
420 nesting_ = 0; | 442 nesting_ = 0; |
421 postpone_interrupts_nesting_ = 0; | 443 postpone_interrupts_nesting_ = 0; |
422 interrupt_flags_ = 0; | 444 interrupt_flags_ = 0; |
| 445 return should_set_stack_limits; |
423 } | 446 } |
424 | 447 |
425 | 448 |
426 void StackGuard::ClearThread(const ExecutionAccess& lock) { | 449 void StackGuard::ClearThread(const ExecutionAccess& lock) { |
427 thread_local_.Clear(); | 450 thread_local_.Clear(); |
| 451 isolate_->heap()->SetStackLimits(); |
428 } | 452 } |
429 | 453 |
430 | 454 |
431 void StackGuard::InitThread(const ExecutionAccess& lock) { | 455 void StackGuard::InitThread(const ExecutionAccess& lock) { |
432 thread_local_.Initialize(); | 456 if (thread_local_.Initialize()) isolate_->heap()->SetStackLimits(); |
433 void* stored_limit = Thread::GetThreadLocal(stack_limit_key); | 457 uintptr_t stored_limit = |
| 458 Isolate::CurrentPerIsolateThreadData()->stack_limit(); |
434 // You should hold the ExecutionAccess lock when you call this. | 459 // You should hold the ExecutionAccess lock when you call this. |
435 if (stored_limit != NULL) { | 460 if (stored_limit != 0) { |
436 StackGuard::SetStackLimit(reinterpret_cast<intptr_t>(stored_limit)); | 461 StackGuard::SetStackLimit(stored_limit); |
437 } | 462 } |
438 } | 463 } |
439 | 464 |
440 | 465 |
441 // --- C a l l s t o n a t i v e s --- | 466 // --- C a l l s t o n a t i v e s --- |
442 | 467 |
443 #define RETURN_NATIVE_CALL(name, argc, argv, has_pending_exception) \ | 468 #define RETURN_NATIVE_CALL(name, argc, argv, has_pending_exception) \ |
444 do { \ | 469 do { \ |
445 Object** args[argc] = argv; \ | 470 Object** args[argc] = argv; \ |
446 ASSERT(has_pending_exception != NULL); \ | 471 ASSERT(has_pending_exception != NULL); \ |
447 return Call(Top::name##_fun(), Top::builtins(), argc, args, \ | 472 return Call(Isolate::Current()->name##_fun(), \ |
448 has_pending_exception); \ | 473 Isolate::Current()->js_builtins_object(), argc, args, \ |
| 474 has_pending_exception); \ |
449 } while (false) | 475 } while (false) |
450 | 476 |
451 | 477 |
452 Handle<Object> Execution::ToBoolean(Handle<Object> obj) { | 478 Handle<Object> Execution::ToBoolean(Handle<Object> obj) { |
453 // See the similar code in runtime.js:ToBoolean. | 479 // See the similar code in runtime.js:ToBoolean. |
454 if (obj->IsBoolean()) return obj; | 480 if (obj->IsBoolean()) return obj; |
455 bool result = true; | 481 bool result = true; |
456 if (obj->IsString()) { | 482 if (obj->IsString()) { |
457 result = Handle<String>::cast(obj)->length() != 0; | 483 result = Handle<String>::cast(obj)->length() != 0; |
458 } else if (obj->IsNull() || obj->IsUndefined()) { | 484 } else if (obj->IsNull() || obj->IsUndefined()) { |
459 result = false; | 485 result = false; |
460 } else if (obj->IsNumber()) { | 486 } else if (obj->IsNumber()) { |
461 double value = obj->Number(); | 487 double value = obj->Number(); |
462 result = !((value == 0) || isnan(value)); | 488 result = !((value == 0) || isnan(value)); |
463 } | 489 } |
464 return Handle<Object>(Heap::ToBoolean(result)); | 490 return Handle<Object>(HEAP->ToBoolean(result)); |
465 } | 491 } |
466 | 492 |
467 | 493 |
468 Handle<Object> Execution::ToNumber(Handle<Object> obj, bool* exc) { | 494 Handle<Object> Execution::ToNumber(Handle<Object> obj, bool* exc) { |
469 RETURN_NATIVE_CALL(to_number, 1, { obj.location() }, exc); | 495 RETURN_NATIVE_CALL(to_number, 1, { obj.location() }, exc); |
470 } | 496 } |
471 | 497 |
472 | 498 |
473 Handle<Object> Execution::ToString(Handle<Object> obj, bool* exc) { | 499 Handle<Object> Execution::ToString(Handle<Object> obj, bool* exc) { |
474 RETURN_NATIVE_CALL(to_string, 1, { obj.location() }, exc); | 500 RETURN_NATIVE_CALL(to_string, 1, { obj.location() }, exc); |
(...skipping 20 matching lines...) Expand all Loading... |
495 RETURN_NATIVE_CALL(to_uint32, 1, { obj.location() }, exc); | 521 RETURN_NATIVE_CALL(to_uint32, 1, { obj.location() }, exc); |
496 } | 522 } |
497 | 523 |
498 | 524 |
499 Handle<Object> Execution::ToInt32(Handle<Object> obj, bool* exc) { | 525 Handle<Object> Execution::ToInt32(Handle<Object> obj, bool* exc) { |
500 RETURN_NATIVE_CALL(to_int32, 1, { obj.location() }, exc); | 526 RETURN_NATIVE_CALL(to_int32, 1, { obj.location() }, exc); |
501 } | 527 } |
502 | 528 |
503 | 529 |
504 Handle<Object> Execution::NewDate(double time, bool* exc) { | 530 Handle<Object> Execution::NewDate(double time, bool* exc) { |
505 Handle<Object> time_obj = Factory::NewNumber(time); | 531 Handle<Object> time_obj = FACTORY->NewNumber(time); |
506 RETURN_NATIVE_CALL(create_date, 1, { time_obj.location() }, exc); | 532 RETURN_NATIVE_CALL(create_date, 1, { time_obj.location() }, exc); |
507 } | 533 } |
508 | 534 |
509 | 535 |
510 #undef RETURN_NATIVE_CALL | 536 #undef RETURN_NATIVE_CALL |
511 | 537 |
512 | 538 |
513 Handle<JSRegExp> Execution::NewJSRegExp(Handle<String> pattern, | 539 Handle<JSRegExp> Execution::NewJSRegExp(Handle<String> pattern, |
514 Handle<String> flags, | 540 Handle<String> flags, |
515 bool* exc) { | 541 bool* exc) { |
| 542 Handle<JSFunction> function = Handle<JSFunction>( |
| 543 pattern->GetIsolate()->global_context()->regexp_function()); |
516 Handle<Object> re_obj = RegExpImpl::CreateRegExpLiteral( | 544 Handle<Object> re_obj = RegExpImpl::CreateRegExpLiteral( |
517 Handle<JSFunction>(Top::global_context()->regexp_function()), | 545 function, pattern, flags, exc); |
518 pattern, | |
519 flags, | |
520 exc); | |
521 if (*exc) return Handle<JSRegExp>(); | 546 if (*exc) return Handle<JSRegExp>(); |
522 return Handle<JSRegExp>::cast(re_obj); | 547 return Handle<JSRegExp>::cast(re_obj); |
523 } | 548 } |
524 | 549 |
525 | 550 |
526 Handle<Object> Execution::CharAt(Handle<String> string, uint32_t index) { | 551 Handle<Object> Execution::CharAt(Handle<String> string, uint32_t index) { |
527 int int_index = static_cast<int>(index); | 552 int int_index = static_cast<int>(index); |
528 if (int_index < 0 || int_index >= string->length()) { | 553 if (int_index < 0 || int_index >= string->length()) { |
529 return Factory::undefined_value(); | 554 return FACTORY->undefined_value(); |
530 } | 555 } |
531 | 556 |
532 Handle<Object> char_at = | 557 Handle<Object> char_at = |
533 GetProperty(Top::builtins(), Factory::char_at_symbol()); | 558 GetProperty(Isolate::Current()->js_builtins_object(), |
| 559 FACTORY->char_at_symbol()); |
534 if (!char_at->IsJSFunction()) { | 560 if (!char_at->IsJSFunction()) { |
535 return Factory::undefined_value(); | 561 return FACTORY->undefined_value(); |
536 } | 562 } |
537 | 563 |
538 bool caught_exception; | 564 bool caught_exception; |
539 Handle<Object> index_object = Factory::NewNumberFromInt(int_index); | 565 Handle<Object> index_object = FACTORY->NewNumberFromInt(int_index); |
540 Object** index_arg[] = { index_object.location() }; | 566 Object** index_arg[] = { index_object.location() }; |
541 Handle<Object> result = TryCall(Handle<JSFunction>::cast(char_at), | 567 Handle<Object> result = TryCall(Handle<JSFunction>::cast(char_at), |
542 string, | 568 string, |
543 ARRAY_SIZE(index_arg), | 569 ARRAY_SIZE(index_arg), |
544 index_arg, | 570 index_arg, |
545 &caught_exception); | 571 &caught_exception); |
546 if (caught_exception) { | 572 if (caught_exception) { |
547 return Factory::undefined_value(); | 573 return FACTORY->undefined_value(); |
548 } | 574 } |
549 return result; | 575 return result; |
550 } | 576 } |
551 | 577 |
552 | 578 |
553 Handle<JSFunction> Execution::InstantiateFunction( | 579 Handle<JSFunction> Execution::InstantiateFunction( |
554 Handle<FunctionTemplateInfo> data, bool* exc) { | 580 Handle<FunctionTemplateInfo> data, bool* exc) { |
555 // Fast case: see if the function has already been instantiated | 581 // Fast case: see if the function has already been instantiated |
556 int serial_number = Smi::cast(data->serial_number())->value(); | 582 int serial_number = Smi::cast(data->serial_number())->value(); |
557 Object* elm = Top::global_context()->function_cache()-> | 583 Object* elm = |
558 GetElementNoExceptionThrown(serial_number); | 584 Isolate::Current()->global_context()->function_cache()-> |
| 585 GetElementNoExceptionThrown(serial_number); |
559 if (elm->IsJSFunction()) return Handle<JSFunction>(JSFunction::cast(elm)); | 586 if (elm->IsJSFunction()) return Handle<JSFunction>(JSFunction::cast(elm)); |
560 // The function has not yet been instantiated in this context; do it. | 587 // The function has not yet been instantiated in this context; do it. |
561 Object** args[1] = { Handle<Object>::cast(data).location() }; | 588 Object** args[1] = { Handle<Object>::cast(data).location() }; |
562 Handle<Object> result = | 589 Handle<Object> result = |
563 Call(Top::instantiate_fun(), Top::builtins(), 1, args, exc); | 590 Call(Isolate::Current()->instantiate_fun(), |
| 591 Isolate::Current()->js_builtins_object(), 1, args, exc); |
564 if (*exc) return Handle<JSFunction>::null(); | 592 if (*exc) return Handle<JSFunction>::null(); |
565 return Handle<JSFunction>::cast(result); | 593 return Handle<JSFunction>::cast(result); |
566 } | 594 } |
567 | 595 |
568 | 596 |
569 Handle<JSObject> Execution::InstantiateObject(Handle<ObjectTemplateInfo> data, | 597 Handle<JSObject> Execution::InstantiateObject(Handle<ObjectTemplateInfo> data, |
570 bool* exc) { | 598 bool* exc) { |
571 if (data->property_list()->IsUndefined() && | 599 if (data->property_list()->IsUndefined() && |
572 !data->constructor()->IsUndefined()) { | 600 !data->constructor()->IsUndefined()) { |
573 // Initialization to make gcc happy. | 601 // Initialization to make gcc happy. |
574 Object* result = NULL; | 602 Object* result = NULL; |
575 { | 603 { |
576 HandleScope scope; | 604 HandleScope scope; |
577 Handle<FunctionTemplateInfo> cons_template = | 605 Handle<FunctionTemplateInfo> cons_template = |
578 Handle<FunctionTemplateInfo>( | 606 Handle<FunctionTemplateInfo>( |
579 FunctionTemplateInfo::cast(data->constructor())); | 607 FunctionTemplateInfo::cast(data->constructor())); |
580 Handle<JSFunction> cons = InstantiateFunction(cons_template, exc); | 608 Handle<JSFunction> cons = InstantiateFunction(cons_template, exc); |
581 if (*exc) return Handle<JSObject>::null(); | 609 if (*exc) return Handle<JSObject>::null(); |
582 Handle<Object> value = New(cons, 0, NULL, exc); | 610 Handle<Object> value = New(cons, 0, NULL, exc); |
583 if (*exc) return Handle<JSObject>::null(); | 611 if (*exc) return Handle<JSObject>::null(); |
584 result = *value; | 612 result = *value; |
585 } | 613 } |
586 ASSERT(!*exc); | 614 ASSERT(!*exc); |
587 return Handle<JSObject>(JSObject::cast(result)); | 615 return Handle<JSObject>(JSObject::cast(result)); |
588 } else { | 616 } else { |
589 Object** args[1] = { Handle<Object>::cast(data).location() }; | 617 Object** args[1] = { Handle<Object>::cast(data).location() }; |
590 Handle<Object> result = | 618 Handle<Object> result = |
591 Call(Top::instantiate_fun(), Top::builtins(), 1, args, exc); | 619 Call(Isolate::Current()->instantiate_fun(), |
| 620 Isolate::Current()->js_builtins_object(), 1, args, exc); |
592 if (*exc) return Handle<JSObject>::null(); | 621 if (*exc) return Handle<JSObject>::null(); |
593 return Handle<JSObject>::cast(result); | 622 return Handle<JSObject>::cast(result); |
594 } | 623 } |
595 } | 624 } |
596 | 625 |
597 | 626 |
598 void Execution::ConfigureInstance(Handle<Object> instance, | 627 void Execution::ConfigureInstance(Handle<Object> instance, |
599 Handle<Object> instance_template, | 628 Handle<Object> instance_template, |
600 bool* exc) { | 629 bool* exc) { |
601 Object** args[2] = { instance.location(), instance_template.location() }; | 630 Object** args[2] = { instance.location(), instance_template.location() }; |
602 Execution::Call(Top::configure_instance_fun(), Top::builtins(), 2, args, exc); | 631 Execution::Call(Isolate::Current()->configure_instance_fun(), |
| 632 Isolate::Current()->js_builtins_object(), 2, args, exc); |
603 } | 633 } |
604 | 634 |
605 | 635 |
606 Handle<String> Execution::GetStackTraceLine(Handle<Object> recv, | 636 Handle<String> Execution::GetStackTraceLine(Handle<Object> recv, |
607 Handle<JSFunction> fun, | 637 Handle<JSFunction> fun, |
608 Handle<Object> pos, | 638 Handle<Object> pos, |
609 Handle<Object> is_global) { | 639 Handle<Object> is_global) { |
610 const int argc = 4; | 640 const int argc = 4; |
611 Object** args[argc] = { recv.location(), | 641 Object** args[argc] = { recv.location(), |
612 Handle<Object>::cast(fun).location(), | 642 Handle<Object>::cast(fun).location(), |
613 pos.location(), | 643 pos.location(), |
614 is_global.location() }; | 644 is_global.location() }; |
615 bool caught_exception = false; | 645 bool caught_exception = false; |
616 Handle<Object> result = TryCall(Top::get_stack_trace_line_fun(), | 646 Handle<Object> result = |
617 Top::builtins(), argc, args, | 647 TryCall(Isolate::Current()->get_stack_trace_line_fun(), |
618 &caught_exception); | 648 Isolate::Current()->js_builtins_object(), argc, args, |
619 if (caught_exception || !result->IsString()) return Factory::empty_symbol(); | 649 &caught_exception); |
| 650 if (caught_exception || !result->IsString()) return FACTORY->empty_symbol(); |
620 return Handle<String>::cast(result); | 651 return Handle<String>::cast(result); |
621 } | 652 } |
622 | 653 |
623 | 654 |
624 static Object* RuntimePreempt() { | 655 static Object* RuntimePreempt() { |
| 656 Isolate* isolate = Isolate::Current(); |
| 657 |
625 // Clear the preempt request flag. | 658 // Clear the preempt request flag. |
626 StackGuard::Continue(PREEMPT); | 659 isolate->stack_guard()->Continue(PREEMPT); |
627 | 660 |
628 ContextSwitcher::PreemptionReceived(); | 661 ContextSwitcher::PreemptionReceived(); |
629 | 662 |
630 #ifdef ENABLE_DEBUGGER_SUPPORT | 663 #ifdef ENABLE_DEBUGGER_SUPPORT |
631 if (Debug::InDebugger()) { | 664 if (isolate->debug()->InDebugger()) { |
632 // If currently in the debugger don't do any actual preemption but record | 665 // If currently in the debugger don't do any actual preemption but record |
633 // that preemption occoured while in the debugger. | 666 // that preemption occoured while in the debugger. |
634 Debug::PreemptionWhileInDebugger(); | 667 isolate->debug()->PreemptionWhileInDebugger(); |
635 } else { | 668 } else { |
636 // Perform preemption. | 669 // Perform preemption. |
637 v8::Unlocker unlocker; | 670 v8::Unlocker unlocker; |
638 Thread::YieldCPU(); | 671 Thread::YieldCPU(); |
639 } | 672 } |
640 #else | 673 #else |
641 // Perform preemption. | 674 { // NOLINT |
642 v8::Unlocker unlocker; | 675 // Perform preemption. |
643 Thread::YieldCPU(); | 676 v8::Unlocker unlocker; |
| 677 Thread::YieldCPU(); |
| 678 } |
644 #endif | 679 #endif |
645 | 680 |
646 return Heap::undefined_value(); | 681 return isolate->heap()->undefined_value(); |
647 } | 682 } |
648 | 683 |
649 | 684 |
650 #ifdef ENABLE_DEBUGGER_SUPPORT | 685 #ifdef ENABLE_DEBUGGER_SUPPORT |
651 Object* Execution::DebugBreakHelper() { | 686 Object* Execution::DebugBreakHelper() { |
| 687 Isolate* isolate = Isolate::Current(); |
| 688 |
652 // Just continue if breaks are disabled. | 689 // Just continue if breaks are disabled. |
653 if (Debug::disable_break()) { | 690 if (isolate->debug()->disable_break()) { |
654 return Heap::undefined_value(); | 691 return isolate->heap()->undefined_value(); |
655 } | 692 } |
656 | 693 |
657 // Ignore debug break during bootstrapping. | 694 // Ignore debug break during bootstrapping. |
658 if (Bootstrapper::IsActive()) { | 695 if (isolate->bootstrapper()->IsActive()) { |
659 return Heap::undefined_value(); | 696 return isolate->heap()->undefined_value(); |
660 } | 697 } |
661 | 698 |
662 { | 699 { |
663 JavaScriptFrameIterator it; | 700 JavaScriptFrameIterator it; |
664 ASSERT(!it.done()); | 701 ASSERT(!it.done()); |
665 Object* fun = it.frame()->function(); | 702 Object* fun = it.frame()->function(); |
666 if (fun && fun->IsJSFunction()) { | 703 if (fun && fun->IsJSFunction()) { |
667 // Don't stop in builtin functions. | 704 // Don't stop in builtin functions. |
668 if (JSFunction::cast(fun)->IsBuiltin()) { | 705 if (JSFunction::cast(fun)->IsBuiltin()) { |
669 return Heap::undefined_value(); | 706 return isolate->heap()->undefined_value(); |
670 } | 707 } |
671 GlobalObject* global = JSFunction::cast(fun)->context()->global(); | 708 GlobalObject* global = JSFunction::cast(fun)->context()->global(); |
672 // Don't stop in debugger functions. | 709 // Don't stop in debugger functions. |
673 if (Debug::IsDebugGlobal(global)) { | 710 if (isolate->debug()->IsDebugGlobal(global)) { |
674 return Heap::undefined_value(); | 711 return isolate->heap()->undefined_value(); |
675 } | 712 } |
676 } | 713 } |
677 } | 714 } |
678 | 715 |
679 // Collect the break state before clearing the flags. | 716 // Collect the break state before clearing the flags. |
680 bool debug_command_only = | 717 bool debug_command_only = |
681 StackGuard::IsDebugCommand() && !StackGuard::IsDebugBreak(); | 718 isolate->stack_guard()->IsDebugCommand() && |
| 719 !isolate->stack_guard()->IsDebugBreak(); |
682 | 720 |
683 // Clear the debug break request flag. | 721 // Clear the debug break request flag. |
684 StackGuard::Continue(DEBUGBREAK); | 722 isolate->stack_guard()->Continue(DEBUGBREAK); |
685 | 723 |
686 ProcessDebugMesssages(debug_command_only); | 724 ProcessDebugMesssages(debug_command_only); |
687 | 725 |
688 // Return to continue execution. | 726 // Return to continue execution. |
689 return Heap::undefined_value(); | 727 return isolate->heap()->undefined_value(); |
690 } | 728 } |
691 | 729 |
692 void Execution::ProcessDebugMesssages(bool debug_command_only) { | 730 void Execution::ProcessDebugMesssages(bool debug_command_only) { |
693 // Clear the debug command request flag. | 731 // Clear the debug command request flag. |
694 StackGuard::Continue(DEBUGCOMMAND); | 732 Isolate::Current()->stack_guard()->Continue(DEBUGCOMMAND); |
695 | 733 |
696 HandleScope scope; | 734 HandleScope scope; |
697 // Enter the debugger. Just continue if we fail to enter the debugger. | 735 // Enter the debugger. Just continue if we fail to enter the debugger. |
698 EnterDebugger debugger; | 736 EnterDebugger debugger; |
699 if (debugger.FailedToEnter()) { | 737 if (debugger.FailedToEnter()) { |
700 return; | 738 return; |
701 } | 739 } |
702 | 740 |
703 // Notify the debug event listeners. Indicate auto continue if the break was | 741 // Notify the debug event listeners. Indicate auto continue if the break was |
704 // a debug command break. | 742 // a debug command break. |
705 Debugger::OnDebugBreak(Factory::undefined_value(), debug_command_only); | 743 Isolate::Current()->debugger()->OnDebugBreak(FACTORY->undefined_value(), |
| 744 debug_command_only); |
706 } | 745 } |
707 | 746 |
708 | 747 |
709 #endif | 748 #endif |
710 | 749 |
711 MaybeObject* Execution::HandleStackGuardInterrupt() { | 750 MaybeObject* Execution::HandleStackGuardInterrupt() { |
712 Counters::stack_interrupts.Increment(); | 751 Isolate* isolate = Isolate::Current(); |
713 if (StackGuard::IsRuntimeProfilerTick()) { | 752 StackGuard* stack_guard = isolate->stack_guard(); |
714 Counters::runtime_profiler_ticks.Increment(); | 753 isolate->counters()->stack_interrupts()->Increment(); |
715 StackGuard::Continue(RUNTIME_PROFILER_TICK); | 754 if (stack_guard->IsRuntimeProfilerTick()) { |
716 RuntimeProfiler::OptimizeNow(); | 755 isolate->counters()->runtime_profiler_ticks()->Increment(); |
| 756 stack_guard->Continue(RUNTIME_PROFILER_TICK); |
| 757 isolate->runtime_profiler()->OptimizeNow(); |
717 } | 758 } |
718 #ifdef ENABLE_DEBUGGER_SUPPORT | 759 #ifdef ENABLE_DEBUGGER_SUPPORT |
719 if (StackGuard::IsDebugBreak() || StackGuard::IsDebugCommand()) { | 760 if (stack_guard->IsDebugBreak() || stack_guard->IsDebugCommand()) { |
720 DebugBreakHelper(); | 761 DebugBreakHelper(); |
721 } | 762 } |
722 #endif | 763 #endif |
723 if (StackGuard::IsPreempted()) RuntimePreempt(); | 764 if (stack_guard->IsPreempted()) RuntimePreempt(); |
724 if (StackGuard::IsTerminateExecution()) { | 765 if (stack_guard->IsTerminateExecution()) { |
725 StackGuard::Continue(TERMINATE); | 766 stack_guard->Continue(TERMINATE); |
726 return Top::TerminateExecution(); | 767 return isolate->TerminateExecution(); |
727 } | 768 } |
728 if (StackGuard::IsInterrupted()) { | 769 if (stack_guard->IsInterrupted()) { |
729 StackGuard::Continue(INTERRUPT); | 770 stack_guard->Continue(INTERRUPT); |
730 return Top::StackOverflow(); | 771 return isolate->StackOverflow(); |
731 } | 772 } |
732 return Heap::undefined_value(); | 773 return isolate->heap()->undefined_value(); |
733 } | 774 } |
734 | 775 |
735 } } // namespace v8::internal | 776 } } // namespace v8::internal |
OLD | NEW |