Skip to content

Commit cb81073

Browse files
varada1110tstuefe
authored andcommitted
8300139: [AIX] Use pthreads to avoid JNI_createVM call from primordial thread
Reviewed-by: dholmes, stuefe
1 parent bbd8ae7 commit cb81073

File tree

7 files changed

+117
-41
lines changed

7 files changed

+117
-41
lines changed

test/hotspot/jtreg/runtime/jni/CalleeSavedRegisters/FPRegs.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,9 +25,6 @@
2525
/*
2626
* @test
2727
* @bug 8067744
28-
* @comment Test uses custom launcher that starts VM in primordial thread. This is
29-
* not possible on aix.
30-
* @requires os.family != "aix"
3128
* @requires vm.flagless
3229
* @library /test/lib
3330
* @modules java.base/jdk.internal.misc

test/hotspot/jtreg/runtime/jni/CalleeSavedRegisters/exeFPRegs.c

+34-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -24,6 +24,9 @@
2424
#include <jni.h>
2525
#include <stdlib.h>
2626

27+
#ifdef AIX
28+
#include <pthread.h>
29+
#endif //AIX
2730
#ifdef WINDOWS
2831
#include <windows.h>
2932
#else
@@ -104,7 +107,15 @@ long long unsigned int d2l(double d) {
104107

105108
#define print_reg(r) printf("%s = %f (0x%llX)\n", #r, r, d2l(r));
106109

107-
int main(int argc, const char** argv) {
110+
typedef struct {
111+
int argc;
112+
char **argv;
113+
} args_list;
114+
115+
static void* run(void* argp) {
116+
args_list *arg = (args_list*) argp;
117+
int argc = arg->argc;
118+
char **argv = arg->argv;
108119
JavaVM* jvm;
109120
JNIEnv* env;
110121
JavaVMInitArgs vm_args;
@@ -239,3 +250,24 @@ int main(int argc, const char** argv) {
239250
return 0;
240251
}
241252

253+
int main(int argc, char *argv[]) {
254+
args_list args;
255+
args.argc = argc;
256+
args.argv = argv;
257+
#ifdef AIX
258+
size_t adjusted_stack_size = 1024*1024;
259+
pthread_t id;
260+
int result;
261+
pthread_attr_t attr;
262+
pthread_attr_init(&attr);
263+
pthread_attr_setstacksize(&attr, adjusted_stack_size);
264+
result = pthread_create(&id, &attr, run, (void *)&args);
265+
if (result != 0) {
266+
fprintf(stderr, "Error: pthread_create failed with error code %d \n", result);
267+
return -1;
268+
}
269+
pthread_join(id, NULL);
270+
#else
271+
run(&args);
272+
#endif //AIX
273+
}

test/jdk/java/lang/reflect/exeCallerAccessTest/CallerAccessTest.java

-3
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@
2525
/**
2626
* @test
2727
* @bug 8221530 8221642
28-
* @summary Test uses custom launcher that starts VM using JNI that verifies
29-
* reflection API with null caller class
3028
* @library /test/lib
31-
* @requires os.family != "aix"
3229
* @run main/native CallerAccessTest
3330
*/
3431

test/jdk/java/lang/reflect/exeCallerAccessTest/exeCallerAccessTest.c

+23-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323

2424
#include <stdio.h>
2525
#include <stdlib.h>
26+
#ifdef AIX
27+
#include <pthread.h>
28+
#endif //AIX
2629

2730
#include "jni.h"
2831
#include "assert.h"
@@ -42,7 +45,7 @@ int setAccessible(JNIEnv *env, char* declaringClass_name, char* field_name);
4245
int trySetAccessible(JNIEnv *env, char* declaringClass_name, char* field_name, jboolean canAccess);
4346
int checkAccess(JNIEnv *env, char* declaringClass_name, char* field_name, jboolean canAccess);
4447

