Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 | |
| 17 | #include "interpreter_common.h" |
| 18 | |
| 19 | namespace art { |
| 20 | namespace interpreter { |
| 21 | |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 22 | static void UnstartedRuntimeInvoke(Thread* self, MethodHelper& mh, |
| 23 | const DexFile::CodeItem* code_item, ShadowFrame* shadow_frame, |
| 24 | JValue* result, size_t arg_offset) |
| 25 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 26 | |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 27 | // Assign register 'src_reg' from shadow_frame to register 'dest_reg' into new_shadow_frame. |
| 28 | static inline void AssignRegister(ShadowFrame& new_shadow_frame, const ShadowFrame& shadow_frame, |
| 29 | size_t dest_reg, size_t src_reg) { |
| 30 | // If both register locations contains the same value, the register probably holds a reference. |
| 31 | int32_t src_value = shadow_frame.GetVReg(src_reg); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 32 | mirror::Object* o = shadow_frame.GetVRegReference<false>(src_reg); |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 33 | if (src_value == reinterpret_cast<int32_t>(o)) { |
| 34 | new_shadow_frame.SetVRegReference(dest_reg, o); |
| 35 | } else { |
| 36 | new_shadow_frame.SetVReg(dest_reg, src_value); |
| 37 | } |
| 38 | } |
| 39 | |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 40 | template<bool is_range, bool do_assignability_check> |
Sebastien Hertz | 9119c5f | 2013-12-16 11:31:45 +0100 | [diff] [blame] | 41 | bool DoCall(ArtMethod* method, Thread* self, ShadowFrame& shadow_frame, |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 42 | const Instruction* inst, uint16_t inst_data, JValue* result) { |
| 43 | // Compute method information. |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 44 | MethodHelper mh(method); |
| 45 | const DexFile::CodeItem* code_item = mh.GetCodeItem(); |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 46 | const uint16_t num_ins = (is_range) ? inst->VRegA_3rc(inst_data) : inst->VRegA_35c(inst_data); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 47 | uint16_t num_regs; |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 48 | if (LIKELY(code_item != NULL)) { |
| 49 | num_regs = code_item->registers_size_; |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 50 | DCHECK_EQ(num_ins, code_item->ins_size_); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 51 | } else { |
| 52 | DCHECK(method->IsNative() || method->IsProxyMethod()); |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 53 | num_regs = num_ins; |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 54 | } |
| 55 | |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 56 | // Allocate shadow frame on the stack. |
Mathieu Chartier | e861ebd | 2013-10-09 15:01:21 -0700 | [diff] [blame] | 57 | const char* old_cause = self->StartAssertNoThreadSuspension("DoCall"); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 58 | void* memory = alloca(ShadowFrame::ComputeSize(num_regs)); |
| 59 | ShadowFrame* new_shadow_frame(ShadowFrame::Create(num_regs, &shadow_frame, method, 0, memory)); |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 60 | |
| 61 | // Initialize new shadow frame. |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 62 | const size_t first_dest_reg = num_regs - num_ins; |
Jeff Hao | a3faaf4 | 2013-09-03 19:07:00 -0700 | [diff] [blame] | 63 | if (do_assignability_check) { |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 64 | // Slow path: we need to do runtime check on reference assignment. We need to load the shorty |
| 65 | // to get the exact type of each reference argument. |
| 66 | const DexFile::TypeList* params = mh.GetParameterTypeList(); |
| 67 | const char* shorty = mh.GetShorty(); |
| 68 | |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 69 | // TODO: find a cleaner way to separate non-range and range information without duplicating code. |
| 70 | uint32_t arg[5]; // only used in invoke-XXX. |
| 71 | uint32_t vregC; // only used in invoke-XXX-range. |
| 72 | if (is_range) { |
| 73 | vregC = inst->VRegC_3rc(); |
| 74 | } else { |
| 75 | inst->GetArgs(arg, inst_data); |
| 76 | } |
Sebastien Hertz | 9119c5f | 2013-12-16 11:31:45 +0100 | [diff] [blame] | 77 | |
| 78 | // Handle receiver apart since it's not part of the shorty. |
| 79 | size_t dest_reg = first_dest_reg; |
| 80 | size_t arg_offset = 0; |
| 81 | if (!method->IsStatic()) { |
| 82 | size_t receiver_reg = (is_range) ? vregC : arg[0]; |
| 83 | new_shadow_frame->SetVRegReference(dest_reg, shadow_frame.GetVRegReference(receiver_reg)); |
| 84 | ++dest_reg; |
| 85 | ++arg_offset; |
| 86 | } |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 87 | for (size_t shorty_pos = 0; dest_reg < num_regs; ++shorty_pos, ++dest_reg, ++arg_offset) { |
| 88 | DCHECK_LT(shorty_pos + 1, mh.GetShortyLength()); |
| 89 | const size_t src_reg = (is_range) ? vregC + arg_offset : arg[arg_offset]; |
| 90 | switch (shorty[shorty_pos + 1]) { |
| 91 | case 'L': { |
| 92 | Object* o = shadow_frame.GetVRegReference(src_reg); |
| 93 | if (do_assignability_check && o != NULL) { |
| 94 | Class* arg_type = mh.GetClassFromTypeIdx(params->GetTypeItem(shorty_pos).type_idx_); |
| 95 | if (arg_type == NULL) { |
| 96 | CHECK(self->IsExceptionPending()); |
Mathieu Chartier | e861ebd | 2013-10-09 15:01:21 -0700 | [diff] [blame] | 97 | self->EndAssertNoThreadSuspension(old_cause); |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 98 | return false; |
| 99 | } |
| 100 | if (!o->VerifierInstanceOf(arg_type)) { |
Mathieu Chartier | e861ebd | 2013-10-09 15:01:21 -0700 | [diff] [blame] | 101 | self->EndAssertNoThreadSuspension(old_cause); |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 102 | // This should never happen. |
| 103 | self->ThrowNewExceptionF(self->GetCurrentLocationForThrow(), |
| 104 | "Ljava/lang/VirtualMachineError;", |
| 105 | "Invoking %s with bad arg %d, type '%s' not instance of '%s'", |
| 106 | mh.GetName(), shorty_pos, |
| 107 | ClassHelper(o->GetClass()).GetDescriptor(), |
| 108 | ClassHelper(arg_type).GetDescriptor()); |
| 109 | return false; |
| 110 | } |
Jeff Hao | a3faaf4 | 2013-09-03 19:07:00 -0700 | [diff] [blame] | 111 | } |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 112 | new_shadow_frame->SetVRegReference(dest_reg, o); |
| 113 | break; |
Jeff Hao | a3faaf4 | 2013-09-03 19:07:00 -0700 | [diff] [blame] | 114 | } |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 115 | case 'J': case 'D': { |
| 116 | uint64_t wide_value = (static_cast<uint64_t>(shadow_frame.GetVReg(src_reg + 1)) << 32) | |
| 117 | static_cast<uint32_t>(shadow_frame.GetVReg(src_reg)); |
| 118 | new_shadow_frame->SetVRegLong(dest_reg, wide_value); |
| 119 | ++dest_reg; |
| 120 | ++arg_offset; |
| 121 | break; |
| 122 | } |
| 123 | default: |
| 124 | new_shadow_frame->SetVReg(dest_reg, shadow_frame.GetVReg(src_reg)); |
| 125 | break; |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 126 | } |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 127 | } |
| 128 | } else { |
| 129 | // Fast path: no extra checks. |
| 130 | if (is_range) { |
| 131 | const uint16_t first_src_reg = inst->VRegC_3rc(); |
| 132 | for (size_t src_reg = first_src_reg, dest_reg = first_dest_reg; dest_reg < num_regs; |
| 133 | ++dest_reg, ++src_reg) { |
| 134 | AssignRegister(*new_shadow_frame, shadow_frame, dest_reg, src_reg); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 135 | } |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 136 | } else { |
| 137 | DCHECK_LE(num_ins, 5U); |
| 138 | uint16_t regList = inst->Fetch16(2); |
| 139 | uint16_t count = num_ins; |
| 140 | if (count == 5) { |
| 141 | AssignRegister(*new_shadow_frame, shadow_frame, first_dest_reg + 4U, (inst_data >> 8) & 0x0f); |
| 142 | --count; |
| 143 | } |
| 144 | for (size_t arg_index = 0; arg_index < count; ++arg_index, regList >>= 4) { |
| 145 | AssignRegister(*new_shadow_frame, shadow_frame, first_dest_reg + arg_index, regList & 0x0f); |
| 146 | } |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 147 | } |
| 148 | } |
Mathieu Chartier | e861ebd | 2013-10-09 15:01:21 -0700 | [diff] [blame] | 149 | self->EndAssertNoThreadSuspension(old_cause); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 150 | |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 151 | // Do the call now. |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 152 | if (LIKELY(Runtime::Current()->IsStarted())) { |
Ian Rogers | 1d99e45 | 2014-01-02 17:36:41 -0800 | [diff] [blame] | 153 | if (kIsDebugBuild && method->GetEntryPointFromInterpreter() == nullptr) { |
| 154 | LOG(FATAL) << "Attempt to invoke non-executable method: " << PrettyMethod(method); |
| 155 | } |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 156 | (method->GetEntryPointFromInterpreter())(self, mh, code_item, new_shadow_frame, result); |
| 157 | } else { |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 158 | UnstartedRuntimeInvoke(self, mh, code_item, new_shadow_frame, result, first_dest_reg); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 159 | } |
| 160 | return !self->IsExceptionPending(); |
| 161 | } |
| 162 | |
| 163 | template <bool is_range, bool do_access_check> |
| 164 | bool DoFilledNewArray(const Instruction* inst, const ShadowFrame& shadow_frame, |
| 165 | Thread* self, JValue* result) { |
| 166 | DCHECK(inst->Opcode() == Instruction::FILLED_NEW_ARRAY || |
| 167 | inst->Opcode() == Instruction::FILLED_NEW_ARRAY_RANGE); |
| 168 | const int32_t length = is_range ? inst->VRegA_3rc() : inst->VRegA_35c(); |
| 169 | if (!is_range) { |
| 170 | // Checks FILLED_NEW_ARRAY's length does not exceed 5 arguments. |
| 171 | CHECK_LE(length, 5); |
| 172 | } |
| 173 | if (UNLIKELY(length < 0)) { |
| 174 | ThrowNegativeArraySizeException(length); |
| 175 | return false; |
| 176 | } |
| 177 | uint16_t type_idx = is_range ? inst->VRegB_3rc() : inst->VRegB_35c(); |
| 178 | Class* arrayClass = ResolveVerifyAndClinit(type_idx, shadow_frame.GetMethod(), |
| 179 | self, false, do_access_check); |
| 180 | if (UNLIKELY(arrayClass == NULL)) { |
| 181 | DCHECK(self->IsExceptionPending()); |
| 182 | return false; |
| 183 | } |
| 184 | CHECK(arrayClass->IsArrayClass()); |
| 185 | Class* componentClass = arrayClass->GetComponentType(); |
| 186 | if (UNLIKELY(componentClass->IsPrimitive() && !componentClass->IsPrimitiveInt())) { |
| 187 | if (componentClass->IsPrimitiveLong() || componentClass->IsPrimitiveDouble()) { |
| 188 | ThrowRuntimeException("Bad filled array request for type %s", |
| 189 | PrettyDescriptor(componentClass).c_str()); |
| 190 | } else { |
| 191 | self->ThrowNewExceptionF(shadow_frame.GetCurrentLocationForThrow(), |
| 192 | "Ljava/lang/InternalError;", |
Brian Carlstrom | 4fa0bcd | 2013-12-10 11:24:21 -0800 | [diff] [blame] | 193 | "Found type %s; filled-new-array not implemented for anything but 'int'", |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 194 | PrettyDescriptor(componentClass).c_str()); |
| 195 | } |
| 196 | return false; |
| 197 | } |
Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 198 | Object* newArray = Array::Alloc<true>(self, arrayClass, length); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 199 | if (UNLIKELY(newArray == NULL)) { |
| 200 | DCHECK(self->IsExceptionPending()); |
| 201 | return false; |
| 202 | } |
Sebastien Hertz | abff643 | 2014-01-27 18:01:39 +0100 | [diff] [blame^] | 203 | uint32_t arg[5]; // only used in filled-new-array. |
| 204 | uint32_t vregC; // only used in filled-new-array-range. |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 205 | if (is_range) { |
Sebastien Hertz | abff643 | 2014-01-27 18:01:39 +0100 | [diff] [blame^] | 206 | vregC = inst->VRegC_3rc(); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 207 | } else { |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 208 | inst->GetArgs(arg); |
Sebastien Hertz | abff643 | 2014-01-27 18:01:39 +0100 | [diff] [blame^] | 209 | } |
| 210 | const bool is_primitive_int_component = componentClass->IsPrimitiveInt(); |
| 211 | for (int32_t i = 0; i < length; ++i) { |
| 212 | size_t src_reg = is_range ? vregC + i : arg[i]; |
| 213 | if (is_primitive_int_component) { |
| 214 | newArray->AsIntArray()->SetWithoutChecks(i, shadow_frame.GetVReg(src_reg)); |
| 215 | } else { |
| 216 | newArray->AsObjectArray<Object>()->SetWithoutChecks(i, shadow_frame.GetVRegReference(src_reg)); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 217 | } |
| 218 | } |
| 219 | |
| 220 | result->SetL(newArray); |
| 221 | return true; |
| 222 | } |
| 223 | |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 224 | static void UnstartedRuntimeInvoke(Thread* self, MethodHelper& mh, |
| 225 | const DexFile::CodeItem* code_item, ShadowFrame* shadow_frame, |
| 226 | JValue* result, size_t arg_offset) { |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 227 | // In a runtime that's not started we intercept certain methods to avoid complicated dependency |
| 228 | // problems in core libraries. |
| 229 | std::string name(PrettyMethod(shadow_frame->GetMethod())); |
Kenny Root | fa31b3c | 2013-12-09 13:51:32 -0800 | [diff] [blame] | 230 | if (name == "java.lang.Class java.lang.Class.forName(java.lang.String)" |
| 231 | || name == "java.lang.Class java.lang.VMClassLoader.loadClass(java.lang.String, boolean)") { |
| 232 | // TODO Class#forName should actually call Class::EnsureInitialized always. Support for the |
| 233 | // other variants that take more arguments should also be added. |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 234 | std::string descriptor(DotToDescriptor(shadow_frame->GetVRegReference(arg_offset)->AsString()->ToModifiedUtf8().c_str())); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 235 | |
| 236 | SirtRef<ClassLoader> class_loader(self, nullptr); // shadow_frame.GetMethod()->GetDeclaringClass()->GetClassLoader(); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 237 | Class* found = Runtime::Current()->GetClassLinker()->FindClass(descriptor.c_str(), |
| 238 | class_loader); |
| 239 | CHECK(found != NULL) << "Class.forName failed in un-started runtime for class: " |
| 240 | << PrettyDescriptor(descriptor); |
| 241 | result->SetL(found); |
Kenny Root | fa31b3c | 2013-12-09 13:51:32 -0800 | [diff] [blame] | 242 | } else if (name == "java.lang.Class java.lang.VMClassLoader.findLoadedClass(java.lang.ClassLoader, java.lang.String)") { |
| 243 | SirtRef<ClassLoader> class_loader(self, down_cast<mirror::ClassLoader*>(shadow_frame->GetVRegReference(arg_offset))); |
| 244 | std::string descriptor(DotToDescriptor(shadow_frame->GetVRegReference(arg_offset + 1)->AsString()->ToModifiedUtf8().c_str())); |
| 245 | |
| 246 | Class* found = Runtime::Current()->GetClassLinker()->FindClass(descriptor.c_str(), |
| 247 | class_loader); |
| 248 | result->SetL(found); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 249 | } else if (name == "java.lang.Object java.lang.Class.newInstance()") { |
| 250 | Class* klass = shadow_frame->GetVRegReference(arg_offset)->AsClass(); |
| 251 | ArtMethod* c = klass->FindDeclaredDirectMethod("<init>", "()V"); |
| 252 | CHECK(c != NULL); |
| 253 | SirtRef<Object> obj(self, klass->AllocObject(self)); |
| 254 | CHECK(obj.get() != NULL); |
| 255 | EnterInterpreterFromInvoke(self, c, obj.get(), NULL, NULL); |
| 256 | result->SetL(obj.get()); |
| 257 | } else if (name == "java.lang.reflect.Field java.lang.Class.getDeclaredField(java.lang.String)") { |
| 258 | // Special managed code cut-out to allow field lookup in a un-started runtime that'd fail |
| 259 | // going the reflective Dex way. |
| 260 | Class* klass = shadow_frame->GetVRegReference(arg_offset)->AsClass(); |
| 261 | String* name = shadow_frame->GetVRegReference(arg_offset + 1)->AsString(); |
| 262 | ArtField* found = NULL; |
| 263 | FieldHelper fh; |
| 264 | ObjectArray<ArtField>* fields = klass->GetIFields(); |
| 265 | for (int32_t i = 0; i < fields->GetLength() && found == NULL; ++i) { |
| 266 | ArtField* f = fields->Get(i); |
| 267 | fh.ChangeField(f); |
| 268 | if (name->Equals(fh.GetName())) { |
| 269 | found = f; |
| 270 | } |
| 271 | } |
| 272 | if (found == NULL) { |
| 273 | fields = klass->GetSFields(); |
| 274 | for (int32_t i = 0; i < fields->GetLength() && found == NULL; ++i) { |
| 275 | ArtField* f = fields->Get(i); |
| 276 | fh.ChangeField(f); |
| 277 | if (name->Equals(fh.GetName())) { |
| 278 | found = f; |
| 279 | } |
| 280 | } |
| 281 | } |
| 282 | CHECK(found != NULL) |
| 283 | << "Failed to find field in Class.getDeclaredField in un-started runtime. name=" |
| 284 | << name->ToModifiedUtf8() << " class=" << PrettyDescriptor(klass); |
| 285 | // TODO: getDeclaredField calls GetType once the field is found to ensure a |
| 286 | // NoClassDefFoundError is thrown if the field's type cannot be resolved. |
| 287 | Class* jlr_Field = self->DecodeJObject(WellKnownClasses::java_lang_reflect_Field)->AsClass(); |
Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 288 | SirtRef<Object> field(self, jlr_Field->AllocNonMovableObject(self)); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 289 | CHECK(field.get() != NULL); |
| 290 | ArtMethod* c = jlr_Field->FindDeclaredDirectMethod("<init>", "(Ljava/lang/reflect/ArtField;)V"); |
| 291 | uint32_t args[1]; |
| 292 | args[0] = reinterpret_cast<uint32_t>(found); |
| 293 | EnterInterpreterFromInvoke(self, c, field.get(), args, NULL); |
| 294 | result->SetL(field.get()); |
| 295 | } else if (name == "void java.lang.System.arraycopy(java.lang.Object, int, java.lang.Object, int, int)" || |
| 296 | name == "void java.lang.System.arraycopy(char[], int, char[], int, int)") { |
| 297 | // Special case array copying without initializing System. |
| 298 | Class* ctype = shadow_frame->GetVRegReference(arg_offset)->GetClass()->GetComponentType(); |
| 299 | jint srcPos = shadow_frame->GetVReg(arg_offset + 1); |
| 300 | jint dstPos = shadow_frame->GetVReg(arg_offset + 3); |
| 301 | jint length = shadow_frame->GetVReg(arg_offset + 4); |
| 302 | if (!ctype->IsPrimitive()) { |
| 303 | ObjectArray<Object>* src = shadow_frame->GetVRegReference(arg_offset)->AsObjectArray<Object>(); |
| 304 | ObjectArray<Object>* dst = shadow_frame->GetVRegReference(arg_offset + 2)->AsObjectArray<Object>(); |
| 305 | for (jint i = 0; i < length; ++i) { |
| 306 | dst->Set(dstPos + i, src->Get(srcPos + i)); |
| 307 | } |
| 308 | } else if (ctype->IsPrimitiveChar()) { |
| 309 | CharArray* src = shadow_frame->GetVRegReference(arg_offset)->AsCharArray(); |
| 310 | CharArray* dst = shadow_frame->GetVRegReference(arg_offset + 2)->AsCharArray(); |
| 311 | for (jint i = 0; i < length; ++i) { |
| 312 | dst->Set(dstPos + i, src->Get(srcPos + i)); |
| 313 | } |
| 314 | } else if (ctype->IsPrimitiveInt()) { |
| 315 | IntArray* src = shadow_frame->GetVRegReference(arg_offset)->AsIntArray(); |
| 316 | IntArray* dst = shadow_frame->GetVRegReference(arg_offset + 2)->AsIntArray(); |
| 317 | for (jint i = 0; i < length; ++i) { |
| 318 | dst->Set(dstPos + i, src->Get(srcPos + i)); |
| 319 | } |
| 320 | } else { |
| 321 | UNIMPLEMENTED(FATAL) << "System.arraycopy of unexpected type: " << PrettyDescriptor(ctype); |
| 322 | } |
| 323 | } else { |
| 324 | // Not special, continue with regular interpreter execution. |
| 325 | artInterpreterToInterpreterBridge(self, mh, code_item, shadow_frame, result); |
| 326 | } |
| 327 | } |
| 328 | |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 329 | // Explicit DoCall template function declarations. |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 330 | #define EXPLICIT_DO_CALL_TEMPLATE_DECL(_is_range, _do_assignability_check) \ |
| 331 | template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) \ |
Sebastien Hertz | 9119c5f | 2013-12-16 11:31:45 +0100 | [diff] [blame] | 332 | bool DoCall<_is_range, _do_assignability_check>(ArtMethod* method, Thread* self, \ |
| 333 | ShadowFrame& shadow_frame, \ |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 334 | const Instruction* inst, uint16_t inst_data, \ |
| 335 | JValue* result) |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 336 | EXPLICIT_DO_CALL_TEMPLATE_DECL(false, false); |
| 337 | EXPLICIT_DO_CALL_TEMPLATE_DECL(false, true); |
| 338 | EXPLICIT_DO_CALL_TEMPLATE_DECL(true, false); |
| 339 | EXPLICIT_DO_CALL_TEMPLATE_DECL(true, true); |
| 340 | #undef EXPLICIT_DO_CALL_TEMPLATE_DECL |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 341 | |
| 342 | // Explicit DoFilledNewArray template function declarations. |
| 343 | #define EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(_is_range_, _check) \ |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 344 | template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) \ |
| 345 | bool DoFilledNewArray<_is_range_, _check>(const Instruction* inst, \ |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 346 | const ShadowFrame& shadow_frame, \ |
| 347 | Thread* self, JValue* result) |
| 348 | EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(false, false); |
| 349 | EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(false, true); |
| 350 | EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(true, false); |
| 351 | EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(true, true); |
| 352 | #undef EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL |
| 353 | |
| 354 | } // namespace interpreter |
| 355 | } // namespace art |