// Declare the thread local variable(s) in the main executable. This can be // used to demonstrate the issues associated with the on-stack static TLS blocks // that may cause insufficient stack space. The dynamic TLS blocks for shared // objects (such as a JNI library) loaded via dlopen are not allocated on stack.
__thread int tls[128 * 1024];
#ifdef __GLIBC__ // glibc 2.15 introduced __pthread_get_minstack int glibc_has_pthread_get_minstack() { constchar* glibc_vers = gnu_get_libc_version(); constint glibc_vers_major = atoi(glibc_vers); constint glibc_vers_minor = atoi(strchr(glibc_vers, '.') + 1);;
printf("GNU libc version: %s\n", glibc_vers); if ((glibc_vers_major > 2) || ((glibc_vers_major == 2) && (glibc_vers_minor >= 15))) { return1;
}
printf("This version does not provide __pthread_get_minstack\n"); return0;
} #else int glibc_has_pthread_get_minstack() { return0;
} #endif
int run(jboolean addTLS) {
JavaVM *jvm;
jclass testClass;
jmethodID runMethod; char* argTLS; int res = -1;
if (addTLS) { if (!glibc_has_pthread_get_minstack()) {
printf("Skipping the test.\n"); return0;
}
argTLS = "-XX:+AdjustStackSizeForTLS";
} else {
argTLS = "-XX:-AdjustStackSizeForTLS"; // default
}
printf("Running test with %s ...\n", argTLS);
JNIEnv *env = create_vm(&jvm, argTLS);
// Run T.run() and check result: // - Expect T.run() to return 'true' when stack size is adjusted for TLS, // return 0 if so // - Expect T.run() to return 'false' if stack size is not adjusted for // TLS, return 0 if so // Return -1 (fail) for other cases
testClass = (*env)->FindClass(env, "T");
runMethod = (*env)->GetStaticMethodID(env, testClass, "run", "()Z"); if ((*env)->CallStaticBooleanMethod(env, testClass, runMethod, NULL)) { if (addTLS) { // expect T.run() to return 'true'
res = 0;
}
} else { if (!addTLS) { // expect T.run() to return 'false'
res = 0;
}
}
if (res == 0) {
printf("Test passed with %s\n", argTLS);
} else {
printf("Test failed with %s\n", argTLS);
} return res;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.