45-
int main(int argc, char** args) {
48+
static void* run(void* argp) {
4649
JavaVM *jvm;
4750
JNIEnv *env;
4851
JavaVMInitArgs vm_args;
@@ -236,3 +239,22 @@ int checkAccess(JNIEnv *env, char* declaringClass_name, char* field_name, jboole
236239
}
237240
return 0;
238241
}
242+
243+
int main(int argc, char *argv[]) {
244+
#ifdef AIX
245+
size_t adjusted_stack_size = 1024*1024;
246+
pthread_t id;
247+
int result;
248+
pthread_attr_t attr;
249+
pthread_attr_init(&attr);
250+
pthread_attr_setstacksize(&attr, adjusted_stack_size);
251+
result = pthread_create(&id, &attr, run, (void *)&argv);
252+
if (result != 0) {
253+
fprintf(stderr, "Error: pthread_create failed with error code %d \n", result);
254+
return -1;
255+
}
256+
pthread_join(id, NULL);
257+
#else
258+
run(&argv);
259+
#endif //AIX
260+
}

test/jdk/jni/nullCaller/NullCallerTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
* jdk.compiler
3333
* @build NullCallerTest
3434
* jdk.test.lib.compiler.CompilerUtils
35-
* @requires os.family != "aix"
3635
* @run main/native NullCallerTest
3736
*/
3837

test/jdk/jni/nullCaller/exeNullCallerTest.cpp

+23-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
*/
2323

2424
#include "CallHelper.hpp"
25+
#ifdef AIX
26+
#include <pthread.h>
27+
#endif //AIX
2528

2629
/*
2730
* Test for JDK-8280902
@@ -156,7 +159,7 @@ void getResourceAsStream(JNIEnv *env) {
156159
class_ClosedResources, env->NewStringUTF("test.txt"));
157160
}
158161

159-
int main(int argc, char** args) {
162+
static void* run(void *arg) {
160163
JavaVM *jvm;
161164
JNIEnv *env;
162165
JavaVMInitArgs vm_args;
@@ -184,3 +187,22 @@ int main(int argc, char** args) {
184187
return 0;
185188
}
186189

190+
int main(int argc, char *argv[]) {
191+
#ifdef AIX
192+
size_t adjusted_stack_size = 1024*1024;
193+
pthread_t id;
194+
int result;
195+
pthread_attr_t attr;
196+
pthread_attr_init(&attr);
197+
pthread_attr_setstacksize(&attr, adjusted_stack_size);
198+
result = pthread_create(&id, &attr, run, (void *)argv);
199+
if (result != 0) {
200+
fprintf(stderr, "Error: pthread_create failed with error code %d \n", result);
201+
return -1;
202+
}
203+
pthread_join(id, NULL);
204+
#else
205+
run(&argv);
206+
#endif //AIX
207+
}
208+
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -24,9 +24,12 @@
2424
#include <jni.h>
2525
#include <stdio.h>
2626
#include <stdlib.h>
27+
#ifdef AIX
28+
#include <pthread.h>
29+
#endif //AIX
2730

28-
JNIEnv* create_vm(JavaVM **jvm)
29-
{
31+
static void* run(void *arg) {
32+
JavaVM *jvm;
3033
JNIEnv* env;
3134
JavaVMInitArgs args;
3235
JavaVMOption options[1];
@@ -41,39 +44,43 @@ JNIEnv* create_vm(JavaVM **jvm)
4144
args.options = &options[0];
4245
args.ignoreUnrecognized = 0;
4346

44-
int ret = JNI_CreateJavaVM(jvm, (void**)&env, &args);
47+
int ret = JNI_CreateJavaVM(&jvm, (void**)&env, &args);
4548
if (ret < 0) {
4649
exit(10);
4750
}
4851

49-
return env;
50-
}
51-
52-
53-
void run(JNIEnv *env) {
54-
jclass test_class;
55-
jmethodID test_method;
52+
jclass test_class;
53+
jmethodID test_method;
5654

57-
test_class = (*env)->FindClass(env, "TestNativeProcessBuilder$Test");
58-
if (test_class == NULL) {
59-
exit(11);
60-
}
55+
test_class = (*env)->FindClass(env, "TestNativeProcessBuilder$Test");
56+
if (test_class == NULL) {
57+
exit(11);
58+
}
6159

62-
test_method = (*env)->GetStaticMethodID(env, test_class, "test", "()V");
63-
if (test_method == NULL) {
64-
exit(12);
65-
}
60+
test_method = (*env)->GetStaticMethodID(env, test_class, "test", "()V");
61+
if (test_method == NULL) {
62+
exit(12);
63+
}
6664

67-
(*env)->CallStaticVoidMethod(env, test_class, test_method);
65+
(*env)->CallStaticVoidMethod(env, test_class, test_method);
66+
return 0;
6867
}
6968

70-
71-
int main(int argc, char **argv)
72-
{
73-
JavaVM *jvm;
74-
JNIEnv *env = create_vm(&jvm);
75-
76-
run(env);
77-
78-
return 0;
69+
int main(int argc, char *argv[]) {
70+
#ifdef AIX
71+
size_t adjusted_stack_size = 1024*1024;
72+
pthread_t id;
73+
int result;
74+
pthread_attr_t attr;
75+
pthread_attr_init(&attr);
76+
pthread_attr_setstacksize(&attr, adjusted_stack_size);
77+
result = pthread_create(&id, &attr, run, (void *)argv);
78+
if (result != 0) {
79+
fprintf(stderr, "Error: pthread_create failed with error code %d \n", result);
80+
return -1;
81+
}
82+
pthread_join(id, NULL);
83+
#else
84+
run(&argv);
85+
#endif //AIX
7986
}

0 commit comments

Comments
 (0)