blob: bffbab7f1e695550b7f6e75ac6cfe4c36d7ccf45 [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>
32
33#include "jni.h"
34#include "JNIHelp.h"
Brian Carlstrom9f8203a2013-06-19 13:49:36 -070035#include "JniInvocation.h"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036#include "android_util_Binder.h"
37
38#include <stdio.h>
39#include <signal.h>
40#include <sys/stat.h>
41#include <sys/types.h>
42#include <signal.h>
43#include <dirent.h>
44#include <assert.h>
45
46
47using namespace android;
48
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049extern int register_android_os_Binder(JNIEnv* env);
50extern int register_android_os_Process(JNIEnv* env);
51extern int register_android_graphics_Bitmap(JNIEnv*);
52extern int register_android_graphics_BitmapFactory(JNIEnv*);
Wei-Ta Chen6b849e22010-09-07 17:32:18 +080053extern int register_android_graphics_BitmapRegionDecoder(JNIEnv*);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054extern int register_android_graphics_Camera(JNIEnv* env);
Leon Scroggins IIId0d7eaf2013-09-06 16:46:57 -040055extern int register_android_graphics_CreateJavaOutputStreamAdaptor(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056extern int register_android_graphics_Graphics(JNIEnv* env);
57extern int register_android_graphics_Interpolator(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058extern int register_android_graphics_MaskFilter(JNIEnv* env);
59extern int register_android_graphics_Movie(JNIEnv* env);
60extern int register_android_graphics_NinePatch(JNIEnv*);
61extern int register_android_graphics_PathEffect(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062extern int register_android_graphics_Shader(JNIEnv* env);
63extern int register_android_graphics_Typeface(JNIEnv* env);
Wei-Ta Chenbca2d612009-11-30 17:52:05 +080064extern int register_android_graphics_YuvImage(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065
66extern int register_com_google_android_gles_jni_EGLImpl(JNIEnv* env);
67extern int register_com_google_android_gles_jni_GLImpl(JNIEnv* env);
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -070068extern int register_android_opengl_jni_EGL14(JNIEnv* env);
Jesse Hall237c2b82013-05-06 11:36:57 -070069extern int register_android_opengl_jni_EGLExt(JNIEnv* env);
Jack Palevich1c4907e2009-04-13 16:22:25 -070070extern int register_android_opengl_jni_GLES10(JNIEnv* env);
71extern int register_android_opengl_jni_GLES10Ext(JNIEnv* env);
72extern int register_android_opengl_jni_GLES11(JNIEnv* env);
73extern int register_android_opengl_jni_GLES11Ext(JNIEnv* env);
Jack Palevich560814f2009-11-19 16:34:55 +080074extern int register_android_opengl_jni_GLES20(JNIEnv* env);
Jesse Halld877efe2013-04-29 15:59:35 -070075extern int register_android_opengl_jni_GLES30(JNIEnv* env);
Jesse Hall7ab63ac2014-05-19 15:13:41 -070076extern int register_android_opengl_jni_GLES31(JNIEnv* env);
77extern int register_android_opengl_jni_GLES31Ext(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);
Ruben Brunkfeb50af2014-05-09 19:58:49 -070081extern int register_android_hardware_camera2_legacy_LegacyCameraDevice(JNIEnv *env);
Eino-Ville Talvalae1f57d62014-05-29 17:17:07 -070082extern int register_android_hardware_camera2_legacy_PerfMeasurement(JNIEnv *env);
Ruben Brunkb6079002014-05-22 12:33:54 -070083extern int register_android_hardware_camera2_DngCreator(JNIEnv *env);
Eric Laurent633cb562015-03-05 15:17:20 -080084extern int register_android_hardware_Radio(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085extern int register_android_hardware_SensorManager(JNIEnv *env);
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -040086extern int register_android_hardware_SerialPort(JNIEnv *env);
Eric Laurent60b62bc2014-04-18 17:50:49 -070087extern int register_android_hardware_SoundTrigger(JNIEnv *env);
Mike Lockwoode7d511e2010-12-30 13:39:37 -050088extern int register_android_hardware_UsbDevice(JNIEnv *env);
Mike Lockwoodacc29cc2011-03-11 08:18:08 -050089extern int register_android_hardware_UsbDeviceConnection(JNIEnv *env);
Mike Lockwoode7d511e2010-12-30 13:39:37 -050090extern int register_android_hardware_UsbRequest(JNIEnv *env);
destradaaa4fa3b52014-07-09 10:46:39 -070091extern int register_android_hardware_location_ActivityRecognitionHardware(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092
93extern int register_android_media_AudioRecord(JNIEnv *env);
94extern int register_android_media_AudioSystem(JNIEnv *env);
95extern int register_android_media_AudioTrack(JNIEnv *env);
96extern int register_android_media_JetPlayer(JNIEnv *env);
97extern int register_android_media_ToneGenerator(JNIEnv *env);
98
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099namespace android {
100
101/*
102 * JNI-based registration functions. Note these are properly contained in
103 * namespace android.
104 */
105extern int register_android_content_AssetManager(JNIEnv* env);
106extern int register_android_util_EventLog(JNIEnv* env);
107extern int register_android_util_Log(JNIEnv* env);
108extern int register_android_content_StringBlock(JNIEnv* env);
109extern int register_android_content_XmlBlock(JNIEnv* env);
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700110extern int register_android_emoji_EmojiFactory(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800111extern int register_android_graphics_Canvas(JNIEnv* env);
John Reck52244ff2014-05-01 21:27:37 -0700112extern int register_android_graphics_CanvasProperty(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113extern int register_android_graphics_ColorFilter(JNIEnv* env);
114extern int register_android_graphics_DrawFilter(JNIEnv* env);
Raph Levien1a73f7322014-01-30 16:06:28 -0800115extern int register_android_graphics_FontFamily(JNIEnv* env);
Mike Reed4c9355c2014-05-07 11:48:37 -0400116extern int register_android_graphics_LayerRasterizer(JNIEnv*);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800117extern int register_android_graphics_Matrix(JNIEnv* env);
118extern int register_android_graphics_Paint(JNIEnv* env);
119extern int register_android_graphics_Path(JNIEnv* env);
120extern int register_android_graphics_PathMeasure(JNIEnv* env);
121extern int register_android_graphics_Picture(JNIEnv*);
122extern int register_android_graphics_PorterDuff(JNIEnv* env);
123extern int register_android_graphics_Rasterizer(JNIEnv* env);
Jeff Brownfbf09772011-01-16 14:06:57 -0800124extern int register_android_graphics_Region(JNIEnv* env);
Jamie Gennisaa0ce332011-01-06 17:04:26 -0800125extern int register_android_graphics_SurfaceTexture(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800126extern int register_android_graphics_Xfermode(JNIEnv* env);
Svetoslav6811f4e2013-09-18 15:58:28 -0700127extern int register_android_graphics_pdf_PdfDocument(JNIEnv* env);
Svetoslav62ce3322014-09-04 21:17:17 -0700128extern int register_android_graphics_pdf_PdfEditor(JNIEnv* env);
Svetoslav29617692014-04-24 18:40:42 -0700129extern int register_android_graphics_pdf_PdfRenderer(JNIEnv* env);
Jeff Brown0a0a1242011-12-02 02:25:22 -0800130extern int register_android_view_DisplayEventReceiver(JNIEnv* env);
Chris Craikc9070eb2015-03-09 18:50:14 -0700131extern int register_android_view_DisplayListCanvas(JNIEnv* env);
132extern int register_android_view_GraphicBuffer(JNIEnv* env);
133extern int register_android_view_HardwareLayer(JNIEnv* env);
John Reckf666ad72014-03-14 16:24:57 -0700134extern int register_android_view_RenderNode(JNIEnv* env);
John Recke45b1fd2014-04-15 09:50:16 -0700135extern int register_android_view_RenderNodeAnimator(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800136extern int register_android_view_Surface(JNIEnv* env);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800137extern int register_android_view_SurfaceControl(JNIEnv* env);
Jeff Brown64a55af2012-08-26 02:47:39 -0700138extern int register_android_view_SurfaceSession(JNIEnv* env);
Romain Guy8f0095c2011-05-02 17:24:22 -0700139extern int register_android_view_TextureView(JNIEnv* env);
Chris Craikc9070eb2015-03-09 18:50:14 -0700140extern int register_android_view_ThreadedRenderer(JNIEnv* env);
John Reck315c3292014-05-09 19:21:04 -0700141extern int register_com_android_internal_view_animation_NativeInterpolatorFactoryHelper(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800142extern int register_android_database_CursorWindow(JNIEnv* env);
Jeff Browne5360fb2011-10-31 17:48:13 -0700143extern int register_android_database_SQLiteConnection(JNIEnv* env);
144extern int register_android_database_SQLiteGlobal(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145extern int register_android_database_SQLiteDebug(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800146extern int register_android_nio_utils(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147extern int register_android_os_Debug(JNIEnv* env);
Christopher Tatefa9e7c02010-05-06 12:07:10 -0700148extern int register_android_os_MessageQueue(JNIEnv* env);
Jeff Sharkeyd84e1ce2012-03-06 18:26:19 -0800149extern int register_android_os_Parcel(JNIEnv* env);
Stephen Smalleyc07fca32012-01-13 08:31:39 -0500150extern int register_android_os_SELinux(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151extern int register_android_os_SystemProperties(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152extern int register_android_os_SystemClock(JNIEnv* env);
Jeff Brown481c1572012-03-09 14:41:15 -0800153extern int register_android_os_Trace(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800154extern int register_android_os_FileObserver(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155extern int register_android_os_UEventObserver(JNIEnv* env);
156extern int register_android_os_MemoryFile(JNIEnv* env);
157extern int register_android_net_LocalSocketImpl(JNIEnv* env);
158extern int register_android_net_NetworkUtils(JNIEnv* env);
Dan Egnor2b4abcd2010-04-07 17:30:50 -0700159extern int register_android_net_TrafficStats(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800160extern int register_android_text_AndroidCharacter(JNIEnv *env);
Anish Athalye88b5b0b2014-06-24 14:39:43 -0700161extern int register_android_text_StaticLayout(JNIEnv *env);
Doug Feltdae8e942010-02-24 14:33:15 -0800162extern int register_android_text_AndroidBidi(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800163extern int register_android_opengl_classes(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164extern int register_android_ddm_DdmHandleNativeHeap(JNIEnv *env);
Narayan Kamath29564cd2014-08-07 10:57:40 +0100165extern int register_android_server_NetworkManagementSocketTagger(JNIEnv* env);
Joe Onorato1cf58742009-06-12 11:06:24 -0700166extern int register_android_backup_BackupDataInput(JNIEnv *env);
Joe Onoratod2110db2009-05-19 13:41:21 -0700167extern int register_android_backup_BackupDataOutput(JNIEnv *env);
Joe Onorato06290a42009-06-18 20:10:37 -0700168extern int register_android_backup_FileBackupHelperBase(JNIEnv *env);
Joe Onorato4ababd92009-06-25 18:29:18 -0400169extern int register_android_backup_BackupHelperDispatcher(JNIEnv *env);
Christopher Tate4a627c72011-04-01 14:43:32 -0700170extern int register_android_app_backup_FullBackup(JNIEnv *env);
Chet Haase9c1e23b2011-03-24 10:51:31 -0700171extern int register_android_app_ActivityThread(JNIEnv *env);
Dianne Hackborn69969e42010-05-04 11:40:40 -0700172extern int register_android_app_NativeActivity(JNIEnv *env);
Jeff Browncbad9762012-09-04 21:57:59 -0700173extern int register_android_media_RemoteDisplay(JNIEnv *env);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700174extern int register_android_view_InputChannel(JNIEnv* env);
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700175extern int register_android_view_InputDevice(JNIEnv* env);
Jeff Brown32cbc38552011-12-01 14:01:49 -0800176extern int register_android_view_InputEventReceiver(JNIEnv* env);
Jeff Brownc28867a2013-03-26 15:42:39 -0700177extern int register_android_view_InputEventSender(JNIEnv* env);
Michael Wrighta44dd262013-04-10 21:12:00 -0700178extern int register_android_view_InputQueue(JNIEnv* env);
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700179extern int register_android_view_KeyCharacterMap(JNIEnv *env);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700180extern int register_android_view_KeyEvent(JNIEnv* env);
181extern int register_android_view_MotionEvent(JNIEnv* env);
Jeff Brown2352b972011-04-12 22:39:53 -0700182extern int register_android_view_PointerIcon(JNIEnv* env);
Jeff Brown2ed24622011-03-14 19:39:54 -0700183extern int register_android_view_VelocityTracker(JNIEnv* env);
Kenny Root02c87302010-07-01 08:10:18 -0700184extern int register_android_content_res_ObbScanner(JNIEnv* env);
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -0700185extern int register_android_content_res_Configuration(JNIEnv* env);
Chet Haase6e0ecb42010-11-03 19:41:18 -0700186extern int register_android_animation_PropertyValuesHolder(JNIEnv *env);
Kenny Root66269ea2011-07-12 14:14:01 -0700187extern int register_com_android_internal_content_NativeLibraryHelper(JNIEnv *env);
Jeff Sharkey9a2c2a62013-01-14 16:48:51 -0800188extern int register_com_android_internal_net_NetworkStatsFactory(JNIEnv *env);
Narayan Kamath973b4662014-03-31 13:41:26 +0100189extern int register_com_android_internal_os_Zygote(JNIEnv *env);
John Reck9fa40712014-05-09 15:26:59 -0700190extern int register_com_android_internal_util_VirtualRefBasePtr(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800191
192static AndroidRuntime* gCurRuntime = NULL;
193
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800194/*
195 * Code written in the Java Programming Language calls here from main().
196 */
Jeff Brown16f5f5c2012-03-15 16:53:55 -0700197static void com_android_internal_os_RuntimeInit_nativeFinishInit(JNIEnv* env, jobject clazz)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800198{
199 gCurRuntime->onStarted();
200}
201
Jeff Brown16f5f5c2012-03-15 16:53:55 -0700202static void com_android_internal_os_RuntimeInit_nativeZygoteInit(JNIEnv* env, jobject clazz)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800203{
204 gCurRuntime->onZygoteInit();
205}
206
Jeff Brown4280c4a2012-03-15 17:48:02 -0700207static void com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup(JNIEnv* env,
208 jobject clazz, jboolean exitWithoutCleanup)
209{
210 gCurRuntime->setExitWithoutCleanup(exitWithoutCleanup);
211}
212
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800213/*
214 * JNI registration.
215 */
216static JNINativeMethod gMethods[] = {
Jeff Brown16f5f5c2012-03-15 16:53:55 -0700217 { "nativeFinishInit", "()V",
218 (void*) com_android_internal_os_RuntimeInit_nativeFinishInit },
219 { "nativeZygoteInit", "()V",
220 (void*) com_android_internal_os_RuntimeInit_nativeZygoteInit },
Jeff Brown4280c4a2012-03-15 17:48:02 -0700221 { "nativeSetExitWithoutCleanup", "(Z)V",
222 (void*) com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup },
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800223};
224
225int register_com_android_internal_os_RuntimeInit(JNIEnv* env)
226{
227 return jniRegisterNativeMethods(env, "com/android/internal/os/RuntimeInit",
228 gMethods, NELEM(gMethods));
229}
230
231// ----------------------------------------------------------------------
232
Andreas Huber9ae000c2014-02-13 17:22:33 +0000233/*static*/ JavaVM* AndroidRuntime::mJavaVM = NULL;
234
Narayan Kamatha23fcd72014-03-28 13:39:21 +0000235AndroidRuntime::AndroidRuntime(char* argBlockStart, const size_t argBlockLength) :
236 mExitWithoutCleanup(false),
237 mArgBlockStart(argBlockStart),
238 mArgBlockLength(argBlockLength)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800239{
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700240 SkGraphics::Init();
Ben Wagner177612332015-01-15 14:16:46 -0500241 // There is also a global font cache, but its budget is specified by
242 // SK_DEFAULT_FONT_CACHE_COUNT_LIMIT and SK_DEFAULT_FONT_CACHE_LIMIT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800243
244 // Pre-allocate enough space to hold a fair number of options.
245 mOptions.setCapacity(20);
246
247 assert(gCurRuntime == NULL); // one per process
248 gCurRuntime = this;
249}
250
251AndroidRuntime::~AndroidRuntime()
252{
253 SkGraphics::Term();
254}
255
Andreas Huber9ae000c2014-02-13 17:22:33 +0000256/*
257 * Register native methods using JNI.
258 */
259/*static*/ int AndroidRuntime::registerNativeMethods(JNIEnv* env,
260 const char* className, const JNINativeMethod* gMethods, int numMethods)
261{
262 return jniRegisterNativeMethods(env, className, gMethods, numMethods);
263}
264
Narayan Kamatha23fcd72014-03-28 13:39:21 +0000265void AndroidRuntime::setArgv0(const char* argv0) {
Jeff Brown00c0cd42014-09-10 16:48:46 -0700266 memset(mArgBlockStart, 0, mArgBlockLength);
Narayan Kamatha23fcd72014-03-28 13:39:21 +0000267 strlcpy(mArgBlockStart, argv0, mArgBlockLength);
268}
269
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100270status_t AndroidRuntime::callMain(const String8& className, jclass clazz,
271 const Vector<String8>& args)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800272{
273 JNIEnv* env;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800274 jmethodID methodId;
275
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100276 ALOGD("Calling main entry %s", className.string());
Dianne Hackborn08e60f22010-09-01 18:17:17 -0700277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800278 env = getJNIEnv();
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700279 if (clazz == NULL || env == NULL) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800280 return UNKNOWN_ERROR;
281 }
282
283 methodId = env->GetStaticMethodID(clazz, "main", "([Ljava/lang/String;)V");
284 if (methodId == NULL) {
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100285 ALOGE("ERROR: could not find method %s.main(String[])\n", className.string());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800286 return UNKNOWN_ERROR;
287 }
288
289 /*
290 * We want to call main() with a String array with our arguments in it.
291 * Create an array and populate it.
292 */
293 jclass stringClass;
294 jobjectArray strArray;
295
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100296 const size_t numArgs = args.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800297 stringClass = env->FindClass("java/lang/String");
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100298 strArray = env->NewObjectArray(numArgs, stringClass, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800299
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100300 for (size_t i = 0; i < numArgs; i++) {
301 jstring argStr = env->NewStringUTF(args[i].string());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800302 env->SetObjectArrayElement(strArray, i, argStr);
303 }
304
305 env->CallStaticVoidMethod(clazz, methodId, strArray);
306 return NO_ERROR;
307}
308
309/*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800310 * The VM calls this through the "exit" hook.
311 */
312static void runtime_exit(int code)
313{
Jeff Brown4280c4a2012-03-15 17:48:02 -0700314 gCurRuntime->exit(code);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800315}
316
317/*
318 * The VM calls this through the "vfprintf" hook.
319 *
320 * We ignore "fp" and just write the results to the log file.
321 */
322static void runtime_vfprintf(FILE* fp, const char* format, va_list ap)
323{
324 LOG_PRI_VA(ANDROID_LOG_INFO, "vm-printf", format, ap);
325}
326
Brad Fitzpatrick0bd52432010-12-13 16:52:35 -0800327/**
328 * The VM calls this when mutex contention debugging is enabled to
329 * determine whether or not the blocked thread was a "sensitive thread"
330 * for user responsiveness/smoothess.
331 *
332 * Our policy for this is whether or not we're tracing any StrictMode
333 * events on this thread (which we might've inherited via Binder calls
334 * into us)
335 */
336static bool runtime_isSensitiveThread() {
337 IPCThreadState* state = IPCThreadState::selfOrNull();
338 return state && state->getStrictModePolicy() != 0;
339}
340
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800341static int hasDir(const char* dir)
342{
343 struct stat s;
344 int res = stat(dir, &s);
345 if (res == 0) {
346 return S_ISDIR(s.st_mode);
347 }
348 return 0;
349}
350
Andreas Gampe995c62d2014-11-14 16:15:17 -0800351static bool hasFile(const char* file) {
352 struct stat s;
353 int res = stat(file, &s);
354 if (res == 0) {
355 return S_ISREG(s.st_mode);
356 }
357 return false;
358}
359
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800360/*
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000361 * Read the persistent locale. Attempts to read to persist.sys.locale
362 * and falls back to the default locale (ro.product.locale) if
363 * persist.sys.locale is empty.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800364 */
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000365static void readLocale(char* locale)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800366{
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000367 // Allocate 4 extra bytes because we might read a property into
368 // this array at offset 4.
369 char propLocale[PROPERTY_VALUE_MAX + 4];
Brian Carlstrom171ea892010-08-24 21:27:52 -0700370
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000371 property_get("persist.sys.locale", propLocale, "");
372 if (propLocale[0] == 0) {
373 property_get("ro.product.locale", propLocale, "");
374
375 if (propLocale[0] == 0) {
376 // If persist.sys.locale and ro.product.locale are missing,
377 // construct a locale value from the individual locale components.
378 property_get("ro.product.locale.language", propLocale, "en");
379
380 // The language code is either two or three chars in length. If it
381 // isn't 2 chars long, assume three. Anything else is an error
382 // anyway.
383 const int offset = (propLocale[2] == 0) ? 2 : 3;
384 propLocale[offset] = '-';
385
386 property_get("ro.product.locale.region", propLocale + offset + 1, "US");
387 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800388 }
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000389
390 strncat(locale, propLocale, PROPERTY_VALUE_MAX);
391 // ALOGD("[DEBUG] locale=%s", locale);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800392}
393
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700394void AndroidRuntime::addOption(const char* optionString, void* extraInfo)
395{
396 JavaVMOption opt;
397 opt.optionString = optionString;
398 opt.extraInfo = extraInfo;
399 mOptions.add(opt);
400}
401
Andy McFaddenf70188a2009-03-31 15:52:13 -0700402/*
Andy McFaddene4d81f22010-07-14 16:02:20 -0700403 * Parse a property containing space-separated options that should be
404 * passed directly to the VM, e.g. "-Xmx32m -verbose:gc -Xregenmap".
405 *
406 * This will cut up "extraOptsBuf" as we chop it into individual options.
407 *
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800408 * If "quotingArg" is non-null, it is passed before each extra option in mOptions.
409 *
Andy McFaddene4d81f22010-07-14 16:02:20 -0700410 * Adds the strings, if any, to mOptions.
411 */
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800412void AndroidRuntime::parseExtraOpts(char* extraOptsBuf, const char* quotingArg)
Andy McFaddene4d81f22010-07-14 16:02:20 -0700413{
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800414 char* start = extraOptsBuf;
415 char* end = NULL;
Andy McFaddene4d81f22010-07-14 16:02:20 -0700416 while (*start != '\0') {
417 while (*start == ' ') /* skip leading whitespace */
418 start++;
419 if (*start == '\0') /* was trailing ws, bail */
420 break;
421
422 end = start+1;
423 while (*end != ' ' && *end != '\0') /* find end of token */
424 end++;
425 if (*end == ' ')
426 *end++ = '\0'; /* mark end, advance to indicate more */
427
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800428 if (quotingArg != NULL) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700429 addOption(quotingArg);
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800430 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700431 addOption(start);
Andy McFaddene4d81f22010-07-14 16:02:20 -0700432 start = end;
433 }
434}
435
436/*
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700437 * Reads a "property" into "buffer" with a default of "defaultArg". If
438 * the property is non-empty, it is treated as a runtime option such
439 * as "-Xmx32m".
440 *
441 * The "runtimeArg" is a prefix for the option such as "-Xms" or "-Xmx".
442 *
443 * If an argument is found, it is added to mOptions.
444 *
445 * If an option is found, it is added to mOptions and true is
446 * returned. Otherwise false is returned.
447 */
448bool AndroidRuntime::parseRuntimeOption(const char* property,
449 char* buffer,
450 const char* runtimeArg,
451 const char* defaultArg)
452{
453 strcpy(buffer, runtimeArg);
454 size_t runtimeArgLen = strlen(runtimeArg);
455 property_get(property, buffer+runtimeArgLen, defaultArg);
456 if (buffer[runtimeArgLen] == '\0') {
457 return false;
458 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700459 addOption(buffer);
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700460 return true;
461}
462
463/*
464 * Reads a "property" into "buffer". If the property is non-empty, it
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700465 * is treated as a dex2oat compiler option that should be
466 * passed as a quoted option, e.g. "-Ximage-compiler-option --compiler-filter=verify-none".
467 *
468 * The "compilerArg" is a prefix for the option such as "--compiler-filter=".
469 *
470 * The "quotingArg" should be "-Ximage-compiler-option" or "-Xcompiler-option".
471 *
472 * If an option is found, it is added to mOptions and true is
473 * returned. Otherwise false is returned.
474 */
475bool AndroidRuntime::parseCompilerOption(const char* property,
476 char* buffer,
477 const char* compilerArg,
478 const char* quotingArg)
479{
480 strcpy(buffer, compilerArg);
481 size_t compilerArgLen = strlen(compilerArg);
482 property_get(property, buffer+compilerArgLen, "");
483 if (buffer[compilerArgLen] == '\0') {
484 return false;
485 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700486 addOption(quotingArg);
487 addOption(buffer);
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700488 return true;
489}
490
491/*
492 * Reads a "property" into "buffer". If the property is non-empty, it
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700493 * is treated as a dex2oat compiler runtime option that should be
494 * passed as a quoted option, e.g. "-Ximage-compiler-option
495 * --runtime-arg -Ximage-compiler-option -Xmx32m".
496 *
497 * The "runtimeArg" is a prefix for the option such as "-Xms" or "-Xmx".
498 *
499 * The "quotingArg" should be "-Ximage-compiler-option" or "-Xcompiler-option".
500 *
501 * If an option is found, it is added to mOptions and true is
502 * returned. Otherwise false is returned.
503 */
504bool AndroidRuntime::parseCompilerRuntimeOption(const char* property,
505 char* buffer,
506 const char* runtimeArg,
507 const char* quotingArg)
508{
509 strcpy(buffer, runtimeArg);
510 size_t runtimeArgLen = strlen(runtimeArg);
511 property_get(property, buffer+runtimeArgLen, "");
512 if (buffer[runtimeArgLen] == '\0') {
513 return false;
514 }
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700515 addOption(quotingArg);
516 addOption("--runtime-arg");
517 addOption(quotingArg);
518 addOption(buffer);
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700519 return true;
520}
521
522/*
Andy McFaddenf70188a2009-03-31 15:52:13 -0700523 * Start the Dalvik Virtual Machine.
524 *
525 * Various arguments, most determined by system properties, are passed in.
526 * The "mOptions" vector is updated.
527 *
Dave Allison07a1e232014-03-14 08:54:33 -0700528 * CAUTION: when adding options in here, be careful not to put the
529 * char buffer inside a nested scope. Adding the buffer to the
530 * options using mOptions.add() does not copy the buffer, so if the
531 * buffer goes out of scope the option may be overwritten. It's best
532 * to put the buffer at the top of the function so that it is more
533 * unlikely that someone will surround it in a scope at a later time
534 * and thus introduce a bug.
535 *
Andy McFaddenf70188a2009-03-31 15:52:13 -0700536 * Returns 0 on success.
537 */
538int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800539{
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800540 JavaVMInitArgs initArgs;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800541 char propBuf[PROPERTY_VALUE_MAX];
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700542 char stackTraceFileBuf[sizeof("-Xstacktracefile:")-1 + PROPERTY_VALUE_MAX];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800543 char jniOptsBuf[sizeof("-Xjniopts:")-1 + PROPERTY_VALUE_MAX];
Carl Shapiro38cfa8c2010-12-07 16:48:29 -0800544 char heapstartsizeOptsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
Dianne Hackbornbdcef702009-08-18 19:15:36 -0700545 char heapsizeOptsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
Carl Shapiro8cdf27c2011-01-19 12:33:12 -0800546 char heapgrowthlimitOptsBuf[sizeof("-XX:HeapGrowthLimit=")-1 + PROPERTY_VALUE_MAX];
Ian Rogers53250102012-09-23 16:38:03 -0700547 char heapminfreeOptsBuf[sizeof("-XX:HeapMinFree=")-1 + PROPERTY_VALUE_MAX];
548 char heapmaxfreeOptsBuf[sizeof("-XX:HeapMaxFree=")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800549 char usejitOptsBuf[sizeof("-Xusejit:")-1 + PROPERTY_VALUE_MAX];
550 char jitcodecachesizeOptsBuf[sizeof("-Xjitcodecachesize:")-1 + PROPERTY_VALUE_MAX];
551 char jitthresholdOptsBuf[sizeof("-Xjitthreshold:")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartier7e4fdec2013-12-02 15:46:51 -0800552 char gctypeOptsBuf[sizeof("-Xgc:")-1 + PROPERTY_VALUE_MAX];
Mathieu Chartierc01936a2014-05-14 15:44:49 -0700553 char backgroundgcOptsBuf[sizeof("-XX:BackgroundGC=")-1 + PROPERTY_VALUE_MAX];
Ian Rogers53250102012-09-23 16:38:03 -0700554 char heaptargetutilizationOptsBuf[sizeof("-XX:HeapTargetUtilization=")-1 + PROPERTY_VALUE_MAX];
Andreas Gampee324ba02015-03-31 16:15:17 -0700555 char cachePruneBuf[sizeof("-Xzygote-max-boot-retry=")-1 + PROPERTY_VALUE_MAX];
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700556 char dex2oatXmsImageFlagsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
557 char dex2oatXmxImageFlagsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
558 char dex2oatXmsFlagsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
559 char dex2oatXmxFlagsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
Brian Carlstrom3fbfbb42014-07-28 19:13:28 -0700560 char dex2oatCompilerFilterBuf[sizeof("--compiler-filter=")-1 + PROPERTY_VALUE_MAX];
561 char dex2oatImageCompilerFilterBuf[sizeof("--compiler-filter=")-1 + PROPERTY_VALUE_MAX];
Andreas Gampee0352382015-03-30 18:43:39 -0700562 char dex2oatThreadsBuf[sizeof("-j")-1 + PROPERTY_VALUE_MAX];
563 char dex2oatThreadsImageBuf[sizeof("-j")-1 + PROPERTY_VALUE_MAX];
Andreas Gampe605cca12015-04-02 23:12:56 -0700564 char dex2oat_isa_variant_key[PROPERTY_KEY_MAX];
565 char dex2oat_isa_variant[sizeof("--instruction-set-variant=") -1 + PROPERTY_VALUE_MAX];
566 char dex2oat_isa_features_key[PROPERTY_KEY_MAX];
567 char dex2oat_isa_features[sizeof("--instruction-set-features=") -1 + PROPERTY_VALUE_MAX];
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800568 char dex2oatFlagsBuf[PROPERTY_VALUE_MAX];
569 char dex2oatImageFlagsBuf[PROPERTY_VALUE_MAX];
Andy McFaddene4d81f22010-07-14 16:02:20 -0700570 char extraOptsBuf[PROPERTY_VALUE_MAX];
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700571 char voldDecryptBuf[PROPERTY_VALUE_MAX];
Ben Cheng52b0e732009-06-19 13:31:12 -0700572 enum {
573 kEMDefault,
574 kEMIntPortable,
575 kEMIntFast,
Ben Cheng52b0e732009-06-19 13:31:12 -0700576 kEMJitCompiler,
Ben Cheng52b0e732009-06-19 13:31:12 -0700577 } executionMode = kEMDefault;
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700578 char profilePeriod[sizeof("-Xprofile-period:")-1 + PROPERTY_VALUE_MAX];
579 char profileDuration[sizeof("-Xprofile-duration:")-1 + PROPERTY_VALUE_MAX];
580 char profileInterval[sizeof("-Xprofile-interval:")-1 + PROPERTY_VALUE_MAX];
581 char profileBackoff[sizeof("-Xprofile-backoff:")-1 + PROPERTY_VALUE_MAX];
582 char profileTopKThreshold[sizeof("-Xprofile-top-k-threshold:")-1 + PROPERTY_VALUE_MAX];
583 char profileTopKChangeThreshold[sizeof("-Xprofile-top-k-change-threshold:")-1 +
584 PROPERTY_VALUE_MAX];
585 char profileType[sizeof("-Xprofile-type:")-1 + PROPERTY_VALUE_MAX];
586 char profileMaxStackDepth[sizeof("-Xprofile-max-stack-depth:")-1 + PROPERTY_VALUE_MAX];
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000587 char localeOption[sizeof("-Duser.locale=") + PROPERTY_VALUE_MAX];
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700588 char lockProfThresholdBuf[sizeof("-Xlockprofthreshold:")-1 + PROPERTY_VALUE_MAX];
Calin Juravle01db9162014-08-07 14:45:53 +0100589 char nativeBridgeLibrary[sizeof("-XX:NativeBridge=") + PROPERTY_VALUE_MAX];
Dmitriy Ivanovff193d62014-09-30 15:10:48 -0700590 char cpuAbiListBuf[sizeof("--cpu-abilist=") + PROPERTY_VALUE_MAX];
Andreas Gampe98f406f2015-06-22 21:09:36 -0700591 char methodTraceFileBuf[sizeof("-Xmethod-trace-file:") + PROPERTY_VALUE_MAX];
592 char methodTraceFileSizeBuf[sizeof("-Xmethod-trace-file-size:") + PROPERTY_VALUE_MAX];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800593
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700594 bool checkJni = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800595 property_get("dalvik.vm.checkjni", propBuf, "");
596 if (strcmp(propBuf, "true") == 0) {
597 checkJni = true;
598 } else if (strcmp(propBuf, "false") != 0) {
599 /* property is neither true nor false; fall back on kernel parameter */
600 property_get("ro.kernel.android.checkjni", propBuf, "");
601 if (propBuf[0] == '1') {
602 checkJni = true;
603 }
604 }
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700605 ALOGD("CheckJNI is %s\n", checkJni ? "ON" : "OFF");
606 if (checkJni) {
607 /* extended JNI checking */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700608 addOption("-Xcheck:jni");
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700609
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700610 /* with -Xcheck:jni, this provides a JNI function call trace */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700611 //addOption("-verbose:jni");
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700612 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800613
614 property_get("dalvik.vm.execution-mode", propBuf, "");
615 if (strcmp(propBuf, "int:portable") == 0) {
616 executionMode = kEMIntPortable;
617 } else if (strcmp(propBuf, "int:fast") == 0) {
618 executionMode = kEMIntFast;
Ben Cheng52b0e732009-06-19 13:31:12 -0700619 } else if (strcmp(propBuf, "int:jit") == 0) {
620 executionMode = kEMJitCompiler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800621 }
622
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700623 parseRuntimeOption("dalvik.vm.stack-trace-file", stackTraceFileBuf, "-Xstacktracefile:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800625 strcpy(jniOptsBuf, "-Xjniopts:");
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700626 if (parseRuntimeOption("dalvik.vm.jniopts", jniOptsBuf, "-Xjniopts:")) {
627 ALOGI("JNI options: '%s'\n", jniOptsBuf);
628 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800629
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800630 /* route exit() to our handler */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700631 addOption("exit", (void*) runtime_exit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800632
633 /* route fprintf() to our handler */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700634 addOption("vfprintf", (void*) runtime_vfprintf);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800635
Brad Fitzpatrick0bd52432010-12-13 16:52:35 -0800636 /* register the framework-specific "is sensitive thread" hook */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700637 addOption("sensitiveThread", (void*) runtime_isSensitiveThread);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800638
639 /* enable verbose; standard options are { jni, gc, class } */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700640 //addOption("-verbose:jni");
641 addOption("-verbose:gc");
642 //addOption("-verbose:class");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800643
Carl Shapiro9e4c8842010-12-08 12:14:46 -0800644 /*
645 * The default starting and maximum size of the heap. Larger
646 * values should be specified in a product property override.
647 */
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700648 parseRuntimeOption("dalvik.vm.heapstartsize", heapstartsizeOptsBuf, "-Xms", "4m");
649 parseRuntimeOption("dalvik.vm.heapsize", heapsizeOptsBuf, "-Xmx", "16m");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800650
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700651 parseRuntimeOption("dalvik.vm.heapgrowthlimit", heapgrowthlimitOptsBuf, "-XX:HeapGrowthLimit=");
652 parseRuntimeOption("dalvik.vm.heapminfree", heapminfreeOptsBuf, "-XX:HeapMinFree=");
653 parseRuntimeOption("dalvik.vm.heapmaxfree", heapmaxfreeOptsBuf, "-XX:HeapMaxFree=");
654 parseRuntimeOption("dalvik.vm.heaptargetutilization",
655 heaptargetutilizationOptsBuf,
656 "-XX:HeapTargetUtilization=");
Ian Rogers53250102012-09-23 16:38:03 -0700657
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800658 /*
659 * JIT related options.
660 */
Mathieu Chartier1fb7aab2015-03-18 18:54:36 -0700661 parseRuntimeOption("dalvik.vm.usejit", usejitOptsBuf, "-Xusejit:");
662 parseRuntimeOption("dalvik.vm.jitcodecachesize", jitcodecachesizeOptsBuf, "-Xjitcodecachesize:");
663 parseRuntimeOption("dalvik.vm.jitthreshold", jitthresholdOptsBuf, "-Xjitthreshold:");
Mathieu Chartier6909c0e2015-03-05 17:00:41 -0800664
Mathieu Chartiere6c22412013-08-20 17:16:03 -0700665 property_get("ro.config.low_ram", propBuf, "");
666 if (strcmp(propBuf, "true") == 0) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700667 addOption("-XX:LowMemoryMode");
Mathieu Chartiere6c22412013-08-20 17:16:03 -0700668 }
669
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700670 parseRuntimeOption("dalvik.vm.gctype", gctypeOptsBuf, "-Xgc:");
671 parseRuntimeOption("dalvik.vm.backgroundgctype", backgroundgcOptsBuf, "-XX:BackgroundGC=");
Mathieu Chartierc01936a2014-05-14 15:44:49 -0700672
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800673 /* enable debugging; set suspend=y to pause during VM init */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800674 /* use android ADB transport */
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700675 addOption("-agentlib:jdwp=transport=dt_android_adb,suspend=n,server=y");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800676
Brian Carlstrom6d77eb92014-07-08 10:40:59 -0700677 parseRuntimeOption("dalvik.vm.lockprof.threshold",
678 lockProfThresholdBuf,
679 "-Xlockprofthreshold:");
Carl Shapirod8f3ec62010-04-12 16:31:59 -0700680
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800681 if (executionMode == kEMIntPortable) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700682 addOption("-Xint:portable");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800683 } else if (executionMode == kEMIntFast) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700684 addOption("-Xint:fast");
Ben Cheng52b0e732009-06-19 13:31:12 -0700685 } else if (executionMode == kEMJitCompiler) {
Brian Carlstrom0d8fb012014-07-30 12:11:41 -0700686 addOption("-Xint:jit");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800687 }
Andy McFaddene2b23e12009-04-03 11:09:46 -0700688
Andreas Gampe08b2d582014-12-18 14:39:22 -0800689 // If we are booting without the real /data, don't spend time compiling.
690 property_get("vold.decrypt", voldDecryptBuf, "");
691 bool skip_compilation = ((strcmp(voldDecryptBuf, "trigger_restart_min_framework") == 0) ||
692 (strcmp(voldDecryptBuf, "1") == 0));
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800693
Andreas Gampe08b2d582014-12-18 14:39:22 -0800694 // Extra options for boot.art/boot.oat image generation.
695 parseCompilerRuntimeOption("dalvik.vm.image-dex2oat-Xms", dex2oatXmsImageFlagsBuf,
696 "-Xms", "-Ximage-compiler-option");
697 parseCompilerRuntimeOption("dalvik.vm.image-dex2oat-Xmx", dex2oatXmxImageFlagsBuf,
698 "-Xmx", "-Ximage-compiler-option");
699 if (skip_compilation) {
Brian Carlstromce5bbbe2014-07-30 15:13:17 -0700700 addOption("-Ximage-compiler-option");
Andreas Gampe08b2d582014-12-18 14:39:22 -0800701 addOption("--compiler-filter=verify-none");
702 } else {
703 parseCompilerOption("dalvik.vm.image-dex2oat-filter", dex2oatImageCompilerFilterBuf,
704 "--compiler-filter=", "-Ximage-compiler-option");
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800705 }
706
Andreas Gampe08b2d582014-12-18 14:39:22 -0800707 // Make sure there is a preloaded-classes file.
708 if (!hasFile("/system/etc/preloaded-classes")) {
709 ALOGE("Missing preloaded-classes file, /system/etc/preloaded-classes not found: %s\n",
710 strerror(errno));
Dmitriy Ivanovff193d62014-09-30 15:10:48 -0700711 return -1;
Andreas Gampe08b2d582014-12-18 14:39:22 -0800712 }
713 addOption("-Ximage-compiler-option");
714 addOption("--image-classes=/system/etc/preloaded-classes");
715
716 // If there is a compiled-classes file, push it.
717 if (hasFile("/system/etc/compiled-classes")) {
718 addOption("-Ximage-compiler-option");
719 addOption("--compiled-classes=/system/etc/compiled-classes");
720 }
721
722 property_get("dalvik.vm.image-dex2oat-flags", dex2oatImageFlagsBuf, "");
723 parseExtraOpts(dex2oatImageFlagsBuf, "-Ximage-compiler-option");
724
725 // Extra options for DexClassLoader.
726 parseCompilerRuntimeOption("dalvik.vm.dex2oat-Xms", dex2oatXmsFlagsBuf,
727 "-Xms", "-Xcompiler-option");
728 parseCompilerRuntimeOption("dalvik.vm.dex2oat-Xmx", dex2oatXmxFlagsBuf,
729 "-Xmx", "-Xcompiler-option");
730 if (skip_compilation) {
731 addOption("-Xcompiler-option");
732 addOption("--compiler-filter=verify-none");
neo.chae155118f2015-01-07 15:32:15 +0900733
734 // We skip compilation when a minimal runtime is brought up for decryption. In that case
735 // /data is temporarily backed by a tmpfs, which is usually small.
736 // If the system image contains prebuilts, they will be relocated into the tmpfs. In this
737 // specific situation it is acceptable to *not* relocate and run out of the prebuilts
738 // directly instead.
739 addOption("--runtime-arg");
740 addOption("-Xnorelocate");
Andreas Gampe08b2d582014-12-18 14:39:22 -0800741 } else {
742 parseCompilerOption("dalvik.vm.dex2oat-filter", dex2oatCompilerFilterBuf,
743 "--compiler-filter=", "-Xcompiler-option");
744 }
Andreas Gampee0352382015-03-30 18:43:39 -0700745 parseCompilerOption("dalvik.vm.dex2oat-threads", dex2oatThreadsBuf, "-j", "-Xcompiler-option");
746 parseCompilerOption("dalvik.vm.image-dex2oat-threads", dex2oatThreadsImageBuf, "-j",
747 "-Ximage-compiler-option");
Andreas Gampe605cca12015-04-02 23:12:56 -0700748
749 // The runtime will compile a boot image, when necessary, not using installd. Thus, we need to
750 // pass the instruction-set-features/variant as an image-compiler-option.
751 // TODO: Find a better way for the instruction-set.
752#if defined(__arm__)
753 constexpr const char* instruction_set = "arm";
754#elif defined(__aarch64__)
755 constexpr const char* instruction_set = "arm64";
756#elif defined(__mips__) && !defined(__LP64__)
757 constexpr const char* instruction_set = "mips";
758#elif defined(__mips__) && defined(__LP64__)
759 constexpr const char* instruction_set = "mips64";
760#elif defined(__i386__)
761 constexpr const char* instruction_set = "x86";
762#elif defined(__x86_64__)
763 constexpr const char* instruction_set = "x86_64";
764#else
765 constexpr const char* instruction_set = "unknown";
766#endif
767 // Note: it is OK to reuse the buffer, as the values are exactly the same between
768 // * compiler-option, used for runtime compilation (DexClassLoader)
769 // * image-compiler-option, used for boot-image compilation on device
770
771 // Copy the variant.
772 sprintf(dex2oat_isa_variant_key, "dalvik.vm.isa.%s.variant", instruction_set);
773 parseCompilerOption(dex2oat_isa_variant_key, dex2oat_isa_variant,
774 "--instruction-set-variant=", "-Ximage-compiler-option");
775 parseCompilerOption(dex2oat_isa_variant_key, dex2oat_isa_variant,
776 "--instruction-set-variant=", "-Xcompiler-option");
777 // Copy the features.
778 sprintf(dex2oat_isa_features_key, "dalvik.vm.isa.%s.features", instruction_set);
779 parseCompilerOption(dex2oat_isa_features_key, dex2oat_isa_features,
780 "--instruction-set-features=", "-Ximage-compiler-option");
781 parseCompilerOption(dex2oat_isa_features_key, dex2oat_isa_features,
782 "--instruction-set-features=", "-Xcompiler-option");
783
784
Andreas Gampe08b2d582014-12-18 14:39:22 -0800785 property_get("dalvik.vm.dex2oat-flags", dex2oatFlagsBuf, "");
786 parseExtraOpts(dex2oatFlagsBuf, "-Xcompiler-option");
787
Andy McFaddene4d81f22010-07-14 16:02:20 -0700788 /* extra options; parse this late so it overrides others */
789 property_get("dalvik.vm.extra-opts", extraOptsBuf, "");
Brian Carlstrom3beff1e2014-02-28 23:27:22 -0800790 parseExtraOpts(extraOptsBuf, NULL);
Andy McFaddene4d81f22010-07-14 16:02:20 -0700791
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800792 /* Set the properties for locale */
793 {
Narayan Kamathd30dbb82015-01-15 14:48:15 +0000794 strcpy(localeOption, "-Duser.locale=");
795 readLocale(localeOption);
796 addOption(localeOption);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800797 }
798
Dave Allison0efbd9a2014-01-30 14:19:51 -0800799 /*
800 * Set profiler options
801 */
Andreas Gampe08b2d582014-12-18 14:39:22 -0800802 // Whether or not the profiler should be enabled.
803 property_get("dalvik.vm.profiler", propBuf, "0");
804 if (propBuf[0] == '1') {
805 addOption("-Xenable-profiler");
806 }
Dave Allison0efbd9a2014-01-30 14:19:51 -0800807
Andreas Gampe08b2d582014-12-18 14:39:22 -0800808 // Whether the profile should start upon app startup or be delayed by some random offset
809 // (in seconds) that is bound between 0 and a fixed value.
810 property_get("dalvik.vm.profile.start-immed", propBuf, "0");
811 if (propBuf[0] == '1') {
812 addOption("-Xprofile-start-immediately");
813 }
Dave Allison0efbd9a2014-01-30 14:19:51 -0800814
Andreas Gampe08b2d582014-12-18 14:39:22 -0800815 // Number of seconds during profile runs.
816 parseRuntimeOption("dalvik.vm.profile.period-secs", profilePeriod, "-Xprofile-period:");
Dave Allison0efbd9a2014-01-30 14:19:51 -0800817
Andreas Gampe08b2d582014-12-18 14:39:22 -0800818 // Length of each profile run (seconds).
819 parseRuntimeOption("dalvik.vm.profile.duration-secs",
820 profileDuration,
821 "-Xprofile-duration:");
Dave Allison0efbd9a2014-01-30 14:19:51 -0800822
Andreas Gampe08b2d582014-12-18 14:39:22 -0800823 // Polling interval during profile run (microseconds).
824 parseRuntimeOption("dalvik.vm.profile.interval-us", profileInterval, "-Xprofile-interval:");
Calin Juravle9828d062014-06-02 16:45:13 +0100825
Andreas Gampe08b2d582014-12-18 14:39:22 -0800826 // Coefficient for period backoff. The the period is multiplied
827 // by this value after each profile run.
828 parseRuntimeOption("dalvik.vm.profile.backoff-coeff", profileBackoff, "-Xprofile-backoff:");
Calin Juravle9828d062014-06-02 16:45:13 +0100829
Andreas Gampe08b2d582014-12-18 14:39:22 -0800830 // Top K% of samples that are considered relevant when
831 // deciding if the app should be recompiled.
832 parseRuntimeOption("dalvik.vm.profile.top-k-thr",
833 profileTopKThreshold,
834 "-Xprofile-top-k-threshold:");
Calin Juravle9828d062014-06-02 16:45:13 +0100835
Andreas Gampe08b2d582014-12-18 14:39:22 -0800836 // The threshold after which a change in the structure of the
837 // top K% profiled samples becomes significant and triggers
838 // recompilation. A change in profile is considered
839 // significant if X% (top-k-change-threshold) of the top K%
840 // (top-k-threshold property) samples has changed.
841 parseRuntimeOption("dalvik.vm.profile.top-k-ch-thr",
842 profileTopKChangeThreshold,
843 "-Xprofile-top-k-change-threshold:");
Wei Jin54fc18b2014-06-09 16:29:54 -0700844
Andreas Gampe08b2d582014-12-18 14:39:22 -0800845 // Type of profile data.
846 parseRuntimeOption("dalvik.vm.profiler.type", profileType, "-Xprofile-type:");
Wei Jin54fc18b2014-06-09 16:29:54 -0700847
Andreas Gampe08b2d582014-12-18 14:39:22 -0800848 // Depth of bounded stack data
849 parseRuntimeOption("dalvik.vm.profile.stack-depth",
850 profileMaxStackDepth,
851 "-Xprofile-max-stack-depth:");
Dave Allison0efbd9a2014-01-30 14:19:51 -0800852
Andreas Gampe98f406f2015-06-22 21:09:36 -0700853 /*
854 * Tracing options.
855 */
856 property_get("dalvik.vm.method-trace", propBuf, "false");
857 if (strcmp(propBuf, "true") == 0) {
858 addOption("-Xmethod-trace");
859 parseRuntimeOption("dalvik.vm.method-trace-file",
860 methodTraceFileBuf,
861 "-Xmethod-trace-file:");
862 parseRuntimeOption("dalvik.vm.method-trace-file-siz",
863 methodTraceFileSizeBuf,
864 "-Xmethod-trace-file-size:");
865 property_get("dalvik.vm.method-trace-stream", propBuf, "false");
866 if (strcmp(propBuf, "true") == 0) {
867 addOption("-Xmethod-trace-stream");
868 }
869 }
870
Andreas Gampe08b2d582014-12-18 14:39:22 -0800871 // Native bridge library. "0" means that native bridge is disabled.
872 property_get("ro.dalvik.vm.native.bridge", propBuf, "");
873 if (propBuf[0] == '\0') {
874 ALOGW("ro.dalvik.vm.native.bridge is not expected to be empty");
875 } else if (strcmp(propBuf, "0") != 0) {
876 snprintf(nativeBridgeLibrary, sizeof("-XX:NativeBridge=") + PROPERTY_VALUE_MAX,
877 "-XX:NativeBridge=%s", propBuf);
878 addOption(nativeBridgeLibrary);
Calin Juravlebe20ed42014-08-26 23:00:11 +0100879 }
Calin Juravle01db9162014-08-07 14:45:53 +0100880
Dmitriy Ivanovff193d62014-09-30 15:10:48 -0700881#if defined(__LP64__)
882 const char* cpu_abilist_property_name = "ro.product.cpu.abilist64";
883#else
884 const char* cpu_abilist_property_name = "ro.product.cpu.abilist32";
885#endif // defined(__LP64__)
886 property_get(cpu_abilist_property_name, propBuf, "");
887 if (propBuf[0] == '\0') {
888 ALOGE("%s is not expected to be empty", cpu_abilist_property_name);
889 return -1;
890 }
891 snprintf(cpuAbiListBuf, sizeof(cpuAbiListBuf), "--cpu-abilist=%s", propBuf);
892 addOption(cpuAbiListBuf);
893
Andreas Gampee324ba02015-03-31 16:15:17 -0700894 // Dalvik-cache pruning counter.
895 parseRuntimeOption("dalvik.vm.zygote.max-boot-retry", cachePruneBuf,
896 "-Xzygote-max-boot-retry=");
897
Andreas Gampe27c39f12015-04-27 18:28:18 +0000898 /*
David Srbecky065075e2015-05-28 17:16:09 +0100899 * When running with debug.generate-debug-info, add --generate-debug-info to
900 * the compiler options so that the boot image, if it is compiled on device,
901 * will include native debugging information.
Andreas Gampe27c39f12015-04-27 18:28:18 +0000902 */
David Srbecky065075e2015-05-28 17:16:09 +0100903 property_get("debug.generate-debug-info", propBuf, "");
Andreas Gampe27c39f12015-04-27 18:28:18 +0000904 if (strcmp(propBuf, "true") == 0) {
905 addOption("-Xcompiler-option");
David Srbecky065075e2015-05-28 17:16:09 +0100906 addOption("--generate-debug-info");
Andreas Gampe27c39f12015-04-27 18:28:18 +0000907 addOption("-Ximage-compiler-option");
David Srbecky065075e2015-05-28 17:16:09 +0100908 addOption("--generate-debug-info");
Andreas Gampe27c39f12015-04-27 18:28:18 +0000909 }
910
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800911 initArgs.version = JNI_VERSION_1_4;
912 initArgs.options = mOptions.editArray();
913 initArgs.nOptions = mOptions.size();
914 initArgs.ignoreUnrecognized = JNI_FALSE;
915
916 /*
917 * Initialize the VM.
918 *
919 * The JavaVM* is essentially per-process, and the JNIEnv* is per-thread.
920 * If this call succeeds, the VM is ready, and we can start issuing
921 * JNI calls.
922 */
Andy McFaddenf70188a2009-03-31 15:52:13 -0700923 if (JNI_CreateJavaVM(pJavaVM, pEnv, &initArgs) < 0) {
Steve Block3762c312012-01-06 19:20:56 +0000924 ALOGE("JNI_CreateJavaVM failed\n");
Dmitriy Ivanovff193d62014-09-30 15:10:48 -0700925 return -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800926 }
927
Dmitriy Ivanovff193d62014-09-30 15:10:48 -0700928 return 0;
Andy McFaddenf70188a2009-03-31 15:52:13 -0700929}
930
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700931char* AndroidRuntime::toSlashClassName(const char* className)
932{
933 char* result = strdup(className);
934 for (char* cp = result; *cp != '\0'; cp++) {
935 if (*cp == '.') {
936 *cp = '/';
937 }
938 }
939 return result;
940}
941
Mike Lockwood9ee5e7e2014-09-08 16:15:21 -0700942/** Create a Java string from an ASCII or Latin-1 string */
943jstring AndroidRuntime::NewStringLatin1(JNIEnv* env, const char* bytes) {
944 if (!bytes) return NULL;
945 int length = strlen(bytes);
946 jchar* buffer = (jchar *)alloca(length * sizeof(jchar));
947 if (!buffer) return NULL;
948 jchar* chp = buffer;
949 for (int i = 0; i < length; i++) {
950 *chp++ = *bytes++;
951 }
952 return env->NewString(buffer, length);
953}
954
955
Andy McFaddenf70188a2009-03-31 15:52:13 -0700956/*
957 * Start the Android runtime. This involves starting the virtual machine
958 * and calling the "static void main(String[] args)" method in the class
959 * named by "className".
Jeff Brownebed7d62011-05-16 17:08:42 -0700960 *
961 * Passes the main function two arguments, the class name and the specified
962 * options string.
Andy McFaddenf70188a2009-03-31 15:52:13 -0700963 */
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100964void AndroidRuntime::start(const char* className, const Vector<String8>& options)
Andy McFaddenf70188a2009-03-31 15:52:13 -0700965{
Dianne Hackborn8e5aafe2014-10-27 18:04:10 -0700966 ALOGD(">>>>>> START %s uid %d <<<<<<\n",
967 className != NULL ? className : "(unknown)", getuid());
Andy McFaddenf70188a2009-03-31 15:52:13 -0700968
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100969 static const String8 startSystemServer("start-system-server");
970
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700971 /*
972 * 'startSystemServer == true' means runtime is obsolete and not run from
Andy McFaddenf70188a2009-03-31 15:52:13 -0700973 * init.rc anymore, so we print out the boot start event here.
974 */
Narayan Kamath22ec1ee2014-04-07 12:44:58 +0100975 for (size_t i = 0; i < options.size(); ++i) {
976 if (options[i] == startSystemServer) {
977 /* track our progress through the boot sequence */
978 const int LOG_BOOT_PROGRESS_START = 3000;
979 LOG_EVENT_LONG(LOG_BOOT_PROGRESS_START, ns2ms(systemTime(SYSTEM_TIME_MONOTONIC)));
980 }
Andy McFaddenf70188a2009-03-31 15:52:13 -0700981 }
982
983 const char* rootDir = getenv("ANDROID_ROOT");
984 if (rootDir == NULL) {
985 rootDir = "/system";
986 if (!hasDir("/system")) {
987 LOG_FATAL("No root directory specified, and /android does not exist.");
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700988 return;
Andy McFaddenf70188a2009-03-31 15:52:13 -0700989 }
990 setenv("ANDROID_ROOT", rootDir, 1);
991 }
992
993 //const char* kernelHack = getenv("LD_ASSUME_KERNEL");
Steve Block5baa3a62011-12-20 16:23:08 +0000994 //ALOGD("Found LD_ASSUME_KERNEL='%s'\n", kernelHack);
Andy McFaddenf70188a2009-03-31 15:52:13 -0700995
996 /* start the virtual machine */
Brian Carlstrom9f8203a2013-06-19 13:49:36 -0700997 JniInvocation jni_invocation;
998 jni_invocation.Init(NULL);
Elliott Hughesd195e5a2011-04-13 15:39:37 -0700999 JNIEnv* env;
1000 if (startVm(&mJavaVM, &env) != 0) {
1001 return;
1002 }
1003 onVmCreated(env);
Andy McFaddenf70188a2009-03-31 15:52:13 -07001004
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001005 /*
1006 * Register android functions.
1007 */
1008 if (startReg(env) < 0) {
Steve Block3762c312012-01-06 19:20:56 +00001009 ALOGE("Unable to register all android natives\n");
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001010 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001011 }
1012
1013 /*
1014 * We want to call main() with a String array with arguments in it.
Jeff Brownebed7d62011-05-16 17:08:42 -07001015 * At present we have two arguments, the class name and an option string.
1016 * Create an array to hold them.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001017 */
1018 jclass stringClass;
1019 jobjectArray strArray;
1020 jstring classNameStr;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001021
1022 stringClass = env->FindClass("java/lang/String");
1023 assert(stringClass != NULL);
Narayan Kamath22ec1ee2014-04-07 12:44:58 +01001024 strArray = env->NewObjectArray(options.size() + 1, stringClass, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001025 assert(strArray != NULL);
1026 classNameStr = env->NewStringUTF(className);
1027 assert(classNameStr != NULL);
1028 env->SetObjectArrayElement(strArray, 0, classNameStr);
Narayan Kamath22ec1ee2014-04-07 12:44:58 +01001029
1030 for (size_t i = 0; i < options.size(); ++i) {
1031 jstring optionsStr = env->NewStringUTF(options.itemAt(i).string());
1032 assert(optionsStr != NULL);
1033 env->SetObjectArrayElement(strArray, i + 1, optionsStr);
1034 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001035
1036 /*
1037 * Start VM. This thread becomes the main thread of the VM, and will
1038 * not return until the VM exits.
1039 */
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001040 char* slashClassName = toSlashClassName(className);
1041 jclass startClass = env->FindClass(slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001042 if (startClass == NULL) {
Steve Block3762c312012-01-06 19:20:56 +00001043 ALOGE("JavaVM unable to locate class '%s'\n", slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001044 /* keep going */
1045 } else {
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001046 jmethodID startMeth = env->GetStaticMethodID(startClass, "main",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001047 "([Ljava/lang/String;)V");
1048 if (startMeth == NULL) {
Steve Block3762c312012-01-06 19:20:56 +00001049 ALOGE("JavaVM unable to find main() in '%s'\n", className);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001050 /* keep going */
1051 } else {
1052 env->CallStaticVoidMethod(startClass, startMeth, strArray);
1053
1054#if 0
1055 if (env->ExceptionCheck())
1056 threadExitUncaughtException(env);
1057#endif
1058 }
1059 }
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001060 free(slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001061
Steve Block5baa3a62011-12-20 16:23:08 +00001062 ALOGD("Shutting down VM\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001063 if (mJavaVM->DetachCurrentThread() != JNI_OK)
Steve Block8564c8d2012-01-05 23:22:43 +00001064 ALOGW("Warning: unable to detach main thread\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001065 if (mJavaVM->DestroyJavaVM() != 0)
Steve Block8564c8d2012-01-05 23:22:43 +00001066 ALOGW("Warning: VM did not shut down cleanly\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001067}
1068
Jeff Brown4280c4a2012-03-15 17:48:02 -07001069void AndroidRuntime::exit(int code)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001070{
Jeff Brown4280c4a2012-03-15 17:48:02 -07001071 if (mExitWithoutCleanup) {
1072 ALOGI("VM exiting with result code %d, cleanup skipped.", code);
1073 ::_exit(code);
1074 } else {
1075 ALOGI("VM exiting with result code %d.", code);
1076 onExit(code);
1077 ::exit(code);
1078 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001079}
1080
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001081void AndroidRuntime::onVmCreated(JNIEnv* env)
1082{
1083 // If AndroidRuntime had anything to do here, we'd have done it in 'start'.
1084}
1085
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001086/*
Andreas Huber9ae000c2014-02-13 17:22:33 +00001087 * Get the JNIEnv pointer for this thread.
1088 *
1089 * Returns NULL if the slot wasn't allocated or populated.
1090 */
1091/*static*/ JNIEnv* AndroidRuntime::getJNIEnv()
1092{
1093 JNIEnv* env;
1094 JavaVM* vm = AndroidRuntime::getJavaVM();
1095 assert(vm != NULL);
1096
1097 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK)
1098 return NULL;
1099 return env;
1100}
1101
1102/*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001103 * Makes the current thread visible to the VM.
1104 *
1105 * The JNIEnv pointer returned is only valid for the current thread, and
1106 * thus must be tucked into thread-local storage.
1107 */
1108static int javaAttachThread(const char* threadName, JNIEnv** pEnv)
1109{
1110 JavaVMAttachArgs args;
1111 JavaVM* vm;
1112 jint result;
1113
1114 vm = AndroidRuntime::getJavaVM();
1115 assert(vm != NULL);
1116
1117 args.version = JNI_VERSION_1_4;
1118 args.name = (char*) threadName;
1119 args.group = NULL;
1120
1121 result = vm->AttachCurrentThread(pEnv, (void*) &args);
1122 if (result != JNI_OK)
Steve Block6215d3f2012-01-04 20:05:49 +00001123 ALOGI("NOTE: attach of thread '%s' failed\n", threadName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001124
1125 return result;
1126}
1127
1128/*
1129 * Detach the current thread from the set visible to the VM.
1130 */
1131static int javaDetachThread(void)
1132{
1133 JavaVM* vm;
1134 jint result;
1135
1136 vm = AndroidRuntime::getJavaVM();
1137 assert(vm != NULL);
1138
1139 result = vm->DetachCurrentThread();
1140 if (result != JNI_OK)
Steve Block3762c312012-01-06 19:20:56 +00001141 ALOGE("ERROR: thread detach failed\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001142 return result;
1143}
1144
1145/*
1146 * When starting a native thread that will be visible from the VM, we
1147 * bounce through this to get the right attach/detach action.
1148 * Note that this function calls free(args)
1149 */
1150/*static*/ int AndroidRuntime::javaThreadShell(void* args) {
1151 void* start = ((void**)args)[0];
1152 void* userData = ((void **)args)[1];
1153 char* name = (char*) ((void **)args)[2]; // we own this storage
1154 free(args);
1155 JNIEnv* env;
1156 int result;
1157
1158 /* hook us into the VM */
1159 if (javaAttachThread(name, &env) != JNI_OK)
1160 return -1;
1161
1162 /* start the thread running */
1163 result = (*(android_thread_func_t)start)(userData);
1164
1165 /* unhook us */
1166 javaDetachThread();
1167 free(name);
1168
1169 return result;
1170}
1171
1172/*
1173 * This is invoked from androidCreateThreadEtc() via the callback
1174 * set with androidSetCreateThreadFunc().
1175 *
1176 * We need to create the new thread in such a way that it gets hooked
1177 * into the VM before it really starts executing.
1178 */
1179/*static*/ int AndroidRuntime::javaCreateThreadEtc(
Elliott Hughesd195e5a2011-04-13 15:39:37 -07001180 android_thread_func_t entryFunction,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001181 void* userData,
1182 const char* threadName,
1183 int32_t threadPriority,
1184 size_t threadStackSize,
1185 android_thread_id_t* threadId)
1186{
1187 void** args = (void**) malloc(3 * sizeof(void*)); // javaThreadShell must free
1188 int result;
1189
Mike Lockwood32f2e622013-10-10 10:11:27 -07001190 if (!threadName)
1191 threadName = "unnamed thread";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001192
1193 args[0] = (void*) entryFunction;
1194 args[1] = userData;
1195 args[2] = (void*) strdup(threadName); // javaThreadShell must free
1196
1197 result = androidCreateRawThreadEtc(AndroidRuntime::javaThreadShell, args,
1198 threadName, threadPriority, threadStackSize, threadId);
1199 return result;
1200}
1201
1202/*
1203 * Create a thread that is visible from the VM.
1204 *
1205 * This is called from elsewhere in the library.
1206 */
Mike Lockwoodf602d362010-06-20 14:28:16 -07001207/*static*/ android_thread_id_t AndroidRuntime::createJavaThread(const char* name,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001208 void (*start)(void *), void* arg)
1209{
Mike Lockwoodf602d362010-06-20 14:28:16 -07001210 android_thread_id_t threadId = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001211 javaCreateThreadEtc((android_thread_func_t) start, arg, name,
Mike Lockwoodf602d362010-06-20 14:28:16 -07001212 ANDROID_PRIORITY_DEFAULT, 0, &threadId);
1213 return threadId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001214}
1215
1216#if 0
1217static void quickTest(void* arg)
1218{
1219 const char* str = (const char*) arg;
1220
1221 printf("In quickTest: %s\n", str);
1222}
1223#endif
1224
1225#ifdef NDEBUG
1226 #define REG_JNI(name) { name }
1227 struct RegJNIRec {
1228 int (*mProc)(JNIEnv*);
1229 };
1230#else
1231 #define REG_JNI(name) { name, #name }
1232 struct RegJNIRec {
1233 int (*mProc)(JNIEnv*);
1234 const char* mName;
1235 };
1236#endif
1237
1238typedef void (*RegJAMProc)();
1239
1240static int register_jni_procs(const RegJNIRec array[], size_t count, JNIEnv* env)
1241{
1242 for (size_t i = 0; i < count; i++) {
1243 if (array[i].mProc(env) < 0) {
1244#ifndef NDEBUG
Steve Block5baa3a62011-12-20 16:23:08 +00001245 ALOGD("----------!!! %s failed to load\n", array[i].mName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001246#endif
1247 return -1;
1248 }
1249 }
1250 return 0;
1251}
1252
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001253static const RegJNIRec gRegJNI[] = {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001254 REG_JNI(register_com_android_internal_os_RuntimeInit),
1255 REG_JNI(register_android_os_SystemClock),
1256 REG_JNI(register_android_util_EventLog),
1257 REG_JNI(register_android_util_Log),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001258 REG_JNI(register_android_content_AssetManager),
1259 REG_JNI(register_android_content_StringBlock),
1260 REG_JNI(register_android_content_XmlBlock),
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001261 REG_JNI(register_android_emoji_EmojiFactory),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001262 REG_JNI(register_android_text_AndroidCharacter),
Anish Athalye88b5b0b2014-06-24 14:39:43 -07001263 REG_JNI(register_android_text_StaticLayout),
Doug Feltdae8e942010-02-24 14:33:15 -08001264 REG_JNI(register_android_text_AndroidBidi),
Jeff Brown9f25b7f2012-04-10 14:30:49 -07001265 REG_JNI(register_android_view_InputDevice),
1266 REG_JNI(register_android_view_KeyCharacterMap),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001267 REG_JNI(register_android_os_Process),
Andreas Hubera8079bf2010-11-16 14:40:31 -08001268 REG_JNI(register_android_os_SystemProperties),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001269 REG_JNI(register_android_os_Binder),
Jeff Sharkeyd84e1ce2012-03-06 18:26:19 -08001270 REG_JNI(register_android_os_Parcel),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001271 REG_JNI(register_android_nio_utils),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001272 REG_JNI(register_android_graphics_Graphics),
Chris Craik54389792013-12-20 13:28:11 -08001273 REG_JNI(register_android_view_DisplayEventReceiver),
John Reckf666ad72014-03-14 16:24:57 -07001274 REG_JNI(register_android_view_RenderNode),
John Recke45b1fd2014-04-15 09:50:16 -07001275 REG_JNI(register_android_view_RenderNodeAnimator),
Romain Guy3b748a42013-04-17 18:54:38 -07001276 REG_JNI(register_android_view_GraphicBuffer),
Chris Craikc9070eb2015-03-09 18:50:14 -07001277 REG_JNI(register_android_view_DisplayListCanvas),
John Reck04fc5832014-02-05 16:38:25 -08001278 REG_JNI(register_android_view_HardwareLayer),
John Reckcec24ae2013-11-05 13:27:50 -08001279 REG_JNI(register_android_view_ThreadedRenderer),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001280 REG_JNI(register_android_view_Surface),
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001281 REG_JNI(register_android_view_SurfaceControl),
Jeff Brown64a55af2012-08-26 02:47:39 -07001282 REG_JNI(register_android_view_SurfaceSession),
Romain Guy8f0095c2011-05-02 17:24:22 -07001283 REG_JNI(register_android_view_TextureView),
John Reck315c3292014-05-09 19:21:04 -07001284 REG_JNI(register_com_android_internal_view_animation_NativeInterpolatorFactoryHelper),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001285 REG_JNI(register_com_google_android_gles_jni_EGLImpl),
1286 REG_JNI(register_com_google_android_gles_jni_GLImpl),
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -07001287 REG_JNI(register_android_opengl_jni_EGL14),
Jesse Hall237c2b82013-05-06 11:36:57 -07001288 REG_JNI(register_android_opengl_jni_EGLExt),
Jack Palevich1c4907e2009-04-13 16:22:25 -07001289 REG_JNI(register_android_opengl_jni_GLES10),
1290 REG_JNI(register_android_opengl_jni_GLES10Ext),
1291 REG_JNI(register_android_opengl_jni_GLES11),
1292 REG_JNI(register_android_opengl_jni_GLES11Ext),
Jack Palevich560814f2009-11-19 16:34:55 +08001293 REG_JNI(register_android_opengl_jni_GLES20),
Jesse Halld877efe2013-04-29 15:59:35 -07001294 REG_JNI(register_android_opengl_jni_GLES30),
Jesse Hall7ab63ac2014-05-19 15:13:41 -07001295 REG_JNI(register_android_opengl_jni_GLES31),
1296 REG_JNI(register_android_opengl_jni_GLES31Ext),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001297
1298 REG_JNI(register_android_graphics_Bitmap),
1299 REG_JNI(register_android_graphics_BitmapFactory),
Wei-Ta Chen6b849e22010-09-07 17:32:18 +08001300 REG_JNI(register_android_graphics_BitmapRegionDecoder),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001301 REG_JNI(register_android_graphics_Camera),
Leon Scroggins IIId0d7eaf2013-09-06 16:46:57 -04001302 REG_JNI(register_android_graphics_CreateJavaOutputStreamAdaptor),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001303 REG_JNI(register_android_graphics_Canvas),
John Reck52244ff2014-05-01 21:27:37 -07001304 REG_JNI(register_android_graphics_CanvasProperty),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001305 REG_JNI(register_android_graphics_ColorFilter),
1306 REG_JNI(register_android_graphics_DrawFilter),
Raph Levien1a73f7322014-01-30 16:06:28 -08001307 REG_JNI(register_android_graphics_FontFamily),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001308 REG_JNI(register_android_graphics_Interpolator),
1309 REG_JNI(register_android_graphics_LayerRasterizer),
1310 REG_JNI(register_android_graphics_MaskFilter),
1311 REG_JNI(register_android_graphics_Matrix),
1312 REG_JNI(register_android_graphics_Movie),
1313 REG_JNI(register_android_graphics_NinePatch),
1314 REG_JNI(register_android_graphics_Paint),
1315 REG_JNI(register_android_graphics_Path),
1316 REG_JNI(register_android_graphics_PathMeasure),
1317 REG_JNI(register_android_graphics_PathEffect),
1318 REG_JNI(register_android_graphics_Picture),
1319 REG_JNI(register_android_graphics_PorterDuff),
1320 REG_JNI(register_android_graphics_Rasterizer),
1321 REG_JNI(register_android_graphics_Region),
1322 REG_JNI(register_android_graphics_Shader),
Jamie Gennisaa0ce332011-01-06 17:04:26 -08001323 REG_JNI(register_android_graphics_SurfaceTexture),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001324 REG_JNI(register_android_graphics_Typeface),
1325 REG_JNI(register_android_graphics_Xfermode),
Wei-Ta Chenbca2d612009-11-30 17:52:05 +08001326 REG_JNI(register_android_graphics_YuvImage),
Svetoslav6811f4e2013-09-18 15:58:28 -07001327 REG_JNI(register_android_graphics_pdf_PdfDocument),
Svetoslav62ce3322014-09-04 21:17:17 -07001328 REG_JNI(register_android_graphics_pdf_PdfEditor),
Svetoslav29617692014-04-24 18:40:42 -07001329 REG_JNI(register_android_graphics_pdf_PdfRenderer),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001330
1331 REG_JNI(register_android_database_CursorWindow),
Jeff Browne5360fb2011-10-31 17:48:13 -07001332 REG_JNI(register_android_database_SQLiteConnection),
1333 REG_JNI(register_android_database_SQLiteGlobal),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001334 REG_JNI(register_android_database_SQLiteDebug),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001335 REG_JNI(register_android_os_Debug),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001336 REG_JNI(register_android_os_FileObserver),
Christopher Tatefa9e7c02010-05-06 12:07:10 -07001337 REG_JNI(register_android_os_MessageQueue),
Stephen Smalleyc07fca32012-01-13 08:31:39 -05001338 REG_JNI(register_android_os_SELinux),
Jeff Brown481c1572012-03-09 14:41:15 -08001339 REG_JNI(register_android_os_Trace),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001340 REG_JNI(register_android_os_UEventObserver),
1341 REG_JNI(register_android_net_LocalSocketImpl),
1342 REG_JNI(register_android_net_NetworkUtils),
Dan Egnor2b4abcd2010-04-07 17:30:50 -07001343 REG_JNI(register_android_net_TrafficStats),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001344 REG_JNI(register_android_os_MemoryFile),
Narayan Kamath973b4662014-03-31 13:41:26 +01001345 REG_JNI(register_com_android_internal_os_Zygote),
John Reck9fa40712014-05-09 15:26:59 -07001346 REG_JNI(register_com_android_internal_util_VirtualRefBasePtr),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001347 REG_JNI(register_android_hardware_Camera),
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -07001348 REG_JNI(register_android_hardware_camera2_CameraMetadata),
Ruben Brunkfeb50af2014-05-09 19:58:49 -07001349 REG_JNI(register_android_hardware_camera2_legacy_LegacyCameraDevice),
Eino-Ville Talvalae1f57d62014-05-29 17:17:07 -07001350 REG_JNI(register_android_hardware_camera2_legacy_PerfMeasurement),
Ruben Brunkb6079002014-05-22 12:33:54 -07001351 REG_JNI(register_android_hardware_camera2_DngCreator),
Eric Laurent633cb562015-03-05 15:17:20 -08001352 REG_JNI(register_android_hardware_Radio),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001353 REG_JNI(register_android_hardware_SensorManager),
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04001354 REG_JNI(register_android_hardware_SerialPort),
Eric Laurent60b62bc2014-04-18 17:50:49 -07001355 REG_JNI(register_android_hardware_SoundTrigger),
Mike Lockwoode7d511e2010-12-30 13:39:37 -05001356 REG_JNI(register_android_hardware_UsbDevice),
Mike Lockwoodacc29cc2011-03-11 08:18:08 -05001357 REG_JNI(register_android_hardware_UsbDeviceConnection),
Mike Lockwoode7d511e2010-12-30 13:39:37 -05001358 REG_JNI(register_android_hardware_UsbRequest),
destradaaa4fa3b52014-07-09 10:46:39 -07001359 REG_JNI(register_android_hardware_location_ActivityRecognitionHardware),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001360 REG_JNI(register_android_media_AudioRecord),
1361 REG_JNI(register_android_media_AudioSystem),
1362 REG_JNI(register_android_media_AudioTrack),
1363 REG_JNI(register_android_media_JetPlayer),
Jeff Browncbad9762012-09-04 21:57:59 -07001364 REG_JNI(register_android_media_RemoteDisplay),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001365 REG_JNI(register_android_media_ToneGenerator),
1366
1367 REG_JNI(register_android_opengl_classes),
JP Abgrall98a4f7e2011-09-02 15:36:33 -07001368 REG_JNI(register_android_server_NetworkManagementSocketTagger),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001369 REG_JNI(register_android_ddm_DdmHandleNativeHeap),
Joe Onorato1cf58742009-06-12 11:06:24 -07001370 REG_JNI(register_android_backup_BackupDataInput),
Joe Onoratod2110db2009-05-19 13:41:21 -07001371 REG_JNI(register_android_backup_BackupDataOutput),
Joe Onorato06290a42009-06-18 20:10:37 -07001372 REG_JNI(register_android_backup_FileBackupHelperBase),
Joe Onorato4ababd92009-06-25 18:29:18 -04001373 REG_JNI(register_android_backup_BackupHelperDispatcher),
Christopher Tate4a627c72011-04-01 14:43:32 -07001374 REG_JNI(register_android_app_backup_FullBackup),
Chet Haase9c1e23b2011-03-24 10:51:31 -07001375 REG_JNI(register_android_app_ActivityThread),
Dianne Hackborn69969e42010-05-04 11:40:40 -07001376 REG_JNI(register_android_app_NativeActivity),
Jeff Brown46b9ac02010-04-22 18:58:52 -07001377 REG_JNI(register_android_view_InputChannel),
Jeff Brown32cbc38552011-12-01 14:01:49 -08001378 REG_JNI(register_android_view_InputEventReceiver),
Jeff Brownc28867a2013-03-26 15:42:39 -07001379 REG_JNI(register_android_view_InputEventSender),
Michael Wrighta44dd262013-04-10 21:12:00 -07001380 REG_JNI(register_android_view_InputQueue),
Jeff Brown46b9ac02010-04-22 18:58:52 -07001381 REG_JNI(register_android_view_KeyEvent),
1382 REG_JNI(register_android_view_MotionEvent),
Jeff Brown2352b972011-04-12 22:39:53 -07001383 REG_JNI(register_android_view_PointerIcon),
Jeff Brown2ed24622011-03-14 19:39:54 -07001384 REG_JNI(register_android_view_VelocityTracker),
Kenny Root02c87302010-07-01 08:10:18 -07001385
1386 REG_JNI(register_android_content_res_ObbScanner),
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -07001387 REG_JNI(register_android_content_res_Configuration),
Chet Haase6e0ecb42010-11-03 19:41:18 -07001388
1389 REG_JNI(register_android_animation_PropertyValuesHolder),
Kenny Root66269ea2011-07-12 14:14:01 -07001390 REG_JNI(register_com_android_internal_content_NativeLibraryHelper),
Jeff Sharkey9a2c2a62013-01-14 16:48:51 -08001391 REG_JNI(register_com_android_internal_net_NetworkStatsFactory),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001392};
1393
1394/*
1395 * Register android native functions with the VM.
1396 */
1397/*static*/ int AndroidRuntime::startReg(JNIEnv* env)
1398{
1399 /*
1400 * This hook causes all future threads created in this process to be
1401 * attached to the JavaVM. (This needs to go away in favor of JNI
1402 * Attach calls.)
1403 */
1404 androidSetCreateThreadFunc((android_create_thread_fn) javaCreateThreadEtc);
1405
Steve Block71f2cf12011-10-20 11:56:00 +01001406 ALOGV("--- registering native functions ---\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001407
1408 /*
1409 * Every "register" function calls one or more things that return
1410 * a local reference (e.g. FindClass). Because we haven't really
1411 * started the VM yet, they're all getting stored in the base frame
1412 * and never released. Use Push/Pop to manage the storage.
1413 */
1414 env->PushLocalFrame(200);
1415
1416 if (register_jni_procs(gRegJNI, NELEM(gRegJNI), env) < 0) {
1417 env->PopLocalFrame(NULL);
1418 return -1;
1419 }
1420 env->PopLocalFrame(NULL);
1421
1422 //createJavaThread("fubar", quickTest, (void*) "hello");
1423
1424 return 0;
1425}
1426
1427AndroidRuntime* AndroidRuntime::getRuntime()
1428{
1429 return gCurRuntime;
1430}
1431
1432/**
1433 * Used by WithFramework to register native functions.
1434 */
1435extern "C"
1436jint Java_com_android_internal_util_WithFramework_registerNatives(
1437 JNIEnv* env, jclass clazz) {
1438 return register_jni_procs(gRegJNI, NELEM(gRegJNI), env);
1439}
1440
1441/**
1442 * Used by LoadClass to register native functions.
1443 */
1444extern "C"
1445jint Java_LoadClass_registerNatives(JNIEnv* env, jclass clazz) {
1446 return register_jni_procs(gRegJNI, NELEM(gRegJNI), env);
1447}
1448
1449} // namespace android