• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // Holds information about possible function call optimizations.
14 class CallOptimization {
15  public:
16   CallOptimization(Isolate* isolate, Handle<Object> function);
17 
18   Context GetAccessorContext(Map holder_map) const;
19   bool IsCrossContextLazyAccessorPair(Context native_context,
20                                       Map holder_map) const;
21 
is_constant_call()22   bool is_constant_call() const { return !constant_function_.is_null(); }
23 
constant_function()24   Handle<JSFunction> constant_function() const {
25     DCHECK(is_constant_call());
26     return constant_function_;
27   }
28 
is_simple_api_call()29   bool is_simple_api_call() const { return is_simple_api_call_; }
30 
expected_receiver_type()31   Handle<FunctionTemplateInfo> expected_receiver_type() const {
32     DCHECK(is_simple_api_call());
33     return expected_receiver_type_;
34   }
35 
api_call_info()36   Handle<CallHandlerInfo> api_call_info() const {
37     DCHECK(is_simple_api_call());
38     return api_call_info_;
39   }
40 
41   enum HolderLookup { kHolderNotFound, kHolderIsReceiver, kHolderFound };
42   Handle<JSObject> LookupHolderOfExpectedType(
43       Handle<Map> receiver_map, HolderLookup* holder_lookup) const;
44 
45   // Check if the api holder is between the receiver and the holder.
46   bool IsCompatibleReceiver(Handle<Object> receiver,
47                             Handle<JSObject> holder) const;
48 
49   // Check if the api holder is between the receiver and the holder.
50   bool IsCompatibleReceiverMap(Handle<Map> receiver_map,
51                                Handle<JSObject> holder) const;
52 
53  private:
54   void Initialize(Isolate* isolate, Handle<JSFunction> function);
55   void Initialize(Isolate* isolate,
56                   Handle<FunctionTemplateInfo> function_template_info);
57 
58   // Determines whether the given function can be called using the
59   // fast api call builtin.
60   void AnalyzePossibleApiFunction(Isolate* isolate,
61                                   Handle<JSFunction> function);
62 
63   Handle<JSFunction> constant_function_;
64   bool is_simple_api_call_;
65   Handle<FunctionTemplateInfo> expected_receiver_type_;
66   Handle<CallHandlerInfo> api_call_info_;
67 };
68 }  // namespace internal
69 }  // namespace v8
70 
71 #endif  // V8_IC_CALL_OPTIMIZATION_H_
72