Skip to content

Instantly share code, notes, and snippets.

@apangin
Created January 15, 2021 11:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apangin/97c1f977dfc08a1c4a59df1a841d56c9 to your computer and use it in GitHub Desktop.
Save apangin/97c1f977dfc08a1c4a59df1a841d56c9 to your computer and use it in GitHub Desktop.
Change non-manageable JVM option in runtime
#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