Tuesday, December 16, 2008

Enable your >4GB in Ubuntu Intrepid

The default kernel uses CONFIG_HIGHMEM4G, which does not let you fully use your huge RAM (RAM is now very cheap) way above 4GB (the limit for a 32 bit address space). The best thing you can do is to tune your kernel. To do it you can download the latest one (from www.kernel.org), then configure it with

make menuconfig

Making sure you load configuration from alternate file "/boot/config-XXXX-generic".

After you have loaded the original configuration, you can select :
Processor Type and Features -> High Memory Support

And then make sure 64GB is selected.

Now you can exit the configuration menu and save your changes.

You're ready to build the kernel. To make it the debian way, you can use:

fakeroot make-kpkg --initrd --append-to-version=-gralfca kernel_headers kernel_image

it will generate the linux_headers and linux_image .deb files which you can install with

dpkg -i linux_headers*.deb
dpkg -i linux_image*.deb

That's it. You will be able to use your RAM after you restart.

Friday, December 12, 2008

Make jboss listen in all interfaces

To make jboss listen in all interfaces you can start it with:

./run.sh -b 0.0.0.0

Wednesday, December 10, 2008

Mix C and C++ with JNI

I did it as follows:

* I implemented an intermediate class in C++ that has a set of functions in C, which call the functions in C++. For instance, let's suppose you have a function func1 that you want to use from JNI. I implemented

extern int func1_cplus (int attrib1, int attrib2);
extern "C" int func1 (int attrib1, int attrib2){
return func1_cplus(attrib1, attrib2);
}
int func1_cplus (int attrib1, int attrib2){
MyClass01 tst = new MyClass01();
}

This was the .c file. The .h file was like:
int func1( int attrib1, int attrib2);

The real trick is to add the extern to the c++ functions in such a way that the C functions can use them.

* I had to build the jni wrapper full of JNIEXPORT, JNICALL, JNIEnv, etc, the usual way, save that I used my Arhuaco's api that took the .h and generated the whole wrapper from it. Anyway,
if you do it by hand, you can use javah to generate the .h from the .java with native keys.
(see JNI book).

*. To compile all the C++ code with g++
 g++ -c -fPIC XX.cpp -o XX.o $(CFLAGS) 


*. To compile the jni wrapper with gcc
gcc -c fPIC -o libWrapper.o libWrapper.c $(CFLAGS)


*. To compile all the classes and the wrapper inside the shared object
g++ -shared -o libWrapper.so *.o