Skip to content

Commit

Permalink
8300139: [AIX] Use pthreads to avoid JNI_createVM call from primordia…
Browse files Browse the repository at this point in the history
…l thread

Reviewed-by: dholmes, stuefe
  • Loading branch information
varada1110 authored and tstuefe committed Feb 13, 2023
1 parent bbd8ae7 commit cb81073
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 41 deletions.
@@ -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
Expand All @@ -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
Expand Down
36 changes: 34 additions & 2 deletions test/hotspot/jtreg/runtime/jni/CalleeSavedRegisters/exeFPRegs.c
@@ -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
Expand All @@ -24,6 +24,9 @@
#include <jni.h>
#include <stdlib.h>

#ifdef AIX
#include <pthread.h>
#endif //AIX
#ifdef WINDOWS
#include <windows.h>
#else
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
}
Expand Up @@ -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
*/

Expand Down
Expand Up @@ -23,6 +23,9 @@

#include <stdio.h>
#include <stdlib.h>
#ifdef AIX
#include <pthread.h>
#endif //AIX

#include "jni.h"
#include "assert.h"
Expand All @@ -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;
Expand Down Expand Up @@ -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
}
1 change: 0 additions & 1 deletion test/jdk/jni/nullCaller/NullCallerTest.java
Expand Up @@ -32,7 +32,6 @@
* jdk.compiler
* @build NullCallerTest
* jdk.test.lib.compiler.CompilerUtils
* @requires os.family != "aix"
* @run main/native NullCallerTest
*/

Expand Down
24 changes: 23 additions & 1 deletion test/jdk/jni/nullCaller/exeNullCallerTest.cpp
Expand Up @@ -22,6 +22,9 @@
*/

#include "CallHelper.hpp"
#ifdef AIX
#include <pthread.h>
#endif //AIX

/*
* Test for JDK-8280902
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
}

65 changes: 36 additions & 29 deletions test/lib-test/jdk/test/lib/process/exejvm-test-launcher.c
@@ -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
Expand All @@ -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];
Expand All @@ -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;
}


void run(JNIEnv *env) {
jclass test_class;
jmethodID test_method;
jclass test_class;
jmethodID test_method;

test_class = (*env)->FindClass(env, "TestNativeProcessBuilder$Test");
if (test_class == NULL) {
exit(11);
}
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);
}
test_method = (*env)->GetStaticMethodID(env, test_class, "test", "()V");
if (test_method == NULL) {
exit(12);
}

(*env)->CallStaticVoidMethod(env, test_class, test_method);
(*env)->CallStaticVoidMethod(env, test_class, test_method);
return 0;
}


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
}

1 comment on commit cb81073

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.