RFR: 8359827: Test runtime/Thread/ThreadCountLimit.java should run exclusively [v2]
SendaoYan
syan at openjdk.org
Mon Jul 21 13:34:40 UTC 2025
On Mon, 21 Jul 2025 11:59:00 GMT, David Holmes <dholmes at openjdk.org> wrote:
> Okay, but in that scenario what is it you are actually running out of?
I think it's running out of "user processes" which limit by `ulimit -u 4096`.
I think it is the user processes set by `ulimit -u` are exhausted that Java cannot start.
I created a small example in C language to illustrate this problem. The create-thread program will try to create threads continuously until it can no longer create threads, or the number of threads created exceeds 5000.
1. Use bash -c "ulimit -u 1000 && ./create-thread" command to test that the number of threads that the create-thread program can create is about 580;
<img width="731" height="94" alt="image" src="https://github.com/user-attachments/assets/c236bc47-f27f-4a54-82b5-643952de255e" />
2. First directly start the create-thread program (background running mode), and then use bash -c "ulimit -u 4096 && ./create-thread" command to test the number of threads that the second create-thread process can create. It will be found that the second create-thread process cannot create any new thread. Explain that the number of max user processes limited by `ulimit -u 4096` includes the number of threads created by the first create-thread process.
This C language example shows that this testcase is not suitable for concurrent running with other test cases, otherwise you may encounter the failure described in the issue
<img width="708" height="218" alt="image" src="https://github.com/user-attachments/assets/6a02d745-3582-4bf6-b9ff-a7161ac6dda5" />
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
void *thread_func() {
while (1) {
sleep(1);
}
return NULL;
}
int main() {
pthread_t tid;
int thread_count = 0;
int ret;
while (thread_count < 5000) {
ret = pthread_create(&tid, NULL, thread_func, NULL);
if (ret != 0) {
if (ret == EAGAIN) {
printf("can not create thread(EAGAIN) anymore: %d\n", thread_count);
break;
} else {
printf("pthread_create error: %s\n", strerror(ret));
break;
}
}
thread_count++;
if (thread_count % 1000 == 0) {
printf("already create thread number %d\n", thread_count);
}
}
printf("total created thread number: %d\n", thread_count);
while (1) {
sleep(1);
}
return 0;
}
> You are changing the test to suit the way you need to run it, but I'm not aware of anyone else reporting issues running this test.
I think the failure descripted by issue, only appearance on huge CPU core number machine.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/26401#issuecomment-3096804639
More information about the hotspot-runtime-dev
mailing list