Intrinsic for java.lang.Thread.currentThread.
Change-Id: I056323a74f8759257bf6b6bb032437e576665006
diff --git a/src/compiler/codegen/codegen.h b/src/compiler/codegen/codegen.h
index 0698156..e512803 100644
--- a/src/compiler/codegen/codegen.h
+++ b/src/compiler/codegen/codegen.h
@@ -211,6 +211,7 @@
bool GenInlinedDoubleCvt(CompilationUnit *cu, CallInfo* info);
bool GenInlinedIndexOf(CompilationUnit* cu, CallInfo* info, bool zero_based);
bool GenInlinedStringCompareTo(CompilationUnit* cu, CallInfo* info);
+ bool GenInlinedCurrentThread(CompilationUnit* cu, CallInfo* info);
bool GenIntrinsic(CompilationUnit* cu, CallInfo* info);
// Shared by all targets - implemented in gen_loadstore.cc.
diff --git a/src/compiler/codegen/gen_invoke.cc b/src/compiler/codegen/gen_invoke.cc
index 41924e2..afaa053 100644
--- a/src/compiler/codegen/gen_invoke.cc
+++ b/src/compiler/codegen/gen_invoke.cc
@@ -18,6 +18,7 @@
#include "../compiler_ir.h"
#include "ralloc_util.h"
#include "codegen_util.h"
+#include "x86/codegen_x86.h"
namespace art {
@@ -1105,6 +1106,20 @@
return true;
}
+bool Codegen::GenInlinedCurrentThread(CompilationUnit* cu, CallInfo* info) {
+ RegLocation rl_dest = InlineTarget(cu, info);
+ RegLocation rl_result = EvalLoc(cu, rl_dest, kCoreReg, true);
+ int offset = Thread::PeerOffset().Int32Value();
+ if (cu->instruction_set == kThumb2) {
+ LoadWordDisp(cu, TargetReg(kSelf), offset, rl_result.low_reg);
+ } else {
+ CHECK(cu->instruction_set == kX86);
+ ((X86Codegen*)this)->OpRegThreadMem(cu, kOpMov, rl_result.low_reg, offset);
+ }
+ StoreValue(cu, rl_dest, rl_result);
+ return true;
+}
+
bool Codegen::GenIntrinsic(CompilationUnit* cu, CallInfo* info)
{
if (info->opt_flags & MIR_INLINED) {
@@ -1172,6 +1187,9 @@
if (tgt_method == "int java.lang.String.length()") {
return GenInlinedStringIsEmptyOrLength(cu, info, false /* is_empty */);
}
+ if (tgt_method == "java.lang.Thread java.lang.Thread.currentThread()") {
+ return GenInlinedCurrentThread(cu, info);
+ }
} else if (tgt_method.find("boolean sun.misc.Unsafe.compareAndSwap") != std::string::npos) {
if (tgt_method == "boolean sun.misc.Unsafe.compareAndSwapInt(java.lang.Object, long, int, int)") {
return GenInlinedCas32(cu, info, false);
diff --git a/src/compiler/codegen/local_optimizations.cc b/src/compiler/codegen/local_optimizations.cc
index ec915f0..69b5d8e 100644
--- a/src/compiler/codegen/local_optimizations.cc
+++ b/src/compiler/codegen/local_optimizations.cc
@@ -20,7 +20,7 @@
#define DEBUG_OPT(X)
-/* Check RAW, WAR, and WAR dependency on the register operands */
+/* Check RAW, WAR, and RAW dependency on the register operands */
#define CHECK_REG_DEP(use, def, check) ((def & check->use_mask) || \
((use | def) & check->def_mask))
diff --git a/src/compiler/codegen/x86/codegen_x86.h b/src/compiler/codegen/x86/codegen_x86.h
index dba4953..4ef186a 100644
--- a/src/compiler/codegen/x86/codegen_x86.h
+++ b/src/compiler/codegen/x86/codegen_x86.h
@@ -18,6 +18,7 @@
#define ART_SRC_COMPILER_CODEGEN_X86_CODEGENX86_H_
#include "../../compiler_internals.h"
+#include "x86_lir.h"
namespace art {
diff --git a/src/compiler/codegen/x86/int_x86.cc b/src/compiler/codegen/x86/int_x86.cc
index 190208b..f8e18ec 100644
--- a/src/compiler/codegen/x86/int_x86.cc
+++ b/src/compiler/codegen/x86/int_x86.cc
@@ -431,6 +431,7 @@
X86OpCode opcode = kX86Bkpt;
switch (op) {
case kOpCmp: opcode = kX86Cmp32RT; break;
+ case kOpMov: opcode = kX86Mov32RT; break;
default:
LOG(FATAL) << "Bad opcode: " << op;
break;
diff --git a/src/thread.cc b/src/thread.cc
index 72ceaf0..75d0468 100644
--- a/src/thread.cc
+++ b/src/thread.cc
@@ -1636,6 +1636,7 @@
DO_THREAD_OFFSET(state_and_flags_);
DO_THREAD_OFFSET(card_table_);
DO_THREAD_OFFSET(exception_);
+ DO_THREAD_OFFSET(opeer_);
DO_THREAD_OFFSET(jni_env_);
DO_THREAD_OFFSET(self_);
DO_THREAD_OFFSET(stack_end_);
diff --git a/src/thread.h b/src/thread.h
index 4c065c5..8b9c81d 100644
--- a/src/thread.h
+++ b/src/thread.h
@@ -442,6 +442,10 @@
return ThreadOffset(OFFSETOF_MEMBER(Thread, exception_));
}
+ static ThreadOffset PeerOffset() {
+ return ThreadOffset(OFFSETOF_MEMBER(Thread, opeer_));
+ }
+
static ThreadOffset ThinLockIdOffset() {
return ThreadOffset(OFFSETOF_MEMBER(Thread, thin_lock_id_));
}