3

Good morning,

We are executing the following code and we are reaching an error message when loading a certain number of dlls:

File file = new File("C:\\Users\\jevora\\Downloads\\dng_tests\\dllsCopies"); file.mkdirs(); for (int i = 1; i < 10000; i++) { String filename = "heatedTankCvode" + i + ".dll"; Files.copy(new File("C:\\Users\\jevora\\Downloads\\dng_tests\\heatedTankCvode.dll").toPath(), new File(file, filename).toPath(), StandardCopyOption.REPLACE_EXISTING); NativeLibrary.getInstance(new File(file, filename).getAbsolutePath()); System.out.println("Loaded: " + filename); } 

As you can see here, we want to load 10,000 dlls using JNA. However,in the following log, the process stops at loading the instance 1,051:

Loaded: heatedTankCvode1048.dll Loaded: heatedTankCvode1049.dll Loaded: heatedTankCvode1050.dll Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'C:\Users\jevora\Downloads\dng_tests\dllsCopies\heatedTankCvode1051.dll': Native library (win32-x86-64/C:\Users\jevora\Downloads\dng_tests\dllsCopies\heatedTankCvode1051.dll) 

About the code, first we copy the dll in a new location with a different name and, then, we try to load it. We wonder if there is a limitation to the amount of dlls that can be loaded. Is there a limitation? can we overcome it?

Thanks in advance

EDIT: I've tried with several memory configurations and it always stop in the 1051 instance

2
  • One thing that will limit you is ... memory. Commented Oct 28, 2021 at 10:00
  • Thanks for commenting. I've set it from 8GB to 20GB and still stopping the same number: 1051 Commented Oct 28, 2021 at 10:48

1 Answer 1

2

I think that the cause might be explained by this old Microsoft Forum post:

It appears that each DLL that you are loading is consuming a TLS (thread local storage) slot. There is a per process limit of 1088 on the number of TLS slots. From all that I have read, the limit is hard ... and there is no way to increase it.

From what I have read, a DLL doesn't have to use TLS, so you should investigate if you can change the way that your DLLs are created so that they don't do this.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you very much for this info! It seems to be exactly what is happening as the amount is pretty similar (probably the jvm itself is loading dlls so they are taking 30 approx). We are not developing the dlls but we can inform about this to the dll developer to see if this can be improved.
The other approach would be to redesign your application architecture so that it doesn't entail loading a ~10,000 DLLs. Maybe there is a good reason to do this, but is seems weird.
Yes...in fact it is weird. All of this comes from the use of the standard FMI. In the standard there are FMUs that, finally, are dynamic libraries. Each dll is a simulation unit that can be instantiated. In the standard it is recommended to allow multiple instantiation of the simulation units using the same dll; probably for the reason you exposed. So, in my opinion, the DLL should be fixed to allow thousands of instantiation of simulation units using only one DLL; instead of loading the DLL for each instantiation.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.