Initialize some global variables in Bitmap.cpp when needed
Bug: 331243037 Flag: EXEMPT bugfix This allows Bitmap class to have a static NativeAllocationRegistry, which can be used to register native allocations of different sizes without creating multiple registries. To make this possible, the static native method nativeGetNativeFinalizer needs to be available during static initialization time in Bitmap class. However, there is a deadlock as shown below which needs to be removed e.g. class Bitmap { private static long sFinalizer = nativeGetNativeFinalizer(); private static native long nativeGetNativeFinalizer(); } The static initialization of sFinalizer depends on the native JNI call nativeGetNativeFinalizer() to be available/registered. However, during JNI registration time in Bitmap.cpp, the calls of GetMethodID() requires the static initialization to be done, this causes deadlock, and hence the code above wouldn't work. To remove this deadlock and thus allow static native methods to be called during static initialization, we moved the initialization of these global variables in Bitmap.cpp, which depends on GetMethodID(), to be done later when they are needed first time. Change-Id: I87bebdbe128a2dad48b162d31ed275ad7908bcd7
Loading
Please register or sign in to comment