OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 // Class for handling inline cache stubs | |
5 // | |
6 // The initial target of an instance call is the resolving and patching runtime | |
7 // function 'ResolvePatchInstanceCall'. It resolves and compiles the | |
8 // target function and patches the instance call to jump to it | |
9 // via an inline cache stub. | |
10 // The inline cache stub checks receiver's class for a distinct set of classes | |
11 // and jumps to the appropriate target. | |
12 // An inline-cache-miss occurs if none of the classes match. As a consequence | |
13 // the old IC stub is replaced with a new one that adds the class check | |
14 // and target for the most recently seen receiver. | |
15 | |
16 #ifndef VM_IC_STUBS_H_ | |
17 #define VM_IC_STUBS_H_ | |
18 | |
19 #include "vm/allocation.h" | |
20 #include "vm/growable_array.h" | |
21 | |
22 namespace dart { | |
23 | |
24 // Forward declarations. | |
25 class Class; | |
26 class Code; | |
27 class Function; | |
28 class RawCode; | |
29 | |
30 class ICStubs : public AllStatic { | |
31 public: | |
32 // Returns an IC stub that jumps to targets' entry points if the receiver | |
33 // matches a class contained in 'classes' array. | |
34 static RawCode* GetICStub(const GrowableArray<const Class*>& classes, | |
35 const GrowableArray<const Function*>& targets); | |
36 | |
37 // Identify classes and their targets contained in the IC stub. | |
38 // 'ic_entry_point' is the start of the IC stubs. 'classes' and 'targets' | |
39 // are the implemented (class, target) tuples. | |
40 // Returns false if the entry_point does not point to an IC stub. | |
41 static bool RecognizeICStub(uword ic_entry_point, | |
42 GrowableArray<const Class*>* classes, | |
43 GrowableArray<const Function*>* targets); | |
44 | |
45 // Replace all 'from' targets with 'to' targets. | |
46 static void PatchTargets(uword ic_entry_point, uword from, uword to); | |
47 | |
48 // Locate a class within the array. Return -1 if class object in 'cls' | |
49 // is not in the array. | |
50 // TODO(srdjan): Remove from ICStubs interface. | |
51 static int IndexOfClass(const GrowableArray<const Class*>& classes, | |
52 const Class& cls); | |
53 | |
54 private: | |
55 static RawCode* FindInCode(const Code& target, | |
56 const GrowableArray<const Class*>& classes); | |
57 static void AppendICStubToTargets( | |
58 const GrowableArray<const Function*>& targets, | |
59 const GrowableArray<const Class*>& classes, | |
60 const Code& ic_stub); | |
61 static bool ParseICStub(uword ic_entry_point, | |
62 GrowableArray<const Class*>* classes, | |
63 GrowableArray<const Function*>* targets, | |
64 uword from, | |
65 uword to); | |
66 }; | |
67 | |
68 } // namespace dart | |
69 | |
70 #endif // VM_IC_STUBS_H_ | |
OLD | NEW |