method_lowering_infos_.data(), count);
}
+bool MIRGraph::SkipCompilationByName(const std::string& methodname) {
+ return cu_->compiler_driver->SkipCompilation(methodname);
+}
+
} // namespace art
bool SkipCompilation(std::string* skip_message);
/*
+ * Should we skip the compilation of this method based on its name?
+ */
+ bool SkipCompilationByName(const std::string& methodname);
+
+ /*
* Parse dex method and add MIR at current insert point. Returns id (which is
* actually the index of the method in the m_units_ array).
*/
PassDriverMEOpts pass_driver(GetPreOptPassManager(), GetPostOptPassManager(), &cu);
pass_driver.Launch();
+ /* For non-leaf methods check if we should skip compilation when the profiler is enabled. */
+ if (cu.compiler_driver->ProfilePresent()
+ && !cu.mir_graph->MethodIsLeaf()
+ && cu.mir_graph->SkipCompilationByName(PrettyMethod(method_idx, dex_file))) {
+ cu.EndTiming();
+ return nullptr;
+ }
+
if (cu.enable_debug & (1 << kDebugDumpCheckStats)) {
cu.mir_graph->DumpCheckStats();
}
// given, too all compilations.
static constexpr bool kRestrictCompilationFiltersToImage = true;
-// Print additional info during profile guided compilation.
-static constexpr bool kDebugProfileGuidedCompilation = false;
-
static double Percentage(size_t x, size_t y) {
return 100.0 * (static_cast<double>(x)) / (static_cast<double>(x + y));
}
const std::string& dump_cfg_file_name, bool dump_cfg_append,
CumulativeLogger* timer, int swap_fd,
const std::string& profile_file)
- : compiler_options_(compiler_options),
+ : profile_present_(false),
+ compiler_options_(compiler_options),
verification_results_(verification_results),
method_inliner_map_(method_inliner_map),
compiler_(Compiler::Create(this, compiler_kind)),
// Read the profile file if one is provided.
if (!profile_file.empty()) {
- profile_compilation_info_.reset(new ProfileCompilationInfo(profile_file));
- LOG(INFO) << "Using profile data from file " << profile_file;
+ profile_present_ = profile_file_.LoadFile(profile_file);
+ if (profile_present_) {
+ LOG(INFO) << "Using profile data form file " << profile_file;
+ } else {
+ LOG(INFO) << "Failed to load profile file " << profile_file;
+ }
}
}
(verified_method->GetEncounteredVerificationFailures() &
(verifier::VERIFY_ERROR_FORCE_INTERPRETER | verifier::VERIFY_ERROR_LOCKING)) == 0 &&
// Is eligable for compilation by methods-to-compile filter.
- driver->IsMethodToCompile(method_ref) &&
- driver->ShouldCompileBasedOnProfile(method_ref);
-
+ driver->IsMethodToCompile(method_ref);
if (compile) {
// NOTE: if compiler declines to compile this method, it will return null.
compiled_method = driver->GetCompiler()->Compile(code_item, access_flags, invoke_type,
return methods_to_compile_->find(tmp.c_str()) != methods_to_compile_->end();
}
-bool CompilerDriver::ShouldCompileBasedOnProfile(const MethodReference& method_ref) const {
- if (profile_compilation_info_ == nullptr) {
- // If we miss profile information it means that we don't do a profile guided compilation.
- // Return true, and let the other filters decide if the method should be compiled.
- return true;
- }
- bool result = profile_compilation_info_->ContainsMethod(method_ref);
-
- if (kDebugProfileGuidedCompilation) {
- LOG(INFO) << "[ProfileGuidedCompilation] "
- << (result ? "Compiled" : "Skipped") << " method:"
- << PrettyMethod(method_ref.dex_method_index, *method_ref.dex_file, true);
- }
- return result;
-}
-
class ResolveCatchBlockExceptionsClassVisitor : public ClassVisitor {
public:
ResolveCatchBlockExceptionsClassVisitor(
void CompilerDriver::Compile(jobject class_loader, const std::vector<const DexFile*>& dex_files,
ThreadPool* thread_pool, TimingLogger* timings) {
- if (profile_compilation_info_ != nullptr) {
- if (!profile_compilation_info_->Load(dex_files)) {
- LOG(WARNING) << "Failed to load offline profile info from "
- << profile_compilation_info_->GetFilename()
- << ". No methods will be compiled";
- } else if (kDebugProfileGuidedCompilation) {
- LOG(INFO) << "[ProfileGuidedCompilation] "
- << profile_compilation_info_->DumpInfo();
- }
- }
for (size_t i = 0; i != dex_files.size(); ++i) {
const DexFile* dex_file = dex_files[i];
CHECK(dex_file != nullptr);
return freezing_constructor_classes_.count(ClassReference(dex_file, class_def_index)) != 0;
}
+bool CompilerDriver::SkipCompilation(const std::string& method_name) {
+ if (!profile_present_) {
+ return false;
+ }
+ // First find the method in the profile file.
+ ProfileFile::ProfileData data;
+ if (!profile_file_.GetProfileData(&data, method_name)) {
+ // Not in profile, no information can be determined.
+ if (kIsDebugBuild) {
+ VLOG(compiler) << "not compiling " << method_name << " because it's not in the profile";
+ }
+ return true;
+ }
+
+ // Methods that comprise top_k_threshold % of the total samples will be compiled.
+ // Compare against the start of the topK percentage bucket just in case the threshold
+ // falls inside a bucket.
+ bool compile = data.GetTopKUsedPercentage() - data.GetUsedPercent()
+ <= compiler_options_->GetTopKProfileThreshold();
+ if (kIsDebugBuild) {
+ if (compile) {
+ LOG(INFO) << "compiling method " << method_name << " because its usage is part of top "
+ << data.GetTopKUsedPercentage() << "% with a percent of " << data.GetUsedPercent() << "%"
+ << " (topKThreshold=" << compiler_options_->GetTopKProfileThreshold() << ")";
+ } else {
+ VLOG(compiler) << "not compiling method " << method_name
+ << " because it's not part of leading " << compiler_options_->GetTopKProfileThreshold()
+ << "% samples)";
+ }
+ }
+ return !compile;
+}
+
std::string CompilerDriver::GetMemoryUsageString(bool extended) const {
std::ostringstream oss;
Runtime* const runtime = Runtime::Current();
#include "compiler.h"
#include "dex_file.h"
#include "driver/compiled_method_storage.h"
-#include "jit/offline_profiling_info.h"
#include "invoke_type.h"
#include "method_reference.h"
#include "mirror/class.h" // For mirror::Class::Status.
#include "os.h"
+#include "profiler.h"
#include "runtime.h"
#include "safe_map.h"
#include "thread_pool.h"
return compiler_.get();
}
+ bool ProfilePresent() const {
+ return profile_present_;
+ }
+
// Are we compiling and creating an image file?
bool IsBootImage() const {
return boot_image_;
// Checks whether the provided method should be compiled, i.e., is in method_to_compile_.
bool IsMethodToCompile(const MethodReference& method_ref) const;
- // Checks whether profile guided compilation is enabled and if the method should be compiled
- // according to the profile file.
- bool ShouldCompileBasedOnProfile(const MethodReference& method_ref) const;
-
void RecordClassStatus(ClassReference ref, mirror::Class::Status status)
REQUIRES(!compiled_classes_lock_);
uint16_t class_def_idx,
const DexFile& dex_file) const;
+ // Should the compiler run on this method given profile information?
+ bool SkipCompilation(const std::string& method_name);
+
// Get memory usage during compilation.
std::string GetMemoryUsageString(bool extended) const;
ThreadPool* thread_pool, TimingLogger* timings)
REQUIRES(!Locks::mutator_lock_);
+ ProfileFile profile_file_;
+ bool profile_present_;
+
const CompilerOptions* const compiler_options_;
VerificationResults* const verification_results_;
DexFileToMethodInlinerMap* const method_inliner_map_;
// This option may be restricted to the boot image, depending on a flag in the implementation.
std::unique_ptr<std::unordered_set<std::string>> methods_to_compile_;
- // Info for profile guided compilation.
- std::unique_ptr<ProfileCompilationInfo> profile_compilation_info_;
-
bool had_hard_verifier_failure_;
size_t thread_count_;
uint64_t last_update_ns = code_cache_->GetLastUpdateTimeNs();
if (offline_profile_info_->NeedsSaving(last_update_ns)) {
- VLOG(profiler) << "Initiate save profiling information to: " << filename;
+ VLOG(profiler) << "Iniate save profiling information to: " << filename;
std::set<ArtMethod*> methods;
{
ScopedObjectAccess soa(Thread::Current());
}
}
+
void OfflineProfilingInfo::AddMethodInfo(ArtMethod* method, DexFileToMethodsMap* info) {
DCHECK(method != nullptr);
const DexFile* dex_file = method->GetDexFile();
info_it->second.insert(method->GetDexMethodIndex());
}
-enum OpenMode {
- READ,
- READ_WRITE
-};
-
-static int OpenFile(const std::string& filename, OpenMode open_mode) {
- int fd = -1;
- switch (open_mode) {
- case READ:
- fd = open(filename.c_str(), O_RDONLY);
- break;
- case READ_WRITE:
- // TODO(calin) allow the shared uid of the app to access the file.
- fd = open(filename.c_str(),
- O_CREAT | O_WRONLY | O_TRUNC | O_NOFOLLOW | O_CLOEXEC,
- S_IRUSR | S_IWUSR);
- break;
- }
-
+static int OpenOrCreateFile(const std::string& filename) {
+ // TODO(calin) allow the shared uid of the app to access the file.
+ int fd = open(filename.c_str(),
+ O_CREAT | O_WRONLY | O_TRUNC | O_NOFOLLOW | O_CLOEXEC,
+ S_IRUSR | S_IWUSR);
if (fd < 0) {
PLOG(WARNING) << "Failed to open profile file " << filename;
return -1;
PLOG(WARNING) << "Failed to lock profile file " << filename;
return -1;
}
+
return fd;
}
} while (length > 0);
}
-static constexpr const char kFieldSeparator = ',';
-static constexpr const char kLineSeparator = '\n';
+static constexpr char kFieldSeparator = ',';
+static constexpr char kLineSeparator = '\n';
/**
* Serialization format:
**/
bool OfflineProfilingInfo::Serialize(const std::string& filename,
const DexFileToMethodsMap& info) const {
- int fd = OpenFile(filename, READ_WRITE);
+ int fd = OpenOrCreateFile(filename);
if (fd == -1) {
return false;
}
return CloseDescriptorForFile(fd, filename);
}
-
-// TODO(calin): This a duplicate of Utils::Split fixing the case where the first character
-// is the separator. Merge the fix into Utils::Split once verified that it doesn't break its users.
-static void SplitString(const std::string& s, char separator, std::vector<std::string>* result) {
- const char* p = s.data();
- const char* end = p + s.size();
- // Check if the first character is the separator.
- if (p != end && *p ==separator) {
- result->push_back("");
- ++p;
- }
- // Process the rest of the characters.
- while (p != end) {
- if (*p == separator) {
- ++p;
- } else {
- const char* start = p;
- while (++p != end && *p != separator) {
- // Skip to the next occurrence of the separator.
- }
- result->push_back(std::string(start, p - start));
- }
- }
-}
-
-bool ProfileCompilationInfo::ProcessLine(const std::string& line,
- const std::vector<const DexFile*>& dex_files) {
- std::vector<std::string> parts;
- SplitString(line, kFieldSeparator, &parts);
- if (parts.size() < 3) {
- LOG(WARNING) << "Invalid line: " << line;
- return false;
- }
-
- const std::string& multidex_suffix = parts[0];
- uint32_t checksum;
- if (!ParseInt(parts[1].c_str(), &checksum)) {
- return false;
- }
-
- const DexFile* current_dex_file = nullptr;
- for (auto dex_file : dex_files) {
- if (DexFile::GetMultiDexSuffix(dex_file->GetLocation()) == multidex_suffix) {
- if (checksum != dex_file->GetLocationChecksum()) {
- LOG(WARNING) << "Checksum mismatch for "
- << dex_file->GetLocation() << " when parsing " << filename_;
- return false;
- }
- current_dex_file = dex_file;
- break;
- }
- }
- if (current_dex_file == nullptr) {
- return true;
- }
-
- for (size_t i = 2; i < parts.size(); i++) {
- uint32_t method_idx;
- if (!ParseInt(parts[i].c_str(), &method_idx)) {
- LOG(WARNING) << "Cannot parse method_idx " << parts[i];
- return false;
- }
- uint16_t class_idx = current_dex_file->GetMethodId(method_idx).class_idx_;
- auto info_it = info_.find(current_dex_file);
- if (info_it == info_.end()) {
- info_it = info_.Put(current_dex_file, ClassToMethodsMap());
- }
- ClassToMethodsMap& class_map = info_it->second;
- auto class_it = class_map.find(class_idx);
- if (class_it == class_map.end()) {
- class_it = class_map.Put(class_idx, std::set<uint32_t>());
- }
- class_it->second.insert(method_idx);
- }
- return true;
-}
-
-// Parses the buffer (of length n) starting from start_from and identify new lines
-// based on kLineSeparator marker.
-// Returns the first position after kLineSeparator in the buffer (starting from start_from),
-// or -1 if the marker doesn't appear.
-// The processed characters are appended to the given line.
-static int GetLineFromBuffer(char* buffer, int n, int start_from, std::string& line) {
- if (start_from >= n) {
- return -1;
- }
- int new_line_pos = -1;
- for (int i = start_from; i < n; i++) {
- if (buffer[i] == kLineSeparator) {
- new_line_pos = i;
- break;
- }
- }
- int append_limit = new_line_pos == -1 ? n : new_line_pos;
- line.append(buffer + start_from, append_limit - start_from);
- // Jump over kLineSeparator and return the position of the next character.
- return new_line_pos == -1 ? new_line_pos : new_line_pos + 1;
-}
-
-bool ProfileCompilationInfo::Load(const std::vector<const DexFile*>& dex_files) {
- if (dex_files.empty()) {
- return true;
- }
- if (kIsDebugBuild) {
- // In debug builds verify that the multidex suffixes are unique.
- std::set<std::string> suffixes;
- for (auto dex_file : dex_files) {
- std::string multidex_suffix = DexFile::GetMultiDexSuffix(dex_file->GetLocation());
- DCHECK(suffixes.find(multidex_suffix) == suffixes.end())
- << "DexFiles appear to belong to different apks."
- << " There are multiple dex files with the same multidex suffix: "
- << multidex_suffix;
- suffixes.insert(multidex_suffix);
- }
- }
- info_.clear();
-
- int fd = OpenFile(filename_, READ);
- if (fd == -1) {
- return false;
- }
-
- std::string current_line;
- const int kBufferSize = 1024;
- char buffer[kBufferSize];
- bool success = true;
-
- while (success) {
- int n = read(fd, buffer, kBufferSize);
- if (n < 0) {
- PLOG(WARNING) << "Error when reading profile file " << filename_;
- success = false;
- break;
- } else if (n == 0) {
- break;
- }
- // Detect the new lines from the buffer. If we manage to complete a line,
- // process it. Otherwise append to the current line.
- int current_start_pos = 0;
- while (current_start_pos < n) {
- current_start_pos = GetLineFromBuffer(buffer, n, current_start_pos, current_line);
- if (current_start_pos == -1) {
- break;
- }
- if (!ProcessLine(current_line, dex_files)) {
- success = false;
- break;
- }
- // Reset the current line (we just processed it).
- current_line.clear();
- }
- }
- if (!success) {
- info_.clear();
- }
- return CloseDescriptorForFile(fd, filename_) && success;
-}
-
-bool ProfileCompilationInfo::ContainsMethod(const MethodReference& method_ref) const {
- auto info_it = info_.find(method_ref.dex_file);
- if (info_it != info_.end()) {
- uint16_t class_idx = method_ref.dex_file->GetMethodId(method_ref.dex_method_index).class_idx_;
- const ClassToMethodsMap& class_map = info_it->second;
- auto class_it = class_map.find(class_idx);
- if (class_it != class_map.end()) {
- const std::set<uint32_t>& methods = class_it->second;
- return methods.find(method_ref.dex_method_index) != methods.end();
- }
- return false;
- }
- return false;
-}
-
-std::string ProfileCompilationInfo::DumpInfo(bool print_full_dex_location) const {
- std::ostringstream os;
- os << "ProfileInfo:" << (info_.empty() ? "empty" : "");
- const std::string kFirstDexFileKeySubstitute = ":classes.dex";
- for (auto info_it : info_) {
- os << "\n";
- const DexFile* dex_file = info_it.first;
- if (print_full_dex_location) {
- os << dex_file->GetLocation();
- } else {
- // Replace the (empty) multidex suffix of the first key with a substitute for easier reading.
- std::string multidex_suffix = DexFile::GetMultiDexSuffix(dex_file->GetLocation());
- os << (multidex_suffix.empty() ? kFirstDexFileKeySubstitute : multidex_suffix);
- }
- for (auto class_it : info_it.second) {
- for (auto method_it : class_it.second) {
- os << "\n " << PrettyMethod(method_it, *dex_file, true);
- }
- }
- }
- return os.str();
-}
-
} // namespace art
#include "atomic.h"
#include "dex_file.h"
-#include "method_reference.h"
#include "safe_map.h"
namespace art {
bool Serialize(const std::string& filename, const DexFileToMethodsMap& info) const;
// TODO(calin): Verify if Atomic is really needed (are we sure to be called from a
- // single thread?)
+ // singe thread?)
Atomic<uint64_t> last_update_time_ns_;
};
-/**
- * Profile information in a format suitable to be queried by the compiler and performing
- * profile guided compilation.
- */
-class ProfileCompilationInfo {
- public:
- // Constructs a ProfileCompilationInfo backed by the provided file.
- explicit ProfileCompilationInfo(const std::string& filename) : filename_(filename) {}
-
- // Loads profile information corresponding to the provided dex files.
- // The dex files' multidex suffixes must be unique.
- // This resets the state of the profiling information
- // (i.e. all previously loaded info are cleared).
- bool Load(const std::vector<const DexFile*>& dex_files);
-
- // Returns true if the method reference is present in the profiling info.
- bool ContainsMethod(const MethodReference& method_ref) const;
-
- const std::string& GetFilename() const { return filename_; }
-
- // Dumps all the loaded profile info into a string and returns it.
- // This is intended for testing and debugging.
- std::string DumpInfo(bool print_full_dex_location = true) const;
-
- private:
- bool ProcessLine(const std::string& line,
- const std::vector<const DexFile*>& dex_files);
-
- using ClassToMethodsMap = SafeMap<uint32_t, std::set<uint32_t>>;
- // Map identifying the location of the profiled methods.
- // dex_file -> class_index -> [dex_method_index]+
- using DexFileToProfileInfoMap = SafeMap<const DexFile*, ClassToMethodsMap>;
-
- const std::string filename_;
- DexFileToProfileInfoMap info_;
-};
-
} // namespace art
#endif // ART_RUNTIME_JIT_OFFLINE_PROFILING_INFO_H_
UnloadNativeBridge();
}
+ MaybeSaveJitProfilingInfo();
+
if (dump_gc_performance_on_shutdown_) {
// This can't be called from the Heap destructor below because it
// could call RosAlloc::InspectAll() which needs the thread_list
+++ /dev/null
-JNI_OnLoad called
-ProfileInfo:
-:classes.dex
- java.lang.String Main.hotMethod()
- void Main.main(java.lang.String[])
-:classes2.dex
- java.lang.String OtherDex.hotMethod()
+++ /dev/null
-Check that saving and restoring profile files works correctly in a JIT environment.
+++ /dev/null
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "dex_file.h"
-
-#include "jit/offline_profiling_info.h"
-#include "jni.h"
-#include "mirror/class-inl.h"
-#include "oat_file_assistant.h"
-#include "oat_file_manager.h"
-#include "scoped_thread_state_change.h"
-#include "thread.h"
-
-namespace art {
-namespace {
-
-extern "C" JNIEXPORT jstring JNICALL Java_Main_getProfileInfoDump(
- JNIEnv* env, jclass, jstring filename, jclass cls_from_primary, jclass cls_from_secondary) {
- // Note:
- // Ideally we would get the dex list from the primary oat file.
- // e.g.
- // oat_file = Runtime::Current()->GetOatFileManager().GetPrimaryOatFile();
- // dex_files = OatFileAssistant::LoadDexFiles(*oat_file, dex_location.c_str());
- // However the ownership of the pointers is complicated since the primary file
- // already exists and the test crashed sporadically because some data changes under
- // our feet.
- // To simplify things get the dex files from the classes passed as arguments.
- const DexFile* dex_primary;
- const DexFile* dex_secondary;
- {
- ScopedObjectAccess soa(Thread::Current());
- dex_primary = soa.Decode<mirror::Class*>(cls_from_primary)->GetDexCache()->GetDexFile();
- dex_secondary = soa.Decode<mirror::Class*>(cls_from_secondary)->GetDexCache()->GetDexFile();
- }
-
- std::vector<const DexFile*> dex_files;
- dex_files.push_back(dex_primary);
- dex_files.push_back(dex_secondary);
-
- const char* filename_chars = env->GetStringUTFChars(filename, nullptr);
- ProfileCompilationInfo info(filename_chars);
- const char* result = info.Load(dex_files)
- ? info.DumpInfo(/*print_full_dex_location*/false).c_str()
- : nullptr;
- env->ReleaseStringUTFChars(filename, filename_chars);
- return env->NewStringUTF(result);
-}
-
-} // namespace
-} // namespace art
+++ /dev/null
-#!/bin/bash
-#
-# Copyright 2015 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-exec ${RUN} \
- -Xcompiler-option --compiler-filter=interpret-only \
- --runtime-option -Xjitsaveprofilinginfo \
- --runtime-option -Xusejit:true \
- --runtime-option -Xjitthreshold:100 \
- "${@}"
+++ /dev/null
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.util.HashMap;
-
-public class OtherDex {
- public void coldMethod() {
- hotMethod();
- }
-
- public String hotMethod() {
- HashMap<String, String> map = new HashMap<String, String>();
- for (int i = 0; i < 10; i++) {
- map.put("" + i, "" + i + 1);
- }
- return map.get("1");
- }
-}
+++ /dev/null
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.io.File;
-import java.io.IOException;
-import java.lang.reflect.Method;
-import java.util.HashMap;
-
-public class Main {
-
- public void coldMethod() {
- hotMethod();
- }
-
- public String hotMethod() {
- HashMap<String, String> map = new HashMap<String, String>();
- for (int i = 0; i < 10; i++) {
- map.put("" + i, "" + i + 1);
- }
- return map.get("1");
- }
-
- private static final String PKG_NAME = "test.package";
- private static final String PROFILE_FILE = PKG_NAME + ".prof";
- private static final String TEMP_FILE_NAME_PREFIX = "dummy";
- private static final String TEMP_FILE_NAME_SUFFIX = ".file";
- private static final int JIT_INVOCATION_COUNT = 101;
-
- /* needs to match Runtime:: kProfileBackground */
- private static final int PROFILE_BACKGROUND = 1;
-
- public static void main(String[] args) throws Exception {
- System.loadLibrary(args[0]);
-
- File file = null;
- File profileDir = null;
- File profileFile = null;
- try {
- // We don't know where we have rights to create the code_cache. So create
- // a dummy temporary file and get its parent directory. That will serve as
- // the app directory.
- file = createTempFile();
- String appDir = file.getParent();
- profileDir = new File(appDir, "code_cache");
- profileDir.mkdir();
-
- // Registering the app info will set the profile file name.
- VMRuntime.registerAppInfo(PKG_NAME, appDir);
-
- // Make sure the hot methods are jitted.
- Main m = new Main();
- OtherDex o = new OtherDex();
- for (int i = 0; i < JIT_INVOCATION_COUNT; i++) {
- m.hotMethod();
- o.hotMethod();
- }
-
- // Updating the process state to BACKGROUND will trigger profile saving.
- VMRuntime.updateProcessState(PROFILE_BACKGROUND);
-
- // Check that the profile file exists.
- profileFile = new File(profileDir, PROFILE_FILE);
- if (!profileFile.exists()) {
- throw new RuntimeException("No profile file found");
- }
- // Dump the profile file.
- // We know what methods are hot and we compare with the golden `expected` output.
- System.out.println(getProfileInfoDump(profileFile.getPath(), m.getClass(), o.getClass()));
- } finally {
- if (file != null) {
- file.delete();
- }
- if (profileFile != null) {
- profileFile.delete();
- }
- if (profileDir != null) {
- profileDir.delete();
- }
- }
- }
-
- private static class VMRuntime {
- private static final Method registerAppInfoMethod;
- private static final Method updateProcessStateMethod;
- private static final Method getRuntimeMethod;
- static {
- try {
- Class c = Class.forName("dalvik.system.VMRuntime");
- registerAppInfoMethod = c.getDeclaredMethod("registerAppInfo",
- String.class, String.class, String.class);
- updateProcessStateMethod = c.getDeclaredMethod("updateProcessState", Integer.TYPE);
- getRuntimeMethod = c.getDeclaredMethod("getRuntime");
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- public static void registerAppInfo(String pkgName, String appDir) throws Exception {
- registerAppInfoMethod.invoke(null, pkgName, appDir, null);
- }
- public static void updateProcessState(int state) throws Exception {
- Object runtime = getRuntimeMethod.invoke(null);
- updateProcessStateMethod.invoke(runtime, state);
- }
- }
-
- static native String getProfileInfoDump(
- String filename, Class<?> clsFromPrimary, Class<?> clsFromSecondary);
-
- private static File createTempFile() throws Exception {
- try {
- return File.createTempFile(TEMP_FILE_NAME_PREFIX, TEMP_FILE_NAME_SUFFIX);
- } catch (IOException e) {
- System.setProperty("java.io.tmpdir", "/data/local/tmp");
- try {
- return File.createTempFile(TEMP_FILE_NAME_PREFIX, TEMP_FILE_NAME_SUFFIX);
- } catch (IOException e2) {
- System.setProperty("java.io.tmpdir", "/sdcard");
- return File.createTempFile(TEMP_FILE_NAME_PREFIX, TEMP_FILE_NAME_SUFFIX);
- }
- }
- }
-}
461-get-reference-vreg/get_reference_vreg_jni.cc \
466-get-live-vreg/get_live_vreg_jni.cc \
497-inlining-and-class-loader/clear_dex_cache.cc \
- 543-env-long-ref/env_long_ref.cc \
- 551-jit-profile-file/offline_profile.cc
+ 543-env-long-ref/env_long_ref.cc
ART_TARGET_LIBARTTEST_$(ART_PHONY_TEST_TARGET_SUFFIX) += $(ART_TARGET_TEST_OUT)/$(TARGET_ARCH)/libarttest.so
ART_TARGET_LIBARTTEST_$(ART_PHONY_TEST_TARGET_SUFFIX) += $(ART_TARGET_TEST_OUT)/$(TARGET_ARCH)/libarttestd.so