1// Copyright (c) 2017, 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
5#ifndef RUNTIME_VM_COMPILATION_TRACE_H_
6#define RUNTIME_VM_COMPILATION_TRACE_H_
7
8#include "platform/assert.h"
9#include "vm/object.h"
10#include "vm/program_visitor.h"
11#include "vm/zone_text_buffer.h"
12
13namespace dart {
14
15class CompilationTraceSaver : public FunctionVisitor {
16 public:
17 explicit CompilationTraceSaver(Zone* zone);
18 void VisitFunction(const Function& function);
19
20 void StealBuffer(uint8_t** buffer, intptr_t* buffer_length) {
21 *buffer = reinterpret_cast<uint8_t*>(buf_.buffer());
22 *buffer_length = buf_.length();
23 }
24
25 private:
26 ZoneTextBuffer buf_;
27 String& func_name_;
28 Class& cls_;
29 String& cls_name_;
30 Library& lib_;
31 String& uri_;
32};
33
34class CompilationTraceLoader : public ValueObject {
35 public:
36 explicit CompilationTraceLoader(Thread* thread);
37
38 ObjectPtr CompileTrace(uint8_t* buffer, intptr_t buffer_length);
39
40 private:
41 ObjectPtr CompileTriple(const char* uri_cstr,
42 const char* cls_cstr,
43 const char* func_cstr);
44 ObjectPtr CompileFunction(const Function& function);
45 void SpeculateInstanceCallTargets(const Function& function);
46
47 Thread* thread_;
48 Zone* zone_;
49 String& uri_;
50 String& class_name_;
51 String& function_name_;
52 String& function_name2_;
53 Library& lib_;
54 Class& cls_;
55 Function& function_;
56 Function& function2_;
57 Field& field_;
58 Array& sites_;
59 ICData& site_;
60 AbstractType& static_type_;
61 Class& receiver_cls_;
62 Function& target_;
63 String& selector_;
64 Array& args_desc_;
65 Object& error_;
66};
67
68class TypeFeedbackSaver : public FunctionVisitor {
69 public:
70 explicit TypeFeedbackSaver(WriteStream* stream);
71
72 void WriteHeader();
73 void SaveClasses();
74 void SaveFields();
75 void VisitFunction(const Function& function);
76
77 private:
78 void WriteClassByName(const Class& cls);
79 void WriteString(const String& value);
80 void WriteInt(intptr_t value) { stream_->Write(static_cast<int32_t>(value)); }
81
82 WriteStream* const stream_;
83 Class& cls_;
84 Library& lib_;
85 String& str_;
86 Array& fields_;
87 Field& field_;
88 Code& code_;
89 Array& call_sites_;
90 ICData& call_site_;
91};
92
93class TypeFeedbackLoader : public ValueObject {
94 public:
95 explicit TypeFeedbackLoader(Thread* thread);
96 ~TypeFeedbackLoader();
97
98 ObjectPtr LoadFeedback(ReadStream* stream);
99
100 private:
101 ObjectPtr CheckHeader();
102 ObjectPtr LoadClasses();
103 ObjectPtr LoadFields();
104 ObjectPtr LoadFunction();
105 FunctionPtr FindFunction(FunctionLayout::Kind kind, intptr_t token_pos);
106
107 ClassPtr ReadClassByName();
108 StringPtr ReadString();
109 intptr_t ReadInt() { return stream_->Read<int32_t>(); }
110
111 Thread* thread_;
112 Zone* zone_;
113 ReadStream* stream_;
114 intptr_t num_cids_;
115 intptr_t* cid_map_;
116 String& uri_;
117 Library& lib_;
118 String& cls_name_;
119 Class& cls_;
120 String& field_name_;
121 Array& fields_;
122 Field& field_;
123 String& func_name_;
124 Function& func_;
125 Array& call_sites_;
126 ICData& call_site_;
127 String& target_name_;
128 Function& target_;
129 Array& args_desc_;
130 GrowableObjectArray& functions_to_compile_;
131 Object& error_;
132};
133
134} // namespace dart
135
136#endif // RUNTIME_VM_COMPILATION_TRACE_H_
137