• 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/JNIHelp.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_java_math_NativeBN);
43     REGISTER(register_java_util_regex_Matcher);
44     REGISTER(register_java_util_regex_Pattern);
45     REGISTER(register_libcore_icu_ICU);
46     REGISTER(register_libcore_icu_NativeConverter);
47     REGISTER(register_libcore_icu_TimeZoneNames);
48     REGISTER(register_libcore_io_AsynchronousCloseMonitor);
49     REGISTER(register_libcore_io_Linux);
50     REGISTER(register_libcore_io_Memory);
51     REGISTER(register_libcore_util_NativeAllocationRegistry);
52     REGISTER(register_org_apache_harmony_dalvik_NativeTestTarget);
53     REGISTER(register_org_apache_harmony_xml_ExpatParser);
54     REGISTER(register_sun_misc_Unsafe);
55 #undef REGISTER
56 
57     JniConstants::Initialize(env);
58     return JNI_VERSION_1_6;
59 }
60 
61 // ART calls this on shutdown, do any global cleanup here.
62 // -- Very important if we restart multiple ART runtimes in the same process to reset the state.
JNI_OnUnload(JavaVM *,void *)63 void JNI_OnUnload(JavaVM*, void*) {
64     // Don't use the JavaVM in this method. ART only calls this once all threads are
65     // unregistered.
66     ALOGV("libjavacore JNI_OnUnload");
67 #define UNREGISTER(FN) extern void FN(); FN()
68     UNREGISTER(unregister_libcore_icu_ICU);
69 #undef UNREGISTER
70     JniConstants::Invalidate();
71     jniUninitializeConstants();
72 }
73