blob: af528b76736eb17cf635b0f6c435fec3e9945c88 [file] [log] [blame]
Shih-wei Liao2d831012011-09-28 22:06:53 -07001/*
Elliott Hughes0f3c5532012-03-30 14:51:51 -07002 * Copyright (C) 2012 The Android Open Source Project
Shih-wei Liao2d831012011-09-28 22:06:53 -07003 *
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 Rogers7655f292013-07-29 11:07:13 -070017#include "entrypoints/entrypoint_utils.h"
Shih-wei Liao2d831012011-09-28 22:06:53 -070018
Mingyao Yang98d1cc82014-05-15 17:02:16 -070019#include "base/mutex.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080020#include "class_linker-inl.h"
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070021#include "dex_file-inl.h"
Ian Rogers1d54e732013-05-02 21:10:01 -070022#include "gc/accounting/card_table-inl.h"
Brian Carlstromea46f952013-07-30 01:26:50 -070023#include "mirror/art_field-inl.h"
24#include "mirror/art_method-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080025#include "mirror/class-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080026#include "mirror/object-inl.h"
27#include "mirror/object_array-inl.h"
Ian Rogersaf6e67a2013-01-16 08:38:37 -080028#include "reflection.h"
29#include "scoped_thread_state_change.h"
TDYa1275bb86012012-04-11 05:57:28 -070030#include "ScopedLocalRef.h"
Elliott Hugheseac76672012-05-24 21:56:51 -070031#include "well_known_classes.h"
TDYa1275bb86012012-04-11 05:57:28 -070032
jeffhao41005dd2012-05-09 17:58:52 -070033namespace art {
34
Brian Carlstrom34375312014-09-10 23:10:47 -070035static inline mirror::Class* CheckFilledNewArrayAlloc(uint32_t type_idx,
Brian Carlstrom34375312014-09-10 23:10:47 -070036 int32_t component_count,
Andreas Gampe1cc7dba2014-12-17 18:43:01 -080037 mirror::ArtMethod* referrer,
Brian Carlstrom34375312014-09-10 23:10:47 -070038 Thread* self,
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080039 bool access_check)
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -070040 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers57b86d42012-03-27 16:05:41 -070041 if (UNLIKELY(component_count < 0)) {
Ian Rogers62d6c772013-02-27 08:32:07 -080042 ThrowNegativeArraySizeException(component_count);
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080043 return nullptr; // Failure
Elliott Hughes6c8867d2011-10-03 16:34:05 -070044 }
Andreas Gampe58a5af82014-07-31 16:23:49 -070045 mirror::Class* klass = referrer->GetDexCacheResolvedType<false>(type_idx);
Ian Rogers57b86d42012-03-27 16:05:41 -070046 if (UNLIKELY(klass == NULL)) { // Not in dex cache so try to resolve
Ian Rogers62d6c772013-02-27 08:32:07 -080047 klass = Runtime::Current()->GetClassLinker()->ResolveType(type_idx, referrer);
Ian Rogers57b86d42012-03-27 16:05:41 -070048 if (klass == NULL) { // Error
Ian Rogers50b35e22012-10-04 10:09:15 -070049 DCHECK(self->IsExceptionPending());
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080050 return nullptr; // Failure
Ian Rogers19846512012-02-24 11:42:47 -080051 }
Ian Rogersea2a11d2011-10-11 16:48:51 -070052 }
Ian Rogers57b86d42012-03-27 16:05:41 -070053 if (UNLIKELY(klass->IsPrimitive() && !klass->IsPrimitiveInt())) {
54 if (klass->IsPrimitiveLong() || klass->IsPrimitiveDouble()) {
Ian Rogers62d6c772013-02-27 08:32:07 -080055 ThrowRuntimeException("Bad filled array request for type %s",
56 PrettyDescriptor(klass).c_str());
Ian Rogers573db4a2011-12-13 15:30:50 -080057 } else {
Ian Rogers62d6c772013-02-27 08:32:07 -080058 ThrowLocation throw_location = self->GetCurrentLocationForThrow();
59 DCHECK(throw_location.GetMethod() == referrer);
Brian Carlstrom34375312014-09-10 23:10:47 -070060 self->ThrowNewExceptionF(
61 throw_location, "Ljava/lang/InternalError;",
62 "Found type %s; filled-new-array not implemented for anything but 'int'",
63 PrettyDescriptor(klass).c_str());
Ian Rogers573db4a2011-12-13 15:30:50 -080064 }
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080065 return nullptr; // Failure
Ian Rogers57b86d42012-03-27 16:05:41 -070066 }
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -070067 if (access_check) {
68 mirror::Class* referrer_klass = referrer->GetDeclaringClass();
69 if (UNLIKELY(!referrer_klass->CanAccess(klass))) {
70 ThrowIllegalAccessErrorClass(referrer_klass, klass);
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080071 return nullptr; // Failure
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -070072 }
73 }
74 DCHECK(klass->IsArrayClass()) << PrettyClass(klass);
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080075 return klass;
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -070076}
77
78// Helper function to allocate array for FILLED_NEW_ARRAY.
Andreas Gampe1cc7dba2014-12-17 18:43:01 -080079mirror::Array* CheckAndAllocArrayFromCode(uint32_t type_idx, int32_t component_count,
80 mirror::ArtMethod* referrer, Thread* self,
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080081 bool access_check,
Mathieu Chartiere6da9af2013-12-16 11:54:42 -080082 gc::AllocatorType /* allocator_type */) {
Andreas Gampe1cc7dba2014-12-17 18:43:01 -080083 mirror::Class* klass = CheckFilledNewArrayAlloc(type_idx, component_count, referrer, self,
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080084 access_check);
85 if (UNLIKELY(klass == nullptr)) {
86 return nullptr;
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -070087 }
Mathieu Chartiere6da9af2013-12-16 11:54:42 -080088 // Always go slow path for now, filled new array is not common.
89 gc::Heap* heap = Runtime::Current()->GetHeap();
90 // Use the current allocator type in case CheckFilledNewArrayAlloc caused us to suspend and then
91 // the heap switched the allocator type while we were suspended.
Hiroshi Yamauchif0edfc32014-09-25 11:46:46 -070092 return mirror::Array::Alloc<false>(self, klass, component_count,
93 klass->GetComponentSizeShift(),
Ian Rogers6fac4472014-02-25 17:01:10 -080094 heap->GetCurrentAllocator());
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -070095}
96
97// Helper function to allocate array for FILLED_NEW_ARRAY.
Brian Carlstrom34375312014-09-10 23:10:47 -070098mirror::Array* CheckAndAllocArrayFromCodeInstrumented(uint32_t type_idx,
Brian Carlstrom34375312014-09-10 23:10:47 -070099 int32_t component_count,
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800100 mirror::ArtMethod* referrer,
Brian Carlstrom34375312014-09-10 23:10:47 -0700101 Thread* self,
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800102 bool access_check,
Mathieu Chartiere6da9af2013-12-16 11:54:42 -0800103 gc::AllocatorType /* allocator_type */) {
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800104 mirror::Class* klass = CheckFilledNewArrayAlloc(type_idx, component_count, referrer, self,
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800105 access_check);
106 if (UNLIKELY(klass == nullptr)) {
107 return nullptr;
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -0700108 }
Mathieu Chartiere6da9af2013-12-16 11:54:42 -0800109 gc::Heap* heap = Runtime::Current()->GetHeap();
110 // Use the current allocator type in case CheckFilledNewArrayAlloc caused us to suspend and then
111 // the heap switched the allocator type while we were suspended.
Hiroshi Yamauchif0edfc32014-09-25 11:46:46 -0700112 return mirror::Array::Alloc<true>(self, klass, component_count,
113 klass->GetComponentSizeShift(),
Ian Rogers6fac4472014-02-25 17:01:10 -0800114 heap->GetCurrentAllocator());
Ian Rogers57b86d42012-03-27 16:05:41 -0700115}
116
jeffhaod7521322012-11-21 15:38:24 -0800117void ThrowStackOverflowError(Thread* self) {
Brian Carlstrom7571e8b2013-08-12 17:04:14 -0700118 if (self->IsHandlingStackOverflow()) {
Andreas Gampe7ea6f792014-07-14 16:21:44 -0700119 LOG(ERROR) << "Recursive stack overflow.";
120 // We don't fail here because SetStackEndForStackOverflow will print better diagnostics.
Brian Carlstrom7571e8b2013-08-12 17:04:14 -0700121 }
Ian Rogers62d6c772013-02-27 08:32:07 -0800122
jeffhaod7521322012-11-21 15:38:24 -0800123 self->SetStackEndForStackOverflow(); // Allow space on the stack for constructor to execute.
124 JNIEnvExt* env = self->GetJniEnv();
125 std::string msg("stack size ");
126 msg += PrettySize(self->GetStackSize());
Andreas Gampe7ea6f792014-07-14 16:21:44 -0700127
128 // Avoid running Java code for exception initialization.
129 // TODO: Checks to make this a bit less brittle.
130
131 std::string error_msg;
132
133 // Allocate an uninitialized object.
134 ScopedLocalRef<jobject> exc(env,
135 env->AllocObject(WellKnownClasses::java_lang_StackOverflowError));
136 if (exc.get() != nullptr) {
137 // "Initialize".
138 // StackOverflowError -> VirtualMachineError -> Error -> Throwable -> Object.
139 // Only Throwable has "custom" fields:
140 // String detailMessage.
141 // Throwable cause (= this).
142 // List<Throwable> suppressedExceptions (= Collections.emptyList()).
143 // Object stackState;
144 // StackTraceElement[] stackTrace;
145 // Only Throwable has a non-empty constructor:
146 // this.stackTrace = EmptyArray.STACK_TRACE_ELEMENT;
147 // fillInStackTrace();
148
149 // detailMessage.
150 // TODO: Use String::FromModifiedUTF...?
151 ScopedLocalRef<jstring> s(env, env->NewStringUTF(msg.c_str()));
152 if (s.get() != nullptr) {
Brian Carlstrom34375312014-09-10 23:10:47 -0700153 env->SetObjectField(exc.get(), WellKnownClasses::java_lang_Throwable_detailMessage, s.get());
Andreas Gampe7ea6f792014-07-14 16:21:44 -0700154
155 // cause.
Brian Carlstrom34375312014-09-10 23:10:47 -0700156 env->SetObjectField(exc.get(), WellKnownClasses::java_lang_Throwable_cause, exc.get());
Andreas Gampe7ea6f792014-07-14 16:21:44 -0700157
158 // suppressedExceptions.
Andreas Gampe7ea6f792014-07-14 16:21:44 -0700159 ScopedLocalRef<jobject> emptylist(env, env->GetStaticObjectField(
Brian Carlstrom34375312014-09-10 23:10:47 -0700160 WellKnownClasses::java_util_Collections,
161 WellKnownClasses::java_util_Collections_EMPTY_LIST));
Andreas Gampe7ea6f792014-07-14 16:21:44 -0700162 CHECK(emptylist.get() != nullptr);
Brian Carlstrom34375312014-09-10 23:10:47 -0700163 env->SetObjectField(exc.get(),
164 WellKnownClasses::java_lang_Throwable_suppressedExceptions,
165 emptylist.get());
Andreas Gampe7ea6f792014-07-14 16:21:44 -0700166
167 // stackState is set as result of fillInStackTrace. fillInStackTrace calls
168 // nativeFillInStackTrace.
169 ScopedLocalRef<jobject> stack_state_val(env, nullptr);
170 {
171 ScopedObjectAccessUnchecked soa(env);
172 stack_state_val.reset(soa.Self()->CreateInternalStackTrace<false>(soa));
173 }
174 if (stack_state_val.get() != nullptr) {
Brian Carlstrom34375312014-09-10 23:10:47 -0700175 env->SetObjectField(exc.get(),
176 WellKnownClasses::java_lang_Throwable_stackState,
177 stack_state_val.get());
Andreas Gampe7ea6f792014-07-14 16:21:44 -0700178
179 // stackTrace.
Andreas Gampe7ea6f792014-07-14 16:21:44 -0700180 ScopedLocalRef<jobject> stack_trace_elem(env, env->GetStaticObjectField(
Brian Carlstrom34375312014-09-10 23:10:47 -0700181 WellKnownClasses::libcore_util_EmptyArray,
182 WellKnownClasses::libcore_util_EmptyArray_STACK_TRACE_ELEMENT));
183 env->SetObjectField(exc.get(),
184 WellKnownClasses::java_lang_Throwable_stackTrace,
185 stack_trace_elem.get());
Andreas Gampe7ea6f792014-07-14 16:21:44 -0700186 } else {
187 error_msg = "Could not create stack trace.";
188 }
Mathieu Chartier50c138f2015-01-07 16:00:03 -0800189 // Throw the exception.
Nicolas Geoffray14691c52015-03-05 10:40:17 +0000190 self->SetException(reinterpret_cast<mirror::Throwable*>(self->DecodeJObject(exc.get())));
Andreas Gampe7ea6f792014-07-14 16:21:44 -0700191 } else {
192 // Could not allocate a string object.
193 error_msg = "Couldn't throw new StackOverflowError because JNI NewStringUTF failed.";
194 }
195 } else {
196 error_msg = "Could not allocate StackOverflowError object.";
197 }
198
199 if (!error_msg.empty()) {
Andreas Gampe1de0f5c2015-02-19 10:54:31 -0800200 LOG(WARNING) << error_msg;
jeffhaod7521322012-11-21 15:38:24 -0800201 CHECK(self->IsExceptionPending());
202 }
Dave Allisonf9439142014-03-27 15:10:22 -0700203
204 bool explicit_overflow_check = Runtime::Current()->ExplicitStackOverflowChecks();
Dave Allisonb090a182014-08-14 17:02:48 +0000205 self->ResetDefaultStackEnd(); // Return to default stack size.
Dave Allison648d7112014-07-25 16:15:27 -0700206
207 // And restore protection if implicit checks are on.
208 if (!explicit_overflow_check) {
209 self->ProtectStack();
210 }
jeffhaod7521322012-11-21 15:38:24 -0800211}
212
Ian Rogerse5877a12014-07-16 12:06:35 -0700213void CheckReferenceResult(mirror::Object* o, Thread* self) {
Ian Rogersc0542af2014-09-03 16:16:56 -0700214 if (o == nullptr) {
Ian Rogerse5877a12014-07-16 12:06:35 -0700215 return;
216 }
Ian Rogerse5877a12014-07-16 12:06:35 -0700217 // Make sure that the result is an instance of the type this method was expected to return.
Ian Rogersded66a02014-10-28 18:12:55 -0700218 mirror::Class* return_type = self->GetCurrentMethod(nullptr)->GetReturnType();
Ian Rogerse5877a12014-07-16 12:06:35 -0700219
220 if (!o->InstanceOf(return_type)) {
Ian Rogersc0542af2014-09-03 16:16:56 -0700221 Runtime::Current()->GetJavaVM()->JniAbortF(nullptr,
222 "attempt to return an instance of %s from %s",
Ian Rogers68d8b422014-07-17 11:09:10 -0700223 PrettyTypeOf(o).c_str(),
Ian Rogersded66a02014-10-28 18:12:55 -0700224 PrettyMethod(self->GetCurrentMethod(nullptr)).c_str());
Ian Rogerse5877a12014-07-16 12:06:35 -0700225 }
226}
227
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -0700228JValue InvokeProxyInvocationHandler(ScopedObjectAccessAlreadyRunnable& soa, const char* shorty,
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800229 jobject rcvr_jobj, jobject interface_method_jobj,
230 std::vector<jvalue>& args) {
231 DCHECK(soa.Env()->IsInstanceOf(rcvr_jobj, WellKnownClasses::java_lang_reflect_Proxy));
232
233 // Build argument array possibly triggering GC.
234 soa.Self()->AssertThreadSuspensionIsAllowable();
235 jobjectArray args_jobj = NULL;
236 const JValue zero;
Jeff Haof00571c2014-05-29 17:29:47 -0700237 int32_t target_sdk_version = Runtime::Current()->GetTargetSdkVersion();
238 // Do not create empty arrays unless needed to maintain Dalvik bug compatibility.
239 if (args.size() > 0 || (target_sdk_version > 0 && target_sdk_version <= 21)) {
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800240 args_jobj = soa.Env()->NewObjectArray(args.size(), WellKnownClasses::java_lang_Object, NULL);
241 if (args_jobj == NULL) {
242 CHECK(soa.Self()->IsExceptionPending());
243 return zero;
244 }
245 for (size_t i = 0; i < args.size(); ++i) {
246 if (shorty[i + 1] == 'L') {
247 jobject val = args.at(i).l;
248 soa.Env()->SetObjectArrayElement(args_jobj, i, val);
249 } else {
250 JValue jv;
251 jv.SetJ(args.at(i).j);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800252 mirror::Object* val = BoxPrimitive(Primitive::GetType(shorty[i + 1]), jv);
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800253 if (val == NULL) {
254 CHECK(soa.Self()->IsExceptionPending());
255 return zero;
256 }
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100257 soa.Decode<mirror::ObjectArray<mirror::Object>* >(args_jobj)->Set<false>(i, val);
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800258 }
259 }
260 }
261
Brian Carlstromea46f952013-07-30 01:26:50 -0700262 // Call Proxy.invoke(Proxy proxy, ArtMethod method, Object[] args).
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800263 jvalue invocation_args[3];
264 invocation_args[0].l = rcvr_jobj;
265 invocation_args[1].l = interface_method_jobj;
266 invocation_args[2].l = args_jobj;
267 jobject result =
Brian Carlstromea46f952013-07-30 01:26:50 -0700268 soa.Env()->CallStaticObjectMethodA(WellKnownClasses::java_lang_reflect_Proxy,
269 WellKnownClasses::java_lang_reflect_Proxy_invoke,
270 invocation_args);
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800271
272 // Unbox result and handle error conditions.
Ian Rogers62d6c772013-02-27 08:32:07 -0800273 if (LIKELY(!soa.Self()->IsExceptionPending())) {
274 if (shorty[0] == 'V' || (shorty[0] == 'L' && result == NULL)) {
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800275 // Do nothing.
276 return zero;
277 } else {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700278 StackHandleScope<1> hs(soa.Self());
Ian Rogersded66a02014-10-28 18:12:55 -0700279 Handle<mirror::ArtMethod> h_interface_method(
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700280 hs.NewHandle(soa.Decode<mirror::ArtMethod*>(interface_method_jobj)));
281 // This can cause thread suspension.
Ian Rogersded66a02014-10-28 18:12:55 -0700282 mirror::Class* result_type = h_interface_method->GetReturnType();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800283 mirror::Object* result_ref = soa.Decode<mirror::Object*>(result);
Ian Rogers62d6c772013-02-27 08:32:07 -0800284 mirror::Object* rcvr = soa.Decode<mirror::Object*>(rcvr_jobj);
Brian Carlstromea46f952013-07-30 01:26:50 -0700285 mirror::ArtMethod* proxy_method;
Ian Rogersded66a02014-10-28 18:12:55 -0700286 if (h_interface_method->GetDeclaringClass()->IsInterface()) {
287 proxy_method = rcvr->GetClass()->FindVirtualMethodForInterface(h_interface_method.Get());
Ian Rogers62d6c772013-02-27 08:32:07 -0800288 } else {
289 // Proxy dispatch to a method defined in Object.
Ian Rogersded66a02014-10-28 18:12:55 -0700290 DCHECK(h_interface_method->GetDeclaringClass()->IsObjectClass());
291 proxy_method = h_interface_method.Get();
Ian Rogers62d6c772013-02-27 08:32:07 -0800292 }
293 ThrowLocation throw_location(rcvr, proxy_method, -1);
294 JValue result_unboxed;
Ian Rogers84956ff2014-03-26 23:52:41 -0700295 if (!UnboxPrimitiveForResult(throw_location, result_ref, result_type, &result_unboxed)) {
Ian Rogers530f71c2013-02-22 23:29:00 -0800296 DCHECK(soa.Self()->IsExceptionPending());
Ian Rogers62d6c772013-02-27 08:32:07 -0800297 return zero;
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800298 }
299 return result_unboxed;
300 }
301 } else {
302 // In the case of checked exceptions that aren't declared, the exception must be wrapped by
303 // a UndeclaredThrowableException.
Nicolas Geoffray14691c52015-03-05 10:40:17 +0000304 mirror::Throwable* exception = soa.Self()->GetException();
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800305 if (exception->IsCheckedException()) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800306 mirror::Object* rcvr = soa.Decode<mirror::Object*>(rcvr_jobj);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700307 mirror::Class* proxy_class = rcvr->GetClass();
Brian Carlstromea46f952013-07-30 01:26:50 -0700308 mirror::ArtMethod* interface_method =
309 soa.Decode<mirror::ArtMethod*>(interface_method_jobj);
310 mirror::ArtMethod* proxy_method =
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800311 rcvr->GetClass()->FindVirtualMethodForInterface(interface_method);
312 int throws_index = -1;
313 size_t num_virt_methods = proxy_class->NumVirtualMethods();
314 for (size_t i = 0; i < num_virt_methods; i++) {
315 if (proxy_class->GetVirtualMethod(i) == proxy_method) {
316 throws_index = i;
317 break;
318 }
319 }
320 CHECK_NE(throws_index, -1);
Brian Carlstrom34375312014-09-10 23:10:47 -0700321 mirror::ObjectArray<mirror::Class>* declared_exceptions =
322 proxy_class->GetThrows()->Get(throws_index);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800323 mirror::Class* exception_class = exception->GetClass();
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800324 bool declares_exception = false;
325 for (int i = 0; i < declared_exceptions->GetLength() && !declares_exception; i++) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800326 mirror::Class* declared_exception = declared_exceptions->Get(i);
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800327 declares_exception = declared_exception->IsAssignableFrom(exception_class);
328 }
329 if (!declares_exception) {
Ian Rogers62d6c772013-02-27 08:32:07 -0800330 ThrowLocation throw_location(rcvr, proxy_method, -1);
331 soa.Self()->ThrowNewWrappedException(throw_location,
332 "Ljava/lang/reflect/UndeclaredThrowableException;",
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800333 NULL);
334 }
335 }
336 return zero;
337 }
338}
Ian Rogers832336b2014-10-08 15:35:22 -0700339
340bool FillArrayData(mirror::Object* obj, const Instruction::ArrayDataPayload* payload) {
341 DCHECK_EQ(payload->ident, static_cast<uint16_t>(Instruction::kArrayDataSignature));
342 if (UNLIKELY(obj == nullptr)) {
343 ThrowNullPointerException(nullptr, "null array in FILL_ARRAY_DATA");
344 return false;
345 }
346 mirror::Array* array = obj->AsArray();
347 DCHECK(!array->IsObjectArray());
348 if (UNLIKELY(static_cast<int32_t>(payload->element_count) > array->GetLength())) {
349 Thread* self = Thread::Current();
350 ThrowLocation throw_location = self->GetCurrentLocationForThrow();
351 self->ThrowNewExceptionF(throw_location,
352 "Ljava/lang/ArrayIndexOutOfBoundsException;",
353 "failed FILL_ARRAY_DATA; length=%d, index=%d",
354 array->GetLength(), payload->element_count);
355 return false;
356 }
357 // Copy data from dex file to memory assuming both are little endian.
358 uint32_t size_in_bytes = payload->element_count * payload->element_width;
359 memcpy(array->GetRawData(payload->element_width, 0), payload->data, size_in_bytes);
360 return true;
361}
362
Shih-wei Liao2d831012011-09-28 22:06:53 -0700363} // namespace art