blob: a5ade6f30fe7d344f5c8b71a9dae50411baf45cc [file] [log] [blame]
Elliott Hughes7ede61e2011-09-14 18:18:06 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Andreas Gampe277ccbd2014-11-03 21:36:10 -080017#include "dalvik_system_VMRuntime.h"
18
Bilyan Borisovbb661c02016-04-04 16:27:32 +010019#ifdef ART_TARGET_ANDROID
Hiroshi Yamauchid7f03392017-03-29 14:47:49 -070020#include <sys/resource.h>
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070021#include <sys/time.h>
Dmitriy Ivanov15efde22015-05-22 18:03:34 -070022extern "C" void android_set_application_target_sdk_version(uint32_t version);
23#endif
Elliott Hugheseac76672012-05-24 21:56:51 -070024#include <limits.h>
Andreas Gampe373a9b52017-10-18 09:01:57 -070025#include "nativehelper/scoped_utf_chars.h"
Elliott Hugheseac76672012-05-24 21:56:51 -070026
Andreas Gampe46ee31b2016-12-14 10:11:49 -080027#include "android-base/stringprintf.h"
28
Ian Rogersd582fa42014-11-05 23:46:43 -080029#include "arch/instruction_set.h"
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070030#include "art_method-inl.h"
Andreas Gampe542451c2016-07-26 09:02:02 -070031#include "base/enums.h"
Ian Rogers98379392014-02-24 16:53:16 -080032#include "class_linker-inl.h"
Ian Rogers62d6c772013-02-27 08:32:07 -080033#include "common_throws.h"
Elliott Hughesf6a1e1e2011-10-25 16:28:04 -070034#include "debugger.h"
David Sehr9e734c72018-01-04 17:56:19 -080035#include "dex/dex_file-inl.h"
36#include "dex/dex_file_types.h"
Brian Carlstrome8104522013-10-15 21:56:36 -070037#include "gc/accounting/card_table-inl.h"
Ian Rogers1d54e732013-05-02 21:10:01 -070038#include "gc/allocator/dlmalloc.h"
Mathieu Chartier82353312013-07-18 10:47:51 -070039#include "gc/heap.h"
Ian Rogers1d54e732013-05-02 21:10:01 -070040#include "gc/space/dlmalloc_space.h"
Brian Carlstrom31d8f522014-09-29 11:22:54 -070041#include "gc/space/image_space.h"
Mathieu Chartiera5eae692014-12-17 17:56:03 -080042#include "gc/task_processor.h"
Brian Carlstrome8104522013-10-15 21:56:36 -070043#include "intern_table.h"
Andreas Gampec15a2f42017-04-21 12:09:39 -070044#include "java_vm_ext.h"
Elliott Hughes7ede61e2011-09-14 18:18:06 -070045#include "jni_internal.h"
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070046#include "mirror/class-inl.h"
Brian Carlstrome8104522013-10-15 21:56:36 -070047#include "mirror/dex_cache-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080048#include "mirror/object-inl.h"
Andreas Gampe87583b32017-05-25 11:22:18 -070049#include "native_util.h"
Steven Morelande431e272017-07-18 16:53:49 -070050#include "nativehelper/jni_macros.h"
Andreas Gampe373a9b52017-10-18 09:01:57 -070051#include "nativehelper/scoped_local_ref.h"
Mathieu Chartier893263b2014-03-04 11:07:42 -080052#include "runtime.h"
Mathieu Chartier0795f232016-09-27 18:43:30 -070053#include "scoped_fast_native_object_access-inl.h"
54#include "scoped_thread_state_change-inl.h"
Elliott Hughes7ede61e2011-09-14 18:18:06 -070055#include "thread.h"
Elliott Hughes88c5c352012-03-15 18:49:48 -070056#include "thread_list.h"
Andreas Gamped0332e02017-09-22 19:23:38 -070057#include "well_known_classes.h"
Andreas Gampe277ccbd2014-11-03 21:36:10 -080058
Elliott Hughes7ede61e2011-09-14 18:18:06 -070059namespace art {
60
Andreas Gampe46ee31b2016-12-14 10:11:49 -080061using android::base::StringPrintf;
62
Elliott Hughes0512f022012-03-15 22:10:52 -070063static jfloat VMRuntime_getTargetHeapUtilization(JNIEnv*, jobject) {
Elliott Hughesb3bd5f02012-03-08 21:05:27 -080064 return Runtime::Current()->GetHeap()->GetTargetHeapUtilization();
Elliott Hughes7ede61e2011-09-14 18:18:06 -070065}
66
Elliott Hughes0512f022012-03-15 22:10:52 -070067static void VMRuntime_nativeSetTargetHeapUtilization(JNIEnv*, jobject, jfloat target) {
Elliott Hughesb3bd5f02012-03-08 21:05:27 -080068 Runtime::Current()->GetHeap()->SetTargetHeapUtilization(target);
Elliott Hughes7ede61e2011-09-14 18:18:06 -070069}
70
Elliott Hughes0512f022012-03-15 22:10:52 -070071static void VMRuntime_startJitCompilation(JNIEnv*, jobject) {
Elliott Hughes7ede61e2011-09-14 18:18:06 -070072}
73
Elliott Hughes0512f022012-03-15 22:10:52 -070074static void VMRuntime_disableJitCompilation(JNIEnv*, jobject) {
Elliott Hughes7ede61e2011-09-14 18:18:06 -070075}
76
David Brazdil4384b102018-01-23 16:10:36 +000077static jboolean VMRuntime_hasUsedHiddenApi(JNIEnv*, jobject) {
78 return Runtime::Current()->HasPendingHiddenApiWarning() ? JNI_TRUE : JNI_FALSE;
79}
80
Mathew Inwood7d74ef52018-03-16 14:18:33 +000081static void VMRuntime_setHiddenApiExemptions(JNIEnv* env,
82 jclass,
83 jobjectArray exemptions) {
84 std::vector<std::string> exemptions_vec;
85 int exemptions_length = env->GetArrayLength(exemptions);
86 for (int i = 0; i < exemptions_length; i++) {
87 jstring exemption = reinterpret_cast<jstring>(env->GetObjectArrayElement(exemptions, i));
88 const char* raw_exemption = env->GetStringUTFChars(exemption, nullptr);
89 exemptions_vec.push_back(raw_exemption);
90 env->ReleaseStringUTFChars(exemption, raw_exemption);
91 }
92
93 Runtime::Current()->SetHiddenApiExemptions(exemptions_vec);
94}
95
Mathieu Chartier590fee92013-09-13 13:46:47 -070096static jobject VMRuntime_newNonMovableArray(JNIEnv* env, jobject, jclass javaElementClass,
Brian Carlstrome8104522013-10-15 21:56:36 -070097 jint length) {
Ian Rogers1eb512d2013-10-18 15:42:20 -070098 ScopedFastNativeObjectAccess soa(env);
Ian Rogersf9c612f2014-02-27 10:58:17 -080099 if (UNLIKELY(length < 0)) {
100 ThrowNegativeArraySizeException(length);
101 return nullptr;
102 }
Mathieu Chartierbc5a7952016-10-17 15:46:31 -0700103 ObjPtr<mirror::Class> element_class = soa.Decode<mirror::Class>(javaElementClass);
Ian Rogers98379392014-02-24 16:53:16 -0800104 if (UNLIKELY(element_class == nullptr)) {
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +0000105 ThrowNullPointerException("element class == null");
Ian Rogers98379392014-02-24 16:53:16 -0800106 return nullptr;
Elliott Hughes7ede61e2011-09-14 18:18:06 -0700107 }
Ian Rogers98379392014-02-24 16:53:16 -0800108 Runtime* runtime = Runtime::Current();
Mathieu Chartierbc5a7952016-10-17 15:46:31 -0700109 ObjPtr<mirror::Class> array_class =
Mathieu Chartierb74cd292014-05-29 14:31:33 -0700110 runtime->GetClassLinker()->FindArrayClass(soa.Self(), &element_class);
Ian Rogers98379392014-02-24 16:53:16 -0800111 if (UNLIKELY(array_class == nullptr)) {
112 return nullptr;
113 }
114 gc::AllocatorType allocator = runtime->GetHeap()->GetCurrentNonMovingAllocator();
Mathieu Chartierbc5a7952016-10-17 15:46:31 -0700115 ObjPtr<mirror::Array> result = mirror::Array::Alloc<true>(soa.Self(),
116 array_class,
117 length,
118 array_class->GetComponentSizeShift(),
119 allocator);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700120 return soa.AddLocalReference<jobject>(result);
Elliott Hughes7ede61e2011-09-14 18:18:06 -0700121}
122
Ian Rogersf9c612f2014-02-27 10:58:17 -0800123static jobject VMRuntime_newUnpaddedArray(JNIEnv* env, jobject, jclass javaElementClass,
124 jint length) {
125 ScopedFastNativeObjectAccess soa(env);
126 if (UNLIKELY(length < 0)) {
127 ThrowNegativeArraySizeException(length);
128 return nullptr;
129 }
Mathieu Chartierbc5a7952016-10-17 15:46:31 -0700130 ObjPtr<mirror::Class> element_class = soa.Decode<mirror::Class>(javaElementClass);
Ian Rogersf9c612f2014-02-27 10:58:17 -0800131 if (UNLIKELY(element_class == nullptr)) {
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +0000132 ThrowNullPointerException("element class == null");
Ian Rogersf9c612f2014-02-27 10:58:17 -0800133 return nullptr;
134 }
Ian Rogersf9c612f2014-02-27 10:58:17 -0800135 Runtime* runtime = Runtime::Current();
Mathieu Chartierbc5a7952016-10-17 15:46:31 -0700136 ObjPtr<mirror::Class> array_class = runtime->GetClassLinker()->FindArrayClass(soa.Self(),
137 &element_class);
Ian Rogersf9c612f2014-02-27 10:58:17 -0800138 if (UNLIKELY(array_class == nullptr)) {
139 return nullptr;
140 }
141 gc::AllocatorType allocator = runtime->GetHeap()->GetCurrentAllocator();
Mathieu Chartierbc5a7952016-10-17 15:46:31 -0700142 ObjPtr<mirror::Array> result = mirror::Array::Alloc<true, true>(
143 soa.Self(),
144 array_class,
145 length,
146 array_class->GetComponentSizeShift(),
147 allocator);
Ian Rogersf9c612f2014-02-27 10:58:17 -0800148 return soa.AddLocalReference<jobject>(result);
149}
150
Elliott Hughes0512f022012-03-15 22:10:52 -0700151static jlong VMRuntime_addressOf(JNIEnv* env, jobject, jobject javaArray) {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700152 if (javaArray == nullptr) { // Most likely allocation failed
Ian Rogersa15e67d2012-02-28 13:51:55 -0800153 return 0;
154 }
Ian Rogers1eb512d2013-10-18 15:42:20 -0700155 ScopedFastNativeObjectAccess soa(env);
Mathieu Chartier0795f232016-09-27 18:43:30 -0700156 ObjPtr<mirror::Array> array = soa.Decode<mirror::Array>(javaArray);
Elliott Hughes7ede61e2011-09-14 18:18:06 -0700157 if (!array->IsArrayInstance()) {
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +0000158 ThrowIllegalArgumentException("not an array");
Elliott Hughes7ede61e2011-09-14 18:18:06 -0700159 return 0;
160 }
Mathieu Chartierbc5a7952016-10-17 15:46:31 -0700161 if (Runtime::Current()->GetHeap()->IsMovableObject(array)) {
Mathieu Chartier590fee92013-09-13 13:46:47 -0700162 ThrowRuntimeException("Trying to get address of movable array object");
163 return 0;
164 }
Ian Rogersef7d42f2014-01-06 12:55:46 -0800165 return reinterpret_cast<uintptr_t>(array->GetRawData(array->GetClass()->GetComponentSize(), 0));
Elliott Hughes7ede61e2011-09-14 18:18:06 -0700166}
167
Elliott Hughes0512f022012-03-15 22:10:52 -0700168static void VMRuntime_clearGrowthLimit(JNIEnv*, jobject) {
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800169 Runtime::Current()->GetHeap()->ClearGrowthLimit();
Elliott Hughes7ede61e2011-09-14 18:18:06 -0700170}
171
Mathieu Chartier379d09f2015-01-08 11:28:13 -0800172static void VMRuntime_clampGrowthLimit(JNIEnv*, jobject) {
173 Runtime::Current()->GetHeap()->ClampGrowthLimit();
174}
175
Elliott Hughes0512f022012-03-15 22:10:52 -0700176static jboolean VMRuntime_isDebuggerActive(JNIEnv*, jobject) {
Elliott Hughesc0f09332012-03-26 13:27:06 -0700177 return Dbg::IsDebuggerActive();
Elliott Hughes7ede61e2011-09-14 18:18:06 -0700178}
179
Oleksiy Vyalov278a80b2016-03-30 20:27:00 -0700180static jboolean VMRuntime_isNativeDebuggable(JNIEnv*, jobject) {
181 return Runtime::Current()->IsNativeDebuggable();
182}
183
Elliott Hughes0512f022012-03-15 22:10:52 -0700184static jobjectArray VMRuntime_properties(JNIEnv* env, jobject) {
Andreas Gamped0332e02017-09-22 19:23:38 -0700185 DCHECK(WellKnownClasses::java_lang_String != nullptr);
186
187 const std::vector<std::string>& properties = Runtime::Current()->GetProperties();
188 ScopedLocalRef<jobjectArray> ret(env,
189 env->NewObjectArray(static_cast<jsize>(properties.size()),
190 WellKnownClasses::java_lang_String,
191 nullptr /* initial element */));
192 if (ret == nullptr) {
193 DCHECK(env->ExceptionCheck());
194 return nullptr;
195 }
196 for (size_t i = 0; i != properties.size(); ++i) {
197 ScopedLocalRef<jstring> str(env, env->NewStringUTF(properties[i].c_str()));
198 if (str == nullptr) {
199 DCHECK(env->ExceptionCheck());
200 return nullptr;
201 }
202 env->SetObjectArrayElement(ret.get(), static_cast<jsize>(i), str.get());
203 DCHECK(!env->ExceptionCheck());
204 }
205 return ret.release();
Elliott Hughes7ede61e2011-09-14 18:18:06 -0700206}
207
Brian Carlstrom7d5ffb52012-02-01 14:27:54 -0800208// This is for backward compatibility with dalvik which returned the
209// meaningless "." when no boot classpath or classpath was
210// specified. Unfortunately, some tests were using java.class.path to
211// lookup relative file locations, so they are counting on this to be
212// ".", presumably some applications or libraries could have as well.
Elliott Hughes0512f022012-03-15 22:10:52 -0700213static const char* DefaultToDot(const std::string& class_path) {
Brian Carlstrom7d5ffb52012-02-01 14:27:54 -0800214 return class_path.empty() ? "." : class_path.c_str();
215}
216
Elliott Hughes0512f022012-03-15 22:10:52 -0700217static jstring VMRuntime_bootClassPath(JNIEnv* env, jobject) {
Brian Carlstroma004aa92012-02-08 18:05:09 -0800218 return env->NewStringUTF(DefaultToDot(Runtime::Current()->GetBootClassPathString()));
Elliott Hughes7ede61e2011-09-14 18:18:06 -0700219}
220
Elliott Hughes0512f022012-03-15 22:10:52 -0700221static jstring VMRuntime_classPath(JNIEnv* env, jobject) {
Brian Carlstroma004aa92012-02-08 18:05:09 -0800222 return env->NewStringUTF(DefaultToDot(Runtime::Current()->GetClassPathString()));
Elliott Hughes7ede61e2011-09-14 18:18:06 -0700223}
224
Elliott Hughes0512f022012-03-15 22:10:52 -0700225static jstring VMRuntime_vmVersion(JNIEnv* env, jobject) {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800226 return env->NewStringUTF(Runtime::GetVersion());
Elliott Hughes7ede61e2011-09-14 18:18:06 -0700227}
228
Brian Carlstromcef450c2013-06-28 14:38:26 -0700229static jstring VMRuntime_vmLibrary(JNIEnv* env, jobject) {
230 return env->NewStringUTF(kIsDebugBuild ? "libartd.so" : "libart.so");
231}
232
Sebastien Hertza7053762014-05-16 16:56:45 +0200233static jstring VMRuntime_vmInstructionSet(JNIEnv* env, jobject) {
234 InstructionSet isa = Runtime::Current()->GetInstructionSet();
235 const char* isa_string = GetInstructionSetString(isa);
236 return env->NewStringUTF(isa_string);
237}
238
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700239static jboolean VMRuntime_is64Bit(JNIEnv*, jobject) {
Sebastien Hertza7053762014-05-16 16:56:45 +0200240 bool is64BitMode = (sizeof(void*) == sizeof(uint64_t));
241 return is64BitMode ? JNI_TRUE : JNI_FALSE;
242}
243
244static jboolean VMRuntime_isCheckJniEnabled(JNIEnv* env, jobject) {
Ian Rogers55256cb2017-12-21 17:07:11 -0800245 return down_cast<JNIEnvExt*>(env)->GetVm()->IsCheckJniEnabled() ? JNI_TRUE : JNI_FALSE;
Sebastien Hertza7053762014-05-16 16:56:45 +0200246}
247
Jeff Haof00571c2014-05-29 17:29:47 -0700248static void VMRuntime_setTargetSdkVersionNative(JNIEnv*, jobject, jint target_sdk_version) {
Ian Rogers987560f2014-04-22 11:42:59 -0700249 // This is the target SDK version of the app we're about to run. It is intended that this a place
250 // where workarounds can be enabled.
Elliott Hughesc2dc62d2012-01-17 20:06:12 -0800251 // Note that targetSdkVersion may be CUR_DEVELOPMENT (10000).
252 // Note that targetSdkVersion may be 0, meaning "current".
Jeff Haof00571c2014-05-29 17:29:47 -0700253 Runtime::Current()->SetTargetSdkVersion(target_sdk_version);
Dmitriy Ivanov15efde22015-05-22 18:03:34 -0700254
Bilyan Borisovbb661c02016-04-04 16:27:32 +0100255#ifdef ART_TARGET_ANDROID
Dmitriy Ivanov15efde22015-05-22 18:03:34 -0700256 // This part is letting libc/dynamic linker know about current app's
257 // target sdk version to enable compatibility workarounds.
258 android_set_application_target_sdk_version(static_cast<uint32_t>(target_sdk_version));
259#endif
Elliott Hughes7ede61e2011-09-14 18:18:06 -0700260}
261
Mathieu Chartier987ccff2013-07-08 11:05:21 -0700262static void VMRuntime_registerNativeAllocation(JNIEnv* env, jobject, jint bytes) {
Ian Rogers1eb512d2013-10-18 15:42:20 -0700263 if (UNLIKELY(bytes < 0)) {
264 ScopedObjectAccess soa(env);
Mathieu Chartier987ccff2013-07-08 11:05:21 -0700265 ThrowRuntimeException("allocation size negative %d", bytes);
266 return;
267 }
Mathieu Chartier8ec31f92014-09-03 10:30:11 -0700268 Runtime::Current()->GetHeap()->RegisterNativeAllocation(env, static_cast<size_t>(bytes));
Mathieu Chartier987ccff2013-07-08 11:05:21 -0700269}
270
Calin Juravle97cbc922016-04-15 16:16:35 +0100271static void VMRuntime_registerSensitiveThread(JNIEnv*, jobject) {
272 Runtime::Current()->RegisterSensitiveThread();
273}
274
Mathieu Chartier987ccff2013-07-08 11:05:21 -0700275static void VMRuntime_registerNativeFree(JNIEnv* env, jobject, jint bytes) {
Ian Rogers1eb512d2013-10-18 15:42:20 -0700276 if (UNLIKELY(bytes < 0)) {
277 ScopedObjectAccess soa(env);
Mathieu Chartier987ccff2013-07-08 11:05:21 -0700278 ThrowRuntimeException("allocation size negative %d", bytes);
279 return;
280 }
Mathieu Chartier8ec31f92014-09-03 10:30:11 -0700281 Runtime::Current()->GetHeap()->RegisterNativeFree(env, static_cast<size_t>(bytes));
Mathieu Chartier987ccff2013-07-08 11:05:21 -0700282}
283
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700284static void VMRuntime_updateProcessState(JNIEnv*, jobject, jint process_state) {
285 Runtime* runtime = Runtime::Current();
Mathieu Chartierf8cb1782016-03-18 18:45:41 -0700286 runtime->UpdateProcessState(static_cast<ProcessState>(process_state));
Mathieu Chartierca2a24d2013-11-25 15:12:12 -0800287}
288
Mathieu Chartiera5eae692014-12-17 17:56:03 -0800289static void VMRuntime_trimHeap(JNIEnv* env, jobject) {
290 Runtime::Current()->GetHeap()->Trim(ThreadForEnv(env));
Elliott Hughes8cf5bc02012-02-02 16:32:16 -0800291}
292
Ian Rogers81d425b2012-09-27 16:03:43 -0700293static void VMRuntime_concurrentGC(JNIEnv* env, jobject) {
Mathieu Chartier35b59a22017-04-17 15:24:43 -0700294 Runtime::Current()->GetHeap()->ConcurrentGC(ThreadForEnv(env), gc::kGcCauseBackground, true);
Mathieu Chartier7664f5c2012-06-08 18:15:32 -0700295}
296
Mathieu Chartiera5eae692014-12-17 17:56:03 -0800297static void VMRuntime_requestHeapTrim(JNIEnv* env, jobject) {
298 Runtime::Current()->GetHeap()->RequestTrim(ThreadForEnv(env));
Mathieu Chartier079101a2014-12-15 14:23:10 -0800299}
Mathieu Chartiera5eae692014-12-17 17:56:03 -0800300
301static void VMRuntime_requestConcurrentGC(JNIEnv* env, jobject) {
Mathieu Chartier35b59a22017-04-17 15:24:43 -0700302 Runtime::Current()->GetHeap()->RequestConcurrentGC(ThreadForEnv(env),
303 gc::kGcCauseBackground,
304 true);
Mathieu Chartiera5eae692014-12-17 17:56:03 -0800305}
306
307static void VMRuntime_startHeapTaskProcessor(JNIEnv* env, jobject) {
308 Runtime::Current()->GetHeap()->GetTaskProcessor()->Start(ThreadForEnv(env));
309}
310
311static void VMRuntime_stopHeapTaskProcessor(JNIEnv* env, jobject) {
312 Runtime::Current()->GetHeap()->GetTaskProcessor()->Stop(ThreadForEnv(env));
313}
314
315static void VMRuntime_runHeapTasks(JNIEnv* env, jobject) {
316 Runtime::Current()->GetHeap()->GetTaskProcessor()->RunAllTasks(ThreadForEnv(env));
Mathieu Chartier079101a2014-12-15 14:23:10 -0800317}
318
Mathieu Chartierbc5a7952016-10-17 15:46:31 -0700319typedef std::map<std::string, ObjPtr<mirror::String>> StringTable;
Brian Carlstrome8104522013-10-15 21:56:36 -0700320
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700321class PreloadDexCachesStringsVisitor : public SingleRootVisitor {
322 public:
Mathieu Chartierd3ed9a32015-04-10 14:23:35 -0700323 explicit PreloadDexCachesStringsVisitor(StringTable* table) : table_(table) { }
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700324
325 void VisitRoot(mirror::Object* root, const RootInfo& info ATTRIBUTE_UNUSED)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700326 OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartierbc5a7952016-10-17 15:46:31 -0700327 ObjPtr<mirror::String> string = root->AsString();
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700328 table_->operator[](string->ToModifiedUtf8()) = string;
329 }
330
331 private:
332 StringTable* const table_;
333};
Brian Carlstrome8104522013-10-15 21:56:36 -0700334
335// Based on ClassLinker::ResolveString.
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700336static void PreloadDexCachesResolveString(
Vladimir Marko753d6132017-07-21 12:43:24 +0100337 ObjPtr<mirror::DexCache> dex_cache, dex::StringIndex string_idx, StringTable& strings)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700338 REQUIRES_SHARED(Locks::mutator_lock_) {
Vladimir Marko753d6132017-07-21 12:43:24 +0100339 uint32_t slot_idx = dex_cache->StringSlotIndex(string_idx);
340 auto pair = dex_cache->GetStrings()[slot_idx].load(std::memory_order_relaxed);
341 if (!pair.object.IsNull()) {
342 return; // The entry already contains some String.
Brian Carlstrome8104522013-10-15 21:56:36 -0700343 }
344 const DexFile* dex_file = dex_cache->GetDexFile();
Ian Rogerscf5077a2013-10-31 12:37:54 -0700345 const char* utf8 = dex_file->StringDataByIdx(string_idx);
Vladimir Marko753d6132017-07-21 12:43:24 +0100346 ObjPtr<mirror::String> string = strings[utf8];
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700347 if (string == nullptr) {
Brian Carlstrome8104522013-10-15 21:56:36 -0700348 return;
349 }
350 // LOG(INFO) << "VMRuntime.preloadDexCaches resolved string=" << utf8;
351 dex_cache->SetResolvedString(string_idx, string);
352}
353
354// Based on ClassLinker::ResolveType.
Mathieu Chartierbc5a7952016-10-17 15:46:31 -0700355static void PreloadDexCachesResolveType(Thread* self,
356 ObjPtr<mirror::DexCache> dex_cache,
Andreas Gampea5b09a62016-11-17 15:21:22 -0800357 dex::TypeIndex type_idx)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700358 REQUIRES_SHARED(Locks::mutator_lock_) {
Vladimir Marko753d6132017-07-21 12:43:24 +0100359 uint32_t slot_idx = dex_cache->TypeSlotIndex(type_idx);
360 auto pair = dex_cache->GetResolvedTypes()[slot_idx].load(std::memory_order_relaxed);
361 if (!pair.object.IsNull()) {
362 return; // The entry already contains some Class.
Brian Carlstrome8104522013-10-15 21:56:36 -0700363 }
364 const DexFile* dex_file = dex_cache->GetDexFile();
365 const char* class_name = dex_file->StringByTypeIdx(type_idx);
366 ClassLinker* linker = Runtime::Current()->GetClassLinker();
Vladimir Marko753d6132017-07-21 12:43:24 +0100367 ObjPtr<mirror::Class> klass = (class_name[1] == '\0')
368 ? linker->FindPrimitiveClass(class_name[0])
369 : linker->LookupClass(self, class_name, nullptr);
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700370 if (klass == nullptr) {
Brian Carlstrome8104522013-10-15 21:56:36 -0700371 return;
372 }
373 // LOG(INFO) << "VMRuntime.preloadDexCaches resolved klass=" << class_name;
374 dex_cache->SetResolvedType(type_idx, klass);
375 // Skip uninitialized classes because filled static storage entry implies it is initialized.
376 if (!klass->IsInitialized()) {
377 // LOG(INFO) << "VMRuntime.preloadDexCaches uninitialized klass=" << class_name;
378 return;
379 }
380 // LOG(INFO) << "VMRuntime.preloadDexCaches static storage klass=" << class_name;
Brian Carlstrome8104522013-10-15 21:56:36 -0700381}
382
383// Based on ClassLinker::ResolveField.
Vladimir Marko753d6132017-07-21 12:43:24 +0100384static void PreloadDexCachesResolveField(ObjPtr<mirror::DexCache> dex_cache,
385 uint32_t field_idx,
Brian Carlstrome8104522013-10-15 21:56:36 -0700386 bool is_static)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700387 REQUIRES_SHARED(Locks::mutator_lock_) {
Vladimir Marko753d6132017-07-21 12:43:24 +0100388 uint32_t slot_idx = dex_cache->FieldSlotIndex(field_idx);
389 auto pair = mirror::DexCache::GetNativePairPtrSize(dex_cache->GetResolvedFields(),
390 slot_idx,
391 kRuntimePointerSize);
392 if (pair.object != nullptr) {
393 return; // The entry already contains some ArtField.
Brian Carlstrome8104522013-10-15 21:56:36 -0700394 }
395 const DexFile* dex_file = dex_cache->GetDexFile();
396 const DexFile::FieldId& field_id = dex_file->GetFieldId(field_idx);
Vladimir Marko666ee3d2017-12-11 18:37:36 +0000397 ObjPtr<mirror::Class> klass = Runtime::Current()->GetClassLinker()->LookupResolvedType(
398 field_id.class_idx_, dex_cache, /* class_loader */ nullptr);
Andreas Gampefa4333d2017-02-14 11:10:34 -0800399 if (klass == nullptr) {
Brian Carlstrome8104522013-10-15 21:56:36 -0700400 return;
401 }
Vladimir Marko753d6132017-07-21 12:43:24 +0100402 ArtField* field = is_static
403 ? mirror::Class::FindStaticField(Thread::Current(), klass, dex_cache, field_idx)
404 : klass->FindInstanceField(dex_cache, field_idx);
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700405 if (field == nullptr) {
Brian Carlstrome8104522013-10-15 21:56:36 -0700406 return;
407 }
Andreas Gampe542451c2016-07-26 09:02:02 -0700408 dex_cache->SetResolvedField(field_idx, field, kRuntimePointerSize);
Brian Carlstrome8104522013-10-15 21:56:36 -0700409}
410
411// Based on ClassLinker::ResolveMethod.
Vladimir Marko753d6132017-07-21 12:43:24 +0100412static void PreloadDexCachesResolveMethod(ObjPtr<mirror::DexCache> dex_cache, uint32_t method_idx)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700413 REQUIRES_SHARED(Locks::mutator_lock_) {
Vladimir Marko753d6132017-07-21 12:43:24 +0100414 uint32_t slot_idx = dex_cache->MethodSlotIndex(method_idx);
415 auto pair = mirror::DexCache::GetNativePairPtrSize(dex_cache->GetResolvedMethods(),
416 slot_idx,
417 kRuntimePointerSize);
418 if (pair.object != nullptr) {
419 return; // The entry already contains some ArtMethod.
Brian Carlstrome8104522013-10-15 21:56:36 -0700420 }
421 const DexFile* dex_file = dex_cache->GetDexFile();
422 const DexFile::MethodId& method_id = dex_file->GetMethodId(method_idx);
Nicolas Geoffrayea179f42018-02-08 22:30:18 +0000423 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
424
425 ObjPtr<mirror::Class> klass = class_linker->LookupResolvedType(
Vladimir Marko666ee3d2017-12-11 18:37:36 +0000426 method_id.class_idx_, dex_cache, /* class_loader */ nullptr);
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700427 if (klass == nullptr) {
Brian Carlstrome8104522013-10-15 21:56:36 -0700428 return;
429 }
Nicolas Geoffrayea179f42018-02-08 22:30:18 +0000430 // Call FindResolvedMethod to populate the dex cache.
431 class_linker->FindResolvedMethod(klass, dex_cache, /* class_loader */ nullptr, method_idx);
Brian Carlstrome8104522013-10-15 21:56:36 -0700432}
433
434struct DexCacheStats {
435 uint32_t num_strings;
436 uint32_t num_types;
437 uint32_t num_fields;
438 uint32_t num_methods;
Brian Carlstrome8104522013-10-15 21:56:36 -0700439 DexCacheStats() : num_strings(0),
440 num_types(0),
441 num_fields(0),
Ian Rogers5ddb4102014-01-07 08:58:46 -0800442 num_methods(0) {}
Brian Carlstrome8104522013-10-15 21:56:36 -0700443};
444
445static const bool kPreloadDexCachesEnabled = true;
446
447// Disabled because it takes a long time (extra half second) but
448// gives almost no benefit in terms of saving private dirty pages.
449static const bool kPreloadDexCachesStrings = false;
450
451static const bool kPreloadDexCachesTypes = true;
452static const bool kPreloadDexCachesFieldsAndMethods = true;
453
454static const bool kPreloadDexCachesCollectStats = true;
455
456static void PreloadDexCachesStatsTotal(DexCacheStats* total) {
457 if (!kPreloadDexCachesCollectStats) {
458 return;
459 }
460
461 ClassLinker* linker = Runtime::Current()->GetClassLinker();
462 const std::vector<const DexFile*>& boot_class_path = linker->GetBootClassPath();
463 for (size_t i = 0; i< boot_class_path.size(); i++) {
464 const DexFile* dex_file = boot_class_path[i];
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700465 CHECK(dex_file != nullptr);
Brian Carlstrome8104522013-10-15 21:56:36 -0700466 total->num_strings += dex_file->NumStringIds();
467 total->num_fields += dex_file->NumFieldIds();
468 total->num_methods += dex_file->NumMethodIds();
469 total->num_types += dex_file->NumTypeIds();
Brian Carlstrome8104522013-10-15 21:56:36 -0700470 }
471}
472
473static void PreloadDexCachesStatsFilled(DexCacheStats* filled)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700474 REQUIRES_SHARED(Locks::mutator_lock_) {
Brian Carlstrome8104522013-10-15 21:56:36 -0700475 if (!kPreloadDexCachesCollectStats) {
Mathieu Chartier673ed3d2015-08-28 14:56:43 -0700476 return;
Brian Carlstrome8104522013-10-15 21:56:36 -0700477 }
Vladimir Markof44d36c2017-03-14 14:18:46 +0000478 // TODO: Update for hash-based DexCache arrays.
Mathieu Chartier673ed3d2015-08-28 14:56:43 -0700479 ClassLinker* const class_linker = Runtime::Current()->GetClassLinker();
480 Thread* const self = Thread::Current();
481 for (const DexFile* dex_file : class_linker->GetBootClassPath()) {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700482 CHECK(dex_file != nullptr);
Andreas Gamped66def32017-04-04 10:09:05 -0700483 // In fallback mode, not all boot classpath components might be registered, yet.
484 if (!class_linker->IsDexFileRegistered(self, *dex_file)) {
485 continue;
486 }
Vladimir Markocd556b02017-02-03 11:47:34 +0000487 ObjPtr<mirror::DexCache> const dex_cache = class_linker->FindDexCache(self, *dex_file);
Andreas Gamped66def32017-04-04 10:09:05 -0700488 DCHECK(dex_cache != nullptr); // Boot class path dex caches are never unloaded.
Vladimir Marko753d6132017-07-21 12:43:24 +0100489 for (size_t j = 0, num_strings = dex_cache->NumStrings(); j < num_strings; ++j) {
490 auto pair = dex_cache->GetStrings()[j].load(std::memory_order_relaxed);
491 if (!pair.object.IsNull()) {
Brian Carlstrome8104522013-10-15 21:56:36 -0700492 filled->num_strings++;
493 }
494 }
Vladimir Marko753d6132017-07-21 12:43:24 +0100495 for (size_t j = 0, num_types = dex_cache->NumResolvedTypes(); j < num_types; ++j) {
496 auto pair = dex_cache->GetResolvedTypes()[j].load(std::memory_order_relaxed);
497 if (!pair.object.IsNull()) {
Brian Carlstrome8104522013-10-15 21:56:36 -0700498 filled->num_types++;
499 }
500 }
Vladimir Marko753d6132017-07-21 12:43:24 +0100501 for (size_t j = 0, num_fields = dex_cache->NumResolvedFields(); j < num_fields; ++j) {
502 auto pair = mirror::DexCache::GetNativePairPtrSize(dex_cache->GetResolvedFields(),
503 j,
504 kRuntimePointerSize);
505 if (pair.object != nullptr) {
Brian Carlstrome8104522013-10-15 21:56:36 -0700506 filled->num_fields++;
507 }
508 }
Vladimir Marko753d6132017-07-21 12:43:24 +0100509 for (size_t j = 0, num_methods = dex_cache->NumResolvedMethods(); j < num_methods; ++j) {
510 auto pair = mirror::DexCache::GetNativePairPtrSize(dex_cache->GetResolvedMethods(),
511 j,
512 kRuntimePointerSize);
513 if (pair.object != nullptr) {
Brian Carlstrome8104522013-10-15 21:56:36 -0700514 filled->num_methods++;
515 }
516 }
Brian Carlstrome8104522013-10-15 21:56:36 -0700517 }
518}
519
520// TODO: http://b/11309598 This code was ported over based on the
521// Dalvik version. However, ART has similar code in other places such
522// as the CompilerDriver. This code could probably be refactored to
523// serve both uses.
524static void VMRuntime_preloadDexCaches(JNIEnv* env, jobject) {
525 if (!kPreloadDexCachesEnabled) {
526 return;
527 }
528
529 ScopedObjectAccess soa(env);
530
531 DexCacheStats total;
532 DexCacheStats before;
533 if (kPreloadDexCachesCollectStats) {
534 LOG(INFO) << "VMRuntime.preloadDexCaches starting";
535 PreloadDexCachesStatsTotal(&total);
536 PreloadDexCachesStatsFilled(&before);
537 }
538
539 Runtime* runtime = Runtime::Current();
540 ClassLinker* linker = runtime->GetClassLinker();
541
542 // We use a std::map to avoid heap allocating StringObjects to lookup in gDvm.literalStrings
543 StringTable strings;
544 if (kPreloadDexCachesStrings) {
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700545 PreloadDexCachesStringsVisitor visitor(&strings);
546 runtime->GetInternTable()->VisitRoots(&visitor, kVisitRootFlagAllRoots);
Brian Carlstrome8104522013-10-15 21:56:36 -0700547 }
548
549 const std::vector<const DexFile*>& boot_class_path = linker->GetBootClassPath();
Mathieu Chartier673ed3d2015-08-28 14:56:43 -0700550 for (size_t i = 0; i < boot_class_path.size(); i++) {
Brian Carlstrome8104522013-10-15 21:56:36 -0700551 const DexFile* dex_file = boot_class_path[i];
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700552 CHECK(dex_file != nullptr);
Vladimir Marko753d6132017-07-21 12:43:24 +0100553 ObjPtr<mirror::DexCache> dex_cache = linker->RegisterDexFile(*dex_file, nullptr);
Andreas Gampefa4333d2017-02-14 11:10:34 -0800554 CHECK(dex_cache != nullptr); // Boot class path dex caches are never unloaded.
Brian Carlstrome8104522013-10-15 21:56:36 -0700555 if (kPreloadDexCachesStrings) {
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800556 for (size_t j = 0; j < dex_cache->NumStrings(); j++) {
Andreas Gampe8a0128a2016-11-28 07:38:35 -0800557 PreloadDexCachesResolveString(dex_cache, dex::StringIndex(j), strings);
Brian Carlstrome8104522013-10-15 21:56:36 -0700558 }
559 }
560
561 if (kPreloadDexCachesTypes) {
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800562 for (size_t j = 0; j < dex_cache->NumResolvedTypes(); j++) {
Vladimir Marko753d6132017-07-21 12:43:24 +0100563 PreloadDexCachesResolveType(soa.Self(), dex_cache, dex::TypeIndex(j));
Brian Carlstrome8104522013-10-15 21:56:36 -0700564 }
565 }
566
567 if (kPreloadDexCachesFieldsAndMethods) {
568 for (size_t class_def_index = 0;
569 class_def_index < dex_file->NumClassDefs();
570 class_def_index++) {
571 const DexFile::ClassDef& class_def = dex_file->GetClassDef(class_def_index);
Ian Rogers13735952014-10-08 12:43:28 -0700572 const uint8_t* class_data = dex_file->GetClassData(class_def);
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700573 if (class_data == nullptr) {
Brian Carlstrome8104522013-10-15 21:56:36 -0700574 continue;
575 }
576 ClassDataItemIterator it(*dex_file, class_data);
577 for (; it.HasNextStaticField(); it.Next()) {
578 uint32_t field_idx = it.GetMemberIndex();
579 PreloadDexCachesResolveField(dex_cache, field_idx, true);
580 }
581 for (; it.HasNextInstanceField(); it.Next()) {
582 uint32_t field_idx = it.GetMemberIndex();
583 PreloadDexCachesResolveField(dex_cache, field_idx, false);
584 }
585 for (; it.HasNextDirectMethod(); it.Next()) {
586 uint32_t method_idx = it.GetMemberIndex();
Vladimir Markoba118822017-06-12 15:41:56 +0100587 PreloadDexCachesResolveMethod(dex_cache, method_idx);
Brian Carlstrome8104522013-10-15 21:56:36 -0700588 }
589 for (; it.HasNextVirtualMethod(); it.Next()) {
590 uint32_t method_idx = it.GetMemberIndex();
Vladimir Markoba118822017-06-12 15:41:56 +0100591 PreloadDexCachesResolveMethod(dex_cache, method_idx);
Brian Carlstrome8104522013-10-15 21:56:36 -0700592 }
593 }
594 }
595 }
596
597 if (kPreloadDexCachesCollectStats) {
598 DexCacheStats after;
599 PreloadDexCachesStatsFilled(&after);
600 LOG(INFO) << StringPrintf("VMRuntime.preloadDexCaches strings total=%d before=%d after=%d",
601 total.num_strings, before.num_strings, after.num_strings);
602 LOG(INFO) << StringPrintf("VMRuntime.preloadDexCaches types total=%d before=%d after=%d",
603 total.num_types, before.num_types, after.num_types);
604 LOG(INFO) << StringPrintf("VMRuntime.preloadDexCaches fields total=%d before=%d after=%d",
605 total.num_fields, before.num_fields, after.num_fields);
606 LOG(INFO) << StringPrintf("VMRuntime.preloadDexCaches methods total=%d before=%d after=%d",
607 total.num_methods, before.num_methods, after.num_methods);
Brian Carlstrome8104522013-10-15 21:56:36 -0700608 LOG(INFO) << StringPrintf("VMRuntime.preloadDexCaches finished");
609 }
610}
611
Dave Allison0aded082013-11-07 13:15:11 -0800612
613/*
614 * This is called by the framework when it knows the application directory and
Calin Juravle31f2c152015-10-23 17:56:15 +0100615 * process name.
Dave Allison0aded082013-11-07 13:15:11 -0800616 */
Calin Juravle31f2c152015-10-23 17:56:15 +0100617static void VMRuntime_registerAppInfo(JNIEnv* env,
618 jclass clazz ATTRIBUTE_UNUSED,
Calin Juravle5e2b9712015-12-18 14:10:00 +0200619 jstring profile_file,
Calin Juravle77651c42017-03-03 18:04:02 -0800620 jobjectArray code_paths) {
Calin Juravle66f55232015-12-08 15:09:10 +0000621 std::vector<std::string> code_paths_vec;
622 int code_paths_length = env->GetArrayLength(code_paths);
623 for (int i = 0; i < code_paths_length; i++) {
624 jstring code_path = reinterpret_cast<jstring>(env->GetObjectArrayElement(code_paths, i));
625 const char* raw_code_path = env->GetStringUTFChars(code_path, nullptr);
626 code_paths_vec.push_back(raw_code_path);
627 env->ReleaseStringUTFChars(code_path, raw_code_path);
628 }
Calin Juravlec1b643c2014-05-30 23:44:11 +0100629
Calin Juravle5e2b9712015-12-18 14:10:00 +0200630 const char* raw_profile_file = env->GetStringUTFChars(profile_file, nullptr);
631 std::string profile_file_str(raw_profile_file);
632 env->ReleaseStringUTFChars(profile_file, raw_profile_file);
Calin Juravlec1b643c2014-05-30 23:44:11 +0100633
Calin Juravle77651c42017-03-03 18:04:02 -0800634 Runtime::Current()->RegisterAppInfo(code_paths_vec, profile_file_str);
Dave Allison0aded082013-11-07 13:15:11 -0800635}
636
Brian Carlstrom31d8f522014-09-29 11:22:54 -0700637static jboolean VMRuntime_isBootClassPathOnDisk(JNIEnv* env, jclass, jstring java_instruction_set) {
638 ScopedUtfChars instruction_set(env, java_instruction_set);
639 if (instruction_set.c_str() == nullptr) {
640 return JNI_FALSE;
641 }
642 InstructionSet isa = GetInstructionSetFromString(instruction_set.c_str());
Vladimir Marko33bff252017-11-01 14:35:42 +0000643 if (isa == InstructionSet::kNone) {
Brian Carlstrom31d8f522014-09-29 11:22:54 -0700644 ScopedLocalRef<jclass> iae(env, env->FindClass("java/lang/IllegalArgumentException"));
645 std::string message(StringPrintf("Instruction set %s is invalid.", instruction_set.c_str()));
646 env->ThrowNew(iae.get(), message.c_str());
647 return JNI_FALSE;
648 }
649 std::string error_msg;
650 std::unique_ptr<ImageHeader> image_header(gc::space::ImageSpace::ReadImageHeader(
651 Runtime::Current()->GetImageLocation().c_str(), isa, &error_msg));
652 return image_header.get() != nullptr;
653}
654
655static jstring VMRuntime_getCurrentInstructionSet(JNIEnv* env, jclass) {
656 return env->NewStringUTF(GetInstructionSetString(kRuntimeISA));
657}
658
Andreas Gampea1425a12016-03-11 17:44:04 -0800659static jboolean VMRuntime_didPruneDalvikCache(JNIEnv* env ATTRIBUTE_UNUSED,
660 jclass klass ATTRIBUTE_UNUSED) {
661 return Runtime::Current()->GetPrunedDalvikCache() ? JNI_TRUE : JNI_FALSE;
662}
663
Hiroshi Yamauchid7f03392017-03-29 14:47:49 -0700664static void VMRuntime_setSystemDaemonThreadPriority(JNIEnv* env ATTRIBUTE_UNUSED,
665 jclass klass ATTRIBUTE_UNUSED) {
666#ifdef ART_TARGET_ANDROID
667 Thread* self = Thread::Current();
668 DCHECK(self != nullptr);
669 pid_t tid = self->GetTid();
670 // We use a priority lower than the default for the system daemon threads (eg HeapTaskDaemon) to
671 // avoid jank due to CPU contentions between GC and other UI-related threads. b/36631902.
672 // We may use a native priority that doesn't have a corresponding java.lang.Thread-level priority.
673 static constexpr int kSystemDaemonNiceValue = 4; // priority 124
674 if (setpriority(PRIO_PROCESS, tid, kSystemDaemonNiceValue) != 0) {
675 PLOG(INFO) << *self << " setpriority(PRIO_PROCESS, " << tid << ", "
676 << kSystemDaemonNiceValue << ") failed";
677 }
678#endif
679}
680
Elliott Hughes0512f022012-03-15 22:10:52 -0700681static JNINativeMethod gMethods[] = {
Igor Murashkin3b6f4402017-02-16 16:13:17 -0800682 FAST_NATIVE_METHOD(VMRuntime, addressOf, "(Ljava/lang/Object;)J"),
Elliott Hughes7ede61e2011-09-14 18:18:06 -0700683 NATIVE_METHOD(VMRuntime, bootClassPath, "()Ljava/lang/String;"),
Mathieu Chartier379d09f2015-01-08 11:28:13 -0800684 NATIVE_METHOD(VMRuntime, clampGrowthLimit, "()V"),
Elliott Hughes7ede61e2011-09-14 18:18:06 -0700685 NATIVE_METHOD(VMRuntime, classPath, "()Ljava/lang/String;"),
686 NATIVE_METHOD(VMRuntime, clearGrowthLimit, "()V"),
Mathieu Chartier7664f5c2012-06-08 18:15:32 -0700687 NATIVE_METHOD(VMRuntime, concurrentGC, "()V"),
Elliott Hughes7ede61e2011-09-14 18:18:06 -0700688 NATIVE_METHOD(VMRuntime, disableJitCompilation, "()V"),
David Brazdil4384b102018-01-23 16:10:36 +0000689 NATIVE_METHOD(VMRuntime, hasUsedHiddenApi, "()Z"),
Mathew Inwood7d74ef52018-03-16 14:18:33 +0000690 NATIVE_METHOD(VMRuntime, setHiddenApiExemptions, "([Ljava/lang/String;)V"),
Elliott Hughes7ede61e2011-09-14 18:18:06 -0700691 NATIVE_METHOD(VMRuntime, getTargetHeapUtilization, "()F"),
Igor Murashkin3b6f4402017-02-16 16:13:17 -0800692 FAST_NATIVE_METHOD(VMRuntime, isDebuggerActive, "()Z"),
693 FAST_NATIVE_METHOD(VMRuntime, isNativeDebuggable, "()Z"),
Elliott Hughes7ede61e2011-09-14 18:18:06 -0700694 NATIVE_METHOD(VMRuntime, nativeSetTargetHeapUtilization, "(F)V"),
Igor Murashkin3b6f4402017-02-16 16:13:17 -0800695 FAST_NATIVE_METHOD(VMRuntime, newNonMovableArray, "(Ljava/lang/Class;I)Ljava/lang/Object;"),
696 FAST_NATIVE_METHOD(VMRuntime, newUnpaddedArray, "(Ljava/lang/Class;I)Ljava/lang/Object;"),
Elliott Hughes7ede61e2011-09-14 18:18:06 -0700697 NATIVE_METHOD(VMRuntime, properties, "()[Ljava/lang/String;"),
Alex Klyubin881392f2013-10-24 16:31:56 -0700698 NATIVE_METHOD(VMRuntime, setTargetSdkVersionNative, "(I)V"),
Mathieu Chartier987ccff2013-07-08 11:05:21 -0700699 NATIVE_METHOD(VMRuntime, registerNativeAllocation, "(I)V"),
Calin Juravle97cbc922016-04-15 16:16:35 +0100700 NATIVE_METHOD(VMRuntime, registerSensitiveThread, "()V"),
Mathieu Chartier987ccff2013-07-08 11:05:21 -0700701 NATIVE_METHOD(VMRuntime, registerNativeFree, "(I)V"),
Mathieu Chartiera5eae692014-12-17 17:56:03 -0800702 NATIVE_METHOD(VMRuntime, requestConcurrentGC, "()V"),
703 NATIVE_METHOD(VMRuntime, requestHeapTrim, "()V"),
704 NATIVE_METHOD(VMRuntime, runHeapTasks, "()V"),
Mathieu Chartierca2a24d2013-11-25 15:12:12 -0800705 NATIVE_METHOD(VMRuntime, updateProcessState, "(I)V"),
Mathieu Chartiera5eae692014-12-17 17:56:03 -0800706 NATIVE_METHOD(VMRuntime, startHeapTaskProcessor, "()V"),
Elliott Hughes7ede61e2011-09-14 18:18:06 -0700707 NATIVE_METHOD(VMRuntime, startJitCompilation, "()V"),
Mathieu Chartiera5eae692014-12-17 17:56:03 -0800708 NATIVE_METHOD(VMRuntime, stopHeapTaskProcessor, "()V"),
Elliott Hughes8cf5bc02012-02-02 16:32:16 -0800709 NATIVE_METHOD(VMRuntime, trimHeap, "()V"),
Elliott Hughes7ede61e2011-09-14 18:18:06 -0700710 NATIVE_METHOD(VMRuntime, vmVersion, "()Ljava/lang/String;"),
Brian Carlstromcef450c2013-06-28 14:38:26 -0700711 NATIVE_METHOD(VMRuntime, vmLibrary, "()Ljava/lang/String;"),
Sebastien Hertza7053762014-05-16 16:56:45 +0200712 NATIVE_METHOD(VMRuntime, vmInstructionSet, "()Ljava/lang/String;"),
Igor Murashkin3b6f4402017-02-16 16:13:17 -0800713 FAST_NATIVE_METHOD(VMRuntime, is64Bit, "()Z"),
714 FAST_NATIVE_METHOD(VMRuntime, isCheckJniEnabled, "()Z"),
Brian Carlstrome8104522013-10-15 21:56:36 -0700715 NATIVE_METHOD(VMRuntime, preloadDexCaches, "()V"),
Calin Juravle77651c42017-03-03 18:04:02 -0800716 NATIVE_METHOD(VMRuntime, registerAppInfo, "(Ljava/lang/String;[Ljava/lang/String;)V"),
Brian Carlstrom31d8f522014-09-29 11:22:54 -0700717 NATIVE_METHOD(VMRuntime, isBootClassPathOnDisk, "(Ljava/lang/String;)Z"),
718 NATIVE_METHOD(VMRuntime, getCurrentInstructionSet, "()Ljava/lang/String;"),
Andreas Gampea1425a12016-03-11 17:44:04 -0800719 NATIVE_METHOD(VMRuntime, didPruneDalvikCache, "()Z"),
Hiroshi Yamauchid7f03392017-03-29 14:47:49 -0700720 NATIVE_METHOD(VMRuntime, setSystemDaemonThreadPriority, "()V"),
Elliott Hughes7ede61e2011-09-14 18:18:06 -0700721};
722
Elliott Hughes7ede61e2011-09-14 18:18:06 -0700723void register_dalvik_system_VMRuntime(JNIEnv* env) {
Elliott Hugheseac76672012-05-24 21:56:51 -0700724 REGISTER_NATIVE_METHODS("dalvik/system/VMRuntime");
Elliott Hughes7ede61e2011-09-14 18:18:06 -0700725}
726
727} // namespace art