| 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" |
| 11 | 11 |
| 12 namespace dart { | 12 namespace dart { |
| 13 | 13 |
| 14 DEFINE_FLAG(bool, trace_natives, false, "Trace invocation of natives"); | 14 DEFINE_FLAG(bool, trace_natives, false, |
| 15 "Trace invocation of natives (debug mode only)"); |
| 15 | 16 |
| 16 | 17 |
| 17 static ExternalLabel native_call_label( | 18 static ExternalLabel native_call_label( |
| 18 "native_function_call", | 19 "native_function_call", |
| 19 reinterpret_cast<uword>(&NativeEntry::NativeCallWrapper)); | 20 reinterpret_cast<uword>(&NativeEntry::NativeCallWrapper)); |
| 20 | 21 |
| 21 | 22 |
| 22 NativeFunction NativeEntry::ResolveNative(const Library& library, | 23 NativeFunction NativeEntry::ResolveNative(const Library& library, |
| 23 const String& function_name, | 24 const String& function_name, |
| 24 int number_of_arguments) { | 25 int number_of_arguments) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 46 void NativeEntry::NativeCallWrapper(Dart_NativeArguments args, | 47 void NativeEntry::NativeCallWrapper(Dart_NativeArguments args, |
| 47 Dart_NativeFunction func) { | 48 Dart_NativeFunction func) { |
| 48 CHECK_STACK_ALIGNMENT; | 49 CHECK_STACK_ALIGNMENT; |
| 49 VERIFY_ON_TRANSITION; | 50 VERIFY_ON_TRANSITION; |
| 50 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 51 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 51 Isolate* isolate = arguments->isolate(); | 52 Isolate* isolate = arguments->isolate(); |
| 52 ApiState* state = isolate->api_state(); | 53 ApiState* state = isolate->api_state(); |
| 53 ASSERT(state != NULL); | 54 ASSERT(state != NULL); |
| 54 ApiLocalScope* current_top_scope = state->top_scope(); | 55 ApiLocalScope* current_top_scope = state->top_scope(); |
| 55 ApiLocalScope* scope = state->reusable_scope(); | 56 ApiLocalScope* scope = state->reusable_scope(); |
| 57 TRACE_NATIVE_CALL("0x%" Px "", reinterpret_cast<uintptr_t>(func)); |
| 56 if (scope == NULL) { | 58 if (scope == NULL) { |
| 57 scope = new ApiLocalScope(current_top_scope, | 59 scope = new ApiLocalScope(current_top_scope, |
| 58 isolate->top_exit_frame_info()); | 60 isolate->top_exit_frame_info()); |
| 59 ASSERT(scope != NULL); | 61 ASSERT(scope != NULL); |
| 60 } else { | 62 } else { |
| 61 scope->Reinit(isolate, | 63 scope->Reinit(isolate, |
| 62 current_top_scope, | 64 current_top_scope, |
| 63 isolate->top_exit_frame_info()); | 65 isolate->top_exit_frame_info()); |
| 64 state->set_reusable_scope(NULL); | 66 state->set_reusable_scope(NULL); |
| 65 } | 67 } |
| 66 state->set_top_scope(scope); // New scope is now the top scope. | 68 state->set_top_scope(scope); // New scope is now the top scope. |
| 67 | 69 |
| 68 func(args); | 70 func(args); |
| 69 | 71 |
| 70 ASSERT(current_top_scope == scope->previous()); | 72 ASSERT(current_top_scope == scope->previous()); |
| 71 state->set_top_scope(current_top_scope); // Reset top scope to previous. | 73 state->set_top_scope(current_top_scope); // Reset top scope to previous. |
| 72 if (state->reusable_scope() == NULL) { | 74 if (state->reusable_scope() == NULL) { |
| 73 scope->Reset(isolate); // Reset the old scope which we just exited. | 75 scope->Reset(isolate); // Reset the old scope which we just exited. |
| 74 state->set_reusable_scope(scope); | 76 state->set_reusable_scope(scope); |
| 75 } else { | 77 } else { |
| 76 ASSERT(state->reusable_scope() != scope); | 78 ASSERT(state->reusable_scope() != scope); |
| 77 delete scope; | 79 delete scope; |
| 78 } | 80 } |
| 79 DEOPTIMIZE_ALOT; | 81 DEOPTIMIZE_ALOT; |
| 80 VERIFY_ON_TRANSITION; | 82 VERIFY_ON_TRANSITION; |
| 81 } | 83 } |
| 82 | 84 |
| 83 } // namespace dart | 85 } // namespace dart |
| OLD | NEW |