Segmentation Violation using Matlab Javabuilder App in Java Program - java

I created a GUI in QTJambi which runs the Matlab code when a button is pressed. Everything runs fine and output is received from the Matlab code, but when I close the window of the GUI, I get a segmentation violation, shown below:
------------------------------------------------------------------------
Segmentation violation detected at Sun Apr 26 19:21:03 2015
------------------------------------------------------------------------
Configuration:
Crash Decoding : Disabled
Current Visual : 0x23 (class 4, depth 24)
Default Encoding : UTF-8
GNU C Library : 2.19 stable
MATLAB Architecture: glnxa64
MATLAB Root : /usr/local/MATLAB/MATLAB_Compiler_Runtime/v83
MATLAB Version : 8.3.0.532 (R2014a)
Operating System : Linux 3.13.0-49-generic #83-Ubuntu SMP Fri Apr 10 20:11:33 UTC 2015 x86_64
Processor ID : x86 Family 31 Model 4 Stepping 3, AuthenticAMD
Virtual Machine : Java 1.7.0_79-b14 with Oracle Corporation OpenJDK 64-Bit Server VM mixed mode
Window System : The X.Org Foundation (11501000), display :0.0
Fault Count: 1
Abnormal termination:
Segmentation violation
Register State (from fault):
RAX = 00007fa7adc2f410 RBX = 0000000000000000
RCX = 00007fa7a8365ae0 RDX = 0000000000000000
RSP = 00007fa7ae80f300 RBP = 00007fa7a83458d0
RSI = 0000000000000000 RDI = 00620069006c68a0
R8 = 00007fa7a833f500 R9 = 00007fa7a8364330
R10 = 00007fa7ae80f130 R11 = 0000000000000000
R12 = 0000000000000080 R13 = 0000000000000008
R14 = 00007fa79bffbfb8 R15 = 0000000000000001
RIP = 00007fa7adc2f414 EFL = 0000000000010206
CS = 0033 FS = 0000 GS = 0000
Stack Trace (from fault):
[ 0] 0x00007fa7adc2f414 /lib/x86_64-linux-gnu/libpthread.so.0+00042004 pthread_mutex_lock+00000004
[ 1] 0x00007fa799a9e2c7 /usr/lib/x86_64-linux-gnu/libX11.so.6+00279239 XrmDestroyDatabase+00000039
[ 2] 0x00007fa799a867b3 /usr/lib/x86_64-linux-gnu/libX11.so.6+00182195 _XFreeDisplayStructure+00001123
[ 3] 0x00007fa799a744ef /usr/lib/x86_64-linux-gnu/libX11.so.6+00107759 XCloseDisplay+00000223
[ 4] 0x00007fa79b580d6e /usr/lib/x86_64-linux-gnu/libQtGui.so.4.8.6+02309486
[ 5] 0x00007fa79b517d66 /usr/lib/x86_64-linux-gnu/libQtGui.so.4.8.6+01879398 _ZN12QApplicationD1Ev+00001158
[ 6] 0x00007fa7938bdb57 /usr/lib/jni/libcom_trolltech_qt_gui.so+05557079 _ZN25QtJambiShell_QApplicationD0Ev+00000023
[ 7] 0x00007fa7a0eaac58 /usr/lib/x86_64-linux-gnu/libQtCore.so.4.8.6+01662040 _ZN7QObject5eventEP6QEvent+00000648
[ 8] 0x00007fa79b51bed3 /usr/lib/x86_64-linux-gnu/libQtGui.so.4.8.6+01896147 _ZN12QApplication5eventEP6QEvent+00000067
[ 9] 0x00007fa79b516e2c /usr/lib/x86_64-linux-gnu/libQtGui.so.4.8.6+01875500 _ZN19QApplicationPrivate13notify_helperEP7QObjectP6QEvent+00000140
[ 10] 0x00007fa79b51d4a0 /usr/lib/x86_64-linux-gnu/libQtGui.so.4.8.6+01901728 _ZN12QApplication6notifyEP7QObjectP6QEvent+00000624
[ 11] 0x00007fa7a0e924dd /usr/lib/x86_64-linux-gnu/libQtCore.so.4.8.6+01561821 _ZN16QCoreApplication14notifyInternalEP7QObjectP6QEvent+00000109
[ 12] 0x00007fa7a0e95b3d /usr/lib/x86_64-linux-gnu/libQtCore.so.4.8.6+01575741 _ZN23QCoreApplicationPrivate16sendPostedEventsEP7QObjectiP11QThreadData+00000493
[ 13] 0x00007fa7a0e96bb0 /usr/lib/x86_64-linux-gnu/libQtCore.so.4.8.6+01579952 _ZN16QCoreApplication4execEv+00000192
[ 14] 0x00007fa7a418d7f8 <unknown-module>+00000000
[ 15] 0x00007fa7a41811d4 <unknown-module>+00000000
[ 16] 0x00007fa7a417b4e7 <unknown-module>+00000000
[ 17] 0x00007fa7ad1f1099 /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server/libjvm.so+06193305
[ 18] 0x00007fa7ad1f0b38 /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server/libjvm.so+06191928
[ 19] 0x00007fa7ad1ffc6b /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server/libjvm.so+06253675
[ 20] 0x00007fa7ad210ed8 /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server/libjvm.so+06323928
[ 21] 0x00007fa7ae40f1f9 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/../lib/amd64/jli/libjli.so+00012793
[ 22] 0x00007fa7adc2d182 /lib/x86_64-linux-gnu/libpthread.so.0+00033154
[ 23] 0x00007fa7ae14147d /lib/x86_64-linux-gnu/libc.so.6+01025149 clone+00000109
If this problem is reproducible, please submit a Service Request via:
http://www.mathworks.com/support/contact_us/
A technical support engineer might contact you with further information.
Thank you for your help.

