blob: 7ed66415e883e7c1ecf02c56e99202cb3568341e [file] [log] [blame]
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001/*
2 * Copyright (C) 2006 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 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080016
17#define LOG_TAG "AndroidRuntime"
18//#define LOG_NDEBUG 0
19
20#include <android_runtime/AndroidRuntime.h>
Mathias Agopian07952722009-05-19 19:08:10 -070021#include <binder/IBinder.h>
Brad Fitzpatrick0bd52432010-12-13 16:52:35 -080022#include <binder/IPCThreadState.h>
Mathias Agopian07952722009-05-19 19:08:10 -070023#include <binder/IServiceManager.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024#include <utils/Log.h>
25#include <utils/misc.h>
Mathias Agopian07952722009-05-19 19:08:10 -070026#include <binder/Parcel.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027#include <utils/threads.h>
28#include <cutils/properties.h>
29
30#include <SkGraphics.h>
31#include <SkImageDecoder.h>
Mike Reedfc8db532009-04-27 11:43:30 -040032#include <SkImageRef_GlobalPool.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033
34#include "jni.h"
35#include "JNIHelp.h"
Brian Carlstrom9f8203a2013-06-19 13:49:36 -070036#include "JniInvocation.h"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037#include "android_util_Binder.h"
38
39#include <stdio.h>
40#include <signal.h>
41#include <sys/stat.h>
42#include <sys/types.h>
43#include <signal.h>
44#include <dirent.h>
45#include <assert.h>
46
47
48using namespace android;
49
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050extern int register_android_os_Binder(JNIEnv* env);
51extern int register_android_os_Process(JNIEnv* env);
52extern int register_android_graphics_Bitmap(JNIEnv*);
53extern int register_android_graphics_BitmapFactory(JNIEnv*);
Wei-Ta Chen6b849e22010-09-07 17:32:18 +080054extern int register_android_graphics_BitmapRegionDecoder(JNIEnv*);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055extern int register_android_graphics_Camera(JNIEnv* env);
Leon Scroggins IIId0d7eaf2013-09-06 16:46:57 -040056extern int register_android_graphics_CreateJavaOutputStreamAdaptor(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057extern int register_android_graphics_Graphics(JNIEnv* env);
58extern int register_android_graphics_Interpolator(JNIEnv* env);
59extern int register_android_graphics_LayerRasterizer(JNIEnv*);
60extern int register_android_graphics_MaskFilter(JNIEnv* env);
61extern int register_android_graphics_Movie(JNIEnv* env);
62extern int register_android_graphics_NinePatch(JNIEnv*);
63extern int register_android_graphics_PathEffect(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064extern int register_android_graphics_Shader(JNIEnv* env);
65extern int register_android_graphics_Typeface(JNIEnv* env);
Wei-Ta Chenbca2d612009-11-30 17:52:05 +080066extern int register_android_graphics_YuvImage(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067
68extern int register_com_google_android_gles_jni_EGLImpl(JNIEnv* env);
69extern int register_com_google_android_gles_jni_GLImpl(JNIEnv* env);
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -070070extern int register_android_opengl_jni_EGL14(JNIEnv* env);
Jesse Hall237c2b82013-05-06 11:36:57 -070071extern int register_android_opengl_jni_EGLExt(JNIEnv* env);
Jack Palevich1c4907e2009-04-13 16:22:25 -070072extern int register_android_opengl_jni_GLES10(JNIEnv* env);
73extern int register_android_opengl_jni_GLES10Ext(JNIEnv* env);
74extern int register_android_opengl_jni_GLES11(JNIEnv* env);
75extern int register_android_opengl_jni_GLES11Ext(JNIEnv* env);
Jack Palevich560814f2009-11-19 16:34:55 +080076extern int register_android_opengl_jni_GLES20(JNIEnv* env);
Jesse Halld877efe2013-04-29 15:59:35 -070077extern int register_android_opengl_jni_GLES30(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080078
79extern int register_android_hardware_Camera(JNIEnv *env);
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -070080extern int register_android_hardware_camera2_CameraMetadata(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081extern int register_android_hardware_SensorManager(JNIEnv *env);
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -040082extern int register_android_hardware_SerialPort(JNIEnv *env);
Mike Lockwoode7d511e2010-12-30 13:39:37 -050083extern int register_android_hardware_UsbDevice(JNIEnv *env);
Mike Lockwoodacc29cc2011-03-11 08:18:08 -050084extern int register_android_hardware_UsbDeviceConnection(JNIEnv *env);
Mike Lockwoode7d511e2010-12-30 13:39:37 -050085extern int register_android_hardware_UsbRequest(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086
87extern int register_android_media_AudioRecord(JNIEnv *env);
88extern int register_android_media_AudioSystem(JNIEnv *env);
89extern int register_android_media_AudioTrack(JNIEnv *env);
90extern int register_android_media_JetPlayer(JNIEnv *env);
91extern int register_android_media_ToneGenerator(JNIEnv *env);
92
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093extern int register_android_util_FloatMath(JNIEnv* env);
94
95namespace android {
96
97/*
98 * JNI-based registration functions. Note these are properly contained in
99 * namespace android.
100 */
101extern int register_android_content_AssetManager(JNIEnv* env);
102extern int register_android_util_EventLog(JNIEnv* env);
103extern int register_android_util_Log(JNIEnv* env);
104extern int register_android_content_StringBlock(JNIEnv* env);
105extern int register_android_content_XmlBlock(JNIEnv* env);
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700106extern int register_android_emoji_EmojiFactory(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107extern int register_android_graphics_Canvas(JNIEnv* env);
108extern int register_android_graphics_ColorFilter(JNIEnv* env);
109extern int register_android_graphics_DrawFilter(JNIEnv* env);
110extern int register_android_graphics_Matrix(JNIEnv* env);
111extern int register_android_graphics_Paint(JNIEnv* env);
112extern int register_android_graphics_Path(JNIEnv* env);
113extern int register_android_graphics_PathMeasure(JNIEnv* env);
114extern int register_android_graphics_Picture(JNIEnv*);
115extern int register_android_graphics_PorterDuff(JNIEnv* env);
116extern int register_android_graphics_Rasterizer(JNIEnv* env);
Jeff Brownfbf09772011-01-16 14:06:57 -0800117extern int register_android_graphics_Region(JNIEnv* env);
Jamie Gennisaa0ce332011-01-06 17:04:26 -0800118extern int register_android_graphics_SurfaceTexture(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119extern int register_android_graphics_Xfermode(JNIEnv* env);
Svetoslav6811f4e2013-09-18 15:58:28 -0700120extern int register_android_graphics_pdf_PdfDocument(JNIEnv* env);
Jeff Brown0a0a1242011-12-02 02:25:22 -0800121extern int register_android_view_DisplayEventReceiver(JNIEnv* env);
Chris Craik54389792013-12-20 13:28:11 -0800122extern int register_android_view_DisplayList(JNIEnv* env);
Romain Guy3b748a42013-04-17 18:54:38 -0700123extern int register_android_view_GraphicBuffer(JNIEnv* env);
Romain Guye4d01122010-06-16 18:44:05 -0700124extern int register_android_view_GLES20Canvas(JNIEnv* env);
John Reck30835792013-11-07 14:21:24 -0800125extern int register_android_view_GLRenderer(JNIEnv* env);
John Reckcec24ae2013-11-05 13:27:50 -0800126extern int register_android_view_ThreadedRenderer(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127extern int register_android_view_Surface(JNIEnv* env);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800128extern int register_android_view_SurfaceControl(JNIEnv* env);
Jeff Brown64a55af2012-08-26 02:47:39 -0700129extern int register_android_view_SurfaceSession(JNIEnv* env);
Romain Guy8f0095c2011-05-02 17:24:22 -0700130extern int register_android_view_TextureView(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131extern int register_android_database_CursorWindow(JNIEnv* env);
Jeff Browne5360fb2011-10-31 17:48:13 -0700132extern int register_android_database_SQLiteConnection(JNIEnv* env);
133extern int register_android_database_SQLiteGlobal(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134extern int register_android_database_SQLiteDebug(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800135extern int register_android_debug_JNITest(JNIEnv* env);
136extern int register_android_nio_utils(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800137extern int register_android_text_format_Time(JNIEnv* env);
138extern int register_android_os_Debug(JNIEnv* env);
Christopher Tatefa9e7c02010-05-06 12:07:10 -0700139extern int register_android_os_MessageQueue(JNIEnv* env);
Jeff Sharkeyd84e1ce2012-03-06 18:26:19 -0800140extern int register_android_os_Parcel(JNIEnv* env);
Stephen Smalleyc07fca32012-01-13 08:31:39 -0500141extern int register_android_os_SELinux(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800142extern int register_android_os_SystemProperties(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800143extern int register_android_os_SystemClock(JNIEnv* env);
Jeff Brown481c1572012-03-09 14:41:15 -0800144extern int register_android_os_Trace(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145extern int register_android_os_FileObserver(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800146extern int register_android_os_UEventObserver(JNIEnv* env);
147extern int register_android_os_MemoryFile(JNIEnv* env);
148extern int register_android_net_LocalSocketImpl(JNIEnv* env);
149extern int register_android_net_NetworkUtils(JNIEnv* env);
Dan Egnor2b4abcd2010-04-07 17:30:50 -0700150extern int register_android_net_TrafficStats(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151extern int register_android_text_AndroidCharacter(JNIEnv *env);
Doug Feltdae8e942010-02-24 14:33:15 -0800152extern int register_android_text_AndroidBidi(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153extern int register_android_opengl_classes(JNIEnv *env);
JP Abgrall98a4f7e2011-09-02 15:36:33 -0700154extern int register_android_server_NetworkManagementSocketTagger(JNIEnv* env);
Christopher Tateecaa7b42010-06-04 14:55:02 -0700155extern int register_android_server_Watchdog(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156extern int register_android_ddm_DdmHandleNativeHeap(JNIEnv *env);
157extern int register_com_android_internal_os_ZygoteInit(JNIEnv* env);
Joe Onorato1cf58742009-06-12 11:06:24 -0700158extern int register_android_backup_BackupDataInput(JNIEnv *env);
Joe Onoratod2110db2009-05-19 13:41:21 -0700159extern int register_android_backup_BackupDataOutput(JNIEnv *env);
Joe Onorato06290a42009-06-18 20:10:37 -0700160extern int register_android_backup_FileBackupHelperBase(JNIEnv *env);
Joe Onorato4ababd92009-06-25 18:29:18 -0400161extern int register_android_backup_BackupHelperDispatcher(JNIEnv *env);
Christopher Tate4a627c72011-04-01 14:43:32 -0700162extern int register_android_app_backup_FullBackup(JNIEnv *env);
Chet Haase9c1e23b2011-03-24 10:51:31 -0700163extern int register_android_app_ActivityThread(JNIEnv *env);
Dianne Hackborn69969e42010-05-04 11:40:40 -0700164extern int register_android_app_NativeActivity(JNIEnv *env);
Jeff Browncbad9762012-09-04 21:57:59 -0700165extern int register_android_media_RemoteDisplay(JNIEnv *env);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700166extern int register_android_view_InputChannel(JNIEnv* env);
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700167extern int register_android_view_InputDevice(JNIEnv* env);
Jeff Brown32cbc38552011-12-01 14:01:49 -0800168extern int register_android_view_InputEventReceiver(JNIEnv* env);
Jeff Brownc28867a2013-03-26 15:42:39 -0700169extern int register_android_view_InputEventSender(JNIEnv* env);
Michael Wrighta44dd262013-04-10 21:12:00 -0700170extern int register_android_view_InputQueue(JNIEnv* env);
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700171extern int register_android_view_KeyCharacterMap(JNIEnv *env);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700172extern int register_android_view_KeyEvent(JNIEnv* env);
173extern int register_android_view_MotionEvent(JNIEnv* env);
Jeff Brown2352b972011-04-12 22:39:53 -0700174extern int register_android_view_PointerIcon(JNIEnv* env);
Jeff Brown2ed24622011-03-14 19:39:54 -0700175extern int register_android_view_VelocityTracker(JNIEnv* env);
Kenny Root02c87302010-07-01 08:10:18 -0700176extern int register_android_content_res_ObbScanner(JNIEnv* env);
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -0700177extern int register_android_content_res_Configuration(JNIEnv* env);
Chet Haase6e0ecb42010-11-03 19:41:18 -0700178extern int register_android_animation_PropertyValuesHolder(JNIEnv *env);
Kenny Root66269ea2011-07-12 14:14:01 -0700179extern int register_com_android_internal_content_NativeLibraryHelper(JNIEnv *env);
Jeff Sharkey9a2c2a62013-01-14 16:48:51 -0800180extern int register_com_android_internal_net_NetworkStatsFactory(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800181
182static AndroidRuntime* gCurRuntime = NULL;
183
184static void doThrow(JNIEnv* env, const char* exc, const char* msg = NULL)
185{
186 if (jniThrowException(env, exc, msg) != 0)
187 assert(false);
188}
189
190/*
191 * Code written in the Java Programming Language calls here from main().
192 */
Jeff Brown16f5f5c2012-03-15 16:53:55 -0700193static void com_android_internal_os_RuntimeInit_nativeFinishInit(JNIEnv* env, jobject clazz)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800194{
195 gCurRuntime->onStarted();
196}
197
Jeff Brown16f5f5c2012-03-15 16:53:55 -0700198static void com_android_internal_os_RuntimeInit_nativeZygoteInit(JNIEnv* env, jobject clazz)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800199{
200 gCurRuntime->onZygoteInit();
201}
202
Jeff Brown4280c4a2012-03-15 17:48:02 -0700203static void com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup(JNIEnv* env,
204 jobject clazz, jboolean exitWithoutCleanup)
205{
206 gCurRuntime->setExitWithoutCleanup(exitWithoutCleanup);
207}
208
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800209/*
210 * JNI registration.
211 */
212static JNINativeMethod gMethods[] = {
Jeff Brown16f5f5c2012-03-15 16:53:55 -0700213 { "nativeFinishInit", "()V",
214 (void*) com_android_internal_os_RuntimeInit_nativeFinishInit },
215 { "nativeZygoteInit", "()V",
216 (void*) com_android_internal_os_RuntimeInit_nativeZygoteInit },
Jeff Brown4280c4a2012-03-15 17:48:02 -0700217 { "nativeSetExitWithoutCleanup", "(Z)V",
218 (void*) com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup },
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800219};
220
221int register_com_android_internal_os_RuntimeInit(JNIEnv* env)
222{
223 return jniRegisterNativeMethods(env, "com/android/internal/os/RuntimeInit",
224 gMethods, NELEM(gMethods));
225}
226
227// ----------------------------------------------------------------------
228
229/*static*/ JavaVM* AndroidRuntime::mJavaVM = NULL;
230
231
Jeff Brown4280c4a2012-03-15 17:48:02 -0700232AndroidRuntime::AndroidRuntime() :
233 mExitWithoutCleanup(false)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800234{
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700235 SkGraphics::Init();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800236 // this sets our preference for 16bit images during decode
237 // in case the src is opaque and 24bit
238 SkImageDecoder::SetDeviceConfig(SkBitmap::kRGB_565_Config);
Mike Reedfc8db532009-04-27 11:43:30 -0400239 // This cache is shared between browser native images, and java "purgeable"
240 // bitmaps. This globalpool is for images that do not either use the java
241 // heap, or are not backed by ashmem. See BitmapFactory.cpp for the key
242 // java call site.
243 SkImageRef_GlobalPool::SetRAMBudget(512 * 1024);
244 // There is also a global font cache, but its budget is specified in code
245 // see SkFontHost_android.cpp
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800246
247 // Pre-allocate enough space to hold a fair number of options.
248 mOptions.setCapacity(20);
249
250 assert(gCurRuntime == NULL); // one per process
251 gCurRuntime = this;
252}
253
254AndroidRuntime::~AndroidRuntime()
255{
256 SkGraphics::Term();
257}
258
259/*
260 * Register native methods using JNI.
261 */
262/*static*/ int AndroidRuntime::registerNativeMethods(JNIEnv* env,
263 const char* className, const JNINativeMethod* gMethods, int numMethods)
264{
265 return jniRegisterNativeMethods(env, className, gMethods, numMethods);
266}
267
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700268status_t AndroidRuntime::callMain(const char* className,
269 jclass clazz, int argc, const char* const argv[])
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800270{
271 JNIEnv* env;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800272 jmethodID methodId;
273
Steve Block5baa3a62011-12-20 16:23:08 +0000274 ALOGD("Calling main entry %s", className);
Dianne Hackborn08e60f22010-09-01 18:17:17 -0700275
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800276 env = getJNIEnv();
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700277 if (clazz == NULL || env == NULL) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800278 return UNKNOWN_ERROR;
279 }
280
281 methodId = env->GetStaticMethodID(clazz, "main", "([Ljava/lang/String;)V");
282 if (methodId == NULL) {
Steve Block3762c312012-01-06 19:20:56 +0000283 ALOGE("ERROR: could not find method %s.main(String[])\n", className);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800284 return UNKNOWN_ERROR;
285 }
286
287 /*
288 * We want to call main() with a String array with our arguments in it.
289 * Create an array and populate it.
290 */
291 jclass stringClass;
292 jobjectArray strArray;
293
294 stringClass = env->FindClass("java/lang/String");
295 strArray = env->NewObjectArray(argc, stringClass, NULL);
296
297 for (int i = 0; i < argc; i++) {
298 jstring argStr = env->NewStringUTF(argv[i]);
299 env->SetObjectArrayElement(strArray, i, argStr);
300 }
301
302 env->CallStaticVoidMethod(clazz, methodId, strArray);
303 return NO_ERROR;
304}
305
306/*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800307 * The VM calls this through the "exit" hook.
308 */
309static void runtime_exit(int code)
310{
Jeff Brown4280c4a2012-03-15 17:48:02 -0700311 gCurRuntime->exit(code);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800312}
313
314/*
315 * The VM calls this through the "vfprintf" hook.
316 *
317 * We ignore "fp" and just write the results to the log file.
318 */
319static void runtime_vfprintf(FILE* fp, const char* format, va_list ap)
320{
321 LOG_PRI_VA(ANDROID_LOG_INFO, "vm-printf", format, ap);
322}
323
Brad Fitzpatrick0bd52432010-12-13 16:52:35 -0800324/**
325 * The VM calls this when mutex contention debugging is enabled to
326 * determine whether or not the blocked thread was a "sensitive thread"
327 * for user responsiveness/smoothess.
328 *
329 * Our policy for this is whether or not we're tracing any StrictMode
330 * events on this thread (which we might've inherited via Binder calls
331 * into us)
332 */
333static bool runtime_isSensitiveThread() {
334 IPCThreadState* state = IPCThreadState::selfOrNull();
335 return state && state->getStrictModePolicy() != 0;
336}
337
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800338
339/**
340 * Add VM arguments to the to-be-executed VM
341 * Stops at first non '-' argument (also stops at an argument of '--')
342 * Returns the number of args consumed
343 */
344int AndroidRuntime::addVmArguments(int argc, const char* const argv[])
345{
346 int i;
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700347
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800348 for (i = 0; i<argc; i++) {
349 if (argv[i][0] != '-') {
350 return i;
351 }
352 if (argv[i][1] == '-' && argv[i][2] == 0) {
353 return i+1;
354 }
355
356 JavaVMOption opt;
357 memset(&opt, 0, sizeof(opt));
358 opt.optionString = (char*)argv[i];
359 mOptions.add(opt);
360 }
361 return i;
362}
363
364static int hasDir(const char* dir)
365{
366 struct stat s;
367 int res = stat(dir, &s);
368 if (res == 0) {
369 return S_ISDIR(s.st_mode);
370 }
371 return 0;
372}
373
374/*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800375 * Read the persistent locale.
376 */
377static void readLocale(char* language, char* region)
378{
379 char propLang[PROPERTY_VALUE_MAX], propRegn[PROPERTY_VALUE_MAX];
Brian Carlstrom171ea892010-08-24 21:27:52 -0700380
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800381 property_get("persist.sys.language", propLang, "");
382 property_get("persist.sys.country", propRegn, "");
383 if (*propLang == 0 && *propRegn == 0) {
384 /* Set to ro properties, default is en_US */
385 property_get("ro.product.locale.language", propLang, "en");
386 property_get("ro.product.locale.region", propRegn, "US");
387 }
388 strncat(language, propLang, 2);
389 strncat(region, propRegn, 2);
Steve Block5baa3a62011-12-20 16:23:08 +0000390 //ALOGD("language=%s region=%s\n", language, region);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800391}
392
Andy McFaddenf70188a2009-03-31 15:52:13 -0700393/*
Andy McFaddene4d81f22010-07-14 16:02:20 -0700394 * Parse a property containing space-separated options that should be
395 * passed directly to the VM, e.g. "-Xmx32m -verbose:gc -Xregenmap".
396 *
397 * This will cut up "extraOptsBuf" as we chop it into individual options.
398 *
399 * Adds the strings, if any, to mOptions.
400 */
401void AndroidRuntime::parseExtraOpts(char* extraOptsBuf)
402{
403 JavaVMOption opt;
404 char* start;
405 char* end;
406
407 memset(&opt, 0, sizeof(opt));
408 start = extraOptsBuf;
409 while (*start != '\0') {
410 while (*start == ' ') /* skip leading whitespace */
411 start++;
412 if (*start == '\0') /* was trailing ws, bail */
413 break;
414
415 end = start+1;
416 while (*end != ' ' && *end != '\0') /* find end of token */
417 end++;
418 if (*end == ' ')
419 *end++ = '\0'; /* mark end, advance to indicate more */
420
421 opt.optionString = start;
422 mOptions.add(opt);
423 start = end;
424 }
425}
426
427/*
Andy McFaddenf70188a2009-03-31 15:52:13 -0700428 * Start the Dalvik Virtual Machine.
429 *
430 * Various arguments, most determined by system properties, are passed in.
431 * The "mOptions" vector is updated.
432 *
433 * Returns 0 on success.
434 */
435int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800436{
Andy McFaddenf70188a2009-03-31 15:52:13 -0700437 int result = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800438 JavaVMInitArgs initArgs;
439 JavaVMOption opt;
440 char propBuf[PROPERTY_VALUE_MAX];
441 char stackTraceFileBuf[PROPERTY_VALUE_MAX];
442 char dexoptFlagsBuf[PROPERTY_VALUE_MAX];
443 char enableAssertBuf[sizeof("-ea:")-1 + PROPERTY_VALUE_MAX];
444 char jniOptsBuf[sizeof("-Xjniopts:")-1 + PROPERTY_VALUE_MAX];
Carl Shapiro38cfa8c2010-12-07 16:48:29 -0800445 char heapstartsizeOptsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
Dianne Hackbornbdcef702009-08-18 19:15:36 -0700446 char heapsizeOptsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
Carl Shapiro8cdf27c2011-01-19 12:33:12 -0800447 char heapgrowthlimitOptsBuf[sizeof("-XX:HeapGrowthLimit=")-1 + PROPERTY_VALUE_MAX];
Ian Rogers53250102012-09-23 16:38:03 -0700448 char heapminfreeOptsBuf[sizeof("-XX:HeapMinFree=")-1 + PROPERTY_VALUE_MAX];
449 char heapmaxfreeOptsBuf[sizeof("-XX:HeapMaxFree=")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartier7e4fdec2013-12-02 15:46:51 -0800450 char gctypeOptsBuf[sizeof("-Xgc:")-1 + PROPERTY_VALUE_MAX];
Ian Rogers53250102012-09-23 16:38:03 -0700451 char heaptargetutilizationOptsBuf[sizeof("-XX:HeapTargetUtilization=")-1 + PROPERTY_VALUE_MAX];
buzbeeb63de6d2013-05-24 13:14:08 -0700452 char jitcodecachesizeOptsBuf[sizeof("-Xjitcodecachesize:")-1 + PROPERTY_VALUE_MAX];
Andy McFaddene4d81f22010-07-14 16:02:20 -0700453 char extraOptsBuf[PROPERTY_VALUE_MAX];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800454 char* stackTraceFile = NULL;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800455 bool checkJni = false;
Andy McFaddene2b23e12009-04-03 11:09:46 -0700456 bool checkDexSum = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800457 bool logStdio = false;
Ben Cheng52b0e732009-06-19 13:31:12 -0700458 enum {
459 kEMDefault,
460 kEMIntPortable,
461 kEMIntFast,
Ben Cheng52b0e732009-06-19 13:31:12 -0700462 kEMJitCompiler,
Ben Cheng52b0e732009-06-19 13:31:12 -0700463 } executionMode = kEMDefault;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800464
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800465
466 property_get("dalvik.vm.checkjni", propBuf, "");
467 if (strcmp(propBuf, "true") == 0) {
468 checkJni = true;
469 } else if (strcmp(propBuf, "false") != 0) {
470 /* property is neither true nor false; fall back on kernel parameter */
471 property_get("ro.kernel.android.checkjni", propBuf, "");
472 if (propBuf[0] == '1') {
473 checkJni = true;
474 }
475 }
476
477 property_get("dalvik.vm.execution-mode", propBuf, "");
478 if (strcmp(propBuf, "int:portable") == 0) {
479 executionMode = kEMIntPortable;
480 } else if (strcmp(propBuf, "int:fast") == 0) {
481 executionMode = kEMIntFast;
Ben Cheng52b0e732009-06-19 13:31:12 -0700482 } else if (strcmp(propBuf, "int:jit") == 0) {
483 executionMode = kEMJitCompiler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800484 }
485
486 property_get("dalvik.vm.stack-trace-file", stackTraceFileBuf, "");
487
Andy McFaddene2b23e12009-04-03 11:09:46 -0700488 property_get("dalvik.vm.check-dex-sum", propBuf, "");
489 if (strcmp(propBuf, "true") == 0) {
490 checkDexSum = true;
491 }
492
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800493 property_get("log.redirect-stdio", propBuf, "");
494 if (strcmp(propBuf, "true") == 0) {
495 logStdio = true;
496 }
497
498 strcpy(enableAssertBuf, "-ea:");
499 property_get("dalvik.vm.enableassertions", enableAssertBuf+4, "");
500
501 strcpy(jniOptsBuf, "-Xjniopts:");
502 property_get("dalvik.vm.jniopts", jniOptsBuf+10, "");
503
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800504 /* route exit() to our handler */
505 opt.extraInfo = (void*) runtime_exit;
506 opt.optionString = "exit";
507 mOptions.add(opt);
508
509 /* route fprintf() to our handler */
510 opt.extraInfo = (void*) runtime_vfprintf;
511 opt.optionString = "vfprintf";
512 mOptions.add(opt);
513
Brad Fitzpatrick0bd52432010-12-13 16:52:35 -0800514 /* register the framework-specific "is sensitive thread" hook */
515 opt.extraInfo = (void*) runtime_isSensitiveThread;
516 opt.optionString = "sensitiveThread";
517 mOptions.add(opt);
518
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800519 opt.extraInfo = NULL;
520
521 /* enable verbose; standard options are { jni, gc, class } */
522 //options[curOpt++].optionString = "-verbose:jni";
523 opt.optionString = "-verbose:gc";
524 mOptions.add(opt);
525 //options[curOpt++].optionString = "-verbose:class";
526
Carl Shapiro9e4c8842010-12-08 12:14:46 -0800527 /*
528 * The default starting and maximum size of the heap. Larger
529 * values should be specified in a product property override.
530 */
Carl Shapiro38cfa8c2010-12-07 16:48:29 -0800531 strcpy(heapstartsizeOptsBuf, "-Xms");
Carl Shapiro9e4c8842010-12-08 12:14:46 -0800532 property_get("dalvik.vm.heapstartsize", heapstartsizeOptsBuf+4, "4m");
Carl Shapiro38cfa8c2010-12-07 16:48:29 -0800533 opt.optionString = heapstartsizeOptsBuf;
534 mOptions.add(opt);
Dianne Hackbornbdcef702009-08-18 19:15:36 -0700535 strcpy(heapsizeOptsBuf, "-Xmx");
536 property_get("dalvik.vm.heapsize", heapsizeOptsBuf+4, "16m");
Dianne Hackbornbdcef702009-08-18 19:15:36 -0700537 opt.optionString = heapsizeOptsBuf;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800538 mOptions.add(opt);
539
Elliott Hughes3f177d72012-04-12 16:02:56 -0700540 // Increase the main thread's interpreter stack size for bug 6315322.
541 opt.optionString = "-XX:mainThreadStackSize=24K";
542 mOptions.add(opt);
543
buzbeeb63de6d2013-05-24 13:14:08 -0700544 // Set the max jit code cache size. Note: size of 0 will disable the JIT.
545 strcpy(jitcodecachesizeOptsBuf, "-Xjitcodecachesize:");
546 property_get("dalvik.vm.jit.codecachesize", jitcodecachesizeOptsBuf+19, NULL);
547 if (jitcodecachesizeOptsBuf[19] != '\0') {
548 opt.optionString = jitcodecachesizeOptsBuf;
549 mOptions.add(opt);
550 }
551
Carl Shapiro8cdf27c2011-01-19 12:33:12 -0800552 strcpy(heapgrowthlimitOptsBuf, "-XX:HeapGrowthLimit=");
553 property_get("dalvik.vm.heapgrowthlimit", heapgrowthlimitOptsBuf+20, "");
554 if (heapgrowthlimitOptsBuf[20] != '\0') {
555 opt.optionString = heapgrowthlimitOptsBuf;
556 mOptions.add(opt);
557 }
558
Ian Rogers53250102012-09-23 16:38:03 -0700559 strcpy(heapminfreeOptsBuf, "-XX:HeapMinFree=");
560 property_get("dalvik.vm.heapminfree", heapminfreeOptsBuf+16, "");
561 if (heapminfreeOptsBuf[16] != '\0') {
562 opt.optionString = heapminfreeOptsBuf;
563 mOptions.add(opt);
564 }
565
566 strcpy(heapmaxfreeOptsBuf, "-XX:HeapMaxFree=");
567 property_get("dalvik.vm.heapmaxfree", heapmaxfreeOptsBuf+16, "");
568 if (heapmaxfreeOptsBuf[16] != '\0') {
569 opt.optionString = heapmaxfreeOptsBuf;
570 mOptions.add(opt);
571 }
572
573 strcpy(heaptargetutilizationOptsBuf, "-XX:HeapTargetUtilization=");
574 property_get("dalvik.vm.heaptargetutilization", heaptargetutilizationOptsBuf+26, "");
Ian Rogers7fef2b82012-10-01 14:54:24 -0700575 if (heaptargetutilizationOptsBuf[26] != '\0') {
Ian Rogers53250102012-09-23 16:38:03 -0700576 opt.optionString = heaptargetutilizationOptsBuf;
577 mOptions.add(opt);
578 }
579
Mathieu Chartiere6c22412013-08-20 17:16:03 -0700580 property_get("ro.config.low_ram", propBuf, "");
581 if (strcmp(propBuf, "true") == 0) {
582 opt.optionString = "-XX:LowMemoryMode";
583 mOptions.add(opt);
584 }
585
Mathieu Chartier7e4fdec2013-12-02 15:46:51 -0800586 strcpy(gctypeOptsBuf, "-Xgc:");
587 property_get("dalvik.vm.gctype", gctypeOptsBuf+5, "");
588 if (gctypeOptsBuf[5] != '\0') {
589 opt.optionString = gctypeOptsBuf;
590 mOptions.add(opt);
591 }
592
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800593 /*
594 * Enable or disable dexopt features, such as bytecode verification and
595 * calculation of register maps for precise GC.
596 */
597 property_get("dalvik.vm.dexopt-flags", dexoptFlagsBuf, "");
598 if (dexoptFlagsBuf[0] != '\0') {
599 const char* opc;
600 const char* val;
601
602 opc = strstr(dexoptFlagsBuf, "v="); /* verification */
603 if (opc != NULL) {
604 switch (*(opc+2)) {
605 case 'n': val = "-Xverify:none"; break;
606 case 'r': val = "-Xverify:remote"; break;
607 case 'a': val = "-Xverify:all"; break;
608 default: val = NULL; break;
609 }
610
611 if (val != NULL) {
612 opt.optionString = val;
613 mOptions.add(opt);
614 }
615 }
616
617 opc = strstr(dexoptFlagsBuf, "o="); /* optimization */
618 if (opc != NULL) {
619 switch (*(opc+2)) {
620 case 'n': val = "-Xdexopt:none"; break;
621 case 'v': val = "-Xdexopt:verified"; break;
622 case 'a': val = "-Xdexopt:all"; break;
Brian Carlstrom08065b92011-04-01 15:49:41 -0700623 case 'f': val = "-Xdexopt:full"; break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800624 default: val = NULL; break;
625 }
626
627 if (val != NULL) {
628 opt.optionString = val;
629 mOptions.add(opt);
630 }
631 }
632
633 opc = strstr(dexoptFlagsBuf, "m=y"); /* register map */
634 if (opc != NULL) {
635 opt.optionString = "-Xgenregmap";
636 mOptions.add(opt);
The Android Open Source Project7b0b1ed2009-03-18 22:20:26 -0700637
638 /* turn on precise GC while we're at it */
639 opt.optionString = "-Xgc:precise";
640 mOptions.add(opt);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800641 }
642 }
643
644 /* enable debugging; set suspend=y to pause during VM init */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800645 /* use android ADB transport */
646 opt.optionString =
647 "-agentlib:jdwp=transport=dt_android_adb,suspend=n,server=y";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800648 mOptions.add(opt);
649
Steve Block5baa3a62011-12-20 16:23:08 +0000650 ALOGD("CheckJNI is %s\n", checkJni ? "ON" : "OFF");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800651 if (checkJni) {
652 /* extended JNI checking */
653 opt.optionString = "-Xcheck:jni";
654 mOptions.add(opt);
655
656 /* set a cap on JNI global references */
657 opt.optionString = "-Xjnigreflimit:2000";
658 mOptions.add(opt);
659
660 /* with -Xcheck:jni, this provides a JNI function call trace */
661 //opt.optionString = "-verbose:jni";
662 //mOptions.add(opt);
663 }
Ben Cheng52b0e732009-06-19 13:31:12 -0700664
Carl Shapirod8f3ec62010-04-12 16:31:59 -0700665 char lockProfThresholdBuf[sizeof("-Xlockprofthreshold:") + sizeof(propBuf)];
666 property_get("dalvik.vm.lockprof.threshold", propBuf, "");
667 if (strlen(propBuf) > 0) {
668 strcpy(lockProfThresholdBuf, "-Xlockprofthreshold:");
669 strcat(lockProfThresholdBuf, propBuf);
670 opt.optionString = lockProfThresholdBuf;
671 mOptions.add(opt);
672 }
673
Ben Cheng52b0e732009-06-19 13:31:12 -0700674 /* Force interpreter-only mode for selected opcodes. Eg "1-0a,3c,f1-ff" */
675 char jitOpBuf[sizeof("-Xjitop:") + PROPERTY_VALUE_MAX];
676 property_get("dalvik.vm.jit.op", propBuf, "");
677 if (strlen(propBuf) > 0) {
678 strcpy(jitOpBuf, "-Xjitop:");
679 strcat(jitOpBuf, propBuf);
680 opt.optionString = jitOpBuf;
681 mOptions.add(opt);
682 }
683
Ben Cheng52b0e732009-06-19 13:31:12 -0700684 /* Force interpreter-only mode for selected methods */
685 char jitMethodBuf[sizeof("-Xjitmethod:") + PROPERTY_VALUE_MAX];
686 property_get("dalvik.vm.jit.method", propBuf, "");
687 if (strlen(propBuf) > 0) {
688 strcpy(jitMethodBuf, "-Xjitmethod:");
689 strcat(jitMethodBuf, propBuf);
690 opt.optionString = jitMethodBuf;
691 mOptions.add(opt);
692 }
Ben Cheng52b0e732009-06-19 13:31:12 -0700693
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800694 if (executionMode == kEMIntPortable) {
695 opt.optionString = "-Xint:portable";
696 mOptions.add(opt);
697 } else if (executionMode == kEMIntFast) {
698 opt.optionString = "-Xint:fast";
699 mOptions.add(opt);
Ben Cheng52b0e732009-06-19 13:31:12 -0700700 } else if (executionMode == kEMJitCompiler) {
701 opt.optionString = "-Xint:jit";
702 mOptions.add(opt);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800703 }
Andy McFaddene2b23e12009-04-03 11:09:46 -0700704
705 if (checkDexSum) {
706 /* perform additional DEX checksum tests */
707 opt.optionString = "-Xcheckdexsum";
708 mOptions.add(opt);
709 }
710
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800711 if (logStdio) {
712 /* convert stdout/stderr to log messages */
713 opt.optionString = "-Xlog-stdio";
714 mOptions.add(opt);
715 }
716
717 if (enableAssertBuf[4] != '\0') {
718 /* accept "all" to mean "all classes and packages" */
719 if (strcmp(enableAssertBuf+4, "all") == 0)
720 enableAssertBuf[3] = '\0';
Steve Block6215d3f2012-01-04 20:05:49 +0000721 ALOGI("Assertions enabled: '%s'\n", enableAssertBuf);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800722 opt.optionString = enableAssertBuf;
723 mOptions.add(opt);
724 } else {
Steve Block71f2cf12011-10-20 11:56:00 +0100725 ALOGV("Assertions disabled\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800726 }
727
728 if (jniOptsBuf[10] != '\0') {
Steve Block6215d3f2012-01-04 20:05:49 +0000729 ALOGI("JNI options: '%s'\n", jniOptsBuf);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800730 opt.optionString = jniOptsBuf;
731 mOptions.add(opt);
732 }
733
734 if (stackTraceFileBuf[0] != '\0') {
735 static const char* stfOptName = "-Xstacktracefile:";
736
737 stackTraceFile = (char*) malloc(strlen(stfOptName) +
738 strlen(stackTraceFileBuf) +1);
739 strcpy(stackTraceFile, stfOptName);
740 strcat(stackTraceFile, stackTraceFileBuf);
741 opt.optionString = stackTraceFile;
742 mOptions.add(opt);
743 }
Andy McFaddene4d81f22010-07-14 16:02:20 -0700744
745 /* extra options; parse this late so it overrides others */
746 property_get("dalvik.vm.extra-opts", extraOptsBuf, "");
747 parseExtraOpts(extraOptsBuf);
748
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800749 /* Set the properties for locale */
750 {
751 char langOption[sizeof("-Duser.language=") + 3];
752 char regionOption[sizeof("-Duser.region=") + 3];
753 strcpy(langOption, "-Duser.language=");
754 strcpy(regionOption, "-Duser.region=");
755 readLocale(langOption, regionOption);
756 opt.extraInfo = NULL;
757 opt.optionString = langOption;
758 mOptions.add(opt);
759 opt.optionString = regionOption;
760 mOptions.add(opt);
761 }
762
763 /*
764 * We don't have /tmp on the device, but we often have an SD card. Apps
765 * shouldn't use this, but some test suites might want to exercise it.
766 */
767 opt.optionString = "-Djava.io.tmpdir=/sdcard";
768 mOptions.add(opt);
769
770 initArgs.version = JNI_VERSION_1_4;
771 initArgs.options = mOptions.editArray();
772 initArgs.nOptions = mOptions.size();
773 initArgs.ignoreUnrecognized = JNI_FALSE;
774
775 /*
776 * Initialize the VM.
777 *
778 * The JavaVM* is essentially per-process, and the JNIEnv* is per-thread.
779 * If this call succeeds, the VM is ready, and we can start issuing
780 * JNI calls.
781 */
Andy McFaddenf70188a2009-03-31 15:52:13 -0700782 if (JNI_CreateJavaVM(pJavaVM, pEnv, &initArgs) < 0) {
Steve Block3762c312012-01-06 19:20:56 +0000783 ALOGE("JNI_CreateJavaVM failed\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800784 goto bail;
785 }
786
Andy McFaddenf70188a2009-03-31 15:52:13 -0700787 result = 0;
788
789bail:
790 free(stackTraceFile);
791 return result;
792}
793
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700794char* AndroidRuntime::toSlashClassName(const char* className)
795{
796 char* result = strdup(className);
797 for (char* cp = result; *cp != '\0'; cp++) {
798 if (*cp == '.') {
799 *cp = '/';
800 }
801 }
802 return result;
803}
804
Andy McFaddenf70188a2009-03-31 15:52:13 -0700805/*
806 * Start the Android runtime. This involves starting the virtual machine
807 * and calling the "static void main(String[] args)" method in the class
808 * named by "className".
Jeff Brownebed7d62011-05-16 17:08:42 -0700809 *
810 * Passes the main function two arguments, the class name and the specified
811 * options string.
Andy McFaddenf70188a2009-03-31 15:52:13 -0700812 */
Jeff Brownebed7d62011-05-16 17:08:42 -0700813void AndroidRuntime::start(const char* className, const char* options)
Andy McFaddenf70188a2009-03-31 15:52:13 -0700814{
Steve Block5baa3a62011-12-20 16:23:08 +0000815 ALOGD("\n>>>>>> AndroidRuntime START %s <<<<<<\n",
Dianne Hackborn08e60f22010-09-01 18:17:17 -0700816 className != NULL ? className : "(unknown)");
Andy McFaddenf70188a2009-03-31 15:52:13 -0700817
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700818 /*
819 * 'startSystemServer == true' means runtime is obsolete and not run from
Andy McFaddenf70188a2009-03-31 15:52:13 -0700820 * init.rc anymore, so we print out the boot start event here.
821 */
Jeff Brownebed7d62011-05-16 17:08:42 -0700822 if (strcmp(options, "start-system-server") == 0) {
Andy McFaddenf70188a2009-03-31 15:52:13 -0700823 /* track our progress through the boot sequence */
824 const int LOG_BOOT_PROGRESS_START = 3000;
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700825 LOG_EVENT_LONG(LOG_BOOT_PROGRESS_START,
Andy McFaddenf70188a2009-03-31 15:52:13 -0700826 ns2ms(systemTime(SYSTEM_TIME_MONOTONIC)));
827 }
828
829 const char* rootDir = getenv("ANDROID_ROOT");
830 if (rootDir == NULL) {
831 rootDir = "/system";
832 if (!hasDir("/system")) {
833 LOG_FATAL("No root directory specified, and /android does not exist.");
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700834 return;
Andy McFaddenf70188a2009-03-31 15:52:13 -0700835 }
836 setenv("ANDROID_ROOT", rootDir, 1);
837 }
838
839 //const char* kernelHack = getenv("LD_ASSUME_KERNEL");
Steve Block5baa3a62011-12-20 16:23:08 +0000840 //ALOGD("Found LD_ASSUME_KERNEL='%s'\n", kernelHack);
Andy McFaddenf70188a2009-03-31 15:52:13 -0700841
842 /* start the virtual machine */
Brian Carlstrom9f8203a2013-06-19 13:49:36 -0700843 JniInvocation jni_invocation;
844 jni_invocation.Init(NULL);
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700845 JNIEnv* env;
846 if (startVm(&mJavaVM, &env) != 0) {
847 return;
848 }
849 onVmCreated(env);
Andy McFaddenf70188a2009-03-31 15:52:13 -0700850
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800851 /*
852 * Register android functions.
853 */
854 if (startReg(env) < 0) {
Steve Block3762c312012-01-06 19:20:56 +0000855 ALOGE("Unable to register all android natives\n");
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700856 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800857 }
858
859 /*
860 * We want to call main() with a String array with arguments in it.
Jeff Brownebed7d62011-05-16 17:08:42 -0700861 * At present we have two arguments, the class name and an option string.
862 * Create an array to hold them.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800863 */
864 jclass stringClass;
865 jobjectArray strArray;
866 jstring classNameStr;
Jeff Brownebed7d62011-05-16 17:08:42 -0700867 jstring optionsStr;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800868
869 stringClass = env->FindClass("java/lang/String");
870 assert(stringClass != NULL);
871 strArray = env->NewObjectArray(2, stringClass, NULL);
872 assert(strArray != NULL);
873 classNameStr = env->NewStringUTF(className);
874 assert(classNameStr != NULL);
875 env->SetObjectArrayElement(strArray, 0, classNameStr);
Jeff Brownebed7d62011-05-16 17:08:42 -0700876 optionsStr = env->NewStringUTF(options);
877 env->SetObjectArrayElement(strArray, 1, optionsStr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800878
879 /*
880 * Start VM. This thread becomes the main thread of the VM, and will
881 * not return until the VM exits.
882 */
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700883 char* slashClassName = toSlashClassName(className);
884 jclass startClass = env->FindClass(slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800885 if (startClass == NULL) {
Steve Block3762c312012-01-06 19:20:56 +0000886 ALOGE("JavaVM unable to locate class '%s'\n", slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800887 /* keep going */
888 } else {
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700889 jmethodID startMeth = env->GetStaticMethodID(startClass, "main",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800890 "([Ljava/lang/String;)V");
891 if (startMeth == NULL) {
Steve Block3762c312012-01-06 19:20:56 +0000892 ALOGE("JavaVM unable to find main() in '%s'\n", className);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800893 /* keep going */
894 } else {
895 env->CallStaticVoidMethod(startClass, startMeth, strArray);
896
897#if 0
898 if (env->ExceptionCheck())
899 threadExitUncaughtException(env);
900#endif
901 }
902 }
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700903 free(slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800904
Steve Block5baa3a62011-12-20 16:23:08 +0000905 ALOGD("Shutting down VM\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800906 if (mJavaVM->DetachCurrentThread() != JNI_OK)
Steve Block8564c8d2012-01-05 23:22:43 +0000907 ALOGW("Warning: unable to detach main thread\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800908 if (mJavaVM->DestroyJavaVM() != 0)
Steve Block8564c8d2012-01-05 23:22:43 +0000909 ALOGW("Warning: VM did not shut down cleanly\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800910}
911
Jeff Brown4280c4a2012-03-15 17:48:02 -0700912void AndroidRuntime::exit(int code)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800913{
Jeff Brown4280c4a2012-03-15 17:48:02 -0700914 if (mExitWithoutCleanup) {
915 ALOGI("VM exiting with result code %d, cleanup skipped.", code);
916 ::_exit(code);
917 } else {
918 ALOGI("VM exiting with result code %d.", code);
919 onExit(code);
920 ::exit(code);
921 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800922}
923
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700924void AndroidRuntime::onVmCreated(JNIEnv* env)
925{
926 // If AndroidRuntime had anything to do here, we'd have done it in 'start'.
927}
928
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800929/*
930 * Get the JNIEnv pointer for this thread.
931 *
932 * Returns NULL if the slot wasn't allocated or populated.
933 */
934/*static*/ JNIEnv* AndroidRuntime::getJNIEnv()
935{
936 JNIEnv* env;
937 JavaVM* vm = AndroidRuntime::getJavaVM();
938 assert(vm != NULL);
939
940 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK)
941 return NULL;
942 return env;
943}
944
945/*
946 * Makes the current thread visible to the VM.
947 *
948 * The JNIEnv pointer returned is only valid for the current thread, and
949 * thus must be tucked into thread-local storage.
950 */
951static int javaAttachThread(const char* threadName, JNIEnv** pEnv)
952{
953 JavaVMAttachArgs args;
954 JavaVM* vm;
955 jint result;
956
957 vm = AndroidRuntime::getJavaVM();
958 assert(vm != NULL);
959
960 args.version = JNI_VERSION_1_4;
961 args.name = (char*) threadName;
962 args.group = NULL;
963
964 result = vm->AttachCurrentThread(pEnv, (void*) &args);
965 if (result != JNI_OK)
Steve Block6215d3f2012-01-04 20:05:49 +0000966 ALOGI("NOTE: attach of thread '%s' failed\n", threadName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800967
968 return result;
969}
970
971/*
972 * Detach the current thread from the set visible to the VM.
973 */
974static int javaDetachThread(void)
975{
976 JavaVM* vm;
977 jint result;
978
979 vm = AndroidRuntime::getJavaVM();
980 assert(vm != NULL);
981
982 result = vm->DetachCurrentThread();
983 if (result != JNI_OK)
Steve Block3762c312012-01-06 19:20:56 +0000984 ALOGE("ERROR: thread detach failed\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800985 return result;
986}
987
988/*
989 * When starting a native thread that will be visible from the VM, we
990 * bounce through this to get the right attach/detach action.
991 * Note that this function calls free(args)
992 */
993/*static*/ int AndroidRuntime::javaThreadShell(void* args) {
994 void* start = ((void**)args)[0];
995 void* userData = ((void **)args)[1];
996 char* name = (char*) ((void **)args)[2]; // we own this storage
997 free(args);
998 JNIEnv* env;
999 int result;
1000
1001 /* hook us into the VM */
1002 if (javaAttachThread(name, &env) != JNI_OK)
1003 return -1;
1004
1005 /* start the thread running */
1006 result = (*(android_thread_func_t)start)(userData);
1007
1008 /* unhook us */
1009 javaDetachThread();
1010 free(name);
1011
1012 return result;
1013}
1014
1015/*
1016 * This is invoked from androidCreateThreadEtc() via the callback
1017 * set with androidSetCreateThreadFunc().
1018 *
1019 * We need to create the new thread in such a way that it gets hooked
1020 * into the VM before it really starts executing.
1021 */
1022/*static*/ int AndroidRuntime::javaCreateThreadEtc(
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001023 android_thread_func_t entryFunction,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001024 void* userData,
1025 const char* threadName,
1026 int32_t threadPriority,
1027 size_t threadStackSize,
1028 android_thread_id_t* threadId)
1029{
1030 void** args = (void**) malloc(3 * sizeof(void*)); // javaThreadShell must free
1031 int result;
1032
Mike Lockwood32f2e622013-10-10 10:11:27 -07001033 if (!threadName)
1034 threadName = "unnamed thread";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001035
1036 args[0] = (void*) entryFunction;
1037 args[1] = userData;
1038 args[2] = (void*) strdup(threadName); // javaThreadShell must free
1039
1040 result = androidCreateRawThreadEtc(AndroidRuntime::javaThreadShell, args,
1041 threadName, threadPriority, threadStackSize, threadId);
1042 return result;
1043}
1044
1045/*
1046 * Create a thread that is visible from the VM.
1047 *
1048 * This is called from elsewhere in the library.
1049 */
Mike Lockwoodf602d362010-06-20 14:28:16 -07001050/*static*/ android_thread_id_t AndroidRuntime::createJavaThread(const char* name,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001051 void (*start)(void *), void* arg)
1052{
Mike Lockwoodf602d362010-06-20 14:28:16 -07001053 android_thread_id_t threadId = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001054 javaCreateThreadEtc((android_thread_func_t) start, arg, name,
Mike Lockwoodf602d362010-06-20 14:28:16 -07001055 ANDROID_PRIORITY_DEFAULT, 0, &threadId);
1056 return threadId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001057}
1058
1059#if 0
1060static void quickTest(void* arg)
1061{
1062 const char* str = (const char*) arg;
1063
1064 printf("In quickTest: %s\n", str);
1065}
1066#endif
1067
1068#ifdef NDEBUG
1069 #define REG_JNI(name) { name }
1070 struct RegJNIRec {
1071 int (*mProc)(JNIEnv*);
1072 };
1073#else
1074 #define REG_JNI(name) { name, #name }
1075 struct RegJNIRec {
1076 int (*mProc)(JNIEnv*);
1077 const char* mName;
1078 };
1079#endif
1080
1081typedef void (*RegJAMProc)();
1082
1083static int register_jni_procs(const RegJNIRec array[], size_t count, JNIEnv* env)
1084{
1085 for (size_t i = 0; i < count; i++) {
1086 if (array[i].mProc(env) < 0) {
1087#ifndef NDEBUG
Steve Block5baa3a62011-12-20 16:23:08 +00001088 ALOGD("----------!!! %s failed to load\n", array[i].mName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001089#endif
1090 return -1;
1091 }
1092 }
1093 return 0;
1094}
1095
1096static void register_jam_procs(const RegJAMProc array[], size_t count)
1097{
1098 for (size_t i = 0; i < count; i++) {
1099 array[i]();
1100 }
1101}
1102
1103static const RegJNIRec gRegJNI[] = {
1104 REG_JNI(register_android_debug_JNITest),
1105 REG_JNI(register_com_android_internal_os_RuntimeInit),
1106 REG_JNI(register_android_os_SystemClock),
1107 REG_JNI(register_android_util_EventLog),
1108 REG_JNI(register_android_util_Log),
1109 REG_JNI(register_android_util_FloatMath),
1110 REG_JNI(register_android_text_format_Time),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001111 REG_JNI(register_android_content_AssetManager),
1112 REG_JNI(register_android_content_StringBlock),
1113 REG_JNI(register_android_content_XmlBlock),
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001114 REG_JNI(register_android_emoji_EmojiFactory),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001115 REG_JNI(register_android_text_AndroidCharacter),
Doug Feltdae8e942010-02-24 14:33:15 -08001116 REG_JNI(register_android_text_AndroidBidi),
Jeff Brown9f25b7f2012-04-10 14:30:49 -07001117 REG_JNI(register_android_view_InputDevice),
1118 REG_JNI(register_android_view_KeyCharacterMap),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001119 REG_JNI(register_android_os_Process),
Andreas Hubera8079bf2010-11-16 14:40:31 -08001120 REG_JNI(register_android_os_SystemProperties),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001121 REG_JNI(register_android_os_Binder),
Jeff Sharkeyd84e1ce2012-03-06 18:26:19 -08001122 REG_JNI(register_android_os_Parcel),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001123 REG_JNI(register_android_nio_utils),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001124 REG_JNI(register_android_graphics_Graphics),
Chris Craik54389792013-12-20 13:28:11 -08001125 REG_JNI(register_android_view_DisplayEventReceiver),
1126 REG_JNI(register_android_view_DisplayList),
Romain Guy3b748a42013-04-17 18:54:38 -07001127 REG_JNI(register_android_view_GraphicBuffer),
Romain Guye4d01122010-06-16 18:44:05 -07001128 REG_JNI(register_android_view_GLES20Canvas),
John Reck30835792013-11-07 14:21:24 -08001129 REG_JNI(register_android_view_GLRenderer),
John Reckcec24ae2013-11-05 13:27:50 -08001130 REG_JNI(register_android_view_ThreadedRenderer),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001131 REG_JNI(register_android_view_Surface),
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001132 REG_JNI(register_android_view_SurfaceControl),
Jeff Brown64a55af2012-08-26 02:47:39 -07001133 REG_JNI(register_android_view_SurfaceSession),
Romain Guy8f0095c2011-05-02 17:24:22 -07001134 REG_JNI(register_android_view_TextureView),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001135 REG_JNI(register_com_google_android_gles_jni_EGLImpl),
1136 REG_JNI(register_com_google_android_gles_jni_GLImpl),
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -07001137 REG_JNI(register_android_opengl_jni_EGL14),
Jesse Hall237c2b82013-05-06 11:36:57 -07001138 REG_JNI(register_android_opengl_jni_EGLExt),
Jack Palevich1c4907e2009-04-13 16:22:25 -07001139 REG_JNI(register_android_opengl_jni_GLES10),
1140 REG_JNI(register_android_opengl_jni_GLES10Ext),
1141 REG_JNI(register_android_opengl_jni_GLES11),
1142 REG_JNI(register_android_opengl_jni_GLES11Ext),
Jack Palevich560814f2009-11-19 16:34:55 +08001143 REG_JNI(register_android_opengl_jni_GLES20),
Jesse Halld877efe2013-04-29 15:59:35 -07001144 REG_JNI(register_android_opengl_jni_GLES30),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001145
1146 REG_JNI(register_android_graphics_Bitmap),
1147 REG_JNI(register_android_graphics_BitmapFactory),
Wei-Ta Chen6b849e22010-09-07 17:32:18 +08001148 REG_JNI(register_android_graphics_BitmapRegionDecoder),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001149 REG_JNI(register_android_graphics_Camera),
Leon Scroggins IIId0d7eaf2013-09-06 16:46:57 -04001150 REG_JNI(register_android_graphics_CreateJavaOutputStreamAdaptor),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001151 REG_JNI(register_android_graphics_Canvas),
1152 REG_JNI(register_android_graphics_ColorFilter),
1153 REG_JNI(register_android_graphics_DrawFilter),
1154 REG_JNI(register_android_graphics_Interpolator),
1155 REG_JNI(register_android_graphics_LayerRasterizer),
1156 REG_JNI(register_android_graphics_MaskFilter),
1157 REG_JNI(register_android_graphics_Matrix),
1158 REG_JNI(register_android_graphics_Movie),
1159 REG_JNI(register_android_graphics_NinePatch),
1160 REG_JNI(register_android_graphics_Paint),
1161 REG_JNI(register_android_graphics_Path),
1162 REG_JNI(register_android_graphics_PathMeasure),
1163 REG_JNI(register_android_graphics_PathEffect),
1164 REG_JNI(register_android_graphics_Picture),
1165 REG_JNI(register_android_graphics_PorterDuff),
1166 REG_JNI(register_android_graphics_Rasterizer),
1167 REG_JNI(register_android_graphics_Region),
1168 REG_JNI(register_android_graphics_Shader),
Jamie Gennisaa0ce332011-01-06 17:04:26 -08001169 REG_JNI(register_android_graphics_SurfaceTexture),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001170 REG_JNI(register_android_graphics_Typeface),
1171 REG_JNI(register_android_graphics_Xfermode),
Wei-Ta Chenbca2d612009-11-30 17:52:05 +08001172 REG_JNI(register_android_graphics_YuvImage),
Svetoslav6811f4e2013-09-18 15:58:28 -07001173 REG_JNI(register_android_graphics_pdf_PdfDocument),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001174
1175 REG_JNI(register_android_database_CursorWindow),
Jeff Browne5360fb2011-10-31 17:48:13 -07001176 REG_JNI(register_android_database_SQLiteConnection),
1177 REG_JNI(register_android_database_SQLiteGlobal),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001178 REG_JNI(register_android_database_SQLiteDebug),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001179 REG_JNI(register_android_os_Debug),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001180 REG_JNI(register_android_os_FileObserver),
Christopher Tatefa9e7c02010-05-06 12:07:10 -07001181 REG_JNI(register_android_os_MessageQueue),
Stephen Smalleyc07fca32012-01-13 08:31:39 -05001182 REG_JNI(register_android_os_SELinux),
Jeff Brown481c1572012-03-09 14:41:15 -08001183 REG_JNI(register_android_os_Trace),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001184 REG_JNI(register_android_os_UEventObserver),
1185 REG_JNI(register_android_net_LocalSocketImpl),
1186 REG_JNI(register_android_net_NetworkUtils),
Dan Egnor2b4abcd2010-04-07 17:30:50 -07001187 REG_JNI(register_android_net_TrafficStats),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001188 REG_JNI(register_android_os_MemoryFile),
1189 REG_JNI(register_com_android_internal_os_ZygoteInit),
1190 REG_JNI(register_android_hardware_Camera),
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -07001191 REG_JNI(register_android_hardware_camera2_CameraMetadata),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001192 REG_JNI(register_android_hardware_SensorManager),
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04001193 REG_JNI(register_android_hardware_SerialPort),
Mike Lockwoode7d511e2010-12-30 13:39:37 -05001194 REG_JNI(register_android_hardware_UsbDevice),
Mike Lockwoodacc29cc2011-03-11 08:18:08 -05001195 REG_JNI(register_android_hardware_UsbDeviceConnection),
Mike Lockwoode7d511e2010-12-30 13:39:37 -05001196 REG_JNI(register_android_hardware_UsbRequest),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001197 REG_JNI(register_android_media_AudioRecord),
1198 REG_JNI(register_android_media_AudioSystem),
1199 REG_JNI(register_android_media_AudioTrack),
1200 REG_JNI(register_android_media_JetPlayer),
Jeff Browncbad9762012-09-04 21:57:59 -07001201 REG_JNI(register_android_media_RemoteDisplay),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001202 REG_JNI(register_android_media_ToneGenerator),
1203
1204 REG_JNI(register_android_opengl_classes),
JP Abgrall98a4f7e2011-09-02 15:36:33 -07001205 REG_JNI(register_android_server_NetworkManagementSocketTagger),
Christopher Tateecaa7b42010-06-04 14:55:02 -07001206 REG_JNI(register_android_server_Watchdog),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001207 REG_JNI(register_android_ddm_DdmHandleNativeHeap),
Joe Onorato1cf58742009-06-12 11:06:24 -07001208 REG_JNI(register_android_backup_BackupDataInput),
Joe Onoratod2110db2009-05-19 13:41:21 -07001209 REG_JNI(register_android_backup_BackupDataOutput),
Joe Onorato06290a42009-06-18 20:10:37 -07001210 REG_JNI(register_android_backup_FileBackupHelperBase),
Joe Onorato4ababd92009-06-25 18:29:18 -04001211 REG_JNI(register_android_backup_BackupHelperDispatcher),
Christopher Tate4a627c72011-04-01 14:43:32 -07001212 REG_JNI(register_android_app_backup_FullBackup),
Chet Haase9c1e23b2011-03-24 10:51:31 -07001213 REG_JNI(register_android_app_ActivityThread),
Dianne Hackborn69969e42010-05-04 11:40:40 -07001214 REG_JNI(register_android_app_NativeActivity),
Jeff Brown46b9ac02010-04-22 18:58:52 -07001215 REG_JNI(register_android_view_InputChannel),
Jeff Brown32cbc38552011-12-01 14:01:49 -08001216 REG_JNI(register_android_view_InputEventReceiver),
Jeff Brownc28867a2013-03-26 15:42:39 -07001217 REG_JNI(register_android_view_InputEventSender),
Michael Wrighta44dd262013-04-10 21:12:00 -07001218 REG_JNI(register_android_view_InputQueue),
Jeff Brown46b9ac02010-04-22 18:58:52 -07001219 REG_JNI(register_android_view_KeyEvent),
1220 REG_JNI(register_android_view_MotionEvent),
Jeff Brown2352b972011-04-12 22:39:53 -07001221 REG_JNI(register_android_view_PointerIcon),
Jeff Brown2ed24622011-03-14 19:39:54 -07001222 REG_JNI(register_android_view_VelocityTracker),
Kenny Root02c87302010-07-01 08:10:18 -07001223
1224 REG_JNI(register_android_content_res_ObbScanner),
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -07001225 REG_JNI(register_android_content_res_Configuration),
Chet Haase6e0ecb42010-11-03 19:41:18 -07001226
1227 REG_JNI(register_android_animation_PropertyValuesHolder),
Kenny Root66269ea2011-07-12 14:14:01 -07001228 REG_JNI(register_com_android_internal_content_NativeLibraryHelper),
Jeff Sharkey9a2c2a62013-01-14 16:48:51 -08001229 REG_JNI(register_com_android_internal_net_NetworkStatsFactory),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001230};
1231
1232/*
1233 * Register android native functions with the VM.
1234 */
1235/*static*/ int AndroidRuntime::startReg(JNIEnv* env)
1236{
1237 /*
1238 * This hook causes all future threads created in this process to be
1239 * attached to the JavaVM. (This needs to go away in favor of JNI
1240 * Attach calls.)
1241 */
1242 androidSetCreateThreadFunc((android_create_thread_fn) javaCreateThreadEtc);
1243
Steve Block71f2cf12011-10-20 11:56:00 +01001244 ALOGV("--- registering native functions ---\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001245
1246 /*
1247 * Every "register" function calls one or more things that return
1248 * a local reference (e.g. FindClass). Because we haven't really
1249 * started the VM yet, they're all getting stored in the base frame
1250 * and never released. Use Push/Pop to manage the storage.
1251 */
1252 env->PushLocalFrame(200);
1253
1254 if (register_jni_procs(gRegJNI, NELEM(gRegJNI), env) < 0) {
1255 env->PopLocalFrame(NULL);
1256 return -1;
1257 }
1258 env->PopLocalFrame(NULL);
1259
1260 //createJavaThread("fubar", quickTest, (void*) "hello");
1261
1262 return 0;
1263}
1264
1265AndroidRuntime* AndroidRuntime::getRuntime()
1266{
1267 return gCurRuntime;
1268}
1269
1270/**
1271 * Used by WithFramework to register native functions.
1272 */
1273extern "C"
1274jint Java_com_android_internal_util_WithFramework_registerNatives(
1275 JNIEnv* env, jclass clazz) {
1276 return register_jni_procs(gRegJNI, NELEM(gRegJNI), env);
1277}
1278
1279/**
1280 * Used by LoadClass to register native functions.
1281 */
1282extern "C"
1283jint Java_LoadClass_registerNatives(JNIEnv* env, jclass clazz) {
1284 return register_jni_procs(gRegJNI, NELEM(gRegJNI), env);
1285}
1286
1287} // namespace android