Fix asm for String#indexOf/compareTo intrinsics
Fixed code for arm arch, it's still broken
on remaining architectures (will be done soon in
following CLs).
OpenJdk string lacks offset and length fields and requires
user to fetch the length from array object.
Change-Id: I682911e4ee72d9597e8a9735ac414c837569eb8e
diff --git a/compiler/dex/quick/dex_file_method_inliner.cc b/compiler/dex/quick/dex_file_method_inliner.cc
index 4559b9c..34ed0f4 100644
--- a/compiler/dex/quick/dex_file_method_inliner.cc
+++ b/compiler/dex/quick/dex_file_method_inliner.cc
@@ -342,15 +342,12 @@
INTRINSIC(JavaLangRefReference, ReferenceGetReferent, _Object, kIntrinsicReferenceGetReferent, 0),
INTRINSIC(JavaLangString, CharAt, I_C, kIntrinsicCharAt, 0),
+ INTRINSIC(JavaLangString, CompareTo, String_I, kIntrinsicCompareTo, 0),
INTRINSIC(JavaLangString, IsEmpty, _Z, kIntrinsicIsEmptyOrLength, kIntrinsicFlagIsEmpty),
+ INTRINSIC(JavaLangString, IndexOf, II_I, kIntrinsicIndexOf, kIntrinsicFlagNone),
+ INTRINSIC(JavaLangString, IndexOf, I_I, kIntrinsicIndexOf, kIntrinsicFlagBase0),
INTRINSIC(JavaLangString, Length, _I, kIntrinsicIsEmptyOrLength, kIntrinsicFlagLength),
- // TODO: Reenable these other intrinsics.
- //
- // INTRINSIC(JavaLangString, CompareTo, String_I, kIntrinsicCompareTo, 0),
- // INTRINSIC(JavaLangString, IndexOf, II_I, kIntrinsicIndexOf, kIntrinsicFlagNone),
- // INTRINSIC(JavaLangString, IndexOf, I_I, kIntrinsicIndexOf, kIntrinsicFlagBase0),
-
INTRINSIC(JavaLangThread, CurrentThread, _Thread, kIntrinsicCurrentThread, 0),
INTRINSIC(LibcoreIoMemory, PeekByte, J_B, kIntrinsicPeek, kSignedByte),
diff --git a/runtime/arch/arm/quick_entrypoints_arm.S b/runtime/arch/arm/quick_entrypoints_arm.S
index 26e6937..ead744a 100644
--- a/runtime/arch/arm/quick_entrypoints_arm.S
+++ b/runtime/arch/arm/quick_entrypoints_arm.S
@@ -1291,9 +1291,9 @@
.cfi_rel_offset r10, 4
.cfi_rel_offset r11, 8
.cfi_rel_offset lr, 12
- ldr r3, [r0, #STRING_COUNT_OFFSET]
- ldr r12, [r0, #STRING_OFFSET_OFFSET]
+
ldr r0, [r0, #STRING_VALUE_OFFSET]
+ ldr r3, [r0, #ARRAY_LENGTH_OFFSET]
/* Clamp start to [0..count] */
cmp r2, #0
@@ -1304,8 +1304,7 @@
movgt r2, r3
/* Build a pointer to the start of string data */
- add r0, #STRING_DATA_OFFSET
- add r0, r0, r12, lsl #1
+ add r0, #OBJECT_ARRAY_DATA_OFFSET
/* Save a copy in r12 to later compute result */
mov r12, r0
@@ -1413,17 +1412,15 @@
.cfi_rel_offset r12, 24
.cfi_rel_offset lr, 28
- ldr r4, [r2, #STRING_OFFSET_OFFSET]
- ldr r9, [r1, #STRING_OFFSET_OFFSET]
- ldr r7, [r2, #STRING_COUNT_OFFSET]
- ldr r10, [r1, #STRING_COUNT_OFFSET]
ldr r2, [r2, #STRING_VALUE_OFFSET]
ldr r1, [r1, #STRING_VALUE_OFFSET]
+ ldr r7, [r2, #ARRAY_LENGTH_OFFSET]
+ ldr r10, [r1, #ARRAY_LENGTH_OFFSET]
+
/*
* At this point, we have:
* value: r2/r1
- * offset: r4/r9
* count: r7/r10
* We're going to compute
* r11 <- countDiff
@@ -1433,15 +1430,12 @@
it ls
movls r10, r7
- /* Now, build pointers to the string data */
- add r2, r2, r4, lsl #1
- add r1, r1, r9, lsl #1
/*
* Note: data pointers point to previous element so we can use pre-index
* mode with base writeback.
*/
- add r2, #STRING_DATA_OFFSET-2 @ offset to contents[-1]
- add r1, #STRING_DATA_OFFSET-2 @ offset to contents[-1]
+ add r2, #OBJECT_ARRAY_DATA_OFFSET-2 @ offset to contents[-1]
+ add r1, #OBJECT_ARRAY_DATA_OFFSET-2 @ offset to contents[-1]
/*
* At this point we have:
diff --git a/runtime/asm_support.h b/runtime/asm_support.h
index 0a57c9a..af282bf 100644
--- a/runtime/asm_support.h
+++ b/runtime/asm_support.h
@@ -38,6 +38,7 @@
// Offsets within java.lang.String.
#define STRING_VALUE_OFFSET 8
+// TODO(pszczepaniak): Remove these:
#define STRING_COUNT_OFFSET 12
#define STRING_OFFSET_OFFSET 20
#define STRING_DATA_OFFSET 12
@@ -62,6 +63,7 @@
// Offsets within java.lang.String.
#define STRING_VALUE_OFFSET 16
+// TODO(pszczepaniak): Remove these:
#define STRING_COUNT_OFFSET 20
#define STRING_OFFSET_OFFSET 28
#define STRING_DATA_OFFSET 20
diff --git a/runtime/mirror/object_test.cc b/runtime/mirror/object_test.cc
index 73164fe..29c3233 100644
--- a/runtime/mirror/object_test.cc
+++ b/runtime/mirror/object_test.cc
@@ -85,7 +85,6 @@
EXPECT_EQ(OBJECT_ARRAY_DATA_OFFSET, Array::DataOffset(sizeof(HeapReference<Object>)).Int32Value());
EXPECT_EQ(STRING_VALUE_OFFSET, String::ValueOffset().Int32Value());
- EXPECT_EQ(STRING_DATA_OFFSET, Array::DataOffset(sizeof(uint16_t)).Int32Value());
EXPECT_EQ(METHOD_DEX_CACHE_METHODS_OFFSET,
ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());