http://uk.mathworks.com/matlabcentral/answers/100053-why-does-jboss-7-1-throw-a-segmentation-violation-when-trying-to-call-a-matlab-builder-ja-2-2-4-r20
I added MWApplication.initialize(MWMCROption.NOJVM); to the main function of my program, before the QTJambi initialisation procedure.

Related

Why high CPU during ArrayBlockingQueue.poll()

Once, I've profiled Java application by Async-profiler (CPU utilization). Adnrei Pangin(apangin) thanks for the Async-profiler!
This is stack(hot methods) was at the top:
Started [itimer] profiling
--- Execution profile ---
Total samples : 6443
unknown_Java : 17 (0.26%)
not_walkable_Java : 2 (0.03%)
thread_exit : 1 (0.02%)
Frame buffer usage : 42.4103%
--- 1710000000 ns (2.65%), 171 samples
[ 0] __pthread_cond_timedwait
[ 1] Unsafe_Park
[ 2] jdk.internal.misc.Unsafe.park
[ 3] java.util.concurrent.locks.LockSupport.parkNanos
[ 4] java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos
[ 5] java.util.concurrent.ArrayBlockingQueue.poll
[ 6] xx.Service.run
[ 7] java.lang.Thread.run
This is Java code which was at the top of CPU-report:
xx.Service.class:
public void run() {
try {
while (execute) {
Event event = queue.poll(100, TimeUnit.MILLISECONDS);
if (event == null) {
continue;
}
do_something();
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
"Queue" is ArrayBlockingQueue because it using from different Java threads.
To my mind function __pthread_cond_timedwait shouldn't consume CPU at all because thread was parking without spin loop.
But it does this.
Is it normal situation or my code with queue.poll() is incorrect?

H2O anomaly per_feature = TRUE java.lang.OutOfMemoryError: Java heap space

I run H2O anomaly with per_feature = TRUE which results in a Java Heap Space error. In some other posts about this error message, I see people suggest using h2o.remove(df) to release the used memory. However, in my case I don’t have any loop, and it seems that there is nothing I can remove to release some used memory.
Here is my code:
library(h2o)
h2o.init(min_mem_size = "10G", max_mem_size = "15G")
data.hex <- as.h2o(data)
x <- names(data.hex)
random_seed <- 42
# Deeplearning Model
print("Deep learning model begins ...")
model.dl = h2o.deeplearning(x = x,
training_frame = data.hex,
autoencoder = TRUE,
activation = "Tanh",
hidden = c(5, 5, 5, 5, 5),
mini_batch_size = 64,
epochs = 100,
stopping_rounds = 15,
variable_importances = TRUE,
seed = random_seed)
# Calculating anomaly per feature
print('Calculating anomaly per feature ...')
errors_per_feature <- h2o.anomaly(model.dl, data.hex, per_feature = TRUE) # Anomaly Detection Algorithm
print('Converting from H2O frame to dataframe ...')
errors1_per_feature <- as.data.frame(errors_per_feature) # Convert back to data frame
Here is the detailed error message:
[1] "Deep learning model begins ..."
|======================================================================| 100%
[1] "Calculating anomaly per feature ..."
ERROR: Unexpected HTTP Status code: 500 Server Error (url = http://localhost:54321/3/Predictions/models/DeepLearning_model_R_1594826474037_2/frames/Accesses_sid_a71f_1)
water.util.DistributedException
[1] "DistributedException from localhost/127.0.0.1:54321: 'Java heap space', caused by java.lang.OutOfMemoryError: Java heap space"
[2] " water.MRTask.getResult(MRTask.java:494)"
[3] " water.MRTask.getResult(MRTask.java:502)"
[4] " water.MRTask.doAll(MRTask.java:397)"
[5] " water.MRTask.doAll(MRTask.java:403)"
[6] " hex.deeplearning.DeepLearningModel.scoreAutoEncoder(DeepLearningModel.java:761)"
[7] " water.api.ModelMetricsHandler.predict(ModelMetricsHandler.java:469)"
[8] " java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)"
[9] " java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)"
[10] " java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)"
[11] " java.base/java.lang.reflect.Method.invoke(Method.java:567)"
[12] " water.api.Handler.handle(Handler.java:60)"
[13] " water.api.RequestServer.serve(RequestServer.java:470)"
[14] " water.api.RequestServer.doGeneric(RequestServer.java:301)"
[15] " water.api.RequestServer.doPost(RequestServer.java:227)"
[16] " javax.servlet.http.HttpServlet.service(HttpServlet.java:755)"
[17] " javax.servlet.http.HttpServlet.service(HttpServlet.java:848)"
[18] " org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:684)"
[19] " org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:501)"
[20] " org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086)"
[21] " org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:427)"
[22] " org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1020)"
[23] " org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)"
[24] " org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:154)"
[25] " org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)"
[26] " water.webserver.jetty8.Jetty8ServerAdapter$LoginHandler.handle(Jetty8ServerAdapter.java:119)"
[27] " org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:154)"
[28] " org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)"
[29] " org.eclipse.jetty.server.Server.handle(Server.java:370)"
[30] " org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:494)"
[31] " org.eclipse.jetty.server.BlockingHttpConnection.handleRequest(BlockingHttpConnection.java:53)"
[32] " org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:984)"
[33] " org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:1045)"
[34] " org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:861)"
[35] " org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:236)"
[36] " org.eclipse.jetty.server.BlockingHttpConnection.handle(BlockingHttpConnection.java:72)"
[37] " org.eclipse.jetty.server.bio.SocketConnector$ConnectorEndPoint.run(SocketConnector.java:264)"
[38] " org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)"
[39] " org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)"
[40] " java.base/java.lang.Thread.run(Thread.java:830)"
[41] "Caused by:java.lang.OutOfMemoryError: Java heap space"
Error in .h2o.doSafeREST(h2oRestApiVersion = h2oRestApiVersion, urlSuffix = page, :
ERROR MESSAGE:
DistributedException from localhost/127.0.0.1:54321: 'Java heap space'
Calls: h2o.anomaly -> .h2o.__remoteSend -> .h2o.doSafeREST
Execution halted
R and H2O version:
H2O cluster version: 3.30.0.6
H2O cluster total nodes: 1
H2O cluster total memory: 13.43 GB
H2O cluster total cores: 16
H2O cluster allowed cores: 16
H2O cluster healthy: TRUE
R Version: R version 3.6.3 (2020-02-29)
I have 16 GB of memory on my macOS.
There are 6 variables (columns) in data: 5 categorical variables and 1 numeric variable. The number of unique values in the 5 categorical variables is 17, 49, 52, 85 and 5032, respectively. The number of rows is ~500k. The data file size is 44 MB (before encoding within H2O).
What can I do in my case to resolve the issue? Please let me know if there is any other information I can provide. Thanks for your help!
[cutting and pasting my response to the h2ostream mailing list here too...]
i suspect the large number of categorical levels is causing the memory to blow up.
try removing that variable and seeing if it at least completes.
if it does, try re-binning into a smaller number of levels somehow.

Can't connect to IPv6-only host from java

I have some IPv6-only hosts. I can successfully execute curl request to it
by curl
$ curl -I my.ip.v6.only.host
HTTP/1.1 200 OK
But when I trying to get it from java I have an error:
HttpGet httpget = new HttpGet("http://my.ip.v6.only.host");
CloseableHttpResponse response = httpclient.execute(httpget);
Stack trace:
INFO: I/O exception (java.net.NoRouteToHostException) caught when processing request to {}->http://my.ip.v6.only.host: No route to host
Mar 17, 2015 7:42:23 PM org.apache.http.impl.execchain.RetryExec execute
INFO: Retrying request to {}->http://my.ip.v6.only.host
java.net.NoRouteToHostException: No route to host
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:72)
at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:123)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:318)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:363)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:219)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:195)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:86)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106)
at MainTest.main(MainTest.java:25)
Problem has been occured on java v1.7.0_65 and v1.8.0_40, MacOS 10.10.2. On previous version MacOS 10.9.5 it works well.
What's going on? How it is possible that host is reachable by curl and unreachable from java.
Also, I've tried to play around -Djava.net.preferIPv6Addresses=true and -Djava.net.preferIPv4Stack=false and it couldn't help.
UPD found a related bug in OpenJDK, JDK-8015415
UPD 2 when I tried to use wired connection instead of wifi, it helped me. Weird.
It can be problem in AirDrop + Java cooperation.
Short answer - try:
$ sudo ifconfig awdl0 down
Investigation of the problem below (thanks for Sergey Shinderuk):
We have such code in java to reproduce:
import java.net.Socket;
public class Test {
public static void main(String[] args) throws Exception {
new Socket("2a02:6b8::3", 80); // ya.ru
}
}
And when we use WiFi, get exception: java.net.NoRouteToHostException: No route to host
While with telnet all ok:
$ telnet 2a02:6b8::3 80
Trying 2a02:6b8::3...
Connected to www.yandex.ru.
Escape character is '^]'.
^C
When we turn off wifi, and use wired connection - all ok. But if we used wired connection, but wifi is turned on - this java code won't work. Which is very strange.
We need to compare arguments for the connect(2) between java and telnet.
$ sudo dtrace -qn 'syscall::connect:entry { print(*(struct sockaddr_in6 *)copyin(arg1, arg2)) }' -c './telnet 2a02:6b8::3 80'
struct sockaddr_in6 {
__uint8_t sin6_len = 0x1c
sa_family_t sin6_family = 0x1e
in_port_t sin6_port = 0x5000
__uint32_t sin6_flowinfo = 0
struct in6_addr sin6_addr = {
union __u6_addr = {
__uint8_t [16] __u6_addr8 = [ 0x2a, 0x2, 0x6, 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x3 ]
__uint16_t [8] __u6_addr16 = [ 0x22a, 0xb806, 0, 0, 0, 0, 0, 0x300 ]
__uint32_t [4] __u6_addr32 = [ 0xb806022a, 0, 0, 0x3000000 ]
}
}
__uint32_t sin6_scope_id = 0
}
You can see that we have printed second argument of connect(2) as struct sockaddr_in6. Also you can see all expected info: AF_INET6, port 80, and ipv6-address.
Make a note: we've launched ./telnet, not telnet - dtrace can't
work with system binaries signed by Apple. So we should copy it.
Same for java:
$ sudo dtrace -qn 'syscall::connect:entry { print(*(struct sockaddr_in6 *)copyin(arg1, arg2)) }' -c '/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/bin/java Test'
[...]
struct sockaddr_in6 {
__uint8_t sin6_len = 0
sa_family_t sin6_family = 0x1e
in_port_t sin6_port = 0x5000
__uint32_t sin6_flowinfo = 0
struct in6_addr sin6_addr = {
union __u6_addr = {
__uint8_t [16] __u6_addr8 = [ 0x2a, 0x2, 0x6, 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x3 ]
__uint16_t [8] __u6_addr16 = [ 0x22a, 0xb806, 0, 0, 0, 0, 0, 0x300 ]
__uint32_t [4] __u6_addr32 = [ 0xb806022a, 0, 0, 0x3000000 ]
}
}
__uint32_t sin6_scope_id = 0x8
}
As we can see, the main difference is that telnet sends sin6_len == 0 but java - sin6_scope_id = 0x8. The main problem in exactly sin6_scope_id. telnet and curl sends scope_id == 0, but java - 0x8. And when we use wired connection, java sends scope_id == 0xb.
To be clear, we try to reproduce problem with scope_id with telnet.
Using WiFi do:
$ telnet 2a02:6b8::3%0 80
Trying 2a02:6b8::3...
Connected to www.yandex.ru.
$ telnet 2a02:6b8::3%8 80
Trying 2a02:6b8::3...
telnet: connect to address 2a02:6b8::3: No route to host
telnet: Unable to connect to remote host
$ telnet 2a02:6b8::3%b 80
Trying 2a02:6b8::3...
Connected to www.yandex.ru.
So telnet can connect with 0xb, but can't with 0x8.
It seems that right place of this code for java is:
http://hg.openjdk.java.net/jdk8u/jdk8u/jdk/file/8fe85977d5a6/src/solaris/native/java/net/net_util_md.c#l105
We've seen that scope_id filled with value of private field java.net.NetworkInterface.defaultIndex, which contains index of some default interface.
We can print all indexes with code:
import java.lang.reflect.Field;
import java.net.NetworkInterface;
import java.util.Collections;
import java.util.List;
public class Test {
public static void main(String[] args) throws Exception {
List<NetworkInterface> netins = Collections.list(NetworkInterface.getNetworkInterfaces());
for (NetworkInterface netin : netins) {
System.out.println(netin + " " + netin.getIndex());
}
Field f = NetworkInterface.class.getDeclaredField("defaultIndex");
f.setAccessible(true);
System.out.println("defaultIndex = " + f.get(NetworkInterface.class));
}
}
On wifi:
$ java Netif
name:awdl0 (awdl0) 8
name:en0 (en0) 4
name:lo0 (lo0) 1
defaultIndex = 8
On wired
$ java Netif
name:en4 (en4) 11
name:lo0 (lo0) 1
defaultIndex = 11
On wired+wifi
$ java Netif
name:awdl0 (awdl0) 8
name:en4 (en4) 11
name:en0 (en0) 4
name:lo0 (lo0) 1
defaultIndex = 8
When wifi connected, defaultIndex == 8, and default interface is awdl0.
So we just
$ sudo ifconfig awdl0 down
and java code works.
Also:
WiFriedX can help.
Another issue: https://bugs.openjdk.java.net/browse/JDK-8132520
What is awd: What is AWDL (Apple Wireless Direct Link) and how does it work?
The author of this patch is https://github.com/snaury.
Explanation:
You need to open libnet.dylib with otool and find _setDefaultScopeID symbol:
otool -tv -p _setDefaultScopeID libnet.dylib
Here you can find comparison with 0 and conditional jump:
000000000000b882 cmpb $0x1e, 0x1(%r14)
000000000000b887 jne 0xb8aa
000000000000b889 cmpl $0x0, 0x18(%r14)
000000000000b88e jne 0xb8aa
You need to replace conditional jump to unconditional jump with any hex editor:
000000000000b882 cmpb $0x1e, 0x1(%r14)
000000000000b887 jne 0xb8aa
000000000000b889 cmpl $0x0, 0x18(%r14)
000000000000b88e jmp 0xb8aa
JNE == 75 1a
JMP == eb 1a
Or use this one line command:
otool -tv -p _setDefaultScopeID libnet.dylib | awk '/cmpl.*\$0x0/ {print $1}' | python -c 'exec """\nwith open("libnet.dylib", "r+b") as fd:\n fd.seek(int(raw_input(), 16) + 5)\n fd.write(chr(235))\n"""'
Wired connection helps me too.
With
$ java -version
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)
I got this problem yesterday. I solved it by overriding DNSResolver of PoolingHttpClientConnectionManager.
private static DnsResolver getDnsResolver() {
return host -> Arrays.stream(InetAddress.getAllByName(host))
.filter(it -> it instanceof Inet6Address)
.toArray(InetAddress[]::new);
}
////////
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(
RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", PlainConnectionSocketFactory.getSocketFactory())
.register("https", SSLConnectionSocketFactory.getSocketFactory())
.build(),
getDnsResolver()
);

Error in JNI method returning ArrayList of Points

I'm trying to use JNI to import a c++ library that I will use in my java project. I have successfully gotten the library method to be called and am trying to return an ArrayList of Point objects from the JNI function. However, I'm getting an error with a rather vague description ('Problematic frame:
V [libjvm.dylib+0x30bab5] JNI_ArgumentPusherVaArg::JNI_ArgumentPusherVaArg(_jmethodID*, __va_list_tag*)+0xd
'). I have no clue what's going on, does anyone know what's going on or how I should interpret this console output? I can attach the log file if anyone wants it.
Console output:
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x000000010550bab5, pid=4633, tid=6403
#
# JRE version: Java(TM) SE Runtime Environment (7.0_51-b13) (build 1.7.0_51-b13)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (24.51-b03 mixed mode bsd-amd64 compressed oops)
# Problematic frame:
# V [libjvm.dylib+0x30bab5] JNI_ArgumentPusherVaArg::JNI_ArgumentPusherVaArg(_jmethodID*, __va_list_tag*)+0xd
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /Users/zalbhathena/Documents/workspace/Thesis-Test-Application/HPA* Program/hs_err_pid4633.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.sun.com/bugreport/crash.jsp
#
Hello World!
ASDFse_dcdt.cpp 284 : Starting init()...
SeDcdt::initfoo.512se_dcdt.cpp 303 : Calculating External Polygon for domain with 4 points...
se_dcdt.cpp 317 : Creating External Polygon...
SeDcdt::initse_dcdt.cpp 326 : Backface v1: -14 -14
se_dcdt.cpp 329 : Backface v2: -14 14
se_dcdt.cpp 332 : Backface v3: 14 14
se_dcdt.cpp 335 : Backface v4: 14 -14
se_triangulator.cpp 417 : insert_point_in_edge...
se_triangulator.cpp 473 : propagate_delaunay...
se_triangulator.cpp 480 : optimizing in constrained mode...4
se_triangulator.cpp 538 : Ok.
se_triangulator.cpp 387 : insert_point_in_face...
se_triangulator.cpp 473 : propagate_delaunay...
se_triangulator.cpp 480 : optimizing in constrained mode...3
se_triangulator.cpp 538 : Ok.
se_triangulator.cpp 417 : insert_point_in_edge...
se_triangulator.cpp 473 : propagate_delaunay...
se_triangulator.cpp 480 : optimizing in constrained mode...4
se_triangulator.cpp 538 : Ok.
se_triangulator.cpp 387 : insert_point_in_face...
se_triangulator.cpp 473 : propagate_delaunay...
se_triangulator.cpp 480 : optimizing in constrained mode...3
se_triangulator.cpp 538 : Ok.
se_triangulator.cpp 417 : insert_point_in_edge...
se_triangulator.cpp 473 : propagate_delaunay...
se_triangulator.cpp 480 : optimizing in constrained mode...4
se_triangulator.cpp 538 : Ok.
se_triangulator.cpp 387 : insert_point_in_face...
se_triangulator.cpp 473 : propagate_delaunay...
se_triangulator.cpp 480 : optimizing in constrained mode...3
se_triangulator.cpp 538 : Ok.
se_triangulator.cpp 387 : insert_point_in_face...
se_triangulator.cpp 473 : propagate_delaunay...
se_triangulator.cpp 480 : optimizing in constrained mode...3
se_triangulator.cpp 538 : Ok.
1
2
3
4
HPAProgram.cpp
/*
* HPAProgram.c++
*
* Created on: Feb 4, 2014
* Author: zalbhathena
*/
//=#include <jni.h>
#include <stdio.h>
#include "HPAProgram.h"
#include "DCDTWrapper.h"
JNIEXPORT jobject JNICALL Java_HPAProgram_sayHello (JNIEnv *env, jobject obj) {
printf("Hello World!\n");
GsArray<GsPnt2> edges;
create_dcdt(&edges);
printf("1\n");
jclass arraylist_class = (*env).FindClass("java/util/ArrayList");
jclass point_class = (*env).FindClass("java/awt/Point");
jmethodID init_arraylist = (*env).GetMethodID(arraylist_class, "<init>", "()V");
jmethodID init_point = (*env).GetMethodID(point_class, "<init>", "(II)V");
jmethodID add_arraylist = (*env).GetMethodID(arraylist_class, "add", "(java/lang/Object)V");
jobject return_obj = (*env).NewObject(arraylist_class, init_arraylist);
printf("2\n");
for (int n=0;n<edges.size();n++)
{
jfloat x = 1;
jfloat y = 1;
printf("3\n");
jobject point_obj = (*env).NewObject(point_class, init_point,x,y);
printf("4\n");
(*env).CallVoidMethod(return_obj, add_arraylist, point_obj);
printf("5\n");
}
return nullptr;
}
DCDTWrapper.cpp
# define END 12345.6
# define FIRST_EXAMPLE Example1
//# include "DCDTsrc/se_dcdt.h"
//# include "DCDTsrc/gs_polygon.h"
//# include <stdlib.h>
# include "DCDTWrapper.h"
static double Example1[] =
{ -10, -10, 10, -10, 10, 10, -10, 10, END,
1, 1, 7, 3, 3, 8, END,
END };
static const double* CurExample = FIRST_EXAMPLE;
static SeDcdt TheDcdt;
static GsPolygon CurPath;
static GsPolygon CurChannel;
static float CurX1=0, CurY1=0, CurX2=0, CurY2=0;
static int CurSelection=0; // -2,-1: moving point, >0: moving polygon
void create_dcdt (GsArray<GsPnt2>* edges)
{
printf("ASDF");
const double* data = CurExample;
GsPolygon pol;
// domain:
while ( *data!=END ) { pol.push().set((float)data[0],(float)data[1]); data+=2; }
TheDcdt.init ( pol, 0.00001f );
while ( *++data!=END )
{ pol.size(0);
while ( *data!=END ) { pol.push().set((float)data[0],(float)data[1]); data+=2; }
TheDcdt.insert_polygon ( pol );
}
GsArray<GsPnt2> unconstr;
TheDcdt.get_mesh_edges(edges, &unconstr);
for(int i = 0; i < unconstr.size(); i++) {
edges -> push(unconstr.get(i));
}
}
HPAProgram.java
import java.util.ArrayList;
public class HPAProgram {
/* static {
//System.out.println(new File(".").getAbsolutePath());
System.loadLibrary("libhpaprogram"); // hello.dll (Windows) or libhello.so (Unixes)
}
//private native void sayHello();
*/
public native ArrayList<String> sayHello();
public static void main(String[] args) {
System.loadLibrary("HPAProgram");
HPAProgram s = new HPAProgram();
s.sayHello();
MapWindowController map = new MapWindowController();
}
}
Function addfrom class ArrayList has return type boolean not void so in c code you have to call CallBooleanMethod from env instead of CallVoidMethod.
Edit: And you need to correct the signature of the add method as well.
You need to change the method signature for "add" element in arrayList as below:
jmethodID add_arraylist = (*env).GetMethodID(arraylist_class, "add", "(java/lang/Object)Z");
instead of
jmethodID add_arraylist = (*env).GetMethodID(arraylist_class, "add", "(java/lang/Object)V");

segment fault cause by optimizer

We encountered one problem when trace log with gdb
.System crash when XMLRPC call and gdb backtrace show:
Program terminated with signal 11, Segmentation fault.
#0 finishCurlMulti (envP=0x0, curlMultiP=0xe37b800, timeoutType=timeout_no,
deadline=..., interruptP=0x0) at xmlrpc_curl_transport.c:572
warning: Source file is more recent than executable.
572
(gdb) bt
#0 finishCurlMulti (envP=0x0, curlMultiP=0xe37b800, timeoutType=timeout_no,
deadline=..., interruptP=0x0) at xmlrpc_curl_transport.c:572
#1 0x00002b84f0b4ad24 in performCurlTransaction (envP=0x46a185d0,
clientTransportP=0xe365d50, serverP=<value optimized out>,
callXmlP=<value optimized out>, responseXmlPP=0x46a185e8)
at xmlrpc_curl_transport.c:1036
#2 performRpc (envP=0x46a185d0, clientTransportP=0xe365d50,
serverP=<value optimized out>, callXmlP=<value optimized out>,
responseXmlPP=0x46a185e8) at xmlrpc_curl_transport.c:1141
#3 call (envP=0x46a185d0, clientTransportP=0xe365d50,
serverP=<value optimized out>, callXmlP=<value optimized out>,
responseXmlPP=0x46a185e8) at xmlrpc_curl_transport.c:1362
===> Is there null pointer error? envP=0x0
-------------------------------------trace frame 1--------------------
(gdb) frame 1
#1 0x00002b84f0b4ad24 in performCurlTransaction (envP=0x46a185d0, clientTransportP=0xe365d50, serverP=<value optimized out>, callXmlP=<value optimized out>,
responseXmlPP=0x46a185e8) at xmlrpc_curl_transport.c:1036
1036 synchronous RPC can be in progress is for the 'perform' method
(gdb) print envP
$1 = <value optimized out>
(gdb) info registers
rax 0x0 0
rbx 0xec59270 247829104
rcx 0x0 0
rdx 0x2 2
rsi 0x46a18200 1184989696
rdi 0xe37b800 238532608
rbp 0x46a185d0 0x46a185d0
rsp 0x46a184e0 0x46a184e0
r8 0x46a17f00 1184988928
r9 0x46a17ef0 1184988912
r10 0x46a18100 1184989440
r11 0x206 518
r12 0xe365d50 238443856
r13 0xe37b800 238532608
r14 0xe99dda0 244964768
r15 0x46a185e8 1184990696
rip 0x2b84f0b4ad24 0x2b84f0b4ad24 <call+340>
eflags 0x10206 [ PF IF RF ]
cs 0x33 51
ss 0xe02b 57387
ds 0x0 0
es 0x0 0
fs 0x63 99
gs 0x0 0
fctrl 0x37f 895
fstat 0x0 0
ftag 0xffff 65535
fiseg 0x0 0
fioff 0x0 0
foseg 0x0 0
fooff 0x0 0
fop 0x0 0
mxcsr 0x1fa0 [ PE IM DM ZM OM UM PM ]
========> do envP store in register rbp?
------------------------Back to frame 0-------------------
(gdb) frame 0
#0 finishCurlMulti (envP=0x0, curlMultiP=0xe37b800, timeoutType=timeout_no, deadline=..., interruptP=0x0) at xmlrpc_curl_transport.c:572
572
(gdb) print envP
$2 = (xmlrpc_env * const) 0x0
(gdb) info register
rax 0x0 0
rbx 0x0 0
rcx 0x0 0
rdx 0x2 2
rsi 0x46a18200 1184989696
rdi 0xe37b800 238532608
rbp 0xe37b800 0xe37b800
rsp 0x46a182f0 0x46a182f0
r8 0x46a17f00 1184988928
r9 0x46a17ef0 1184988912
r10 0x46a18100 1184989440
r11 0x206 518
r12 0x0 0
r13 0x0 0
r14 0x0 0
r15 0x0 0
rip 0x2b84f0b49e93 0x2b84f0b49e93 <finishCurlMulti+259>
eflags 0x10206 [ PF IF RF ]
cs 0x33 51
ss 0xe02b 57387
ds 0x0 0
es 0x0 0
fs 0x63 99
gs 0x0 0
fctrl 0x37f 895
fstat 0x0 0
ftag 0xffff 65535
fiseg 0x0 0
fioff 0x0 0
foseg 0x0 0
fooff 0x0 0
fop 0x0 0
mxcsr 0x1fa0 [ PE IM DM ZM OM UM PM ]
========> Please tell me what is wrong in this case?
I'm trying to use -O0 to disable optimizer but i don't sure.
Thanks.
Here is my backtrace with correct souce file:
#0 finishCurlMulti (envP=0x0, curlMultiP=0x12e2580, timeoutType=timeout_yes, deadline=..., interruptP=0x0) at xmlrpc_curl_transport.c:572
#1 0x00002abe7f51d0b4 in finishAsynch (clientTransportP=0x12e24c0, timeoutType=timeout_yes, timeout=10000) at xmlrpc_curl_transport.c:1301
#2 0x00002abe7f72f5c6 in xmlrpc_c::clientXmlTransport_http::finishAsync (this=0x12e2470, timeout=...) at client.cpp:624
#3 0x00002abe7f72f64a in xmlrpc_c::client_xml::finishAsync (this=0x1304bf0, timeout=...) at client.cpp:893
#4 0x00002aaaab57c26d in UrlStruct::runXmlRpc (this=0x122d140, method="mediacontrol.onEvent", paramList=<value optimized out>, result=<value optimized out>) at Utils.cpp:146
#5 0x00002aaaab57c526 in IVRUtils::executeXmlRpc (controllerUrl=0x12e2580, methodName=Traceback (most recent call last):
#6 0x00002aaaab54366a in IvrCoreSession::_exec_xmlrpc_cmd (this=0x2aaab48277f0, paramList=..., result=0x41228cb0) at IvrCoreSession.cpp:307
#7 0x00002aaaab544c95 in IvrCoreSession::fireEndCallEvent (this=0x2aaab48277f0) at IvrCoreSession.cpp:504
#8 0x00002aaaab54752d in IvrCoreSession::~IvrCoreSession (this=0x2aaab48277f0, __in_chrg=<value optimized out>) at IvrCoreSession.cpp:101
#9 0x000000000047c15d in AmSessionContainer::clean_sessions (this=0x10cbdd0) at AmSessionContainer.cpp:94
#10 0x000000000047c898 in AmSessionContainer::run (this=0x10cbdd0) at AmSessionContainer.cpp:132
#11 0x000000000049266c in AmThread::_start (_t=<value optimized out>) at AmThread.cpp:70
#12 0x000000397ec0673d in start_thread () from /lib64/libpthread.so.0
#13 0x000000397e0d40cd in clone () from /lib64/libc.so.6
This bug occur every 6 days. And we use xmlrpc-c lib with curl build option --enable-threaded-resolver. Please give us some idea.
Thanks.
This looks dangerous:
warning: Source file is more recent than executable
This means the debug symbols don't match your source code. Build and try again; you might be hunting a bug that has already been fixed.
Also check the code in performCurlTransaction() at xmlrpc_curl_transport.c:1036 because this function gets envP != null but it calls finishCurlMulti with null.

Categories