Posts Tagged ‘java’

Using JSVC with Tomcat on a 64-bits machine with a 32-bits JVM.

The Problem

After a good amount of research and issues that  looked like memory leaks I’m moving my jvms to 32-bits JVMs for the servers that do not need a heap larger than 2GB. This was ok and a fast switch of the /usr/local/java symlink, BUT it was not as easy with JSVC that I use to run Tomcat under the user tomcat. The problem is that when I compile jsvc on a 64-bits machine it will auto-magically find the box as x86_64 and then expect that your jvm is also 64 bits.

The Fix

What I found that needs to be done is to force the compiler to use 32bit flags, so first lets run the configure string

[root ~]# cd /usr/local/tomcat/bin && tar -zxf jsvc.tar.gz
[root ~]# cd jsvc-src && chmod +x configure
[root ~]# CFLAGS=-m32 CPPFLAGS=-m32 CCASFLAGS=-m32 LDFLAGS="-L/usr/lib -L/lib" ./configure --build=i686-pc-linux-gnu

now the next step is to run make

[root ~]# make

What you will now see is that the last step of the make will fail horribly with the following error:

gcc -L/usr/lib -L/lib -ldl -lpthread jsvc-unix.o libservice.a -o ../jsvc
/usr/bin/ld: skipping incompatible /usr/lib/libdl.so when searching for -ldl
/usr/bin/ld: skipping incompatible /usr/lib/libdl.a when searching for -ldl
/usr/bin/ld: skipping incompatible /usr/lib/libpthread.so when searching for -lpthread
/usr/bin/ld: skipping incompatible /usr/lib/libpthread.a when searching for -lpthread
/usr/bin/ld: skipping incompatible /usr/lib/libc.so when searching for -lc
/usr/bin/ld: skipping incompatible /usr/lib/libc.a when searching for -lc
/usr/bin/ld: warning: i386 architecture of input file `jsvc-unix.o' is incompatible with i386:x86-64 output
/usr/bin/ld: warning: i386 architecture of input file `libservice.a(arguments.o)' is incompatible with i386:x86-64 output
/usr/bin/ld: warning: i386 architecture of input file `libservice.a(debug.o)' is incompatible with i386:x86-64 output
/usr/bin/ld: warning: i386 architecture of input file `libservice.a(help.o)' is incompatible with i386:x86-64 output
/usr/bin/ld: warning: i386 architecture of input file `libservice.a(home.o)' is incompatible with i386:x86-64 output
/usr/bin/ld: warning: i386 architecture of input file `libservice.a(java.o)' is incompatible with i386:x86-64 output
/usr/bin/ld: warning: i386 architecture of input file `libservice.a(location.o)' is incompatible with i386:x86-64 output
/usr/bin/ld: warning: i386 architecture of input file `libservice.a(replace.o)' is incompatible with i386:x86-64 output
/usr/bin/ld: warning: i386 architecture of input file `libservice.a(dso-dlfcn.o)' is incompatible with i386:x86-64 output
make[1]: Leaving directory `/usr/local/tomcat/bin/jsvc-src/native'

Looks like the last gcc left out the -m32 and therefor fails.. Lets do the last task manually

[root ~]# cd native && gcc -m32 -L/usr/local/java/lib -L/usr/lib -L/lib -ldl -lpthread jsvc-unix.o libservice.a -o ../jsvc && cd ..

now if you do the following you should have a correctly compiled 32-bits jsvc executable that points to your 32 bits jvm

[root ~]# file jsvc
jsvc: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), for GNU/Linux 2.6.9, not stripped

Nice!

Resources

http://www.mail-archive.com/users@tomcat.apache.org/msg36176.html

Advertisements

Eclipse MemoryAnalyzer Exit Code=-1

I was looking for a nice tool to read java heap dumps and found that regular JHat was not a great way to go with the 1.6GiB dump files I have. A friend pointed me to a Eclipse project Memory Analyzer (MAT) http://www.eclipse.org/mat/ which is the old SAP analyzer…

Starting it up I got the Exit Code=-1 error and found that this tool is currently not working with java 1.6.x on a mac. If you want to force the tool to use 1.5 open a terminal window and follow these instructions:
freddy@svn:~/mat/MemoryAnalyzer.app/Contents$ pwd
/Users/freddy/mat/MemoryAnalyzer.app/Contents
freddy@svn:~/mat/MemoryAnalyzer.app/Contents$ vi Info.plist
Uncomment this line:
… eworks/JavaVM.framework/Versions/1.5.0/Commands/java
This will force the use of Java 1.5!