Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

FreeBSD pl/java problem : backend hangs

2 views
Skip to first unread message

Achilleas Mantzios

unread,
Feb 4, 2013, 8:17:22 AM2/4/13
to
Hello community,

I am running postgresql 9.2.2 with
openjdk version "1.6.0_32"
OpenJDK Runtime Environment (build 1.6.0_32-b25)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)
On FreeBSD 8.3-RELEASE

I am having trouble even running simple tests like :
CREATE FUNCTION getsysprop(VARCHAR)
RETURNS VARCHAR
AS 'java.lang.System.getProperty'
LANGUAGE java;

SELECT getsysprop('user.home');

When i do that, the session hangs, and have to kill -9 the backend.

Searching with truss got :

gettimeofday({1359983241.596250 },0x0) = 0 (0x0)
gettimeofday({1359983241.596275 },0x0) = 0 (0x0)
gettimeofday({1359983241.596300 },0x0) = 0 (0x0)
gettimeofday({1359983241.596327 },0x0) = 0 (0x0)
gettimeofday({1359983241.596352 },0x0) = 0 (0x0)
gettimeofday({1359983241.596378 },0x0) = 0 (0x0)
gettimeofday({1359983241.596403 },0x0) = 0 (0x0)
gettimeofday({1359983241.596431 },0x0) = 0 (0x0)
gettimeofday({1359983241.596458 },0x0) = 0 (0x0)
gettimeofday({1359983241.596482 },0x0) = 0 (0x0)
gettimeofday({1359983241.596507 },0x0) = 0 (0x0)
gettimeofday({1359983241.596532 },0x0) = 0 (0x0)
gettimeofday({1359983241.596556 },0x0) = 0 (0x0)
_umtx_op(0x7fffffffc7e8,0x3,0x1,0x0,0x0,0x1) = 0 (0x0)
sigprocmask(SIG_BLOCK,SIGHUP|SIGINT|SIGQUIT|SIGABRT|SIGEMT|SIGKILL|SIGSYS|SIGPIPE|SIGALRM|SIGTERM|SIGURG|SIGSTOP|SIGTSTP|SIGCONT|SIGCHLD|SIGTTIN|SIGTTOU|SIGIO|SIGXCPU|SIGXFSZ|SIGVTALRM|SIGPROF|SIGWINCH|SIGINFO|SIGUSR1|SIGUSR2,0x0) = 0 (0x0)
sigprocmask(SIG_SETMASK,0x0,0x0) = 0 (0x0)
sigprocmask(SIG_BLOCK,SIGHUP|SIGINT|SIGQUIT|SIGABRT|SIGEMT|SIGKILL|SIGSYS|SIGPIPE|SIGALRM|SIGTERM|SIGURG|SIGSTOP|SIGTSTP|SIGCONT|SIGCHLD|SIGTTIN|SIGTTOU|SIGIO|SIGXCPU|SIGXFSZ|SIGVTALRM|SIGPROF|SIGWINCH|SIGINFO|SIGUSR1|SIGUSR2,0x0) = 0 (0x0)
sigprocmask(SIG_SETMASK,0x0,0x0) = 0 (0x0)

while ktrace gave :

98910 initial thread CALL gettimeofday(0x7fffffffc900,0)
98910 initial thread RET gettimeofday 0
98910 initial thread CALL gettimeofday(0x7fffffffc900,0)
98910 initial thread RET gettimeofday 0
98910 initial thread CALL gettimeofday(0x7fffffffc900,0)
98910 initial thread RET gettimeofday 0
98910 initial thread CALL gettimeofday(0x7fffffffc900,0)
98910 initial thread RET gettimeofday 0
98910 initial thread CALL gettimeofday(0x7fffffffc940,0)
98910 initial thread RET gettimeofday 0
98910 initial thread CALL _umtx_op(0x7fffffffc7e8,0x3,0x1,0,0)
98910 initial thread RET _umtx_op 0
98910 initial thread CALL sigprocmask(SIG_BLOCK,0x7fffffffc780,0x8016167d8)
98910 initial thread RET sigprocmask 0
98910 initial thread CALL sigprocmask(SIG_SETMASK,0x8016167d8,0)
98910 initial thread RET sigprocmask 0
98910 initial thread CALL sigprocmask(SIG_BLOCK,0x7fffffffc6e0,0x8016167d8)
98910 initial thread RET sigprocmask 0
98910 initial thread CALL sigprocmask(SIG_SETMASK,0x8016167d8,0)
98910 initial thread RET sigprocmask 0
98910 initial thread CALL _umtx_op(0x8f8dc4280,0x11,0,0,0)

