• 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 
23 #include <nativehelper/JniConstants.h>
24 #include "nativehelper/JniConstants-priv.h"
25 #include <nativehelper/ScopedLocalFrame.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     JniConstants::init(env);
35 
36     ScopedLocalFrame localFrame(env);
37 
38 #define REGISTER(FN) extern void FN(JNIEnv*); FN(env)
39     REGISTER(register_android_system_OsConstants);
40     //    REGISTER(register_java_lang_StringToReal);
41     REGISTER(register_java_lang_invoke_MethodHandle);
42     REGISTER(register_java_lang_invoke_VarHandle);
43     REGISTER(register_java_math_NativeBN);
44     REGISTER(register_java_util_regex_Matcher);
45     REGISTER(register_java_util_regex_Pattern);
46     REGISTER(register_libcore_icu_ICU);
47     REGISTER(register_libcore_icu_NativeConverter);
48     REGISTER(register_libcore_icu_TimeZoneNames);
49     REGISTER(register_libcore_io_AsynchronousCloseMonitor);
50     REGISTER(register_libcore_io_Linux);
51     REGISTER(register_libcore_io_Memory);
52     REGISTER(register_libcore_util_NativeAllocationRegistry);
53     REGISTER(register_org_apache_harmony_dalvik_NativeTestTarget);
54     REGISTER(register_org_apache_harmony_xml_ExpatParser);
55     REGISTER(register_sun_misc_Unsafe);
56 #undef REGISTER
57 
58     return JNI_VERSION_1_6;
59 }
60 
61 // DalvikVM calls this on shutdown, do any global cleanup here.
62 // -- Very important if we restart multiple DalvikVMs in the same process to reset the state.
JNI_OnUnload(JavaVM * vm,void *)63 void JNI_OnUnload(JavaVM* vm, void*) {
64     JNIEnv* env;
65     if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
66         ALOGE("JavaVM::GetEnv() failed");
67         abort();
68     }
69     ALOGV("libjavacore JNI_OnUnload");
70 
71     ScopedLocalFrame localFrame(env);
72 
73 #define UNREGISTER(FN) extern void FN(JNIEnv*); FN(env)
74     UNREGISTER(unregister_libcore_icu_ICU);
75 #undef UNREGISTER
76 
77     // Ensure that libnativehelper caching is invalidated, in case a new runtime is to be brought
78     // up later.
79     android::ClearJniConstantsCache();
80 }
81