blob: 82fa93e41b2d12549dda3d8cfdd6aa9c7dcc8d3b [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/* //device/libs/android_runtime/AndroidRuntime.cpp
2**
3** Copyright 2006, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#define LOG_TAG "AndroidRuntime"
19//#define LOG_NDEBUG 0
20
21#include <android_runtime/AndroidRuntime.h>
Mathias Agopian07952722009-05-19 19:08:10 -070022#include <binder/IBinder.h>
23#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>
Mathias Agopian8ed6beb2009-06-05 01:26:23 -070027#include <utils/StringArray.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028#include <utils/threads.h>
29#include <cutils/properties.h>
30
31#include <SkGraphics.h>
32#include <SkImageDecoder.h>
Mike Reedfc8db532009-04-27 11:43:30 -040033#include <SkImageRef_GlobalPool.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034
35#include "jni.h"
36#include "JNIHelp.h"
37#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
50extern void register_BindTest();
51
52extern int register_android_os_Binder(JNIEnv* env);
53extern int register_android_os_Process(JNIEnv* env);
54extern int register_android_graphics_Bitmap(JNIEnv*);
55extern int register_android_graphics_BitmapFactory(JNIEnv*);
56extern int register_android_graphics_Camera(JNIEnv* env);
57extern 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);
64extern int register_android_graphics_Region(JNIEnv* env);
65extern int register_android_graphics_Shader(JNIEnv* env);
66extern int register_android_graphics_Typeface(JNIEnv* env);
67
68extern int register_com_google_android_gles_jni_EGLImpl(JNIEnv* env);
69extern int register_com_google_android_gles_jni_GLImpl(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);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074
75extern int register_android_hardware_Camera(JNIEnv *env);
76
77extern int register_android_hardware_SensorManager(JNIEnv *env);
78
79extern int register_android_media_AudioRecord(JNIEnv *env);
80extern int register_android_media_AudioSystem(JNIEnv *env);
81extern int register_android_media_AudioTrack(JNIEnv *env);
82extern int register_android_media_JetPlayer(JNIEnv *env);
83extern int register_android_media_ToneGenerator(JNIEnv *env);
84
85extern int register_android_message_digest_sha1(JNIEnv *env);
86
87extern int register_android_util_FloatMath(JNIEnv* env);
88
89namespace android {
90
91/*
92 * JNI-based registration functions. Note these are properly contained in
93 * namespace android.
94 */
95extern int register_android_content_AssetManager(JNIEnv* env);
96extern int register_android_util_EventLog(JNIEnv* env);
97extern int register_android_util_Log(JNIEnv* env);
98extern int register_android_content_StringBlock(JNIEnv* env);
99extern int register_android_content_XmlBlock(JNIEnv* env);
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700100extern int register_android_emoji_EmojiFactory(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800101extern int register_android_graphics_Canvas(JNIEnv* env);
102extern int register_android_graphics_ColorFilter(JNIEnv* env);
103extern int register_android_graphics_DrawFilter(JNIEnv* env);
104extern int register_android_graphics_Matrix(JNIEnv* env);
105extern int register_android_graphics_Paint(JNIEnv* env);
106extern int register_android_graphics_Path(JNIEnv* env);
107extern int register_android_graphics_PathMeasure(JNIEnv* env);
108extern int register_android_graphics_Picture(JNIEnv*);
109extern int register_android_graphics_PorterDuff(JNIEnv* env);
110extern int register_android_graphics_Rasterizer(JNIEnv* env);
111extern int register_android_graphics_Xfermode(JNIEnv* env);
112extern int register_android_graphics_PixelFormat(JNIEnv* env);
113extern int register_com_android_internal_graphics_NativeUtils(JNIEnv *env);
114extern int register_android_view_Display(JNIEnv* env);
115extern int register_android_view_Surface(JNIEnv* env);
116extern int register_android_view_ViewRoot(JNIEnv* env);
117extern int register_android_database_CursorWindow(JNIEnv* env);
118extern int register_android_database_SQLiteDatabase(JNIEnv* env);
119extern int register_android_database_SQLiteDebug(JNIEnv* env);
120extern int register_android_database_SQLiteProgram(JNIEnv* env);
121extern int register_android_database_SQLiteQuery(JNIEnv* env);
122extern int register_android_database_SQLiteStatement(JNIEnv* env);
123extern int register_android_debug_JNITest(JNIEnv* env);
124extern int register_android_nio_utils(JNIEnv* env);
125extern int register_android_pim_EventRecurrence(JNIEnv* env);
126extern int register_android_text_format_Time(JNIEnv* env);
127extern int register_android_os_Debug(JNIEnv* env);
128extern int register_android_os_ParcelFileDescriptor(JNIEnv *env);
129extern int register_android_os_Power(JNIEnv *env);
130extern int register_android_os_StatFs(JNIEnv *env);
131extern int register_android_os_SystemProperties(JNIEnv *env);
132extern int register_android_os_Hardware(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800133extern int register_android_os_SystemClock(JNIEnv* env);
134extern int register_android_os_FileObserver(JNIEnv *env);
135extern int register_android_os_FileUtils(JNIEnv *env);
136extern int register_android_os_UEventObserver(JNIEnv* env);
137extern int register_android_os_MemoryFile(JNIEnv* env);
138extern int register_android_net_LocalSocketImpl(JNIEnv* env);
139extern int register_android_net_NetworkUtils(JNIEnv* env);
140extern int register_android_net_wifi_WifiManager(JNIEnv* env);
141extern int register_android_security_Md5MessageDigest(JNIEnv *env);
142extern int register_android_text_AndroidCharacter(JNIEnv *env);
143extern int register_android_text_KeyCharacterMap(JNIEnv *env);
144extern int register_android_opengl_classes(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145extern int register_android_bluetooth_HeadsetBase(JNIEnv* env);
146extern int register_android_bluetooth_BluetoothAudioGateway(JNIEnv* env);
Nick Pelly0b6955a2009-05-26 19:13:43 -0700147extern int register_android_bluetooth_BluetoothSocket(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148extern int register_android_bluetooth_ScoSocket(JNIEnv *env);
Nick Pellybd022f42009-08-14 18:33:38 -0700149extern int register_android_server_BluetoothService(JNIEnv* env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150extern int register_android_server_BluetoothEventLoop(JNIEnv *env);
151extern int register_android_server_BluetoothA2dpService(JNIEnv* env);
152extern int register_android_ddm_DdmHandleNativeHeap(JNIEnv *env);
153extern int register_com_android_internal_os_ZygoteInit(JNIEnv* env);
154extern int register_android_util_Base64(JNIEnv* env);
155extern int register_android_location_GpsLocationProvider(JNIEnv* env);
Joe Onorato1cf58742009-06-12 11:06:24 -0700156extern int register_android_backup_BackupDataInput(JNIEnv *env);
Joe Onoratod2110db2009-05-19 13:41:21 -0700157extern int register_android_backup_BackupDataOutput(JNIEnv *env);
Joe Onorato06290a42009-06-18 20:10:37 -0700158extern int register_android_backup_FileBackupHelperBase(JNIEnv *env);
Joe Onorato4ababd92009-06-25 18:29:18 -0400159extern int register_android_backup_BackupHelperDispatcher(JNIEnv *env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800160
161static AndroidRuntime* gCurRuntime = NULL;
162
163static void doThrow(JNIEnv* env, const char* exc, const char* msg = NULL)
164{
165 if (jniThrowException(env, exc, msg) != 0)
166 assert(false);
167}
168
169/*
170 * Code written in the Java Programming Language calls here from main().
171 */
172static void com_android_internal_os_RuntimeInit_finishInit(JNIEnv* env, jobject clazz)
173{
174 gCurRuntime->onStarted();
175}
176
177static void com_android_internal_os_RuntimeInit_zygoteInit(JNIEnv* env, jobject clazz)
178{
179 gCurRuntime->onZygoteInit();
180}
181
182static jint com_android_internal_os_RuntimeInit_isComputerOn(JNIEnv* env, jobject clazz)
183{
184 return 1;
185}
186
187static void com_android_internal_os_RuntimeInit_turnComputerOn(JNIEnv* env, jobject clazz)
188{
189}
190
191static jint com_android_internal_os_RuntimeInit_getQwertyKeyboard(JNIEnv* env, jobject clazz)
192{
193 char* value = getenv("qwerty");
194 if (value != NULL && strcmp(value, "true") == 0) {
195 return 1;
196 }
197
198 return 0;
199}
200
201/*
202 * JNI registration.
203 */
204static JNINativeMethod gMethods[] = {
205 { "finishInit", "()V",
206 (void*) com_android_internal_os_RuntimeInit_finishInit },
207 { "zygoteInitNative", "()V",
208 (void*) com_android_internal_os_RuntimeInit_zygoteInit },
209 { "isComputerOn", "()I",
210 (void*) com_android_internal_os_RuntimeInit_isComputerOn },
211 { "turnComputerOn", "()V",
212 (void*) com_android_internal_os_RuntimeInit_turnComputerOn },
213 { "getQwertyKeyboard", "()I",
214 (void*) com_android_internal_os_RuntimeInit_getQwertyKeyboard },
215};
216
217int register_com_android_internal_os_RuntimeInit(JNIEnv* env)
218{
219 return jniRegisterNativeMethods(env, "com/android/internal/os/RuntimeInit",
220 gMethods, NELEM(gMethods));
221}
222
223// ----------------------------------------------------------------------
224
225/*static*/ JavaVM* AndroidRuntime::mJavaVM = NULL;
226
227
228AndroidRuntime::AndroidRuntime()
229{
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700230 SkGraphics::Init();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800231 // this sets our preference for 16bit images during decode
232 // in case the src is opaque and 24bit
233 SkImageDecoder::SetDeviceConfig(SkBitmap::kRGB_565_Config);
Mike Reedfc8db532009-04-27 11:43:30 -0400234 // This cache is shared between browser native images, and java "purgeable"
235 // bitmaps. This globalpool is for images that do not either use the java
236 // heap, or are not backed by ashmem. See BitmapFactory.cpp for the key
237 // java call site.
238 SkImageRef_GlobalPool::SetRAMBudget(512 * 1024);
239 // There is also a global font cache, but its budget is specified in code
240 // see SkFontHost_android.cpp
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800241
242 // Pre-allocate enough space to hold a fair number of options.
243 mOptions.setCapacity(20);
244
245 assert(gCurRuntime == NULL); // one per process
246 gCurRuntime = this;
247}
248
249AndroidRuntime::~AndroidRuntime()
250{
251 SkGraphics::Term();
252}
253
254/*
255 * Register native methods using JNI.
256 */
257/*static*/ int AndroidRuntime::registerNativeMethods(JNIEnv* env,
258 const char* className, const JNINativeMethod* gMethods, int numMethods)
259{
260 return jniRegisterNativeMethods(env, className, gMethods, numMethods);
261}
262
263/*
264 * Call a static Java Programming Language function that takes no arguments and returns void.
265 */
266status_t AndroidRuntime::callStatic(const char* className, const char* methodName)
267{
268 JNIEnv* env;
269 jclass clazz;
270 jmethodID methodId;
271
272 env = getJNIEnv();
273 if (env == NULL)
274 return UNKNOWN_ERROR;
275
276 clazz = findClass(env, className);
277 if (clazz == NULL) {
278 LOGE("ERROR: could not find class '%s'\n", className);
279 return UNKNOWN_ERROR;
280 }
281 methodId = env->GetStaticMethodID(clazz, methodName, "()V");
282 if (methodId == NULL) {
283 LOGE("ERROR: could not find method %s.%s\n", className, methodName);
284 return UNKNOWN_ERROR;
285 }
286
287 env->CallStaticVoidMethod(clazz, methodId);
288
289 return NO_ERROR;
290}
291
292status_t AndroidRuntime::callMain(
293 const char* className, int argc, const char* const argv[])
294{
295 JNIEnv* env;
296 jclass clazz;
297 jmethodID methodId;
298
299 env = getJNIEnv();
300 if (env == NULL)
301 return UNKNOWN_ERROR;
302
303 clazz = findClass(env, className);
304 if (clazz == NULL) {
305 LOGE("ERROR: could not find class '%s'\n", className);
306 return UNKNOWN_ERROR;
307 }
308
309 methodId = env->GetStaticMethodID(clazz, "main", "([Ljava/lang/String;)V");
310 if (methodId == NULL) {
311 LOGE("ERROR: could not find method %s.main(String[])\n", className);
312 return UNKNOWN_ERROR;
313 }
314
315 /*
316 * We want to call main() with a String array with our arguments in it.
317 * Create an array and populate it.
318 */
319 jclass stringClass;
320 jobjectArray strArray;
321
322 stringClass = env->FindClass("java/lang/String");
323 strArray = env->NewObjectArray(argc, stringClass, NULL);
324
325 for (int i = 0; i < argc; i++) {
326 jstring argStr = env->NewStringUTF(argv[i]);
327 env->SetObjectArrayElement(strArray, i, argStr);
328 }
329
330 env->CallStaticVoidMethod(clazz, methodId, strArray);
331 return NO_ERROR;
332}
333
334/*
335 * Find the named class.
336 */
337jclass AndroidRuntime::findClass(JNIEnv* env, const char* className)
338{
339 char* convName = NULL;
340
341 if (env->ExceptionCheck()) {
342 LOGE("ERROR: exception pending on entry to findClass()\n");
343 return NULL;
344 }
345
346 /*
347 * JNI FindClass uses class names with slashes, but ClassLoader.loadClass
348 * uses the dotted "binary name" format. We don't need to convert the
349 * name with the new approach.
350 */
351#if 0
352 /* (convName only created if necessary -- use className) */
353 for (char* cp = const_cast<char*>(className); *cp != '\0'; cp++) {
354 if (*cp == '.') {
355 if (convName == NULL) {
356 convName = strdup(className);
357 cp = convName + (cp-className);
358 className = convName;
359 }
360 *cp = '/';
361 }
362 }
363#endif
364
365 /*
366 * This is a little awkward because the JNI FindClass call uses the
367 * class loader associated with the native method we're executing in.
368 * Because this native method is part of a "boot" class, JNI doesn't
369 * look for the class in CLASSPATH, which unfortunately is a likely
370 * location for it. (Had we issued the FindClass call before calling
371 * into the VM -- at which point there isn't a native method frame on
372 * the stack -- the VM would have checked CLASSPATH. We have to do
373 * this because we call into Java Programming Language code and
374 * bounce back out.)
375 *
376 * JNI lacks a "find class in a specific class loader" operation, so we
377 * have to do things the hard way.
378 */
379 jclass cls = NULL;
380 //cls = env->FindClass(className);
381
382 jclass javaLangClassLoader;
383 jmethodID getSystemClassLoader, loadClass;
384 jobject systemClassLoader;
385 jstring strClassName;
386
387 /* find the "system" class loader; none of this is expected to fail */
388 javaLangClassLoader = env->FindClass("java/lang/ClassLoader");
389 assert(javaLangClassLoader != NULL);
390 getSystemClassLoader = env->GetStaticMethodID(javaLangClassLoader,
391 "getSystemClassLoader", "()Ljava/lang/ClassLoader;");
392 loadClass = env->GetMethodID(javaLangClassLoader,
393 "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;");
394 assert(getSystemClassLoader != NULL && loadClass != NULL);
395 systemClassLoader = env->CallStaticObjectMethod(javaLangClassLoader,
396 getSystemClassLoader);
397 assert(systemClassLoader != NULL);
398
399 /* create an object for the class name string; alloc could fail */
400 strClassName = env->NewStringUTF(className);
401 if (env->ExceptionCheck()) {
402 LOGE("ERROR: unable to convert '%s' to string\n", className);
403 goto bail;
404 }
405 LOGV("system class loader is %p, loading %p (%s)\n",
406 systemClassLoader, strClassName, className);
407
408 /* try to find the named class */
409 cls = (jclass) env->CallObjectMethod(systemClassLoader, loadClass,
410 strClassName);
411 if (env->ExceptionCheck()) {
412 LOGE("ERROR: unable to load class '%s' from %p\n",
413 className, systemClassLoader);
414 cls = NULL;
415 goto bail;
416 }
417
418bail:
419 free(convName);
420 return cls;
421}
422
423/*
424 * The VM calls this through the "exit" hook.
425 */
426static void runtime_exit(int code)
427{
428 gCurRuntime->onExit(code);
429 exit(code);
430}
431
432/*
433 * The VM calls this through the "vfprintf" hook.
434 *
435 * We ignore "fp" and just write the results to the log file.
436 */
437static void runtime_vfprintf(FILE* fp, const char* format, va_list ap)
438{
439 LOG_PRI_VA(ANDROID_LOG_INFO, "vm-printf", format, ap);
440}
441
442
443/**
444 * Add VM arguments to the to-be-executed VM
445 * Stops at first non '-' argument (also stops at an argument of '--')
446 * Returns the number of args consumed
447 */
448int AndroidRuntime::addVmArguments(int argc, const char* const argv[])
449{
450 int i;
451
452 for (i = 0; i<argc; i++) {
453 if (argv[i][0] != '-') {
454 return i;
455 }
456 if (argv[i][1] == '-' && argv[i][2] == 0) {
457 return i+1;
458 }
459
460 JavaVMOption opt;
461 memset(&opt, 0, sizeof(opt));
462 opt.optionString = (char*)argv[i];
463 mOptions.add(opt);
464 }
465 return i;
466}
467
468static int hasDir(const char* dir)
469{
470 struct stat s;
471 int res = stat(dir, &s);
472 if (res == 0) {
473 return S_ISDIR(s.st_mode);
474 }
475 return 0;
476}
477
478/*
479 * We just want failed write() calls to just return with an error.
480 */
481static void blockSigpipe()
482{
483 sigset_t mask;
484
485 sigemptyset(&mask);
486 sigaddset(&mask, SIGPIPE);
487 if (sigprocmask(SIG_BLOCK, &mask, NULL) != 0)
488 LOGW("WARNING: SIGPIPE not blocked\n");
489}
490
491/*
492 * Read the persistent locale.
493 */
494static void readLocale(char* language, char* region)
495{
496 char propLang[PROPERTY_VALUE_MAX], propRegn[PROPERTY_VALUE_MAX];
497
498 property_get("persist.sys.language", propLang, "");
499 property_get("persist.sys.country", propRegn, "");
500 if (*propLang == 0 && *propRegn == 0) {
501 /* Set to ro properties, default is en_US */
502 property_get("ro.product.locale.language", propLang, "en");
503 property_get("ro.product.locale.region", propRegn, "US");
504 }
505 strncat(language, propLang, 2);
506 strncat(region, propRegn, 2);
507 //LOGD("language=%s region=%s\n", language, region);
508}
509
Andy McFaddenf70188a2009-03-31 15:52:13 -0700510/*
511 * Start the Dalvik Virtual Machine.
512 *
513 * Various arguments, most determined by system properties, are passed in.
514 * The "mOptions" vector is updated.
515 *
516 * Returns 0 on success.
517 */
518int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800519{
Andy McFaddenf70188a2009-03-31 15:52:13 -0700520 int result = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800521 JavaVMInitArgs initArgs;
522 JavaVMOption opt;
523 char propBuf[PROPERTY_VALUE_MAX];
524 char stackTraceFileBuf[PROPERTY_VALUE_MAX];
525 char dexoptFlagsBuf[PROPERTY_VALUE_MAX];
526 char enableAssertBuf[sizeof("-ea:")-1 + PROPERTY_VALUE_MAX];
527 char jniOptsBuf[sizeof("-Xjniopts:")-1 + PROPERTY_VALUE_MAX];
Dianne Hackbornbdcef702009-08-18 19:15:36 -0700528 char heapsizeOptsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800529 char* stackTraceFile = NULL;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800530 bool checkJni = false;
Andy McFaddene2b23e12009-04-03 11:09:46 -0700531 bool checkDexSum = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800532 bool logStdio = false;
Ben Cheng52b0e732009-06-19 13:31:12 -0700533 enum {
534 kEMDefault,
535 kEMIntPortable,
536 kEMIntFast,
537#if defined(WITH_JIT)
538 kEMJitCompiler,
539#endif
540 } executionMode = kEMDefault;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800541
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800542
543 property_get("dalvik.vm.checkjni", propBuf, "");
544 if (strcmp(propBuf, "true") == 0) {
545 checkJni = true;
546 } else if (strcmp(propBuf, "false") != 0) {
547 /* property is neither true nor false; fall back on kernel parameter */
548 property_get("ro.kernel.android.checkjni", propBuf, "");
549 if (propBuf[0] == '1') {
550 checkJni = true;
551 }
552 }
553
554 property_get("dalvik.vm.execution-mode", propBuf, "");
555 if (strcmp(propBuf, "int:portable") == 0) {
556 executionMode = kEMIntPortable;
557 } else if (strcmp(propBuf, "int:fast") == 0) {
558 executionMode = kEMIntFast;
Ben Cheng52b0e732009-06-19 13:31:12 -0700559#if defined(WITH_JIT)
560 } else if (strcmp(propBuf, "int:jit") == 0) {
561 executionMode = kEMJitCompiler;
562#endif
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800563 }
564
565 property_get("dalvik.vm.stack-trace-file", stackTraceFileBuf, "");
566
Andy McFaddene2b23e12009-04-03 11:09:46 -0700567 property_get("dalvik.vm.check-dex-sum", propBuf, "");
568 if (strcmp(propBuf, "true") == 0) {
569 checkDexSum = true;
570 }
571
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800572 property_get("log.redirect-stdio", propBuf, "");
573 if (strcmp(propBuf, "true") == 0) {
574 logStdio = true;
575 }
576
577 strcpy(enableAssertBuf, "-ea:");
578 property_get("dalvik.vm.enableassertions", enableAssertBuf+4, "");
579
580 strcpy(jniOptsBuf, "-Xjniopts:");
581 property_get("dalvik.vm.jniopts", jniOptsBuf+10, "");
582
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800583 /* route exit() to our handler */
584 opt.extraInfo = (void*) runtime_exit;
585 opt.optionString = "exit";
586 mOptions.add(opt);
587
588 /* route fprintf() to our handler */
589 opt.extraInfo = (void*) runtime_vfprintf;
590 opt.optionString = "vfprintf";
591 mOptions.add(opt);
592
593 opt.extraInfo = NULL;
594
595 /* enable verbose; standard options are { jni, gc, class } */
596 //options[curOpt++].optionString = "-verbose:jni";
597 opt.optionString = "-verbose:gc";
598 mOptions.add(opt);
599 //options[curOpt++].optionString = "-verbose:class";
600
Dianne Hackbornbdcef702009-08-18 19:15:36 -0700601 strcpy(heapsizeOptsBuf, "-Xmx");
602 property_get("dalvik.vm.heapsize", heapsizeOptsBuf+4, "16m");
603 //LOGI("Heap size: %s", heapsizeOptsBuf);
604 opt.optionString = heapsizeOptsBuf;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800605 mOptions.add(opt);
606
607 /*
608 * Enable or disable dexopt features, such as bytecode verification and
609 * calculation of register maps for precise GC.
610 */
611 property_get("dalvik.vm.dexopt-flags", dexoptFlagsBuf, "");
612 if (dexoptFlagsBuf[0] != '\0') {
613 const char* opc;
614 const char* val;
615
616 opc = strstr(dexoptFlagsBuf, "v="); /* verification */
617 if (opc != NULL) {
618 switch (*(opc+2)) {
619 case 'n': val = "-Xverify:none"; break;
620 case 'r': val = "-Xverify:remote"; break;
621 case 'a': val = "-Xverify:all"; break;
622 default: val = NULL; break;
623 }
624
625 if (val != NULL) {
626 opt.optionString = val;
627 mOptions.add(opt);
628 }
629 }
630
631 opc = strstr(dexoptFlagsBuf, "o="); /* optimization */
632 if (opc != NULL) {
633 switch (*(opc+2)) {
634 case 'n': val = "-Xdexopt:none"; break;
635 case 'v': val = "-Xdexopt:verified"; break;
636 case 'a': val = "-Xdexopt:all"; break;
637 default: val = NULL; break;
638 }
639
640 if (val != NULL) {
641 opt.optionString = val;
642 mOptions.add(opt);
643 }
644 }
645
646 opc = strstr(dexoptFlagsBuf, "m=y"); /* register map */
647 if (opc != NULL) {
648 opt.optionString = "-Xgenregmap";
649 mOptions.add(opt);
The Android Open Source Project7b0b1ed2009-03-18 22:20:26 -0700650
651 /* turn on precise GC while we're at it */
652 opt.optionString = "-Xgc:precise";
653 mOptions.add(opt);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800654 }
655 }
656
657 /* enable debugging; set suspend=y to pause during VM init */
658#ifdef HAVE_ANDROID_OS
659 /* use android ADB transport */
660 opt.optionString =
661 "-agentlib:jdwp=transport=dt_android_adb,suspend=n,server=y";
662#else
663 /* use TCP socket; address=0 means start at port 8000 and probe up */
664 LOGI("Using TCP socket for JDWP\n");
665 opt.optionString =
666 "-agentlib:jdwp=transport=dt_socket,suspend=n,server=y,address=0";
667#endif
668 mOptions.add(opt);
669
670 char enableDPBuf[sizeof("-Xdeadlockpredict:") + PROPERTY_VALUE_MAX];
671 property_get("dalvik.vm.deadlock-predict", propBuf, "");
672 if (strlen(propBuf) > 0) {
673 strcpy(enableDPBuf, "-Xdeadlockpredict:");
674 strcat(enableDPBuf, propBuf);
675 opt.optionString = enableDPBuf;
676 mOptions.add(opt);
677 }
678
679 LOGD("CheckJNI is %s\n", checkJni ? "ON" : "OFF");
680 if (checkJni) {
681 /* extended JNI checking */
682 opt.optionString = "-Xcheck:jni";
683 mOptions.add(opt);
684
685 /* set a cap on JNI global references */
686 opt.optionString = "-Xjnigreflimit:2000";
687 mOptions.add(opt);
688
689 /* with -Xcheck:jni, this provides a JNI function call trace */
690 //opt.optionString = "-verbose:jni";
691 //mOptions.add(opt);
692 }
Ben Cheng52b0e732009-06-19 13:31:12 -0700693
694#if defined(WITH_JIT)
695 /* Minimal profile threshold to trigger JIT compilation */
696 char jitThresholdBuf[sizeof("-Xthreshold:") + PROPERTY_VALUE_MAX];
697 property_get("dalvik.vm.jit.threshold", propBuf, "");
698 if (strlen(propBuf) > 0) {
699 strcpy(jitThresholdBuf, "-Xthreshold:");
700 strcat(jitThresholdBuf, propBuf);
701 opt.optionString = jitThresholdBuf;
702 mOptions.add(opt);
703 }
704
705 /* Force interpreter-only mode for selected opcodes. Eg "1-0a,3c,f1-ff" */
706 char jitOpBuf[sizeof("-Xjitop:") + PROPERTY_VALUE_MAX];
707 property_get("dalvik.vm.jit.op", propBuf, "");
708 if (strlen(propBuf) > 0) {
709 strcpy(jitOpBuf, "-Xjitop:");
710 strcat(jitOpBuf, propBuf);
711 opt.optionString = jitOpBuf;
712 mOptions.add(opt);
713 }
714
715 /*
716 * Reverse the polarity of dalvik.vm.jit.op and force interpreter-only
717 * for non-selected opcodes.
718 */
Ben Chenge090f3b2009-06-19 17:13:36 -0700719 property_get("dalvik.vm.jit.includeop", propBuf, "");
Ben Cheng52b0e732009-06-19 13:31:12 -0700720 if (strlen(propBuf) > 0) {
721 opt.optionString = "-Xincludeselectedop";
722 mOptions.add(opt);
723 }
724
725 /* Force interpreter-only mode for selected methods */
726 char jitMethodBuf[sizeof("-Xjitmethod:") + PROPERTY_VALUE_MAX];
727 property_get("dalvik.vm.jit.method", propBuf, "");
728 if (strlen(propBuf) > 0) {
729 strcpy(jitMethodBuf, "-Xjitmethod:");
730 strcat(jitMethodBuf, propBuf);
731 opt.optionString = jitMethodBuf;
732 mOptions.add(opt);
733 }
734
735 /*
736 * Reverse the polarity of dalvik.vm.jit.method and force interpreter-only
737 * for non-selected methods.
738 */
Ben Chenge090f3b2009-06-19 17:13:36 -0700739 property_get("dalvik.vm.jit.includemethod", propBuf, "");
Ben Cheng52b0e732009-06-19 13:31:12 -0700740 if (strlen(propBuf) > 0) {
741 opt.optionString = "-Xincludeselectedmethod";
742 mOptions.add(opt);
743 }
Ben Cheng0e01fbf2009-07-17 16:03:26 -0700744
745 /*
746 * Enable profile collection on JIT'ed code.
747 */
748 property_get("dalvik.vm.jit.profile", propBuf, "");
749 if (strlen(propBuf) > 0) {
750 opt.optionString = "-Xjitprofile";
751 mOptions.add(opt);
752 }
Ben Chengacc56ec2009-09-11 12:59:53 -0700753
754 /*
755 * Disable optimizations by setting the corresponding bit to 1.
756 */
757 char jitOptBuf[sizeof("-Xjitdisableopt:") + PROPERTY_VALUE_MAX];
758 property_get("dalvik.vm.jit.disableopt", propBuf, "");
759 if (strlen(propBuf) > 0) {
760 strcpy(jitOptBuf, "-Xjitdisableopt:");
761 strcat(jitOptBuf, propBuf);
762 opt.optionString = jitOptBuf;
763 mOptions.add(opt);
764 }
Ben Cheng52b0e732009-06-19 13:31:12 -0700765#endif
766
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800767 if (executionMode == kEMIntPortable) {
768 opt.optionString = "-Xint:portable";
769 mOptions.add(opt);
770 } else if (executionMode == kEMIntFast) {
771 opt.optionString = "-Xint:fast";
772 mOptions.add(opt);
Ben Cheng52b0e732009-06-19 13:31:12 -0700773#if defined(WITH_JIT)
774 } else if (executionMode == kEMJitCompiler) {
775 opt.optionString = "-Xint:jit";
776 mOptions.add(opt);
777#endif
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800778 }
Andy McFaddene2b23e12009-04-03 11:09:46 -0700779
780 if (checkDexSum) {
781 /* perform additional DEX checksum tests */
782 opt.optionString = "-Xcheckdexsum";
783 mOptions.add(opt);
784 }
785
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800786 if (logStdio) {
787 /* convert stdout/stderr to log messages */
788 opt.optionString = "-Xlog-stdio";
789 mOptions.add(opt);
790 }
791
792 if (enableAssertBuf[4] != '\0') {
793 /* accept "all" to mean "all classes and packages" */
794 if (strcmp(enableAssertBuf+4, "all") == 0)
795 enableAssertBuf[3] = '\0';
796 LOGI("Assertions enabled: '%s'\n", enableAssertBuf);
797 opt.optionString = enableAssertBuf;
798 mOptions.add(opt);
799 } else {
800 LOGV("Assertions disabled\n");
801 }
802
803 if (jniOptsBuf[10] != '\0') {
804 LOGI("JNI options: '%s'\n", jniOptsBuf);
805 opt.optionString = jniOptsBuf;
806 mOptions.add(opt);
807 }
808
809 if (stackTraceFileBuf[0] != '\0') {
810 static const char* stfOptName = "-Xstacktracefile:";
811
812 stackTraceFile = (char*) malloc(strlen(stfOptName) +
813 strlen(stackTraceFileBuf) +1);
814 strcpy(stackTraceFile, stfOptName);
815 strcat(stackTraceFile, stackTraceFileBuf);
816 opt.optionString = stackTraceFile;
817 mOptions.add(opt);
818 }
819
820 /* Set the properties for locale */
821 {
822 char langOption[sizeof("-Duser.language=") + 3];
823 char regionOption[sizeof("-Duser.region=") + 3];
824 strcpy(langOption, "-Duser.language=");
825 strcpy(regionOption, "-Duser.region=");
826 readLocale(langOption, regionOption);
827 opt.extraInfo = NULL;
828 opt.optionString = langOption;
829 mOptions.add(opt);
830 opt.optionString = regionOption;
831 mOptions.add(opt);
832 }
833
834 /*
835 * We don't have /tmp on the device, but we often have an SD card. Apps
836 * shouldn't use this, but some test suites might want to exercise it.
837 */
838 opt.optionString = "-Djava.io.tmpdir=/sdcard";
839 mOptions.add(opt);
840
841 initArgs.version = JNI_VERSION_1_4;
842 initArgs.options = mOptions.editArray();
843 initArgs.nOptions = mOptions.size();
844 initArgs.ignoreUnrecognized = JNI_FALSE;
845
846 /*
847 * Initialize the VM.
848 *
849 * The JavaVM* is essentially per-process, and the JNIEnv* is per-thread.
850 * If this call succeeds, the VM is ready, and we can start issuing
851 * JNI calls.
852 */
Andy McFaddenf70188a2009-03-31 15:52:13 -0700853 if (JNI_CreateJavaVM(pJavaVM, pEnv, &initArgs) < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800854 LOGE("JNI_CreateJavaVM failed\n");
855 goto bail;
856 }
857
Andy McFaddenf70188a2009-03-31 15:52:13 -0700858 result = 0;
859
860bail:
861 free(stackTraceFile);
862 return result;
863}
864
865/*
866 * Start the Android runtime. This involves starting the virtual machine
867 * and calling the "static void main(String[] args)" method in the class
868 * named by "className".
869 */
870void AndroidRuntime::start(const char* className, const bool startSystemServer)
871{
872 LOGD("\n>>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<\n");
873
874 char* slashClassName = NULL;
875 char* cp;
876 JNIEnv* env;
877
878 blockSigpipe();
879
880 /*
881 * 'startSystemServer == true' means runtime is obslete and not run from
882 * init.rc anymore, so we print out the boot start event here.
883 */
884 if (startSystemServer) {
885 /* track our progress through the boot sequence */
886 const int LOG_BOOT_PROGRESS_START = 3000;
887 LOG_EVENT_LONG(LOG_BOOT_PROGRESS_START,
888 ns2ms(systemTime(SYSTEM_TIME_MONOTONIC)));
889 }
890
891 const char* rootDir = getenv("ANDROID_ROOT");
892 if (rootDir == NULL) {
893 rootDir = "/system";
894 if (!hasDir("/system")) {
895 LOG_FATAL("No root directory specified, and /android does not exist.");
896 goto bail;
897 }
898 setenv("ANDROID_ROOT", rootDir, 1);
899 }
900
901 //const char* kernelHack = getenv("LD_ASSUME_KERNEL");
902 //LOGD("Found LD_ASSUME_KERNEL='%s'\n", kernelHack);
903
904 /* start the virtual machine */
905 if (startVm(&mJavaVM, &env) != 0)
906 goto bail;
907
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800908 /*
909 * Register android functions.
910 */
911 if (startReg(env) < 0) {
912 LOGE("Unable to register all android natives\n");
913 goto bail;
914 }
915
916 /*
917 * We want to call main() with a String array with arguments in it.
918 * At present we only have one argument, the class name. Create an
919 * array to hold it.
920 */
921 jclass stringClass;
922 jobjectArray strArray;
923 jstring classNameStr;
924 jstring startSystemServerStr;
925
926 stringClass = env->FindClass("java/lang/String");
927 assert(stringClass != NULL);
928 strArray = env->NewObjectArray(2, stringClass, NULL);
929 assert(strArray != NULL);
930 classNameStr = env->NewStringUTF(className);
931 assert(classNameStr != NULL);
932 env->SetObjectArrayElement(strArray, 0, classNameStr);
933 startSystemServerStr = env->NewStringUTF(startSystemServer ?
934 "true" : "false");
935 env->SetObjectArrayElement(strArray, 1, startSystemServerStr);
936
937 /*
938 * Start VM. This thread becomes the main thread of the VM, and will
939 * not return until the VM exits.
940 */
941 jclass startClass;
942 jmethodID startMeth;
943
944 slashClassName = strdup(className);
945 for (cp = slashClassName; *cp != '\0'; cp++)
946 if (*cp == '.')
947 *cp = '/';
948
949 startClass = env->FindClass(slashClassName);
950 if (startClass == NULL) {
951 LOGE("JavaVM unable to locate class '%s'\n", slashClassName);
952 /* keep going */
953 } else {
954 startMeth = env->GetStaticMethodID(startClass, "main",
955 "([Ljava/lang/String;)V");
956 if (startMeth == NULL) {
957 LOGE("JavaVM unable to find main() in '%s'\n", className);
958 /* keep going */
959 } else {
960 env->CallStaticVoidMethod(startClass, startMeth, strArray);
961
962#if 0
963 if (env->ExceptionCheck())
964 threadExitUncaughtException(env);
965#endif
966 }
967 }
968
969 LOGD("Shutting down VM\n");
970 if (mJavaVM->DetachCurrentThread() != JNI_OK)
971 LOGW("Warning: unable to detach main thread\n");
972 if (mJavaVM->DestroyJavaVM() != 0)
973 LOGW("Warning: VM did not shut down cleanly\n");
974
975bail:
976 free(slashClassName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800977}
978
979void AndroidRuntime::start()
980{
981 start("com.android.internal.os.RuntimeInit",
982 false /* Don't start the system server */);
983}
984
985void AndroidRuntime::onExit(int code)
986{
987 LOGI("AndroidRuntime onExit calling exit(%d)", code);
988 exit(code);
989}
990
991/*
992 * Get the JNIEnv pointer for this thread.
993 *
994 * Returns NULL if the slot wasn't allocated or populated.
995 */
996/*static*/ JNIEnv* AndroidRuntime::getJNIEnv()
997{
998 JNIEnv* env;
999 JavaVM* vm = AndroidRuntime::getJavaVM();
1000 assert(vm != NULL);
1001
1002 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK)
1003 return NULL;
1004 return env;
1005}
1006
1007/*
1008 * Makes the current thread visible to the VM.
1009 *
1010 * The JNIEnv pointer returned is only valid for the current thread, and
1011 * thus must be tucked into thread-local storage.
1012 */
1013static int javaAttachThread(const char* threadName, JNIEnv** pEnv)
1014{
1015 JavaVMAttachArgs args;
1016 JavaVM* vm;
1017 jint result;
1018
1019 vm = AndroidRuntime::getJavaVM();
1020 assert(vm != NULL);
1021
1022 args.version = JNI_VERSION_1_4;
1023 args.name = (char*) threadName;
1024 args.group = NULL;
1025
1026 result = vm->AttachCurrentThread(pEnv, (void*) &args);
1027 if (result != JNI_OK)
1028 LOGE("ERROR: thread attach failed\n");
1029
1030 return result;
1031}
1032
1033/*
1034 * Detach the current thread from the set visible to the VM.
1035 */
1036static int javaDetachThread(void)
1037{
1038 JavaVM* vm;
1039 jint result;
1040
1041 vm = AndroidRuntime::getJavaVM();
1042 assert(vm != NULL);
1043
1044 result = vm->DetachCurrentThread();
1045 if (result != JNI_OK)
1046 LOGE("ERROR: thread detach failed\n");
1047 return result;
1048}
1049
1050/*
1051 * When starting a native thread that will be visible from the VM, we
1052 * bounce through this to get the right attach/detach action.
1053 * Note that this function calls free(args)
1054 */
1055/*static*/ int AndroidRuntime::javaThreadShell(void* args) {
1056 void* start = ((void**)args)[0];
1057 void* userData = ((void **)args)[1];
1058 char* name = (char*) ((void **)args)[2]; // we own this storage
1059 free(args);
1060 JNIEnv* env;
1061 int result;
1062
1063 /* hook us into the VM */
1064 if (javaAttachThread(name, &env) != JNI_OK)
1065 return -1;
1066
1067 /* start the thread running */
1068 result = (*(android_thread_func_t)start)(userData);
1069
1070 /* unhook us */
1071 javaDetachThread();
1072 free(name);
1073
1074 return result;
1075}
1076
1077/*
1078 * This is invoked from androidCreateThreadEtc() via the callback
1079 * set with androidSetCreateThreadFunc().
1080 *
1081 * We need to create the new thread in such a way that it gets hooked
1082 * into the VM before it really starts executing.
1083 */
1084/*static*/ int AndroidRuntime::javaCreateThreadEtc(
1085 android_thread_func_t entryFunction,
1086 void* userData,
1087 const char* threadName,
1088 int32_t threadPriority,
1089 size_t threadStackSize,
1090 android_thread_id_t* threadId)
1091{
1092 void** args = (void**) malloc(3 * sizeof(void*)); // javaThreadShell must free
1093 int result;
1094
1095 assert(threadName != NULL);
1096
1097 args[0] = (void*) entryFunction;
1098 args[1] = userData;
1099 args[2] = (void*) strdup(threadName); // javaThreadShell must free
1100
1101 result = androidCreateRawThreadEtc(AndroidRuntime::javaThreadShell, args,
1102 threadName, threadPriority, threadStackSize, threadId);
1103 return result;
1104}
1105
1106/*
1107 * Create a thread that is visible from the VM.
1108 *
1109 * This is called from elsewhere in the library.
1110 */
1111/*static*/ void AndroidRuntime::createJavaThread(const char* name,
1112 void (*start)(void *), void* arg)
1113{
1114 javaCreateThreadEtc((android_thread_func_t) start, arg, name,
1115 ANDROID_PRIORITY_DEFAULT, 0, NULL);
1116}
1117
1118#if 0
1119static void quickTest(void* arg)
1120{
1121 const char* str = (const char*) arg;
1122
1123 printf("In quickTest: %s\n", str);
1124}
1125#endif
1126
1127#ifdef NDEBUG
1128 #define REG_JNI(name) { name }
1129 struct RegJNIRec {
1130 int (*mProc)(JNIEnv*);
1131 };
1132#else
1133 #define REG_JNI(name) { name, #name }
1134 struct RegJNIRec {
1135 int (*mProc)(JNIEnv*);
1136 const char* mName;
1137 };
1138#endif
1139
1140typedef void (*RegJAMProc)();
1141
1142static int register_jni_procs(const RegJNIRec array[], size_t count, JNIEnv* env)
1143{
1144 for (size_t i = 0; i < count; i++) {
1145 if (array[i].mProc(env) < 0) {
1146#ifndef NDEBUG
1147 LOGD("----------!!! %s failed to load\n", array[i].mName);
1148#endif
1149 return -1;
1150 }
1151 }
1152 return 0;
1153}
1154
1155static void register_jam_procs(const RegJAMProc array[], size_t count)
1156{
1157 for (size_t i = 0; i < count; i++) {
1158 array[i]();
1159 }
1160}
1161
1162static const RegJNIRec gRegJNI[] = {
1163 REG_JNI(register_android_debug_JNITest),
1164 REG_JNI(register_com_android_internal_os_RuntimeInit),
1165 REG_JNI(register_android_os_SystemClock),
1166 REG_JNI(register_android_util_EventLog),
1167 REG_JNI(register_android_util_Log),
1168 REG_JNI(register_android_util_FloatMath),
1169 REG_JNI(register_android_text_format_Time),
1170 REG_JNI(register_android_pim_EventRecurrence),
1171 REG_JNI(register_android_content_AssetManager),
1172 REG_JNI(register_android_content_StringBlock),
1173 REG_JNI(register_android_content_XmlBlock),
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001174 REG_JNI(register_android_emoji_EmojiFactory),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001175 REG_JNI(register_android_security_Md5MessageDigest),
1176 REG_JNI(register_android_text_AndroidCharacter),
1177 REG_JNI(register_android_text_KeyCharacterMap),
1178 REG_JNI(register_android_os_Process),
1179 REG_JNI(register_android_os_Binder),
1180 REG_JNI(register_android_os_Hardware),
1181 REG_JNI(register_android_view_Display),
1182 REG_JNI(register_android_nio_utils),
1183 REG_JNI(register_android_graphics_PixelFormat),
1184 REG_JNI(register_android_graphics_Graphics),
1185 REG_JNI(register_android_view_Surface),
1186 REG_JNI(register_android_view_ViewRoot),
1187 REG_JNI(register_com_google_android_gles_jni_EGLImpl),
1188 REG_JNI(register_com_google_android_gles_jni_GLImpl),
Jack Palevich1c4907e2009-04-13 16:22:25 -07001189 REG_JNI(register_android_opengl_jni_GLES10),
1190 REG_JNI(register_android_opengl_jni_GLES10Ext),
1191 REG_JNI(register_android_opengl_jni_GLES11),
1192 REG_JNI(register_android_opengl_jni_GLES11Ext),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001193
1194 REG_JNI(register_android_graphics_Bitmap),
1195 REG_JNI(register_android_graphics_BitmapFactory),
1196 REG_JNI(register_android_graphics_Camera),
1197 REG_JNI(register_android_graphics_Canvas),
1198 REG_JNI(register_android_graphics_ColorFilter),
1199 REG_JNI(register_android_graphics_DrawFilter),
1200 REG_JNI(register_android_graphics_Interpolator),
1201 REG_JNI(register_android_graphics_LayerRasterizer),
1202 REG_JNI(register_android_graphics_MaskFilter),
1203 REG_JNI(register_android_graphics_Matrix),
1204 REG_JNI(register_android_graphics_Movie),
1205 REG_JNI(register_android_graphics_NinePatch),
1206 REG_JNI(register_android_graphics_Paint),
1207 REG_JNI(register_android_graphics_Path),
1208 REG_JNI(register_android_graphics_PathMeasure),
1209 REG_JNI(register_android_graphics_PathEffect),
1210 REG_JNI(register_android_graphics_Picture),
1211 REG_JNI(register_android_graphics_PorterDuff),
1212 REG_JNI(register_android_graphics_Rasterizer),
1213 REG_JNI(register_android_graphics_Region),
1214 REG_JNI(register_android_graphics_Shader),
1215 REG_JNI(register_android_graphics_Typeface),
1216 REG_JNI(register_android_graphics_Xfermode),
1217 REG_JNI(register_com_android_internal_graphics_NativeUtils),
1218
1219 REG_JNI(register_android_database_CursorWindow),
1220 REG_JNI(register_android_database_SQLiteDatabase),
1221 REG_JNI(register_android_database_SQLiteDebug),
1222 REG_JNI(register_android_database_SQLiteProgram),
1223 REG_JNI(register_android_database_SQLiteQuery),
1224 REG_JNI(register_android_database_SQLiteStatement),
1225 REG_JNI(register_android_os_Debug),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001226 REG_JNI(register_android_os_FileObserver),
1227 REG_JNI(register_android_os_FileUtils),
1228 REG_JNI(register_android_os_ParcelFileDescriptor),
1229 REG_JNI(register_android_os_Power),
1230 REG_JNI(register_android_os_StatFs),
1231 REG_JNI(register_android_os_SystemProperties),
1232 REG_JNI(register_android_os_UEventObserver),
1233 REG_JNI(register_android_net_LocalSocketImpl),
1234 REG_JNI(register_android_net_NetworkUtils),
1235 REG_JNI(register_android_net_wifi_WifiManager),
1236 REG_JNI(register_android_os_MemoryFile),
1237 REG_JNI(register_com_android_internal_os_ZygoteInit),
1238 REG_JNI(register_android_hardware_Camera),
1239 REG_JNI(register_android_hardware_SensorManager),
1240 REG_JNI(register_android_media_AudioRecord),
1241 REG_JNI(register_android_media_AudioSystem),
1242 REG_JNI(register_android_media_AudioTrack),
1243 REG_JNI(register_android_media_JetPlayer),
1244 REG_JNI(register_android_media_ToneGenerator),
1245
1246 REG_JNI(register_android_opengl_classes),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001247 REG_JNI(register_android_bluetooth_HeadsetBase),
1248 REG_JNI(register_android_bluetooth_BluetoothAudioGateway),
Nick Pelly0b6955a2009-05-26 19:13:43 -07001249 REG_JNI(register_android_bluetooth_BluetoothSocket),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001250 REG_JNI(register_android_bluetooth_ScoSocket),
Nick Pellybd022f42009-08-14 18:33:38 -07001251 REG_JNI(register_android_server_BluetoothService),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001252 REG_JNI(register_android_server_BluetoothEventLoop),
1253 REG_JNI(register_android_server_BluetoothA2dpService),
1254 REG_JNI(register_android_message_digest_sha1),
1255 REG_JNI(register_android_ddm_DdmHandleNativeHeap),
1256 REG_JNI(register_android_util_Base64),
1257 REG_JNI(register_android_location_GpsLocationProvider),
Joe Onorato1cf58742009-06-12 11:06:24 -07001258 REG_JNI(register_android_backup_BackupDataInput),
Joe Onoratod2110db2009-05-19 13:41:21 -07001259 REG_JNI(register_android_backup_BackupDataOutput),
Joe Onorato06290a42009-06-18 20:10:37 -07001260 REG_JNI(register_android_backup_FileBackupHelperBase),
Joe Onorato4ababd92009-06-25 18:29:18 -04001261 REG_JNI(register_android_backup_BackupHelperDispatcher),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001262};
1263
1264/*
1265 * Register android native functions with the VM.
1266 */
1267/*static*/ int AndroidRuntime::startReg(JNIEnv* env)
1268{
1269 /*
1270 * This hook causes all future threads created in this process to be
1271 * attached to the JavaVM. (This needs to go away in favor of JNI
1272 * Attach calls.)
1273 */
1274 androidSetCreateThreadFunc((android_create_thread_fn) javaCreateThreadEtc);
1275
1276 LOGD("--- registering native functions ---\n");
1277
1278 /*
1279 * Every "register" function calls one or more things that return
1280 * a local reference (e.g. FindClass). Because we haven't really
1281 * started the VM yet, they're all getting stored in the base frame
1282 * and never released. Use Push/Pop to manage the storage.
1283 */
1284 env->PushLocalFrame(200);
1285
1286 if (register_jni_procs(gRegJNI, NELEM(gRegJNI), env) < 0) {
1287 env->PopLocalFrame(NULL);
1288 return -1;
1289 }
1290 env->PopLocalFrame(NULL);
1291
1292 //createJavaThread("fubar", quickTest, (void*) "hello");
1293
1294 return 0;
1295}
1296
1297AndroidRuntime* AndroidRuntime::getRuntime()
1298{
1299 return gCurRuntime;
1300}
1301
1302/**
1303 * Used by WithFramework to register native functions.
1304 */
1305extern "C"
1306jint Java_com_android_internal_util_WithFramework_registerNatives(
1307 JNIEnv* env, jclass clazz) {
1308 return register_jni_procs(gRegJNI, NELEM(gRegJNI), env);
1309}
1310
1311/**
1312 * Used by LoadClass to register native functions.
1313 */
1314extern "C"
1315jint Java_LoadClass_registerNatives(JNIEnv* env, jclass clazz) {
1316 return register_jni_procs(gRegJNI, NELEM(gRegJNI), env);
1317}
1318
1319} // namespace android