Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1051)

Side by Side Diff: src/execution.cc

Issue 7060010: Merge bleeding edge into the GC branch up to 7948. The asserts (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/gc/
Patch Set: Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/execution.h ('k') | src/extensions/experimental/experimental.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 } 138 }
139 return Handle<Object>(); 139 return Handle<Object>();
140 } else { 140 } else {
141 isolate->clear_pending_message(); 141 isolate->clear_pending_message();
142 } 142 }
143 143
144 return Handle<Object>(value->ToObjectUnchecked(), isolate); 144 return Handle<Object>(value->ToObjectUnchecked(), isolate);
145 } 145 }
146 146
147 147
148 Handle<Object> Execution::Call(Handle<JSFunction> func, 148 Handle<Object> Execution::Call(Handle<Object> callable,
149 Handle<Object> receiver, 149 Handle<Object> receiver,
150 int argc, 150 int argc,
151 Object*** args, 151 Object*** args,
152 bool* pending_exception) { 152 bool* pending_exception) {
153 if (!callable->IsJSFunction()) {
154 callable = TryGetFunctionDelegate(callable, pending_exception);
155 if (*pending_exception) return callable;
156 }
157 Handle<JSFunction> func = Handle<JSFunction>::cast(callable);
153 return Invoke(false, func, receiver, argc, args, pending_exception); 158 return Invoke(false, func, receiver, argc, args, pending_exception);
154 } 159 }
155 160
156 161
157 Handle<Object> Execution::New(Handle<JSFunction> func, int argc, 162 Handle<Object> Execution::New(Handle<JSFunction> func, int argc,
158 Object*** args, bool* pending_exception) { 163 Object*** args, bool* pending_exception) {
159 return Invoke(true, func, Isolate::Current()->global(), argc, args, 164 return Invoke(true, func, Isolate::Current()->global(), argc, args,
160 pending_exception); 165 pending_exception);
161 } 166 }
162 167
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 if (object->IsHeapObject() && 275 if (object->IsHeapObject() &&
271 HeapObject::cast(*object)->map()->has_instance_call_handler()) { 276 HeapObject::cast(*object)->map()->has_instance_call_handler()) {
272 return Handle<JSFunction>( 277 return Handle<JSFunction>(
273 isolate->global_context()->call_as_constructor_delegate()); 278 isolate->global_context()->call_as_constructor_delegate());
274 } 279 }
275 280
276 return isolate->factory()->undefined_value(); 281 return isolate->factory()->undefined_value();
277 } 282 }
278 283
279 284
285 Handle<Object> Execution::TryGetConstructorDelegate(
286 Handle<Object> object,
287 bool* has_pending_exception) {
288 ASSERT(!object->IsJSFunction());
289 Isolate* isolate = Isolate::Current();
290
291 // If you return a function from here, it will be called when an
292 // attempt is made to call the given object as a constructor.
293
294 // Objects created through the API can have an instance-call handler
295 // that should be used when calling the object as a function.
296 if (object->IsHeapObject() &&
297 HeapObject::cast(*object)->map()->has_instance_call_handler()) {
298 return Handle<JSFunction>(
299 isolate->global_context()->call_as_constructor_delegate());
300 }
301
302 // If the Object doesn't have an instance-call handler we should
303 // throw a non-callable exception.
304 i::Handle<i::Object> error_obj = isolate->factory()->NewTypeError(
305 "called_non_callable", i::HandleVector<i::Object>(&object, 1));
306 isolate->Throw(*error_obj);
307 *has_pending_exception = true;
308
309 return isolate->factory()->undefined_value();
310 }
311
312
280 bool StackGuard::IsStackOverflow() { 313 bool StackGuard::IsStackOverflow() {
281 ExecutionAccess access(isolate_); 314 ExecutionAccess access(isolate_);
282 return (thread_local_.jslimit_ != kInterruptLimit && 315 return (thread_local_.jslimit_ != kInterruptLimit &&
283 thread_local_.climit_ != kInterruptLimit); 316 thread_local_.climit_ != kInterruptLimit);
284 } 317 }
285 318
286 319
287 void StackGuard::EnableInterrupts() { 320 void StackGuard::EnableInterrupts() {
288 ExecutionAccess access(isolate_); 321 ExecutionAccess access(isolate_);
289 if (has_pending_interrupts(access)) { 322 if (has_pending_interrupts(access)) {
290 set_interrupt_limits(access); 323 set_interrupt_limits(access);
291 } 324 }
292 } 325 }
293 326
294 327
295 void StackGuard::SetStackLimit(uintptr_t limit) { 328 void StackGuard::SetStackLimit(uintptr_t limit) {
296 ExecutionAccess access(isolate_); 329 ExecutionAccess access(isolate_);
297 // If the current limits are special (eg due to a pending interrupt) then 330 // If the current limits are special (eg due to a pending interrupt) then
298 // leave them alone. 331 // leave them alone.
299 uintptr_t jslimit = SimulatorStack::JsLimitFromCLimit(limit); 332 uintptr_t jslimit = SimulatorStack::JsLimitFromCLimit(isolate_, limit);
300 if (thread_local_.jslimit_ == thread_local_.real_jslimit_) { 333 if (thread_local_.jslimit_ == thread_local_.real_jslimit_) {
301 thread_local_.jslimit_ = jslimit; 334 thread_local_.jslimit_ = jslimit;
302 } 335 }
303 if (thread_local_.climit_ == thread_local_.real_climit_) { 336 if (thread_local_.climit_ == thread_local_.real_climit_) {
304 thread_local_.climit_ = limit; 337 thread_local_.climit_ = limit;
305 } 338 }
306 thread_local_.real_climit_ = limit; 339 thread_local_.real_climit_ = limit;
307 thread_local_.real_jslimit_ = jslimit; 340 thread_local_.real_jslimit_ = jslimit;
308 } 341 }
309 342
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 real_jslimit_ = kIllegalLimit; 494 real_jslimit_ = kIllegalLimit;
462 jslimit_ = kIllegalLimit; 495 jslimit_ = kIllegalLimit;
463 real_climit_ = kIllegalLimit; 496 real_climit_ = kIllegalLimit;
464 climit_ = kIllegalLimit; 497 climit_ = kIllegalLimit;
465 nesting_ = 0; 498 nesting_ = 0;
466 postpone_interrupts_nesting_ = 0; 499 postpone_interrupts_nesting_ = 0;
467 interrupt_flags_ = 0; 500 interrupt_flags_ = 0;
468 } 501 }
469 502
470 503
471 bool StackGuard::ThreadLocal::Initialize() { 504 bool StackGuard::ThreadLocal::Initialize(Isolate* isolate) {
472 bool should_set_stack_limits = false; 505 bool should_set_stack_limits = false;
473 if (real_climit_ == kIllegalLimit) { 506 if (real_climit_ == kIllegalLimit) {
474 // Takes the address of the limit variable in order to find out where 507 // Takes the address of the limit variable in order to find out where
475 // the top of stack is right now. 508 // the top of stack is right now.
476 const uintptr_t kLimitSize = FLAG_stack_size * KB; 509 const uintptr_t kLimitSize = FLAG_stack_size * KB;
477 uintptr_t limit = reinterpret_cast<uintptr_t>(&limit) - kLimitSize; 510 uintptr_t limit = reinterpret_cast<uintptr_t>(&limit) - kLimitSize;
478 ASSERT(reinterpret_cast<uintptr_t>(&limit) > kLimitSize); 511 ASSERT(reinterpret_cast<uintptr_t>(&limit) > kLimitSize);
479 real_jslimit_ = SimulatorStack::JsLimitFromCLimit(limit); 512 real_jslimit_ = SimulatorStack::JsLimitFromCLimit(isolate, limit);
480 jslimit_ = SimulatorStack::JsLimitFromCLimit(limit); 513 jslimit_ = SimulatorStack::JsLimitFromCLimit(isolate, limit);
481 real_climit_ = limit; 514 real_climit_ = limit;
482 climit_ = limit; 515 climit_ = limit;
483 should_set_stack_limits = true; 516 should_set_stack_limits = true;
484 } 517 }
485 nesting_ = 0; 518 nesting_ = 0;
486 postpone_interrupts_nesting_ = 0; 519 postpone_interrupts_nesting_ = 0;
487 interrupt_flags_ = 0; 520 interrupt_flags_ = 0;
488 return should_set_stack_limits; 521 return should_set_stack_limits;
489 } 522 }
490 523
491 524
492 void StackGuard::ClearThread(const ExecutionAccess& lock) { 525 void StackGuard::ClearThread(const ExecutionAccess& lock) {
493 thread_local_.Clear(); 526 thread_local_.Clear();
494 isolate_->heap()->SetStackLimits(); 527 isolate_->heap()->SetStackLimits();
495 } 528 }
496 529
497 530
498 void StackGuard::InitThread(const ExecutionAccess& lock) { 531 void StackGuard::InitThread(const ExecutionAccess& lock) {
499 if (thread_local_.Initialize()) isolate_->heap()->SetStackLimits(); 532 if (thread_local_.Initialize(isolate_)) isolate_->heap()->SetStackLimits();
500 uintptr_t stored_limit = 533 Isolate::PerIsolateThreadData* per_thread =
501 Isolate::CurrentPerIsolateThreadData()->stack_limit(); 534 isolate_->FindOrAllocatePerThreadDataForThisThread();
535 uintptr_t stored_limit = per_thread->stack_limit();
502 // You should hold the ExecutionAccess lock when you call this. 536 // You should hold the ExecutionAccess lock when you call this.
503 if (stored_limit != 0) { 537 if (stored_limit != 0) {
504 StackGuard::SetStackLimit(stored_limit); 538 StackGuard::SetStackLimit(stored_limit);
505 } 539 }
506 } 540 }
507 541
508 542
509 // --- C a l l s t o n a t i v e s --- 543 // --- C a l l s t o n a t i v e s ---
510 544
511 #define RETURN_NATIVE_CALL(name, argc, argv, has_pending_exception) \ 545 #define RETURN_NATIVE_CALL(name, argc, argv, has_pending_exception) \
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 748
715 ContextSwitcher::PreemptionReceived(); 749 ContextSwitcher::PreemptionReceived();
716 750
717 #ifdef ENABLE_DEBUGGER_SUPPORT 751 #ifdef ENABLE_DEBUGGER_SUPPORT
718 if (isolate->debug()->InDebugger()) { 752 if (isolate->debug()->InDebugger()) {
719 // If currently in the debugger don't do any actual preemption but record 753 // If currently in the debugger don't do any actual preemption but record
720 // that preemption occoured while in the debugger. 754 // that preemption occoured while in the debugger.
721 isolate->debug()->PreemptionWhileInDebugger(); 755 isolate->debug()->PreemptionWhileInDebugger();
722 } else { 756 } else {
723 // Perform preemption. 757 // Perform preemption.
724 v8::Unlocker unlocker; 758 v8::Unlocker unlocker(reinterpret_cast<v8::Isolate*>(isolate));
725 Thread::YieldCPU(); 759 Thread::YieldCPU();
726 } 760 }
727 #else 761 #else
728 { // NOLINT 762 { // NOLINT
729 // Perform preemption. 763 // Perform preemption.
730 v8::Unlocker unlocker; 764 v8::Unlocker unlocker(reinterpret_cast<v8::Isolate*>(isolate));
731 Thread::YieldCPU(); 765 Thread::YieldCPU();
732 } 766 }
733 #endif 767 #endif
734 768
735 return isolate->heap()->undefined_value(); 769 return isolate->heap()->undefined_value();
736 } 770 }
737 771
738 772
739 #ifdef ENABLE_DEBUGGER_SUPPORT 773 #ifdef ENABLE_DEBUGGER_SUPPORT
740 Object* Execution::DebugBreakHelper() { 774 Object* Execution::DebugBreakHelper() {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 return isolate->TerminateExecution(); 862 return isolate->TerminateExecution();
829 } 863 }
830 if (stack_guard->IsInterrupted()) { 864 if (stack_guard->IsInterrupted()) {
831 stack_guard->Continue(INTERRUPT); 865 stack_guard->Continue(INTERRUPT);
832 return isolate->StackOverflow(); 866 return isolate->StackOverflow();
833 } 867 }
834 return isolate->heap()->undefined_value(); 868 return isolate->heap()->undefined_value();
835 } 869 }
836 870
837 } } // namespace v8::internal 871 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/execution.h ('k') | src/extensions/experimental/experimental.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698