Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Types | Static Public Member Functions | List of all members
dart::MethodRecognizer Class Reference

#include <method_recognizer.h>

Inheritance diagram for dart::MethodRecognizer:
dart::AllStatic

Public Types

enum  Kind { kUnknown , kNumRecognizedMethods }
 

Static Public Member Functions

static intptr_t NumArgsCheckedForStaticCall (const Function &function)
 
static intptr_t ResultCidFromPragma (const Object &function_or_field)
 
static bool HasNonNullableResultTypeFromPragma (const Object &function_or_field)
 
static intptr_t MethodKindToReceiverCid (Kind kind)
 
static const char * KindToCString (Kind kind)
 
static const char * KindToFunctionNameCString (Kind kind)
 
static bool IsMarkedAsRecognized (const Function &function, const char *kind=nullptr)
 
static void InitializeState ()
 

Detailed Description

Definition at line 25 of file method_recognizer.h.

Member Enumeration Documentation

◆ Kind

Enumerator
kUnknown 
kNumRecognizedMethods 

Definition at line 27 of file method_recognizer.h.

27 {
29#define DEFINE_ENUM_LIST(class_name, function_name, enum_name, fp) k##enum_name,
31#undef DEFINE_ENUM_LIST
33 };
#define DEFINE_ENUM_LIST(class_name, function_name, enum_name, fp)
#define RECOGNIZED_LIST(V)

Member Function Documentation

◆ HasNonNullableResultTypeFromPragma()

bool dart::MethodRecognizer::HasNonNullableResultTypeFromPragma ( const Object function_or_field)
static

Definition at line 80 of file method_recognizer.cc.

81 {
82 auto T = Thread::Current();
83 auto Z = T->zone();
84 auto& option = Object::Handle(Z);
85 if (Library::FindPragma(T, /*only_core=*/true, function_or_field,
86 Symbols::vm_non_nullable_result_type(),
87 /*multiple=*/false, &option)) {
88 return true;
89 }
90
91 // If nothing said otherwise, the return type is nullable.
92 return false;
93}
#define Z
static bool FindPragma(Thread *T, bool only_core, const Object &object, const String &pragma_name, bool multiple=false, Object *options=nullptr)
Definition object.cc:4201
static Object & Handle()
Definition object.h:407
static Thread * Current()
Definition thread.h:361
#define T

◆ InitializeState()

void dart::MethodRecognizer::InitializeState ( )
static

Definition at line 178 of file method_recognizer.cc.

