Skip to content

Commit

Permalink
WOOOOOOOO say bye-bye lagspike!
Browse files Browse the repository at this point in the history
  • Loading branch information
The Judge committed Sep 29, 2024
1 parent 4200dd9 commit a4e56f8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/main/java/pojlib/util/JREUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,8 @@ public static int launchJavaVM(final Activity activity, final List<String> JVMAr
userArgs.add("-XX:+UseZGC");
userArgs.add("-XX:+ZGenerational");
userArgs.add("-XX:+UnlockExperimentalVMOptions");
userArgs.add("-XX:+AllowUserSignalHandlers");
userArgs.add("-XX:+UseSignalChaining");
userArgs.add("-XX:+UnlockDiagnosticVMOptions");
userArgs.add("-XX:-ImplicitNullChecks");
userArgs.add("-XX:+DisableExplicitGC");
userArgs.add("-XX:+UseCriticalJavaThreadPriority");

Expand Down
12 changes: 11 additions & 1 deletion src/main/jni/jre_launcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ static const jint const_ergo_class = 0; // DEFAULT_POLICY
static struct sigaction old_sa[NSIG];

void (*__old_sa)(int signal, siginfo_t *info, void *reserved);
int (*sigaction_p) (int signum,
const struct sigaction *_Nullable restrict act,
struct sigaction *_Nullable restrict oldact);
int (*JVM_handle_linux_signal)(int signo, siginfo_t* siginfo, void* ucontext, int abort_if_unrecognized);

void android_sigaction(int signal, siginfo_t *info, void *reserved) {
Expand Down Expand Up @@ -121,6 +124,13 @@ static jint launchJVM(int margc, char** margv) {
*/
JNIEXPORT jint JNICALL Java_com_oracle_dalvik_VMLauncher_launchJVM(JNIEnv *env, jclass clazz, jobjectArray argsArray) {
#ifdef TRY_SIG2JVM
void* libjsig = dlopen("libjsig.so", RTLD_LAZY | RTLD_GLOBAL);
if (NULL == libjsig) {
LOGE("JSig lib = NULL: %s", dlerror());
return -1;
}
sigaction_p = (void*) dlsym(libjsig, "sigaction");

void* libjvm = dlopen("libjvm.so", RTLD_LAZY | RTLD_GLOBAL);
if (NULL == libjvm) {
LOGE("JVM lib = NULL: %s", dlerror());
Expand All @@ -137,7 +147,7 @@ JNIEXPORT jint JNICALL Java_com_oracle_dalvik_VMLauncher_launchJVM(JNIEnv *env,
catcher.sa_sigaction = android_sigaction;
catcher.sa_flags = SA_SIGINFO|SA_RESTART;
// SA_RESETHAND;
#define CATCHSIG(X) sigaction(X, &catcher, &old_sa[X])
#define CATCHSIG(X) sigaction_p(X, &catcher, &old_sa[X])
CATCHSIG(SIGILL);
CATCHSIG(SIGABRT);
CATCHSIG(SIGBUS);
Expand Down

0 comments on commit a4e56f8

Please sign in to comment.