| 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/native_entry.h" | 5 #include "vm/native_entry.h" |
| 6 | 6 |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 | 8 |
| 9 #include "vm/dart_api_impl.h" | 9 #include "vm/dart_api_impl.h" |
| 10 #include "vm/dart_api_state.h" | 10 #include "vm/dart_api_state.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 NativeFunction NativeEntry::ResolveNative(const Library& library, | 23 NativeFunction NativeEntry::ResolveNative(const Library& library, |
| 24 const String& function_name, | 24 const String& function_name, |
| 25 int number_of_arguments, | 25 int number_of_arguments, |
| 26 bool* auto_setup_scope) { | 26 bool* auto_setup_scope) { |
| 27 // Now resolve the native function to the corresponding native entrypoint. | 27 // Now resolve the native function to the corresponding native entrypoint. |
| 28 if (library.native_entry_resolver() == 0) { | 28 if (library.native_entry_resolver() == 0) { |
| 29 // Native methods are not allowed in the library to which this | 29 // Native methods are not allowed in the library to which this |
| 30 // class belongs in. | 30 // class belongs in. |
| 31 return NULL; | 31 return NULL; |
| 32 } | 32 } |
| 33 Isolate* isolate = Isolate::Current(); | |
| 34 VmToNativeTimerScope timer(isolate); | |
| 35 Dart_EnterScope(); // Enter a new Dart API scope as we invoke API entries. | 33 Dart_EnterScope(); // Enter a new Dart API scope as we invoke API entries. |
| 36 Dart_NativeEntryResolver resolver = library.native_entry_resolver(); | 34 Dart_NativeEntryResolver resolver = library.native_entry_resolver(); |
| 37 Dart_NativeFunction native_function = | 35 Dart_NativeFunction native_function = |
| 38 resolver(Api::NewHandle(isolate, function_name.raw()), | 36 resolver(Api::NewHandle(Isolate::Current(), function_name.raw()), |
| 39 number_of_arguments, auto_setup_scope); | 37 number_of_arguments, auto_setup_scope); |
| 40 Dart_ExitScope(); // Exit the Dart API scope. | 38 Dart_ExitScope(); // Exit the Dart API scope. |
| 41 return reinterpret_cast<NativeFunction>(native_function); | 39 return reinterpret_cast<NativeFunction>(native_function); |
| 42 } | 40 } |
| 43 | 41 |
| 44 | 42 |
| 45 const ExternalLabel& NativeEntry::NativeCallWrapperLabel() { | 43 const ExternalLabel& NativeEntry::NativeCallWrapperLabel() { |
| 46 return native_call_label; | 44 return native_call_label; |
| 47 } | 45 } |
| 48 | 46 |
| 49 | 47 |
| 50 void NativeEntry::NativeCallWrapper(Dart_NativeArguments args, | 48 void NativeEntry::NativeCallWrapper(Dart_NativeArguments args, |
| 51 Dart_NativeFunction func) { | 49 Dart_NativeFunction func) { |
| 52 CHECK_STACK_ALIGNMENT; | 50 CHECK_STACK_ALIGNMENT; |
| 53 VERIFY_ON_TRANSITION; | 51 VERIFY_ON_TRANSITION; |
| 54 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 52 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 55 Isolate* isolate = arguments->isolate(); | 53 Isolate* isolate = arguments->isolate(); |
| 56 DartToVmTimerScope timer(isolate); | |
| 57 ApiState* state = isolate->api_state(); | 54 ApiState* state = isolate->api_state(); |
| 58 ASSERT(state != NULL); | 55 ASSERT(state != NULL); |
| 59 ApiLocalScope* current_top_scope = state->top_scope(); | 56 ApiLocalScope* current_top_scope = state->top_scope(); |
| 60 ApiLocalScope* scope = state->reusable_scope(); | 57 ApiLocalScope* scope = state->reusable_scope(); |
| 61 TRACE_NATIVE_CALL("0x%" Px "", reinterpret_cast<uintptr_t>(func)); | 58 TRACE_NATIVE_CALL("0x%" Px "", reinterpret_cast<uintptr_t>(func)); |
| 62 if (scope == NULL) { | 59 if (scope == NULL) { |
| 63 scope = new ApiLocalScope(current_top_scope, | 60 scope = new ApiLocalScope(current_top_scope, |
| 64 isolate->top_exit_frame_info()); | 61 isolate->top_exit_frame_info()); |
| 65 ASSERT(scope != NULL); | 62 ASSERT(scope != NULL); |
| 66 } else { | 63 } else { |
| 67 scope->Reinit(isolate, | 64 scope->Reinit(isolate, |
| 68 current_top_scope, | 65 current_top_scope, |
| 69 isolate->top_exit_frame_info()); | 66 isolate->top_exit_frame_info()); |
| 70 state->set_reusable_scope(NULL); | 67 state->set_reusable_scope(NULL); |
| 71 } | 68 } |
| 72 state->set_top_scope(scope); // New scope is now the top scope. | 69 state->set_top_scope(scope); // New scope is now the top scope. |
| 73 | 70 |
| 74 { | 71 func(args); |
| 75 VmToNativeTimerScope native_timer(isolate); | |
| 76 func(args); | |
| 77 } | |
| 78 | 72 |
| 79 ASSERT(current_top_scope == scope->previous()); | 73 ASSERT(current_top_scope == scope->previous()); |
| 80 state->set_top_scope(current_top_scope); // Reset top scope to previous. | 74 state->set_top_scope(current_top_scope); // Reset top scope to previous. |
| 81 if (state->reusable_scope() == NULL) { | 75 if (state->reusable_scope() == NULL) { |
| 82 scope->Reset(isolate); // Reset the old scope which we just exited. | 76 scope->Reset(isolate); // Reset the old scope which we just exited. |
| 83 state->set_reusable_scope(scope); | 77 state->set_reusable_scope(scope); |
| 84 } else { | 78 } else { |
| 85 ASSERT(state->reusable_scope() != scope); | 79 ASSERT(state->reusable_scope() != scope); |
| 86 delete scope; | 80 delete scope; |
| 87 } | 81 } |
| 88 DEOPTIMIZE_ALOT; | 82 DEOPTIMIZE_ALOT; |
| 89 VERIFY_ON_TRANSITION; | 83 VERIFY_ON_TRANSITION; |
| 90 } | 84 } |
| 91 | 85 |
| 92 } // namespace dart | 86 } // namespace dart |
| OLD | NEW |