From 527489c06d827f5d08a8053bedcd26db4608c9f0 Mon Sep 17 00:00:00 2001 From: Jiangli Zhou Date: Mon, 10 Feb 2025 20:19:48 +0000 Subject: [PATCH] 8349284: Make libExplicitAttach work on static JDK Reviewed-by: alanb, dholmes --- make/test/JtregNativeJdk.gmk | 1 - .../AttachCurrentThread/libExplicitAttach.c | 18 ++++++++---------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/make/test/JtregNativeJdk.gmk b/make/test/JtregNativeJdk.gmk index 39bf03f46fc..8384698654d 100644 --- a/make/test/JtregNativeJdk.gmk +++ b/make/test/JtregNativeJdk.gmk @@ -84,7 +84,6 @@ else BUILD_JDK_JTREG_LIBRARIES_LDFLAGS_libLinkerInvokerModule := -pthread BUILD_JDK_JTREG_LIBRARIES_LDFLAGS_libLoaderLookupInvoker := -pthread - BUILD_JDK_JTREG_LIBRARIES_JDK_LIBS_libExplicitAttach := java.base:libjvm BUILD_JDK_JTREG_LIBRARIES_LDFLAGS_libExplicitAttach := -pthread BUILD_JDK_JTREG_LIBRARIES_LDFLAGS_libImplicitAttach := -pthread BUILD_JDK_JTREG_EXCLUDE += exerevokeall.c diff --git a/test/jdk/java/lang/Thread/jni/AttachCurrentThread/libExplicitAttach.c b/test/jdk/java/lang/Thread/jni/AttachCurrentThread/libExplicitAttach.c index 6855e8ca1ee..170f15f21d9 100644 --- a/test/jdk/java/lang/Thread/jni/AttachCurrentThread/libExplicitAttach.c +++ b/test/jdk/java/lang/Thread/jni/AttachCurrentThread/libExplicitAttach.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2025, 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 @@ -26,22 +26,20 @@ #define STACK_SIZE 0x100000 +static JavaVM *vm; + +JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void* reserved) { + vm = jvm; + return JNI_VERSION_1_8; +} + /** * Attach the current thread with JNI AttachCurrentThread, call a method, and detach. */ void* thread_main(void* arg) { - JavaVM *vm; JNIEnv *env; - JavaVMInitArgs vm_args; - jsize count; jint res; - res = JNI_GetCreatedJavaVMs(&vm, 1, &count); - if (res != JNI_OK) { - fprintf(stderr, "JNI_GetCreatedJavaVMs failed: %d\n", res); - return NULL; - } - res = (*vm)->AttachCurrentThread(vm, (void **) &env, NULL); if (res != JNI_OK) { fprintf(stderr, "AttachCurrentThreadAsDaemon failed: %d\n", res);