• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #define LOG_TAG "libcore" // We'll be next to "dalvikvm" in the log; make the distinction clear.
18 
19 #include <stdlib.h>
20 
21 #include <log/log.h>
22 #include <nativehelper/JNIPlatformHelp.h>
23 #include <nativehelper/ScopedLocalFrame.h>
24 
25 #include "JniConstants.h"
26 
27 // DalvikVM calls this on startup, so we can statically register all our native methods.
JNI_OnLoad(JavaVM * vm,void *)28 jint JNI_OnLoad(JavaVM* vm, void*) {
29     JNIEnv* env;
30     if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
31         ALOGE("JavaVM::GetEnv() failed");
32         abort();
33     }
34 
35     ScopedLocalFrame localFrame(env);
36 
37 #define REGISTER(FN) extern void FN(JNIEnv*); FN(env)
38     REGISTER(register_android_system_OsConstants);
39     //    REGISTER(register_java_lang_StringToReal);
40     REGISTER(register_java_lang_invoke_MethodHandle);
41     REGISTER(register_java_lang_invoke_VarHandle);
42     REGISTER(register_libcore_icu_ICU);
43     REGISTER(register_libcore_io_AsynchronousCloseMonitor);
44     REGISTER(register_libcore_io_Linux);
45     REGISTER(register_libcore_io_Memory);
46     REGISTER(register_libcore_math_NativeBN);
47     REGISTER(register_libcore_util_NativeAllocationRegistry);
48     REGISTER(register_org_apache_harmony_xml_ExpatParser);
49     REGISTER(register_sun_misc_Unsafe);
50 #undef REGISTER
51 
52     JniConstants::Initialize(env);
53     return JNI_VERSION_1_6;
54 }
55 
56 // ART calls this on shutdown, do any global cleanup here.
57 // -- Very important if we restart multiple ART runtimes in the same process to reset the state.
JNI_OnUnload(JavaVM *,void *)58 void JNI_OnUnload(JavaVM*, void*) {
59     // Don't use the JavaVM in this method. ART only calls this once all threads are
60     // unregistered.
61     ALOGV("libjavacore JNI_OnUnload");
62 #define UNREGISTER(FN) extern void FN(); FN()
63     UNREGISTER(unregister_libcore_icu_ICU);
64 #undef UNREGISTER
65     JniConstants::Invalidate();
66     jniUninitializeConstants();
67 }
68