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

Side by Side Diff: runtime/vm/native_entry.cc

Issue 22303002: Auto create ApiLocalScope before calling native functions, this ensures that (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 4 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 | « runtime/vm/native_entry.h ('k') | runtime/vm/native_entry_test.cc » ('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 (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 11
11 namespace dart { 12 namespace dart {
12 13
13 DEFINE_FLAG(bool, trace_natives, false, "Trace invocation of natives"); 14 DEFINE_FLAG(bool, trace_natives, false, "Trace invocation of natives");
14 15
15 NativeFunction NativeEntry::ResolveNative(const Class& cls, 16
17 static ExternalLabel native_call_label(
18 "native_function_call",
19 reinterpret_cast<uword>(&NativeEntry::NativeCallWrapper));
20
21
22 NativeFunction NativeEntry::ResolveNative(const Library& library,
16 const String& function_name, 23 const String& function_name,
17 int number_of_arguments) { 24 int number_of_arguments) {
18 // Now resolve the native function to the corresponding native entrypoint. 25 // Now resolve the native function to the corresponding native entrypoint.
19 const Library& library = Library::Handle(cls.library());
20 if (library.native_entry_resolver() == 0) { 26 if (library.native_entry_resolver() == 0) {
21 // Native methods are not allowed in the library to which this 27 // Native methods are not allowed in the library to which this
22 // class belongs in. 28 // class belongs in.
23 return NULL; 29 return NULL;
24 } 30 }
25 Dart_EnterScope(); // Enter a new Dart API scope as we invoke API entries. 31 Dart_EnterScope(); // Enter a new Dart API scope as we invoke API entries.
26 Dart_NativeEntryResolver resolver = library.native_entry_resolver(); 32 Dart_NativeEntryResolver resolver = library.native_entry_resolver();
27 Dart_NativeFunction native_function = 33 Dart_NativeFunction native_function =
28 resolver(Api::NewHandle(Isolate::Current(), function_name.raw()), 34 resolver(Api::NewHandle(Isolate::Current(), function_name.raw()),
29 number_of_arguments); 35 number_of_arguments);
30 Dart_ExitScope(); // Exit the Dart API scope. 36 Dart_ExitScope(); // Exit the Dart API scope.
31 return reinterpret_cast<NativeFunction>(native_function); 37 return reinterpret_cast<NativeFunction>(native_function);
32 } 38 }
33 39
40
41 const ExternalLabel& NativeEntry::NativeCallWrapperLabel() {
42 return native_call_label;
43 }
44
45
46 void NativeEntry::NativeCallWrapper(Dart_NativeArguments args,
47 Dart_NativeFunction func) {
48 CHECK_STACK_ALIGNMENT;
49 VERIFY_ON_TRANSITION;
50 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
51 Isolate* isolate = arguments->isolate();
52 ApiState* state = isolate->api_state();
53 ASSERT(state != NULL);
54 ApiLocalScope* current_top_scope = state->top_scope();
55 ApiLocalScope* scope = state->reusable_scope();
56 if (scope == NULL) {
57 scope = new ApiLocalScope(current_top_scope,
58 isolate->top_exit_frame_info());
59 ASSERT(scope != NULL);
60 } else {
61 scope->Reinit(isolate,
62 current_top_scope,
63 isolate->top_exit_frame_info());
64 state->set_reusable_scope(NULL);
65 }
66 state->set_top_scope(scope); // New scope is now the top scope.
67
68 func(args);
69
70 ASSERT(current_top_scope == scope->previous());
71 state->set_top_scope(current_top_scope); // Reset top scope to previous.
72 if (state->reusable_scope() == NULL) {
73 scope->Reset(isolate); // Reset the old scope which we just exited.
74 state->set_reusable_scope(scope);
75 } else {
76 ASSERT(state->reusable_scope() != scope);
77 delete scope;
78 }
79 DEOPTIMIZE_ALOT;
80 VERIFY_ON_TRANSITION;
81 }
82
34 } // namespace dart 83 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/native_entry.h ('k') | runtime/vm/native_entry_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698