Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2016, 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 VM_SIMULATOR_DBC_H_ | |
| 6 #define VM_SIMULATOR_DBC_H_ | |
| 7 | |
| 8 #ifndef VM_SIMULATOR_H_ | |
| 9 #error Do not include simulator_dbc.h directly; use simulator.h. | |
| 10 #endif | |
| 11 | |
| 12 #include "vm/constants_dbc.h" | |
| 13 #include "vm/method_recognizer.h" | |
| 14 | |
| 15 namespace dart { | |
| 16 | |
| 17 class Isolate; | |
| 18 class RawObject; | |
| 19 class SimulatorSetjmpBuffer; | |
| 20 class Thread; | |
| 21 class Code; | |
| 22 class Array; | |
| 23 class RawICData; | |
| 24 class RawArray; | |
| 25 class RawObjectPool; | |
| 26 class RawFunction; | |
| 27 | |
| 28 // Simulator intrinsic handler. It is invoked on entry to the intrinsified | |
| 29 // function via Intrinsic bytecode before the frame is setup. | |
| 30 // If the handler returns true then Intrinsic bytecode works as a return | |
| 31 // instruction returning the value in result. Otherwise interpreter proceeds to | |
| 32 // execute the body of the function. | |
| 33 typedef bool (*IntrinsicHandler)(Thread* thread, | |
| 34 RawObject** FP, | |
| 35 RawObject** result); | |
| 36 | |
| 37 | |
| 38 class Simulator { | |
| 39 public: | |
| 40 static const uword kSimulatorStackUnderflowSize = 64; | |
| 41 | |
| 42 Simulator(); | |
| 43 ~Simulator(); | |
| 44 | |
| 45 // The currently executing Simulator instance, which is associated to the | |
| 46 // current isolate | |
| 47 static Simulator* Current(); | |
| 48 | |
| 49 // Accessors to the internal simulator stack base and top. | |
| 50 uword StackBase() const { return reinterpret_cast<uword>(stack_); } | |
| 51 uword StackTop() const; | |
| 52 | |
| 53 // The isolate's top_exit_frame_info refers to a Dart frame in the simulator | |
| 54 // stack. The simulator's top_exit_frame_info refers to a C++ frame in the | |
| 55 // native stack. | |
| 56 uword top_exit_frame_info() const { return top_exit_frame_info_; } | |
| 57 void set_top_exit_frame_info(uword value) { top_exit_frame_info_ = value; } | |
| 58 | |
| 59 // Call on program start. | |
| 60 static void InitOnce(); | |
| 61 | |
| 62 RawObject* Call(const Code& code, | |
| 63 const Array& arguments_descriptor, | |
| 64 const Array& arguments, | |
| 65 Thread* thread); | |
| 66 | |
| 67 void Longjmp(uword pc, | |
| 68 uword sp, | |
| 69 uword fp, | |
| 70 RawObject* raw_exception, | |
| 71 RawObject* raw_stacktrace, | |
| 72 Thread* thread); | |
| 73 | |
| 74 uword sp() const { | |
| 75 return reinterpret_cast<uword>(top_); | |
| 76 } | |
| 77 | |
| 78 enum InstrinsicId { | |
|
Florian Schneider
2016/04/12 02:29:59
s/InstrinsicId/IntrinsicId/g
Vyacheslav Egorov (Google)
2016/04/12 09:01:21
Done.
| |
| 79 #define V(test_class_name, test_function_name, enum_name, fp) \ | |
| 80 k##enum_name##Intrinsic, | |
| 81 ALL_INTRINSICS_LIST(V) | |
| 82 GRAPH_INTRINSICS_LIST(V) | |
| 83 #undef V | |
| 84 kIntrinsicCount, | |
| 85 }; | |
| 86 | |
| 87 static bool IsSupportedIntrinsic(InstrinsicId id) { | |
| 88 return intrinsics_[id] != NULL; | |
| 89 } | |
| 90 | |
| 91 enum SpecialIndex { | |
| 92 kExceptionSpecialIndex, | |
| 93 kStacktraceSpecialIndex, | |
| 94 kSpecialIndexCount | |
| 95 }; | |
| 96 | |
| 97 private: | |
| 98 uintptr_t* stack_; | |
| 99 uintptr_t* base_; | |
| 100 uintptr_t* top_; | |
| 101 uword pc_; | |
| 102 | |
| 103 SimulatorSetjmpBuffer* last_setjmp_buffer_; | |
| 104 uword top_exit_frame_info_; | |
| 105 | |
| 106 RawObject* special_[kSpecialIndexCount]; | |
| 107 | |
| 108 static IntrinsicHandler intrinsics_[kIntrinsicCount]; | |
| 109 | |
| 110 void Exit(Thread* thread, | |
| 111 RawObject** base, | |
| 112 RawObject** exit_frame, | |
| 113 uint32_t* pc); | |
| 114 | |
| 115 void CallRuntime(Thread* thread, | |
| 116 RawObject** base, | |
| 117 RawObject** exit_frame, | |
| 118 uint32_t* pc, | |
| 119 intptr_t argc_tag, | |
| 120 RawObject** args, | |
| 121 RawObject** result, | |
| 122 uword target); | |
| 123 | |
| 124 void Invoke(Thread* thread, | |
| 125 RawObject** call_base, | |
| 126 RawObject** call_top, | |
| 127 RawObjectPool** pp, | |
| 128 uint32_t** pc, | |
| 129 RawObject*** B, | |
| 130 RawObject*** SP); | |
| 131 | |
| 132 void InlineCacheMiss(int checked_args, | |
| 133 Thread* thread, | |
| 134 RawICData* icdata, | |
| 135 RawObject** call_base, | |
| 136 RawObject** top, | |
| 137 uint32_t* pc, | |
| 138 RawObject** B, RawObject** SP); | |
| 139 | |
| 140 void InstanceCall1(Thread* thread, | |
| 141 RawICData* icdata, | |
| 142 RawObject** call_base, | |
| 143 RawObject** call_top, | |
| 144 Array* argdesc, | |
| 145 RawObjectPool** pp, | |
| 146 uint32_t** pc, | |
| 147 RawObject*** B, RawObject*** SP); | |
| 148 | |
| 149 void InstanceCall2(Thread* thread, | |
| 150 RawICData* icdata, | |
| 151 RawObject** call_base, | |
| 152 RawObject** call_top, | |
| 153 Array* argdesc, | |
| 154 RawObjectPool** pp, | |
| 155 uint32_t** pc, | |
| 156 RawObject*** B, RawObject*** SP); | |
| 157 | |
| 158 void InstanceCall3(Thread* thread, | |
| 159 RawICData* icdata, | |
| 160 RawObject** call_base, | |
| 161 RawObject** call_top, | |
| 162 Array* argdesc, | |
| 163 RawObjectPool** pp, | |
| 164 uint32_t** pc, | |
| 165 RawObject*** B, RawObject*** SP); | |
| 166 | |
| 167 // Longjmp support for exceptions. | |
| 168 SimulatorSetjmpBuffer* last_setjmp_buffer() { | |
| 169 return last_setjmp_buffer_; | |
| 170 } | |
| 171 void set_last_setjmp_buffer(SimulatorSetjmpBuffer* buffer) { | |
| 172 last_setjmp_buffer_ = buffer; | |
| 173 } | |
| 174 | |
| 175 friend class SimulatorSetjmpBuffer; | |
| 176 DISALLOW_COPY_AND_ASSIGN(Simulator); | |
| 177 }; | |
| 178 | |
| 179 } // namespace dart | |
| 180 | |
| 181 #endif // VM_SIMULATOR_DBC_H_ | |
| OLD | NEW |