86 #include "controller.h"
89 using namespace std::chrono;
90 using namespace r_code;
92 #define MAX_VALUE_SIZE 128
99 : Overlay(MAX_VALUE_SIZE)
102 Overlay::Overlay(
size_t values_size) :
_Object(), invalidated_(0) {
105 values_.resize(values_size);
108 Overlay::Overlay(Controller *c,
bool load_code) :
_Object(), controller_(c), value_commit_index_(0), code_(NULL), invalidated_(0) {
115 Overlay::~Overlay() {
121 Code* Overlay::get_object()
const {
return ((Controller*)controller_)->get_object(); }
122 r_exec::View* Overlay::get_view()
const {
return ((Controller*)controller_)->get_view(); }
124 inline Code *Overlay::get_core_object()
const {
126 return controller_->get_core_object();
129 void Overlay::load_code() {
134 Code *
object = get_core_object();
136 code_size_ =
object->code_size();
138 memcpy(code_, &object->code(0), code_size_ *
sizeof(
r_code::Atom));
141 void Overlay::reset() {
143 memcpy(code_, &get_object()->get_reference(0)->code(0), code_size_ *
sizeof(
r_code::Atom));
146 void Overlay::rollback() {
148 Code *
object = get_core_object();
149 Atom *original_code = &
object->code(0);
150 for (uint16 i = 0; i < patch_indices_.size(); ++i)
151 code_[patch_indices_[i]] = original_code[patch_indices_[i]];
152 patch_indices_.clear();
154 if (value_commit_index_ != values_.size()) {
156 if (value_commit_index_ > 0)
157 values_.resize(value_commit_index_);
160 value_commit_index_ = values_.size();
164 void Overlay::commit() {
166 patch_indices_.clear();
167 value_commit_index_ = values_.size();
170 void Overlay::patch_code(uint16 index,
Atom value) {
172 code_[index] = value;
173 patch_indices_.push_back(index);
176 uint16 Overlay::get_last_patch_index() {
178 return patch_indices_.size();
181 void Overlay::unpatch_code(uint16 patch_index) {
183 Code *
object = get_core_object();
184 Atom *original_code = &
object->code(0);
185 for (uint16 i = patch_index; i < patch_indices_.size(); ++i)
186 code_[patch_indices_[i]] = original_code[patch_indices_[i]];
187 patch_indices_.resize(patch_index);
197 return _Mem::Get()->build_object(head);
202 Controller::Controller(
_View *view) :
_Object(), invalidated_(0), activated_(0), view_(view) {
207 switch (get_object()->code(0).getDescriptor()) {
208 case Atom::INSTANTIATED_PROGRAM:
209 case Atom::INSTANTIATED_INPUT_LESS_PROGRAM:
210 case Atom::INSTANTIATED_ANTI_PROGRAM:
211 time_scope_ = Utils::GetDuration<Code>(get_object(), IPGM_TSC);
213 case Atom::INSTANTIATED_CPP_PROGRAM:
214 time_scope_ = Utils::GetDuration<Code>(get_object(), ICPP_PGM_TSC);
219 Controller::~Controller() {
222 void Controller::set_view(View *view) {
229 if (is_alive() && !input->object_->is_invalidated())
234 void Controller::push_reduction_job(_ReductionJob* j) {
235 _Mem::Get()->push_reduction_job(j);
240 OController::OController(
_View *view) : Controller(view) {
243 OController::~OController() {