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

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

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_arguments.h ('k') | runtime/vm/native_entry.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 #ifndef VM_NATIVE_ENTRY_H_ 5 #ifndef VM_NATIVE_ENTRY_H_
6 #define VM_NATIVE_ENTRY_H_ 6 #define VM_NATIVE_ENTRY_H_
7 7
8 #include "vm/allocation.h" 8 #include "vm/allocation.h"
9 #include "vm/assembler.h" 9 #include "vm/assembler.h"
10 #include "vm/code_generator.h" 10 #include "vm/code_generator.h"
11 #include "vm/exceptions.h" 11 #include "vm/exceptions.h"
12 #include "vm/native_arguments.h" 12 #include "vm/native_arguments.h"
13 #include "vm/verifier.h" 13 #include "vm/verifier.h"
14 14
15 #include "include/dart_api.h" 15 #include "include/dart_api.h"
16 16
17 namespace dart { 17 namespace dart {
18 18
19 DECLARE_FLAG(bool, deoptimize_alot);
20 DECLARE_FLAG(bool, trace_natives);
21
22 // Forward declarations. 19 // Forward declarations.
23 class Class; 20 class Class;
24 class String; 21 class String;
25 22
26 typedef void (*NativeFunction)(NativeArguments* arguments); 23 typedef void (*NativeFunction)(NativeArguments* arguments);
27 24
28 25
29 #define NATIVE_ENTRY_FUNCTION(name) BootstrapNatives::DN_##name 26 #define NATIVE_ENTRY_FUNCTION(name) BootstrapNatives::DN_##name
30 27
31 #ifdef DEBUG 28 #ifdef DEBUG
32 #define SET_NATIVE_RETVAL(args, value) \ 29 #define SET_NATIVE_RETVAL(args, value) \
33 RawObject* retval = value; \ 30 RawObject* retval = value; \
34 ASSERT(retval->IsDartInstance()); \ 31 ASSERT(retval->IsDartInstance()); \
35 arguments->SetReturnUnsafe(retval); 32 arguments->SetReturnUnsafe(retval);
36 #else 33 #else
37 #define SET_NATIVE_RETVAL(arguments, value) \ 34 #define SET_NATIVE_RETVAL(arguments, value) \
38 arguments->SetReturnUnsafe(value); 35 arguments->SetReturnUnsafe(value);
39 #endif 36 #endif
40 37
41 #define DEFINE_NATIVE_ENTRY(name, argument_count) \ 38 #define DEFINE_NATIVE_ENTRY(name, argument_count) \
42 static RawObject* DN_Helper##name(Isolate* isolate, \ 39 static RawObject* DN_Helper##name(Isolate* isolate, \
43 NativeArguments* arguments); \ 40 NativeArguments* arguments); \
44 void NATIVE_ENTRY_FUNCTION(name)(Dart_NativeArguments args) { \ 41 void NATIVE_ENTRY_FUNCTION(name)(Dart_NativeArguments args) { \
45 CHECK_STACK_ALIGNMENT; \ 42 CHECK_STACK_ALIGNMENT; \
46 VERIFY_ON_TRANSITION; \ 43 VERIFY_ON_TRANSITION; \
47 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); \ 44 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); \
48 ASSERT(arguments->NativeArgCount() == argument_count); \ 45 ASSERT(arguments->NativeArgCount() == argument_count); \
49 if (FLAG_trace_natives) OS::Print("Calling native: %s\n", ""#name); \ 46 TRACE_NATIVES(""#name); \
50 { \ 47 { \
51 StackZone zone(arguments->isolate()); \ 48 StackZone zone(arguments->isolate()); \
52 HANDLESCOPE(arguments->isolate()); \
53 SET_NATIVE_RETVAL(arguments, \ 49 SET_NATIVE_RETVAL(arguments, \
54 DN_Helper##name(arguments->isolate(), arguments)); \ 50 DN_Helper##name(arguments->isolate(), arguments)); \
55 if (FLAG_deoptimize_alot) DeoptimizeAll(); \ 51 DEOPTIMIZE_ALOT; \
56 } \ 52 } \
57 VERIFY_ON_TRANSITION; \ 53 VERIFY_ON_TRANSITION; \
58 } \ 54 } \
59 static RawObject* DN_Helper##name(Isolate* isolate, \ 55 static RawObject* DN_Helper##name(Isolate* isolate, \
60 NativeArguments* arguments) 56 NativeArguments* arguments)
61 57
62 58
63 // Natives should throw an exception if an illegal argument or null is passed. 59 // Natives should throw an exception if an illegal argument or null is passed.
64 // type name = value. 60 // type name = value.
65 #define GET_NON_NULL_NATIVE_ARGUMENT(type, name, value) \ 61 #define GET_NON_NULL_NATIVE_ARGUMENT(type, name, value) \
(...skipping 19 matching lines...) Expand all
85 __args__.SetAt(0, __##name##_instance__); \ 81 __args__.SetAt(0, __##name##_instance__); \
86 Exceptions::ThrowByType(Exceptions::kArgument, __args__); \ 82 Exceptions::ThrowByType(Exceptions::kArgument, __args__); \
87 } \ 83 } \
88 } \ 84 } \
89 name ^= value; 85 name ^= value;
90 86
91 87
92 // Helper class for resolving and handling native functions. 88 // Helper class for resolving and handling native functions.
93 class NativeEntry : public AllStatic { 89 class NativeEntry : public AllStatic {
94 public: 90 public:
91 static const intptr_t kNumCallWrapperArguments = 2;
92
95 // Resolve specified dart native function to the actual native entrypoint. 93 // Resolve specified dart native function to the actual native entrypoint.
96 static NativeFunction ResolveNative(const Class& cls, 94 static NativeFunction ResolveNative(const Library& library,
97 const String& function_name, 95 const String& function_name,
98 int number_of_arguments); 96 int number_of_arguments);
97 static void NativeCallWrapper(Dart_NativeArguments args,
98 Dart_NativeFunction func);
99 static const ExternalLabel& NativeCallWrapperLabel();
99 }; 100 };
100 101
101 } // namespace dart 102 } // namespace dart
102 103
103 #endif // VM_NATIVE_ENTRY_H_ 104 #endif // VM_NATIVE_ENTRY_H_
OLDNEW
« no previous file with comments | « runtime/vm/native_arguments.h ('k') | runtime/vm/native_entry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698