blob: 5b72468fcdfae2269f203f99303983d710ae121c [file] [log] [blame]
Mathieu Chartierde4b08f2017-07-10 14:13:41 -07001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ART_RUNTIME_QUICKEN_INFO_H_
18#define ART_RUNTIME_QUICKEN_INFO_H_
19
20#include "dex_instruction.h"
21
22namespace art {
23
24// QuickenInfoTable is a table of 16 bit dex indices. There is one slot fo every instruction that is
25// possibly dequickenable.
26class QuickenInfoTable {
27 public:
28 explicit QuickenInfoTable(const uint8_t* data) : data_(data) {}
29
30 bool IsNull() const {
31 return data_ == nullptr;
32 }
33
34 uint16_t GetData(size_t index) const {
35 return data_[index * 2] | (static_cast<uint16_t>(data_[index * 2 + 1]) << 8);
36 }
37
38 // Returns true if the dex instruction has an index in the table. (maybe dequickenable).
39 static bool NeedsIndexForInstruction(const Instruction* inst) {
40 return inst->IsQuickened() || inst->Opcode() == Instruction::NOP;
41 }
42
43 static size_t NumberOfIndices(size_t bytes) {
44 return bytes / sizeof(uint16_t);
45 }
46
47 private:
48 const uint8_t* const data_;
49
50 DISALLOW_COPY_AND_ASSIGN(QuickenInfoTable);
51};
52
53} // namespace art
54
55#endif // ART_RUNTIME_QUICKEN_INFO_H_