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