2 * Copyright (C) 2015 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "code_simulator_container.h"
24 CodeSimulatorContainer::CodeSimulatorContainer(InstructionSet target_isa)
25 : libart_simulator_handle_(nullptr),
27 const char* libart_simulator_so_name =
28 kIsDebugBuild ? "libartd-simulator.so" : "libart-simulator.so";
29 libart_simulator_handle_ = dlopen(libart_simulator_so_name, RTLD_NOW);
30 // It is not a real error when libart-simulator does not exist, e.g., on target.
31 if (libart_simulator_handle_ == nullptr) {
32 VLOG(simulator) << "Could not load " << libart_simulator_so_name << ": " << dlerror();
34 typedef CodeSimulator* (*create_code_simulator_ptr_)(InstructionSet target_isa);
35 create_code_simulator_ptr_ create_code_simulator_ =
36 reinterpret_cast<create_code_simulator_ptr_>(
37 dlsym(libart_simulator_handle_, "CreateCodeSimulator"));
38 DCHECK(create_code_simulator_ != nullptr) << "Fail to find symbol of CreateCodeSimulator: "
40 simulator_ = create_code_simulator_(target_isa);
44 CodeSimulatorContainer::~CodeSimulatorContainer() {
45 // Free simulator object before closing libart-simulator because destructor of
46 // CodeSimulator lives in it.
47 if (simulator_ != nullptr) {
50 if (libart_simulator_handle_ != nullptr) {
51 dlclose(libart_simulator_handle_);