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