1 // Copyright 2014 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef V8_IC_CALL_OPTIMIZATION_H_ 6 #define V8_IC_CALL_OPTIMIZATION_H_ 7 8 #include "src/api/api-arguments.h" 9 #include "src/objects/objects.h" 10 11 namespace v8 { 12 namespace internal { 13 14 // Holds information about possible function call optimizations. 15 class CallOptimization { 16 public: 17 template <class IsolateT> 18 CallOptimization(IsolateT* isolate, Handle<Object> function); 19 20 Context GetAccessorContext(Map holder_map) const; 21 bool IsCrossContextLazyAccessorPair(Context native_context, 22 Map holder_map) const; 23 is_constant_call()24 bool is_constant_call() const { return !constant_function_.is_null(); } accept_any_receiver()25 bool accept_any_receiver() const { return accept_any_receiver_; } requires_signature_check()26 bool requires_signature_check() const { 27 return !expected_receiver_type_.is_null(); 28 } 29 constant_function()30 Handle<JSFunction> constant_function() const { 31 DCHECK(is_constant_call()); 32 return constant_function_; 33 } 34 is_simple_api_call()35 bool is_simple_api_call() const { return is_simple_api_call_; } 36 expected_receiver_type()37 Handle<FunctionTemplateInfo> expected_receiver_type() const { 38 DCHECK(is_simple_api_call()); 39 return expected_receiver_type_; 40 } 41 api_call_info()42 Handle<CallHandlerInfo> api_call_info() const { 43 DCHECK(is_simple_api_call()); 44 return api_call_info_; 45 } 46 47 enum HolderLookup { kHolderNotFound, kHolderIsReceiver, kHolderFound }; 48 49 template <class IsolateT> 50 Handle<JSObject> LookupHolderOfExpectedType( 51 IsolateT* isolate, Handle<Map> receiver_map, 52 HolderLookup* holder_lookup) const; 53 54 bool IsCompatibleReceiverMap(Handle<JSObject> api_holder, 55 Handle<JSObject> holder, HolderLookup) const; 56 57 private: 58 template <class IsolateT> 59 void Initialize(IsolateT* isolate, Handle<JSFunction> function); 60 template <class IsolateT> 61 void Initialize(IsolateT* isolate, 62 Handle<FunctionTemplateInfo> function_template_info); 63 64 // Determines whether the given function can be called using the 65 // fast api call builtin. 66 template <class IsolateT> 67 void AnalyzePossibleApiFunction(IsolateT* isolate, 68 Handle<JSFunction> function); 69 70 Handle<JSFunction> constant_function_; 71 Handle<FunctionTemplateInfo> expected_receiver_type_; 72 Handle<CallHandlerInfo> api_call_info_; 73 74 // TODO(gsathya): Change these to be a bitfield and do a single fast check 75 // rather than two checks. 76 bool is_simple_api_call_ = false; 77 bool accept_any_receiver_ = false; 78 }; 79 80 } // namespace internal 81 } // namespace v8 82 83 #endif // V8_IC_CALL_OPTIMIZATION_H_ 84