Introduce a ensureJitBaselineCompiled for tests.
To fix the flakiness when relying on having baseline compiled code.
Test: 638-checker-inline-cache-intrinsic
Bug: 169616148
Change-Id: I21d114db29bb337f4eb1349b2b2b5901e71f41b3
diff --git a/test/638-checker-inline-cache-intrinsic/src/Main.java b/test/638-checker-inline-cache-intrinsic/src/Main.java
index 5334487..738e13c 100644
--- a/test/638-checker-inline-cache-intrinsic/src/Main.java
+++ b/test/638-checker-inline-cache-intrinsic/src/Main.java
@@ -63,6 +63,9 @@
}
public static void test() {
+ ensureJitBaselineCompiled(Main.class, "$noinline$stringEquals");
+ ensureJitBaselineCompiled(Main.class, "$noinline$inlineMonomorphic");
+ ensureJitBaselineCompiled(Main.class, "$noinline$knownReceiverType");
// Warm up inline cache.
for (int i = 0; i < 600000; i++) {
$noinline$inlineMonomorphic(str);
@@ -91,5 +94,6 @@
static String str = "xyz";
+ private static native void ensureJitBaselineCompiled(Class<?> itf, String method_name);
private static native void ensureJitCompiled(Class<?> itf, String method_name);
}
diff --git a/test/common/runtime_state.cc b/test/common/runtime_state.cc
index c4edf19..ac3cbdd 100644
--- a/test/common/runtime_state.cc
+++ b/test/common/runtime_state.cc
@@ -229,7 +229,9 @@
return jit->GetCodeCache()->ContainsMethod(method);
}
-static void ForceJitCompiled(Thread* self, ArtMethod* method) REQUIRES(!Locks::mutator_lock_) {
+static void ForceJitCompiled(Thread* self,
+ ArtMethod* method,
+ CompilationKind kind) REQUIRES(!Locks::mutator_lock_) {
{
ScopedObjectAccess soa(self);
if (!Runtime::Current()->GetRuntimeCallbacks()->IsMethodSafeToJit(method)) {
@@ -271,10 +273,9 @@
usleep(1000);
ScopedObjectAccess soa(self);
// Will either ensure it's compiled or do the compilation itself. We do
- // this before checking if we will execute JIT code to make sure the
- // method is compiled 'optimized' and not baseline (tests expect optimized
- // compilation).
- jit->CompileMethod(method, self, CompilationKind::kOptimized, /*prejit=*/ false);
+ // this before checking if we will execute JIT code in case the request
+ // is for an 'optimized' compilation.
+ jit->CompileMethod(method, self, kind, /*prejit=*/ false);
} while (!code_cache->ContainsPc(method->GetEntryPointFromQuickCompiledCode()));
}
@@ -290,7 +291,7 @@
ScopedObjectAccess soa(self);
method = ArtMethod::FromReflectedMethod(soa, meth);
}
- ForceJitCompiled(self, method);
+ ForceJitCompiled(self, method, CompilationKind::kOptimized);
}
extern "C" JNIEXPORT void JNICALL Java_Main_ensureJitCompiled(JNIEnv* env,
@@ -310,7 +311,27 @@
ScopedUtfChars chars(env, method_name);
method = GetMethod(soa, cls, chars);
}
- ForceJitCompiled(self, method);
+ ForceJitCompiled(self, method, CompilationKind::kOptimized);
+}
+
+extern "C" JNIEXPORT void JNICALL Java_Main_ensureJitBaselineCompiled(JNIEnv* env,
+ jclass,
+ jclass cls,
+ jstring method_name) {
+ jit::Jit* jit = GetJitIfEnabled();
+ if (jit == nullptr) {
+ return;
+ }
+
+ Thread* self = Thread::Current();
+ ArtMethod* method = nullptr;
+ {
+ ScopedObjectAccess soa(self);
+
+ ScopedUtfChars chars(env, method_name);
+ method = GetMethod(soa, cls, chars);
+ }
+ ForceJitCompiled(self, method, CompilationKind::kBaseline);
}
extern "C" JNIEXPORT jboolean JNICALL Java_Main_hasSingleImplementation(JNIEnv* env,