ART: Do not emit load when inlining unused Thread.currentThread()
When the result is not used, do not emit the load. This avoids
uninitialized registers leading to size-check errors.
Change-Id: I212392ffea7243720f120b2f12679df286106a02
diff --git a/compiler/dex/quick/gen_invoke.cc b/compiler/dex/quick/gen_invoke.cc
index 02f39ac..6c0dfe8 100755
--- a/compiler/dex/quick/gen_invoke.cc
+++ b/compiler/dex/quick/gen_invoke.cc
@@ -1638,6 +1638,12 @@
bool Mir2Lir::GenInlinedCurrentThread(CallInfo* info) {
RegLocation rl_dest = InlineTarget(info);
+
+ // Early exit if the result is unused.
+ if (rl_dest.orig_sreg < 0) {
+ return true;
+ }
+
RegLocation rl_result = EvalLoc(rl_dest, kRefReg, true);
switch (cu_->instruction_set) {
diff --git a/test/082-inline-execute/src/Main.java b/test/082-inline-execute/src/Main.java
index 5b8134d..3b11879 100644
--- a/test/082-inline-execute/src/Main.java
+++ b/test/082-inline-execute/src/Main.java
@@ -49,6 +49,7 @@
test_String_indexOf();
test_String_isEmpty();
test_String_length();
+ test_Thread_currentThread();
}
/*
@@ -70,6 +71,17 @@
return (b - a) < maxDelta;
}
+ /**
+ * Will test inlining Thread.currentThread().
+ */
+ public static void test_Thread_currentThread() {
+ // 1. Do not use result.
+ Thread.currentThread();
+
+ // 2. Result should not be null.
+ Assert.assertNotNull(Thread.currentThread());
+ }
+
public static void test_String_length() {
String str0 = "";
String str1 = "x";