I found some relevant problems with FreeBSD systems hanging after an _umtx_op but all those point
to threading problems that now are solved. I found nothing modern about _umtx_op.

I know FreeBSD is not a "Tier-1" platform for postgresql (nor java), but this is my main platform and i'd like
to stick with this.

Is there anything i could do to get closer to make pl/java work with FreeBSD?

Also read this http://postgresql.1045698.n5.nabble.com/Java-VM-stalls-during-quot-install-jar-quot-td3290754.html thread.
Very close to my situation. JNI standalone also worked for me.

Any hints/pointers ?

-
Achilleas Mantzios
IT DEV
IT DEPT
Dynacom Tankers Mgmt
_______________________________________________
freebs...@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-java
To unsubscribe, send any mail to "freebsd-java...@freebsd.org"

Achilleas Mantzios

unread,
Feb 4, 2013, 8:16:38 AM2/4/13
to

Ronald Klop

unread,
Feb 4, 2013, 8:47:13 AM2/4/13
to
I have no experience running java as a backend of pgsql.
Can you run jstack on the backend?

Ronald.
> Dynacom Tankers Mgmt

Achilleas Mantzios

unread,
Feb 4, 2013, 9:09:56 AM2/4/13
to
Thanx Ronald,

postgres@smadev:~> jstack 384
384: Unable to open socket file: target process not responding or HotSpot VM not loaded
The -F option can be used when the target process is not responding

Also jstack -F fails as well
postgres@smadev:~> jstack -F 384
Attaching to process ID 384, please wait...
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at sun.tools.jstack.JStack.runJStackTool(JStack.java:136)
at sun.tools.jstack.JStack.main(JStack.java:102)
Caused by: sun.jvm.hotspot.debugger.UnalignedAddressException: Trying to read at address: 0x746f705c6c4f4867 with alignment: 4
at sun.jvm.hotspot.debugger.bsd.BsdDebuggerLocal$1.checkAlignment(BsdDebuggerLocal.java:181)
at sun.jvm.hotspot.debugger.bsd.BsdDebuggerLocal.readCInteger(BsdDebuggerLocal.java:478)
at sun.jvm.hotspot.debugger.DebuggerBase.readAddressValue(DebuggerBase.java:454)
at sun.jvm.hotspot.debugger.bsd.BsdDebuggerLocal.readAddress(BsdDebuggerLocal.java:423)
at sun.jvm.hotspot.debugger.bsd.BsdAddress.getAddressAt(BsdAddress.java:74)
at sun.jvm.hotspot.HotSpotTypeDataBase.readVMTypes(HotSpotTypeDataBase.java:108)
at sun.jvm.hotspot.HotSpotTypeDataBase.<init>(HotSpotTypeDataBase.java:85)
at sun.jvm.hotspot.bugspot.BugSpotAgent.setupVM(BugSpotAgent.java:574)
at sun.jvm.hotspot.bugspot.BugSpotAgent.go(BugSpotAgent.java:495)
at sun.jvm.hotspot.bugspot.BugSpotAgent.attach(BugSpotAgent.java:333)
at sun.jvm.hotspot.tools.Tool.start(Tool.java:163)
at sun.jvm.hotspot.tools.JStack.main(JStack.java:86)

