You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
vmavanur opened this issue
Aug 28, 2024
· 0 comments
Labels
bugIssues that are problems in the code as reported by the communitytestingIssues that enhance or fix our test suiteswindowsIssues that affect or relate to the WINDOWS OS
Our application at Actian uses JNI, which calls msvcp140.dll from the latest MSVC C++17 redistributable included with MSVC 2022. However, the installed or unzipped JRE17 comes with its own msvcp140.dll, which is an older version. This mismatch is causing an UnsatisfiedLinkError for our native DLL, leading to application crashes. When we renamed the msvcp140.dll in c:\program files\eclipse adoptium\jdk-17.0.11.9-hotspot\bin we don't see the exception
MSVC' s MSVCP140.dll version
C:\dev\test\12_4_dcng-26926>C:\Users\vmavanur\Downloads\SysinternalsSuite\sigcheck.exe C:\Windows\System32\msvcp140.dll
Sigcheck v2.90 - File version and signature viewer
Copyright (C) 2004-2022 Mark Russinovich
Sysinternals - www.sysinternals.com
c:\windows\system32\msvcp140.dll:
Verified: Signed
Signing date: 10:19 AM 4/27/2024
Publisher: Microsoft Windows Software Compatibility Publisher
Company: Microsoft Corporation
Description: Microsoft« C Runtime Library
Product: Microsoft« Visual Studio«
Prod version: 14.40.33810.0
File version: 14.40.33810.0
MachineType: 64-bit
JDK MSVCP140.dll version
C:\dev\test\12_4_dcng-26926>C:\Users\vmavanur\Downloads\SysinternalsSuite\sigcheck.exe "C:\Program Files\Eclipse Adoptium\jdk-17.0.11.9-hotspot\bin\msvcp140.dll"
Sigcheck v2.90 - File version and signature viewer
Copyright (C) 2004-2022 Mark Russinovich
Sysinternals - www.sysinternals.com
c:\program files\eclipse adoptium\jdk-17.0.11.9-hotspot\bin\msvcp140.dll:
Verified: Signed
Signing date: 12:12 AM 4/17/2024
Publisher: Eclipse.org Foundation, Inc.
Company: Microsoft Corporation
Description: Microsoft« C Runtime Library
Product: Microsoft« Visual Studio«
Prod version: 14.29.30139.0
File version: 14.29.30139.0 built by: vcwrkspc
MachineType: 64-bit
extern "C" JNIEXPORT jstring JNICALL Java_NativeExampleSingleton_sortAndConcat(JNIEnv* env, jobject obj, jintArray numbers) {
// Get the array length and elements
jsize length = env->GetArrayLength(numbers);
jint* elems = env->GetIntArrayElements(numbers, 0);
// Use std::vector and std::sort (features from msvcp140.dll)
std::vector<int> vec(elems, elems + length);
std::sort(vec.begin(), vec.end());
// Concatenate the sorted numbers into a string
std::string result = "Sorted numbers: ";
for (int num : vec) {
result += std::to_string(num) + " ";
}
// Release the JNI array
env->ReleaseIntArrayElements(numbers, elems, 0);
// Return the result as a new Java string
return env->NewStringUTF(result.c_str());
}
*/
#include <jni.h>
#include
#include // for std::sort
#include
#include
#include // for std::mutex
// Global mutex to synchronize access to the native method
std::mutex sortAndConcatMutex;
// Implementation of the native method
extern "C" JNIEXPORT jstring JNICALL Java_NativeExampleSingleton_sortAndConcat(JNIEnv* env, jobject obj, jintArray numbers) {
// Lock the mutex to ensure thread-safety
std::lock_guardstd::mutex guard(sortAndConcatMutex);
// Get the array length and elements
jsize length = env->GetArrayLength(numbers);
jint* elems = env->GetIntArrayElements(numbers, 0);
// Use std::vector and std::sort (features from msvcp140.dll)
std::vector<int> vec(elems, elems + length);
std::sort(vec.begin(), vec.end());
// Concatenate the sorted numbers into a string
std::string result = "Sorted numbers: ";
for (int num : vec) {
result += std::to_string(num) + " ";
}
// Release the JNI array
env->ReleaseIntArrayElements(numbers, elems, 0);
// Return the result as a new Java string
return env->NewStringUTF(result.c_str());
}
JAVA CODE
// NativeExampleSingleton.java
public class NativeExampleSingleton {
// Static variable to hold the single instance of the class
private static NativeExampleSingleton instance;
// Load the native library
static {
System.loadLibrary("NativeExampleSingleton"); // Load the DLL
}
// Private constructor to prevent instantiation
private NativeExampleSingleton() {}
// Static method to provide access to the instance
public static NativeExampleSingleton instance() {
if (instance == null) {
instance = new NativeExampleSingleton();
}
return instance;
}
// Declare the native method
public native String sortAndConcat(int[] numbers);
public static void main(String[] args) {
// Use the instance method to access the singleton
NativeExampleSingleton example = NativeExampleSingleton.instance();
int[] numbers = {5, 3, 8, 1, 9};
String result = example.sortAndConcat(numbers);
System.out.println(result); // Outputs the sorted and concatenated numbers
}
bugIssues that are problems in the code as reported by the communitytestingIssues that enhance or fix our test suiteswindowsIssues that affect or relate to the WINDOWS OS
Please provide a brief summary of the bug
Our application at Actian uses JNI, which calls msvcp140.dll from the latest MSVC C++17 redistributable included with MSVC 2022. However, the installed or unzipped JRE17 comes with its own msvcp140.dll, which is an older version. This mismatch is causing an UnsatisfiedLinkError for our native DLL, leading to application crashes. When we renamed the msvcp140.dll in c:\program files\eclipse adoptium\jdk-17.0.11.9-hotspot\bin we don't see the exception
MSVC' s MSVCP140.dll version
C:\dev\test\12_4_dcng-26926>C:\Users\vmavanur\Downloads\SysinternalsSuite\sigcheck.exe C:\Windows\System32\msvcp140.dll
Sigcheck v2.90 - File version and signature viewer
Copyright (C) 2004-2022 Mark Russinovich
Sysinternals - www.sysinternals.com
c:\windows\system32\msvcp140.dll:
Verified: Signed
Signing date: 10:19 AM 4/27/2024
Publisher: Microsoft Windows Software Compatibility Publisher
Company: Microsoft Corporation
Description: Microsoft« C Runtime Library
Product: Microsoft« Visual Studio«
Prod version: 14.40.33810.0
File version: 14.40.33810.0
MachineType: 64-bit
JDK MSVCP140.dll version
C:\dev\test\12_4_dcng-26926>C:\Users\vmavanur\Downloads\SysinternalsSuite\sigcheck.exe "C:\Program Files\Eclipse Adoptium\jdk-17.0.11.9-hotspot\bin\msvcp140.dll"
Sigcheck v2.90 - File version and signature viewer
Copyright (C) 2004-2022 Mark Russinovich
Sysinternals - www.sysinternals.com
c:\program files\eclipse adoptium\jdk-17.0.11.9-hotspot\bin\msvcp140.dll:
Verified: Signed
Signing date: 12:12 AM 4/17/2024
Publisher: Eclipse.org Foundation, Inc.
Company: Microsoft Corporation
Description: Microsoft« C Runtime Library
Product: Microsoft« Visual Studio«
Prod version: 14.29.30139.0
File version: 14.29.30139.0 built by: vcwrkspc
MachineType: 64-bit
Did you test with the latest update version?
Please provide steps to reproduce where possible
SAMPLE CODE TO TEST
CPP code :
// NativeExample1.cpp
/*
#include <jni.h>
#include
#include // for std::sort
#include
#include
extern "C" JNIEXPORT jstring JNICALL Java_NativeExampleSingleton_sortAndConcat(JNIEnv* env, jobject obj, jintArray numbers) {
// Get the array length and elements
jsize length = env->GetArrayLength(numbers);
jint* elems = env->GetIntArrayElements(numbers, 0);
}
*/
#include <jni.h>
#include
#include // for std::sort
#include
#include
#include // for std::mutex
// Global mutex to synchronize access to the native method
std::mutex sortAndConcatMutex;
// Implementation of the native method
extern "C" JNIEXPORT jstring JNICALL Java_NativeExampleSingleton_sortAndConcat(JNIEnv* env, jobject obj, jintArray numbers) {
// Lock the mutex to ensure thread-safety
std::lock_guardstd::mutex guard(sortAndConcatMutex);
}
JAVA CODE
// NativeExampleSingleton.java
public class NativeExampleSingleton {
}
hs_err_pid30392.log
Expected Results
NO crashes and the JNI call must not fail
Actual Results
"C:\dev\test\12_3_zlibstatic>java NativeExampleSingleton.java
A fatal error has been detected by the Java Runtime Environment:
EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ffca5243020, pid=940, tid=33456
JRE version: OpenJDK Runtime Environment Temurin-17.0.11+9 (17.0.11+9) (build 17.0.11+9)
Java VM: OpenJDK 64-Bit Server VM Temurin-17.0.11+9 (17.0.11+9, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, windows-amd64)
Problematic frame:
C [msvcp140.dll+0x13020]
No core dump will be written. Minidumps are not enabled by default on client versions of Windows
An error report file with more information is saved as:
C:\dev\test\12_3_zlibstatic\hs_err_pid940.log
If you would like to submit a bug report, please visit:
https://github.com/adoptium/adoptium-support/issues
The crash happened outside the Java Virtual Machine in native code.
See problematic frame for where to report the bug."
What Java Version are you using?
C:\dev\test\12_3_zlibstatic>java --version openjdk 17.0.11 2024-04-16 OpenJDK Runtime Environment Temurin-17.0.11+9 (build 17.0.11+9) OpenJDK 64-Bit Server VM Temurin-17.0.11+9 (build 17.0.11+9, mixed mode, sharing)
What is your operating system and platform?
WIndows 10 64 bit version
How did you install Java?
https://adoptium.net/temurin/archive/?version=17
This code has worked before with jdk11 and msvc17(c++14)
Did it work before?
Did you test with other Java versions?
Relevant log output
hs_err_pid30392.log
No response
The text was updated successfully, but these errors were encountered: