Created
January 15, 2021 11:23
-
-
Save apangin/97c1f977dfc08a1c4a59df1a841d56c9 to your computer and use it in GitHub Desktop.
Change non-manageable JVM option in runtime
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <jvmti.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
JNIEXPORT jint JNICALL | |
Agent_OnAttach(JavaVM* vm, char* options, void* reserved) { | |
if (options != NULL) { | |
int* addr = (int*)strtol(options, NULL, 0); | |
printf("vmoption [%p] = %d\n", addr, *addr); fflush(stdout); | |
const char* eq = strchr(options, '='); | |
if (eq != NULL) { | |
int val = atoi(eq + 1); | |
*addr = val; | |
printf("vmoption [%p] := %d\n", addr, val); fflush(stdout); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment