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