blob: c559389dba7b76152716ca34ad7e71e440af90bf [file] [log] [blame]
Andreas Gampe2969bcd2015-03-09 12:57:41 -07001/*
2 * Copyright (C) 2015 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 "unstarted_runtime.h"
18
19#include <cmath>
20#include <unordered_map>
21
Andreas Gampeaacc25d2015-04-01 14:49:06 -070022#include "ScopedLocalRef.h"
23
Mathieu Chartiere401d142015-04-22 13:56:20 -070024#include "art_method-inl.h"
Andreas Gampe2969bcd2015-03-09 12:57:41 -070025#include "base/logging.h"
26#include "base/macros.h"
27#include "class_linker.h"
28#include "common_throws.h"
29#include "entrypoints/entrypoint_utils-inl.h"
30#include "handle_scope-inl.h"
31#include "interpreter/interpreter_common.h"
32#include "mirror/array-inl.h"
Andreas Gampe2969bcd2015-03-09 12:57:41 -070033#include "mirror/class.h"
Mathieu Chartierdaaf3262015-03-24 13:30:28 -070034#include "mirror/field-inl.h"
Andreas Gampe2969bcd2015-03-09 12:57:41 -070035#include "mirror/object-inl.h"
36#include "mirror/object_array-inl.h"
37#include "mirror/string-inl.h"
38#include "nth_caller_visitor.h"
39#include "thread.h"
Sebastien Hertz2fd7e692015-04-02 11:11:19 +020040#include "transaction.h"
Andreas Gampe2969bcd2015-03-09 12:57:41 -070041#include "well_known_classes.h"
Andreas Gampef778eb22015-04-13 14:17:09 -070042#include "zip_archive.h"
Andreas Gampe2969bcd2015-03-09 12:57:41 -070043
44namespace art {
45namespace interpreter {
46
Andreas Gampe068b0c02015-03-11 12:44:47 -070047static void AbortTransactionOrFail(Thread* self, const char* fmt, ...)
Sebastien Hertz45b15972015-04-03 16:07:05 +020048 __attribute__((__format__(__printf__, 2, 3)))
Mathieu Chartier90443472015-07-16 20:32:27 -070049 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz45b15972015-04-03 16:07:05 +020050
51static void AbortTransactionOrFail(Thread* self, const char* fmt, ...) {
Andreas Gampe068b0c02015-03-11 12:44:47 -070052 va_list args;
Andreas Gampe068b0c02015-03-11 12:44:47 -070053 if (Runtime::Current()->IsActiveTransaction()) {
Sebastien Hertz45b15972015-04-03 16:07:05 +020054 va_start(args, fmt);
55 AbortTransactionV(self, fmt, args);
Andreas Gampe068b0c02015-03-11 12:44:47 -070056 va_end(args);
57 } else {
Sebastien Hertz45b15972015-04-03 16:07:05 +020058 va_start(args, fmt);
59 std::string msg;
60 StringAppendV(&msg, fmt, args);
61 va_end(args);
62 LOG(FATAL) << "Trying to abort, but not in transaction mode: " << msg;
Andreas Gampe068b0c02015-03-11 12:44:47 -070063 UNREACHABLE();
64 }
65}
66
Andreas Gampe2969bcd2015-03-09 12:57:41 -070067// Helper function to deal with class loading in an unstarted runtime.
68static void UnstartedRuntimeFindClass(Thread* self, Handle<mirror::String> className,
69 Handle<mirror::ClassLoader> class_loader, JValue* result,
70 const std::string& method_name, bool initialize_class,
71 bool abort_if_not_found)
Mathieu Chartier90443472015-07-16 20:32:27 -070072 SHARED_REQUIRES(Locks::mutator_lock_) {
Andreas Gampe2969bcd2015-03-09 12:57:41 -070073 CHECK(className.Get() != nullptr);
74 std::string descriptor(DotToDescriptor(className->ToModifiedUtf8().c_str()));
75 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
76
77 mirror::Class* found = class_linker->FindClass(self, descriptor.c_str(), class_loader);
78 if (found == nullptr && abort_if_not_found) {
79 if (!self->IsExceptionPending()) {
Andreas Gampe068b0c02015-03-11 12:44:47 -070080 AbortTransactionOrFail(self, "%s failed in un-started runtime for class: %s",
81 method_name.c_str(), PrettyDescriptor(descriptor.c_str()).c_str());
Andreas Gampe2969bcd2015-03-09 12:57:41 -070082 }
83 return;
84 }
85 if (found != nullptr && initialize_class) {
86 StackHandleScope<1> hs(self);
87 Handle<mirror::Class> h_class(hs.NewHandle(found));
88 if (!class_linker->EnsureInitialized(self, h_class, true, true)) {
89 CHECK(self->IsExceptionPending());
90 return;
91 }
92 }
93 result->SetL(found);
94}
95
96// Common helper for class-loading cutouts in an unstarted runtime. We call Runtime methods that
97// rely on Java code to wrap errors in the correct exception class (i.e., NoClassDefFoundError into
98// ClassNotFoundException), so need to do the same. The only exception is if the exception is
Sebastien Hertz2fd7e692015-04-02 11:11:19 +020099// actually the transaction abort exception. This must not be wrapped, as it signals an
100// initialization abort.
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700101static void CheckExceptionGenerateClassNotFound(Thread* self)
Mathieu Chartier90443472015-07-16 20:32:27 -0700102 SHARED_REQUIRES(Locks::mutator_lock_) {
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700103 if (self->IsExceptionPending()) {
Sebastien Hertz2fd7e692015-04-02 11:11:19 +0200104 // If it is not the transaction abort exception, wrap it.
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700105 std::string type(PrettyTypeOf(self->GetException()));
Sebastien Hertz2fd7e692015-04-02 11:11:19 +0200106 if (type != Transaction::kAbortExceptionDescriptor) {
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700107 self->ThrowNewWrappedException("Ljava/lang/ClassNotFoundException;",
108 "ClassNotFoundException");
109 }
110 }
111}
112
Andreas Gampe5d4bb1d2015-04-14 22:16:14 -0700113static mirror::String* GetClassName(Thread* self, ShadowFrame* shadow_frame, size_t arg_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700114 SHARED_REQUIRES(Locks::mutator_lock_) {
Andreas Gampe5d4bb1d2015-04-14 22:16:14 -0700115 mirror::Object* param = shadow_frame->GetVRegReference(arg_offset);
116 if (param == nullptr) {
117 AbortTransactionOrFail(self, "Null-pointer in Class.forName.");
118 return nullptr;
119 }
120 return param->AsString();
121}
122
Andreas Gampe799681b2015-05-15 19:24:12 -0700123void UnstartedRuntime::UnstartedClassForName(
Mathieu Chartiere401d142015-04-22 13:56:20 -0700124 Thread* self, ShadowFrame* shadow_frame, JValue* result, size_t arg_offset) {
Andreas Gampe5d4bb1d2015-04-14 22:16:14 -0700125 mirror::String* class_name = GetClassName(self, shadow_frame, arg_offset);
126 if (class_name == nullptr) {
127 return;
128 }
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700129 StackHandleScope<1> hs(self);
130 Handle<mirror::String> h_class_name(hs.NewHandle(class_name));
131 UnstartedRuntimeFindClass(self, h_class_name, NullHandle<mirror::ClassLoader>(), result,
132 "Class.forName", true, false);
133 CheckExceptionGenerateClassNotFound(self);
134}
135
Andreas Gampe799681b2015-05-15 19:24:12 -0700136void UnstartedRuntime::UnstartedClassForNameLong(
Mathieu Chartiere401d142015-04-22 13:56:20 -0700137 Thread* self, ShadowFrame* shadow_frame, JValue* result, size_t arg_offset) {
Andreas Gampe5d4bb1d2015-04-14 22:16:14 -0700138 mirror::String* class_name = GetClassName(self, shadow_frame, arg_offset);
139 if (class_name == nullptr) {
Andreas Gampebf4d3af2015-04-14 10:10:33 -0700140 return;
141 }
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700142 bool initialize_class = shadow_frame->GetVReg(arg_offset + 1) != 0;
143 mirror::ClassLoader* class_loader =
144 down_cast<mirror::ClassLoader*>(shadow_frame->GetVRegReference(arg_offset + 2));
145 StackHandleScope<2> hs(self);
146 Handle<mirror::String> h_class_name(hs.NewHandle(class_name));
147 Handle<mirror::ClassLoader> h_class_loader(hs.NewHandle(class_loader));
148 UnstartedRuntimeFindClass(self, h_class_name, h_class_loader, result, "Class.forName",
149 initialize_class, false);
150 CheckExceptionGenerateClassNotFound(self);
151}
152
Andreas Gampe799681b2015-05-15 19:24:12 -0700153void UnstartedRuntime::UnstartedClassClassForName(
Mathieu Chartiere401d142015-04-22 13:56:20 -0700154 Thread* self, ShadowFrame* shadow_frame, JValue* result, size_t arg_offset) {
Andreas Gampe5d4bb1d2015-04-14 22:16:14 -0700155 mirror::String* class_name = GetClassName(self, shadow_frame, arg_offset);
156 if (class_name == nullptr) {
157 return;
158 }
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700159 bool initialize_class = shadow_frame->GetVReg(arg_offset + 1) != 0;
160 mirror::ClassLoader* class_loader =
161 down_cast<mirror::ClassLoader*>(shadow_frame->GetVRegReference(arg_offset + 2));
162 StackHandleScope<2> hs(self);
163 Handle<mirror::String> h_class_name(hs.NewHandle(class_name));
164 Handle<mirror::ClassLoader> h_class_loader(hs.NewHandle(class_loader));
165 UnstartedRuntimeFindClass(self, h_class_name, h_class_loader, result, "Class.classForName",
166 initialize_class, false);
167 CheckExceptionGenerateClassNotFound(self);
168}
169
Andreas Gampe799681b2015-05-15 19:24:12 -0700170void UnstartedRuntime::UnstartedClassNewInstance(
Mathieu Chartiere401d142015-04-22 13:56:20 -0700171 Thread* self, ShadowFrame* shadow_frame, JValue* result, size_t arg_offset) {
172 StackHandleScope<2> hs(self); // Class, constructor, object.
Andreas Gampe5d4bb1d2015-04-14 22:16:14 -0700173 mirror::Object* param = shadow_frame->GetVRegReference(arg_offset);
174 if (param == nullptr) {
175 AbortTransactionOrFail(self, "Null-pointer in Class.newInstance.");
176 return;
177 }
178 mirror::Class* klass = param->AsClass();
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700179 Handle<mirror::Class> h_klass(hs.NewHandle(klass));
Andreas Gampe0f7e3d62015-03-11 13:24:35 -0700180
181 // Check that it's not null.
182 if (h_klass.Get() == nullptr) {
183 AbortTransactionOrFail(self, "Class reference is null for newInstance");
184 return;
185 }
186
187 // If we're in a transaction, class must not be finalizable (it or a superclass has a finalizer).
188 if (Runtime::Current()->IsActiveTransaction()) {
189 if (h_klass.Get()->IsFinalizable()) {
Sebastien Hertz45b15972015-04-03 16:07:05 +0200190 AbortTransactionF(self, "Class for newInstance is finalizable: '%s'",
191 PrettyClass(h_klass.Get()).c_str());
Andreas Gampe0f7e3d62015-03-11 13:24:35 -0700192 return;
193 }
194 }
195
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700196 // There are two situations in which we'll abort this run.
197 // 1) If the class isn't yet initialized and initialization fails.
198 // 2) If we can't find the default constructor. We'll postpone the exception to runtime.
199 // Note that 2) could likely be handled here, but for safety abort the transaction.
200 bool ok = false;
Mathieu Chartiere401d142015-04-22 13:56:20 -0700201 auto* cl = Runtime::Current()->GetClassLinker();
202 if (cl->EnsureInitialized(self, h_klass, true, true)) {
203 auto* cons = h_klass->FindDeclaredDirectMethod("<init>", "()V", cl->GetImagePointerSize());
204 if (cons != nullptr) {
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700205 Handle<mirror::Object> h_obj(hs.NewHandle(klass->AllocObject(self)));
206 CHECK(h_obj.Get() != nullptr); // We don't expect OOM at compile-time.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700207 EnterInterpreterFromInvoke(self, cons, h_obj.Get(), nullptr, nullptr);
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700208 if (!self->IsExceptionPending()) {
209 result->SetL(h_obj.Get());
210 ok = true;
211 }
212 } else {
213 self->ThrowNewExceptionF("Ljava/lang/InternalError;",
214 "Could not find default constructor for '%s'",
215 PrettyClass(h_klass.Get()).c_str());
216 }
217 }
218 if (!ok) {
Andreas Gampe068b0c02015-03-11 12:44:47 -0700219 AbortTransactionOrFail(self, "Failed in Class.newInstance for '%s' with %s",
220 PrettyClass(h_klass.Get()).c_str(),
221 PrettyTypeOf(self->GetException()).c_str());
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700222 }
223}
224
Andreas Gampe799681b2015-05-15 19:24:12 -0700225void UnstartedRuntime::UnstartedClassGetDeclaredField(
Mathieu Chartiere401d142015-04-22 13:56:20 -0700226 Thread* self, ShadowFrame* shadow_frame, JValue* result, size_t arg_offset) {
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700227 // Special managed code cut-out to allow field lookup in a un-started runtime that'd fail
228 // going the reflective Dex way.
229 mirror::Class* klass = shadow_frame->GetVRegReference(arg_offset)->AsClass();
230 mirror::String* name2 = shadow_frame->GetVRegReference(arg_offset + 1)->AsString();
Mathieu Chartierc7853442015-03-27 14:35:38 -0700231 ArtField* found = nullptr;
Mathieu Chartier54d220e2015-07-30 16:20:06 -0700232 for (ArtField& field : klass->GetIFields()) {
233 if (name2->Equals(field.GetName())) {
234 found = &field;
Mathieu Chartierc7853442015-03-27 14:35:38 -0700235 break;
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700236 }
237 }
238 if (found == nullptr) {
Mathieu Chartier54d220e2015-07-30 16:20:06 -0700239 for (ArtField& field : klass->GetSFields()) {
240 if (name2->Equals(field.GetName())) {
241 found = &field;
Mathieu Chartierc7853442015-03-27 14:35:38 -0700242 break;
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700243 }
244 }
245 }
Andreas Gampe068b0c02015-03-11 12:44:47 -0700246 if (found == nullptr) {
247 AbortTransactionOrFail(self, "Failed to find field in Class.getDeclaredField in un-started "
248 " runtime. name=%s class=%s", name2->ToModifiedUtf8().c_str(),
249 PrettyDescriptor(klass).c_str());
250 return;
251 }
Mathieu Chartierdaaf3262015-03-24 13:30:28 -0700252 if (Runtime::Current()->IsActiveTransaction()) {
253 result->SetL(mirror::Field::CreateFromArtField<true>(self, found, true));
254 } else {
255 result->SetL(mirror::Field::CreateFromArtField<false>(self, found, true));
256 }
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700257}
258
Andreas Gampe799681b2015-05-15 19:24:12 -0700259void UnstartedRuntime::UnstartedVmClassLoaderFindLoadedClass(
Mathieu Chartiere401d142015-04-22 13:56:20 -0700260 Thread* self, ShadowFrame* shadow_frame, JValue* result, size_t arg_offset) {
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700261 mirror::String* class_name = shadow_frame->GetVRegReference(arg_offset + 1)->AsString();
262 mirror::ClassLoader* class_loader =
263 down_cast<mirror::ClassLoader*>(shadow_frame->GetVRegReference(arg_offset));
264 StackHandleScope<2> hs(self);
265 Handle<mirror::String> h_class_name(hs.NewHandle(class_name));
266 Handle<mirror::ClassLoader> h_class_loader(hs.NewHandle(class_loader));
267 UnstartedRuntimeFindClass(self, h_class_name, h_class_loader, result,
268 "VMClassLoader.findLoadedClass", false, false);
269 // This might have an error pending. But semantics are to just return null.
270 if (self->IsExceptionPending()) {
271 // If it is an InternalError, keep it. See CheckExceptionGenerateClassNotFound.
272 std::string type(PrettyTypeOf(self->GetException()));
273 if (type != "java.lang.InternalError") {
274 self->ClearException();
275 }
276 }
277}
278
Mathieu Chartiere401d142015-04-22 13:56:20 -0700279void UnstartedRuntime::UnstartedVoidLookupType(
280 Thread* self ATTRIBUTE_UNUSED, ShadowFrame* shadow_frame ATTRIBUTE_UNUSED, JValue* result,
281 size_t arg_offset ATTRIBUTE_UNUSED) {
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700282 result->SetL(Runtime::Current()->GetClassLinker()->FindPrimitiveClass('V'));
283}
284
Andreas Gampe8e6c3fd2015-03-11 18:34:44 -0700285// Arraycopy emulation.
286// Note: we can't use any fast copy functions, as they are not available under transaction.
287
288template <typename T>
289static void PrimitiveArrayCopy(Thread* self,
290 mirror::Array* src_array, int32_t src_pos,
291 mirror::Array* dst_array, int32_t dst_pos,
292 int32_t length)
Mathieu Chartier90443472015-07-16 20:32:27 -0700293 SHARED_REQUIRES(Locks::mutator_lock_) {
Andreas Gampe8e6c3fd2015-03-11 18:34:44 -0700294 if (src_array->GetClass()->GetComponentType() != dst_array->GetClass()->GetComponentType()) {
295 AbortTransactionOrFail(self, "Types mismatched in arraycopy: %s vs %s.",
296 PrettyDescriptor(src_array->GetClass()->GetComponentType()).c_str(),
297 PrettyDescriptor(dst_array->GetClass()->GetComponentType()).c_str());
298 return;
299 }
300 mirror::PrimitiveArray<T>* src = down_cast<mirror::PrimitiveArray<T>*>(src_array);
301 mirror::PrimitiveArray<T>* dst = down_cast<mirror::PrimitiveArray<T>*>(dst_array);
302 const bool copy_forward = (dst_pos < src_pos) || (dst_pos - src_pos >= length);
303 if (copy_forward) {
304 for (int32_t i = 0; i < length; ++i) {
305 dst->Set(dst_pos + i, src->Get(src_pos + i));
306 }
307 } else {
308 for (int32_t i = 1; i <= length; ++i) {
309 dst->Set(dst_pos + length - i, src->Get(src_pos + length - i));
310 }
311 }
312}
313
Andreas Gampe799681b2015-05-15 19:24:12 -0700314void UnstartedRuntime::UnstartedSystemArraycopy(
Mathieu Chartiere401d142015-04-22 13:56:20 -0700315 Thread* self, ShadowFrame* shadow_frame, JValue* result ATTRIBUTE_UNUSED, size_t arg_offset) {
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700316 // Special case array copying without initializing System.
Andreas Gampe8e6c3fd2015-03-11 18:34:44 -0700317 jint src_pos = shadow_frame->GetVReg(arg_offset + 1);
318 jint dst_pos = shadow_frame->GetVReg(arg_offset + 3);
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700319 jint length = shadow_frame->GetVReg(arg_offset + 4);
Andreas Gampe8e6c3fd2015-03-11 18:34:44 -0700320 mirror::Array* src_array = shadow_frame->GetVRegReference(arg_offset)->AsArray();
321 mirror::Array* dst_array = shadow_frame->GetVRegReference(arg_offset + 2)->AsArray();
322
323 // Null checking.
324 if (src_array == nullptr) {
325 AbortTransactionOrFail(self, "src is null in arraycopy.");
326 return;
327 }
328 if (dst_array == nullptr) {
329 AbortTransactionOrFail(self, "dst is null in arraycopy.");
330 return;
331 }
332
333 // Bounds checking.
334 if (UNLIKELY(src_pos < 0) || UNLIKELY(dst_pos < 0) || UNLIKELY(length < 0) ||
335 UNLIKELY(src_pos > src_array->GetLength() - length) ||
336 UNLIKELY(dst_pos > dst_array->GetLength() - length)) {
337 self->ThrowNewExceptionF("Ljava/lang/ArrayIndexOutOfBoundsException;",
338 "src.length=%d srcPos=%d dst.length=%d dstPos=%d length=%d",
339 src_array->GetLength(), src_pos, dst_array->GetLength(), dst_pos,
340 length);
341 AbortTransactionOrFail(self, "Index out of bounds.");
342 return;
343 }
344
345 // Type checking.
346 mirror::Class* src_type = shadow_frame->GetVRegReference(arg_offset)->GetClass()->
347 GetComponentType();
348
349 if (!src_type->IsPrimitive()) {
350 // Check that the second type is not primitive.
351 mirror::Class* trg_type = shadow_frame->GetVRegReference(arg_offset + 2)->GetClass()->
352 GetComponentType();
353 if (trg_type->IsPrimitiveInt()) {
354 AbortTransactionOrFail(self, "Type mismatch in arraycopy: %s vs %s",
355 PrettyDescriptor(src_array->GetClass()->GetComponentType()).c_str(),
356 PrettyDescriptor(dst_array->GetClass()->GetComponentType()).c_str());
357 return;
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700358 }
Andreas Gampe8e6c3fd2015-03-11 18:34:44 -0700359
360 // For simplicity only do this if the component types are the same. Otherwise we have to copy
361 // even more code from the object-array functions.
362 if (src_type != trg_type) {
363 AbortTransactionOrFail(self, "Types not the same in arraycopy: %s vs %s",
364 PrettyDescriptor(src_array->GetClass()->GetComponentType()).c_str(),
365 PrettyDescriptor(dst_array->GetClass()->GetComponentType()).c_str());
366 return;
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700367 }
Andreas Gampe8e6c3fd2015-03-11 18:34:44 -0700368
369 mirror::ObjectArray<mirror::Object>* src = src_array->AsObjectArray<mirror::Object>();
370 mirror::ObjectArray<mirror::Object>* dst = dst_array->AsObjectArray<mirror::Object>();
371 if (src == dst) {
372 // Can overlap, but not have type mismatches.
373 const bool copy_forward = (dst_pos < src_pos) || (dst_pos - src_pos >= length);
374 if (copy_forward) {
375 for (int32_t i = 0; i < length; ++i) {
376 dst->Set(dst_pos + i, src->Get(src_pos + i));
377 }
378 } else {
379 for (int32_t i = 1; i <= length; ++i) {
380 dst->Set(dst_pos + length - i, src->Get(src_pos + length - i));
381 }
382 }
383 } else {
384 // Can't overlap. Would need type checks, but we abort above.
385 for (int32_t i = 0; i < length; ++i) {
386 dst->Set(dst_pos + i, src->Get(src_pos + i));
387 }
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700388 }
Andreas Gampe8e6c3fd2015-03-11 18:34:44 -0700389 } else if (src_type->IsPrimitiveChar()) {
390 PrimitiveArrayCopy<uint16_t>(self, src_array, src_pos, dst_array, dst_pos, length);
391 } else if (src_type->IsPrimitiveInt()) {
392 PrimitiveArrayCopy<int32_t>(self, src_array, src_pos, dst_array, dst_pos, length);
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700393 } else {
Andreas Gampe068b0c02015-03-11 12:44:47 -0700394 AbortTransactionOrFail(self, "Unimplemented System.arraycopy for type '%s'",
Andreas Gampe8e6c3fd2015-03-11 18:34:44 -0700395 PrettyDescriptor(src_type).c_str());
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700396 }
397}
398
Andreas Gampe799681b2015-05-15 19:24:12 -0700399void UnstartedRuntime::UnstartedSystemArraycopyChar(
Mathieu Chartiere401d142015-04-22 13:56:20 -0700400 Thread* self, ShadowFrame* shadow_frame, JValue* result, size_t arg_offset) {
Andreas Gampe799681b2015-05-15 19:24:12 -0700401 // Just forward.
402 UnstartedRuntime::UnstartedSystemArraycopy(self, shadow_frame, result, arg_offset);
403}
404
405void UnstartedRuntime::UnstartedSystemArraycopyInt(
Mathieu Chartiere401d142015-04-22 13:56:20 -0700406 Thread* self, ShadowFrame* shadow_frame, JValue* result, size_t arg_offset) {
Andreas Gampe799681b2015-05-15 19:24:12 -0700407 // Just forward.
408 UnstartedRuntime::UnstartedSystemArraycopy(self, shadow_frame, result, arg_offset);
409}
410
411void UnstartedRuntime::UnstartedThreadLocalGet(
Mathieu Chartiere401d142015-04-22 13:56:20 -0700412 Thread* self, ShadowFrame* shadow_frame, JValue* result, size_t arg_offset ATTRIBUTE_UNUSED) {
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700413 std::string caller(PrettyMethod(shadow_frame->GetLink()->GetMethod()));
414 bool ok = false;
415 if (caller == "java.lang.String java.lang.IntegralToString.convertInt"
416 "(java.lang.AbstractStringBuilder, int)") {
417 // Allocate non-threadlocal buffer.
418 result->SetL(mirror::CharArray::Alloc(self, 11));
419 ok = true;
420 } else if (caller == "java.lang.RealToString java.lang.RealToString.getInstance()") {
421 // Note: RealToString is implemented and used in a different fashion than IntegralToString.
422 // Conversion is done over an actual object of RealToString (the conversion method is an
423 // instance method). This means it is not as clear whether it is correct to return a new
424 // object each time. The caller needs to be inspected by hand to see whether it (incorrectly)
425 // stores the object for later use.
426 // See also b/19548084 for a possible rewrite and bringing it in line with IntegralToString.
427 if (shadow_frame->GetLink()->GetLink() != nullptr) {
428 std::string caller2(PrettyMethod(shadow_frame->GetLink()->GetLink()->GetMethod()));
429 if (caller2 == "java.lang.String java.lang.Double.toString(double)") {
430 // Allocate new object.
431 StackHandleScope<2> hs(self);
432 Handle<mirror::Class> h_real_to_string_class(hs.NewHandle(
433 shadow_frame->GetLink()->GetMethod()->GetDeclaringClass()));
434 Handle<mirror::Object> h_real_to_string_obj(hs.NewHandle(
435 h_real_to_string_class->AllocObject(self)));
436 if (h_real_to_string_obj.Get() != nullptr) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700437 auto* cl = Runtime::Current()->GetClassLinker();
438 ArtMethod* init_method = h_real_to_string_class->FindDirectMethod(
439 "<init>", "()V", cl->GetImagePointerSize());
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700440 if (init_method == nullptr) {
441 h_real_to_string_class->DumpClass(LOG(FATAL), mirror::Class::kDumpClassFullDetail);
442 } else {
443 JValue invoke_result;
444 EnterInterpreterFromInvoke(self, init_method, h_real_to_string_obj.Get(), nullptr,
445 nullptr);
446 if (!self->IsExceptionPending()) {
447 result->SetL(h_real_to_string_obj.Get());
448 ok = true;
449 }
450 }
451 }
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700452 }
453 }
454 }
455
456 if (!ok) {
Andreas Gampe068b0c02015-03-11 12:44:47 -0700457 AbortTransactionOrFail(self, "Could not create RealToString object");
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700458 }
459}
460
Andreas Gampe799681b2015-05-15 19:24:12 -0700461void UnstartedRuntime::UnstartedMathCeil(
Andreas Gampedd9d0552015-03-09 12:57:41 -0700462 Thread* self ATTRIBUTE_UNUSED, ShadowFrame* shadow_frame, JValue* result, size_t arg_offset) {
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700463 double in = shadow_frame->GetVRegDouble(arg_offset);
464 double out;
465 // Special cases:
466 // 1) NaN, infinity, +0, -0 -> out := in. All are guaranteed by cmath.
467 // -1 < in < 0 -> out := -0.
468 if (-1.0 < in && in < 0) {
469 out = -0.0;
470 } else {
471 out = ceil(in);
472 }
473 result->SetD(out);
474}
475
Andreas Gampe799681b2015-05-15 19:24:12 -0700476void UnstartedRuntime::UnstartedObjectHashCode(
Mathieu Chartiere401d142015-04-22 13:56:20 -0700477 Thread* self ATTRIBUTE_UNUSED, ShadowFrame* shadow_frame, JValue* result, size_t arg_offset) {
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700478 mirror::Object* obj = shadow_frame->GetVRegReference(arg_offset);
479 result->SetI(obj->IdentityHashCode());
480}
481
Andreas Gampe799681b2015-05-15 19:24:12 -0700482void UnstartedRuntime::UnstartedDoubleDoubleToRawLongBits(
Andreas Gampedd9d0552015-03-09 12:57:41 -0700483 Thread* self ATTRIBUTE_UNUSED, ShadowFrame* shadow_frame, JValue* result, size_t arg_offset) {
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700484 double in = shadow_frame->GetVRegDouble(arg_offset);
Roland Levillainda4d79b2015-03-24 14:36:11 +0000485 result->SetJ(bit_cast<int64_t, double>(in));
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700486}
487
Andreas Gampedd9d0552015-03-09 12:57:41 -0700488static mirror::Object* GetDexFromDexCache(Thread* self, mirror::DexCache* dex_cache)
Mathieu Chartier90443472015-07-16 20:32:27 -0700489 SHARED_REQUIRES(Locks::mutator_lock_) {
Andreas Gampedd9d0552015-03-09 12:57:41 -0700490 const DexFile* dex_file = dex_cache->GetDexFile();
491 if (dex_file == nullptr) {
492 return nullptr;
493 }
494
495 // Create the direct byte buffer.
496 JNIEnv* env = self->GetJniEnv();
497 DCHECK(env != nullptr);
498 void* address = const_cast<void*>(reinterpret_cast<const void*>(dex_file->Begin()));
Andreas Gampeaacc25d2015-04-01 14:49:06 -0700499 ScopedLocalRef<jobject> byte_buffer(env, env->NewDirectByteBuffer(address, dex_file->Size()));
500 if (byte_buffer.get() == nullptr) {
Andreas Gampedd9d0552015-03-09 12:57:41 -0700501 DCHECK(self->IsExceptionPending());
502 return nullptr;
503 }
504
505 jvalue args[1];
Andreas Gampeaacc25d2015-04-01 14:49:06 -0700506 args[0].l = byte_buffer.get();
507
508 ScopedLocalRef<jobject> dex(env, env->CallStaticObjectMethodA(
509 WellKnownClasses::com_android_dex_Dex,
510 WellKnownClasses::com_android_dex_Dex_create,
511 args));
512
513 return self->DecodeJObject(dex.get());
Andreas Gampedd9d0552015-03-09 12:57:41 -0700514}
515
Andreas Gampe799681b2015-05-15 19:24:12 -0700516void UnstartedRuntime::UnstartedDexCacheGetDexNative(
Mathieu Chartiere401d142015-04-22 13:56:20 -0700517 Thread* self, ShadowFrame* shadow_frame, JValue* result, size_t arg_offset) {
Andreas Gampedd9d0552015-03-09 12:57:41 -0700518 // We will create the Dex object, but the image writer will release it before creating the
519 // art file.
520 mirror::Object* src = shadow_frame->GetVRegReference(arg_offset);
521 bool have_dex = false;
522 if (src != nullptr) {
523 mirror::Object* dex = GetDexFromDexCache(self, reinterpret_cast<mirror::DexCache*>(src));
524 if (dex != nullptr) {
525 have_dex = true;
526 result->SetL(dex);
527 }
528 }
529 if (!have_dex) {
530 self->ClearException();
Sebastien Hertz2fd7e692015-04-02 11:11:19 +0200531 Runtime::Current()->AbortTransactionAndThrowAbortError(self, "Could not create Dex object");
Andreas Gampedd9d0552015-03-09 12:57:41 -0700532 }
533}
534
535static void UnstartedMemoryPeek(
536 Primitive::Type type, ShadowFrame* shadow_frame, JValue* result, size_t arg_offset) {
537 int64_t address = shadow_frame->GetVRegLong(arg_offset);
538 // TODO: Check that this is in the heap somewhere. Otherwise we will segfault instead of
539 // aborting the transaction.
540
541 switch (type) {
542 case Primitive::kPrimByte: {
543 result->SetB(*reinterpret_cast<int8_t*>(static_cast<intptr_t>(address)));
544 return;
545 }
546
547 case Primitive::kPrimShort: {
Andreas Gampe799681b2015-05-15 19:24:12 -0700548 typedef int16_t unaligned_short __attribute__ ((aligned (1)));
549 result->SetS(*reinterpret_cast<unaligned_short*>(static_cast<intptr_t>(address)));
Andreas Gampedd9d0552015-03-09 12:57:41 -0700550 return;
551 }
552
553 case Primitive::kPrimInt: {
Andreas Gampe799681b2015-05-15 19:24:12 -0700554 typedef int32_t unaligned_int __attribute__ ((aligned (1)));
555 result->SetI(*reinterpret_cast<unaligned_int*>(static_cast<intptr_t>(address)));
Andreas Gampedd9d0552015-03-09 12:57:41 -0700556 return;
557 }
558
559 case Primitive::kPrimLong: {
Andreas Gampe799681b2015-05-15 19:24:12 -0700560 typedef int64_t unaligned_long __attribute__ ((aligned (1)));
561 result->SetJ(*reinterpret_cast<unaligned_long*>(static_cast<intptr_t>(address)));
Andreas Gampedd9d0552015-03-09 12:57:41 -0700562 return;
563 }
564
565 case Primitive::kPrimBoolean:
566 case Primitive::kPrimChar:
567 case Primitive::kPrimFloat:
568 case Primitive::kPrimDouble:
569 case Primitive::kPrimVoid:
570 case Primitive::kPrimNot:
571 LOG(FATAL) << "Not in the Memory API: " << type;
572 UNREACHABLE();
573 }
574 LOG(FATAL) << "Should not reach here";
575 UNREACHABLE();
576}
577
Andreas Gampe799681b2015-05-15 19:24:12 -0700578void UnstartedRuntime::UnstartedMemoryPeekByte(
Mathieu Chartiere401d142015-04-22 13:56:20 -0700579 Thread* self ATTRIBUTE_UNUSED, ShadowFrame* shadow_frame, JValue* result, size_t arg_offset) {
Andreas Gampe799681b2015-05-15 19:24:12 -0700580 UnstartedMemoryPeek(Primitive::kPrimByte, shadow_frame, result, arg_offset);
581}
582
583void UnstartedRuntime::UnstartedMemoryPeekShort(
Mathieu Chartiere401d142015-04-22 13:56:20 -0700584 Thread* self ATTRIBUTE_UNUSED, ShadowFrame* shadow_frame, JValue* result, size_t arg_offset) {
Andreas Gampe799681b2015-05-15 19:24:12 -0700585 UnstartedMemoryPeek(Primitive::kPrimShort, shadow_frame, result, arg_offset);
586}
587
588void UnstartedRuntime::UnstartedMemoryPeekInt(
Mathieu Chartiere401d142015-04-22 13:56:20 -0700589 Thread* self ATTRIBUTE_UNUSED, ShadowFrame* shadow_frame, JValue* result, size_t arg_offset) {
Andreas Gampe799681b2015-05-15 19:24:12 -0700590 UnstartedMemoryPeek(Primitive::kPrimInt, shadow_frame, result, arg_offset);
591}
592
593void UnstartedRuntime::UnstartedMemoryPeekLong(
Mathieu Chartiere401d142015-04-22 13:56:20 -0700594 Thread* self ATTRIBUTE_UNUSED, ShadowFrame* shadow_frame, JValue* result, size_t arg_offset) {
Andreas Gampe799681b2015-05-15 19:24:12 -0700595 UnstartedMemoryPeek(Primitive::kPrimLong, shadow_frame, result, arg_offset);
Andreas Gampedd9d0552015-03-09 12:57:41 -0700596}
597
598static void UnstartedMemoryPeekArray(
599 Primitive::Type type, Thread* self, ShadowFrame* shadow_frame, size_t arg_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700600 SHARED_REQUIRES(Locks::mutator_lock_) {
Andreas Gampedd9d0552015-03-09 12:57:41 -0700601 int64_t address_long = shadow_frame->GetVRegLong(arg_offset);
602 mirror::Object* obj = shadow_frame->GetVRegReference(arg_offset + 2);
603 if (obj == nullptr) {
Sebastien Hertz2fd7e692015-04-02 11:11:19 +0200604 Runtime::Current()->AbortTransactionAndThrowAbortError(self, "Null pointer in peekArray");
Andreas Gampedd9d0552015-03-09 12:57:41 -0700605 return;
606 }
607 mirror::Array* array = obj->AsArray();
608
609 int offset = shadow_frame->GetVReg(arg_offset + 3);
610 int count = shadow_frame->GetVReg(arg_offset + 4);
611 if (offset < 0 || offset + count > array->GetLength()) {
612 std::string error_msg(StringPrintf("Array out of bounds in peekArray: %d/%d vs %d",
613 offset, count, array->GetLength()));
Sebastien Hertz2fd7e692015-04-02 11:11:19 +0200614 Runtime::Current()->AbortTransactionAndThrowAbortError(self, error_msg.c_str());
Andreas Gampedd9d0552015-03-09 12:57:41 -0700615 return;
616 }
617
618 switch (type) {
619 case Primitive::kPrimByte: {
620 int8_t* address = reinterpret_cast<int8_t*>(static_cast<intptr_t>(address_long));
621 mirror::ByteArray* byte_array = array->AsByteArray();
622 for (int32_t i = 0; i < count; ++i, ++address) {
623 byte_array->SetWithoutChecks<true>(i + offset, *address);
624 }
625 return;
626 }
627
628 case Primitive::kPrimShort:
629 case Primitive::kPrimInt:
630 case Primitive::kPrimLong:
631 LOG(FATAL) << "Type unimplemented for Memory Array API, should not reach here: " << type;
632 UNREACHABLE();
633
634 case Primitive::kPrimBoolean:
635 case Primitive::kPrimChar:
636 case Primitive::kPrimFloat:
637 case Primitive::kPrimDouble:
638 case Primitive::kPrimVoid:
639 case Primitive::kPrimNot:
640 LOG(FATAL) << "Not in the Memory API: " << type;
641 UNREACHABLE();
642 }
643 LOG(FATAL) << "Should not reach here";
644 UNREACHABLE();
645}
646
Andreas Gampe799681b2015-05-15 19:24:12 -0700647void UnstartedRuntime::UnstartedMemoryPeekByteArray(
Mathieu Chartiere401d142015-04-22 13:56:20 -0700648 Thread* self, ShadowFrame* shadow_frame, JValue* result ATTRIBUTE_UNUSED, size_t arg_offset) {
Andreas Gampe799681b2015-05-15 19:24:12 -0700649 UnstartedMemoryPeekArray(Primitive::kPrimByte, self, shadow_frame, arg_offset);
Andreas Gampedd9d0552015-03-09 12:57:41 -0700650}
651
Andreas Gampef778eb22015-04-13 14:17:09 -0700652// This allows reading security.properties in an unstarted runtime and initialize Security.
Andreas Gampe799681b2015-05-15 19:24:12 -0700653void UnstartedRuntime::UnstartedSecurityGetSecurityPropertiesReader(
Mathieu Chartiere401d142015-04-22 13:56:20 -0700654 Thread* self, ShadowFrame* shadow_frame ATTRIBUTE_UNUSED, JValue* result,
655 size_t arg_offset ATTRIBUTE_UNUSED) {
Andreas Gampef778eb22015-04-13 14:17:09 -0700656 Runtime* runtime = Runtime::Current();
657 const std::vector<const DexFile*>& path = runtime->GetClassLinker()->GetBootClassPath();
658 std::string canonical(DexFile::GetDexCanonicalLocation(path[0]->GetLocation().c_str()));
659 mirror::String* string_data;
660
661 // Use a block to enclose the I/O and MemMap code so buffers are released early.
662 {
663 std::string error_msg;
664 std::unique_ptr<ZipArchive> zip_archive(ZipArchive::Open(canonical.c_str(), &error_msg));
665 if (zip_archive.get() == nullptr) {
666 AbortTransactionOrFail(self, "Could not open zip file %s: %s", canonical.c_str(),
667 error_msg.c_str());
668 return;
669 }
670 std::unique_ptr<ZipEntry> zip_entry(zip_archive->Find("java/security/security.properties",
671 &error_msg));
672 if (zip_entry.get() == nullptr) {
673 AbortTransactionOrFail(self, "Could not find security.properties file in %s: %s",
674 canonical.c_str(), error_msg.c_str());
675 return;
676 }
677 std::unique_ptr<MemMap> map(zip_entry->ExtractToMemMap(canonical.c_str(),
678 "java/security/security.properties",
679 &error_msg));
680 if (map.get() == nullptr) {
681 AbortTransactionOrFail(self, "Could not unzip security.properties file in %s: %s",
682 canonical.c_str(), error_msg.c_str());
683 return;
684 }
685
686 uint32_t length = zip_entry->GetUncompressedLength();
687 std::unique_ptr<char[]> tmp(new char[length + 1]);
688 memcpy(tmp.get(), map->Begin(), length);
689 tmp.get()[length] = 0; // null terminator
690
691 string_data = mirror::String::AllocFromModifiedUtf8(self, tmp.get());
692 }
693
694 if (string_data == nullptr) {
695 AbortTransactionOrFail(self, "Could not create string from file content of %s",
696 canonical.c_str());
697 return;
698 }
699
700 // Create a StringReader.
701 StackHandleScope<3> hs(self);
702 Handle<mirror::String> h_string(hs.NewHandle(string_data));
703
704 Handle<mirror::Class> h_class(hs.NewHandle(
705 runtime->GetClassLinker()->FindClass(self,
706 "Ljava/io/StringReader;",
707 NullHandle<mirror::ClassLoader>())));
708 if (h_class.Get() == nullptr) {
709 AbortTransactionOrFail(self, "Could not find StringReader class");
710 return;
711 }
712
713 if (!runtime->GetClassLinker()->EnsureInitialized(self, h_class, true, true)) {
714 AbortTransactionOrFail(self, "Could not initialize StringReader class");
715 return;
716 }
717
718 Handle<mirror::Object> h_obj(hs.NewHandle(h_class->AllocObject(self)));
719 if (h_obj.Get() == nullptr) {
720 AbortTransactionOrFail(self, "Could not allocate StringReader object");
721 return;
722 }
723
Mathieu Chartiere401d142015-04-22 13:56:20 -0700724 auto* cl = Runtime::Current()->GetClassLinker();
725 ArtMethod* constructor = h_class->FindDeclaredDirectMethod(
726 "<init>", "(Ljava/lang/String;)V", cl->GetImagePointerSize());
Andreas Gampef778eb22015-04-13 14:17:09 -0700727 if (constructor == nullptr) {
728 AbortTransactionOrFail(self, "Could not find StringReader constructor");
729 return;
730 }
731
732 uint32_t args[1];
733 args[0] = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(h_string.Get()));
734 EnterInterpreterFromInvoke(self, constructor, h_obj.Get(), args, nullptr);
735
736 if (self->IsExceptionPending()) {
737 AbortTransactionOrFail(self, "Could not run StringReader constructor");
738 return;
739 }
740
741 result->SetL(h_obj.Get());
742}
743
Kenny Root1c9e61c2015-05-14 15:58:17 -0700744// This allows reading the new style of String objects during compilation.
Andreas Gampe799681b2015-05-15 19:24:12 -0700745void UnstartedRuntime::UnstartedStringGetCharsNoCheck(
Mathieu Chartiere401d142015-04-22 13:56:20 -0700746 Thread* self, ShadowFrame* shadow_frame, JValue* result ATTRIBUTE_UNUSED, size_t arg_offset) {
Kenny Root1c9e61c2015-05-14 15:58:17 -0700747 jint start = shadow_frame->GetVReg(arg_offset + 1);
748 jint end = shadow_frame->GetVReg(arg_offset + 2);
749 jint index = shadow_frame->GetVReg(arg_offset + 4);
750 mirror::String* string = shadow_frame->GetVRegReference(arg_offset)->AsString();
751 if (string == nullptr) {
752 AbortTransactionOrFail(self, "String.getCharsNoCheck with null object");
753 return;
754 }
Kenny Root57f91e82015-05-14 15:58:17 -0700755 DCHECK_GE(start, 0);
756 DCHECK_GE(end, string->GetLength());
Kenny Root1c9e61c2015-05-14 15:58:17 -0700757 StackHandleScope<1> hs(self);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700758 Handle<mirror::CharArray> h_char_array(
759 hs.NewHandle(shadow_frame->GetVRegReference(arg_offset + 3)->AsCharArray()));
Kenny Root57f91e82015-05-14 15:58:17 -0700760 DCHECK_LE(index, h_char_array->GetLength());
761 DCHECK_LE(end - start, h_char_array->GetLength() - index);
Kenny Root1c9e61c2015-05-14 15:58:17 -0700762 string->GetChars(start, end, h_char_array, index);
763}
764
765// This allows reading chars from the new style of String objects during compilation.
Andreas Gampe799681b2015-05-15 19:24:12 -0700766void UnstartedRuntime::UnstartedStringCharAt(
Mathieu Chartiere401d142015-04-22 13:56:20 -0700767 Thread* self, ShadowFrame* shadow_frame, JValue* result, size_t arg_offset) {
Kenny Root1c9e61c2015-05-14 15:58:17 -0700768 jint index = shadow_frame->GetVReg(arg_offset + 1);
769 mirror::String* string = shadow_frame->GetVRegReference(arg_offset)->AsString();
770 if (string == nullptr) {
771 AbortTransactionOrFail(self, "String.charAt with null object");
772 return;
773 }
774 result->SetC(string->CharAt(index));
775}
776
Kenny Root57f91e82015-05-14 15:58:17 -0700777// This allows setting chars from the new style of String objects during compilation.
Andreas Gampe799681b2015-05-15 19:24:12 -0700778void UnstartedRuntime::UnstartedStringSetCharAt(
Mathieu Chartiere401d142015-04-22 13:56:20 -0700779 Thread* self, ShadowFrame* shadow_frame, JValue* result ATTRIBUTE_UNUSED, size_t arg_offset) {
Kenny Root57f91e82015-05-14 15:58:17 -0700780 jint index = shadow_frame->GetVReg(arg_offset + 1);
781 jchar c = shadow_frame->GetVReg(arg_offset + 2);
782 mirror::String* string = shadow_frame->GetVRegReference(arg_offset)->AsString();
783 if (string == nullptr) {
784 AbortTransactionOrFail(self, "String.setCharAt with null object");
785 return;
786 }
787 string->SetCharAt(index, c);
788}
789
Kenny Root1c9e61c2015-05-14 15:58:17 -0700790// This allows creating the new style of String objects during compilation.
Andreas Gampe799681b2015-05-15 19:24:12 -0700791void UnstartedRuntime::UnstartedStringFactoryNewStringFromChars(
Mathieu Chartiere401d142015-04-22 13:56:20 -0700792 Thread* self, ShadowFrame* shadow_frame, JValue* result, size_t arg_offset) {
Kenny Root1c9e61c2015-05-14 15:58:17 -0700793 jint offset = shadow_frame->GetVReg(arg_offset);
794 jint char_count = shadow_frame->GetVReg(arg_offset + 1);
795 DCHECK_GE(char_count, 0);
796 StackHandleScope<1> hs(self);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700797 Handle<mirror::CharArray> h_char_array(
798 hs.NewHandle(shadow_frame->GetVRegReference(arg_offset + 2)->AsCharArray()));
Kenny Root1c9e61c2015-05-14 15:58:17 -0700799 Runtime* runtime = Runtime::Current();
800 gc::AllocatorType allocator = runtime->GetHeap()->GetCurrentAllocator();
801 result->SetL(mirror::String::AllocFromCharArray<true>(self, char_count, h_char_array, offset, allocator));
802}
803
804// This allows creating the new style of String objects during compilation.
Andreas Gampe799681b2015-05-15 19:24:12 -0700805void UnstartedRuntime::UnstartedStringFactoryNewStringFromString(
Mathieu Chartiere401d142015-04-22 13:56:20 -0700806 Thread* self, ShadowFrame* shadow_frame, JValue* result, size_t arg_offset) {
Kenny Root57f91e82015-05-14 15:58:17 -0700807 mirror::String* to_copy = shadow_frame->GetVRegReference(arg_offset)->AsString();
808 if (to_copy == nullptr) {
809 AbortTransactionOrFail(self, "StringFactory.newStringFromString with null object");
810 return;
811 }
812 StackHandleScope<1> hs(self);
813 Handle<mirror::String> h_string(hs.NewHandle(to_copy));
814 Runtime* runtime = Runtime::Current();
815 gc::AllocatorType allocator = runtime->GetHeap()->GetCurrentAllocator();
816 result->SetL(mirror::String::AllocFromString<true>(self, h_string->GetLength(), h_string, 0,
817 allocator));
818}
819
Andreas Gampe799681b2015-05-15 19:24:12 -0700820void UnstartedRuntime::UnstartedStringFastSubstring(
Mathieu Chartiere401d142015-04-22 13:56:20 -0700821 Thread* self, ShadowFrame* shadow_frame, JValue* result, size_t arg_offset) {
Kenny Root1c9e61c2015-05-14 15:58:17 -0700822 jint start = shadow_frame->GetVReg(arg_offset + 1);
823 jint length = shadow_frame->GetVReg(arg_offset + 2);
Kenny Root57f91e82015-05-14 15:58:17 -0700824 DCHECK_GE(start, 0);
Kenny Root1c9e61c2015-05-14 15:58:17 -0700825 DCHECK_GE(length, 0);
826 StackHandleScope<1> hs(self);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700827 Handle<mirror::String> h_string(
828 hs.NewHandle(shadow_frame->GetVRegReference(arg_offset)->AsString()));
Kenny Root57f91e82015-05-14 15:58:17 -0700829 DCHECK_LE(start, h_string->GetLength());
830 DCHECK_LE(start + length, h_string->GetLength());
Kenny Root1c9e61c2015-05-14 15:58:17 -0700831 Runtime* runtime = Runtime::Current();
832 gc::AllocatorType allocator = runtime->GetHeap()->GetCurrentAllocator();
833 result->SetL(mirror::String::AllocFromString<true>(self, length, h_string, start, allocator));
834}
835
Kenny Root57f91e82015-05-14 15:58:17 -0700836// This allows getting the char array for new style of String objects during compilation.
Andreas Gampe799681b2015-05-15 19:24:12 -0700837void UnstartedRuntime::UnstartedStringToCharArray(
Kenny Root57f91e82015-05-14 15:58:17 -0700838 Thread* self, ShadowFrame* shadow_frame, JValue* result, size_t arg_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700839 SHARED_REQUIRES(Locks::mutator_lock_) {
Kenny Root57f91e82015-05-14 15:58:17 -0700840 mirror::String* string = shadow_frame->GetVRegReference(arg_offset)->AsString();
841 if (string == nullptr) {
842 AbortTransactionOrFail(self, "String.charAt with null object");
843 return;
844 }
845 result->SetL(string->ToCharArray(self));
846}
847
Mathieu Chartiere401d142015-04-22 13:56:20 -0700848void UnstartedRuntime::UnstartedJNIVMRuntimeNewUnpaddedArray(
849 Thread* self, ArtMethod* method ATTRIBUTE_UNUSED, mirror::Object* receiver ATTRIBUTE_UNUSED,
850 uint32_t* args, JValue* result) {
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700851 int32_t length = args[1];
852 DCHECK_GE(length, 0);
853 mirror::Class* element_class = reinterpret_cast<mirror::Object*>(args[0])->AsClass();
854 Runtime* runtime = Runtime::Current();
855 mirror::Class* array_class = runtime->GetClassLinker()->FindArrayClass(self, &element_class);
856 DCHECK(array_class != nullptr);
857 gc::AllocatorType allocator = runtime->GetHeap()->GetCurrentAllocator();
858 result->SetL(mirror::Array::Alloc<true, true>(self, array_class, length,
859 array_class->GetComponentSizeShift(), allocator));
860}
861
Mathieu Chartiere401d142015-04-22 13:56:20 -0700862void UnstartedRuntime::UnstartedJNIVMStackGetCallingClassLoader(
863 Thread* self ATTRIBUTE_UNUSED, ArtMethod* method ATTRIBUTE_UNUSED,
864 mirror::Object* receiver ATTRIBUTE_UNUSED, uint32_t* args ATTRIBUTE_UNUSED, JValue* result) {
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700865 result->SetL(nullptr);
866}
867
Mathieu Chartiere401d142015-04-22 13:56:20 -0700868void UnstartedRuntime::UnstartedJNIVMStackGetStackClass2(
869 Thread* self, ArtMethod* method ATTRIBUTE_UNUSED, mirror::Object* receiver ATTRIBUTE_UNUSED,
870 uint32_t* args ATTRIBUTE_UNUSED, JValue* result) {
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700871 NthCallerVisitor visitor(self, 3);
872 visitor.WalkStack();
873 if (visitor.caller != nullptr) {
874 result->SetL(visitor.caller->GetDeclaringClass());
875 }
876}
877
Mathieu Chartiere401d142015-04-22 13:56:20 -0700878void UnstartedRuntime::UnstartedJNIMathLog(
879 Thread* self ATTRIBUTE_UNUSED, ArtMethod* method ATTRIBUTE_UNUSED,
880 mirror::Object* receiver ATTRIBUTE_UNUSED, uint32_t* args, JValue* result) {
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700881 JValue value;
882 value.SetJ((static_cast<uint64_t>(args[1]) << 32) | args[0]);
883 result->SetD(log(value.GetD()));
884}
885
Mathieu Chartiere401d142015-04-22 13:56:20 -0700886void UnstartedRuntime::UnstartedJNIMathExp(
887 Thread* self ATTRIBUTE_UNUSED, ArtMethod* method ATTRIBUTE_UNUSED,
888 mirror::Object* receiver ATTRIBUTE_UNUSED, uint32_t* args, JValue* result) {
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700889 JValue value;
890 value.SetJ((static_cast<uint64_t>(args[1]) << 32) | args[0]);
891 result->SetD(exp(value.GetD()));
892}
893
Mathieu Chartiere401d142015-04-22 13:56:20 -0700894void UnstartedRuntime::UnstartedJNIClassGetNameNative(
895 Thread* self, ArtMethod* method ATTRIBUTE_UNUSED, mirror::Object* receiver,
896 uint32_t* args ATTRIBUTE_UNUSED, JValue* result) {
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700897 StackHandleScope<1> hs(self);
898 result->SetL(mirror::Class::ComputeName(hs.NewHandle(receiver->AsClass())));
899}
900
Mathieu Chartiere401d142015-04-22 13:56:20 -0700901void UnstartedRuntime::UnstartedJNIFloatFloatToRawIntBits(
902 Thread* self ATTRIBUTE_UNUSED, ArtMethod* method ATTRIBUTE_UNUSED,
903 mirror::Object* receiver ATTRIBUTE_UNUSED, uint32_t* args, JValue* result) {
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700904 result->SetI(args[0]);
905}
906
Mathieu Chartiere401d142015-04-22 13:56:20 -0700907void UnstartedRuntime::UnstartedJNIFloatIntBitsToFloat(
908 Thread* self ATTRIBUTE_UNUSED, ArtMethod* method ATTRIBUTE_UNUSED,
909 mirror::Object* receiver ATTRIBUTE_UNUSED, uint32_t* args, JValue* result) {
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700910 result->SetI(args[0]);
911}
912
Mathieu Chartiere401d142015-04-22 13:56:20 -0700913void UnstartedRuntime::UnstartedJNIObjectInternalClone(
914 Thread* self, ArtMethod* method ATTRIBUTE_UNUSED, mirror::Object* receiver,
915 uint32_t* args ATTRIBUTE_UNUSED, JValue* result) {
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700916 result->SetL(receiver->Clone(self));
917}
918
Mathieu Chartiere401d142015-04-22 13:56:20 -0700919void UnstartedRuntime::UnstartedJNIObjectNotifyAll(
920 Thread* self, ArtMethod* method ATTRIBUTE_UNUSED, mirror::Object* receiver,
921 uint32_t* args ATTRIBUTE_UNUSED, JValue* result ATTRIBUTE_UNUSED) {
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700922 receiver->NotifyAll(self);
923}
924
Mathieu Chartiere401d142015-04-22 13:56:20 -0700925void UnstartedRuntime::UnstartedJNIStringCompareTo(
926 Thread* self, ArtMethod* method ATTRIBUTE_UNUSED, mirror::Object* receiver, uint32_t* args,
927 JValue* result) {
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700928 mirror::String* rhs = reinterpret_cast<mirror::Object*>(args[0])->AsString();
929 if (rhs == nullptr) {
Andreas Gampe068b0c02015-03-11 12:44:47 -0700930 AbortTransactionOrFail(self, "String.compareTo with null object");
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700931 }
932 result->SetI(receiver->AsString()->CompareTo(rhs));
933}
934
Mathieu Chartiere401d142015-04-22 13:56:20 -0700935void UnstartedRuntime::UnstartedJNIStringIntern(
936 Thread* self ATTRIBUTE_UNUSED, ArtMethod* method ATTRIBUTE_UNUSED, mirror::Object* receiver,
937 uint32_t* args ATTRIBUTE_UNUSED, JValue* result) {
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700938 result->SetL(receiver->AsString()->Intern());
939}
940
Mathieu Chartiere401d142015-04-22 13:56:20 -0700941void UnstartedRuntime::UnstartedJNIStringFastIndexOf(
942 Thread* self ATTRIBUTE_UNUSED, ArtMethod* method ATTRIBUTE_UNUSED, mirror::Object* receiver,
943 uint32_t* args, JValue* result) {
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700944 result->SetI(receiver->AsString()->FastIndexOf(args[0], args[1]));
945}
946
Mathieu Chartiere401d142015-04-22 13:56:20 -0700947void UnstartedRuntime::UnstartedJNIArrayCreateMultiArray(
948 Thread* self, ArtMethod* method ATTRIBUTE_UNUSED, mirror::Object* receiver ATTRIBUTE_UNUSED,
949 uint32_t* args, JValue* result) {
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700950 StackHandleScope<2> hs(self);
951 auto h_class(hs.NewHandle(reinterpret_cast<mirror::Class*>(args[0])->AsClass()));
952 auto h_dimensions(hs.NewHandle(reinterpret_cast<mirror::IntArray*>(args[1])->AsIntArray()));
953 result->SetL(mirror::Array::CreateMultiArray(self, h_class, h_dimensions));
954}
955
Mathieu Chartiere401d142015-04-22 13:56:20 -0700956void UnstartedRuntime::UnstartedJNIArrayCreateObjectArray(
957 Thread* self, ArtMethod* method ATTRIBUTE_UNUSED, mirror::Object* receiver ATTRIBUTE_UNUSED,
958 uint32_t* args, JValue* result) {
Andreas Gampee598e042015-04-10 14:57:10 -0700959 int32_t length = static_cast<int32_t>(args[1]);
960 if (length < 0) {
961 ThrowNegativeArraySizeException(length);
962 return;
963 }
964 mirror::Class* element_class = reinterpret_cast<mirror::Class*>(args[0])->AsClass();
965 Runtime* runtime = Runtime::Current();
966 ClassLinker* class_linker = runtime->GetClassLinker();
967 mirror::Class* array_class = class_linker->FindArrayClass(self, &element_class);
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700968 if (UNLIKELY(array_class == nullptr)) {
Andreas Gampee598e042015-04-10 14:57:10 -0700969 CHECK(self->IsExceptionPending());
970 return;
971 }
972 DCHECK(array_class->IsObjectArrayClass());
973 mirror::Array* new_array = mirror::ObjectArray<mirror::Object*>::Alloc(
974 self, array_class, length, runtime->GetHeap()->GetCurrentAllocator());
975 result->SetL(new_array);
976}
977
Mathieu Chartiere401d142015-04-22 13:56:20 -0700978void UnstartedRuntime::UnstartedJNIThrowableNativeFillInStackTrace(
979 Thread* self, ArtMethod* method ATTRIBUTE_UNUSED, mirror::Object* receiver ATTRIBUTE_UNUSED,
980 uint32_t* args ATTRIBUTE_UNUSED, JValue* result) {
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700981 ScopedObjectAccessUnchecked soa(self);
982 if (Runtime::Current()->IsActiveTransaction()) {
983 result->SetL(soa.Decode<mirror::Object*>(self->CreateInternalStackTrace<true>(soa)));
984 } else {
985 result->SetL(soa.Decode<mirror::Object*>(self->CreateInternalStackTrace<false>(soa)));
986 }
987}
988
Mathieu Chartiere401d142015-04-22 13:56:20 -0700989void UnstartedRuntime::UnstartedJNISystemIdentityHashCode(
990 Thread* self ATTRIBUTE_UNUSED, ArtMethod* method ATTRIBUTE_UNUSED,
991 mirror::Object* receiver ATTRIBUTE_UNUSED, uint32_t* args, JValue* result) {
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700992 mirror::Object* obj = reinterpret_cast<mirror::Object*>(args[0]);
993 result->SetI((obj != nullptr) ? obj->IdentityHashCode() : 0);
994}
995
Mathieu Chartiere401d142015-04-22 13:56:20 -0700996void UnstartedRuntime::UnstartedJNIByteOrderIsLittleEndian(
997 Thread* self ATTRIBUTE_UNUSED, ArtMethod* method ATTRIBUTE_UNUSED,
998 mirror::Object* receiver ATTRIBUTE_UNUSED, uint32_t* args ATTRIBUTE_UNUSED, JValue* result) {
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700999 result->SetZ(JNI_TRUE);
1000}
1001
Mathieu Chartiere401d142015-04-22 13:56:20 -07001002void UnstartedRuntime::UnstartedJNIUnsafeCompareAndSwapInt(
1003 Thread* self ATTRIBUTE_UNUSED, ArtMethod* method ATTRIBUTE_UNUSED,
1004 mirror::Object* receiver ATTRIBUTE_UNUSED, uint32_t* args, JValue* result) {
Andreas Gampe2969bcd2015-03-09 12:57:41 -07001005 mirror::Object* obj = reinterpret_cast<mirror::Object*>(args[0]);
1006 jlong offset = (static_cast<uint64_t>(args[2]) << 32) | args[1];
1007 jint expectedValue = args[3];
1008 jint newValue = args[4];
1009 bool success;
1010 if (Runtime::Current()->IsActiveTransaction()) {
1011 success = obj->CasFieldStrongSequentiallyConsistent32<true>(MemberOffset(offset),
1012 expectedValue, newValue);
1013 } else {
1014 success = obj->CasFieldStrongSequentiallyConsistent32<false>(MemberOffset(offset),
1015 expectedValue, newValue);
1016 }
1017 result->SetZ(success ? JNI_TRUE : JNI_FALSE);
1018}
1019
Mathieu Chartiere401d142015-04-22 13:56:20 -07001020void UnstartedRuntime::UnstartedJNIUnsafePutObject(
1021 Thread* self ATTRIBUTE_UNUSED, ArtMethod* method ATTRIBUTE_UNUSED,
1022 mirror::Object* receiver ATTRIBUTE_UNUSED, uint32_t* args, JValue* result ATTRIBUTE_UNUSED) {
Andreas Gampe2969bcd2015-03-09 12:57:41 -07001023 mirror::Object* obj = reinterpret_cast<mirror::Object*>(args[0]);
1024 jlong offset = (static_cast<uint64_t>(args[2]) << 32) | args[1];
1025 mirror::Object* newValue = reinterpret_cast<mirror::Object*>(args[3]);
1026 if (Runtime::Current()->IsActiveTransaction()) {
1027 obj->SetFieldObject<true>(MemberOffset(offset), newValue);
1028 } else {
1029 obj->SetFieldObject<false>(MemberOffset(offset), newValue);
1030 }
1031}
1032
Andreas Gampe799681b2015-05-15 19:24:12 -07001033void UnstartedRuntime::UnstartedJNIUnsafeGetArrayBaseOffsetForComponentType(
Mathieu Chartiere401d142015-04-22 13:56:20 -07001034 Thread* self ATTRIBUTE_UNUSED, ArtMethod* method ATTRIBUTE_UNUSED,
1035 mirror::Object* receiver ATTRIBUTE_UNUSED, uint32_t* args, JValue* result) {
Andreas Gampe2969bcd2015-03-09 12:57:41 -07001036 mirror::Class* component = reinterpret_cast<mirror::Object*>(args[0])->AsClass();
1037 Primitive::Type primitive_type = component->GetPrimitiveType();
1038 result->SetI(mirror::Array::DataOffset(Primitive::ComponentSize(primitive_type)).Int32Value());
1039}
1040
Andreas Gampe799681b2015-05-15 19:24:12 -07001041void UnstartedRuntime::UnstartedJNIUnsafeGetArrayIndexScaleForComponentType(
Mathieu Chartiere401d142015-04-22 13:56:20 -07001042 Thread* self ATTRIBUTE_UNUSED, ArtMethod* method ATTRIBUTE_UNUSED,
1043 mirror::Object* receiver ATTRIBUTE_UNUSED, uint32_t* args, JValue* result) {
Andreas Gampe2969bcd2015-03-09 12:57:41 -07001044 mirror::Class* component = reinterpret_cast<mirror::Object*>(args[0])->AsClass();
1045 Primitive::Type primitive_type = component->GetPrimitiveType();
1046 result->SetI(Primitive::ComponentSize(primitive_type));
1047}
1048
Andreas Gampedd9d0552015-03-09 12:57:41 -07001049typedef void (*InvokeHandler)(Thread* self, ShadowFrame* shadow_frame, JValue* result,
Andreas Gampe2969bcd2015-03-09 12:57:41 -07001050 size_t arg_size);
1051
Mathieu Chartiere401d142015-04-22 13:56:20 -07001052typedef void (*JNIHandler)(Thread* self, ArtMethod* method, mirror::Object* receiver,
Andreas Gampe2969bcd2015-03-09 12:57:41 -07001053 uint32_t* args, JValue* result);
1054
1055static bool tables_initialized_ = false;
1056static std::unordered_map<std::string, InvokeHandler> invoke_handlers_;
1057static std::unordered_map<std::string, JNIHandler> jni_handlers_;
1058
Andreas Gampe799681b2015-05-15 19:24:12 -07001059void UnstartedRuntime::InitializeInvokeHandlers() {
1060#define UNSTARTED_DIRECT(ShortName, Sig) \
1061 invoke_handlers_.insert(std::make_pair(Sig, & UnstartedRuntime::Unstarted ## ShortName));
1062#include "unstarted_runtime_list.h"
1063 UNSTARTED_RUNTIME_DIRECT_LIST(UNSTARTED_DIRECT)
1064#undef UNSTARTED_RUNTIME_DIRECT_LIST
1065#undef UNSTARTED_RUNTIME_JNI_LIST
1066#undef UNSTARTED_DIRECT
Andreas Gampe2969bcd2015-03-09 12:57:41 -07001067}
1068
Andreas Gampe799681b2015-05-15 19:24:12 -07001069void UnstartedRuntime::InitializeJNIHandlers() {
1070#define UNSTARTED_JNI(ShortName, Sig) \
1071 jni_handlers_.insert(std::make_pair(Sig, & UnstartedRuntime::UnstartedJNI ## ShortName));
1072#include "unstarted_runtime_list.h"
1073 UNSTARTED_RUNTIME_JNI_LIST(UNSTARTED_JNI)
1074#undef UNSTARTED_RUNTIME_DIRECT_LIST
1075#undef UNSTARTED_RUNTIME_JNI_LIST
1076#undef UNSTARTED_JNI
Andreas Gampe2969bcd2015-03-09 12:57:41 -07001077}
1078
Andreas Gampe799681b2015-05-15 19:24:12 -07001079void UnstartedRuntime::Initialize() {
Andreas Gampe2969bcd2015-03-09 12:57:41 -07001080 CHECK(!tables_initialized_);
1081
Andreas Gampe799681b2015-05-15 19:24:12 -07001082 InitializeInvokeHandlers();
1083 InitializeJNIHandlers();
Andreas Gampe2969bcd2015-03-09 12:57:41 -07001084
1085 tables_initialized_ = true;
1086}
1087
Andreas Gampe799681b2015-05-15 19:24:12 -07001088void UnstartedRuntime::Invoke(Thread* self, const DexFile::CodeItem* code_item,
1089 ShadowFrame* shadow_frame, JValue* result, size_t arg_offset) {
Andreas Gampe2969bcd2015-03-09 12:57:41 -07001090 // In a runtime that's not started we intercept certain methods to avoid complicated dependency
1091 // problems in core libraries.
1092 CHECK(tables_initialized_);
1093
1094 std::string name(PrettyMethod(shadow_frame->GetMethod()));
1095 const auto& iter = invoke_handlers_.find(name);
1096 if (iter != invoke_handlers_.end()) {
Kenny Root57f91e82015-05-14 15:58:17 -07001097 // Clear out the result in case it's not zeroed out.
1098 result->SetL(0);
Andreas Gampe2969bcd2015-03-09 12:57:41 -07001099 (*iter->second)(self, shadow_frame, result, arg_offset);
1100 } else {
1101 // Not special, continue with regular interpreter execution.
1102 artInterpreterToInterpreterBridge(self, code_item, shadow_frame, result);
1103 }
1104}
1105
1106// Hand select a number of methods to be run in a not yet started runtime without using JNI.
Mathieu Chartiere401d142015-04-22 13:56:20 -07001107void UnstartedRuntime::Jni(Thread* self, ArtMethod* method, mirror::Object* receiver,
Andreas Gampe799681b2015-05-15 19:24:12 -07001108 uint32_t* args, JValue* result) {
Andreas Gampe2969bcd2015-03-09 12:57:41 -07001109 std::string name(PrettyMethod(method));
1110 const auto& iter = jni_handlers_.find(name);
1111 if (iter != jni_handlers_.end()) {
Kenny Root57f91e82015-05-14 15:58:17 -07001112 // Clear out the result in case it's not zeroed out.
1113 result->SetL(0);
Andreas Gampe2969bcd2015-03-09 12:57:41 -07001114 (*iter->second)(self, method, receiver, args, result);
1115 } else if (Runtime::Current()->IsActiveTransaction()) {
Sebastien Hertz45b15972015-04-03 16:07:05 +02001116 AbortTransactionF(self, "Attempt to invoke native method in non-started runtime: %s",
1117 name.c_str());
Andreas Gampe2969bcd2015-03-09 12:57:41 -07001118 } else {
1119 LOG(FATAL) << "Calling native method " << PrettyMethod(method) << " in an unstarted "
1120 "non-transactional runtime";
1121 }
1122}
1123
1124} // namespace interpreter
1125} // namespace art