178 {
179 GrowableArray<Library*> libs(3);
180 Libraries(&libs);
181 Function& func = Function::Handle();
182 bool fingerprints_match = true;
183
184 for (intptr_t i = 1; i < MethodRecognizer::kNumRecognizedMethods; i++) {
185 const MethodRecognizer::Kind kind = static_cast<MethodRecognizer::Kind>(i);
188 if (!func.IsNull()) {
189 fingerprints_match =
190 func.CheckSourceFingerprint(recognized_methods[i].fp) &&
191 fingerprints_match;
192 func.set_recognized_kind(kind);
193 switch (kind) {
194#define RECOGNIZE_METHOD(class_name, function_name, enum_name, fp) \
195 case MethodRecognizer::k##enum_name: \
196 func.reset_unboxed_parameters_and_return(); \
197 break;
199#undef RECOGNIZE_METHOD
200 default:
201 break;
202 }
203 } else if (!FLAG_precompiled_mode) {
204 fingerprints_match = false;
205 OS::PrintErr("Missing %s::%s\n", recognized_methods[i].class_name,
207 }
208 }
209
210#define SET_FUNCTION_BIT(class_name, function_name, dest, fp, setter, value) \
211 func = Library::GetFunction(libs, #class_name, #function_name); \
212 if (!func.IsNull()) { \
213 fingerprints_match = \
214 func.CheckSourceFingerprint(fp) && fingerprints_match; \
215 func.setter(value); \
216 } else if (!FLAG_precompiled_mode) { \
217 OS::PrintErr("Missing %s::%s\n", #class_name, #function_name); \
218 fingerprints_match = false; \
219 }
220
221#define SET_IS_POLYMORPHIC_TARGET(class_name, function_name, dest, fp) \
222 SET_FUNCTION_BIT(class_name, function_name, dest, fp, \
223 set_is_polymorphic_target, true)
224
226
227#undef SET_RECOGNIZED_KIND
228#undef SET_IS_POLYMORPHIC_TARGET
229#undef SET_FUNCTION_BIT
230
231 if (!fingerprints_match) {
232 // Private names are mangled. Mangling depends on Library::private_key_.
233 // If registering a new bootstrap library, add at the end.
234 FATAL(
235 "FP mismatch while recognizing methods. If the behavior of "
236 "these functions has changed, then changes are also needed in "
237 "the VM's compiler. Otherwise the fingerprint can simply be "
238 "updated in recognized_methods_list.h\n");
239 }
240}
static FunctionPtr GetFunction(const GrowableArray< Library * > &libs, const char *class_name, const char *function_name)
Definition object.cc:15352
static void static void PrintErr(const char *format,...) PRINTF_ATTRIBUTE(1
#define FATAL(error)
#define SET_IS_POLYMORPHIC_TARGET(class_name, function_name, dest, fp)
#define RECOGNIZE_METHOD(class_name, function_name, enum_name, fp)
const char *const class_name
static const struct dart::@131 recognized_methods[MethodRecognizer::kNumRecognizedMethods]
const uint32_t fp
const char *const function_name
#define ALL_INTRINSICS_LIST(V)
#define POLYMORPHIC_TARGET_LIST(V)

◆ IsMarkedAsRecognized()

bool dart::MethodRecognizer::IsMarkedAsRecognized ( const Function function,
const char *  kind = nullptr 
)
static

Definition at line 158 of file method_recognizer.cc.

159 {
160 const Function* functionp =
161 function.IsDynamicInvocationForwarder()
162 ? &Function::Handle(function.ForwardingTarget())
163 : &function;
164 Object& options = Object::Handle();
165 bool is_recognized = Library::FindPragma(
166 Thread::Current(), /*only_core=*/true, *functionp,
167 Symbols::vm_recognized(), /*multiple=*/false, &options);
168 if (!is_recognized) return false;
169 if (kind == nullptr) return true;
170
171 ASSERT(options.IsString());
172 ASSERT(String::Cast(options).Equals("asm-intrinsic") ||
173 String::Cast(options).Equals("graph-intrinsic") ||
174 String::Cast(options).Equals("other"));
175 return String::Cast(options).Equals(kind);
176}
const char * options
#define ASSERT(E)
Dart_NativeFunction function
Definition fuchsia.cc:51
static bool Equals(const Object &expected, const Object &actual)

◆ KindToCString()

const char * dart::MethodRecognizer::KindToCString ( Kind  kind)
static

Definition at line 145 of file method_recognizer.cc.

145 {
146 if (kind >= kUnknown && kind < kNumRecognizedMethods)
147 return recognized_methods[kind].enum_name;
148 return "?";
149}

◆ KindToFunctionNameCString()

const char * dart::MethodRecognizer::KindToFunctionNameCString ( Kind  kind)
static

Definition at line 151 of file method_recognizer.cc.

151 {
152 if (kind >= kUnknown && kind < kNumRecognizedMethods)
153 return recognized_methods[kind].function_name;
154 return "?";
155}

◆ MethodKindToReceiverCid()

intptr_t dart::MethodRecognizer::MethodKindToReceiverCid ( Kind  kind)
static

Definition at line 95 of file method_recognizer.cc.

95 {
96 switch (kind) {
97 case kObjectArrayGetIndexed:
98 case kObjectArraySetIndexed:
99 case kObjectArraySetIndexedUnchecked:
100 return kArrayCid;
101
102 case kGrowableArrayGetIndexed:
103 case kGrowableArraySetIndexed:
104 case kGrowableArraySetIndexedUnchecked:
105 return kGrowableObjectArrayCid;
106
107#define TYPED_DATA_GET_SET_INDEXED_CASES(clazz) \
108 case k##clazz##ArrayGetIndexed: \
109 case k##clazz##ArraySetIndexed: \
110 return kTypedData##clazz##ArrayCid; \
111 case kExternal##clazz##ArrayGetIndexed: \
112 return kExternalTypedData##clazz##ArrayCid; \
113 case k##clazz##ArrayViewGetIndexed: \
114 return kTypedData##clazz##ArrayViewCid;
115
117#undef TYPED_DATA_GET_SET_INDEXED_CASES
118
119 case kExternalUint8ArraySetIndexed:
120 return kExternalTypedDataUint8ArrayCid;
121
122 case kExternalUint8ClampedArraySetIndexed:
123 return kExternalTypedDataUint8ClampedArrayCid;
124
125 default:
126 break;
127 }
128 UNREACHABLE();
129 return kIllegalCid;
130}
#define UNREACHABLE()
Definition assert.h:248
#define DART_CLASS_LIST_TYPED_DATA(V)
Definition class_id.h:177
#define TYPED_DATA_GET_SET_INDEXED_CASES(clazz)
@ kIllegalCid
Definition class_id.h:214

◆ NumArgsCheckedForStaticCall()

intptr_t dart::MethodRecognizer::NumArgsCheckedForStaticCall ( const Function function)
static

Definition at line 14 of file method_recognizer.cc.

15 {
16 switch (function.recognized_kind()) {
17 case MethodRecognizer::kDoubleFromInteger:
18 case MethodRecognizer::kMathMin:
19 case MethodRecognizer::kMathMax:
20 return 2;
21 default:
22 return 0;
23 }
24}

◆ ResultCidFromPragma()

intptr_t dart::MethodRecognizer::ResultCidFromPragma ( const Object function_or_field)
static

Definition at line 26 of file method_recognizer.cc.

27 {
28 auto T = Thread::Current();
29 auto Z = T->zone();
30 auto& option = Object::Handle(Z);
31 if (Library::FindPragma(T, /*only_core=*/true, function_or_field,
32 Symbols::vm_exact_result_type(),
33 /*multiple=*/false, &option)) {
34 if (option.IsType()) {
35 return Type::Cast(option).type_class_id();
36 } else if (option.IsString()) {
37 auto& str = String::Cast(option);
38 // 'str' should match the pattern '([^#]+)#([^#\?]+)' where group 1
39 // is the library URI and group 2 is the class name.
40 bool parse_failure = false;
41 intptr_t library_end = -1;
42 for (intptr_t i = 0; i < str.Length(); ++i) {
43 if (str.CharAt(i) == '#') {
44 if (library_end != -1) {
45 parse_failure = true;
46 break;
47 } else {
48 library_end = i;
49 }
50 }
51 }
52 if (!parse_failure && library_end > 0) {
53 auto& tmp =
54 String::Handle(String::SubString(str, 0, library_end, Heap::kOld));
55 const auto& library = Library::Handle(Library::LookupLibrary(T, tmp));
56 if (!library.IsNull()) {
57 tmp = String::SubString(str, library_end + 1,
58 str.Length() - library_end - 1, Heap::kOld);
59 const auto& klass =
60 Class::Handle(library.LookupClassAllowPrivate(tmp));
61 if (!klass.IsNull()) {
62 return klass.id();
63 }
64 }
65 }
66 } else if (option.IsArray()) {
67 const Array& array = Array::Cast(option);
68 if (array.Length() > 0) {
69 const Object& type = Object::Handle(Array::Cast(option).At(0));
70 if (type.IsType()) {
71 return Type::Cast(type).type_class_id();
72 }
73 }
74 }
75 }
76
77 return kDynamicCid;
78}
@ kOld
Definition heap.h:39
static LibraryPtr LookupLibrary(Thread *thread, const String &url)
Definition object.cc:14646
static StringPtr SubString(const String &str, intptr_t begin_index, Heap::Space space=Heap::kNew)
Definition object.cc:24159
@ kDynamicCid
Definition class_id.h:253

The documentation for this class was generated from the following files: