I'm trying to implement the method described here and here which override new and delete in a SWIG module in order to allocate memory on the Java heap instead of natively.
I added the SWIG prescription to my interface file. It compiles fine, and when I run my Java GUI, I can see from cout statements that it appears to be newing and deleteing without problems for a while (over 100k times). Eventually though, I always get this (same stack trace):
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007fff8754c0e0, pid=61178, tid=81411
#
# JRE version: Java(TM) SE Runtime Environment (8.0_60-b27) (build 1.8.0_60-b27)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.60-b23 mixed mode bsd-amd64 compressed oops)
# Problematic frame:
# C [libsystem_platform.dylib+0x50e0] _platform_memmove$VARIANT$Haswell+0x1c0
Using my cout statements, it looks like the sample code is using the same addresses inside delete as it used in new, so the code itself appears to be working. There are no known memory issues with my code (I've analyzed it using AddressSanitizer and Valgrind), and furthermore, if I comment out only the cached_jvm = jvm; line (which results in the code using malloc/free instead of on the JVM heap), then it works ok. I'm not running out of heap memory -- for my testing I'm using small sample data.
If I switch the ReleaseByteArrayElements line to use mode JNI_ABORT instead of 0, then the free does not fail in the same place, but other problems occur afterwards which I didn’t bother to figure out.
Why is it segfaulting? Are there certain kinds of memory operations that are not compatible with this approach? I'm not using malloc/free (directly). I'm linking to a 3rd party library in C++, and they might be up to something.
Here's a sample compile line:
/usr/bin/clang++ -DEngine_EXPORTS -m64 -W -Wall -Wconversion -Wshadow -Wno-error=shadow -fdiagnostics-show-option -Wno-sign-conversion -stdlib=libc++ -ftemplate-depth=1000 -O3 -fno-omit-frame-pointer -ffast-math -funroll-loops -dynamic -fPIC -fno-common -fvisibility=hidden -fvisibility-inlines-hidden -Werror -Wno-error -fno-strict-aliasing -g -fPIC -I/third/party/include -I/my/include -I/System/Library/Frameworks/JavaVM.framework/Headers -o CMakeFiles/Engine.dir/engineJAVA_wrap.cxx.o -c engineJAVA_wrap.cxx
Stack trace:
Thread 59 Crashed:: Java: Thread-22
0 libsystem_kernel.dylib 0x00007fff902fbf06 __pthread_kill + 10
1 libsystem_pthread.dylib 0x00007fff98e704ec pthread_kill + 90
2 libsystem_c.dylib 0x00007fff95c736df abort + 129
3 libjvm.dylib 0x000000010a282beb os::abort(bool) + 25
4 libjvm.dylib 0x000000010a3a6a2a VMError::report_and_die() + 2304
5 libjvm.dylib 0x000000010a3a6d9b crash_handler(int, __siginfo*, void*) + 106
6 libsystem_platform.dylib 0x00007fff8754952a _sigtramp + 26
7 ??? 000000000000000000 0 + 0
8 libjvm.dylib 0x000000010a27d0b1 os::print_location(outputStream*, long, bool) + 917
9 libjvm.dylib 0x000000010a283d89 os::print_register_info(outputStream*, void*) + 83
10 libjvm.dylib 0x000000010a3a588c VMError::report(outputStream*) + 2142
11 libjvm.dylib 0x000000010a3a6522 VMError::report_and_die() + 1016
12 libjvm.dylib 0x000000010a284816 JVM_handle_bsd_signal + 1131
13 libjvm.dylib 0x000000010a280a7b signalHandler(int, __siginfo*, void*) + 47
14 libsystem_platform.dylib 0x00007fff8754952a _sigtramp + 26
15 ??? 0x0000000000000001 0 + 1
16 libjvm.dylib 0x000000010a11d830 jni_ReleaseByteArrayElements + 124
17 libengineEngine.jnilib 0x000000012750e41b JNIEnv_::ReleaseByteArrayElements(_jbyteArray*, signed char*, int) + 75 (jni.h:1689)
18 libengineEngine.jnilib 0x000000012750e1f8 operator delete(void*) + 408 (engineJAVA_wrap.cxx:298)
19 libengineEngine.jnilib 0x000000012750f710 Java_engineJNI_delete_1VectorMol + 80 (engineJAVA_wrap.cxx:586)
20 ??? 0x000000010ad9e954 0 + 4477020500
21 ??? 0x000000010ad90c4d 0 + 4476963917
22 ??? 0x000000010ad90c4d 0 + 4476963917
23 ??? 0x000000010ad90c92 0 + 4476963986
24 ??? 0x000000010ad90c4d 0 + 4476963917
25 ??? 0x000000010ad90c4d 0 + 4476963917
26 ??? 0x000000010ad90c4d 0 + 4476963917
27 ??? 0x000000010ad90c4d 0 + 4476963917
28 ??? 0x000000010ad909d0 0 + 4476963280
29 ??? 0x000000010ad90c92 0 + 4476963986
30 ??? 0x000000010ad897a7 0 + 4476934055
31 libjvm.dylib 0x000000010a0eab0e JavaCalls::call_helper(JavaValue*, methodHandle*, JavaCallArguments*, Thread*) + 1710
32 libjvm.dylib 0x000000010a0eb29c JavaCalls::call_virtual(JavaValue*, KlassHandle, Symbol*, Symbol*, JavaCallArguments*, Thread*) + 356
33 libjvm.dylib 0x000000010a0eb448 JavaCalls::call_virtual(JavaValue*, Handle, KlassHandle, Symbol*, Symbol*, Thread*) + 74
34 libjvm.dylib 0x000000010a145965 thread_entry(JavaThread*, Thread*) + 124
35 libjvm.dylib 0x000000010a3612d3 JavaThread::thread_main_inner() + 155
36 libjvm.dylib 0x000000010a3629ce JavaThread::run() + 450
37 libjvm.dylib 0x000000010a28343a java_start(Thread*) + 246
38 libsystem_pthread.dylib 0x00007fff98e6d99d _pthread_body + 131
39 libsystem_pthread.dylib 0x00007fff98e6d91a _pthread_start + 168
40 libsystem_pthread.dylib 0x00007fff98e6b351 thread_start + 13
Edit:
I found that if I comment out all my .delete() calls (SWIG generated method) in my Java code, then I get a different error:
# SIGILL (0x4) at pc=0x00007fff95c7379f, pid=85146, tid=80651
#
# JRE version: Java(TM) SE Runtime Environment (8.0_60-b27) (build 1.8.0_60-b27)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.60-b23 mixed mode bsd-amd64 compressed oops)
# Problematic frame:
# C [libsystem_c.dylib+0x5e79f] __abort+0xb1
and SIGILL is a new one to me...
Related
So, I developed an app in Qt. It works just fine on my MacOs virtual machine. So I deployed it, I codesigned it. But I get an error, when I'm trying to launch on another Mac device. Funnny thing is if I launch it using sudo, like sudo App.app/Contents/MacOS/App it works. The error text is
Thread 2 Crashed:: Dispatch queue: com.apple.root.default-qos
0 libsystem_kernel.dylib 0x00007fff20364792 abort_with_payload + 10
1 libsystem_kernel.dylib 0x00007fff203661d9 abort_with_payload_wrapper_internal + 80
2 libsystem_kernel.dylib 0x00007fff2036620b abort_with_payload + 9
3 com.apple.TCC 0x00007fff24bd61b4 __TCC_CRASHING_DUE_TO_PRIVACY_VIOLATION + 163
4 com.apple.TCC 0x00007fff24bd69e6 __TCCAccessRequest_block_invoke.128 + 498
5 com.apple.TCC 0x00007fff24bd460a __tccd_send_message_block_invoke + 573
6 libxpc.dylib 0x00007fff200bcab8 _xpc_connection_reply_callout + 36
7 libxpc.dylib 0x00007fff200bca40 _xpc_connection_call_reply_async + 69
8 libdispatch.dylib 0x00007fff201cc831 _dispatch_client_callout3 + 8
9 libdispatch.dylib 0x00007fff201e5010 _dispatch_mach_msg_async_reply_invoke + 375
10 libdispatch.dylib 0x00007fff201dc564 _dispatch_kevent_worker_thread + 1390
11 libsystem_pthread.dylib 0x00007fff203744e1 _pthread_wqthread + 386
12 libsystem_pthread.dylib 0x00007fff20373467 start_wqthread + 15
And I have really hard time trying to understand what's the reason for such behaviour. I read some information about related problems, and it seem like it's missing some kind of permission. But I can't understand what excatly the permission should be. Can anyone explain what should I do?
I built my React Native app fully in Expo and built with expo build:ios, without ever ejecting.
My app was rejected for Beta Testing in Testflight, and there are crash logs in txt file format, and this is the thread that crashed:
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x000000022c4d10dc 0x22c4ae000 + 143580
1 libsystem_pthread.dylib 0x000000022c54a094 0x22c548000 + 8340
2 libsystem_c.dylib 0x000000022c42aea8 0x22c3d0000 + 372392
3 libc++abi.dylib 0x000000022baf7788 0x22baf6000 + 6024
4 libc++abi.dylib 0x000000022baf7934 0x22baf6000 + 6452
5 libobjc.A.dylib 0x000000022bb0ee00 0x22bb09000 + 24064
6 libc++abi.dylib 0x000000022bb03838 0x22baf6000 + 55352
7 libc++abi.dylib 0x000000022bb038c4 0x22baf6000 + 55492
8 libdispatch.dylib 0x000000022c3747e8 0x22c314000 + 395240
9 libdispatch.dylib 0x000000022c322004 0x22c314000 + 57348
10 CoreFoundation 0x000000022c8c5c1c 0x22c81c000 + 695324
11 CoreFoundation 0x000000022c8c0b54 0x22c81c000 + 674644
12 CoreFoundation 0x000000022c8c00b0 0x22c81c000 + 671920
13 GraphicsServices 0x000000022eac079c 0x22eab6000 + 42908
14 UIKitCore 0x0000000258e30978 0x258574000 + 9161080
15 ExpoKitApp 0x00000001007fb2d8 0x1007f4000 + 29400
16 libdyld.dylib 0x000000022c3858e0 0x22c384000 + 6368
I can't figure out how to symbolicate these because all I have is a txt file.
I'm also concerned that even a symbolicated log will be helpful, because it looks like there's a single step, simply labeled ExpoKitApp, that started the crash, and I can't imagine there being much useful information that might come out of that one line.
Does anyone have experience hunting down crash bugs in an unejected Expo app?
I'm using Qt 5.3 mingw on windows and writing application with Qt/QML.
sometimes, a crash happens at start-up when I run the project in Debug mode and trying to debug the code.
the inferior stopped because it received a signal from operating system
Is there any problem with QML or something else?
the stack is like this when error happens.
0 QScopedPointer<QObjectData, QScopedPointerDeleter<QObjectData> >::data 143 0x9d2250c
1 qGetPtrHelper<QScopedPointer<QObjectData> > 941 0x99e1cc7
2 QOpenGLContext::d_func 148 0x9d21f9b
3 QOpenGLContext::isValid 596 0x99e05d1
4 GLAcquireContext::GLAcquireContext 75 0x1af7ec21
5 QQuickContext2DTexture::paint 247 0x1aef2b79
6 QQuickContext2DTexture::event 366 0x1aef34a1
7 QApplicationPrivate::notify_helper 3500 0x217eded3
8 QApplication::notify 2953 0x217eb985
9 QCoreApplication::notifyInternal 935 0x6b929f96
10 QCoreApplication::sendEvent 237 0x6b9cf2db
11 QCoreApplicationPrivate::sendPostedEvents 1539 0x6b92b14e
12 QEventDispatcherWin32::sendPostedEvents 1143 0x6b97b006
13 qt_internal_proc(HWND__*, unsigned int, unsigned int, long)#16 421 0x6b978708
14 gapfnScSendMessage C:\Windows\syswow64\user32.dll 0x768362fa
15 ?? 0x2e07d2
16 USER32!GetThreadDesktop C:\Windows\syswow64\user32.dll 0x76836d3a
17 __lambda0::operator() 364 0x6b978443
18 ?? 0x2e07d2
19 USER32!CharPrevW C:\Windows\syswow64\user32.dll 0x768377c4
20 USER32!DispatchMessageW C:\Windows\syswow64\user32.dll 0x7683788a
21 QEventDispatcherWin32::processEvents 756 0x6b979a0b
22 QEventLoop::processEvents 136 0x6b92803c
23 QEventLoop::exec 212 0x6b9282d7
24 QThread::exec 511 0x6b795f49
25 QThread::run 578 0x6b7960b1
26 QThreadPrivate::start(void*)#4 407 0x6b798b3e
27 msvcrt!_itow_s C:\Windows\syswow64\msvcrt.dll 0x76231287
28 msvcrt!_endthreadex C:\Windows\syswow64\msvcrt.dll 0x76231328
29 KERNEL32!BaseThreadInitThunk C:\Windows\syswow64\kernel32.dll 0x76a233aa
30 ntdll!RtlInitializeExceptionChain C:\Windows\system32\ntdll.dll 0x77079ef2
31 ntdll!RtlInitializeExceptionChain C:\Windows\system32\ntdll.dll 0x77079ec5
32 ??
Any suggestion will be appreciated.
Thanks in advance.
I have a bunch of QWebViews rendered onto a widget. There comes a point at which I start getting the error QThread::start: Failed to create thread (The access code is invalid.). Looking at the Qt source, it appears that _beginthreadex is returning a null handle and errno is ERROR_INVALID_ACCESS, but I have no idea why.
Here is the backtrace at the printing of the error:
0 qErrnoWarning qglobal.cpp 2451 0x69ccdd3c
1 QThread::start qthread_win.cpp 469 0x69cd5831
2 QThreadPoolPrivate::tryStart qthreadpool.cpp 203 0x69ccc3f5
3 QThreadPool::start qthreadpool.cpp 474 0x69cccdf4
4 QHostInfoLookupManager::work qhostinfo.cpp 633 0x6cb9b071
5 QHostInfoLookupManager::scheduleLookup qhostinfo.cpp 652 0x6cb9b143
6 QHostInfo::lookupHost qhostinfo.cpp 202 0x6cb9a220
7 qt_qhostinfo_lookup qhostinfo.cpp 722 0x6cb9b4b6
8 QAbstractSocket::connectToHostImplementation qabstractsocket.cpp 1427 0x6cbb17f5
9 QAbstractSocket::qt_static_metacall moc_qabstractsocket.cpp 166 0x6cbb4925
10 QMetaMethod::invoke qmetaobject.cpp 1664 0x69dc784f
11 QMetaObject::invokeMethod qmetaobject.cpp 1179 0x69dc6d6b
12 QMetaObject::invokeMethod qobjectdefs.h 418 0x6cd361dd
13 QAbstractSocket::connectToHost qabstractsocket.cpp 1342 0x6cbb13b3
14 QSslSocket::connectToHostImplementation qsslsocket.cpp 1744 0x6cbc7340
15 QSslSocket::qt_static_metacall moc_qsslsocket.cpp 91 0x6cbc93cf
16 QMetaMethod::invoke qmetaobject.cpp 1664 0x69dc784f
17 QMetaObject::invokeMethod qmetaobject.cpp 1179 0x69dc6d6b
18 QMetaObject::invokeMethod qobjectdefs.h 418 0x6cd361dd
19 QAbstractSocket::connectToHost qabstractsocket.cpp 1342 0x6cbb13b3
20 QSslSocket::connectToHostEncrypted qsslsocket.cpp 422 0x6cbc55e1
21 QHttpNetworkConnectionChannel::ensureConnection qhttpnetworkconnectionchannel.cpp 607 0x6cb6191f
22 QHttpNetworkConnectionPrivate::_q_startNextRequest qhttpnetworkconnection.cpp 862 0x6cb5e92c
23 QHttpNetworkConnectionPrivate::queueRequest qhttpnetworkconnection.cpp 501 0x6cb5c57d
24 QHttpNetworkConnection::sendRequest qhttpnetworkconnection.cpp 931 0x6cb5edf2
25 QHttpThreadDelegate::startRequest qhttpthreaddelegate.cpp 291 0x6cb8912a
26 QHttpThreadDelegate::qt_static_metacall moc_qhttpthreaddelegate_p.cpp 113 0x6cbd147c
27 QMetaCallEvent::placeMetaCall qobject.cpp 525 0x69dcf91c
28 QObject::event qobject.cpp 1195 0x69dd08db
29 QApplicationPrivate::notify_helper qapplication.cpp 4551 0x2582f44
30 QApplication::notify qapplication.cpp 3933 0x25808b7
31 QCoreApplication::notifyInternal qcoreapplication.cpp 915 0x69dc0dc6
32 QCoreApplication::sendEvent qcoreapplication.h 231 0x69e35185
33 QCoreApplicationPrivate::sendPostedEvents qcoreapplication.cpp 1539 0x69dc1d2a
34 qt_internal_proc qeventdispatcher_win.cpp 496 0x69de2590
35 USER32!OffsetRect C:\Windows\syswow64\user32.dll 0 0x74cc62fa
36 ?? 0 0x152404
37 ?? 0 0x401
38 ?? 0
The code at the call looks like:
d->handle = (Qt::HANDLE) _beginthreadex(NULL, d->stackSize, QThreadPrivate::start, //d->stackSize is 0
this, CREATE_SUSPENDED, &(d->id));
if (!d->handle) {
qErrnoWarning(errno, "QThread::start: Failed to create thread");
d->running = false;
d->finished = true;
return;
}
Why is this happening and how do I fix it?
EDIT: also of note, there are exactly 500 threads at the point in which this breaks.
There's a good chance you've run out of free address space in your process (for thread stacks) after creating 500 threads. On 32-bit Windows, processes only get 2GB of address space by default (the upper half of the address space being reserved for the kernel). 500 1MB thread stacks (the default size, Qt may go higher or lower) plus all the other allocations your process makes could easily be using that up.
See this Old New Thing article for more.
Possible fixes:
If you know your QThreads don't need very big stacks, you can call QThread::setStackSize() to set a smaller size before starting the thread.
Consider using a thread pool and/or just reducing the number of concurrent threads you start. It's unlikely that you have enough CPU cores to make 500+ threads productive.
Use the Windows /3GB switch and make your application LARGE ADDRESS AWARE to get 3GB of user-mode address space.
Go 64-bit (for 63 bits of user-mode address space).
I am following a tutorial for a word processor for my QT module at uni.
It has asked me to put set this attribute:
MainWindow::setAttribute(Qt::WA_DeleteOnClose);
the problem comes when i run the application it causes an error saying that the application has closed unexpectedly.
Also it asked me to make a actionExit action and add to the file toolbar, which doesnt show, i am guessing that it is due to the fact that i am writing it on OSx and the exit/quit is taken care for you with the cmd+Q shortcut.
I was wondering if anyone could shed some light on this problem for me so that i know for future reference. if needed i can post the tutorial + source code.
Thanks
edit: backtrace from the debugger(hope this is correct)
0 __pthread_kill 0 0x7fff8eaff212
1 pthread_kill 0 0x7fff86f7eaf4
2 abort 0 0x7fff86fc2dce
3 free 0 0x7fff86f96959
4 MainWindow::~MainWindow mainwindow.cpp 22 0x100002cff
5 QObject::event 0 0x100e48906
6 QWidget::event 0 0x1000ecd5e
7 QMainWindow::event 0 0x10049cadb
8 QApplicationPrivate::notify_helper 0 0x10009593d
9 QApplication::notify 0 0x10009bdc4
10 QCoreApplication::notifyInternal 0 0x100e3417c
11 QCoreApplicationPrivate::sendPostedEvents 0 0x100e355a0
12 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ 0 0x7fff90925101
13 __CFRunLoopDoSources0 0 0x7fff90924a25
14 __CFRunLoopRun 0 0x7fff90947dc5
15 CFRunLoopRunSpecific 0 0x7fff909476b2
16 RunCurrentEventLoopInMode 0 0x7fff8d0f60a4
17 ReceiveNextEventCommon 0 0x7fff8d0f5d84
18 BlockUntilNextEventMatchingListInMode 0 0x7fff8d0f5cd3
19 _DPSNextEvent 0 0x7fff91a00613
20 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] 0 0x7fff919ffed2
... <More>
Is your MainWindow object declared on the stack, by any chance? If so, then DeleteOnClose is not a good idea, simply because deleting an object that is on the stack is an error.