8300139: [AIX] Use pthreads to avoid JNI_createVM call from primordial thread

Reviewed-by: dholmes, stuefe
This commit is contained in:
Varada M 2023-02-13 11:12:36 +00:00 committed by Thomas Stuefe
parent bbd8ae7820
commit cb8107303e
7 changed files with 120 additions and 44 deletions

View File

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

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,6 +24,9 @@
#include <jni.h>
#include <stdlib.h>
#ifdef AIX
#include <pthread.h>
#endif //AIX
#ifdef WINDOWS
#include <windows.h>
#else
@ -104,7 +107,15 @@ long long unsigned int d2l(double d) {
#define print_reg(r) printf("%s = %f (0x%llX)\n", #r, r, d2l(r));
int main(int argc, const char** argv) {
typedef struct {
int argc;
char **argv;
} args_list;
static void* run(void* argp) {
args_list *arg = (args_list*) argp;
int argc = arg->argc;
char **argv = arg->argv;
JavaVM* jvm;
JNIEnv* env;
JavaVMInitArgs vm_args;
@ -239,3 +250,24 @@ int main(int argc, const char** argv) {
return 0;
}
int main(int argc, char *argv[]) {
args_list args;
args.argc = argc;
args.argv = argv;
#ifdef AIX
size_t adjusted_stack_size = 1024*1024;
pthread_t id;
int result;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr, adjusted_stack_size);
result = pthread_create(&id, &attr, run, (void *)&args);
if (result != 0) {
fprintf(stderr, "Error: pthread_create failed with error code %d \n", result);
return -1;
}
pthread_join(id, NULL);
#else
run(&args);
#endif //AIX
}

View File

@ -25,10 +25,7 @@
/**
* @test
* @bug 8221530 8221642
* @summary Test uses custom launcher that starts VM using JNI that verifies
* reflection API with null caller class
* @library /test/lib
* @requires os.family != "aix"
* @run main/native CallerAccessTest
*/

View File

@ -23,6 +23,9 @@
#include <stdio.h>
#include <stdlib.h>
#ifdef AIX
#include <pthread.h>
#endif //AIX
#include "jni.h"
#include "assert.h"
@ -42,7 +45,7 @@ int setAccessible(JNIEnv *env, char* declaringClass_name, char* field_name);
int trySetAccessible(JNIEnv *env, char* declaringClass_name, char* field_name, jboolean canAccess);
int checkAccess(JNIEnv *env, char* declaringClass_name, char* field_name, jboolean canAccess);
int main(int argc, char** args) {
static void* run(void* argp) {
JavaVM *jvm;
JNIEnv *env;
JavaVMInitArgs vm_args;
@ -236,3 +239,22 @@ int checkAccess(JNIEnv *env, char* declaringClass_name, char* field_name, jboole
}
return 0;
}
int main(int argc, char *argv[]) {
#ifdef AIX
size_t adjusted_stack_size = 1024*1024;
pthread_t id;
int result;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr, adjusted_stack_size);
result = pthread_create(&id, &attr, run, (void *)&argv);
if (result != 0) {
fprintf(stderr, "Error: pthread_create failed with error code %d \n", result);
return -1;
}
pthread_join(id, NULL);
#else
run(&argv);
#endif //AIX
}

View File

@ -32,7 +32,6 @@
* jdk.compiler
* @build NullCallerTest
* jdk.test.lib.compiler.CompilerUtils
* @requires os.family != "aix"
* @run main/native NullCallerTest
*/

View File

@ -22,6 +22,9 @@
*/
#include "CallHelper.hpp"
#ifdef AIX
#include <pthread.h>
#endif //AIX
/*
* Test for JDK-8280902
@ -156,7 +159,7 @@ void getResourceAsStream(JNIEnv *env) {
class_ClosedResources, env->NewStringUTF("test.txt"));
}
int main(int argc, char** args) {
static void* run(void *arg) {
JavaVM *jvm;
JNIEnv *env;
JavaVMInitArgs vm_args;
@ -184,3 +187,22 @@ int main(int argc, char** args) {
return 0;
}
int main(int argc, char *argv[]) {
#ifdef AIX
size_t adjusted_stack_size = 1024*1024;
pthread_t id;
int result;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr, adjusted_stack_size);
result = pthread_create(&id, &attr, run, (void *)argv);
if (result != 0) {
fprintf(stderr, "Error: pthread_create failed with error code %d \n", result);
return -1;
}
pthread_join(id, NULL);
#else
run(&argv);
#endif //AIX
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,9 +24,12 @@
#include <jni.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef AIX
#include <pthread.h>
#endif //AIX
JNIEnv* create_vm(JavaVM **jvm)
{
static void* run(void *arg) {
JavaVM *jvm;
JNIEnv* env;
JavaVMInitArgs args;
JavaVMOption options[1];
@ -41,39 +44,43 @@ JNIEnv* create_vm(JavaVM **jvm)
args.options = &options[0];
args.ignoreUnrecognized = 0;
int ret = JNI_CreateJavaVM(jvm, (void**)&env, &args);
int ret = JNI_CreateJavaVM(&jvm, (void**)&env, &args);
if (ret < 0) {
exit(10);
}
return env;
jclass test_class;
jmethodID test_method;
test_class = (*env)->FindClass(env, "TestNativeProcessBuilder$Test");
if (test_class == NULL) {
exit(11);
}
test_method = (*env)->GetStaticMethodID(env, test_class, "test", "()V");
if (test_method == NULL) {
exit(12);
}
(*env)->CallStaticVoidMethod(env, test_class, test_method);
return 0;
}
void run(JNIEnv *env) {
jclass test_class;
jmethodID test_method;
test_class = (*env)->FindClass(env, "TestNativeProcessBuilder$Test");
if (test_class == NULL) {
exit(11);
}
test_method = (*env)->GetStaticMethodID(env, test_class, "test", "()V");
if (test_method == NULL) {
exit(12);
}
(*env)->CallStaticVoidMethod(env, test_class, test_method);
}
int main(int argc, char **argv)
{
JavaVM *jvm;
JNIEnv *env = create_vm(&jvm);
run(env);
return 0;
int main(int argc, char *argv[]) {
#ifdef AIX
size_t adjusted_stack_size = 1024*1024;
pthread_t id;
int result;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr, adjusted_stack_size);
result = pthread_create(&id, &attr, run, (void *)argv);
if (result != 0) {
fprintf(stderr, "Error: pthread_create failed with error code %d \n", result);
return -1;
}
pthread_join(id, NULL);
#else
run(&argv);
#endif //AIX
}