blob: e4fbc86020b4c4e8a40524e3d3fafabcc6171398 [file] [log] [blame]
Elliott Hugheseb02a122012-06-12 11:35:40 -07001/*
2 * Copyright (C) 2012 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
Ian Rogerse63db272014-07-15 15:36:11 -070017#include "common_runtime_test.h"
18
19#include <dirent.h>
20#include <dlfcn.h>
21#include <fcntl.h>
Andreas Gampe369810a2015-01-14 19:53:31 -080022#include <stdlib.h>
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070023#include <cstdio>
Andreas Gampe373a9b52017-10-18 09:01:57 -070024#include "nativehelper/scoped_local_ref.h"
Ian Rogerse63db272014-07-15 15:36:11 -070025
Andreas Gampe46ee31b2016-12-14 10:11:49 -080026#include "android-base/stringprintf.h"
Andreas Gampefdb7a612017-11-01 15:11:13 -070027#include <unicode/uvernum.h>
Andreas Gampe46ee31b2016-12-14 10:11:49 -080028
Mathieu Chartiere401d142015-04-22 13:56:20 -070029#include "art_field-inl.h"
David Sehr891a50e2017-10-27 17:01:07 -070030#include "base/file_utils.h"
Elliott Hughes07ed66b2012-12-12 18:34:25 -080031#include "base/logging.h"
Steven Morelande431e272017-07-18 16:53:49 -070032#include "base/macros.h"
Andreas Gampedcc528d2017-12-07 13:37:10 -080033#include "base/runtime_debug.h"
Ian Rogerse63db272014-07-15 15:36:11 -070034#include "base/stl_util.h"
Ian Rogerse63db272014-07-15 15:36:11 -070035#include "base/unix_file/fd_file.h"
36#include "class_linker.h"
37#include "compiler_callbacks.h"
David Sehr013fd802018-01-11 22:55:24 -080038#include "dex/art_dex_file_loader.h"
David Sehr9e734c72018-01-04 17:56:19 -080039#include "dex/dex_file-inl.h"
40#include "dex/dex_file_loader.h"
David Sehr67bf42e2018-02-26 16:43:04 -080041#include "dex/primitive.h"
Ian Rogerse63db272014-07-15 15:36:11 -070042#include "gc/heap.h"
Steven Morelande431e272017-07-18 16:53:49 -070043#include "gc_root-inl.h"
Elliott Hugheseb02a122012-06-12 11:35:40 -070044#include "gtest/gtest.h"
Andreas Gampe81c6f8d2015-03-25 17:19:53 -070045#include "handle_scope-inl.h"
Andreas Gampe9b5cba42015-03-11 09:53:50 -070046#include "interpreter/unstarted_runtime.h"
Andreas Gampec15a2f42017-04-21 12:09:39 -070047#include "java_vm_ext.h"
Ian Rogerse63db272014-07-15 15:36:11 -070048#include "jni_internal.h"
Steven Morelande431e272017-07-18 16:53:49 -070049#include "mem_map.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070050#include "mirror/class-inl.h"
Ian Rogerse63db272014-07-15 15:36:11 -070051#include "mirror/class_loader.h"
Mathieu Chartiere58991b2015-10-13 07:59:34 -070052#include "native/dalvik_system_DexFile.h"
Ian Rogerse63db272014-07-15 15:36:11 -070053#include "noop_compiler_callbacks.h"
54#include "os.h"
55#include "runtime-inl.h"
Mathieu Chartier0795f232016-09-27 18:43:30 -070056#include "scoped_thread_state_change-inl.h"
Ian Rogerse63db272014-07-15 15:36:11 -070057#include "thread.h"
58#include "well_known_classes.h"
Elliott Hugheseb02a122012-06-12 11:35:40 -070059
60int main(int argc, char **argv) {
Andreas Gampe369810a2015-01-14 19:53:31 -080061 // Gtests can be very noisy. For example, an executable with multiple tests will trigger native
62 // bridge warnings. The following line reduces the minimum log severity to ERROR and suppresses
63 // everything else. In case you want to see all messages, comment out the line.
Nicolas Geoffraya7a47592015-11-24 09:17:30 +000064 setenv("ANDROID_LOG_TAGS", "*:e", 1);
Andreas Gampe369810a2015-01-14 19:53:31 -080065
Andreas Gampe51d80cc2017-06-21 21:05:13 -070066 art::InitLogging(argv, art::Runtime::Abort);
Andreas Gampe3fec9ac2016-09-13 10:47:28 -070067 LOG(INFO) << "Running main() from common_runtime_test.cc...";
Elliott Hugheseb02a122012-06-12 11:35:40 -070068 testing::InitGoogleTest(&argc, argv);
69 return RUN_ALL_TESTS();
70}
Ian Rogerse63db272014-07-15 15:36:11 -070071
72namespace art {
73
Andreas Gampe46ee31b2016-12-14 10:11:49 -080074using android::base::StringPrintf;
75
Ian Rogerse63db272014-07-15 15:36:11 -070076ScratchFile::ScratchFile() {
77 // ANDROID_DATA needs to be set
78 CHECK_NE(static_cast<char*>(nullptr), getenv("ANDROID_DATA")) <<
79 "Are you subclassing RuntimeTest?";
80 filename_ = getenv("ANDROID_DATA");
81 filename_ += "/TmpFile-XXXXXX";
82 int fd = mkstemp(&filename_[0]);
Andreas Gampe29d38e72016-03-23 15:31:51 +000083 CHECK_NE(-1, fd) << strerror(errno) << " for " << filename_;
Andreas Gampe4303ba92014-11-06 01:00:46 -080084 file_.reset(new File(fd, GetFilename(), true));
Ian Rogerse63db272014-07-15 15:36:11 -070085}
86
Mathieu Chartier866d8742016-09-21 15:24:18 -070087ScratchFile::ScratchFile(const ScratchFile& other, const char* suffix)
88 : ScratchFile(other.GetFilename() + suffix) {}
89
90ScratchFile::ScratchFile(const std::string& filename) : filename_(filename) {
Ian Rogerse63db272014-07-15 15:36:11 -070091 int fd = open(filename_.c_str(), O_RDWR | O_CREAT, 0666);
92 CHECK_NE(-1, fd);
Andreas Gampe4303ba92014-11-06 01:00:46 -080093 file_.reset(new File(fd, GetFilename(), true));
Ian Rogerse63db272014-07-15 15:36:11 -070094}
95
96ScratchFile::ScratchFile(File* file) {
Mathieu Chartier2cebb242015-04-21 16:50:40 -070097 CHECK(file != nullptr);
Ian Rogerse63db272014-07-15 15:36:11 -070098 filename_ = file->GetPath();
99 file_.reset(file);
100}
101
Mathieu Chartier866d8742016-09-21 15:24:18 -0700102ScratchFile::ScratchFile(ScratchFile&& other) {
103 *this = std::move(other);
104}
105
106ScratchFile& ScratchFile::operator=(ScratchFile&& other) {
107 if (GetFile() != other.GetFile()) {
108 std::swap(filename_, other.filename_);
109 std::swap(file_, other.file_);
110 }
111 return *this;
112}
113
Ian Rogerse63db272014-07-15 15:36:11 -0700114ScratchFile::~ScratchFile() {
115 Unlink();
116}
117
118int ScratchFile::GetFd() const {
119 return file_->Fd();
120}
121
Andreas Gampee21dc3d2014-12-08 16:59:43 -0800122void ScratchFile::Close() {
Andreas Gampe4303ba92014-11-06 01:00:46 -0800123 if (file_.get() != nullptr) {
124 if (file_->FlushCloseOrErase() != 0) {
125 PLOG(WARNING) << "Error closing scratch file.";
126 }
127 }
Andreas Gampee21dc3d2014-12-08 16:59:43 -0800128}
129
130void ScratchFile::Unlink() {
131 if (!OS::FileExists(filename_.c_str())) {
132 return;
133 }
134 Close();
Ian Rogerse63db272014-07-15 15:36:11 -0700135 int unlink_result = unlink(filename_.c_str());
136 CHECK_EQ(0, unlink_result);
137}
138
Andreas Gampe9b5cba42015-03-11 09:53:50 -0700139static bool unstarted_initialized_ = false;
140
Andreas Gampe48864112017-01-19 17:23:17 -0800141CommonRuntimeTestImpl::CommonRuntimeTestImpl()
142 : class_linker_(nullptr), java_lang_dex_file_(nullptr) {
143}
Mathieu Chartier91c91162016-01-15 09:48:15 -0800144
145CommonRuntimeTestImpl::~CommonRuntimeTestImpl() {
Richard Uhlerfbef44d2014-12-23 09:48:51 -0800146 // Ensure the dex files are cleaned up before the runtime.
147 loaded_dex_files_.clear();
148 runtime_.reset();
149}
Ian Rogerse63db272014-07-15 15:36:11 -0700150
Mathieu Chartier91c91162016-01-15 09:48:15 -0800151void CommonRuntimeTestImpl::SetUpAndroidRoot() {
Ian Rogerse63db272014-07-15 15:36:11 -0700152 if (IsHost()) {
153 // $ANDROID_ROOT is set on the device, but not necessarily on the host.
154 // But it needs to be set so that icu4c can find its locale data.
155 const char* android_root_from_env = getenv("ANDROID_ROOT");
156 if (android_root_from_env == nullptr) {
157 // Use ANDROID_HOST_OUT for ANDROID_ROOT if it is set.
158 const char* android_host_out = getenv("ANDROID_HOST_OUT");
159 if (android_host_out != nullptr) {
160 setenv("ANDROID_ROOT", android_host_out, 1);
161 } else {
162 // Build it from ANDROID_BUILD_TOP or cwd
163 std::string root;
164 const char* android_build_top = getenv("ANDROID_BUILD_TOP");
165 if (android_build_top != nullptr) {
166 root += android_build_top;
167 } else {
168 // Not set by build server, so default to current directory
169 char* cwd = getcwd(nullptr, 0);
170 setenv("ANDROID_BUILD_TOP", cwd, 1);
171 root += cwd;
172 free(cwd);
173 }
174#if defined(__linux__)
175 root += "/out/host/linux-x86";
176#elif defined(__APPLE__)
177 root += "/out/host/darwin-x86";
178#else
179#error unsupported OS
180#endif
181 setenv("ANDROID_ROOT", root.c_str(), 1);
182 }
183 }
184 setenv("LD_LIBRARY_PATH", ":", 0); // Required by java.lang.System.<clinit>.
185
186 // Not set by build server, so default
187 if (getenv("ANDROID_HOST_OUT") == nullptr) {
188 setenv("ANDROID_HOST_OUT", getenv("ANDROID_ROOT"), 1);
189 }
190 }
Andreas Gampe7747c8d2014-08-06 14:53:03 -0700191}
Ian Rogerse63db272014-07-15 15:36:11 -0700192
Mathieu Chartier91c91162016-01-15 09:48:15 -0800193void CommonRuntimeTestImpl::SetUpAndroidData(std::string& android_data) {
Ian Rogerse63db272014-07-15 15:36:11 -0700194 // On target, Cannot use /mnt/sdcard because it is mounted noexec, so use subdir of dalvik-cache
Andreas Gampe5a79fde2014-08-06 13:12:26 -0700195 if (IsHost()) {
196 const char* tmpdir = getenv("TMPDIR");
197 if (tmpdir != nullptr && tmpdir[0] != 0) {
198 android_data = tmpdir;
199 } else {
200 android_data = "/tmp";
201 }
202 } else {
203 android_data = "/data/dalvik-cache";
204 }
205 android_data += "/art-data-XXXXXX";
Ian Rogerse63db272014-07-15 15:36:11 -0700206 if (mkdtemp(&android_data[0]) == nullptr) {
207 PLOG(FATAL) << "mkdtemp(\"" << &android_data[0] << "\") failed";
208 }
209 setenv("ANDROID_DATA", android_data.c_str(), 1);
210}
211
Mathieu Chartier91c91162016-01-15 09:48:15 -0800212void CommonRuntimeTestImpl::TearDownAndroidData(const std::string& android_data,
213 bool fail_on_error) {
Andreas Gampe7747c8d2014-08-06 14:53:03 -0700214 if (fail_on_error) {
215 ASSERT_EQ(rmdir(android_data.c_str()), 0);
216 } else {
217 rmdir(android_data.c_str());
218 }
219}
220
David Srbecky3e52aa42015-04-12 07:45:18 +0100221// Helper - find directory with the following format:
222// ${ANDROID_BUILD_TOP}/${subdir1}/${subdir2}-${version}/${subdir3}/bin/
223static std::string GetAndroidToolsDir(const std::string& subdir1,
224 const std::string& subdir2,
225 const std::string& subdir3) {
226 std::string root;
227 const char* android_build_top = getenv("ANDROID_BUILD_TOP");
228 if (android_build_top != nullptr) {
229 root = android_build_top;
230 } else {
231 // Not set by build server, so default to current directory
232 char* cwd = getcwd(nullptr, 0);
233 setenv("ANDROID_BUILD_TOP", cwd, 1);
234 root = cwd;
235 free(cwd);
236 }
237
238 std::string toolsdir = root + "/" + subdir1;
239 std::string founddir;
240 DIR* dir;
241 if ((dir = opendir(toolsdir.c_str())) != nullptr) {
242 float maxversion = 0;
243 struct dirent* entry;
244 while ((entry = readdir(dir)) != nullptr) {
245 std::string format = subdir2 + "-%f";
246 float version;
247 if (std::sscanf(entry->d_name, format.c_str(), &version) == 1) {
248 if (version > maxversion) {
249 maxversion = version;
250 founddir = toolsdir + "/" + entry->d_name + "/" + subdir3 + "/bin/";
251 }
252 }
253 }
254 closedir(dir);
255 }
256
257 if (founddir.empty()) {
Roland Levillain91d65e02016-01-19 15:59:16 +0000258 ADD_FAILURE() << "Cannot find Android tools directory.";
David Srbecky3e52aa42015-04-12 07:45:18 +0100259 }
260 return founddir;
261}
262
Mathieu Chartier91c91162016-01-15 09:48:15 -0800263std::string CommonRuntimeTestImpl::GetAndroidHostToolsDir() {
David Srbecky3e52aa42015-04-12 07:45:18 +0100264 return GetAndroidToolsDir("prebuilts/gcc/linux-x86/host",
265 "x86_64-linux-glibc2.15",
266 "x86_64-linux");
267}
268
Mathieu Chartier91c91162016-01-15 09:48:15 -0800269std::string CommonRuntimeTestImpl::GetAndroidTargetToolsDir(InstructionSet isa) {
David Srbecky3e52aa42015-04-12 07:45:18 +0100270 switch (isa) {
Vladimir Marko33bff252017-11-01 14:35:42 +0000271 case InstructionSet::kArm:
272 case InstructionSet::kThumb2:
David Srbecky3e52aa42015-04-12 07:45:18 +0100273 return GetAndroidToolsDir("prebuilts/gcc/linux-x86/arm",
274 "arm-linux-androideabi",
275 "arm-linux-androideabi");
Vladimir Marko33bff252017-11-01 14:35:42 +0000276 case InstructionSet::kArm64:
David Srbecky3e52aa42015-04-12 07:45:18 +0100277 return GetAndroidToolsDir("prebuilts/gcc/linux-x86/aarch64",
278 "aarch64-linux-android",
279 "aarch64-linux-android");
Vladimir Marko33bff252017-11-01 14:35:42 +0000280 case InstructionSet::kX86:
281 case InstructionSet::kX86_64:
David Srbecky3e52aa42015-04-12 07:45:18 +0100282 return GetAndroidToolsDir("prebuilts/gcc/linux-x86/x86",
283 "x86_64-linux-android",
284 "x86_64-linux-android");
Vladimir Marko33bff252017-11-01 14:35:42 +0000285 case InstructionSet::kMips:
286 case InstructionSet::kMips64:
David Srbecky3e52aa42015-04-12 07:45:18 +0100287 return GetAndroidToolsDir("prebuilts/gcc/linux-x86/mips",
288 "mips64el-linux-android",
289 "mips64el-linux-android");
Vladimir Marko33bff252017-11-01 14:35:42 +0000290 case InstructionSet::kNone:
David Srbecky3e52aa42015-04-12 07:45:18 +0100291 break;
292 }
293 ADD_FAILURE() << "Invalid isa " << isa;
294 return "";
295}
296
Mathieu Chartier91c91162016-01-15 09:48:15 -0800297std::string CommonRuntimeTestImpl::GetCoreArtLocation() {
Igor Murashkin37743352014-11-13 14:38:00 -0800298 return GetCoreFileLocation("art");
299}
300
Mathieu Chartier91c91162016-01-15 09:48:15 -0800301std::string CommonRuntimeTestImpl::GetCoreOatLocation() {
Igor Murashkin37743352014-11-13 14:38:00 -0800302 return GetCoreFileLocation("oat");
303}
Andreas Gampe7747c8d2014-08-06 14:53:03 -0700304
Mathieu Chartier91c91162016-01-15 09:48:15 -0800305std::unique_ptr<const DexFile> CommonRuntimeTestImpl::LoadExpectSingleDexFile(
306 const char* location) {
Richard Uhlerfbef44d2014-12-23 09:48:51 -0800307 std::vector<std::unique_ptr<const DexFile>> dex_files;
Ian Rogerse63db272014-07-15 15:36:11 -0700308 std::string error_msg;
Richard Uhler66d874d2015-01-15 09:37:19 -0800309 MemMap::Init();
Aart Bik37d6a3b2016-06-21 18:30:10 -0700310 static constexpr bool kVerifyChecksum = true;
David Sehr013fd802018-01-11 22:55:24 -0800311 const ArtDexFileLoader dex_file_loader;
312 if (!dex_file_loader.Open(
Nicolas Geoffray095c6c92017-10-19 13:59:55 +0100313 location, location, /* verify */ true, kVerifyChecksum, &error_msg, &dex_files)) {
Ian Rogerse63db272014-07-15 15:36:11 -0700314 LOG(FATAL) << "Could not open .dex file '" << location << "': " << error_msg << "\n";
Richard Uhlerfbef44d2014-12-23 09:48:51 -0800315 UNREACHABLE();
Ian Rogerse63db272014-07-15 15:36:11 -0700316 } else {
317 CHECK_EQ(1U, dex_files.size()) << "Expected only one dex file in " << location;
Richard Uhlerfbef44d2014-12-23 09:48:51 -0800318 return std::move(dex_files[0]);
Ian Rogerse63db272014-07-15 15:36:11 -0700319 }
320}
321
Mathieu Chartier91c91162016-01-15 09:48:15 -0800322void CommonRuntimeTestImpl::SetUp() {
Andreas Gampe7747c8d2014-08-06 14:53:03 -0700323 SetUpAndroidRoot();
324 SetUpAndroidData(android_data_);
Ian Rogerse63db272014-07-15 15:36:11 -0700325 dalvik_cache_.append(android_data_.c_str());
326 dalvik_cache_.append("/dalvik-cache");
327 int mkdir_result = mkdir(dalvik_cache_.c_str(), 0700);
328 ASSERT_EQ(mkdir_result, 0);
329
Ian Rogerse63db272014-07-15 15:36:11 -0700330 std::string min_heap_string(StringPrintf("-Xms%zdm", gc::Heap::kDefaultInitialSize / MB));
331 std::string max_heap_string(StringPrintf("-Xmx%zdm", gc::Heap::kDefaultMaximumSize / MB));
332
Ian Rogerse63db272014-07-15 15:36:11 -0700333
334 RuntimeOptions options;
Narayan Kamathd1ef4362015-11-12 11:49:06 +0000335 std::string boot_class_path_string = "-Xbootclasspath";
336 for (const std::string &core_dex_file_name : GetLibCoreDexFileNames()) {
337 boot_class_path_string += ":";
338 boot_class_path_string += core_dex_file_name;
339 }
340
Richard Uhlerc2752592015-01-02 13:28:22 -0800341 options.push_back(std::make_pair(boot_class_path_string, nullptr));
Ian Rogerse63db272014-07-15 15:36:11 -0700342 options.push_back(std::make_pair("-Xcheck:jni", nullptr));
Richard Uhlerc2752592015-01-02 13:28:22 -0800343 options.push_back(std::make_pair(min_heap_string, nullptr));
344 options.push_back(std::make_pair(max_heap_string, nullptr));
Andreas Gampe1c5b42f2017-06-15 18:20:45 -0700345 options.push_back(std::make_pair("-XX:SlowDebug=true", nullptr));
Andreas Gampe46c4c852017-06-21 19:49:08 -0700346 static bool gSlowDebugTestFlag = false;
347 RegisterRuntimeDebugFlag(&gSlowDebugTestFlag);
Andreas Gampebb9c6b12015-03-29 13:56:36 -0700348
349 callbacks_.reset(new NoopCompilerCallbacks());
350
Ian Rogerse63db272014-07-15 15:36:11 -0700351 SetUpRuntimeOptions(&options);
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800352
Andreas Gampebb9c6b12015-03-29 13:56:36 -0700353 // Install compiler-callbacks if SetupRuntimeOptions hasn't deleted them.
354 if (callbacks_.get() != nullptr) {
355 options.push_back(std::make_pair("compilercallbacks", callbacks_.get()));
356 }
357
Richard Uhler66d874d2015-01-15 09:37:19 -0800358 PreRuntimeCreate();
Ian Rogerse63db272014-07-15 15:36:11 -0700359 if (!Runtime::Create(options, false)) {
360 LOG(FATAL) << "Failed to create runtime";
361 return;
362 }
Richard Uhler66d874d2015-01-15 09:37:19 -0800363 PostRuntimeCreate();
Ian Rogerse63db272014-07-15 15:36:11 -0700364 runtime_.reset(Runtime::Current());
365 class_linker_ = runtime_->GetClassLinker();
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700366
Andreas Gampea00f0122015-12-16 16:54:35 -0800367 // Runtime::Create acquired the mutator_lock_ that is normally given away when we
368 // Runtime::Start, give it away now and then switch to a more managable ScopedObjectAccess.
369 Thread::Current()->TransitionFromRunnableToSuspended(kNative);
370
371 // Get the boot class path from the runtime so it can be used in tests.
372 boot_class_path_ = class_linker_->GetBootClassPath();
373 ASSERT_FALSE(boot_class_path_.empty());
374 java_lang_dex_file_ = boot_class_path_[0];
375
376 FinalizeSetup();
Andreas Gampe46c4c852017-06-21 19:49:08 -0700377
378 // Ensure that we're really running with debug checks enabled.
379 CHECK(gSlowDebugTestFlag);
Andreas Gampea00f0122015-12-16 16:54:35 -0800380}
381
Mathieu Chartier91c91162016-01-15 09:48:15 -0800382void CommonRuntimeTestImpl::FinalizeSetup() {
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700383 // Initialize maps for unstarted runtime. This needs to be here, as running clinits needs this
384 // set up.
Andreas Gampe9b5cba42015-03-11 09:53:50 -0700385 if (!unstarted_initialized_) {
Andreas Gampe799681b2015-05-15 19:24:12 -0700386 interpreter::UnstartedRuntime::Initialize();
Andreas Gampe9b5cba42015-03-11 09:53:50 -0700387 unstarted_initialized_ = true;
388 }
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700389
Andreas Gampea00f0122015-12-16 16:54:35 -0800390 {
391 ScopedObjectAccess soa(Thread::Current());
392 class_linker_->RunRootClinits();
393 }
Ian Rogerse63db272014-07-15 15:36:11 -0700394
395 // We're back in native, take the opportunity to initialize well known classes.
396 WellKnownClasses::Init(Thread::Current()->GetJniEnv());
397
398 // Create the heap thread pool so that the GC runs in parallel for tests. Normally, the thread
399 // pool is created by the runtime.
400 runtime_->GetHeap()->CreateThreadPool();
401 runtime_->GetHeap()->VerifyHeap(); // Check for heap corruption before the test
Hiroshi Yamauchi4460a842015-03-09 11:57:48 -0700402 // Reduce timinig-dependent flakiness in OOME behavior (eg StubTest.AllocObject).
403 runtime_->GetHeap()->SetMinIntervalHomogeneousSpaceCompactionByOom(0U);
Ian Rogerse63db272014-07-15 15:36:11 -0700404}
405
Mathieu Chartierf70fe3d2017-06-21 15:24:02 -0700406void CommonRuntimeTestImpl::ClearDirectory(const char* dirpath, bool recursive) {
Alex Lighta59dd802014-07-02 16:28:08 -0700407 ASSERT_TRUE(dirpath != nullptr);
408 DIR* dir = opendir(dirpath);
Ian Rogerse63db272014-07-15 15:36:11 -0700409 ASSERT_TRUE(dir != nullptr);
410 dirent* e;
Alex Lighta59dd802014-07-02 16:28:08 -0700411 struct stat s;
Ian Rogerse63db272014-07-15 15:36:11 -0700412 while ((e = readdir(dir)) != nullptr) {
413 if ((strcmp(e->d_name, ".") == 0) || (strcmp(e->d_name, "..") == 0)) {
414 continue;
415 }
Jeff Haof0a3f092014-07-24 16:26:09 -0700416 std::string filename(dirpath);
Ian Rogerse63db272014-07-15 15:36:11 -0700417 filename.push_back('/');
418 filename.append(e->d_name);
Alex Lighta59dd802014-07-02 16:28:08 -0700419 int stat_result = lstat(filename.c_str(), &s);
420 ASSERT_EQ(0, stat_result) << "unable to stat " << filename;
421 if (S_ISDIR(s.st_mode)) {
Mathieu Chartierf70fe3d2017-06-21 15:24:02 -0700422 if (recursive) {
423 ClearDirectory(filename.c_str());
424 int rmdir_result = rmdir(filename.c_str());
425 ASSERT_EQ(0, rmdir_result) << filename;
426 }
Alex Lighta59dd802014-07-02 16:28:08 -0700427 } else {
428 int unlink_result = unlink(filename.c_str());
429 ASSERT_EQ(0, unlink_result) << filename;
430 }
Ian Rogerse63db272014-07-15 15:36:11 -0700431 }
432 closedir(dir);
Alex Lighta59dd802014-07-02 16:28:08 -0700433}
434
Mathieu Chartier91c91162016-01-15 09:48:15 -0800435void CommonRuntimeTestImpl::TearDown() {
Alex Lighta59dd802014-07-02 16:28:08 -0700436 const char* android_data = getenv("ANDROID_DATA");
437 ASSERT_TRUE(android_data != nullptr);
438 ClearDirectory(dalvik_cache_.c_str());
Ian Rogerse63db272014-07-15 15:36:11 -0700439 int rmdir_cache_result = rmdir(dalvik_cache_.c_str());
440 ASSERT_EQ(0, rmdir_cache_result);
Andreas Gampe7747c8d2014-08-06 14:53:03 -0700441 TearDownAndroidData(android_data_, true);
Andreas Gampe3f41a012016-02-18 16:53:41 -0800442 dalvik_cache_.clear();
Ian Rogerse63db272014-07-15 15:36:11 -0700443
Andreas Gampe48864112017-01-19 17:23:17 -0800444 if (runtime_ != nullptr) {
445 runtime_->GetHeap()->VerifyHeap(); // Check for heap corruption after the test
446 }
Ian Rogerse63db272014-07-15 15:36:11 -0700447}
448
Andreas Gampec7d4a582015-09-30 11:52:02 -0700449static std::string GetDexFileName(const std::string& jar_prefix, bool host) {
450 std::string path;
451 if (host) {
Ian Rogerse63db272014-07-15 15:36:11 -0700452 const char* host_dir = getenv("ANDROID_HOST_OUT");
453 CHECK(host_dir != nullptr);
Andreas Gampec7d4a582015-09-30 11:52:02 -0700454 path = host_dir;
455 } else {
456 path = GetAndroidRoot();
Ian Rogerse63db272014-07-15 15:36:11 -0700457 }
Andreas Gampec7d4a582015-09-30 11:52:02 -0700458
459 std::string suffix = host
460 ? "-hostdex" // The host version.
461 : "-testdex"; // The unstripped target version.
462
463 return StringPrintf("%s/framework/%s%s.jar", path.c_str(), jar_prefix.c_str(), suffix.c_str());
464}
465
Mathieu Chartier91c91162016-01-15 09:48:15 -0800466std::vector<std::string> CommonRuntimeTestImpl::GetLibCoreDexFileNames() {
Andreas Gampec7d4a582015-09-30 11:52:02 -0700467 return std::vector<std::string>({GetDexFileName("core-oj", IsHost()),
468 GetDexFileName("core-libart", IsHost())});
Ian Rogerse63db272014-07-15 15:36:11 -0700469}
470
Mathieu Chartier91c91162016-01-15 09:48:15 -0800471std::string CommonRuntimeTestImpl::GetTestAndroidRoot() {
Ian Rogerse63db272014-07-15 15:36:11 -0700472 if (IsHost()) {
473 const char* host_dir = getenv("ANDROID_HOST_OUT");
474 CHECK(host_dir != nullptr);
475 return host_dir;
476 }
477 return GetAndroidRoot();
478}
479
Andreas Gampe1fe5e5c2014-07-11 21:14:35 -0700480// Check that for target builds we have ART_TARGET_NATIVETEST_DIR set.
481#ifdef ART_TARGET
482#ifndef ART_TARGET_NATIVETEST_DIR
483#error "ART_TARGET_NATIVETEST_DIR not set."
484#endif
485// Wrap it as a string literal.
486#define ART_TARGET_NATIVETEST_DIR_STRING STRINGIFY(ART_TARGET_NATIVETEST_DIR) "/"
487#else
488#define ART_TARGET_NATIVETEST_DIR_STRING ""
489#endif
490
Andreas Gampee1459ae2016-06-29 09:36:30 -0700491std::string CommonRuntimeTestImpl::GetTestDexFileName(const char* name) const {
Ian Rogerse63db272014-07-15 15:36:11 -0700492 CHECK(name != nullptr);
493 std::string filename;
494 if (IsHost()) {
495 filename += getenv("ANDROID_HOST_OUT");
496 filename += "/framework/";
497 } else {
Andreas Gampe1fe5e5c2014-07-11 21:14:35 -0700498 filename += ART_TARGET_NATIVETEST_DIR_STRING;
Ian Rogerse63db272014-07-15 15:36:11 -0700499 }
500 filename += "art-gtest-";
501 filename += name;
502 filename += ".jar";
Richard Uhler66d874d2015-01-15 09:37:19 -0800503 return filename;
504}
505
Mathieu Chartier91c91162016-01-15 09:48:15 -0800506std::vector<std::unique_ptr<const DexFile>> CommonRuntimeTestImpl::OpenTestDexFiles(
507 const char* name) {
Richard Uhler66d874d2015-01-15 09:37:19 -0800508 std::string filename = GetTestDexFileName(name);
Aart Bik37d6a3b2016-06-21 18:30:10 -0700509 static constexpr bool kVerifyChecksum = true;
Ian Rogerse63db272014-07-15 15:36:11 -0700510 std::string error_msg;
David Sehr013fd802018-01-11 22:55:24 -0800511 const ArtDexFileLoader dex_file_loader;
Richard Uhlerfbef44d2014-12-23 09:48:51 -0800512 std::vector<std::unique_ptr<const DexFile>> dex_files;
David Sehr013fd802018-01-11 22:55:24 -0800513 bool success = dex_file_loader.Open(filename.c_str(),
514 filename.c_str(),
515 /* verify */ true,
516 kVerifyChecksum,
517 &error_msg, &dex_files);
Ian Rogerse63db272014-07-15 15:36:11 -0700518 CHECK(success) << "Failed to open '" << filename << "': " << error_msg;
Richard Uhlerfbef44d2014-12-23 09:48:51 -0800519 for (auto& dex_file : dex_files) {
Ian Rogerse63db272014-07-15 15:36:11 -0700520 CHECK_EQ(PROT_READ, dex_file->GetPermissions());
521 CHECK(dex_file->IsReadOnly());
522 }
Ian Rogerse63db272014-07-15 15:36:11 -0700523 return dex_files;
524}
525
Mathieu Chartier91c91162016-01-15 09:48:15 -0800526std::unique_ptr<const DexFile> CommonRuntimeTestImpl::OpenTestDexFile(const char* name) {
Richard Uhlerfbef44d2014-12-23 09:48:51 -0800527 std::vector<std::unique_ptr<const DexFile>> vector = OpenTestDexFiles(name);
Ian Rogerse63db272014-07-15 15:36:11 -0700528 EXPECT_EQ(1U, vector.size());
Richard Uhlerfbef44d2014-12-23 09:48:51 -0800529 return std::move(vector[0]);
Ian Rogerse63db272014-07-15 15:36:11 -0700530}
531
Mathieu Chartier91c91162016-01-15 09:48:15 -0800532std::vector<const DexFile*> CommonRuntimeTestImpl::GetDexFiles(jobject jclass_loader) {
Andreas Gampe81c6f8d2015-03-25 17:19:53 -0700533 ScopedObjectAccess soa(Thread::Current());
534
Calin Juravlec79470d2017-07-12 17:37:42 -0700535 StackHandleScope<1> hs(soa.Self());
Andreas Gampe81c6f8d2015-03-25 17:19:53 -0700536 Handle<mirror::ClassLoader> class_loader = hs.NewHandle(
Mathieu Chartier0795f232016-09-27 18:43:30 -0700537 soa.Decode<mirror::ClassLoader>(jclass_loader));
Calin Juravlec79470d2017-07-12 17:37:42 -0700538 return GetDexFiles(soa, class_loader);
539}
Andreas Gampe81c6f8d2015-03-25 17:19:53 -0700540
Calin Juravlec79470d2017-07-12 17:37:42 -0700541std::vector<const DexFile*> CommonRuntimeTestImpl::GetDexFiles(
542 ScopedObjectAccess& soa,
543 Handle<mirror::ClassLoader> class_loader) {
544 std::vector<const DexFile*> ret;
545
546 DCHECK(
547 (class_loader->GetClass() ==
548 soa.Decode<mirror::Class>(WellKnownClasses::dalvik_system_PathClassLoader)) ||
549 (class_loader->GetClass() ==
550 soa.Decode<mirror::Class>(WellKnownClasses::dalvik_system_DelegateLastClassLoader)));
Andreas Gampe81c6f8d2015-03-25 17:19:53 -0700551
552 // The class loader is a PathClassLoader which inherits from BaseDexClassLoader.
553 // We need to get the DexPathList and loop through it.
Andreas Gampe08883de2016-11-08 13:20:52 -0800554 ArtField* cookie_field = jni::DecodeArtField(WellKnownClasses::dalvik_system_DexFile_cookie);
Mathieu Chartierc7853442015-03-27 14:35:38 -0700555 ArtField* dex_file_field =
Andreas Gampe08883de2016-11-08 13:20:52 -0800556 jni::DecodeArtField(WellKnownClasses::dalvik_system_DexPathList__Element_dexFile);
Mathieu Chartier3398c782016-09-30 10:27:43 -0700557 ObjPtr<mirror::Object> dex_path_list =
Andreas Gampe08883de2016-11-08 13:20:52 -0800558 jni::DecodeArtField(WellKnownClasses::dalvik_system_BaseDexClassLoader_pathList)->
559 GetObject(class_loader.Get());
Mathieu Chartierc7853442015-03-27 14:35:38 -0700560 if (dex_path_list != nullptr && dex_file_field!= nullptr && cookie_field != nullptr) {
Andreas Gampe81c6f8d2015-03-25 17:19:53 -0700561 // DexPathList has an array dexElements of Elements[] which each contain a dex file.
Mathieu Chartier3398c782016-09-30 10:27:43 -0700562 ObjPtr<mirror::Object> dex_elements_obj =
Andreas Gampe08883de2016-11-08 13:20:52 -0800563 jni::DecodeArtField(WellKnownClasses::dalvik_system_DexPathList_dexElements)->
564 GetObject(dex_path_list);
Andreas Gampe81c6f8d2015-03-25 17:19:53 -0700565 // Loop through each dalvik.system.DexPathList$Element's dalvik.system.DexFile and look
566 // at the mCookie which is a DexFile vector.
567 if (dex_elements_obj != nullptr) {
Calin Juravlec79470d2017-07-12 17:37:42 -0700568 StackHandleScope<1> hs(soa.Self());
Andreas Gampe81c6f8d2015-03-25 17:19:53 -0700569 Handle<mirror::ObjectArray<mirror::Object>> dex_elements =
570 hs.NewHandle(dex_elements_obj->AsObjectArray<mirror::Object>());
571 for (int32_t i = 0; i < dex_elements->GetLength(); ++i) {
Mathieu Chartier3398c782016-09-30 10:27:43 -0700572 ObjPtr<mirror::Object> element = dex_elements->GetWithoutChecks(i);
Andreas Gampe81c6f8d2015-03-25 17:19:53 -0700573 if (element == nullptr) {
574 // Should never happen, fall back to java code to throw a NPE.
575 break;
576 }
Mathieu Chartier3398c782016-09-30 10:27:43 -0700577 ObjPtr<mirror::Object> dex_file = dex_file_field->GetObject(element);
Andreas Gampe81c6f8d2015-03-25 17:19:53 -0700578 if (dex_file != nullptr) {
Mathieu Chartier3398c782016-09-30 10:27:43 -0700579 ObjPtr<mirror::LongArray> long_array = cookie_field->GetObject(dex_file)->AsLongArray();
Andreas Gampe81c6f8d2015-03-25 17:19:53 -0700580 DCHECK(long_array != nullptr);
581 int32_t long_array_size = long_array->GetLength();
Mathieu Chartiere58991b2015-10-13 07:59:34 -0700582 for (int32_t j = kDexFileIndexStart; j < long_array_size; ++j) {
Andreas Gampe81c6f8d2015-03-25 17:19:53 -0700583 const DexFile* cp_dex_file = reinterpret_cast<const DexFile*>(static_cast<uintptr_t>(
584 long_array->GetWithoutChecks(j)));
585 if (cp_dex_file == nullptr) {
586 LOG(WARNING) << "Null DexFile";
587 continue;
588 }
589 ret.push_back(cp_dex_file);
590 }
591 }
592 }
593 }
594 }
595
596 return ret;
597}
598
Mathieu Chartier91c91162016-01-15 09:48:15 -0800599const DexFile* CommonRuntimeTestImpl::GetFirstDexFile(jobject jclass_loader) {
Andreas Gampe81c6f8d2015-03-25 17:19:53 -0700600 std::vector<const DexFile*> tmp(GetDexFiles(jclass_loader));
601 DCHECK(!tmp.empty());
602 const DexFile* ret = tmp[0];
603 DCHECK(ret != nullptr);
604 return ret;
605}
606
Nicolas Geoffrayd01f60c2016-10-28 14:45:48 +0100607jobject CommonRuntimeTestImpl::LoadMultiDex(const char* first_dex_name,
608 const char* second_dex_name) {
609 std::vector<std::unique_ptr<const DexFile>> first_dex_files = OpenTestDexFiles(first_dex_name);
610 std::vector<std::unique_ptr<const DexFile>> second_dex_files = OpenTestDexFiles(second_dex_name);
611 std::vector<const DexFile*> class_path;
612 CHECK_NE(0U, first_dex_files.size());
613 CHECK_NE(0U, second_dex_files.size());
614 for (auto& dex_file : first_dex_files) {
615 class_path.push_back(dex_file.get());
616 loaded_dex_files_.push_back(std::move(dex_file));
617 }
618 for (auto& dex_file : second_dex_files) {
619 class_path.push_back(dex_file.get());
620 loaded_dex_files_.push_back(std::move(dex_file));
621 }
622
623 Thread* self = Thread::Current();
624 jobject class_loader = Runtime::Current()->GetClassLinker()->CreatePathClassLoader(self,
625 class_path);
626 self->SetClassLoaderOverride(class_loader);
627 return class_loader;
628}
629
Mathieu Chartier91c91162016-01-15 09:48:15 -0800630jobject CommonRuntimeTestImpl::LoadDex(const char* dex_name) {
Calin Juravle7865ac72017-06-28 11:03:12 -0700631 jobject class_loader = LoadDexInPathClassLoader(dex_name, nullptr);
632 Thread::Current()->SetClassLoaderOverride(class_loader);
633 return class_loader;
634}
635
636jobject CommonRuntimeTestImpl::LoadDexInWellKnownClassLoader(const std::string& dex_name,
637 jclass loader_class,
638 jobject parent_loader) {
639 std::vector<std::unique_ptr<const DexFile>> dex_files = OpenTestDexFiles(dex_name.c_str());
Richard Uhlerfbef44d2014-12-23 09:48:51 -0800640 std::vector<const DexFile*> class_path;
Ian Rogerse63db272014-07-15 15:36:11 -0700641 CHECK_NE(0U, dex_files.size());
Richard Uhlerfbef44d2014-12-23 09:48:51 -0800642 for (auto& dex_file : dex_files) {
643 class_path.push_back(dex_file.get());
Richard Uhlerfbef44d2014-12-23 09:48:51 -0800644 loaded_dex_files_.push_back(std::move(dex_file));
Ian Rogerse63db272014-07-15 15:36:11 -0700645 }
Ian Rogers68d8b422014-07-17 11:09:10 -0700646 Thread* self = Thread::Current();
Calin Juravle7865ac72017-06-28 11:03:12 -0700647 ScopedObjectAccess soa(self);
648
649 jobject result = Runtime::Current()->GetClassLinker()->CreateWellKnownClassLoader(
650 self,
651 class_path,
652 loader_class,
653 parent_loader);
654
655 {
656 // Verify we build the correct chain.
657
658 ObjPtr<mirror::ClassLoader> actual_class_loader = soa.Decode<mirror::ClassLoader>(result);
659 // Verify that the result has the correct class.
660 CHECK_EQ(soa.Decode<mirror::Class>(loader_class), actual_class_loader->GetClass());
661 // Verify that the parent is not null. The boot class loader will be set up as a
662 // proper object.
663 ObjPtr<mirror::ClassLoader> actual_parent(actual_class_loader->GetParent());
664 CHECK(actual_parent != nullptr);
665
666 if (parent_loader != nullptr) {
667 // We were given a parent. Verify that it's what we expect.
668 ObjPtr<mirror::ClassLoader> expected_parent = soa.Decode<mirror::ClassLoader>(parent_loader);
669 CHECK_EQ(expected_parent, actual_parent);
670 } else {
671 // No parent given. The parent must be the BootClassLoader.
672 CHECK(Runtime::Current()->GetClassLinker()->IsBootClassLoader(soa, actual_parent));
673 }
674 }
675
676 return result;
677}
678
679jobject CommonRuntimeTestImpl::LoadDexInPathClassLoader(const std::string& dex_name,
680 jobject parent_loader) {
681 return LoadDexInWellKnownClassLoader(dex_name,
682 WellKnownClasses::dalvik_system_PathClassLoader,
683 parent_loader);
684}
685
686jobject CommonRuntimeTestImpl::LoadDexInDelegateLastClassLoader(const std::string& dex_name,
687 jobject parent_loader) {
688 return LoadDexInWellKnownClassLoader(dex_name,
689 WellKnownClasses::dalvik_system_DelegateLastClassLoader,
690 parent_loader);
Ian Rogerse63db272014-07-15 15:36:11 -0700691}
692
Mathieu Chartier91c91162016-01-15 09:48:15 -0800693std::string CommonRuntimeTestImpl::GetCoreFileLocation(const char* suffix) {
Igor Murashkin37743352014-11-13 14:38:00 -0800694 CHECK(suffix != nullptr);
695
696 std::string location;
697 if (IsHost()) {
698 const char* host_dir = getenv("ANDROID_HOST_OUT");
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700699 CHECK(host_dir != nullptr);
Richard Uhler67e1dc52017-02-06 16:50:17 +0000700 location = StringPrintf("%s/framework/core.%s", host_dir, suffix);
Igor Murashkin37743352014-11-13 14:38:00 -0800701 } else {
Richard Uhler67e1dc52017-02-06 16:50:17 +0000702 location = StringPrintf("/data/art-test/core.%s", suffix);
Igor Murashkin37743352014-11-13 14:38:00 -0800703 }
704
705 return location;
706}
707
Calin Juravlec79470d2017-07-12 17:37:42 -0700708std::string CommonRuntimeTestImpl::CreateClassPath(
709 const std::vector<std::unique_ptr<const DexFile>>& dex_files) {
710 CHECK(!dex_files.empty());
711 std::string classpath = dex_files[0]->GetLocation();
712 for (size_t i = 1; i < dex_files.size(); i++) {
713 classpath += ":" + dex_files[i]->GetLocation();
714 }
715 return classpath;
716}
717
718std::string CommonRuntimeTestImpl::CreateClassPathWithChecksums(
719 const std::vector<std::unique_ptr<const DexFile>>& dex_files) {
720 CHECK(!dex_files.empty());
721 std::string classpath = dex_files[0]->GetLocation() + "*" +
722 std::to_string(dex_files[0]->GetLocationChecksum());
723 for (size_t i = 1; i < dex_files.size(); i++) {
724 classpath += ":" + dex_files[i]->GetLocation() + "*" +
725 std::to_string(dex_files[i]->GetLocationChecksum());
726 }
727 return classpath;
728}
729
Andreas Gampe26761f72017-07-20 18:00:39 -0700730void CommonRuntimeTestImpl::FillHeap(Thread* self,
731 ClassLinker* class_linker,
732 VariableSizedHandleScope* handle_scope) {
733 DCHECK(handle_scope != nullptr);
734
735 Runtime::Current()->GetHeap()->SetIdealFootprint(1 * GB);
736
737 // Class java.lang.Object.
738 Handle<mirror::Class> c(handle_scope->NewHandle(
739 class_linker->FindSystemClass(self, "Ljava/lang/Object;")));
740 // Array helps to fill memory faster.
741 Handle<mirror::Class> ca(handle_scope->NewHandle(
742 class_linker->FindSystemClass(self, "[Ljava/lang/Object;")));
743
744 // Start allocating with ~128K
745 size_t length = 128 * KB;
746 while (length > 40) {
747 const int32_t array_length = length / 4; // Object[] has elements of size 4.
748 MutableHandle<mirror::Object> h(handle_scope->NewHandle<mirror::Object>(
749 mirror::ObjectArray<mirror::Object>::Alloc(self, ca.Get(), array_length)));
750 if (self->IsExceptionPending() || h == nullptr) {
751 self->ClearException();
752
753 // Try a smaller length
754 length = length / 2;
755 // Use at most a quarter the reported free space.
756 size_t mem = Runtime::Current()->GetHeap()->GetFreeMemory();
757 if (length * 4 > mem) {
758 length = mem / 4;
759 }
760 }
761 }
762
763 // Allocate simple objects till it fails.
764 while (!self->IsExceptionPending()) {
765 handle_scope->NewHandle<mirror::Object>(c->AllocObject(self));
766 }
767 self->ClearException();
768}
769
770void CommonRuntimeTestImpl::SetUpRuntimeOptionsForFillHeap(RuntimeOptions *options) {
771 // Use a smaller heap
772 bool found = false;
773 for (std::pair<std::string, const void*>& pair : *options) {
774 if (pair.first.find("-Xmx") == 0) {
775 pair.first = "-Xmx4M"; // Smallest we can go.
776 found = true;
777 }
778 }
779 if (!found) {
780 options->emplace_back("-Xmx4M", nullptr);
781 }
782}
783
Ian Rogerse63db272014-07-15 15:36:11 -0700784CheckJniAbortCatcher::CheckJniAbortCatcher() : vm_(Runtime::Current()->GetJavaVM()) {
Ian Rogers68d8b422014-07-17 11:09:10 -0700785 vm_->SetCheckJniAbortHook(Hook, &actual_);
Ian Rogerse63db272014-07-15 15:36:11 -0700786}
787
788CheckJniAbortCatcher::~CheckJniAbortCatcher() {
Ian Rogers68d8b422014-07-17 11:09:10 -0700789 vm_->SetCheckJniAbortHook(nullptr, nullptr);
Ian Rogerse63db272014-07-15 15:36:11 -0700790 EXPECT_TRUE(actual_.empty()) << actual_;
791}
792
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700793void CheckJniAbortCatcher::Check(const std::string& expected_text) {
794 Check(expected_text.c_str());
795}
796
Ian Rogerse63db272014-07-15 15:36:11 -0700797void CheckJniAbortCatcher::Check(const char* expected_text) {
798 EXPECT_TRUE(actual_.find(expected_text) != std::string::npos) << "\n"
799 << "Expected to find: " << expected_text << "\n"
800 << "In the output : " << actual_;
801 actual_.clear();
802}
803
804void CheckJniAbortCatcher::Hook(void* data, const std::string& reason) {
805 // We use += because when we're hooking the aborts like this, multiple problems can be found.
806 *reinterpret_cast<std::string*>(data) += reason;
807}
808
809} // namespace art