Stabilisation fixes for JNA (and Tests) #1603
Stabilisation fixes for JNA (and Tests) #1603matthiasblaesing merged 8 commits intojava-native-access:masterfrom
Conversation
…gned certificates The tests assumption that certificates in the ROOT store are all self signed does not hold anymore.
Use system property java.home in favor of environment variable JAVA_HOME to register the windows service.
e8cade5 to
f69984f
Compare
|
@dbwiddis it would be great if you could have a look at this. I have two intentions here. The first is a general check of the changes here. The motivation for the first four changes was, that even locally I could no run the unittests reliably anymore. With the changes I can run the tests and get clean runs most of the time. The reason I got working was the fifth commit, which was motivated by unittests, that became unstable after recent changes (see above). The second intention is a request for help for the
I see your reasoning, but it seems, that windows does not listen to reason :-) |
dblock
left a comment
There was a problem hiding this comment.
I was curious about this one. What memory do we malloc where we then try to delete pointers in random locations of it? Meaning, do you have an actual example where a block is allocated with non-zero bytes, then other code calls free on a particular byte within that block?
Also left some minor questions/comments that you can disregard if you like.
|
|
||
| // Launch IE in a manner that should ensure it opens even if the system default browser is Chrome, Firefox, or something else. | ||
| Runtime.getRuntime().exec("cmd /c start iexplore.exe -nohome \"about:blank\""); | ||
| hr = Ole32.INSTANCE.CoInitializeEx(Pointer.NULL, Ole32.COINIT_MULTITHREADED); |
There was a problem hiding this comment.
Will tearDown() still run if this fails? Making sure you don't over- CoUninitialize().
There was a problem hiding this comment.
Will
tearDown()still run if this fails? Making sure you don't over-CoUninitialize().
"fails" would only include an hr of RPC_E_CHANGED_MODE. Both S_OK and S_FALSE require the uninitialize.
| OleAuto.INSTANCE.VariantClear(url); | ||
| OleAuto.INSTANCE.VariantClear(result); | ||
|
|
||
| ieDispatch.Release(); |
There was a problem hiding this comment.
This will not cleanup with a failure, move the release into tearDown()?
| Runtime.getRuntime().exec("cmd /c start iexplore.exe -nomerge -nohome \"http://www.google.com\""); | ||
| WinNT.HRESULT hr; | ||
|
|
||
| hr = Ole32.INSTANCE.CoInitializeEx(Pointer.NULL, Ole32.COINIT_MULTITHREADED); |
There was a problem hiding this comment.
Make a base class since this is repeated?
dbwiddis
left a comment
There was a problem hiding this comment.
LGTM generally.
The UDP stats test should be accurate per the docs. I guess a weak fallback would be to test that if either errors or no port is positive, then received is positive, e.g.,
Math.min(1, stats.dwNoPorts + stats.dwInErrors) <= stats.dwInDatagrams|
|
||
| // Launch IE in a manner that should ensure it opens even if the system default browser is Chrome, Firefox, or something else. | ||
| Runtime.getRuntime().exec("cmd /c start iexplore.exe -nohome \"about:blank\""); | ||
| hr = Ole32.INSTANCE.CoInitializeEx(Pointer.NULL, Ole32.COINIT_MULTITHREADED); |
There was a problem hiding this comment.
Will
tearDown()still run if this fails? Making sure you don't over-CoUninitialize().
"fails" would only include an hr of RPC_E_CHANGED_MODE. Both S_OK and S_FALSE require the uninitialize.
- Advapi32#DecryptFile can be called on read-only file - Secur32Test is unstable with ImpersonateSecurityContext, splitting it into separate test improves stability - Fix IPHlpAPITest#testGetUdpStatistics - the statistics that is returned can be inconsistent
malloc does not clear the memory it allocates and thus random data can be present. It was observed, that cleanup routines assume, that fields not holding NULL need to be freed for example. That is not true if the field was not cleared on allocation. One such example was callback->arg_classes in free_callback.
0f78dd5 to
1b86791
Compare
Have a look in Line 148 in 0a33062 the arguments are further processed and while doing so, the entries of the Line 165 in 0a33062 Line 174 in 0a33062 Line 183 in 0a33062 Line 192 in 0a33062 Then a jump to Lines 316 to 320 in 0a33062 And in Lines 329 to 337 in 0a33062
There might be other places and I modified the most obvious candidates.
Good idea - I'll add it - lets see if it helps. @dblock @dbwiddis in general I agree, that he COM invocation of the IE starting could be improved, but I stared at this to long already and the biggest part is yet to come (the native parts need to be rebuild again). I pushed an update. |
dblock
left a comment
There was a problem hiding this comment.
So is there any measurable performance difference between using malloc/calloc?
Code LGTM.
|
@matthiasblaesing Thank you for the detailed explanation. |
|
@matthiasblaesing feel free to merge |
|
@Panxuefeng-loongson you offered to rebuild the loongarch64 binaries if necessary. I would appreciate it, if you could rebuild the binaries based on this PR/my |
fb7fbe9 to
2e94624
Compare
|
@matthiasblaesing I have already sent it to you via email. If there are any issues, please provide feedback |
The binary is also available for download directly from loongson: https://maven.loongnix.cn/loongarch/maven/cn/loongson/jna/native/linux-loongarch64/7.0.2/linux-loongarch64-7.0.2.jar
02d5482 to
d84bfc4
Compare
|
Appveyor is happy with this build (tests that are runnable in CI ran clean after a single restart). github-actions agrees. @Panxuefeng-loongson kindly provided the binary for linux-loongarch64 (downloadable independently from https://maven.loongnix.cn/loongarch/maven/cn/loongson/jna/native/linux-loongarch64/) @dbwiddis and @dblock (via email) reviewed. Thank you all. |
The primary reason for this PR is e8cade5:
After 4bf9f92, which reduces the number of WeakReferences used when callbacks are created, higher error rates were observed in unittests. The errors were not normal problems (i.e. Exceptions), but hard JVM crashes. Investigation showed, that in callback code cleanup routines assumed, that fields not holding NULL need to be freed:
jna/native/callback.c
Lines 338 to 346 in e8cade5
That assumption is false as
mallocwas used for memory allocation, which does not zero the allocated memory. That behavior does not matter if the memory is allocated from the OS, which zeros pages before handing them to the application, but if memory is freed and later reused by the same application, zeroing needs to be done by the application.Instead of
mallocallocations are now done withcalloc, which zeros memory. It is assumed, that the benefit (higher runtime safety) if worth more than the, assumed small, performance hit by the zeroing step.To prevent other potential problems,
callocis also applied in other locations, that might not be fully initialized.The other commits address problems rendering unittests unstable:
JAVA_HOMEin windows service test