1*795d594fSAndroid Build Coastguard Worker /* 2*795d594fSAndroid Build Coastguard Worker * Copyright (C) 2017 The Android Open Source Project 3*795d594fSAndroid Build Coastguard Worker * 4*795d594fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*795d594fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*795d594fSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*795d594fSAndroid Build Coastguard Worker * 8*795d594fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*795d594fSAndroid Build Coastguard Worker * 10*795d594fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*795d594fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*795d594fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*795d594fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*795d594fSAndroid Build Coastguard Worker * limitations under the License. 15*795d594fSAndroid Build Coastguard Worker */ 16*795d594fSAndroid Build Coastguard Worker 17*795d594fSAndroid Build Coastguard Worker #ifndef ART_RUNTIME_DEXOPT_TEST_H_ 18*795d594fSAndroid Build Coastguard Worker #define ART_RUNTIME_DEXOPT_TEST_H_ 19*795d594fSAndroid Build Coastguard Worker 20*795d594fSAndroid Build Coastguard Worker #include <string> 21*795d594fSAndroid Build Coastguard Worker #include <vector> 22*795d594fSAndroid Build Coastguard Worker 23*795d594fSAndroid Build Coastguard Worker #include "base/macros.h" 24*795d594fSAndroid Build Coastguard Worker #include "dex2oat_environment_test.h" 25*795d594fSAndroid Build Coastguard Worker 26*795d594fSAndroid Build Coastguard Worker namespace art HIDDEN { 27*795d594fSAndroid Build Coastguard Worker 28*795d594fSAndroid Build Coastguard Worker class DexoptTest : public Dex2oatEnvironmentTest { 29*795d594fSAndroid Build Coastguard Worker public: 30*795d594fSAndroid Build Coastguard Worker void SetUp() override; 31*795d594fSAndroid Build Coastguard Worker 32*795d594fSAndroid Build Coastguard Worker void PreRuntimeCreate() override; 33*795d594fSAndroid Build Coastguard Worker 34*795d594fSAndroid Build Coastguard Worker void PostRuntimeCreate() override; 35*795d594fSAndroid Build Coastguard Worker 36*795d594fSAndroid Build Coastguard Worker std::string GenerateAlternateImage(const std::string& scratch_dir); 37*795d594fSAndroid Build Coastguard Worker 38*795d594fSAndroid Build Coastguard Worker // Generate an oat file for the purposes of test. 39*795d594fSAndroid Build Coastguard Worker // The oat file will be generated for dex_location in the given oat_location 40*795d594fSAndroid Build Coastguard Worker // with the following configuration: 41*795d594fSAndroid Build Coastguard Worker // filter - controls the compilation filter 42*795d594fSAndroid Build Coastguard Worker // with_alternate_image - if true, the oat file will be generated with an 43*795d594fSAndroid Build Coastguard Worker // image checksum different than the current image checksum. 44*795d594fSAndroid Build Coastguard Worker void GenerateOatForTest(const std::string& dex_location, 45*795d594fSAndroid Build Coastguard Worker const std::string& oat_location, 46*795d594fSAndroid Build Coastguard Worker CompilerFilter::Filter filter, 47*795d594fSAndroid Build Coastguard Worker bool with_alternate_image, 48*795d594fSAndroid Build Coastguard Worker const char* compilation_reason = nullptr, 49*795d594fSAndroid Build Coastguard Worker const std::vector<std::string>& extra_args = {}); 50*795d594fSAndroid Build Coastguard Worker 51*795d594fSAndroid Build Coastguard Worker // Generate an odex file for the purposes of test. 52*795d594fSAndroid Build Coastguard Worker void GenerateOdexForTest(const std::string& dex_location, 53*795d594fSAndroid Build Coastguard Worker const std::string& odex_location, 54*795d594fSAndroid Build Coastguard Worker CompilerFilter::Filter filter, 55*795d594fSAndroid Build Coastguard Worker const char* compilation_reason = nullptr, 56*795d594fSAndroid Build Coastguard Worker const std::vector<std::string>& extra_args = {}); 57*795d594fSAndroid Build Coastguard Worker 58*795d594fSAndroid Build Coastguard Worker // Generate an oat file for the given dex location in its oat location (under 59*795d594fSAndroid Build Coastguard Worker // the dalvik cache). 60*795d594fSAndroid Build Coastguard Worker void GenerateOatForTest(const char* dex_location, 61*795d594fSAndroid Build Coastguard Worker CompilerFilter::Filter filter, 62*795d594fSAndroid Build Coastguard Worker bool with_alternate_image); 63*795d594fSAndroid Build Coastguard Worker 64*795d594fSAndroid Build Coastguard Worker // Generate a standard oat file in the oat location. 65*795d594fSAndroid Build Coastguard Worker void GenerateOatForTest(const char* dex_location, CompilerFilter::Filter filter); 66*795d594fSAndroid Build Coastguard Worker 67*795d594fSAndroid Build Coastguard Worker bool Dex2Oat(const std::vector<std::string>& args, std::string* error_msg); 68*795d594fSAndroid Build Coastguard Worker 69*795d594fSAndroid Build Coastguard Worker private: 70*795d594fSAndroid Build Coastguard Worker // Reserve memory around where the image will be loaded so other memory 71*795d594fSAndroid Build Coastguard Worker // won't conflict when it comes time to load the image. 72*795d594fSAndroid Build Coastguard Worker // This can be called with an already loaded image to reserve the space 73*795d594fSAndroid Build Coastguard Worker // around it. 74*795d594fSAndroid Build Coastguard Worker void ReserveImageSpace(); 75*795d594fSAndroid Build Coastguard Worker 76*795d594fSAndroid Build Coastguard Worker // Reserve a chunk of memory for the image space in the given range. 77*795d594fSAndroid Build Coastguard Worker // Only has effect for chunks with a positive number of bytes. 78*795d594fSAndroid Build Coastguard Worker void ReserveImageSpaceChunk(uintptr_t start, uintptr_t end); 79*795d594fSAndroid Build Coastguard Worker 80*795d594fSAndroid Build Coastguard Worker // Unreserve any memory reserved by ReserveImageSpace. This should be called 81*795d594fSAndroid Build Coastguard Worker // before the image is loaded. 82*795d594fSAndroid Build Coastguard Worker void UnreserveImageSpace(); 83*795d594fSAndroid Build Coastguard Worker 84*795d594fSAndroid Build Coastguard Worker std::vector<MemMap> image_reservation_; 85*795d594fSAndroid Build Coastguard Worker }; 86*795d594fSAndroid Build Coastguard Worker 87*795d594fSAndroid Build Coastguard Worker } // namespace art 88*795d594fSAndroid Build Coastguard Worker 89*795d594fSAndroid Build Coastguard Worker #endif // ART_RUNTIME_DEXOPT_TEST_H_ 90