--
You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/df823ce383afc9b45d859ec27a19036d16d867e3.camel%40manticore-projects.com.
Native crashes are very frequently a result of incorrect mappings.
This project fails on my M2 Macbook, although the crashing native function is different. Here’s the stack trace:
Stack: [0x00000003057e3000,0x00000003058e3000], sp=0x00000003058dcd80, free space=999k
Native frames: (J=compiled Java code, A=aot compiled Java code, j=interpreted, Vv=VM code, C=native code)
C [libfpng.dylib+0xdbb0] fpng_encode_image_to_memory+0x10
C [jna15943423394244317169.tmp+0xf17a] ffi_prep_go_closure+0x55a
Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j com.sun.jna.Native.invokePointer(Lcom/sun/jna/Function;JI[Ljava/lang/Object;)J+0
j com.sun.jna.Function.invokePointer(I[Ljava/lang/Object;)Lcom/sun/jna/Pointer;+7
j com.sun.jna.Function.invoke([Ljava/lang/Object;Ljava/lang/Class;ZI)Ljava/lang/Object;+440
j com.sun.jna.Function.invoke(Ljava/lang/reflect/Method;[Ljava/lang/Class;Ljava/lang/Class;[Ljava/lang/Object;Ljava/util/Map;)Ljava/lang/Object;+271
j com.sun.jna.Library$Handler.invoke(Ljava/lang/Object;Ljava/lang/reflect/Method;[Ljava/lang/Object;)Ljava/lang/Object;+390
j com.sun.proxy.$Proxy16.fpng_encode_image_to_memory([BIIII)Lcom/manticore/tools/Encoder$ByteArray;+46
j com.manticore.tools.FPNGEncoder.encode(Ljava/awt/image/BufferedImage;II)[B+28
The bottom line in that stack trace indicates a Java BufferedImage object is being passed to native, and since that’s not something the type mapper understands, unpredictable things are happening.
In the function in the test report I’d investigate the byte[] argument.
Try to instrument your crashing gradle test runner to output the top several lines of the generated log files.
--
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/948AD2F3-BE7A-6640-AEDE-A0B9D7650074%40hxcore.ol.
M2 Macbook
Yep, that’s arm64 which may explain why I’m getting different results than you (and why it doesn’t work, ever, for me.)
--
You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/6f57cc446e34dd2a53e868a7e98096632107e802.camel%40manticore-projects.com.
I’ll go try on an x86 mac shortly.
As for “what’s different” there could be different assumptions about the processor.
I looked into the native code for the function that’s crashing and see a compiler conditional based on a processor feature (can_use_sse41) …. Really hard to debug based on a single line.
uint32_t fpng_adler32(const void* pData, size_t size, uint32_t adler)
{
#if FPNG_X86_OR_X64_CPU && !FPNG_NO_SSE
if (g_cpu_info.can_use_sse41())
return adler32_sse_16((const uint8_t*)pData, size, adler);
#endif
return fpng_adler32_scalar((const uint8_t*)pData, size, adler);
}
From: jna-...@googlegroups.com <jna-...@googlegroups.com> on behalf of Support <sup...@manticore-projects.com>
Date: Wednesday, November 22, 2023 at 9:52
PM
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/92c46e118c4d899137c04829e9293767ff5a0527.camel%40manticore-projects.com.
> M2 is ARM64Sorry, this is presumptuous since Apple offers Rosetta 2.
I made an attempt to patch fpng-python for a baseline.https://github.com/tresf/fpng-python/tree/fixes (README.md too)I've only tested it on M1, but it causes a segmentation fault on MacOS, but not on Ubuntu (both ARM64).
--
You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/6f57cc446e34dd2a53e868a7e98096632107e802.camel%40manticore-projects.com.
--
You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/335fb5a6d6d35e6a4ad9325c3dcba523989738b1.camel%40manticore-projects.com.
I was getting those failures with ./gradlew test. The jmh one seems to run benchmarks normally with no crash.
--
You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/4ff4f5a78bf7130f240431af2904ff29594dc549.camel%40manticore-projects.com.
Benchmark (imageName) Mode Cnt Score Error Units
FPNGEBenchmark.encode example.png avgt 3 3.760 ± 0.282 ms/op
FPNGEBenchmark.encode looklet-look-scale6.png avgt 3 374.481 ± 174.265 ms/op
FPNGEncoderBenchmark.encode example.png avgt 3 8.693 ± 5.758 ms/op
FPNGEncoderBenchmark.encode looklet-look-scale6.png avgt 3 642.674 ± 319.904 ms/op
ImageIOEncoderBenchmark.encode example.png avgt 3 96.261 ± 4.445 ms/op
ImageIOEncoderBenchmark.encode looklet-look-scale6.png avgt 3 2265.919 ± 467.095 ms/op <-- outch!
ObjectPlanetPNGEncoderBenchmark.encode example.png avgt 3 76.676 ± 5.559 ms/op
ObjectPlanetPNGEncoderBenchmark.encode looklet-look-scale6.png avgt 3 1653.728 ± 135.696 ms/op
PNGEncoderBenchmark.encode example.png avgt 3 55.403 ± 13.296 ms/op
PNGEncoderBenchmark.encode looklet-look-scale6.png avgt 3 1129.696 ± 166.870 ms/op
PNGEncoderBenchmark.encodeFastest example.png avgt 3 52.664 ± 4.737 ms/op
PNGEncoderBenchmark.encodeFastest looklet-look-scale6.png avgt 3 980.785 ± 163.863 ms/op
--
You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/3469cbb005a269a9d781d35b6b57d2f2e570426f.camel%40manticore-projects.com.
Nope, even jmh crashes on my (ARM64) M2.
From: jna-...@googlegroups.com <jna-...@googlegroups.com> on behalf of Support <sup...@manticore-projects.com>
Date: Wednesday, November 22, 2023 at 10:52
PM
--
You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/3469cbb005a269a9d781d35b6b57d2f2e570426f.camel%40manticore-projects.com.
Nope, even jmh crashes on my (ARM64) M2.
Nope, doesn’t look like anything built. There are x86-64 images there that I presume were downloaded from the github fork.
No need to buy me beverages, just contribute to the open source community and pay it forward.
From: jna-...@googlegroups.com <jna-...@googlegroups.com> on behalf of Support <sup...@manticore-projects.com>
Date: Wednesday, November 22, 2023 at 11:02 PM
To: jna-...@googlegroups.com <jna-...@googlegroups.com>
Subject: Re: JNA segfaults on MacOS, often but not always
--
You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/15794fc97a25c13c7d2a34654084d29e23b9ffe1.camel%40manticore-projects.com.
No need to buy me beverages, just contribute to the open source community and pay it forward.
git clone --depth 1 https://github.com/manticore-projects/fpng-java.git
cd fpng-java
./gradlew :maven-test:test
1) There seems to be a MacOS specific JDK bug, when reading certain 3 channel PNG via InputStream into ImageIO. They claimed to have fixed that for JDK 11/12 but I still reproduced this reliably on GitHub MacOS Runner and on my Catalina VM.I mitigated it successfully by writing the Image InputStream into a File first, before loading this File into ImageIO. (Although this should not make any difference.)
I remember a similar bug I had about 8 years ago. Converting it to ARGB was my workaround. Is there a chance that writing it to PNG adds an alpha channel?
With regards to testing, I tried to execute :maven-test:test on M1, but all I get are errors.
With regards to logs, Gradle gives me a 50-line debug
> Task :maven-test:test |
FPNGTest > encodeFPNGTest(String, int) > [1] example, 3 FAILED |
java.lang.UnsatisfiedLinkError at FPNGETest.java:38 |
./gradlew :fpng-java:test :fpnge-java:test
./gradlew :fpng-java:test :fpnge-java:test
It briefly shows a bunch of messages about X86_64 but they disappear and there are more similar errors.
If you’re using this for developing Open Source software, consider applying for an account at the Gnu Compile Farm: https://gcc.gnu.org/wiki/CompileFarm
One of the machines you’ll have access to is cfarm104, an M1 Mac Mini (arm64).
From: jna-...@googlegroups.com <jna-...@googlegroups.com> on behalf of Support <sup...@manticore-projects.com>
Date: Tuesday, November 28, 2023 at 7:07 PM
To: jna-...@googlegroups.com <jna-...@googlegroups.com>
Subject: Re: JNA segfaults on MacOS, often but not always
--
You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/25fa044c94d3ba8bc820e59b63f674b404364107.camel%40manticore-projects.com.
If you’re using this for developing Open Source software, consider applying for an account at the Gnu Compile Farm: https://gcc.gnu.org/wiki/CompileFarm
One of the machines you’ll have access to is cfarm104, an M1 Mac Mini (arm64).
cfarm104
Graphs |
22 | Mac mini (2020) | arm64 | Apple M1 |
8 cores 8 threads CPU graph |
16.0 GB
Mem. graph |
0 bytes
Disk usage |
MacOSX 12.6 21.6.0 21.6.0 |
library {
linkage = [Linkage.STATIC, Linkage.SHARED]
targetMachines = [
machines.linux.x86_64,
machines.windows.x86, machines.windows.x86_64,
machines.macOS.x86_64, machines.macOS.architecture("aarch64")
]
}
#if defined(__SSE4_2__)
#include <nmmintrin.h>
#elif defined(__aarch64__)
#include <arm_neon.h>
#endif
// z[i] = x[i] + y[i]
void vadd(const int* x, const int* y, int* z, unsigned int count) {
// process 4 integers (128bits) with simd
unsigned int i = 0;
for (; i + 4 <= count; i += 4) {
#if defined(__SSE4_2__)
const __m128i vx = _mm_lddqu_si128((const __m128i*)(x + i));
const __m128i vy = _mm_lddqu_si128((const __m128i*)(y + i));
const __m128i vz = _mm_add_epi32(vx, vy);
_mm_storeu_si128((__m128i*)(z + i), vz);
#elif defined(__aarch64__)
const int32x4_t vx = vld1q_s32(x + i);
const int32x4_t vy = vld1q_s32(y + i);
const int32x4_t vz = vaddq_s32(vx, vy);
vst1q_s32(z + i, vz);
#endif
}
// tail loop
for (; i < count; ++i) {
z[i] = x[i] + y[i];
}
}
set(CMAKE_C_FLAGS "-march=native -mfpu=neon -mfloat-abi=hard ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "-march=native -mfpu=neon -mfloat-abi=hard ${CMAKE_CXX_FLAGS}")
for fpng, it does appear to be missing some optimizations for non-SSE processors. Since you're working from a copy of fpng (rather than a submodule) you don't appear to be using this, however if any compiler flags can be offered upstream, it'll help others.
localhost:~# cat /proc/cpuinfo
processor : 0
BogoMIPS : 125.00
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x1
CPU part : 0xd07
CPU revision : 0
qemu-system-aarch64 -m 2048 -smp 4 -M virt -nographic \
-cpu cortex-a57 \
-bios QEMU_EFI.fd \
-drive if=none,file=alpine-virt-3.18.4-aarch64.iso,id=hd0 -device virtio-blk-device,drive=hd0 \
-device virtio-net-device,netdev=net0 -netdev user,hostfwd=tcp:127.0.0.1:2222-:22,id=net0
-drive file=user-data.img,format=raw