blob: a5f05dc8fceccb6a0119fc8cb1527678568f9414 [file] [log] [blame]
Phil Wang751beff2015-08-28 15:17:15 +08001/*
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#include <dlfcn.h>
18
19#include "code_simulator_container.h"
Andreas Gampe71da4872017-07-26 10:02:07 -070020
21#include "code_simulator.h"
Phil Wang751beff2015-08-28 15:17:15 +080022#include "globals.h"
23
24namespace art {
25
26CodeSimulatorContainer::CodeSimulatorContainer(InstructionSet target_isa)
27 : libart_simulator_handle_(nullptr),
28 simulator_(nullptr) {
29 const char* libart_simulator_so_name =
30 kIsDebugBuild ? "libartd-simulator.so" : "libart-simulator.so";
31 libart_simulator_handle_ = dlopen(libart_simulator_so_name, RTLD_NOW);
32 // It is not a real error when libart-simulator does not exist, e.g., on target.
33 if (libart_simulator_handle_ == nullptr) {
34 VLOG(simulator) << "Could not load " << libart_simulator_so_name << ": " << dlerror();
35 } else {
36 typedef CodeSimulator* (*create_code_simulator_ptr_)(InstructionSet target_isa);
37 create_code_simulator_ptr_ create_code_simulator_ =
38 reinterpret_cast<create_code_simulator_ptr_>(
39 dlsym(libart_simulator_handle_, "CreateCodeSimulator"));
40 DCHECK(create_code_simulator_ != nullptr) << "Fail to find symbol of CreateCodeSimulator: "
41 << dlerror();
42 simulator_ = create_code_simulator_(target_isa);
43 }
44}
45
46CodeSimulatorContainer::~CodeSimulatorContainer() {
47 // Free simulator object before closing libart-simulator because destructor of
48 // CodeSimulator lives in it.
49 if (simulator_ != nullptr) {
50 delete simulator_;
51 }
52 if (libart_simulator_handle_ != nullptr) {
53 dlclose(libart_simulator_handle_);
54 }
55}
56
57} // namespace art