Fix profile saver hotness for AOT code
If the counter is larger than the warm threshold, mark the method as
hot. This fixes a bug for profiling arleady compiled methods where
they would not be marked as hot no matter what the counter was.
Also removed unused functions, and reverted HasSeenMethod to verify
that the method is hot.
Bug: 139883463
Test: test-art-host
Change-Id: I243e528e9f06da7223eed9b91ad613d4f1ad9524
diff --git a/runtime/jit/jit.h b/runtime/jit/jit.h
index 13a9c7b..59861c5 100644
--- a/runtime/jit/jit.h
+++ b/runtime/jit/jit.h
@@ -124,10 +124,6 @@
profile_saver_options_.SetWaitForJitNotificationsToSave(value);
}
- void SetProfileAOTCode(bool value) {
- profile_saver_options_.SetProfileAOTCode(value);
- }
-
void SetJitAtFirstUse() {
use_jit_compilation_ = true;
compile_threshold_ = 0;
diff --git a/runtime/jit/profile_saver.cc b/runtime/jit/profile_saver.cc
index 129a30a..9399470 100644
--- a/runtime/jit/profile_saver.cc
+++ b/runtime/jit/profile_saver.cc
@@ -37,6 +37,7 @@
#include "gc/collector_type.h"
#include "gc/gc_cause.h"
#include "gc/scoped_gc_critical_section.h"
+#include "jit/jit.h"
#include "jit/profiling_info.h"
#include "oat_file_manager.h"
#include "profile/profile_compilation_info.h"
@@ -421,9 +422,12 @@
MutexLock mu(self, *Locks::profiler_lock_);
profiler_pthread = profiler_pthread_;
}
- const uint32_t hot_method_sample_threshold = startup ?
- options_.GetHotStartupMethodSamples(is_low_ram) :
- std::numeric_limits<uint32_t>::max();
+ uint32_t hot_method_sample_threshold = std::numeric_limits<uint32_t>::max();
+ if (startup) {
+ hot_method_sample_threshold = options_.GetHotStartupMethodSamples(is_low_ram);
+ } else if (Runtime::Current()->GetJit() != nullptr) {
+ hot_method_sample_threshold = Runtime::Current()->GetJit()->WarmMethodThreshold();
+ }
SampleClassesAndExecutedMethods(profiler_pthread,
options_.GetProfileBootClassPath(),
&allocator,
@@ -916,11 +920,8 @@
if (!info.Load(profile, /*clear_if_invalid=*/false)) {
return false;
}
- ProfileCompilationInfo::MethodHotness hotness = info.GetMethodHotness(ref);
- // Ignore hot parameter for now since it was causing test 595 to be flaky. TODO: Investigate.
- // b/63635729
- UNUSED(hot);
- return hotness.IsInProfile();
+ const ProfileCompilationInfo::MethodHotness hotness = info.GetMethodHotness(ref);
+ return hot ? hotness.IsHot() : hotness.IsInProfile();
}
return false;
}
diff --git a/runtime/jit/profile_saver_options.h b/runtime/jit/profile_saver_options.h
index 18f7899..1cff713 100644
--- a/runtime/jit/profile_saver_options.h
+++ b/runtime/jit/profile_saver_options.h
@@ -112,9 +112,6 @@
bool GetProfileAOTCode() const {
return profile_aot_code_;
}
- void SetProfileAOTCode(bool value) {
- profile_aot_code_ = value;
- }
bool GetWaitForJitNotificationsToSave() const {
return wait_for_jit_notifications_to_save_;
}
diff --git a/test/2230-profile-save-hotness/expected.txt b/test/2230-profile-save-hotness/expected.txt
new file mode 100644
index 0000000..6a5618e
--- /dev/null
+++ b/test/2230-profile-save-hotness/expected.txt
@@ -0,0 +1 @@
+JNI_OnLoad called
diff --git a/test/2230-profile-save-hotness/info.txt b/test/2230-profile-save-hotness/info.txt
new file mode 100644
index 0000000..c230391
--- /dev/null
+++ b/test/2230-profile-save-hotness/info.txt
@@ -0,0 +1 @@
+Check that profile recording with AOT hotness.
diff --git a/test/2230-profile-save-hotness/run b/test/2230-profile-save-hotness/run
new file mode 100644
index 0000000..6725d3b
--- /dev/null
+++ b/test/2230-profile-save-hotness/run
@@ -0,0 +1,23 @@
+#!/bin/bash
+#
+# Copyright 2019 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.
+
+# Run quicken otherwise the profile saver won't start?
+${RUN} \
+ -Xcompiler-option --count-hotness-in-compiled-code \
+ -Xcompiler-option --compiler-filter=speed \
+ --runtime-option -Xps-profile-aot-code \
+ --runtime-option -Xjitsaveprofilinginfo \
+ --runtime-option -Xusejit:true "${@}"
diff --git a/test/2230-profile-save-hotness/src-art/Main.java b/test/2230-profile-save-hotness/src-art/Main.java
new file mode 100644
index 0000000..41cb435
--- /dev/null
+++ b/test/2230-profile-save-hotness/src-art/Main.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2019 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 dalvik.system.VMRuntime;
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Method;
+
+public class Main {
+ public static void $noinline$hotnessCount() {}
+
+ public static void $noinline$hotnessCountWithLoop(int count) {
+ for (int i = 0; i < count; i++) {
+ $noinline$hotnessCount();
+ }
+ }
+
+ public static void main(String[] args) throws Exception {
+ System.loadLibrary(args[0]);
+ if (!isAotCompiled(Main.class, "main")) {
+ return;
+ }
+
+ File file = null;
+ try {
+ file = createTempFile();
+ String codePath = System.getenv("DEX_LOCATION") + "/2230-profile-save-hotness.jar";
+ VMRuntime.registerAppInfo(file.getPath(), new String[] {codePath});
+
+ // Test that the profile saves an app method with a profiling info.
+ $noinline$hotnessCountWithLoop(10000);
+ ensureProfileProcessing();
+ Method appMethod = Main.class.getDeclaredMethod("$noinline$hotnessCount");
+ if (!presentInProfile(file.getPath(), appMethod)) {
+ System.out.println("App method not hot in profile");
+ }
+ } finally {
+ if (file != null) {
+ file.delete();
+ }
+ }
+ }
+
+ // Checks if the profiles saver has the method as hot/warm.
+ public static native boolean presentInProfile(String profile, Method method);
+ // Ensures the profile saver does its usual processing.
+ public static native void ensureProfileProcessing();
+ public static native boolean isAotCompiled(Class<?> cls, String methodName);
+ public static native int getHotnessCounter(Class<?> cls, String methodName);
+
+ private static final String TEMP_FILE_NAME_PREFIX = "dummy";
+ private static final String TEMP_FILE_NAME_SUFFIX = "-file";
+
+ 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);
+ }
+ }
+ }
+}
diff --git a/test/knownfailures.json b/test/knownfailures.json
index 4f119a8..2611077 100644
--- a/test/knownfailures.json
+++ b/test/knownfailures.json
@@ -502,7 +502,8 @@
"909-attach-agent",
"924-threads",
"981-dedup-original-dex",
- "1900-track-alloc"
+ "1900-track-alloc",
+ "2230-profile-save-hotness"
],
"description": ["Tests that require exact knowledge of the deoptimization state, the ",
"number of plugins and agents, or breaks other openjdkjvmti assumptions."],
@@ -1093,7 +1094,8 @@
"1940-ddms-ext",
"1945-proxy-method-arguments",
"1946-list-descriptors",
- "1947-breakpoint-redefine-deopt"
+ "1947-breakpoint-redefine-deopt",
+ "2230-profile-save-hotness"
],
"variant": "jvm",
"bug": "b/73888836",