Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

msvcp140.dll shipped with jre17 is incompatible with msvc 2022 msvcp140.dll #3927

Open
1 task done
vmavanur opened this issue Aug 28, 2024 · 0 comments
Open
1 task done
Labels
bug Issues that are problems in the code as reported by the community testing Issues that enhance or fix our test suites windows Issues that affect or relate to the WINDOWS OS

Comments

@vmavanur
Copy link

vmavanur commented Aug 28, 2024

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?

  • Yes

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);

// 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
}

}
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?

This code has worked before with jdk11 and msvc17(c++14)

Did you test with other Java versions?

Same issue with jdk21 and msvc2022

Relevant log output

hs_err_pid30392.log
No response

@vmavanur vmavanur added the bug Issues that are problems in the code as reported by the community label Aug 28, 2024
@karianna karianna transferred this issue from adoptium/adoptium-support Aug 29, 2024
@github-actions github-actions bot added testing Issues that enhance or fix our test suites windows Issues that affect or relate to the WINDOWS OS labels Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues that are problems in the code as reported by the community testing Issues that enhance or fix our test suites windows Issues that affect or relate to the WINDOWS OS
Projects
Status: Todo
Development

No branches or pull requests

1 participant