Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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 | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 17 | #include "gc/card_table-inl.h" |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 18 | #include "jni_internal.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 19 | #include "mirror/array.h" |
| 20 | #include "mirror/class.h" |
| 21 | #include "mirror/class-inl.h" |
| 22 | #include "mirror/object-inl.h" |
Ian Rogers | 693ff61 | 2013-02-01 10:56:12 -0800 | [diff] [blame] | 23 | #include "mirror/object_array-inl.h" |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 24 | #include "scoped_thread_state_change.h" |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 25 | |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 26 | /* |
| 27 | * We make guarantees about the atomicity of accesses to primitive |
| 28 | * variables. These guarantees also apply to elements of arrays. |
| 29 | * In particular, 8-bit, 16-bit, and 32-bit accesses must be atomic and |
| 30 | * must not cause "word tearing". Accesses to 64-bit array elements must |
| 31 | * either be atomic or treated as two 32-bit operations. References are |
| 32 | * always read and written atomically, regardless of the number of bits |
| 33 | * used to represent them. |
| 34 | * |
| 35 | * We can't rely on standard libc functions like memcpy(3) and memmove(3) |
| 36 | * in our implementation of System.arraycopy, because they may copy |
| 37 | * byte-by-byte (either for the full run or for "unaligned" parts at the |
| 38 | * start or end). We need to use functions that guarantee 16-bit or 32-bit |
| 39 | * atomicity as appropriate. |
| 40 | * |
| 41 | * System.arraycopy() is heavily used, so having an efficient implementation |
| 42 | * is important. The bionic libc provides a platform-optimized memory move |
| 43 | * function that should be used when possible. If it's not available, |
| 44 | * the trivial "reference implementation" versions below can be used until |
| 45 | * a proper version can be written. |
| 46 | * |
| 47 | * For these functions, The caller must guarantee that dst/src are aligned |
| 48 | * appropriately for the element type, and that n is a multiple of the |
| 49 | * element size. |
| 50 | */ |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 51 | |
Elliott Hughes | 6324e21 | 2013-02-15 17:55:35 -0800 | [diff] [blame^] | 52 | /* |
| 53 | * Works like memmove(), except: |
| 54 | * - if all arguments are at least 32-bit aligned, we guarantee that we |
| 55 | * will use operations that preserve atomicity of 32-bit values |
| 56 | * - if not, we guarantee atomicity of 16-bit values |
| 57 | * |
| 58 | * If all three arguments are not at least 16-bit aligned, the behavior |
| 59 | * of this function is undefined. (We could remove this restriction by |
| 60 | * testing for unaligned values and punting to memmove(), but that's |
| 61 | * not currently useful.) |
| 62 | * |
| 63 | * TODO: add loop for 64-bit alignment |
| 64 | * TODO: use __builtin_prefetch |
| 65 | * TODO: write ARM/MIPS/x86 optimized versions |
| 66 | */ |
| 67 | void MemmoveWords(void* dst, const void* src, size_t n) { |
Elliott Hughes | cc60747 | 2011-10-17 15:34:11 -0700 | [diff] [blame] | 68 | DCHECK_EQ((((uintptr_t) dst | (uintptr_t) src | n) & 0x01), 0U); |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 69 | |
Elliott Hughes | 6324e21 | 2013-02-15 17:55:35 -0800 | [diff] [blame^] | 70 | char* d = reinterpret_cast<char*>(dst); |
| 71 | const char* s = reinterpret_cast<const char*>(src); |
| 72 | size_t copyCount; |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 73 | |
Elliott Hughes | 6324e21 | 2013-02-15 17:55:35 -0800 | [diff] [blame^] | 74 | // If the source and destination pointers are the same, this is |
| 75 | // an expensive no-op. Testing for an empty move now allows us |
| 76 | // to skip a check later. |
| 77 | if (n == 0 || d == s) { |
| 78 | return; |
| 79 | } |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 80 | |
Elliott Hughes | 6324e21 | 2013-02-15 17:55:35 -0800 | [diff] [blame^] | 81 | // Determine if the source and destination buffers will overlap if |
| 82 | // we copy data forward (i.e. *dst++ = *src++). |
| 83 | // |
| 84 | // It's okay if the destination buffer starts before the source and |
| 85 | // there is some overlap, because the reader is always ahead of the |
| 86 | // writer. |
| 87 | if (LIKELY((d < s) || ((size_t)(d - s) >= n))) { |
| 88 | // Copy forward. We prefer 32-bit loads and stores even for 16-bit |
| 89 | // data, so sort that out. |
| 90 | if (((reinterpret_cast<uintptr_t>(d) | reinterpret_cast<uintptr_t>(s)) & 0x03) != 0) { |
| 91 | // Not 32-bit aligned. Two possibilities: |
| 92 | // (1) Congruent, we can align to 32-bit by copying one 16-bit val |
| 93 | // (2) Non-congruent, we can do one of: |
| 94 | // a. copy whole buffer as a series of 16-bit values |
| 95 | // b. load/store 32 bits, using shifts to ensure alignment |
| 96 | // c. just copy the as 32-bit values and assume the CPU |
| 97 | // will do a reasonable job |
| 98 | // |
| 99 | // We're currently using (a), which is suboptimal. |
| 100 | if (((reinterpret_cast<uintptr_t>(d) ^ reinterpret_cast<uintptr_t>(s)) & 0x03) != 0) { |
| 101 | copyCount = n; |
| 102 | } else { |
| 103 | copyCount = 2; |
| 104 | } |
| 105 | n -= copyCount; |
| 106 | copyCount /= sizeof(uint16_t); |
| 107 | |
| 108 | while (copyCount--) { |
| 109 | *reinterpret_cast<uint16_t*>(d) = *reinterpret_cast<const uint16_t*>(s); |
| 110 | d += sizeof(uint16_t); |
| 111 | s += sizeof(uint16_t); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | // Copy 32-bit aligned words. |
| 116 | copyCount = n / sizeof(uint32_t); |
| 117 | while (copyCount--) { |
| 118 | *reinterpret_cast<uint32_t*>(d) = *reinterpret_cast<const uint32_t*>(s); |
| 119 | d += sizeof(uint32_t); |
| 120 | s += sizeof(uint32_t); |
| 121 | } |
| 122 | |
| 123 | // Check for leftovers. Either we finished exactly, or we have one remaining 16-bit chunk. |
| 124 | if ((n & 0x02) != 0) { |
| 125 | *(uint16_t*)d = *(uint16_t*)s; |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 126 | } |
| 127 | } else { |
Elliott Hughes | 6324e21 | 2013-02-15 17:55:35 -0800 | [diff] [blame^] | 128 | // Copy backward, starting at the end. |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 129 | d += n; |
| 130 | s += n; |
Elliott Hughes | 6324e21 | 2013-02-15 17:55:35 -0800 | [diff] [blame^] | 131 | |
| 132 | if (((reinterpret_cast<uintptr_t>(d) | reinterpret_cast<uintptr_t>(s)) & 0x03) != 0) { |
| 133 | // try for 32-bit alignment. |
| 134 | if (((reinterpret_cast<uintptr_t>(d) ^ reinterpret_cast<uintptr_t>(s)) & 0x03) != 0) { |
| 135 | copyCount = n; |
| 136 | } else { |
| 137 | copyCount = 2; |
| 138 | } |
| 139 | n -= copyCount; |
| 140 | copyCount /= sizeof(uint16_t); |
| 141 | |
| 142 | while (copyCount--) { |
| 143 | d -= sizeof(uint16_t); |
| 144 | s -= sizeof(uint16_t); |
| 145 | *reinterpret_cast<uint16_t*>(d) = *reinterpret_cast<const uint16_t*>(s); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | // Copy 32-bit aligned words. |
| 150 | copyCount = n / sizeof(uint32_t); |
| 151 | while (copyCount--) { |
| 152 | d -= sizeof(uint32_t); |
| 153 | s -= sizeof(uint32_t); |
| 154 | *reinterpret_cast<uint32_t*>(d) = *reinterpret_cast<const uint32_t*>(s); |
| 155 | } |
| 156 | |
| 157 | // Copy leftovers. |
| 158 | if ((n & 0x02) != 0) { |
| 159 | d -= sizeof(uint16_t); |
| 160 | s -= sizeof(uint16_t); |
| 161 | *reinterpret_cast<uint16_t*>(d) = *reinterpret_cast<const uint16_t*>(s); |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 162 | } |
| 163 | } |
| 164 | } |
| 165 | |
Elliott Hughes | 6324e21 | 2013-02-15 17:55:35 -0800 | [diff] [blame^] | 166 | #define move16 MemmoveWords |
| 167 | #define move32 MemmoveWords |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 168 | |
| 169 | namespace art { |
| 170 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 171 | static void ThrowArrayStoreException_NotAnArray(const char* identifier, mirror::Object* array) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 172 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Elliott Hughes | 54e7df1 | 2011-09-16 11:47:04 -0700 | [diff] [blame] | 173 | std::string actualType(PrettyTypeOf(array)); |
Elliott Hughes | 5cb5ad2 | 2011-10-02 12:13:39 -0700 | [diff] [blame] | 174 | Thread::Current()->ThrowNewExceptionF("Ljava/lang/ArrayStoreException;", |
Elliott Hughes | 81aa5b3 | 2012-01-17 13:47:13 -0800 | [diff] [blame] | 175 | "%s of type %s is not an array", identifier, actualType.c_str()); |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 176 | } |
| 177 | |
Elliott Hughes | 0512f02 | 2012-03-15 22:10:52 -0700 | [diff] [blame] | 178 | static void System_arraycopy(JNIEnv* env, jclass, jobject javaSrc, jint srcPos, jobject javaDst, jint dstPos, jint length) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 179 | ScopedObjectAccess soa(env); |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 180 | |
| 181 | // Null pointer checks. |
| 182 | if (javaSrc == NULL) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 183 | soa.Self()->ThrowNewException("Ljava/lang/NullPointerException;", "src == null"); |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 184 | return; |
| 185 | } |
| 186 | if (javaDst == NULL) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 187 | soa.Self()->ThrowNewException("Ljava/lang/NullPointerException;", "dst == null"); |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 188 | return; |
| 189 | } |
| 190 | |
| 191 | // Make sure source and destination are both arrays. |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 192 | mirror::Object* srcObject = soa.Decode<mirror::Object*>(javaSrc); |
| 193 | mirror::Object* dstObject = soa.Decode<mirror::Object*>(javaDst); |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 194 | if (!srcObject->IsArrayInstance()) { |
Elliott Hughes | 81aa5b3 | 2012-01-17 13:47:13 -0800 | [diff] [blame] | 195 | ThrowArrayStoreException_NotAnArray("source", srcObject); |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 196 | return; |
| 197 | } |
| 198 | if (!dstObject->IsArrayInstance()) { |
Elliott Hughes | 81aa5b3 | 2012-01-17 13:47:13 -0800 | [diff] [blame] | 199 | ThrowArrayStoreException_NotAnArray("destination", dstObject); |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 200 | return; |
| 201 | } |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 202 | mirror::Array* srcArray = srcObject->AsArray(); |
| 203 | mirror::Array* dstArray = dstObject->AsArray(); |
| 204 | mirror::Class* srcComponentType = srcArray->GetClass()->GetComponentType(); |
| 205 | mirror::Class* dstComponentType = dstArray->GetClass()->GetComponentType(); |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 206 | |
| 207 | // Bounds checking. |
| 208 | if (srcPos < 0 || dstPos < 0 || length < 0 || srcPos > srcArray->GetLength() - length || dstPos > dstArray->GetLength() - length) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 209 | soa.Self()->ThrowNewExceptionF("Ljava/lang/ArrayIndexOutOfBoundsException;", |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 210 | "src.length=%d srcPos=%d dst.length=%d dstPos=%d length=%d", |
| 211 | srcArray->GetLength(), srcPos, dstArray->GetLength(), dstPos, length); |
| 212 | return; |
| 213 | } |
| 214 | |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 215 | // Handle primitive arrays. |
| 216 | if (srcComponentType->IsPrimitive() || dstComponentType->IsPrimitive()) { |
| 217 | // If one of the arrays holds a primitive type the other array must hold the exact same type. |
| 218 | if (srcComponentType->IsPrimitive() != dstComponentType->IsPrimitive() || srcComponentType != dstComponentType) { |
Elliott Hughes | 54e7df1 | 2011-09-16 11:47:04 -0700 | [diff] [blame] | 219 | std::string srcType(PrettyTypeOf(srcArray)); |
| 220 | std::string dstType(PrettyTypeOf(dstArray)); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 221 | soa.Self()->ThrowNewExceptionF("Ljava/lang/ArrayStoreException;", |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 222 | "Incompatible types: src=%s, dst=%s", srcType.c_str(), dstType.c_str()); |
| 223 | return; |
| 224 | } |
| 225 | |
Ian Rogers | a15e67d | 2012-02-28 13:51:55 -0800 | [diff] [blame] | 226 | size_t width = srcArray->GetClass()->GetComponentSize(); |
| 227 | uint8_t* dstBytes = reinterpret_cast<uint8_t*>(dstArray->GetRawData(width)); |
| 228 | const uint8_t* srcBytes = reinterpret_cast<const uint8_t*>(srcArray->GetRawData(width)); |
| 229 | |
| 230 | switch (width) { |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 231 | case 1: |
| 232 | memmove(dstBytes + dstPos, srcBytes + srcPos, length); |
| 233 | break; |
| 234 | case 2: |
| 235 | move16(dstBytes + dstPos * 2, srcBytes + srcPos * 2, length * 2); |
| 236 | break; |
| 237 | case 4: |
| 238 | move32(dstBytes + dstPos * 4, srcBytes + srcPos * 4, length * 4); |
| 239 | break; |
| 240 | case 8: |
| 241 | // We don't need to guarantee atomicity of the entire 64-bit word. |
| 242 | move32(dstBytes + dstPos * 8, srcBytes + srcPos * 8, length * 8); |
| 243 | break; |
| 244 | default: |
Elliott Hughes | 54e7df1 | 2011-09-16 11:47:04 -0700 | [diff] [blame] | 245 | LOG(FATAL) << "Unknown primitive array type: " << PrettyTypeOf(srcArray); |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | return; |
| 249 | } |
| 250 | |
| 251 | // Neither class is primitive. Are the types trivially compatible? |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 252 | const size_t width = sizeof(mirror::Object*); |
Ian Rogers | a15e67d | 2012-02-28 13:51:55 -0800 | [diff] [blame] | 253 | uint8_t* dstBytes = reinterpret_cast<uint8_t*>(dstArray->GetRawData(width)); |
| 254 | const uint8_t* srcBytes = reinterpret_cast<const uint8_t*>(srcArray->GetRawData(width)); |
Elliott Hughes | ab3530d | 2012-01-09 16:04:56 -0800 | [diff] [blame] | 255 | if (dstArray == srcArray || dstComponentType->IsAssignableFrom(srcComponentType)) { |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 256 | // Yes. Bulk copy. |
Brian Carlstrom | b6db9d2 | 2011-09-18 11:39:12 -0700 | [diff] [blame] | 257 | COMPILE_ASSERT(sizeof(width) == sizeof(uint32_t), move32_assumes_Object_references_are_32_bit); |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 258 | move32(dstBytes + dstPos * width, srcBytes + srcPos * width, length * width); |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 259 | Runtime::Current()->GetHeap()->WriteBarrierArray(dstArray, dstPos, length); |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 260 | return; |
| 261 | } |
| 262 | |
Elliott Hughes | ab3530d | 2012-01-09 16:04:56 -0800 | [diff] [blame] | 263 | // The arrays are not trivially compatible. However, we may still be able to copy some or all of |
| 264 | // the elements if the source objects are compatible (for example, copying an Object[] to |
| 265 | // String[], the Objects being copied might actually be Strings). |
| 266 | // We can't do a bulk move because that would introduce a check-use race condition, so we copy |
| 267 | // elements one by one. |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 268 | |
Elliott Hughes | ab3530d | 2012-01-09 16:04:56 -0800 | [diff] [blame] | 269 | // We already dealt with overlapping copies, so we don't need to cope with that case below. |
| 270 | CHECK_NE(dstArray, srcArray); |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 271 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 272 | mirror::Object* const * srcObjects = |
| 273 | reinterpret_cast<mirror::Object* const *>(srcBytes + srcPos * width); |
| 274 | mirror::Object** dstObjects = reinterpret_cast<mirror::Object**>(dstBytes + dstPos * width); |
| 275 | mirror::Class* dstClass = dstArray->GetClass()->GetComponentType(); |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 276 | |
Elliott Hughes | ab3530d | 2012-01-09 16:04:56 -0800 | [diff] [blame] | 277 | // We want to avoid redundant IsAssignableFrom checks where possible, so we cache a class that |
| 278 | // we know is assignable to the destination array's component type. |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 279 | mirror::Class* lastAssignableElementClass = dstClass; |
Elliott Hughes | ab3530d | 2012-01-09 16:04:56 -0800 | [diff] [blame] | 280 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 281 | mirror::Object* o = NULL; |
Elliott Hughes | ab3530d | 2012-01-09 16:04:56 -0800 | [diff] [blame] | 282 | int i = 0; |
| 283 | for (; i < length; ++i) { |
Elliott Hughes | 025c5de | 2012-01-10 11:05:48 -0800 | [diff] [blame] | 284 | o = srcObjects[i]; |
Elliott Hughes | ab3530d | 2012-01-09 16:04:56 -0800 | [diff] [blame] | 285 | if (o != NULL) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 286 | mirror::Class* oClass = o->GetClass(); |
Elliott Hughes | ab3530d | 2012-01-09 16:04:56 -0800 | [diff] [blame] | 287 | if (lastAssignableElementClass == oClass) { |
| 288 | dstObjects[i] = o; |
| 289 | } else if (dstClass->IsAssignableFrom(oClass)) { |
| 290 | lastAssignableElementClass = oClass; |
| 291 | dstObjects[i] = o; |
| 292 | } else { |
| 293 | // Can't put this element into the array. |
| 294 | break; |
| 295 | } |
| 296 | } else { |
| 297 | dstObjects[i] = NULL; |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 298 | } |
| 299 | } |
| 300 | |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 301 | Runtime::Current()->GetHeap()->WriteBarrierArray(dstArray, dstPos, length); |
Elliott Hughes | ab3530d | 2012-01-09 16:04:56 -0800 | [diff] [blame] | 302 | if (i != length) { |
Elliott Hughes | 025c5de | 2012-01-10 11:05:48 -0800 | [diff] [blame] | 303 | std::string actualSrcType(PrettyTypeOf(o)); |
Elliott Hughes | 54e7df1 | 2011-09-16 11:47:04 -0700 | [diff] [blame] | 304 | std::string dstType(PrettyTypeOf(dstArray)); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 305 | soa.Self()->ThrowNewExceptionF("Ljava/lang/ArrayStoreException;", |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 306 | "source[%d] of type %s cannot be stored in destination array of type %s", |
Elliott Hughes | ab3530d | 2012-01-09 16:04:56 -0800 | [diff] [blame] | 307 | srcPos + i, actualSrcType.c_str(), dstType.c_str()); |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 308 | return; |
| 309 | } |
| 310 | } |
| 311 | |
Elliott Hughes | 0512f02 | 2012-03-15 22:10:52 -0700 | [diff] [blame] | 312 | static jint System_identityHashCode(JNIEnv* env, jclass, jobject javaObject) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 313 | ScopedObjectAccess soa(env); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 314 | mirror::Object* o = soa.Decode<mirror::Object*>(javaObject); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 315 | return static_cast<jint>(o->IdentityHashCode()); |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 316 | } |
| 317 | |
Elliott Hughes | 0512f02 | 2012-03-15 22:10:52 -0700 | [diff] [blame] | 318 | static JNINativeMethod gMethods[] = { |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 319 | NATIVE_METHOD(System, arraycopy, "(Ljava/lang/Object;ILjava/lang/Object;II)V"), |
| 320 | NATIVE_METHOD(System, identityHashCode, "(Ljava/lang/Object;)I"), |
| 321 | }; |
| 322 | |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 323 | void register_java_lang_System(JNIEnv* env) { |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 324 | REGISTER_NATIVE_METHODS("java/lang/System"); |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | } // namespace art |