| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/dart_entry.h" | 5 #include "vm/dart_entry.h" |
| 6 | 6 |
| 7 #include "vm/class_finalizer.h" | 7 #include "vm/class_finalizer.h" |
| 8 #include "vm/code_generator.h" | 8 #include "vm/code_generator.h" |
| 9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
| 10 #include "vm/debugger.h" | 10 #include "vm/debugger.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 const Array& arguments) { | 26 const Array& arguments) { |
| 27 ASSERT(Thread::Current()->IsMutatorThread()); | 27 ASSERT(Thread::Current()->IsMutatorThread()); |
| 28 const Array& arguments_descriptor = | 28 const Array& arguments_descriptor = |
| 29 Array::Handle(ArgumentsDescriptor::New(arguments.Length())); | 29 Array::Handle(ArgumentsDescriptor::New(arguments.Length())); |
| 30 return InvokeFunction(function, arguments, arguments_descriptor); | 30 return InvokeFunction(function, arguments, arguments_descriptor); |
| 31 } | 31 } |
| 32 | 32 |
| 33 | 33 |
| 34 class ScopedIsolateStackLimits : public ValueObject { | 34 class ScopedIsolateStackLimits : public ValueObject { |
| 35 public: | 35 public: |
| 36 explicit ScopedIsolateStackLimits(Isolate* isolate) | 36 explicit ScopedIsolateStackLimits(Thread* thread) |
| 37 : isolate_(isolate), stack_base_(Isolate::GetCurrentStackPointer()) { | 37 : thread_(thread), saved_stack_limit_(0) { |
| 38 ASSERT(isolate_ != NULL); | 38 ASSERT(thread != NULL); |
| 39 ASSERT(isolate_ == Isolate::Current()); | 39 // Set the thread's stack_base based on the current |
| 40 if (stack_base_ >= isolate_->stack_base()) { | 40 // stack pointer, we keep refining this value as we |
| 41 isolate_->SetStackLimitFromStackBase(stack_base_); | 41 // see higher stack pointers (Note: we assume the stack |
| 42 // grows from high to low addresses). |
| 43 OSThread* os_thread = thread->os_thread(); |
| 44 ASSERT(os_thread != NULL); |
| 45 uword current_sp = Isolate::GetCurrentStackPointer(); |
| 46 if (current_sp > os_thread->stack_base()) { |
| 47 os_thread->set_stack_base(current_sp); |
| 42 } | 48 } |
| 49 // Save the Isolate's current stack limit and adjust the stack |
| 50 // limit based on the thread's stack_base. |
| 51 Isolate* isolate = thread->isolate(); |
| 52 ASSERT(isolate == Isolate::Current()); |
| 53 saved_stack_limit_ = isolate->saved_stack_limit(); |
| 54 isolate->SetStackLimitFromStackBase(os_thread->stack_base()); |
| 43 } | 55 } |
| 44 | 56 |
| 45 ~ScopedIsolateStackLimits() { | 57 ~ScopedIsolateStackLimits() { |
| 46 ASSERT(isolate_ == Isolate::Current()); | 58 Isolate* isolate = thread_->isolate(); |
| 47 if (isolate_->stack_base() == stack_base_) { | 59 ASSERT(isolate == Isolate::Current()); |
| 48 // Bottomed out. | 60 // Since we started with a stack limit of 0 we should be getting back |
| 49 isolate_->ClearStackLimit(); | 61 // to a stack limit of 0 when all nested invocations are done and |
| 50 } | 62 // we have bottomed out. |
| 63 isolate->SetStackLimit(saved_stack_limit_); |
| 51 } | 64 } |
| 52 | 65 |
| 53 private: | 66 private: |
| 54 Isolate* isolate_; | 67 Thread* thread_; |
| 55 uword stack_base_; | 68 uword saved_stack_limit_; |
| 56 }; | 69 }; |
| 57 | 70 |
| 58 | 71 |
| 59 // Clears/restores Thread::long_jump_base on construction/destruction. | 72 // Clears/restores Thread::long_jump_base on construction/destruction. |
| 60 // Ensures that we do not attempt to long jump across Dart frames. | 73 // Ensures that we do not attempt to long jump across Dart frames. |
| 61 class SuspendLongJumpScope : public StackResource { | 74 class SuspendLongJumpScope : public StackResource { |
| 62 public: | 75 public: |
| 63 explicit SuspendLongJumpScope(Thread* thread) | 76 explicit SuspendLongJumpScope(Thread* thread) |
| 64 : StackResource(thread), | 77 : StackResource(thread), |
| 65 saved_long_jump_base_(thread->long_jump_base()) { | 78 saved_long_jump_base_(thread->long_jump_base()) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 77 | 90 |
| 78 | 91 |
| 79 RawObject* DartEntry::InvokeFunction(const Function& function, | 92 RawObject* DartEntry::InvokeFunction(const Function& function, |
| 80 const Array& arguments, | 93 const Array& arguments, |
| 81 const Array& arguments_descriptor) { | 94 const Array& arguments_descriptor) { |
| 82 // Get the entrypoint corresponding to the function specified, this | 95 // Get the entrypoint corresponding to the function specified, this |
| 83 // will result in a compilation of the function if it is not already | 96 // will result in a compilation of the function if it is not already |
| 84 // compiled. | 97 // compiled. |
| 85 Thread* thread = Thread::Current(); | 98 Thread* thread = Thread::Current(); |
| 86 Zone* zone = thread->zone(); | 99 Zone* zone = thread->zone(); |
| 87 Isolate* isolate = thread->isolate(); | |
| 88 ASSERT(thread->IsMutatorThread()); | 100 ASSERT(thread->IsMutatorThread()); |
| 89 if (!function.HasCode()) { | 101 if (!function.HasCode()) { |
| 90 const Error& error = Error::Handle( | 102 const Error& error = Error::Handle( |
| 91 zone, Compiler::CompileFunction(thread, function)); | 103 zone, Compiler::CompileFunction(thread, function)); |
| 92 if (!error.IsNull()) { | 104 if (!error.IsNull()) { |
| 93 return error.raw(); | 105 return error.raw(); |
| 94 } | 106 } |
| 95 } | 107 } |
| 96 // Now Call the invoke stub which will invoke the dart function. | 108 // Now Call the invoke stub which will invoke the dart function. |
| 97 invokestub entrypoint = reinterpret_cast<invokestub>( | 109 invokestub entrypoint = reinterpret_cast<invokestub>( |
| 98 StubCode::InvokeDartCode_entry()->EntryPoint()); | 110 StubCode::InvokeDartCode_entry()->EntryPoint()); |
| 99 const Code& code = Code::Handle(zone, function.CurrentCode()); | 111 const Code& code = Code::Handle(zone, function.CurrentCode()); |
| 100 ASSERT(!code.IsNull()); | 112 ASSERT(!code.IsNull()); |
| 101 ASSERT(thread->no_callback_scope_depth() == 0); | 113 ASSERT(thread->no_callback_scope_depth() == 0); |
| 102 ScopedIsolateStackLimits stack_limit(isolate); | 114 ScopedIsolateStackLimits stack_limit(thread); |
| 103 SuspendLongJumpScope suspend_long_jump_scope(thread); | 115 SuspendLongJumpScope suspend_long_jump_scope(thread); |
| 104 #if defined(USING_SIMULATOR) | 116 #if defined(USING_SIMULATOR) |
| 105 return bit_copy<RawObject*, int64_t>(Simulator::Current()->Call( | 117 return bit_copy<RawObject*, int64_t>(Simulator::Current()->Call( |
| 106 reinterpret_cast<intptr_t>(entrypoint), | 118 reinterpret_cast<intptr_t>(entrypoint), |
| 107 reinterpret_cast<intptr_t>(&code), | 119 reinterpret_cast<intptr_t>(&code), |
| 108 reinterpret_cast<intptr_t>(&arguments_descriptor), | 120 reinterpret_cast<intptr_t>(&arguments_descriptor), |
| 109 reinterpret_cast<intptr_t>(&arguments), | 121 reinterpret_cast<intptr_t>(&arguments), |
| 110 reinterpret_cast<intptr_t>(thread))); | 122 reinterpret_cast<intptr_t>(thread))); |
| 111 #else | 123 #else |
| 112 return entrypoint(code, | 124 return entrypoint(code, |
| (...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 const Array& args = Array::Handle(Array::New(kNumArguments)); | 592 const Array& args = Array::Handle(Array::New(kNumArguments)); |
| 581 args.SetAt(0, map); | 593 args.SetAt(0, map); |
| 582 args.SetAt(1, key); | 594 args.SetAt(1, key); |
| 583 args.SetAt(2, value); | 595 args.SetAt(2, value); |
| 584 const Object& result = Object::Handle(DartEntry::InvokeFunction(function, | 596 const Object& result = Object::Handle(DartEntry::InvokeFunction(function, |
| 585 args)); | 597 args)); |
| 586 return result.raw(); | 598 return result.raw(); |
| 587 } | 599 } |
| 588 | 600 |
| 589 } // namespace dart | 601 } // namespace dart |
| OLD | NEW |