Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 17 | #include <cstdio> |
| 18 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 19 | #include "art_field-inl.h" |
Vladimir Marko | 3481ba2 | 2015-04-13 12:22:36 +0100 | [diff] [blame] | 20 | #include "class_linker-inl.h" |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 21 | #include "common_runtime_test.h" |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 22 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 23 | #include "mirror/art_method-inl.h" |
| 24 | #include "mirror/class-inl.h" |
Andreas Gampe | 2ba8d4b | 2014-05-02 17:33:17 -0700 | [diff] [blame] | 25 | #include "mirror/string-inl.h" |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 26 | #include "scoped_thread_state_change.h" |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 27 | |
| 28 | namespace art { |
| 29 | |
| 30 | |
| 31 | class StubTest : public CommonRuntimeTest { |
| 32 | protected: |
| 33 | // We need callee-save methods set up in the Runtime for exceptions. |
| 34 | void SetUp() OVERRIDE { |
| 35 | // Do the normal setup. |
| 36 | CommonRuntimeTest::SetUp(); |
| 37 | |
| 38 | { |
| 39 | // Create callee-save methods |
| 40 | ScopedObjectAccess soa(Thread::Current()); |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 41 | runtime_->SetInstructionSet(kRuntimeISA); |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 42 | for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) { |
| 43 | Runtime::CalleeSaveType type = Runtime::CalleeSaveType(i); |
| 44 | if (!runtime_->HasCalleeSaveMethod(type)) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 45 | runtime_->SetCalleeSaveMethod(runtime_->CreateCalleeSaveMethod(), type); |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 46 | } |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 51 | void SetUpRuntimeOptions(RuntimeOptions *options) OVERRIDE { |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 52 | // Use a smaller heap |
| 53 | for (std::pair<std::string, const void*>& pair : *options) { |
| 54 | if (pair.first.find("-Xmx") == 0) { |
| 55 | pair.first = "-Xmx4M"; // Smallest we can go. |
| 56 | } |
| 57 | } |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 58 | options->push_back(std::make_pair("-Xint", nullptr)); |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 59 | } |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 60 | |
Mathieu Chartier | 119c6bd | 2014-05-09 14:11:47 -0700 | [diff] [blame] | 61 | // Helper function needed since TEST_F makes a new class. |
| 62 | Thread::tls_ptr_sized_values* GetTlsPtr(Thread* self) { |
| 63 | return &self->tlsPtr_; |
| 64 | } |
| 65 | |
Andreas Gampe | 4fc046e | 2014-05-06 16:56:39 -0700 | [diff] [blame] | 66 | public: |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 67 | size_t Invoke3(size_t arg0, size_t arg1, size_t arg2, uintptr_t code, Thread* self) { |
Andreas Gampe | 6cf8010 | 2014-05-19 11:32:41 -0700 | [diff] [blame] | 68 | return Invoke3WithReferrer(arg0, arg1, arg2, code, self, nullptr); |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 69 | } |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 70 | |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 71 | // TODO: Set up a frame according to referrer's specs. |
| 72 | size_t Invoke3WithReferrer(size_t arg0, size_t arg1, size_t arg2, uintptr_t code, Thread* self, |
| 73 | mirror::ArtMethod* referrer) { |
| 74 | // Push a transition back into managed code onto the linked list in thread. |
| 75 | ManagedStack fragment; |
| 76 | self->PushManagedStackFragment(&fragment); |
| 77 | |
| 78 | size_t result; |
Andreas Gampe | 6cf8010 | 2014-05-19 11:32:41 -0700 | [diff] [blame] | 79 | size_t fpr_result = 0; |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 80 | #if defined(__i386__) |
| 81 | // TODO: Set the thread? |
| 82 | __asm__ __volatile__( |
Ian Rogers | c5f1773 | 2014-06-05 20:48:42 -0700 | [diff] [blame] | 83 | "subl $12, %%esp\n\t" // Align stack. |
| 84 | "pushl %[referrer]\n\t" // Store referrer. |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 85 | "call *%%edi\n\t" // Call the stub |
Ian Rogers | c5f1773 | 2014-06-05 20:48:42 -0700 | [diff] [blame] | 86 | "addl $16, %%esp" // Pop referrer |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 87 | : "=a" (result) |
| 88 | // Use the result from eax |
Andreas Gampe | 2f6e351 | 2014-06-07 01:32:33 -0700 | [diff] [blame] | 89 | : "a"(arg0), "c"(arg1), "d"(arg2), "D"(code), [referrer]"r"(referrer) |
| 90 | // This places code into edi, arg0 into eax, arg1 into ecx, and arg2 into edx |
| 91 | : "memory"); // clobber. |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 92 | // TODO: Should we clobber the other registers? EBX gets clobbered by some of the stubs, |
| 93 | // but compilation fails when declaring that. |
| 94 | #elif defined(__arm__) |
| 95 | __asm__ __volatile__( |
| 96 | "push {r1-r12, lr}\n\t" // Save state, 13*4B = 52B |
| 97 | ".cfi_adjust_cfa_offset 52\n\t" |
| 98 | "push {r9}\n\t" |
| 99 | ".cfi_adjust_cfa_offset 4\n\t" |
| 100 | "mov r9, %[referrer]\n\n" |
| 101 | "str r9, [sp, #-8]!\n\t" // Push referrer, +8B padding so 16B aligned |
| 102 | ".cfi_adjust_cfa_offset 8\n\t" |
| 103 | "ldr r9, [sp, #8]\n\t" |
| 104 | |
| 105 | // Push everything on the stack, so we don't rely on the order. What a mess. :-( |
| 106 | "sub sp, sp, #20\n\t" |
| 107 | "str %[arg0], [sp]\n\t" |
| 108 | "str %[arg1], [sp, #4]\n\t" |
| 109 | "str %[arg2], [sp, #8]\n\t" |
| 110 | "str %[code], [sp, #12]\n\t" |
| 111 | "str %[self], [sp, #16]\n\t" |
| 112 | "ldr r0, [sp]\n\t" |
| 113 | "ldr r1, [sp, #4]\n\t" |
| 114 | "ldr r2, [sp, #8]\n\t" |
| 115 | "ldr r3, [sp, #12]\n\t" |
| 116 | "ldr r9, [sp, #16]\n\t" |
| 117 | "add sp, sp, #20\n\t" |
| 118 | |
| 119 | "blx r3\n\t" // Call the stub |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 120 | "add sp, sp, #12\n\t" // Pop null and padding |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 121 | ".cfi_adjust_cfa_offset -12\n\t" |
| 122 | "pop {r1-r12, lr}\n\t" // Restore state |
| 123 | ".cfi_adjust_cfa_offset -52\n\t" |
| 124 | "mov %[result], r0\n\t" // Save the result |
| 125 | : [result] "=r" (result) |
| 126 | // Use the result from r0 |
| 127 | : [arg0] "r"(arg0), [arg1] "r"(arg1), [arg2] "r"(arg2), [code] "r"(code), [self] "r"(self), |
| 128 | [referrer] "r"(referrer) |
Andreas Gampe | 2f6e351 | 2014-06-07 01:32:33 -0700 | [diff] [blame] | 129 | : "memory"); // clobber. |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 130 | #elif defined(__aarch64__) |
| 131 | __asm__ __volatile__( |
Andreas Gampe | f39b378 | 2014-06-03 14:38:30 -0700 | [diff] [blame] | 132 | // Spill x0-x7 which we say we don't clobber. May contain args. |
Andreas Gampe | 6cf8010 | 2014-05-19 11:32:41 -0700 | [diff] [blame] | 133 | "sub sp, sp, #64\n\t" |
| 134 | ".cfi_adjust_cfa_offset 64\n\t" |
Andreas Gampe | f39b378 | 2014-06-03 14:38:30 -0700 | [diff] [blame] | 135 | "stp x0, x1, [sp]\n\t" |
| 136 | "stp x2, x3, [sp, #16]\n\t" |
| 137 | "stp x4, x5, [sp, #32]\n\t" |
| 138 | "stp x6, x7, [sp, #48]\n\t" |
Andreas Gampe | 6cf8010 | 2014-05-19 11:32:41 -0700 | [diff] [blame] | 139 | |
Andreas Gampe | f39b378 | 2014-06-03 14:38:30 -0700 | [diff] [blame] | 140 | "sub sp, sp, #16\n\t" // Reserve stack space, 16B aligned |
| 141 | ".cfi_adjust_cfa_offset 16\n\t" |
| 142 | "str %[referrer], [sp]\n\t" // referrer |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 143 | |
| 144 | // Push everything on the stack, so we don't rely on the order. What a mess. :-( |
| 145 | "sub sp, sp, #48\n\t" |
Andreas Gampe | 6cf8010 | 2014-05-19 11:32:41 -0700 | [diff] [blame] | 146 | ".cfi_adjust_cfa_offset 48\n\t" |
Andreas Gampe | f39b378 | 2014-06-03 14:38:30 -0700 | [diff] [blame] | 147 | // All things are "r" constraints, so direct str/stp should work. |
| 148 | "stp %[arg0], %[arg1], [sp]\n\t" |
| 149 | "stp %[arg2], %[code], [sp, #16]\n\t" |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 150 | "str %[self], [sp, #32]\n\t" |
Andreas Gampe | 6cf8010 | 2014-05-19 11:32:41 -0700 | [diff] [blame] | 151 | |
| 152 | // Now we definitely have x0-x3 free, use it to garble d8 - d15 |
| 153 | "movk x0, #0xfad0\n\t" |
| 154 | "movk x0, #0xebad, lsl #16\n\t" |
| 155 | "movk x0, #0xfad0, lsl #32\n\t" |
| 156 | "movk x0, #0xebad, lsl #48\n\t" |
| 157 | "fmov d8, x0\n\t" |
| 158 | "add x0, x0, 1\n\t" |
| 159 | "fmov d9, x0\n\t" |
| 160 | "add x0, x0, 1\n\t" |
| 161 | "fmov d10, x0\n\t" |
| 162 | "add x0, x0, 1\n\t" |
| 163 | "fmov d11, x0\n\t" |
| 164 | "add x0, x0, 1\n\t" |
| 165 | "fmov d12, x0\n\t" |
| 166 | "add x0, x0, 1\n\t" |
| 167 | "fmov d13, x0\n\t" |
| 168 | "add x0, x0, 1\n\t" |
| 169 | "fmov d14, x0\n\t" |
| 170 | "add x0, x0, 1\n\t" |
| 171 | "fmov d15, x0\n\t" |
| 172 | |
Andreas Gampe | f39b378 | 2014-06-03 14:38:30 -0700 | [diff] [blame] | 173 | // Load call params into the right registers. |
| 174 | "ldp x0, x1, [sp]\n\t" |
| 175 | "ldp x2, x3, [sp, #16]\n\t" |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 176 | "ldr x18, [sp, #32]\n\t" |
| 177 | "add sp, sp, #48\n\t" |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 178 | ".cfi_adjust_cfa_offset -48\n\t" |
| 179 | |
Andreas Gampe | 6cf8010 | 2014-05-19 11:32:41 -0700 | [diff] [blame] | 180 | |
| 181 | "blr x3\n\t" // Call the stub |
Andreas Gampe | f39b378 | 2014-06-03 14:38:30 -0700 | [diff] [blame] | 182 | "mov x8, x0\n\t" // Store result |
| 183 | "add sp, sp, #16\n\t" // Drop the quick "frame" |
| 184 | ".cfi_adjust_cfa_offset -16\n\t" |
Andreas Gampe | 6cf8010 | 2014-05-19 11:32:41 -0700 | [diff] [blame] | 185 | |
| 186 | // Test d8 - d15. We can use x1 and x2. |
| 187 | "movk x1, #0xfad0\n\t" |
| 188 | "movk x1, #0xebad, lsl #16\n\t" |
| 189 | "movk x1, #0xfad0, lsl #32\n\t" |
| 190 | "movk x1, #0xebad, lsl #48\n\t" |
| 191 | "fmov x2, d8\n\t" |
| 192 | "cmp x1, x2\n\t" |
| 193 | "b.ne 1f\n\t" |
| 194 | "add x1, x1, 1\n\t" |
| 195 | |
| 196 | "fmov x2, d9\n\t" |
| 197 | "cmp x1, x2\n\t" |
| 198 | "b.ne 1f\n\t" |
| 199 | "add x1, x1, 1\n\t" |
| 200 | |
| 201 | "fmov x2, d10\n\t" |
| 202 | "cmp x1, x2\n\t" |
| 203 | "b.ne 1f\n\t" |
| 204 | "add x1, x1, 1\n\t" |
| 205 | |
| 206 | "fmov x2, d11\n\t" |
| 207 | "cmp x1, x2\n\t" |
| 208 | "b.ne 1f\n\t" |
| 209 | "add x1, x1, 1\n\t" |
| 210 | |
| 211 | "fmov x2, d12\n\t" |
| 212 | "cmp x1, x2\n\t" |
| 213 | "b.ne 1f\n\t" |
| 214 | "add x1, x1, 1\n\t" |
| 215 | |
| 216 | "fmov x2, d13\n\t" |
| 217 | "cmp x1, x2\n\t" |
| 218 | "b.ne 1f\n\t" |
| 219 | "add x1, x1, 1\n\t" |
| 220 | |
| 221 | "fmov x2, d14\n\t" |
| 222 | "cmp x1, x2\n\t" |
| 223 | "b.ne 1f\n\t" |
| 224 | "add x1, x1, 1\n\t" |
| 225 | |
| 226 | "fmov x2, d15\n\t" |
| 227 | "cmp x1, x2\n\t" |
| 228 | "b.ne 1f\n\t" |
| 229 | |
Andreas Gampe | f39b378 | 2014-06-03 14:38:30 -0700 | [diff] [blame] | 230 | "mov x9, #0\n\t" // Use x9 as flag, in clobber list |
Andreas Gampe | 6cf8010 | 2014-05-19 11:32:41 -0700 | [diff] [blame] | 231 | |
| 232 | // Finish up. |
| 233 | "2:\n\t" |
Andreas Gampe | f39b378 | 2014-06-03 14:38:30 -0700 | [diff] [blame] | 234 | "ldp x0, x1, [sp]\n\t" // Restore stuff not named clobbered, may contain fpr_result |
| 235 | "ldp x2, x3, [sp, #16]\n\t" |
| 236 | "ldp x4, x5, [sp, #32]\n\t" |
| 237 | "ldp x6, x7, [sp, #48]\n\t" |
| 238 | "add sp, sp, #64\n\t" // Free stack space, now sp as on entry |
Andreas Gampe | 6cf8010 | 2014-05-19 11:32:41 -0700 | [diff] [blame] | 239 | ".cfi_adjust_cfa_offset -64\n\t" |
| 240 | |
Andreas Gampe | f39b378 | 2014-06-03 14:38:30 -0700 | [diff] [blame] | 241 | "str x9, %[fpr_result]\n\t" // Store the FPR comparison result |
| 242 | "mov %[result], x8\n\t" // Store the call result |
| 243 | |
Andreas Gampe | 6cf8010 | 2014-05-19 11:32:41 -0700 | [diff] [blame] | 244 | "b 3f\n\t" // Goto end |
| 245 | |
| 246 | // Failed fpr verification. |
| 247 | "1:\n\t" |
Andreas Gampe | f39b378 | 2014-06-03 14:38:30 -0700 | [diff] [blame] | 248 | "mov x9, #1\n\t" |
Andreas Gampe | 6cf8010 | 2014-05-19 11:32:41 -0700 | [diff] [blame] | 249 | "b 2b\n\t" // Goto finish-up |
| 250 | |
| 251 | // End |
| 252 | "3:\n\t" |
Andreas Gampe | cf4035a | 2014-05-28 22:43:01 -0700 | [diff] [blame] | 253 | : [result] "=r" (result) |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 254 | // Use the result from r0 |
| 255 | : [arg0] "0"(arg0), [arg1] "r"(arg1), [arg2] "r"(arg2), [code] "r"(code), [self] "r"(self), |
Andreas Gampe | cf4035a | 2014-05-28 22:43:01 -0700 | [diff] [blame] | 256 | [referrer] "r"(referrer), [fpr_result] "m" (fpr_result) |
Andreas Gampe | f39b378 | 2014-06-03 14:38:30 -0700 | [diff] [blame] | 257 | : "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", "x16", "x17", "x18", "x19", "x20", |
| 258 | "x21", "x22", "x23", "x24", "x25", "x26", "x27", "x28", "x30", |
| 259 | "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", |
| 260 | "d8", "d9", "d10", "d11", "d12", "d13", "d14", "d15", |
| 261 | "d16", "d17", "d18", "d19", "d20", "d21", "d22", "d23", |
Andreas Gampe | 2f6e351 | 2014-06-07 01:32:33 -0700 | [diff] [blame] | 262 | "d24", "d25", "d26", "d27", "d28", "d29", "d30", "d31", |
| 263 | "memory"); // clobber. |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 264 | #elif defined(__x86_64__) && !defined(__APPLE__) && defined(__clang__) |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 265 | // Note: Uses the native convention |
| 266 | // TODO: Set the thread? |
| 267 | __asm__ __volatile__( |
| 268 | "pushq %[referrer]\n\t" // Push referrer |
| 269 | "pushq (%%rsp)\n\t" // & 16B alignment padding |
| 270 | ".cfi_adjust_cfa_offset 16\n\t" |
| 271 | "call *%%rax\n\t" // Call the stub |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 272 | "addq $16, %%rsp\n\t" // Pop null and padding |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 273 | ".cfi_adjust_cfa_offset -16\n\t" |
| 274 | : "=a" (result) |
| 275 | // Use the result from rax |
Andreas Gampe | 5c3d3a9 | 2015-01-21 12:23:50 -0800 | [diff] [blame] | 276 | : "D"(arg0), "S"(arg1), "d"(arg2), "a"(code), [referrer] "c"(referrer) |
Andreas Gampe | 2f6e351 | 2014-06-07 01:32:33 -0700 | [diff] [blame] | 277 | // This places arg0 into rdi, arg1 into rsi, arg2 into rdx, and code into rax |
Andreas Gampe | 5c3d3a9 | 2015-01-21 12:23:50 -0800 | [diff] [blame] | 278 | : "rbx", "rbp", "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", |
Andreas Gampe | 2f6e351 | 2014-06-07 01:32:33 -0700 | [diff] [blame] | 279 | "memory"); // clobber all |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 280 | // TODO: Should we clobber the other registers? |
| 281 | #else |
Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 282 | UNUSED(arg0, arg1, arg2, code, referrer); |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 283 | LOG(WARNING) << "Was asked to invoke for an architecture I do not understand."; |
| 284 | result = 0; |
| 285 | #endif |
| 286 | // Pop transition. |
| 287 | self->PopManagedStackFragment(fragment); |
Andreas Gampe | 6cf8010 | 2014-05-19 11:32:41 -0700 | [diff] [blame] | 288 | |
| 289 | fp_result = fpr_result; |
| 290 | EXPECT_EQ(0U, fp_result); |
| 291 | |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 292 | return result; |
| 293 | } |
| 294 | |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 295 | // TODO: Set up a frame according to referrer's specs. |
| 296 | size_t Invoke3WithReferrerAndHidden(size_t arg0, size_t arg1, size_t arg2, uintptr_t code, |
| 297 | Thread* self, mirror::ArtMethod* referrer, size_t hidden) { |
| 298 | // Push a transition back into managed code onto the linked list in thread. |
| 299 | ManagedStack fragment; |
| 300 | self->PushManagedStackFragment(&fragment); |
| 301 | |
| 302 | size_t result; |
| 303 | size_t fpr_result = 0; |
| 304 | #if defined(__i386__) |
| 305 | // TODO: Set the thread? |
| 306 | __asm__ __volatile__( |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 307 | "movd %[hidden], %%xmm7\n\t" |
Ian Rogers | c5f1773 | 2014-06-05 20:48:42 -0700 | [diff] [blame] | 308 | "subl $12, %%esp\n\t" // Align stack. |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 309 | "pushl %[referrer]\n\t" // Store referrer |
| 310 | "call *%%edi\n\t" // Call the stub |
Ian Rogers | c5f1773 | 2014-06-05 20:48:42 -0700 | [diff] [blame] | 311 | "addl $16, %%esp" // Pop referrer |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 312 | : "=a" (result) |
| 313 | // Use the result from eax |
Andreas Gampe | 1a7e292 | 2014-05-21 15:37:53 -0700 | [diff] [blame] | 314 | : "a"(arg0), "c"(arg1), "d"(arg2), "D"(code), [referrer]"r"(referrer), [hidden]"m"(hidden) |
Andreas Gampe | 2f6e351 | 2014-06-07 01:32:33 -0700 | [diff] [blame] | 315 | // This places code into edi, arg0 into eax, arg1 into ecx, and arg2 into edx |
| 316 | : "memory"); // clobber. |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 317 | // TODO: Should we clobber the other registers? EBX gets clobbered by some of the stubs, |
| 318 | // but compilation fails when declaring that. |
| 319 | #elif defined(__arm__) |
| 320 | __asm__ __volatile__( |
| 321 | "push {r1-r12, lr}\n\t" // Save state, 13*4B = 52B |
| 322 | ".cfi_adjust_cfa_offset 52\n\t" |
| 323 | "push {r9}\n\t" |
| 324 | ".cfi_adjust_cfa_offset 4\n\t" |
| 325 | "mov r9, %[referrer]\n\n" |
| 326 | "str r9, [sp, #-8]!\n\t" // Push referrer, +8B padding so 16B aligned |
| 327 | ".cfi_adjust_cfa_offset 8\n\t" |
| 328 | "ldr r9, [sp, #8]\n\t" |
| 329 | |
| 330 | // Push everything on the stack, so we don't rely on the order. What a mess. :-( |
| 331 | "sub sp, sp, #24\n\t" |
| 332 | "str %[arg0], [sp]\n\t" |
| 333 | "str %[arg1], [sp, #4]\n\t" |
| 334 | "str %[arg2], [sp, #8]\n\t" |
| 335 | "str %[code], [sp, #12]\n\t" |
| 336 | "str %[self], [sp, #16]\n\t" |
| 337 | "str %[hidden], [sp, #20]\n\t" |
| 338 | "ldr r0, [sp]\n\t" |
| 339 | "ldr r1, [sp, #4]\n\t" |
| 340 | "ldr r2, [sp, #8]\n\t" |
| 341 | "ldr r3, [sp, #12]\n\t" |
| 342 | "ldr r9, [sp, #16]\n\t" |
| 343 | "ldr r12, [sp, #20]\n\t" |
| 344 | "add sp, sp, #24\n\t" |
| 345 | |
| 346 | "blx r3\n\t" // Call the stub |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 347 | "add sp, sp, #12\n\t" // Pop null and padding |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 348 | ".cfi_adjust_cfa_offset -12\n\t" |
| 349 | "pop {r1-r12, lr}\n\t" // Restore state |
| 350 | ".cfi_adjust_cfa_offset -52\n\t" |
| 351 | "mov %[result], r0\n\t" // Save the result |
| 352 | : [result] "=r" (result) |
| 353 | // Use the result from r0 |
Andreas Gampe | 2f6e351 | 2014-06-07 01:32:33 -0700 | [diff] [blame] | 354 | : [arg0] "r"(arg0), [arg1] "r"(arg1), [arg2] "r"(arg2), [code] "r"(code), [self] "r"(self), |
| 355 | [referrer] "r"(referrer), [hidden] "r"(hidden) |
| 356 | : "memory"); // clobber. |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 357 | #elif defined(__aarch64__) |
| 358 | __asm__ __volatile__( |
Andreas Gampe | f39b378 | 2014-06-03 14:38:30 -0700 | [diff] [blame] | 359 | // Spill x0-x7 which we say we don't clobber. May contain args. |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 360 | "sub sp, sp, #64\n\t" |
| 361 | ".cfi_adjust_cfa_offset 64\n\t" |
Andreas Gampe | f39b378 | 2014-06-03 14:38:30 -0700 | [diff] [blame] | 362 | "stp x0, x1, [sp]\n\t" |
| 363 | "stp x2, x3, [sp, #16]\n\t" |
| 364 | "stp x4, x5, [sp, #32]\n\t" |
| 365 | "stp x6, x7, [sp, #48]\n\t" |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 366 | |
Andreas Gampe | f39b378 | 2014-06-03 14:38:30 -0700 | [diff] [blame] | 367 | "sub sp, sp, #16\n\t" // Reserve stack space, 16B aligned |
| 368 | ".cfi_adjust_cfa_offset 16\n\t" |
| 369 | "str %[referrer], [sp]\n\t" // referrer |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 370 | |
| 371 | // Push everything on the stack, so we don't rely on the order. What a mess. :-( |
| 372 | "sub sp, sp, #48\n\t" |
| 373 | ".cfi_adjust_cfa_offset 48\n\t" |
Andreas Gampe | f39b378 | 2014-06-03 14:38:30 -0700 | [diff] [blame] | 374 | // All things are "r" constraints, so direct str/stp should work. |
| 375 | "stp %[arg0], %[arg1], [sp]\n\t" |
| 376 | "stp %[arg2], %[code], [sp, #16]\n\t" |
| 377 | "stp %[self], %[hidden], [sp, #32]\n\t" |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 378 | |
| 379 | // Now we definitely have x0-x3 free, use it to garble d8 - d15 |
| 380 | "movk x0, #0xfad0\n\t" |
| 381 | "movk x0, #0xebad, lsl #16\n\t" |
| 382 | "movk x0, #0xfad0, lsl #32\n\t" |
| 383 | "movk x0, #0xebad, lsl #48\n\t" |
| 384 | "fmov d8, x0\n\t" |
| 385 | "add x0, x0, 1\n\t" |
| 386 | "fmov d9, x0\n\t" |
| 387 | "add x0, x0, 1\n\t" |
| 388 | "fmov d10, x0\n\t" |
| 389 | "add x0, x0, 1\n\t" |
| 390 | "fmov d11, x0\n\t" |
| 391 | "add x0, x0, 1\n\t" |
| 392 | "fmov d12, x0\n\t" |
| 393 | "add x0, x0, 1\n\t" |
| 394 | "fmov d13, x0\n\t" |
| 395 | "add x0, x0, 1\n\t" |
| 396 | "fmov d14, x0\n\t" |
| 397 | "add x0, x0, 1\n\t" |
| 398 | "fmov d15, x0\n\t" |
| 399 | |
Andreas Gampe | f39b378 | 2014-06-03 14:38:30 -0700 | [diff] [blame] | 400 | // Load call params into the right registers. |
| 401 | "ldp x0, x1, [sp]\n\t" |
| 402 | "ldp x2, x3, [sp, #16]\n\t" |
Andreas Gampe | 1a7e292 | 2014-05-21 15:37:53 -0700 | [diff] [blame] | 403 | "ldp x18, x17, [sp, #32]\n\t" |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 404 | "add sp, sp, #48\n\t" |
| 405 | ".cfi_adjust_cfa_offset -48\n\t" |
| 406 | |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 407 | "blr x3\n\t" // Call the stub |
Andreas Gampe | f39b378 | 2014-06-03 14:38:30 -0700 | [diff] [blame] | 408 | "mov x8, x0\n\t" // Store result |
| 409 | "add sp, sp, #16\n\t" // Drop the quick "frame" |
| 410 | ".cfi_adjust_cfa_offset -16\n\t" |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 411 | |
| 412 | // Test d8 - d15. We can use x1 and x2. |
| 413 | "movk x1, #0xfad0\n\t" |
| 414 | "movk x1, #0xebad, lsl #16\n\t" |
| 415 | "movk x1, #0xfad0, lsl #32\n\t" |
| 416 | "movk x1, #0xebad, lsl #48\n\t" |
| 417 | "fmov x2, d8\n\t" |
| 418 | "cmp x1, x2\n\t" |
| 419 | "b.ne 1f\n\t" |
| 420 | "add x1, x1, 1\n\t" |
| 421 | |
| 422 | "fmov x2, d9\n\t" |
| 423 | "cmp x1, x2\n\t" |
| 424 | "b.ne 1f\n\t" |
| 425 | "add x1, x1, 1\n\t" |
| 426 | |
| 427 | "fmov x2, d10\n\t" |
| 428 | "cmp x1, x2\n\t" |
| 429 | "b.ne 1f\n\t" |
| 430 | "add x1, x1, 1\n\t" |
| 431 | |
| 432 | "fmov x2, d11\n\t" |
| 433 | "cmp x1, x2\n\t" |
| 434 | "b.ne 1f\n\t" |
| 435 | "add x1, x1, 1\n\t" |
| 436 | |
| 437 | "fmov x2, d12\n\t" |
| 438 | "cmp x1, x2\n\t" |
| 439 | "b.ne 1f\n\t" |
| 440 | "add x1, x1, 1\n\t" |
| 441 | |
| 442 | "fmov x2, d13\n\t" |
| 443 | "cmp x1, x2\n\t" |
| 444 | "b.ne 1f\n\t" |
| 445 | "add x1, x1, 1\n\t" |
| 446 | |
| 447 | "fmov x2, d14\n\t" |
| 448 | "cmp x1, x2\n\t" |
| 449 | "b.ne 1f\n\t" |
| 450 | "add x1, x1, 1\n\t" |
| 451 | |
| 452 | "fmov x2, d15\n\t" |
| 453 | "cmp x1, x2\n\t" |
| 454 | "b.ne 1f\n\t" |
| 455 | |
Andreas Gampe | f39b378 | 2014-06-03 14:38:30 -0700 | [diff] [blame] | 456 | "mov x9, #0\n\t" // Use x9 as flag, in clobber list |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 457 | |
| 458 | // Finish up. |
| 459 | "2:\n\t" |
Andreas Gampe | f39b378 | 2014-06-03 14:38:30 -0700 | [diff] [blame] | 460 | "ldp x0, x1, [sp]\n\t" // Restore stuff not named clobbered, may contain fpr_result |
| 461 | "ldp x2, x3, [sp, #16]\n\t" |
| 462 | "ldp x4, x5, [sp, #32]\n\t" |
| 463 | "ldp x6, x7, [sp, #48]\n\t" |
| 464 | "add sp, sp, #64\n\t" // Free stack space, now sp as on entry |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 465 | ".cfi_adjust_cfa_offset -64\n\t" |
| 466 | |
Andreas Gampe | f39b378 | 2014-06-03 14:38:30 -0700 | [diff] [blame] | 467 | "str x9, %[fpr_result]\n\t" // Store the FPR comparison result |
| 468 | "mov %[result], x8\n\t" // Store the call result |
| 469 | |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 470 | "b 3f\n\t" // Goto end |
| 471 | |
| 472 | // Failed fpr verification. |
| 473 | "1:\n\t" |
Andreas Gampe | f39b378 | 2014-06-03 14:38:30 -0700 | [diff] [blame] | 474 | "mov x9, #1\n\t" |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 475 | "b 2b\n\t" // Goto finish-up |
| 476 | |
| 477 | // End |
| 478 | "3:\n\t" |
Andreas Gampe | f39b378 | 2014-06-03 14:38:30 -0700 | [diff] [blame] | 479 | : [result] "=r" (result) |
| 480 | // Use the result from r0 |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 481 | : [arg0] "0"(arg0), [arg1] "r"(arg1), [arg2] "r"(arg2), [code] "r"(code), [self] "r"(self), |
Andreas Gampe | f39b378 | 2014-06-03 14:38:30 -0700 | [diff] [blame] | 482 | [referrer] "r"(referrer), [hidden] "r"(hidden), [fpr_result] "m" (fpr_result) |
| 483 | : "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", "x16", "x17", "x18", "x19", "x20", |
| 484 | "x21", "x22", "x23", "x24", "x25", "x26", "x27", "x28", "x30", |
| 485 | "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", |
| 486 | "d8", "d9", "d10", "d11", "d12", "d13", "d14", "d15", |
| 487 | "d16", "d17", "d18", "d19", "d20", "d21", "d22", "d23", |
Andreas Gampe | 2f6e351 | 2014-06-07 01:32:33 -0700 | [diff] [blame] | 488 | "d24", "d25", "d26", "d27", "d28", "d29", "d30", "d31", |
| 489 | "memory"); // clobber. |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 490 | #elif defined(__x86_64__) && !defined(__APPLE__) && defined(__clang__) |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 491 | // Note: Uses the native convention |
| 492 | // TODO: Set the thread? |
| 493 | __asm__ __volatile__( |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 494 | "pushq %[referrer]\n\t" // Push referrer |
| 495 | "pushq (%%rsp)\n\t" // & 16B alignment padding |
| 496 | ".cfi_adjust_cfa_offset 16\n\t" |
Andreas Gampe | 1a7e292 | 2014-05-21 15:37:53 -0700 | [diff] [blame] | 497 | "call *%%rbx\n\t" // Call the stub |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 498 | "addq $16, %%rsp\n\t" // Pop null and padding |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 499 | ".cfi_adjust_cfa_offset -16\n\t" |
| 500 | : "=a" (result) |
| 501 | // Use the result from rax |
Andreas Gampe | 1a7e292 | 2014-05-21 15:37:53 -0700 | [diff] [blame] | 502 | : "D"(arg0), "S"(arg1), "d"(arg2), "b"(code), [referrer] "c"(referrer), [hidden] "a"(hidden) |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 503 | // This places arg0 into rdi, arg1 into rsi, arg2 into rdx, and code into rax |
Andreas Gampe | 1a7e292 | 2014-05-21 15:37:53 -0700 | [diff] [blame] | 504 | : "rbp", "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", |
Andreas Gampe | 2f6e351 | 2014-06-07 01:32:33 -0700 | [diff] [blame] | 505 | "memory"); // clobber all |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 506 | // TODO: Should we clobber the other registers? |
| 507 | #else |
Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 508 | UNUSED(arg0, arg1, arg2, code, referrer, hidden); |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 509 | LOG(WARNING) << "Was asked to invoke for an architecture I do not understand."; |
| 510 | result = 0; |
| 511 | #endif |
| 512 | // Pop transition. |
| 513 | self->PopManagedStackFragment(fragment); |
| 514 | |
| 515 | fp_result = fpr_result; |
| 516 | EXPECT_EQ(0U, fp_result); |
| 517 | |
| 518 | return result; |
| 519 | } |
| 520 | |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 521 | // Method with 32b arg0, 64b arg1 |
| 522 | size_t Invoke3UWithReferrer(size_t arg0, uint64_t arg1, uintptr_t code, Thread* self, |
| 523 | mirror::ArtMethod* referrer) { |
Ian Rogers | c3ccc10 | 2014-06-25 11:52:14 -0700 | [diff] [blame] | 524 | #if (defined(__x86_64__) && !defined(__APPLE__)) || defined(__aarch64__) |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 525 | // Just pass through. |
| 526 | return Invoke3WithReferrer(arg0, arg1, 0U, code, self, referrer); |
| 527 | #else |
| 528 | // Need to split up arguments. |
| 529 | uint32_t lower = static_cast<uint32_t>(arg1 & 0xFFFFFFFF); |
| 530 | uint32_t upper = static_cast<uint32_t>((arg1 >> 32) & 0xFFFFFFFF); |
| 531 | |
| 532 | return Invoke3WithReferrer(arg0, lower, upper, code, self, referrer); |
| 533 | #endif |
| 534 | } |
| 535 | |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 536 | static uintptr_t GetEntrypoint(Thread* self, QuickEntrypointEnum entrypoint) { |
| 537 | int32_t offset; |
| 538 | #ifdef __LP64__ |
| 539 | offset = GetThreadOffset<8>(entrypoint).Int32Value(); |
| 540 | #else |
| 541 | offset = GetThreadOffset<4>(entrypoint).Int32Value(); |
| 542 | #endif |
| 543 | return *reinterpret_cast<uintptr_t*>(reinterpret_cast<uint8_t*>(self) + offset); |
| 544 | } |
| 545 | |
Andreas Gampe | 6cf8010 | 2014-05-19 11:32:41 -0700 | [diff] [blame] | 546 | protected: |
| 547 | size_t fp_result; |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 548 | }; |
| 549 | |
| 550 | |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 551 | TEST_F(StubTest, Memcpy) { |
Ian Rogers | c3ccc10 | 2014-06-25 11:52:14 -0700 | [diff] [blame] | 552 | #if defined(__i386__) || (defined(__x86_64__) && !defined(__APPLE__)) |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 553 | Thread* self = Thread::Current(); |
| 554 | |
| 555 | uint32_t orig[20]; |
| 556 | uint32_t trg[20]; |
| 557 | for (size_t i = 0; i < 20; ++i) { |
| 558 | orig[i] = i; |
| 559 | trg[i] = 0; |
| 560 | } |
| 561 | |
| 562 | Invoke3(reinterpret_cast<size_t>(&trg[4]), reinterpret_cast<size_t>(&orig[4]), |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 563 | 10 * sizeof(uint32_t), StubTest::GetEntrypoint(self, kQuickMemcpy), self); |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 564 | |
| 565 | EXPECT_EQ(orig[0], trg[0]); |
| 566 | |
| 567 | for (size_t i = 1; i < 4; ++i) { |
| 568 | EXPECT_NE(orig[i], trg[i]); |
| 569 | } |
| 570 | |
| 571 | for (size_t i = 4; i < 14; ++i) { |
| 572 | EXPECT_EQ(orig[i], trg[i]); |
| 573 | } |
| 574 | |
| 575 | for (size_t i = 14; i < 20; ++i) { |
| 576 | EXPECT_NE(orig[i], trg[i]); |
| 577 | } |
| 578 | |
| 579 | // TODO: Test overlapping? |
| 580 | |
| 581 | #else |
| 582 | LOG(INFO) << "Skipping memcpy as I don't know how to do that on " << kRuntimeISA; |
| 583 | // Force-print to std::cout so it's also outside the logcat. |
| 584 | std::cout << "Skipping memcpy as I don't know how to do that on " << kRuntimeISA << std::endl; |
| 585 | #endif |
| 586 | } |
| 587 | |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 588 | TEST_F(StubTest, LockObject) { |
Ian Rogers | c3ccc10 | 2014-06-25 11:52:14 -0700 | [diff] [blame] | 589 | #if defined(__i386__) || defined(__arm__) || defined(__aarch64__) || (defined(__x86_64__) && !defined(__APPLE__)) |
Andreas Gampe | 2ba8d4b | 2014-05-02 17:33:17 -0700 | [diff] [blame] | 590 | static constexpr size_t kThinLockLoops = 100; |
| 591 | |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 592 | Thread* self = Thread::Current(); |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 593 | |
| 594 | const uintptr_t art_quick_lock_object = StubTest::GetEntrypoint(self, kQuickLockObject); |
| 595 | |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 596 | // Create an object |
| 597 | ScopedObjectAccess soa(self); |
| 598 | // garbage is created during ClassLinker::Init |
| 599 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 600 | StackHandleScope<2> hs(soa.Self()); |
| 601 | Handle<mirror::String> obj( |
| 602 | hs.NewHandle(mirror::String::AllocFromModifiedUtf8(soa.Self(), "hello, world!"))); |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 603 | LockWord lock = obj->GetLockWord(false); |
| 604 | LockWord::LockState old_state = lock.GetState(); |
| 605 | EXPECT_EQ(LockWord::LockState::kUnlocked, old_state); |
| 606 | |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 607 | Invoke3(reinterpret_cast<size_t>(obj.Get()), 0U, 0U, art_quick_lock_object, self); |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 608 | |
| 609 | LockWord lock_after = obj->GetLockWord(false); |
| 610 | LockWord::LockState new_state = lock_after.GetState(); |
| 611 | EXPECT_EQ(LockWord::LockState::kThinLocked, new_state); |
Andreas Gampe | 7177d7c | 2014-05-02 12:10:02 -0700 | [diff] [blame] | 612 | EXPECT_EQ(lock_after.ThinLockCount(), 0U); // Thin lock starts count at zero |
| 613 | |
| 614 | for (size_t i = 1; i < kThinLockLoops; ++i) { |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 615 | Invoke3(reinterpret_cast<size_t>(obj.Get()), 0U, 0U, art_quick_lock_object, self); |
Andreas Gampe | 7177d7c | 2014-05-02 12:10:02 -0700 | [diff] [blame] | 616 | |
| 617 | // Check we're at lock count i |
| 618 | |
| 619 | LockWord l_inc = obj->GetLockWord(false); |
| 620 | LockWord::LockState l_inc_state = l_inc.GetState(); |
| 621 | EXPECT_EQ(LockWord::LockState::kThinLocked, l_inc_state); |
| 622 | EXPECT_EQ(l_inc.ThinLockCount(), i); |
| 623 | } |
| 624 | |
Andreas Gampe | 4fc046e | 2014-05-06 16:56:39 -0700 | [diff] [blame] | 625 | // Force a fat lock by running identity hashcode to fill up lock word. |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 626 | Handle<mirror::String> obj2(hs.NewHandle( |
| 627 | mirror::String::AllocFromModifiedUtf8(soa.Self(), "hello, world!"))); |
Andreas Gampe | 7177d7c | 2014-05-02 12:10:02 -0700 | [diff] [blame] | 628 | |
Andreas Gampe | 4fc046e | 2014-05-06 16:56:39 -0700 | [diff] [blame] | 629 | obj2->IdentityHashCode(); |
| 630 | |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 631 | Invoke3(reinterpret_cast<size_t>(obj2.Get()), 0U, 0U, art_quick_lock_object, self); |
Andreas Gampe | 4fc046e | 2014-05-06 16:56:39 -0700 | [diff] [blame] | 632 | |
| 633 | LockWord lock_after2 = obj2->GetLockWord(false); |
| 634 | LockWord::LockState new_state2 = lock_after2.GetState(); |
| 635 | EXPECT_EQ(LockWord::LockState::kFatLocked, new_state2); |
| 636 | EXPECT_NE(lock_after2.FatLockMonitor(), static_cast<Monitor*>(nullptr)); |
| 637 | |
| 638 | // Test done. |
Andreas Gampe | 7177d7c | 2014-05-02 12:10:02 -0700 | [diff] [blame] | 639 | #else |
| 640 | LOG(INFO) << "Skipping lock_object as I don't know how to do that on " << kRuntimeISA; |
| 641 | // Force-print to std::cout so it's also outside the logcat. |
| 642 | std::cout << "Skipping lock_object as I don't know how to do that on " << kRuntimeISA << std::endl; |
| 643 | #endif |
| 644 | } |
| 645 | |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 646 | |
Andreas Gampe | 7177d7c | 2014-05-02 12:10:02 -0700 | [diff] [blame] | 647 | class RandGen { |
| 648 | public: |
| 649 | explicit RandGen(uint32_t seed) : val_(seed) {} |
| 650 | |
| 651 | uint32_t next() { |
| 652 | val_ = val_ * 48271 % 2147483647 + 13; |
| 653 | return val_; |
| 654 | } |
| 655 | |
| 656 | uint32_t val_; |
| 657 | }; |
| 658 | |
| 659 | |
Andreas Gampe | 4fc046e | 2014-05-06 16:56:39 -0700 | [diff] [blame] | 660 | // NO_THREAD_SAFETY_ANALYSIS as we do not want to grab exclusive mutator lock for MonitorInfo. |
| 661 | static void TestUnlockObject(StubTest* test) NO_THREAD_SAFETY_ANALYSIS { |
Ian Rogers | c3ccc10 | 2014-06-25 11:52:14 -0700 | [diff] [blame] | 662 | #if defined(__i386__) || defined(__arm__) || defined(__aarch64__) || (defined(__x86_64__) && !defined(__APPLE__)) |
Andreas Gampe | 2ba8d4b | 2014-05-02 17:33:17 -0700 | [diff] [blame] | 663 | static constexpr size_t kThinLockLoops = 100; |
| 664 | |
Andreas Gampe | 7177d7c | 2014-05-02 12:10:02 -0700 | [diff] [blame] | 665 | Thread* self = Thread::Current(); |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 666 | |
| 667 | const uintptr_t art_quick_lock_object = StubTest::GetEntrypoint(self, kQuickLockObject); |
| 668 | const uintptr_t art_quick_unlock_object = StubTest::GetEntrypoint(self, kQuickUnlockObject); |
Andreas Gampe | 7177d7c | 2014-05-02 12:10:02 -0700 | [diff] [blame] | 669 | // Create an object |
| 670 | ScopedObjectAccess soa(self); |
| 671 | // garbage is created during ClassLinker::Init |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 672 | static constexpr size_t kNumberOfLocks = 10; // Number of objects = lock |
| 673 | StackHandleScope<kNumberOfLocks + 1> hs(self); |
| 674 | Handle<mirror::String> obj( |
| 675 | hs.NewHandle(mirror::String::AllocFromModifiedUtf8(soa.Self(), "hello, world!"))); |
Andreas Gampe | 7177d7c | 2014-05-02 12:10:02 -0700 | [diff] [blame] | 676 | LockWord lock = obj->GetLockWord(false); |
| 677 | LockWord::LockState old_state = lock.GetState(); |
| 678 | EXPECT_EQ(LockWord::LockState::kUnlocked, old_state); |
| 679 | |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 680 | test->Invoke3(reinterpret_cast<size_t>(obj.Get()), 0U, 0U, art_quick_unlock_object, self); |
Andreas Gampe | 7177d7c | 2014-05-02 12:10:02 -0700 | [diff] [blame] | 681 | // This should be an illegal monitor state. |
| 682 | EXPECT_TRUE(self->IsExceptionPending()); |
| 683 | self->ClearException(); |
| 684 | |
| 685 | LockWord lock_after = obj->GetLockWord(false); |
| 686 | LockWord::LockState new_state = lock_after.GetState(); |
| 687 | EXPECT_EQ(LockWord::LockState::kUnlocked, new_state); |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 688 | |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 689 | test->Invoke3(reinterpret_cast<size_t>(obj.Get()), 0U, 0U, art_quick_lock_object, self); |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 690 | |
| 691 | LockWord lock_after2 = obj->GetLockWord(false); |
| 692 | LockWord::LockState new_state2 = lock_after2.GetState(); |
| 693 | EXPECT_EQ(LockWord::LockState::kThinLocked, new_state2); |
| 694 | |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 695 | test->Invoke3(reinterpret_cast<size_t>(obj.Get()), 0U, 0U, art_quick_unlock_object, self); |
Andreas Gampe | 7177d7c | 2014-05-02 12:10:02 -0700 | [diff] [blame] | 696 | |
| 697 | LockWord lock_after3 = obj->GetLockWord(false); |
| 698 | LockWord::LockState new_state3 = lock_after3.GetState(); |
| 699 | EXPECT_EQ(LockWord::LockState::kUnlocked, new_state3); |
| 700 | |
| 701 | // Stress test: |
| 702 | // Keep a number of objects and their locks in flight. Randomly lock or unlock one of them in |
| 703 | // each step. |
| 704 | |
| 705 | RandGen r(0x1234); |
| 706 | |
Andreas Gampe | 7177d7c | 2014-05-02 12:10:02 -0700 | [diff] [blame] | 707 | constexpr size_t kIterations = 10000; // Number of iterations |
Andreas Gampe | 4fc046e | 2014-05-06 16:56:39 -0700 | [diff] [blame] | 708 | constexpr size_t kMoveToFat = 1000; // Chance of 1:kMoveFat to make a lock fat. |
Andreas Gampe | 7177d7c | 2014-05-02 12:10:02 -0700 | [diff] [blame] | 709 | |
| 710 | size_t counts[kNumberOfLocks]; |
Andreas Gampe | 4fc046e | 2014-05-06 16:56:39 -0700 | [diff] [blame] | 711 | bool fat[kNumberOfLocks]; // Whether a lock should be thin or fat. |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 712 | Handle<mirror::String> objects[kNumberOfLocks]; |
Andreas Gampe | 7177d7c | 2014-05-02 12:10:02 -0700 | [diff] [blame] | 713 | |
| 714 | // Initialize = allocate. |
| 715 | for (size_t i = 0; i < kNumberOfLocks; ++i) { |
| 716 | counts[i] = 0; |
Andreas Gampe | 4fc046e | 2014-05-06 16:56:39 -0700 | [diff] [blame] | 717 | fat[i] = false; |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 718 | objects[i] = hs.NewHandle(mirror::String::AllocFromModifiedUtf8(soa.Self(), "")); |
Andreas Gampe | 7177d7c | 2014-05-02 12:10:02 -0700 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | for (size_t i = 0; i < kIterations; ++i) { |
| 722 | // Select which lock to update. |
| 723 | size_t index = r.next() % kNumberOfLocks; |
| 724 | |
Andreas Gampe | 4fc046e | 2014-05-06 16:56:39 -0700 | [diff] [blame] | 725 | // Make lock fat? |
| 726 | if (!fat[index] && (r.next() % kMoveToFat == 0)) { |
| 727 | fat[index] = true; |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 728 | objects[index]->IdentityHashCode(); |
Andreas Gampe | 7177d7c | 2014-05-02 12:10:02 -0700 | [diff] [blame] | 729 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 730 | LockWord lock_iter = objects[index]->GetLockWord(false); |
Andreas Gampe | 4fc046e | 2014-05-06 16:56:39 -0700 | [diff] [blame] | 731 | LockWord::LockState iter_state = lock_iter.GetState(); |
| 732 | if (counts[index] == 0) { |
| 733 | EXPECT_EQ(LockWord::LockState::kHashCode, iter_state); |
| 734 | } else { |
| 735 | EXPECT_EQ(LockWord::LockState::kFatLocked, iter_state); |
| 736 | } |
Andreas Gampe | 7177d7c | 2014-05-02 12:10:02 -0700 | [diff] [blame] | 737 | } else { |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 738 | bool take_lock; // Whether to lock or unlock in this step. |
Andreas Gampe | 4fc046e | 2014-05-06 16:56:39 -0700 | [diff] [blame] | 739 | if (counts[index] == 0) { |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 740 | take_lock = true; |
Andreas Gampe | 4fc046e | 2014-05-06 16:56:39 -0700 | [diff] [blame] | 741 | } else if (counts[index] == kThinLockLoops) { |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 742 | take_lock = false; |
Andreas Gampe | 4fc046e | 2014-05-06 16:56:39 -0700 | [diff] [blame] | 743 | } else { |
| 744 | // Randomly. |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 745 | take_lock = r.next() % 2 == 0; |
Andreas Gampe | 4fc046e | 2014-05-06 16:56:39 -0700 | [diff] [blame] | 746 | } |
Andreas Gampe | 7177d7c | 2014-05-02 12:10:02 -0700 | [diff] [blame] | 747 | |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 748 | if (take_lock) { |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 749 | test->Invoke3(reinterpret_cast<size_t>(objects[index].Get()), 0U, 0U, art_quick_lock_object, |
| 750 | self); |
Andreas Gampe | 4fc046e | 2014-05-06 16:56:39 -0700 | [diff] [blame] | 751 | counts[index]++; |
| 752 | } else { |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 753 | test->Invoke3(reinterpret_cast<size_t>(objects[index].Get()), 0U, 0U, |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 754 | art_quick_unlock_object, self); |
Andreas Gampe | 4fc046e | 2014-05-06 16:56:39 -0700 | [diff] [blame] | 755 | counts[index]--; |
| 756 | } |
Andreas Gampe | 7177d7c | 2014-05-02 12:10:02 -0700 | [diff] [blame] | 757 | |
Andreas Gampe | 4fc046e | 2014-05-06 16:56:39 -0700 | [diff] [blame] | 758 | EXPECT_FALSE(self->IsExceptionPending()); |
| 759 | |
| 760 | // Check the new state. |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 761 | LockWord lock_iter = objects[index]->GetLockWord(true); |
Andreas Gampe | 4fc046e | 2014-05-06 16:56:39 -0700 | [diff] [blame] | 762 | LockWord::LockState iter_state = lock_iter.GetState(); |
| 763 | if (fat[index]) { |
| 764 | // Abuse MonitorInfo. |
| 765 | EXPECT_EQ(LockWord::LockState::kFatLocked, iter_state) << index; |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 766 | MonitorInfo info(objects[index].Get()); |
Andreas Gampe | 4fc046e | 2014-05-06 16:56:39 -0700 | [diff] [blame] | 767 | EXPECT_EQ(counts[index], info.entry_count_) << index; |
| 768 | } else { |
| 769 | if (counts[index] > 0) { |
| 770 | EXPECT_EQ(LockWord::LockState::kThinLocked, iter_state); |
| 771 | EXPECT_EQ(counts[index] - 1, lock_iter.ThinLockCount()); |
| 772 | } else { |
| 773 | EXPECT_EQ(LockWord::LockState::kUnlocked, iter_state); |
| 774 | } |
| 775 | } |
Andreas Gampe | 7177d7c | 2014-05-02 12:10:02 -0700 | [diff] [blame] | 776 | } |
| 777 | } |
| 778 | |
| 779 | // Unlock the remaining count times and then check it's unlocked. Then deallocate. |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 780 | // Go reverse order to correctly handle Handles. |
Andreas Gampe | 7177d7c | 2014-05-02 12:10:02 -0700 | [diff] [blame] | 781 | for (size_t i = 0; i < kNumberOfLocks; ++i) { |
| 782 | size_t index = kNumberOfLocks - 1 - i; |
| 783 | size_t count = counts[index]; |
| 784 | while (count > 0) { |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 785 | test->Invoke3(reinterpret_cast<size_t>(objects[index].Get()), 0U, 0U, art_quick_unlock_object, |
| 786 | self); |
Andreas Gampe | 7177d7c | 2014-05-02 12:10:02 -0700 | [diff] [blame] | 787 | count--; |
| 788 | } |
| 789 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 790 | LockWord lock_after4 = objects[index]->GetLockWord(false); |
Andreas Gampe | 7177d7c | 2014-05-02 12:10:02 -0700 | [diff] [blame] | 791 | LockWord::LockState new_state4 = lock_after4.GetState(); |
Andreas Gampe | 4fc046e | 2014-05-06 16:56:39 -0700 | [diff] [blame] | 792 | EXPECT_TRUE(LockWord::LockState::kUnlocked == new_state4 |
| 793 | || LockWord::LockState::kFatLocked == new_state4); |
Andreas Gampe | 7177d7c | 2014-05-02 12:10:02 -0700 | [diff] [blame] | 794 | } |
| 795 | |
Andreas Gampe | 4fc046e | 2014-05-06 16:56:39 -0700 | [diff] [blame] | 796 | // Test done. |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 797 | #else |
Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 798 | UNUSED(test); |
Andreas Gampe | 7177d7c | 2014-05-02 12:10:02 -0700 | [diff] [blame] | 799 | LOG(INFO) << "Skipping unlock_object as I don't know how to do that on " << kRuntimeISA; |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 800 | // Force-print to std::cout so it's also outside the logcat. |
Andreas Gampe | 7177d7c | 2014-05-02 12:10:02 -0700 | [diff] [blame] | 801 | std::cout << "Skipping unlock_object as I don't know how to do that on " << kRuntimeISA << std::endl; |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 802 | #endif |
| 803 | } |
| 804 | |
Andreas Gampe | 4fc046e | 2014-05-06 16:56:39 -0700 | [diff] [blame] | 805 | TEST_F(StubTest, UnlockObject) { |
Andreas Gampe | 369810a | 2015-01-14 19:53:31 -0800 | [diff] [blame] | 806 | // This will lead to monitor error messages in the log. |
| 807 | ScopedLogSeverity sls(LogSeverity::FATAL); |
| 808 | |
Andreas Gampe | 4fc046e | 2014-05-06 16:56:39 -0700 | [diff] [blame] | 809 | TestUnlockObject(this); |
| 810 | } |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 811 | |
Ian Rogers | c3ccc10 | 2014-06-25 11:52:14 -0700 | [diff] [blame] | 812 | #if defined(__i386__) || defined(__arm__) || defined(__aarch64__) || (defined(__x86_64__) && !defined(__APPLE__)) |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 813 | extern "C" void art_quick_check_cast(void); |
| 814 | #endif |
| 815 | |
| 816 | TEST_F(StubTest, CheckCast) { |
Ian Rogers | c3ccc10 | 2014-06-25 11:52:14 -0700 | [diff] [blame] | 817 | #if defined(__i386__) || defined(__arm__) || defined(__aarch64__) || (defined(__x86_64__) && !defined(__APPLE__)) |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 818 | Thread* self = Thread::Current(); |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 819 | |
| 820 | const uintptr_t art_quick_check_cast = StubTest::GetEntrypoint(self, kQuickCheckCast); |
| 821 | |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 822 | // Find some classes. |
| 823 | ScopedObjectAccess soa(self); |
| 824 | // garbage is created during ClassLinker::Init |
| 825 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 826 | StackHandleScope<2> hs(soa.Self()); |
| 827 | Handle<mirror::Class> c( |
| 828 | hs.NewHandle(class_linker_->FindSystemClass(soa.Self(), "[Ljava/lang/Object;"))); |
| 829 | Handle<mirror::Class> c2( |
| 830 | hs.NewHandle(class_linker_->FindSystemClass(soa.Self(), "[Ljava/lang/String;"))); |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 831 | |
| 832 | EXPECT_FALSE(self->IsExceptionPending()); |
| 833 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 834 | Invoke3(reinterpret_cast<size_t>(c.Get()), reinterpret_cast<size_t>(c.Get()), 0U, |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 835 | art_quick_check_cast, self); |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 836 | |
| 837 | EXPECT_FALSE(self->IsExceptionPending()); |
| 838 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 839 | Invoke3(reinterpret_cast<size_t>(c2.Get()), reinterpret_cast<size_t>(c2.Get()), 0U, |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 840 | art_quick_check_cast, self); |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 841 | |
| 842 | EXPECT_FALSE(self->IsExceptionPending()); |
| 843 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 844 | Invoke3(reinterpret_cast<size_t>(c.Get()), reinterpret_cast<size_t>(c2.Get()), 0U, |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 845 | art_quick_check_cast, self); |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 846 | |
| 847 | EXPECT_FALSE(self->IsExceptionPending()); |
| 848 | |
| 849 | // TODO: Make the following work. But that would require correct managed frames. |
| 850 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 851 | Invoke3(reinterpret_cast<size_t>(c2.Get()), reinterpret_cast<size_t>(c.Get()), 0U, |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 852 | art_quick_check_cast, self); |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 853 | |
| 854 | EXPECT_TRUE(self->IsExceptionPending()); |
| 855 | self->ClearException(); |
| 856 | |
| 857 | #else |
| 858 | LOG(INFO) << "Skipping check_cast as I don't know how to do that on " << kRuntimeISA; |
| 859 | // Force-print to std::cout so it's also outside the logcat. |
| 860 | std::cout << "Skipping check_cast as I don't know how to do that on " << kRuntimeISA << std::endl; |
| 861 | #endif |
| 862 | } |
| 863 | |
| 864 | |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 865 | TEST_F(StubTest, APutObj) { |
Hiroshi Yamauchi | d6881ae | 2014-04-28 17:21:48 -0700 | [diff] [blame] | 866 | TEST_DISABLED_FOR_HEAP_REFERENCE_POISONING(); |
| 867 | |
Ian Rogers | c3ccc10 | 2014-06-25 11:52:14 -0700 | [diff] [blame] | 868 | #if defined(__i386__) || defined(__arm__) || defined(__aarch64__) || (defined(__x86_64__) && !defined(__APPLE__)) |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 869 | Thread* self = Thread::Current(); |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 870 | |
| 871 | // Do not check non-checked ones, we'd need handlers and stuff... |
| 872 | const uintptr_t art_quick_aput_obj_with_null_and_bound_check = |
| 873 | StubTest::GetEntrypoint(self, kQuickAputObjectWithNullAndBoundCheck); |
| 874 | |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 875 | // Create an object |
| 876 | ScopedObjectAccess soa(self); |
| 877 | // garbage is created during ClassLinker::Init |
| 878 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 879 | StackHandleScope<5> hs(soa.Self()); |
| 880 | Handle<mirror::Class> c( |
| 881 | hs.NewHandle(class_linker_->FindSystemClass(soa.Self(), "Ljava/lang/Object;"))); |
| 882 | Handle<mirror::Class> ca( |
| 883 | hs.NewHandle(class_linker_->FindSystemClass(soa.Self(), "[Ljava/lang/String;"))); |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 884 | |
| 885 | // Build a string array of size 1 |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 886 | Handle<mirror::ObjectArray<mirror::Object>> array( |
| 887 | hs.NewHandle(mirror::ObjectArray<mirror::Object>::Alloc(soa.Self(), ca.Get(), 10))); |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 888 | |
| 889 | // Build a string -> should be assignable |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 890 | Handle<mirror::String> str_obj( |
| 891 | hs.NewHandle(mirror::String::AllocFromModifiedUtf8(soa.Self(), "hello, world!"))); |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 892 | |
| 893 | // Build a generic object -> should fail assigning |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 894 | Handle<mirror::Object> obj_obj(hs.NewHandle(c->AllocObject(soa.Self()))); |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 895 | |
| 896 | // Play with it... |
| 897 | |
| 898 | // 1) Success cases |
Andreas Gampe | f4e910b | 2014-04-29 16:55:52 -0700 | [diff] [blame] | 899 | // 1.1) Assign str_obj to array[0..3] |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 900 | |
| 901 | EXPECT_FALSE(self->IsExceptionPending()); |
| 902 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 903 | Invoke3(reinterpret_cast<size_t>(array.Get()), 0U, reinterpret_cast<size_t>(str_obj.Get()), |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 904 | art_quick_aput_obj_with_null_and_bound_check, self); |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 905 | |
| 906 | EXPECT_FALSE(self->IsExceptionPending()); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 907 | EXPECT_EQ(str_obj.Get(), array->Get(0)); |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 908 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 909 | Invoke3(reinterpret_cast<size_t>(array.Get()), 1U, reinterpret_cast<size_t>(str_obj.Get()), |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 910 | art_quick_aput_obj_with_null_and_bound_check, self); |
Andreas Gampe | f4e910b | 2014-04-29 16:55:52 -0700 | [diff] [blame] | 911 | |
| 912 | EXPECT_FALSE(self->IsExceptionPending()); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 913 | EXPECT_EQ(str_obj.Get(), array->Get(1)); |
Andreas Gampe | f4e910b | 2014-04-29 16:55:52 -0700 | [diff] [blame] | 914 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 915 | Invoke3(reinterpret_cast<size_t>(array.Get()), 2U, reinterpret_cast<size_t>(str_obj.Get()), |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 916 | art_quick_aput_obj_with_null_and_bound_check, self); |
Andreas Gampe | f4e910b | 2014-04-29 16:55:52 -0700 | [diff] [blame] | 917 | |
| 918 | EXPECT_FALSE(self->IsExceptionPending()); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 919 | EXPECT_EQ(str_obj.Get(), array->Get(2)); |
Andreas Gampe | f4e910b | 2014-04-29 16:55:52 -0700 | [diff] [blame] | 920 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 921 | Invoke3(reinterpret_cast<size_t>(array.Get()), 3U, reinterpret_cast<size_t>(str_obj.Get()), |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 922 | art_quick_aput_obj_with_null_and_bound_check, self); |
Andreas Gampe | f4e910b | 2014-04-29 16:55:52 -0700 | [diff] [blame] | 923 | |
| 924 | EXPECT_FALSE(self->IsExceptionPending()); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 925 | EXPECT_EQ(str_obj.Get(), array->Get(3)); |
Andreas Gampe | f4e910b | 2014-04-29 16:55:52 -0700 | [diff] [blame] | 926 | |
| 927 | // 1.2) Assign null to array[0..3] |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 928 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 929 | Invoke3(reinterpret_cast<size_t>(array.Get()), 0U, reinterpret_cast<size_t>(nullptr), |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 930 | art_quick_aput_obj_with_null_and_bound_check, self); |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 931 | |
| 932 | EXPECT_FALSE(self->IsExceptionPending()); |
Andreas Gampe | f4e910b | 2014-04-29 16:55:52 -0700 | [diff] [blame] | 933 | EXPECT_EQ(nullptr, array->Get(0)); |
| 934 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 935 | Invoke3(reinterpret_cast<size_t>(array.Get()), 1U, reinterpret_cast<size_t>(nullptr), |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 936 | art_quick_aput_obj_with_null_and_bound_check, self); |
Andreas Gampe | f4e910b | 2014-04-29 16:55:52 -0700 | [diff] [blame] | 937 | |
| 938 | EXPECT_FALSE(self->IsExceptionPending()); |
| 939 | EXPECT_EQ(nullptr, array->Get(1)); |
| 940 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 941 | Invoke3(reinterpret_cast<size_t>(array.Get()), 2U, reinterpret_cast<size_t>(nullptr), |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 942 | art_quick_aput_obj_with_null_and_bound_check, self); |
Andreas Gampe | f4e910b | 2014-04-29 16:55:52 -0700 | [diff] [blame] | 943 | |
| 944 | EXPECT_FALSE(self->IsExceptionPending()); |
| 945 | EXPECT_EQ(nullptr, array->Get(2)); |
| 946 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 947 | Invoke3(reinterpret_cast<size_t>(array.Get()), 3U, reinterpret_cast<size_t>(nullptr), |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 948 | art_quick_aput_obj_with_null_and_bound_check, self); |
Andreas Gampe | f4e910b | 2014-04-29 16:55:52 -0700 | [diff] [blame] | 949 | |
| 950 | EXPECT_FALSE(self->IsExceptionPending()); |
| 951 | EXPECT_EQ(nullptr, array->Get(3)); |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 952 | |
| 953 | // TODO: Check _which_ exception is thrown. Then make 3) check that it's the right check order. |
| 954 | |
| 955 | // 2) Failure cases (str into str[]) |
| 956 | // 2.1) Array = null |
| 957 | // TODO: Throwing NPE needs actual DEX code |
| 958 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 959 | // Invoke3(reinterpret_cast<size_t>(nullptr), 0U, reinterpret_cast<size_t>(str_obj.Get()), |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 960 | // reinterpret_cast<uintptr_t>(&art_quick_aput_obj_with_null_and_bound_check), self); |
| 961 | // |
| 962 | // EXPECT_TRUE(self->IsExceptionPending()); |
| 963 | // self->ClearException(); |
| 964 | |
| 965 | // 2.2) Index < 0 |
| 966 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 967 | Invoke3(reinterpret_cast<size_t>(array.Get()), static_cast<size_t>(-1), |
| 968 | reinterpret_cast<size_t>(str_obj.Get()), |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 969 | art_quick_aput_obj_with_null_and_bound_check, self); |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 970 | |
| 971 | EXPECT_TRUE(self->IsExceptionPending()); |
| 972 | self->ClearException(); |
| 973 | |
| 974 | // 2.3) Index > 0 |
| 975 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 976 | Invoke3(reinterpret_cast<size_t>(array.Get()), 10U, reinterpret_cast<size_t>(str_obj.Get()), |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 977 | art_quick_aput_obj_with_null_and_bound_check, self); |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 978 | |
| 979 | EXPECT_TRUE(self->IsExceptionPending()); |
| 980 | self->ClearException(); |
| 981 | |
| 982 | // 3) Failure cases (obj into str[]) |
| 983 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 984 | Invoke3(reinterpret_cast<size_t>(array.Get()), 0U, reinterpret_cast<size_t>(obj_obj.Get()), |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 985 | art_quick_aput_obj_with_null_and_bound_check, self); |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 986 | |
| 987 | EXPECT_TRUE(self->IsExceptionPending()); |
| 988 | self->ClearException(); |
| 989 | |
| 990 | // Tests done. |
| 991 | #else |
| 992 | LOG(INFO) << "Skipping aput_obj as I don't know how to do that on " << kRuntimeISA; |
| 993 | // Force-print to std::cout so it's also outside the logcat. |
| 994 | std::cout << "Skipping aput_obj as I don't know how to do that on " << kRuntimeISA << std::endl; |
| 995 | #endif |
| 996 | } |
| 997 | |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 998 | TEST_F(StubTest, AllocObject) { |
| 999 | TEST_DISABLED_FOR_HEAP_REFERENCE_POISONING(); |
| 1000 | |
Ian Rogers | c3ccc10 | 2014-06-25 11:52:14 -0700 | [diff] [blame] | 1001 | #if defined(__i386__) || defined(__arm__) || defined(__aarch64__) || (defined(__x86_64__) && !defined(__APPLE__)) |
Andreas Gampe | 369810a | 2015-01-14 19:53:31 -0800 | [diff] [blame] | 1002 | // This will lead to OOM error messages in the log. |
| 1003 | ScopedLogSeverity sls(LogSeverity::FATAL); |
| 1004 | |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 1005 | // TODO: Check the "Unresolved" allocation stubs |
| 1006 | |
| 1007 | Thread* self = Thread::Current(); |
| 1008 | // Create an object |
| 1009 | ScopedObjectAccess soa(self); |
| 1010 | // garbage is created during ClassLinker::Init |
| 1011 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1012 | StackHandleScope<2> hs(soa.Self()); |
| 1013 | Handle<mirror::Class> c( |
| 1014 | hs.NewHandle(class_linker_->FindSystemClass(soa.Self(), "Ljava/lang/Object;"))); |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 1015 | |
| 1016 | // Play with it... |
| 1017 | |
| 1018 | EXPECT_FALSE(self->IsExceptionPending()); |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 1019 | { |
| 1020 | // Use an arbitrary method from c to use as referrer |
| 1021 | size_t result = Invoke3(static_cast<size_t>(c->GetDexTypeIndex()), // type_idx |
| 1022 | reinterpret_cast<size_t>(c->GetVirtualMethod(0)), // arbitrary |
| 1023 | 0U, |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 1024 | StubTest::GetEntrypoint(self, kQuickAllocObject), |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 1025 | self); |
| 1026 | |
| 1027 | EXPECT_FALSE(self->IsExceptionPending()); |
| 1028 | EXPECT_NE(reinterpret_cast<size_t>(nullptr), result); |
| 1029 | mirror::Object* obj = reinterpret_cast<mirror::Object*>(result); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1030 | EXPECT_EQ(c.Get(), obj->GetClass()); |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 1031 | VerifyObject(obj); |
| 1032 | } |
| 1033 | |
| 1034 | { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 1035 | // We can use null in the second argument as we do not need a method here (not used in |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 1036 | // resolved/initialized cases) |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1037 | size_t result = Invoke3(reinterpret_cast<size_t>(c.Get()), reinterpret_cast<size_t>(nullptr), 0U, |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 1038 | StubTest::GetEntrypoint(self, kQuickAllocObjectResolved), |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 1039 | self); |
| 1040 | |
| 1041 | EXPECT_FALSE(self->IsExceptionPending()); |
| 1042 | EXPECT_NE(reinterpret_cast<size_t>(nullptr), result); |
| 1043 | mirror::Object* obj = reinterpret_cast<mirror::Object*>(result); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1044 | EXPECT_EQ(c.Get(), obj->GetClass()); |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 1045 | VerifyObject(obj); |
| 1046 | } |
| 1047 | |
| 1048 | { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 1049 | // We can use null in the second argument as we do not need a method here (not used in |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 1050 | // resolved/initialized cases) |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1051 | size_t result = Invoke3(reinterpret_cast<size_t>(c.Get()), reinterpret_cast<size_t>(nullptr), 0U, |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 1052 | StubTest::GetEntrypoint(self, kQuickAllocObjectInitialized), |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 1053 | self); |
| 1054 | |
| 1055 | EXPECT_FALSE(self->IsExceptionPending()); |
| 1056 | EXPECT_NE(reinterpret_cast<size_t>(nullptr), result); |
| 1057 | mirror::Object* obj = reinterpret_cast<mirror::Object*>(result); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1058 | EXPECT_EQ(c.Get(), obj->GetClass()); |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 1059 | VerifyObject(obj); |
| 1060 | } |
| 1061 | |
| 1062 | // Failure tests. |
| 1063 | |
| 1064 | // Out-of-memory. |
| 1065 | { |
| 1066 | Runtime::Current()->GetHeap()->SetIdealFootprint(1 * GB); |
| 1067 | |
| 1068 | // Array helps to fill memory faster. |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1069 | Handle<mirror::Class> ca( |
| 1070 | hs.NewHandle(class_linker_->FindSystemClass(soa.Self(), "[Ljava/lang/Object;"))); |
| 1071 | |
| 1072 | // Use arbitrary large amount for now. |
| 1073 | static const size_t kMaxHandles = 1000000; |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 1074 | std::unique_ptr<StackHandleScope<kMaxHandles>> hsp(new StackHandleScope<kMaxHandles>(self)); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1075 | |
| 1076 | std::vector<Handle<mirror::Object>> handles; |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 1077 | // Start allocating with 128K |
| 1078 | size_t length = 128 * KB / 4; |
| 1079 | while (length > 10) { |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1080 | Handle<mirror::Object> h(hsp->NewHandle<mirror::Object>( |
| 1081 | mirror::ObjectArray<mirror::Object>::Alloc(soa.Self(), ca.Get(), length / 4))); |
| 1082 | if (self->IsExceptionPending() || h.Get() == nullptr) { |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 1083 | self->ClearException(); |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 1084 | |
| 1085 | // Try a smaller length |
| 1086 | length = length / 8; |
| 1087 | // Use at most half the reported free space. |
| 1088 | size_t mem = Runtime::Current()->GetHeap()->GetFreeMemory(); |
| 1089 | if (length * 8 > mem) { |
| 1090 | length = mem / 8; |
| 1091 | } |
| 1092 | } else { |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1093 | handles.push_back(h); |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 1094 | } |
| 1095 | } |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1096 | LOG(INFO) << "Used " << handles.size() << " arrays to fill space."; |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 1097 | |
| 1098 | // Allocate simple objects till it fails. |
| 1099 | while (!self->IsExceptionPending()) { |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1100 | Handle<mirror::Object> h = hsp->NewHandle(c->AllocObject(soa.Self())); |
| 1101 | if (!self->IsExceptionPending() && h.Get() != nullptr) { |
| 1102 | handles.push_back(h); |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 1103 | } |
| 1104 | } |
| 1105 | self->ClearException(); |
| 1106 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1107 | size_t result = Invoke3(reinterpret_cast<size_t>(c.Get()), reinterpret_cast<size_t>(nullptr), 0U, |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 1108 | StubTest::GetEntrypoint(self, kQuickAllocObjectInitialized), |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 1109 | self); |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 1110 | EXPECT_TRUE(self->IsExceptionPending()); |
| 1111 | self->ClearException(); |
| 1112 | EXPECT_EQ(reinterpret_cast<size_t>(nullptr), result); |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 1113 | } |
| 1114 | |
| 1115 | // Tests done. |
| 1116 | #else |
| 1117 | LOG(INFO) << "Skipping alloc_object as I don't know how to do that on " << kRuntimeISA; |
| 1118 | // Force-print to std::cout so it's also outside the logcat. |
| 1119 | std::cout << "Skipping alloc_object as I don't know how to do that on " << kRuntimeISA << std::endl; |
| 1120 | #endif |
| 1121 | } |
| 1122 | |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 1123 | TEST_F(StubTest, AllocObjectArray) { |
| 1124 | TEST_DISABLED_FOR_HEAP_REFERENCE_POISONING(); |
| 1125 | |
Ian Rogers | c3ccc10 | 2014-06-25 11:52:14 -0700 | [diff] [blame] | 1126 | #if defined(__i386__) || defined(__arm__) || defined(__aarch64__) || (defined(__x86_64__) && !defined(__APPLE__)) |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 1127 | // TODO: Check the "Unresolved" allocation stubs |
| 1128 | |
Andreas Gampe | 369810a | 2015-01-14 19:53:31 -0800 | [diff] [blame] | 1129 | // This will lead to OOM error messages in the log. |
| 1130 | ScopedLogSeverity sls(LogSeverity::FATAL); |
| 1131 | |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 1132 | Thread* self = Thread::Current(); |
| 1133 | // Create an object |
| 1134 | ScopedObjectAccess soa(self); |
| 1135 | // garbage is created during ClassLinker::Init |
| 1136 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1137 | StackHandleScope<2> hs(self); |
| 1138 | Handle<mirror::Class> c( |
| 1139 | hs.NewHandle(class_linker_->FindSystemClass(soa.Self(), "[Ljava/lang/Object;"))); |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 1140 | |
| 1141 | // Needed to have a linked method. |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1142 | Handle<mirror::Class> c_obj( |
| 1143 | hs.NewHandle(class_linker_->FindSystemClass(soa.Self(), "Ljava/lang/Object;"))); |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 1144 | |
| 1145 | // Play with it... |
| 1146 | |
| 1147 | EXPECT_FALSE(self->IsExceptionPending()); |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1148 | |
| 1149 | // For some reason this does not work, as the type_idx is artificial and outside what the |
| 1150 | // resolved types of c_obj allow... |
| 1151 | |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 1152 | if ((false)) { |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 1153 | // Use an arbitrary method from c to use as referrer |
| 1154 | size_t result = Invoke3(static_cast<size_t>(c->GetDexTypeIndex()), // type_idx |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 1155 | 10U, |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 1156 | reinterpret_cast<size_t>(c_obj->GetVirtualMethod(0)), // arbitrary |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 1157 | StubTest::GetEntrypoint(self, kQuickAllocArray), |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 1158 | self); |
| 1159 | |
| 1160 | EXPECT_FALSE(self->IsExceptionPending()); |
| 1161 | EXPECT_NE(reinterpret_cast<size_t>(nullptr), result); |
| 1162 | mirror::Array* obj = reinterpret_cast<mirror::Array*>(result); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1163 | EXPECT_EQ(c.Get(), obj->GetClass()); |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 1164 | VerifyObject(obj); |
| 1165 | EXPECT_EQ(obj->GetLength(), 10); |
| 1166 | } |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1167 | |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 1168 | { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 1169 | // We can use null in the second argument as we do not need a method here (not used in |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 1170 | // resolved/initialized cases) |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 1171 | size_t result = Invoke3(reinterpret_cast<size_t>(c.Get()), 10U, |
| 1172 | reinterpret_cast<size_t>(nullptr), |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 1173 | StubTest::GetEntrypoint(self, kQuickAllocArrayResolved), |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 1174 | self); |
Nicolas Geoffray | 14691c5 | 2015-03-05 10:40:17 +0000 | [diff] [blame] | 1175 | EXPECT_FALSE(self->IsExceptionPending()) << PrettyTypeOf(self->GetException()); |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 1176 | EXPECT_NE(reinterpret_cast<size_t>(nullptr), result); |
| 1177 | mirror::Object* obj = reinterpret_cast<mirror::Object*>(result); |
| 1178 | EXPECT_TRUE(obj->IsArrayInstance()); |
| 1179 | EXPECT_TRUE(obj->IsObjectArray()); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1180 | EXPECT_EQ(c.Get(), obj->GetClass()); |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 1181 | VerifyObject(obj); |
| 1182 | mirror::Array* array = reinterpret_cast<mirror::Array*>(result); |
| 1183 | EXPECT_EQ(array->GetLength(), 10); |
| 1184 | } |
| 1185 | |
| 1186 | // Failure tests. |
| 1187 | |
| 1188 | // Out-of-memory. |
| 1189 | { |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 1190 | size_t result = Invoke3(reinterpret_cast<size_t>(c.Get()), |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 1191 | GB, // that should fail... |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 1192 | reinterpret_cast<size_t>(nullptr), |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 1193 | StubTest::GetEntrypoint(self, kQuickAllocArrayResolved), |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 1194 | self); |
| 1195 | |
| 1196 | EXPECT_TRUE(self->IsExceptionPending()); |
| 1197 | self->ClearException(); |
| 1198 | EXPECT_EQ(reinterpret_cast<size_t>(nullptr), result); |
| 1199 | } |
| 1200 | |
| 1201 | // Tests done. |
| 1202 | #else |
| 1203 | LOG(INFO) << "Skipping alloc_array as I don't know how to do that on " << kRuntimeISA; |
| 1204 | // Force-print to std::cout so it's also outside the logcat. |
| 1205 | std::cout << "Skipping alloc_array as I don't know how to do that on " << kRuntimeISA << std::endl; |
| 1206 | #endif |
| 1207 | } |
| 1208 | |
Alexei Zavjalov | 315ccab | 2014-05-01 23:24:05 +0700 | [diff] [blame] | 1209 | |
Alexei Zavjalov | 315ccab | 2014-05-01 23:24:05 +0700 | [diff] [blame] | 1210 | TEST_F(StubTest, StringCompareTo) { |
| 1211 | TEST_DISABLED_FOR_HEAP_REFERENCE_POISONING(); |
| 1212 | |
Ian Rogers | c3ccc10 | 2014-06-25 11:52:14 -0700 | [diff] [blame] | 1213 | #if defined(__i386__) || defined(__arm__) || defined(__aarch64__) || (defined(__x86_64__) && !defined(__APPLE__)) |
Alexei Zavjalov | 315ccab | 2014-05-01 23:24:05 +0700 | [diff] [blame] | 1214 | // TODO: Check the "Unresolved" allocation stubs |
| 1215 | |
| 1216 | Thread* self = Thread::Current(); |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 1217 | |
| 1218 | const uintptr_t art_quick_string_compareto = StubTest::GetEntrypoint(self, kQuickStringCompareTo); |
| 1219 | |
Alexei Zavjalov | 315ccab | 2014-05-01 23:24:05 +0700 | [diff] [blame] | 1220 | ScopedObjectAccess soa(self); |
| 1221 | // garbage is created during ClassLinker::Init |
| 1222 | |
| 1223 | // Create some strings |
| 1224 | // Use array so we can index into it and use a matrix for expected results |
Andreas Gampe | 2ba8d4b | 2014-05-02 17:33:17 -0700 | [diff] [blame] | 1225 | // Setup: The first half is standard. The second half uses a non-zero offset. |
| 1226 | // TODO: Shared backing arrays. |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 1227 | const char* c[] = { "", "", "a", "aa", "ab", |
Serban Constantinescu | 86797a7 | 2014-06-19 16:17:56 +0100 | [diff] [blame] | 1228 | "aacaacaacaacaacaac", // This one's under the default limit to go to __memcmp16. |
| 1229 | "aacaacaacaacaacaacaacaacaacaacaacaac", // This one's over. |
| 1230 | "aacaacaacaacaacaacaacaacaacaacaacaaca" }; // As is this one. We need a separate one to |
| 1231 | // defeat object-equal optimizations. |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1232 | static constexpr size_t kStringCount = arraysize(c); |
Alexei Zavjalov | 315ccab | 2014-05-01 23:24:05 +0700 | [diff] [blame] | 1233 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1234 | StackHandleScope<kStringCount> hs(self); |
| 1235 | Handle<mirror::String> s[kStringCount]; |
Alexei Zavjalov | 315ccab | 2014-05-01 23:24:05 +0700 | [diff] [blame] | 1236 | |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1237 | for (size_t i = 0; i < kStringCount; ++i) { |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1238 | s[i] = hs.NewHandle(mirror::String::AllocFromModifiedUtf8(soa.Self(), c[i])); |
Alexei Zavjalov | 315ccab | 2014-05-01 23:24:05 +0700 | [diff] [blame] | 1239 | } |
| 1240 | |
| 1241 | // TODO: wide characters |
| 1242 | |
| 1243 | // Matrix of expectations. First component is first parameter. Note we only check against the |
Andreas Gampe | 2ba8d4b | 2014-05-02 17:33:17 -0700 | [diff] [blame] | 1244 | // sign, not the value. As we are testing random offsets, we need to compute this and need to |
| 1245 | // rely on String::CompareTo being correct. |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1246 | int32_t expected[kStringCount][kStringCount]; |
| 1247 | for (size_t x = 0; x < kStringCount; ++x) { |
| 1248 | for (size_t y = 0; y < kStringCount; ++y) { |
| 1249 | expected[x][y] = s[x]->CompareTo(s[y].Get()); |
Andreas Gampe | 2ba8d4b | 2014-05-02 17:33:17 -0700 | [diff] [blame] | 1250 | } |
| 1251 | } |
Alexei Zavjalov | 315ccab | 2014-05-01 23:24:05 +0700 | [diff] [blame] | 1252 | |
| 1253 | // Play with it... |
| 1254 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1255 | for (size_t x = 0; x < kStringCount; ++x) { |
| 1256 | for (size_t y = 0; y < kStringCount; ++y) { |
Alexei Zavjalov | 315ccab | 2014-05-01 23:24:05 +0700 | [diff] [blame] | 1257 | // Test string_compareto x y |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1258 | size_t result = Invoke3(reinterpret_cast<size_t>(s[x].Get()), |
| 1259 | reinterpret_cast<size_t>(s[y].Get()), 0U, |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 1260 | art_quick_string_compareto, self); |
Alexei Zavjalov | 315ccab | 2014-05-01 23:24:05 +0700 | [diff] [blame] | 1261 | |
| 1262 | EXPECT_FALSE(self->IsExceptionPending()); |
| 1263 | |
| 1264 | // The result is a 32b signed integer |
| 1265 | union { |
| 1266 | size_t r; |
| 1267 | int32_t i; |
| 1268 | } conv; |
| 1269 | conv.r = result; |
| 1270 | int32_t e = expected[x][y]; |
Andreas Gampe | 2ba8d4b | 2014-05-02 17:33:17 -0700 | [diff] [blame] | 1271 | EXPECT_TRUE(e == 0 ? conv.i == 0 : true) << "x=" << c[x] << " y=" << c[y] << " res=" << |
| 1272 | conv.r; |
| 1273 | EXPECT_TRUE(e < 0 ? conv.i < 0 : true) << "x=" << c[x] << " y=" << c[y] << " res=" << |
| 1274 | conv.r; |
| 1275 | EXPECT_TRUE(e > 0 ? conv.i > 0 : true) << "x=" << c[x] << " y=" << c[y] << " res=" << |
| 1276 | conv.r; |
Alexei Zavjalov | 315ccab | 2014-05-01 23:24:05 +0700 | [diff] [blame] | 1277 | } |
| 1278 | } |
| 1279 | |
Andreas Gampe | 7177d7c | 2014-05-02 12:10:02 -0700 | [diff] [blame] | 1280 | // TODO: Deallocate things. |
| 1281 | |
Alexei Zavjalov | 315ccab | 2014-05-01 23:24:05 +0700 | [diff] [blame] | 1282 | // Tests done. |
| 1283 | #else |
| 1284 | LOG(INFO) << "Skipping string_compareto as I don't know how to do that on " << kRuntimeISA; |
| 1285 | // Force-print to std::cout so it's also outside the logcat. |
| 1286 | std::cout << "Skipping string_compareto as I don't know how to do that on " << kRuntimeISA << |
| 1287 | std::endl; |
| 1288 | #endif |
| 1289 | } |
| 1290 | |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1291 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1292 | static void GetSetBooleanStatic(ArtField* f, Thread* self, |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1293 | mirror::ArtMethod* referrer, StubTest* test) |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1294 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 1295 | #if defined(__i386__) || defined(__arm__) || defined(__aarch64__) || (defined(__x86_64__) && !defined(__APPLE__)) |
| 1296 | constexpr size_t num_values = 5; |
| 1297 | uint8_t values[num_values] = { 0, 1, 2, 128, 0xFF }; |
| 1298 | |
| 1299 | for (size_t i = 0; i < num_values; ++i) { |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1300 | test->Invoke3WithReferrer(static_cast<size_t>(f->GetDexFieldIndex()), |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1301 | static_cast<size_t>(values[i]), |
| 1302 | 0U, |
| 1303 | StubTest::GetEntrypoint(self, kQuickSet8Static), |
| 1304 | self, |
| 1305 | referrer); |
| 1306 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1307 | size_t res = test->Invoke3WithReferrer(static_cast<size_t>(f->GetDexFieldIndex()), |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1308 | 0U, 0U, |
| 1309 | StubTest::GetEntrypoint(self, kQuickGetBooleanStatic), |
| 1310 | self, |
| 1311 | referrer); |
| 1312 | // Boolean currently stores bools as uint8_t, be more zealous about asserting correct writes/gets. |
| 1313 | EXPECT_EQ(values[i], static_cast<uint8_t>(res)) << "Iteration " << i; |
| 1314 | } |
| 1315 | #else |
Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 1316 | UNUSED(f, self, referrer, test); |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1317 | LOG(INFO) << "Skipping set_boolean_static as I don't know how to do that on " << kRuntimeISA; |
| 1318 | // Force-print to std::cout so it's also outside the logcat. |
| 1319 | std::cout << "Skipping set_boolean_static as I don't know how to do that on " << kRuntimeISA << std::endl; |
| 1320 | #endif |
| 1321 | } |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1322 | static void GetSetByteStatic(ArtField* f, Thread* self, mirror::ArtMethod* referrer, |
| 1323 | StubTest* test) |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1324 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 1325 | #if defined(__i386__) || defined(__arm__) || defined(__aarch64__) || (defined(__x86_64__) && !defined(__APPLE__)) |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 1326 | int8_t values[] = { -128, -64, 0, 64, 127 }; |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1327 | |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 1328 | for (size_t i = 0; i < arraysize(values); ++i) { |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1329 | test->Invoke3WithReferrer(static_cast<size_t>(f->GetDexFieldIndex()), |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1330 | static_cast<size_t>(values[i]), |
| 1331 | 0U, |
| 1332 | StubTest::GetEntrypoint(self, kQuickSet8Static), |
| 1333 | self, |
| 1334 | referrer); |
| 1335 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1336 | size_t res = test->Invoke3WithReferrer(static_cast<size_t>(f->GetDexFieldIndex()), |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1337 | 0U, 0U, |
| 1338 | StubTest::GetEntrypoint(self, kQuickGetByteStatic), |
| 1339 | self, |
| 1340 | referrer); |
| 1341 | EXPECT_EQ(values[i], static_cast<int8_t>(res)) << "Iteration " << i; |
| 1342 | } |
| 1343 | #else |
Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 1344 | UNUSED(f, self, referrer, test); |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1345 | LOG(INFO) << "Skipping set_byte_static as I don't know how to do that on " << kRuntimeISA; |
| 1346 | // Force-print to std::cout so it's also outside the logcat. |
| 1347 | std::cout << "Skipping set_byte_static as I don't know how to do that on " << kRuntimeISA << std::endl; |
| 1348 | #endif |
| 1349 | } |
| 1350 | |
| 1351 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1352 | static void GetSetBooleanInstance(Handle<mirror::Object>* obj, ArtField* f, Thread* self, |
| 1353 | mirror::ArtMethod* referrer, StubTest* test) |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1354 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 1355 | #if defined(__i386__) || defined(__arm__) || defined(__aarch64__) || (defined(__x86_64__) && !defined(__APPLE__)) |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 1356 | uint8_t values[] = { 0, true, 2, 128, 0xFF }; |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1357 | |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 1358 | for (size_t i = 0; i < arraysize(values); ++i) { |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1359 | test->Invoke3WithReferrer(static_cast<size_t>(f->GetDexFieldIndex()), |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1360 | reinterpret_cast<size_t>(obj->Get()), |
| 1361 | static_cast<size_t>(values[i]), |
| 1362 | StubTest::GetEntrypoint(self, kQuickSet8Instance), |
| 1363 | self, |
| 1364 | referrer); |
| 1365 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1366 | uint8_t res = f->GetBoolean(obj->Get()); |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1367 | EXPECT_EQ(values[i], res) << "Iteration " << i; |
| 1368 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1369 | f->SetBoolean<false>(obj->Get(), res); |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1370 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1371 | size_t res2 = test->Invoke3WithReferrer(static_cast<size_t>(f->GetDexFieldIndex()), |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1372 | reinterpret_cast<size_t>(obj->Get()), |
| 1373 | 0U, |
| 1374 | StubTest::GetEntrypoint(self, kQuickGetBooleanInstance), |
| 1375 | self, |
| 1376 | referrer); |
| 1377 | EXPECT_EQ(res, static_cast<uint8_t>(res2)); |
| 1378 | } |
| 1379 | #else |
Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 1380 | UNUSED(obj, f, self, referrer, test); |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1381 | LOG(INFO) << "Skipping set_boolean_instance as I don't know how to do that on " << kRuntimeISA; |
| 1382 | // Force-print to std::cout so it's also outside the logcat. |
| 1383 | std::cout << "Skipping set_boolean_instance as I don't know how to do that on " << kRuntimeISA << std::endl; |
| 1384 | #endif |
| 1385 | } |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1386 | static void GetSetByteInstance(Handle<mirror::Object>* obj, ArtField* f, |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1387 | Thread* self, mirror::ArtMethod* referrer, StubTest* test) |
| 1388 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 1389 | #if defined(__i386__) || defined(__arm__) || defined(__aarch64__) || (defined(__x86_64__) && !defined(__APPLE__)) |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 1390 | int8_t values[] = { -128, -64, 0, 64, 127 }; |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1391 | |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 1392 | for (size_t i = 0; i < arraysize(values); ++i) { |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1393 | test->Invoke3WithReferrer(static_cast<size_t>(f->GetDexFieldIndex()), |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1394 | reinterpret_cast<size_t>(obj->Get()), |
| 1395 | static_cast<size_t>(values[i]), |
| 1396 | StubTest::GetEntrypoint(self, kQuickSet8Instance), |
| 1397 | self, |
| 1398 | referrer); |
| 1399 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1400 | int8_t res = f->GetByte(obj->Get()); |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1401 | EXPECT_EQ(res, values[i]) << "Iteration " << i; |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1402 | f->SetByte<false>(obj->Get(), ++res); |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1403 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1404 | size_t res2 = test->Invoke3WithReferrer(static_cast<size_t>(f->GetDexFieldIndex()), |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1405 | reinterpret_cast<size_t>(obj->Get()), |
| 1406 | 0U, |
| 1407 | StubTest::GetEntrypoint(self, kQuickGetByteInstance), |
| 1408 | self, |
| 1409 | referrer); |
| 1410 | EXPECT_EQ(res, static_cast<int8_t>(res2)); |
| 1411 | } |
| 1412 | #else |
Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 1413 | UNUSED(obj, f, self, referrer, test); |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1414 | LOG(INFO) << "Skipping set_byte_instance as I don't know how to do that on " << kRuntimeISA; |
| 1415 | // Force-print to std::cout so it's also outside the logcat. |
| 1416 | std::cout << "Skipping set_byte_instance as I don't know how to do that on " << kRuntimeISA << std::endl; |
| 1417 | #endif |
| 1418 | } |
| 1419 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1420 | static void GetSetCharStatic(ArtField* f, Thread* self, mirror::ArtMethod* referrer, |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1421 | StubTest* test) |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1422 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 1423 | #if defined(__i386__) || defined(__arm__) || defined(__aarch64__) || (defined(__x86_64__) && !defined(__APPLE__)) |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 1424 | uint16_t values[] = { 0, 1, 2, 255, 32768, 0xFFFF }; |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1425 | |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 1426 | for (size_t i = 0; i < arraysize(values); ++i) { |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1427 | test->Invoke3WithReferrer(static_cast<size_t>(f->GetDexFieldIndex()), |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1428 | static_cast<size_t>(values[i]), |
| 1429 | 0U, |
| 1430 | StubTest::GetEntrypoint(self, kQuickSet16Static), |
| 1431 | self, |
| 1432 | referrer); |
| 1433 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1434 | size_t res = test->Invoke3WithReferrer(static_cast<size_t>(f->GetDexFieldIndex()), |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1435 | 0U, 0U, |
| 1436 | StubTest::GetEntrypoint(self, kQuickGetCharStatic), |
| 1437 | self, |
| 1438 | referrer); |
| 1439 | |
| 1440 | EXPECT_EQ(values[i], static_cast<uint16_t>(res)) << "Iteration " << i; |
| 1441 | } |
| 1442 | #else |
Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 1443 | UNUSED(f, self, referrer, test); |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1444 | LOG(INFO) << "Skipping set_char_static as I don't know how to do that on " << kRuntimeISA; |
| 1445 | // Force-print to std::cout so it's also outside the logcat. |
| 1446 | std::cout << "Skipping set_char_static as I don't know how to do that on " << kRuntimeISA << std::endl; |
| 1447 | #endif |
| 1448 | } |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1449 | static void GetSetShortStatic(ArtField* f, Thread* self, |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1450 | mirror::ArtMethod* referrer, StubTest* test) |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1451 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 1452 | #if defined(__i386__) || defined(__arm__) || defined(__aarch64__) || (defined(__x86_64__) && !defined(__APPLE__)) |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 1453 | int16_t values[] = { -0x7FFF, -32768, 0, 255, 32767, 0x7FFE }; |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1454 | |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 1455 | for (size_t i = 0; i < arraysize(values); ++i) { |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1456 | test->Invoke3WithReferrer(static_cast<size_t>(f->GetDexFieldIndex()), |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1457 | static_cast<size_t>(values[i]), |
| 1458 | 0U, |
| 1459 | StubTest::GetEntrypoint(self, kQuickSet16Static), |
| 1460 | self, |
| 1461 | referrer); |
| 1462 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1463 | size_t res = test->Invoke3WithReferrer(static_cast<size_t>(f->GetDexFieldIndex()), |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1464 | 0U, 0U, |
| 1465 | StubTest::GetEntrypoint(self, kQuickGetShortStatic), |
| 1466 | self, |
| 1467 | referrer); |
| 1468 | |
| 1469 | EXPECT_EQ(static_cast<int16_t>(res), values[i]) << "Iteration " << i; |
| 1470 | } |
| 1471 | #else |
Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 1472 | UNUSED(f, self, referrer, test); |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1473 | LOG(INFO) << "Skipping set_short_static as I don't know how to do that on " << kRuntimeISA; |
| 1474 | // Force-print to std::cout so it's also outside the logcat. |
| 1475 | std::cout << "Skipping set_short_static as I don't know how to do that on " << kRuntimeISA << std::endl; |
| 1476 | #endif |
| 1477 | } |
| 1478 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1479 | static void GetSetCharInstance(Handle<mirror::Object>* obj, ArtField* f, |
| 1480 | Thread* self, mirror::ArtMethod* referrer, StubTest* test) |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1481 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 1482 | #if defined(__i386__) || defined(__arm__) || defined(__aarch64__) || (defined(__x86_64__) && !defined(__APPLE__)) |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 1483 | uint16_t values[] = { 0, 1, 2, 255, 32768, 0xFFFF }; |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1484 | |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 1485 | for (size_t i = 0; i < arraysize(values); ++i) { |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1486 | test->Invoke3WithReferrer(static_cast<size_t>(f->GetDexFieldIndex()), |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1487 | reinterpret_cast<size_t>(obj->Get()), |
| 1488 | static_cast<size_t>(values[i]), |
| 1489 | StubTest::GetEntrypoint(self, kQuickSet16Instance), |
| 1490 | self, |
| 1491 | referrer); |
| 1492 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1493 | uint16_t res = f->GetChar(obj->Get()); |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1494 | EXPECT_EQ(res, values[i]) << "Iteration " << i; |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1495 | f->SetChar<false>(obj->Get(), ++res); |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1496 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1497 | size_t res2 = test->Invoke3WithReferrer(static_cast<size_t>(f->GetDexFieldIndex()), |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1498 | reinterpret_cast<size_t>(obj->Get()), |
| 1499 | 0U, |
| 1500 | StubTest::GetEntrypoint(self, kQuickGetCharInstance), |
| 1501 | self, |
| 1502 | referrer); |
| 1503 | EXPECT_EQ(res, static_cast<uint16_t>(res2)); |
| 1504 | } |
| 1505 | #else |
Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 1506 | UNUSED(obj, f, self, referrer, test); |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1507 | LOG(INFO) << "Skipping set_char_instance as I don't know how to do that on " << kRuntimeISA; |
| 1508 | // Force-print to std::cout so it's also outside the logcat. |
| 1509 | std::cout << "Skipping set_char_instance as I don't know how to do that on " << kRuntimeISA << std::endl; |
| 1510 | #endif |
| 1511 | } |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1512 | static void GetSetShortInstance(Handle<mirror::Object>* obj, ArtField* f, |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1513 | Thread* self, mirror::ArtMethod* referrer, StubTest* test) |
| 1514 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 1515 | #if defined(__i386__) || defined(__arm__) || defined(__aarch64__) || (defined(__x86_64__) && !defined(__APPLE__)) |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 1516 | int16_t values[] = { -0x7FFF, -32768, 0, 255, 32767, 0x7FFE }; |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1517 | |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 1518 | for (size_t i = 0; i < arraysize(values); ++i) { |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1519 | test->Invoke3WithReferrer(static_cast<size_t>(f->GetDexFieldIndex()), |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1520 | reinterpret_cast<size_t>(obj->Get()), |
| 1521 | static_cast<size_t>(values[i]), |
| 1522 | StubTest::GetEntrypoint(self, kQuickSet16Instance), |
| 1523 | self, |
| 1524 | referrer); |
| 1525 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1526 | int16_t res = f->GetShort(obj->Get()); |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1527 | EXPECT_EQ(res, values[i]) << "Iteration " << i; |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1528 | f->SetShort<false>(obj->Get(), ++res); |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1529 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1530 | size_t res2 = test->Invoke3WithReferrer(static_cast<size_t>(f->GetDexFieldIndex()), |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1531 | reinterpret_cast<size_t>(obj->Get()), |
| 1532 | 0U, |
| 1533 | StubTest::GetEntrypoint(self, kQuickGetShortInstance), |
| 1534 | self, |
| 1535 | referrer); |
| 1536 | EXPECT_EQ(res, static_cast<int16_t>(res2)); |
| 1537 | } |
| 1538 | #else |
Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 1539 | UNUSED(obj, f, self, referrer, test); |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1540 | LOG(INFO) << "Skipping set_short_instance as I don't know how to do that on " << kRuntimeISA; |
| 1541 | // Force-print to std::cout so it's also outside the logcat. |
| 1542 | std::cout << "Skipping set_short_instance as I don't know how to do that on " << kRuntimeISA << std::endl; |
| 1543 | #endif |
| 1544 | } |
| 1545 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1546 | static void GetSet32Static(ArtField* f, Thread* self, mirror::ArtMethod* referrer, |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1547 | StubTest* test) |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1548 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | c3ccc10 | 2014-06-25 11:52:14 -0700 | [diff] [blame] | 1549 | #if defined(__i386__) || defined(__arm__) || defined(__aarch64__) || (defined(__x86_64__) && !defined(__APPLE__)) |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 1550 | uint32_t values[] = { 0, 1, 2, 255, 32768, 1000000, 0xFFFFFFFF }; |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1551 | |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 1552 | for (size_t i = 0; i < arraysize(values); ++i) { |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1553 | test->Invoke3WithReferrer(static_cast<size_t>(f->GetDexFieldIndex()), |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1554 | static_cast<size_t>(values[i]), |
| 1555 | 0U, |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 1556 | StubTest::GetEntrypoint(self, kQuickSet32Static), |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1557 | self, |
| 1558 | referrer); |
| 1559 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1560 | size_t res = test->Invoke3WithReferrer(static_cast<size_t>(f->GetDexFieldIndex()), |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1561 | 0U, 0U, |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 1562 | StubTest::GetEntrypoint(self, kQuickGet32Static), |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1563 | self, |
| 1564 | referrer); |
| 1565 | |
| 1566 | EXPECT_EQ(res, values[i]) << "Iteration " << i; |
| 1567 | } |
| 1568 | #else |
Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 1569 | UNUSED(f, self, referrer, test); |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1570 | LOG(INFO) << "Skipping set32static as I don't know how to do that on " << kRuntimeISA; |
| 1571 | // Force-print to std::cout so it's also outside the logcat. |
| 1572 | std::cout << "Skipping set32static as I don't know how to do that on " << kRuntimeISA << std::endl; |
| 1573 | #endif |
| 1574 | } |
| 1575 | |
| 1576 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1577 | static void GetSet32Instance(Handle<mirror::Object>* obj, ArtField* f, |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1578 | Thread* self, mirror::ArtMethod* referrer, StubTest* test) |
| 1579 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | c3ccc10 | 2014-06-25 11:52:14 -0700 | [diff] [blame] | 1580 | #if defined(__i386__) || defined(__arm__) || defined(__aarch64__) || (defined(__x86_64__) && !defined(__APPLE__)) |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 1581 | uint32_t values[] = { 0, 1, 2, 255, 32768, 1000000, 0xFFFFFFFF }; |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1582 | |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 1583 | for (size_t i = 0; i < arraysize(values); ++i) { |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1584 | test->Invoke3WithReferrer(static_cast<size_t>(f->GetDexFieldIndex()), |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1585 | reinterpret_cast<size_t>(obj->Get()), |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1586 | static_cast<size_t>(values[i]), |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 1587 | StubTest::GetEntrypoint(self, kQuickSet32Instance), |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1588 | self, |
| 1589 | referrer); |
| 1590 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1591 | int32_t res = f->GetInt(obj->Get()); |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1592 | EXPECT_EQ(res, static_cast<int32_t>(values[i])) << "Iteration " << i; |
| 1593 | |
| 1594 | res++; |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1595 | f->SetInt<false>(obj->Get(), res); |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1596 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1597 | size_t res2 = test->Invoke3WithReferrer(static_cast<size_t>(f->GetDexFieldIndex()), |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1598 | reinterpret_cast<size_t>(obj->Get()), |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1599 | 0U, |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 1600 | StubTest::GetEntrypoint(self, kQuickGet32Instance), |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1601 | self, |
| 1602 | referrer); |
| 1603 | EXPECT_EQ(res, static_cast<int32_t>(res2)); |
| 1604 | } |
| 1605 | #else |
Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 1606 | UNUSED(obj, f, self, referrer, test); |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1607 | LOG(INFO) << "Skipping set32instance as I don't know how to do that on " << kRuntimeISA; |
| 1608 | // Force-print to std::cout so it's also outside the logcat. |
| 1609 | std::cout << "Skipping set32instance as I don't know how to do that on " << kRuntimeISA << std::endl; |
| 1610 | #endif |
| 1611 | } |
| 1612 | |
| 1613 | |
Ian Rogers | c3ccc10 | 2014-06-25 11:52:14 -0700 | [diff] [blame] | 1614 | #if defined(__i386__) || defined(__arm__) || defined(__aarch64__) || (defined(__x86_64__) && !defined(__APPLE__)) |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1615 | |
| 1616 | static void set_and_check_static(uint32_t f_idx, mirror::Object* val, Thread* self, |
| 1617 | mirror::ArtMethod* referrer, StubTest* test) |
| 1618 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 1619 | test->Invoke3WithReferrer(static_cast<size_t>(f_idx), |
| 1620 | reinterpret_cast<size_t>(val), |
| 1621 | 0U, |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 1622 | StubTest::GetEntrypoint(self, kQuickSetObjStatic), |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1623 | self, |
| 1624 | referrer); |
| 1625 | |
| 1626 | size_t res = test->Invoke3WithReferrer(static_cast<size_t>(f_idx), |
| 1627 | 0U, 0U, |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 1628 | StubTest::GetEntrypoint(self, kQuickGetObjStatic), |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1629 | self, |
| 1630 | referrer); |
| 1631 | |
| 1632 | EXPECT_EQ(res, reinterpret_cast<size_t>(val)) << "Value " << val; |
| 1633 | } |
| 1634 | #endif |
| 1635 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1636 | static void GetSetObjStatic(ArtField* f, Thread* self, mirror::ArtMethod* referrer, |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1637 | StubTest* test) |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1638 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | c3ccc10 | 2014-06-25 11:52:14 -0700 | [diff] [blame] | 1639 | #if defined(__i386__) || defined(__arm__) || defined(__aarch64__) || (defined(__x86_64__) && !defined(__APPLE__)) |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1640 | set_and_check_static(f->GetDexFieldIndex(), nullptr, self, referrer, test); |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1641 | |
| 1642 | // Allocate a string object for simplicity. |
| 1643 | mirror::String* str = mirror::String::AllocFromModifiedUtf8(self, "Test"); |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1644 | set_and_check_static(f->GetDexFieldIndex(), str, self, referrer, test); |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1645 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1646 | set_and_check_static(f->GetDexFieldIndex(), nullptr, self, referrer, test); |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1647 | #else |
Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 1648 | UNUSED(f, self, referrer, test); |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1649 | LOG(INFO) << "Skipping setObjstatic as I don't know how to do that on " << kRuntimeISA; |
| 1650 | // Force-print to std::cout so it's also outside the logcat. |
| 1651 | std::cout << "Skipping setObjstatic as I don't know how to do that on " << kRuntimeISA << std::endl; |
| 1652 | #endif |
| 1653 | } |
| 1654 | |
| 1655 | |
Ian Rogers | c3ccc10 | 2014-06-25 11:52:14 -0700 | [diff] [blame] | 1656 | #if defined(__i386__) || defined(__arm__) || defined(__aarch64__) || (defined(__x86_64__) && !defined(__APPLE__)) |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1657 | static void set_and_check_instance(ArtField* f, mirror::Object* trg, |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1658 | mirror::Object* val, Thread* self, mirror::ArtMethod* referrer, |
| 1659 | StubTest* test) |
| 1660 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1661 | test->Invoke3WithReferrer(static_cast<size_t>(f->GetDexFieldIndex()), |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1662 | reinterpret_cast<size_t>(trg), |
| 1663 | reinterpret_cast<size_t>(val), |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 1664 | StubTest::GetEntrypoint(self, kQuickSetObjInstance), |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1665 | self, |
| 1666 | referrer); |
| 1667 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1668 | size_t res = test->Invoke3WithReferrer(static_cast<size_t>(f->GetDexFieldIndex()), |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1669 | reinterpret_cast<size_t>(trg), |
| 1670 | 0U, |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 1671 | StubTest::GetEntrypoint(self, kQuickGetObjInstance), |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1672 | self, |
| 1673 | referrer); |
| 1674 | |
| 1675 | EXPECT_EQ(res, reinterpret_cast<size_t>(val)) << "Value " << val; |
| 1676 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1677 | EXPECT_EQ(val, f->GetObj(trg)); |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1678 | } |
| 1679 | #endif |
| 1680 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1681 | static void GetSetObjInstance(Handle<mirror::Object>* obj, ArtField* f, |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1682 | Thread* self, mirror::ArtMethod* referrer, StubTest* test) |
| 1683 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | c3ccc10 | 2014-06-25 11:52:14 -0700 | [diff] [blame] | 1684 | #if defined(__i386__) || defined(__arm__) || defined(__aarch64__) || (defined(__x86_64__) && !defined(__APPLE__)) |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1685 | set_and_check_instance(f, obj->Get(), nullptr, self, referrer, test); |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1686 | |
| 1687 | // Allocate a string object for simplicity. |
| 1688 | mirror::String* str = mirror::String::AllocFromModifiedUtf8(self, "Test"); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1689 | set_and_check_instance(f, obj->Get(), str, self, referrer, test); |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1690 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1691 | set_and_check_instance(f, obj->Get(), nullptr, self, referrer, test); |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1692 | #else |
Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 1693 | UNUSED(obj, f, self, referrer, test); |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1694 | LOG(INFO) << "Skipping setObjinstance as I don't know how to do that on " << kRuntimeISA; |
| 1695 | // Force-print to std::cout so it's also outside the logcat. |
| 1696 | std::cout << "Skipping setObjinstance as I don't know how to do that on " << kRuntimeISA << std::endl; |
| 1697 | #endif |
| 1698 | } |
| 1699 | |
| 1700 | |
| 1701 | // TODO: Complete these tests for 32b architectures. |
| 1702 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1703 | static void GetSet64Static(ArtField* f, Thread* self, mirror::ArtMethod* referrer, |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1704 | StubTest* test) |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1705 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | c3ccc10 | 2014-06-25 11:52:14 -0700 | [diff] [blame] | 1706 | #if (defined(__x86_64__) && !defined(__APPLE__)) || defined(__aarch64__) |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 1707 | uint64_t values[] = { 0, 1, 2, 255, 32768, 1000000, 0xFFFFFFFF, 0xFFFFFFFFFFFF }; |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1708 | |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 1709 | for (size_t i = 0; i < arraysize(values); ++i) { |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1710 | test->Invoke3UWithReferrer(static_cast<size_t>(f->GetDexFieldIndex()), |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1711 | values[i], |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 1712 | StubTest::GetEntrypoint(self, kQuickSet64Static), |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1713 | self, |
| 1714 | referrer); |
| 1715 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1716 | size_t res = test->Invoke3WithReferrer(static_cast<size_t>(f->GetDexFieldIndex()), |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1717 | 0U, 0U, |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 1718 | StubTest::GetEntrypoint(self, kQuickGet64Static), |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1719 | self, |
| 1720 | referrer); |
| 1721 | |
| 1722 | EXPECT_EQ(res, values[i]) << "Iteration " << i; |
| 1723 | } |
| 1724 | #else |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1725 | UNUSED(f, self, referrer, test); |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1726 | LOG(INFO) << "Skipping set64static as I don't know how to do that on " << kRuntimeISA; |
| 1727 | // Force-print to std::cout so it's also outside the logcat. |
| 1728 | std::cout << "Skipping set64static as I don't know how to do that on " << kRuntimeISA << std::endl; |
| 1729 | #endif |
| 1730 | } |
| 1731 | |
| 1732 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1733 | static void GetSet64Instance(Handle<mirror::Object>* obj, ArtField* f, |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1734 | Thread* self, mirror::ArtMethod* referrer, StubTest* test) |
| 1735 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | c3ccc10 | 2014-06-25 11:52:14 -0700 | [diff] [blame] | 1736 | #if (defined(__x86_64__) && !defined(__APPLE__)) || defined(__aarch64__) |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 1737 | uint64_t values[] = { 0, 1, 2, 255, 32768, 1000000, 0xFFFFFFFF, 0xFFFFFFFFFFFF }; |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1738 | |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 1739 | for (size_t i = 0; i < arraysize(values); ++i) { |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1740 | test->Invoke3WithReferrer(static_cast<size_t>(f->GetDexFieldIndex()), |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1741 | reinterpret_cast<size_t>(obj->Get()), |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1742 | static_cast<size_t>(values[i]), |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 1743 | StubTest::GetEntrypoint(self, kQuickSet64Instance), |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1744 | self, |
| 1745 | referrer); |
| 1746 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1747 | int64_t res = f->GetLong(obj->Get()); |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1748 | EXPECT_EQ(res, static_cast<int64_t>(values[i])) << "Iteration " << i; |
| 1749 | |
| 1750 | res++; |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1751 | f->SetLong<false>(obj->Get(), res); |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1752 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1753 | size_t res2 = test->Invoke3WithReferrer(static_cast<size_t>(f->GetDexFieldIndex()), |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1754 | reinterpret_cast<size_t>(obj->Get()), |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1755 | 0U, |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 1756 | StubTest::GetEntrypoint(self, kQuickGet64Instance), |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1757 | self, |
| 1758 | referrer); |
| 1759 | EXPECT_EQ(res, static_cast<int64_t>(res2)); |
| 1760 | } |
| 1761 | #else |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1762 | UNUSED(obj, f, self, referrer, test); |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1763 | LOG(INFO) << "Skipping set64instance as I don't know how to do that on " << kRuntimeISA; |
| 1764 | // Force-print to std::cout so it's also outside the logcat. |
| 1765 | std::cout << "Skipping set64instance as I don't know how to do that on " << kRuntimeISA << std::endl; |
| 1766 | #endif |
| 1767 | } |
| 1768 | |
| 1769 | static void TestFields(Thread* self, StubTest* test, Primitive::Type test_type) { |
| 1770 | // garbage is created during ClassLinker::Init |
| 1771 | |
| 1772 | JNIEnv* env = Thread::Current()->GetJniEnv(); |
| 1773 | jclass jc = env->FindClass("AllFields"); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 1774 | CHECK(jc != nullptr); |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1775 | jobject o = env->AllocObject(jc); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 1776 | CHECK(o != nullptr); |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1777 | |
| 1778 | ScopedObjectAccess soa(self); |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1779 | StackHandleScope<4> hs(self); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1780 | Handle<mirror::Object> obj(hs.NewHandle(soa.Decode<mirror::Object*>(o))); |
| 1781 | Handle<mirror::Class> c(hs.NewHandle(obj->GetClass())); |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1782 | // Need a method as a referrer |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1783 | Handle<mirror::ArtMethod> m(hs.NewHandle(c->GetDirectMethod(0))); |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1784 | |
| 1785 | // Play with it... |
| 1786 | |
| 1787 | // Static fields. |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1788 | ArtField* fields = c->GetSFields(); |
| 1789 | size_t num_fields = c->NumStaticFields(); |
| 1790 | for (size_t i = 0; i < num_fields; ++i) { |
| 1791 | ArtField* f = &fields[i]; |
| 1792 | Primitive::Type type = f->GetTypeAsPrimitiveType(); |
| 1793 | if (test_type != type) { |
| 1794 | continue; |
| 1795 | } |
| 1796 | switch (type) { |
| 1797 | case Primitive::Type::kPrimBoolean: |
| 1798 | GetSetBooleanStatic(f, self, m.Get(), test); |
| 1799 | break; |
| 1800 | case Primitive::Type::kPrimByte: |
| 1801 | GetSetByteStatic(f, self, m.Get(), test); |
| 1802 | break; |
| 1803 | case Primitive::Type::kPrimChar: |
| 1804 | GetSetCharStatic(f, self, m.Get(), test); |
| 1805 | break; |
| 1806 | case Primitive::Type::kPrimShort: |
| 1807 | GetSetShortStatic(f, self, m.Get(), test); |
| 1808 | break; |
| 1809 | case Primitive::Type::kPrimInt: |
| 1810 | GetSet32Static(f, self, m.Get(), test); |
| 1811 | break; |
| 1812 | case Primitive::Type::kPrimLong: |
| 1813 | GetSet64Static(f, self, m.Get(), test); |
| 1814 | break; |
| 1815 | case Primitive::Type::kPrimNot: |
| 1816 | // Don't try array. |
| 1817 | if (f->GetTypeDescriptor()[0] != '[') { |
| 1818 | GetSetObjStatic(f, self, m.Get(), test); |
| 1819 | } |
| 1820 | break; |
| 1821 | default: |
| 1822 | break; // Skip. |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1823 | } |
| 1824 | } |
| 1825 | |
| 1826 | // Instance fields. |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1827 | fields = c->GetIFields(); |
| 1828 | num_fields = c->NumInstanceFields(); |
| 1829 | for (size_t i = 0; i < num_fields; ++i) { |
| 1830 | ArtField* f = &fields[i]; |
| 1831 | Primitive::Type type = f->GetTypeAsPrimitiveType(); |
| 1832 | if (test_type != type) { |
| 1833 | continue; |
| 1834 | } |
| 1835 | switch (type) { |
| 1836 | case Primitive::Type::kPrimBoolean: |
| 1837 | GetSetBooleanInstance(&obj, f, self, m.Get(), test); |
| 1838 | break; |
| 1839 | case Primitive::Type::kPrimByte: |
| 1840 | GetSetByteInstance(&obj, f, self, m.Get(), test); |
| 1841 | break; |
| 1842 | case Primitive::Type::kPrimChar: |
| 1843 | GetSetCharInstance(&obj, f, self, m.Get(), test); |
| 1844 | break; |
| 1845 | case Primitive::Type::kPrimShort: |
| 1846 | GetSetShortInstance(&obj, f, self, m.Get(), test); |
| 1847 | break; |
| 1848 | case Primitive::Type::kPrimInt: |
| 1849 | GetSet32Instance(&obj, f, self, m.Get(), test); |
| 1850 | break; |
| 1851 | case Primitive::Type::kPrimLong: |
| 1852 | GetSet64Instance(&obj, f, self, m.Get(), test); |
| 1853 | break; |
| 1854 | case Primitive::Type::kPrimNot: |
| 1855 | // Don't try array. |
| 1856 | if (f->GetTypeDescriptor()[0] != '[') { |
| 1857 | GetSetObjInstance(&obj, f, self, m.Get(), test); |
| 1858 | } |
| 1859 | break; |
| 1860 | default: |
| 1861 | break; // Skip. |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1862 | } |
| 1863 | } |
| 1864 | |
| 1865 | // TODO: Deallocate things. |
| 1866 | } |
| 1867 | |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1868 | TEST_F(StubTest, Fields8) { |
| 1869 | TEST_DISABLED_FOR_HEAP_REFERENCE_POISONING(); |
| 1870 | |
| 1871 | Thread* self = Thread::Current(); |
| 1872 | |
| 1873 | self->TransitionFromSuspendedToRunnable(); |
| 1874 | LoadDex("AllFields"); |
| 1875 | bool started = runtime_->Start(); |
| 1876 | CHECK(started); |
| 1877 | |
| 1878 | TestFields(self, this, Primitive::Type::kPrimBoolean); |
| 1879 | TestFields(self, this, Primitive::Type::kPrimByte); |
| 1880 | } |
| 1881 | |
| 1882 | TEST_F(StubTest, Fields16) { |
| 1883 | TEST_DISABLED_FOR_HEAP_REFERENCE_POISONING(); |
| 1884 | |
| 1885 | Thread* self = Thread::Current(); |
| 1886 | |
| 1887 | self->TransitionFromSuspendedToRunnable(); |
| 1888 | LoadDex("AllFields"); |
| 1889 | bool started = runtime_->Start(); |
| 1890 | CHECK(started); |
| 1891 | |
| 1892 | TestFields(self, this, Primitive::Type::kPrimChar); |
| 1893 | TestFields(self, this, Primitive::Type::kPrimShort); |
| 1894 | } |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1895 | |
| 1896 | TEST_F(StubTest, Fields32) { |
| 1897 | TEST_DISABLED_FOR_HEAP_REFERENCE_POISONING(); |
| 1898 | |
| 1899 | Thread* self = Thread::Current(); |
| 1900 | |
| 1901 | self->TransitionFromSuspendedToRunnable(); |
| 1902 | LoadDex("AllFields"); |
| 1903 | bool started = runtime_->Start(); |
| 1904 | CHECK(started); |
| 1905 | |
| 1906 | TestFields(self, this, Primitive::Type::kPrimInt); |
| 1907 | } |
| 1908 | |
| 1909 | TEST_F(StubTest, FieldsObj) { |
| 1910 | TEST_DISABLED_FOR_HEAP_REFERENCE_POISONING(); |
| 1911 | |
| 1912 | Thread* self = Thread::Current(); |
| 1913 | |
| 1914 | self->TransitionFromSuspendedToRunnable(); |
| 1915 | LoadDex("AllFields"); |
| 1916 | bool started = runtime_->Start(); |
| 1917 | CHECK(started); |
| 1918 | |
| 1919 | TestFields(self, this, Primitive::Type::kPrimNot); |
| 1920 | } |
| 1921 | |
| 1922 | TEST_F(StubTest, Fields64) { |
| 1923 | TEST_DISABLED_FOR_HEAP_REFERENCE_POISONING(); |
| 1924 | |
| 1925 | Thread* self = Thread::Current(); |
| 1926 | |
| 1927 | self->TransitionFromSuspendedToRunnable(); |
| 1928 | LoadDex("AllFields"); |
| 1929 | bool started = runtime_->Start(); |
| 1930 | CHECK(started); |
| 1931 | |
| 1932 | TestFields(self, this, Primitive::Type::kPrimLong); |
| 1933 | } |
| 1934 | |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 1935 | TEST_F(StubTest, IMT) { |
Ian Rogers | c3ccc10 | 2014-06-25 11:52:14 -0700 | [diff] [blame] | 1936 | #if defined(__i386__) || defined(__arm__) || defined(__aarch64__) || (defined(__x86_64__) && !defined(__APPLE__)) |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 1937 | TEST_DISABLED_FOR_HEAP_REFERENCE_POISONING(); |
| 1938 | |
| 1939 | Thread* self = Thread::Current(); |
| 1940 | |
| 1941 | ScopedObjectAccess soa(self); |
| 1942 | StackHandleScope<7> hs(self); |
| 1943 | |
| 1944 | JNIEnv* env = Thread::Current()->GetJniEnv(); |
| 1945 | |
| 1946 | // ArrayList |
| 1947 | |
| 1948 | // Load ArrayList and used methods (JNI). |
| 1949 | jclass arraylist_jclass = env->FindClass("java/util/ArrayList"); |
| 1950 | ASSERT_NE(nullptr, arraylist_jclass); |
| 1951 | jmethodID arraylist_constructor = env->GetMethodID(arraylist_jclass, "<init>", "()V"); |
| 1952 | ASSERT_NE(nullptr, arraylist_constructor); |
| 1953 | jmethodID contains_jmethod = env->GetMethodID(arraylist_jclass, "contains", "(Ljava/lang/Object;)Z"); |
| 1954 | ASSERT_NE(nullptr, contains_jmethod); |
| 1955 | jmethodID add_jmethod = env->GetMethodID(arraylist_jclass, "add", "(Ljava/lang/Object;)Z"); |
| 1956 | ASSERT_NE(nullptr, add_jmethod); |
| 1957 | |
| 1958 | // Get mirror representation. |
| 1959 | Handle<mirror::ArtMethod> contains_amethod(hs.NewHandle(soa.DecodeMethod(contains_jmethod))); |
| 1960 | |
| 1961 | // Patch up ArrayList.contains. |
| 1962 | if (contains_amethod.Get()->GetEntryPointFromQuickCompiledCode() == nullptr) { |
| 1963 | contains_amethod.Get()->SetEntryPointFromQuickCompiledCode(reinterpret_cast<void*>( |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 1964 | StubTest::GetEntrypoint(self, kQuickQuickToInterpreterBridge))); |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 1965 | } |
| 1966 | |
| 1967 | // List |
| 1968 | |
| 1969 | // Load List and used methods (JNI). |
| 1970 | jclass list_jclass = env->FindClass("java/util/List"); |
| 1971 | ASSERT_NE(nullptr, list_jclass); |
| 1972 | jmethodID inf_contains_jmethod = env->GetMethodID(list_jclass, "contains", "(Ljava/lang/Object;)Z"); |
| 1973 | ASSERT_NE(nullptr, inf_contains_jmethod); |
| 1974 | |
| 1975 | // Get mirror representation. |
| 1976 | Handle<mirror::ArtMethod> inf_contains(hs.NewHandle(soa.DecodeMethod(inf_contains_jmethod))); |
| 1977 | |
| 1978 | // Object |
| 1979 | |
| 1980 | jclass obj_jclass = env->FindClass("java/lang/Object"); |
| 1981 | ASSERT_NE(nullptr, obj_jclass); |
| 1982 | jmethodID obj_constructor = env->GetMethodID(obj_jclass, "<init>", "()V"); |
| 1983 | ASSERT_NE(nullptr, obj_constructor); |
| 1984 | |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 1985 | // Create instances. |
| 1986 | |
| 1987 | jobject jarray_list = env->NewObject(arraylist_jclass, arraylist_constructor); |
| 1988 | ASSERT_NE(nullptr, jarray_list); |
| 1989 | Handle<mirror::Object> array_list(hs.NewHandle(soa.Decode<mirror::Object*>(jarray_list))); |
| 1990 | |
| 1991 | jobject jobj = env->NewObject(obj_jclass, obj_constructor); |
| 1992 | ASSERT_NE(nullptr, jobj); |
| 1993 | Handle<mirror::Object> obj(hs.NewHandle(soa.Decode<mirror::Object*>(jobj))); |
| 1994 | |
Andreas Gampe | 1a7e292 | 2014-05-21 15:37:53 -0700 | [diff] [blame] | 1995 | // Invocation tests. |
| 1996 | |
| 1997 | // 1. imt_conflict |
| 1998 | |
| 1999 | // Contains. |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 2000 | |
| 2001 | size_t result = |
| 2002 | Invoke3WithReferrerAndHidden(0U, reinterpret_cast<size_t>(array_list.Get()), |
| 2003 | reinterpret_cast<size_t>(obj.Get()), |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 2004 | StubTest::GetEntrypoint(self, kQuickQuickImtConflictTrampoline), |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 2005 | self, contains_amethod.Get(), |
| 2006 | static_cast<size_t>(inf_contains.Get()->GetDexMethodIndex())); |
| 2007 | |
| 2008 | ASSERT_FALSE(self->IsExceptionPending()); |
| 2009 | EXPECT_EQ(static_cast<size_t>(JNI_FALSE), result); |
| 2010 | |
| 2011 | // Add object. |
| 2012 | |
| 2013 | env->CallBooleanMethod(jarray_list, add_jmethod, jobj); |
| 2014 | |
Nicolas Geoffray | 14691c5 | 2015-03-05 10:40:17 +0000 | [diff] [blame] | 2015 | ASSERT_FALSE(self->IsExceptionPending()) << PrettyTypeOf(self->GetException()); |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 2016 | |
Andreas Gampe | 1a7e292 | 2014-05-21 15:37:53 -0700 | [diff] [blame] | 2017 | // Contains. |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 2018 | |
| 2019 | result = Invoke3WithReferrerAndHidden(0U, reinterpret_cast<size_t>(array_list.Get()), |
| 2020 | reinterpret_cast<size_t>(obj.Get()), |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 2021 | StubTest::GetEntrypoint(self, kQuickQuickImtConflictTrampoline), |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 2022 | self, contains_amethod.Get(), |
| 2023 | static_cast<size_t>(inf_contains.Get()->GetDexMethodIndex())); |
| 2024 | |
| 2025 | ASSERT_FALSE(self->IsExceptionPending()); |
| 2026 | EXPECT_EQ(static_cast<size_t>(JNI_TRUE), result); |
Andreas Gampe | 1a7e292 | 2014-05-21 15:37:53 -0700 | [diff] [blame] | 2027 | |
| 2028 | // 2. regular interface trampoline |
| 2029 | |
| 2030 | result = Invoke3WithReferrer(static_cast<size_t>(inf_contains.Get()->GetDexMethodIndex()), |
| 2031 | reinterpret_cast<size_t>(array_list.Get()), |
| 2032 | reinterpret_cast<size_t>(obj.Get()), |
| 2033 | StubTest::GetEntrypoint(self, |
| 2034 | kQuickInvokeInterfaceTrampolineWithAccessCheck), |
| 2035 | self, contains_amethod.Get()); |
| 2036 | |
| 2037 | ASSERT_FALSE(self->IsExceptionPending()); |
| 2038 | EXPECT_EQ(static_cast<size_t>(JNI_TRUE), result); |
| 2039 | |
| 2040 | result = Invoke3WithReferrer(static_cast<size_t>(inf_contains.Get()->GetDexMethodIndex()), |
| 2041 | reinterpret_cast<size_t>(array_list.Get()), |
| 2042 | reinterpret_cast<size_t>(array_list.Get()), |
| 2043 | StubTest::GetEntrypoint(self, |
| 2044 | kQuickInvokeInterfaceTrampolineWithAccessCheck), |
| 2045 | self, contains_amethod.Get()); |
| 2046 | |
| 2047 | ASSERT_FALSE(self->IsExceptionPending()); |
| 2048 | EXPECT_EQ(static_cast<size_t>(JNI_FALSE), result); |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 2049 | #else |
Andreas Gampe | 6aac355 | 2014-06-09 14:55:53 -0700 | [diff] [blame] | 2050 | LOG(INFO) << "Skipping imt as I don't know how to do that on " << kRuntimeISA; |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 2051 | // Force-print to std::cout so it's also outside the logcat. |
Andreas Gampe | 6aac355 | 2014-06-09 14:55:53 -0700 | [diff] [blame] | 2052 | std::cout << "Skipping imt as I don't know how to do that on " << kRuntimeISA << std::endl; |
| 2053 | #endif |
| 2054 | } |
| 2055 | |
Andreas Gampe | 6aac355 | 2014-06-09 14:55:53 -0700 | [diff] [blame] | 2056 | TEST_F(StubTest, StringIndexOf) { |
| 2057 | #if defined(__arm__) || defined(__aarch64__) |
Hiroshi Yamauchi | 52fa814 | 2014-06-16 12:59:49 -0700 | [diff] [blame] | 2058 | TEST_DISABLED_FOR_HEAP_REFERENCE_POISONING(); |
| 2059 | |
Andreas Gampe | 6aac355 | 2014-06-09 14:55:53 -0700 | [diff] [blame] | 2060 | Thread* self = Thread::Current(); |
| 2061 | ScopedObjectAccess soa(self); |
| 2062 | // garbage is created during ClassLinker::Init |
| 2063 | |
| 2064 | // Create some strings |
| 2065 | // Use array so we can index into it and use a matrix for expected results |
| 2066 | // Setup: The first half is standard. The second half uses a non-zero offset. |
| 2067 | // TODO: Shared backing arrays. |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 2068 | const char* c_str[] = { "", "a", "ba", "cba", "dcba", "edcba", "asdfghjkl" }; |
| 2069 | static constexpr size_t kStringCount = arraysize(c_str); |
| 2070 | const char c_char[] = { 'a', 'b', 'c', 'd', 'e' }; |
| 2071 | static constexpr size_t kCharCount = arraysize(c_char); |
Andreas Gampe | 6aac355 | 2014-06-09 14:55:53 -0700 | [diff] [blame] | 2072 | |
| 2073 | StackHandleScope<kStringCount> hs(self); |
| 2074 | Handle<mirror::String> s[kStringCount]; |
| 2075 | |
| 2076 | for (size_t i = 0; i < kStringCount; ++i) { |
| 2077 | s[i] = hs.NewHandle(mirror::String::AllocFromModifiedUtf8(soa.Self(), c_str[i])); |
| 2078 | } |
| 2079 | |
| 2080 | // Matrix of expectations. First component is first parameter. Note we only check against the |
| 2081 | // sign, not the value. As we are testing random offsets, we need to compute this and need to |
| 2082 | // rely on String::CompareTo being correct. |
| 2083 | static constexpr size_t kMaxLen = 9; |
| 2084 | DCHECK_LE(strlen(c_str[kStringCount-1]), kMaxLen) << "Please fix the indexof test."; |
| 2085 | |
| 2086 | // Last dimension: start, offset by 1. |
| 2087 | int32_t expected[kStringCount][kCharCount][kMaxLen + 3]; |
| 2088 | for (size_t x = 0; x < kStringCount; ++x) { |
| 2089 | for (size_t y = 0; y < kCharCount; ++y) { |
| 2090 | for (size_t z = 0; z <= kMaxLen + 2; ++z) { |
| 2091 | expected[x][y][z] = s[x]->FastIndexOf(c_char[y], static_cast<int32_t>(z) - 1); |
| 2092 | } |
| 2093 | } |
| 2094 | } |
| 2095 | |
| 2096 | // Play with it... |
| 2097 | |
| 2098 | for (size_t x = 0; x < kStringCount; ++x) { |
| 2099 | for (size_t y = 0; y < kCharCount; ++y) { |
| 2100 | for (size_t z = 0; z <= kMaxLen + 2; ++z) { |
| 2101 | int32_t start = static_cast<int32_t>(z) - 1; |
| 2102 | |
| 2103 | // Test string_compareto x y |
| 2104 | size_t result = Invoke3(reinterpret_cast<size_t>(s[x].Get()), c_char[y], start, |
Andreas Gampe | 29b3841 | 2014-08-13 00:15:43 -0700 | [diff] [blame] | 2105 | StubTest::GetEntrypoint(self, kQuickIndexOf), self); |
Andreas Gampe | 6aac355 | 2014-06-09 14:55:53 -0700 | [diff] [blame] | 2106 | |
| 2107 | EXPECT_FALSE(self->IsExceptionPending()); |
| 2108 | |
| 2109 | // The result is a 32b signed integer |
| 2110 | union { |
| 2111 | size_t r; |
| 2112 | int32_t i; |
| 2113 | } conv; |
| 2114 | conv.r = result; |
| 2115 | |
| 2116 | EXPECT_EQ(expected[x][y][z], conv.i) << "Wrong result for " << c_str[x] << " / " << |
| 2117 | c_char[y] << " @ " << start; |
| 2118 | } |
| 2119 | } |
| 2120 | } |
| 2121 | |
| 2122 | // TODO: Deallocate things. |
| 2123 | |
| 2124 | // Tests done. |
| 2125 | #else |
| 2126 | LOG(INFO) << "Skipping indexof as I don't know how to do that on " << kRuntimeISA; |
| 2127 | // Force-print to std::cout so it's also outside the logcat. |
| 2128 | std::cout << "Skipping indexof as I don't know how to do that on " << kRuntimeISA << std::endl; |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 2129 | #endif |
| 2130 | } |
| 2131 | |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 2132 | } // namespace art |