summaryrefslogtreecommitdiffstats
path: root/compiler/dex/quick/lazy_debug_frame_opcode_writer.cc
blob: 5cfb0ff557548bcf775af407f307339584ee0c57 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "lazy_debug_frame_opcode_writer.h"
#include "mir_to_lir.h"

namespace art {
namespace dwarf {

const ArenaVector<uint8_t>* LazyDebugFrameOpCodeWriter::Patch(size_t code_size) {
  if (!this->enabled_) {
    DCHECK(this->data()->empty());
    return this->data();
  }
  if (!patched_) {
    patched_ = true;
    // Move our data buffer to temporary variable.
    ArenaVector<uint8_t> old_opcodes(this->opcodes_.get_allocator());
    old_opcodes.swap(this->opcodes_);
    // Refill our data buffer with patched opcodes.
    this->opcodes_.reserve(old_opcodes.size() + advances_.size() + 4);
    size_t pos = 0;
    for (auto advance : advances_) {
      DCHECK_GE(advance.pos, pos);
      // Copy old data up to the point when advance was issued.
      this->opcodes_.insert(this->opcodes_.end(),
                            old_opcodes.begin() + pos,
                            old_opcodes.begin() + advance.pos);
      pos = advance.pos;
      // This may be null if there is no slow-path code after return.
      LIR* next_lir = NEXT_LIR(advance.last_lir_insn);
      // Insert the advance command with its final offset.
      Base::AdvancePC(next_lir != nullptr ? next_lir->offset : code_size);
    }
    // Copy the final segment.
    this->opcodes_.insert(this->opcodes_.end(),
                          old_opcodes.begin() + pos,
                          old_opcodes.end());
    Base::AdvancePC(code_size);
  }
  return this->data();
}

}  // namespace dwarf
}  // namespace art