1 /*
2  * Copyright (C) 2015 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_CODE_SIMULATOR_CONTAINER_H_
18 #define ART_RUNTIME_CODE_SIMULATOR_CONTAINER_H_
19 
20 #include "arch/instruction_set.h"
21 #include "base/logging.h"
22 #include "simulator/code_simulator.h"
23 
24 namespace art {
25 
26 // This container dynamically opens and closes libart-simulator.
27 class CodeSimulatorContainer {
28  public:
29   explicit CodeSimulatorContainer(InstructionSet target_isa);
30   ~CodeSimulatorContainer();
31 
CanSimulate()32   bool CanSimulate() const {
33     return simulator_ != nullptr;
34   }
35 
Get()36   CodeSimulator* Get() {
37     DCHECK(CanSimulate());
38     return simulator_;
39   }
40 
Get()41   const CodeSimulator* Get() const {
42     DCHECK(CanSimulate());
43     return simulator_;
44   }
45 
46  private:
47   void* libart_simulator_handle_;
48   CodeSimulator* simulator_;
49 
50   DISALLOW_COPY_AND_ASSIGN(CodeSimulatorContainer);
51 };
52 
53 }  // namespace art
54 
55 #endif  // ART_RUNTIME_CODE_SIMULATOR_CONTAINER_H_
56