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

Closed
1 task done
vmavanur opened this issue Aug 28, 2024 · 12 comments
Closed
1 task done
Labels
bug Issues that are problems in the code as reported by the community duplicate Issues that are a duplicate of an issue in this (or another) repository 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
@sxa
Copy link
Member

sxa commented Sep 30, 2024

@vmavanur Can you check if this is a duplicate of the issue raised at #3887 please? It sounds similar.

@vmavanur
Copy link
Author

vmavanur commented Sep 30, 2024 via email

@Dani-Hub
Copy link

Not being @vmavanur : But I also think that #3887 is effectively the same issue.

@vmavanur
Copy link
Author

vmavanur commented Sep 30, 2024

I did go through the entire comments in #3887, and it is the same issue.

@karianna karianna closed this as completed Oct 1, 2024
@karianna karianna added the duplicate Issues that are a duplicate of an issue in this (or another) repository label Oct 1, 2024
@andrew-m-leonard
Copy link
Contributor

@vmavanur @Dani-Hub Hi, we have a fix to this problem, upgrading to the latest vs2022 Redist DLLs, would you be able to verify these test build artifacts work as intended in your scenarios please? All being well, next weeks releases will contain this fix.
https://ci.adoptium.net/job/build-scripts/job/jobs/job/jdk17u/job/jdk17u-windows-x64-temurin/536/artifact/workspace/target/

@Dani-Hub
Copy link

Dani-Hub commented Oct 9, 2024

I will try to validate the fix. It might need a day or two, though

@andrew-m-leonard
Copy link
Contributor

I will try to validate the fix. It might need a day or two, though

thank you @Dani-Hub

@Dani-Hub
Copy link

@andrew-m-leonard : Our team could successfully confirm that the above referenced JRE and JDK fixes the here reported problem on our end.

@andrew-m-leonard
Copy link
Contributor

@andrew-m-leonard : Our team could successfully confirm that the above referenced JRE and JDK fixes the here reported problem on our end.

Thank you @Dani-Hub that's fantastic, I much appreciate your time in confirming it works.

I can confirm this fix is in the builds for this week's releases.

Cheers
Andrew

@Dani-Hub
Copy link

Thank you @Dani-Hub that's fantastic, I much appreciate your time in confirming it works.

I can confirm this fix is in the builds for this week's releases.

That's great to hear! Will we also get fixes for the Java-11 JREs soon?

@andrew-m-leonard
Copy link
Contributor

Thank you @Dani-Hub that's fantastic, I much appreciate your time in confirming it works.
I can confirm this fix is in the builds for this week's releases.

That's great to hear! Will we also get fixes for the Java-11 JREs soon?

Yes, all versions are being upgraded, this week's releases for jdk8,11,17,21,23 will all have the updated MS Redist DLLs

@vmavanur
Copy link
Author

vmavanur commented Oct 22, 2024 via email

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 duplicate Issues that are a duplicate of an issue in this (or another) repository testing Issues that enhance or fix our test suites windows Issues that affect or relate to the WINDOWS OS
Projects
Status: Done
Development

No branches or pull requests

5 participants