Achilleas Mantzios

unread,
Feb 4, 2013, 10:16:27 AM2/4/13
to
I am thinking of trying to address this problem twofold :

1) establish a connection with the pl/java people
2) trying to go back and forth from there and here to try to debug the problem

Lets wait for some recommendation/help from there, and then i'll get back
to this list for more.

Achilleas Mantzios

unread,
Feb 4, 2013, 10:48:20 AM2/4/13
to
It seems that it gets hung in JNI_CreateJavaVM.

I can write and run standalone JNI programs outside postgrsesql (even as postgres user),
but when i try to run it from within postgres, then it gets hang.

Any ideas?

Achilleas Mantzios

unread,
Feb 4, 2013, 12:00:18 PM2/4/13
to
It surely is a problem with running JNI from within postgresql in FreeBSD :

Wrote a very small C postgresql function which simply calls JNI
and it hangs as well.

#include "postgres.h"

#include "utils/elog.h"
#include "utils/palloc.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "storage/bufpage.h"
#include "catalog/pg_type.h"

#include <jni.h>

PG_MODULE_MAGIC;

PG_FUNCTION_INFO_V1(jnitest);
Datum jnitest(PG_FUNCTION_ARGS);

Datum
jnitest(PG_FUNCTION_ARGS)
{
int res;
JNIEnv *env;
JavaVM *jvm;
JavaVMInitArgs vm_args;
JavaVMOption *options=NULL;
vm_args.version = 0x00010002;
vm_args.options = options;
vm_args.nOptions = 0;
vm_args.ignoreUnrecognized = JNI_TRUE;
/* Create the Java VM */
res = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);

PG_RETURN_POINTER(res);
}

create function jnitest() RETURNS integer LANGUAGE c AS '$libdir/jnitest', 'jnitest';

dynacom=# select jnitest();

^^^ hangs, it seems the call to res = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
just never completes

So, this must be a FreeBSD/PostgreSQL/JNI thing.

Any help/where to go from here would be very welcome.

Konstantin Belousov

unread,
Feb 4, 2013, 12:18:59 PM2/4/13
to
Try to start the postgres daemon with 'LD_PRELOAD=/lib/libthr.so.3'
env variable set.

Achilleas Mantzios

unread,
Feb 5, 2013, 3:38:18 AM2/5/13
to
On Δευ 04 Φεβ 2013 19:18:59 you wrote:

> Try to start the postgres daemon with 'LD_PRELOAD=/lib/libthr.so.3'
> env variable set.

Thanx, i tried with this, inside postgresql startup script with no luck.
I also saw this thread here : http://www.postgresql.org/message-id/68c429ede4cde387...@cs.helsinki.fi
(but could not find its continuation over the FreeBSD camp)
The author claims that postgres backend executable must be linked with -lpthread.
Inside postgres's Makefile.global i can see
PTHREAD_CFLAGS = -pthread -D_REENTRANT -D_THREAD_SAFE -D_POSIX_PTHREAD_SEMANTICS
THREAD_LIBS = -lpthread
however when i do

root@smadev:/usr/local/src/postgresql-9.2.2# ldd /usr/local/pgsql/bin/postgres
/usr/local/pgsql/bin/postgres:
libm.so.5 => /lib/libm.so.5 (0x800ae5000)
libldap-2.4.so.8 => /usr/local/lib/libldap-2.4.so.8 (0x800c05000)
libc.so.7 => /lib/libc.so.7 (0x800d47000)
liblber-2.4.so.8 => /usr/local/lib/liblber-2.4.so.8 (0x800f89000)
libssl.so.6 => /usr/lib/libssl.so.6 (0x801096000)
libcrypto.so.6 => /lib/libcrypto.so.6 (0x8011e9000)

i see nothing thread (libpthread or libtrh) related.

Any help to overcome this much appreciated.
0 new messages