Clear image caches in reaction to system VM warnings

* java/org/gnu/emacs/EmacsNative.java (onLowMemory):

* java/org/gnu/emacs/EmacsService.java (onLowMemory): New
function.

* src/android.c (android_on_low_memory, onLowMemory): New
functions called when a VM caution is registered.  Clear
the image cache and run garbage collection.
This commit is contained in:
Po Lu 2023-11-10 14:57:24 +08:00
parent 5dc3c9f4ec
commit 5324723c2b
3 changed files with 35 additions and 0 deletions

View file

@ -96,6 +96,9 @@ public static native void setEmacsParams (AssetManager assetManager,
thread, then return. */
public static native void shutDownEmacs ();
/* Garbage collect and clear each frame's image cache. */
public static native void onLowMemory ();
/* Abort and generate a native core dump. */
public static native void emacsAbort ();

View file

@ -321,6 +321,10 @@ invocation of app_process (through android-emacs) can
}
}
/* The native functions the subsequent two functions call do nothing
in the infrequent case the Emacs thread is awaiting a response
for the main thread. Caveat emptor! */
@Override
public void
onDestroy ()
@ -333,6 +337,14 @@ invocation of app_process (through android-emacs) can
super.onDestroy ();
}
@Override
public void
onLowMemory ()
{
EmacsNative.onLowMemory ();
super.onLowMemory ();
}
/* Functions from here on must only be called from the Emacs

View file

@ -1957,6 +1957,26 @@ NATIVE_NAME (shutDownEmacs) (JNIEnv *env, jobject object)
android_run_in_emacs_thread (android_shut_down_emacs, NULL);
}
/* Carry out garbage collection and clear all image caches on the
Android terminal. Called when the system has depleted most of its
memory and desires that background processes release unused
core. */
static void
android_on_low_memory (void *closure)
{
Fclear_image_cache (Qt, Qt);
garbage_collect ();
}
JNIEXPORT void JNICALL
NATIVE_NAME (onLowMemory) (JNIEnv *env, jobject object)
{
JNI_STACK_ALIGNMENT_PROLOGUE;
android_run_in_emacs_thread (android_on_low_memory, NULL);
}
JNIEXPORT jlong JNICALL
NATIVE_NAME (sendConfigureNotify) (JNIEnv *env, jobject object,
jshort window, jlong time,