[kaffe] porting & debugging

Gerlando Falauto iurly at writeme.com
Tue Apr 8 13:53:01 PDT 2003

Hi folks,

I am trying to port kaffe-1.0.7 (eventually the jit engine too) to yet
another platform (a weird, proprietary VLIW processor), and after several
weeks of struggling because of the limitations of the compiler (no int64
support, limited availability of system calls and so on...) I finally 
got to the part where I am able to run HelloWorldApp. Yippie!

Before I take a path that could lead to suicide, which is trying to work
on the JIT (and I know for sure suicide is where I am headed), I would
like to get threads to work, but I can't figure any way out of this.

Here's what I have essentially done so far:

* Packaged a library of functions to operate on 64-bit types (struct of
two 32-bit integers) and replaced every operation between jlong variables
with the appropriate function call
* Implemented sysDepCallMethod() using the target assembly
* Defined COMPARE_AND_EXCHANGE in plain C (there is no support for 
inline asm), using a mutex to protect the code (there is no atomic 
exchange operation in the target assembly)
* Enabled unix-pthreads as the thread system
* Implemented sem_* using a condition variable and a mutex
* Disabled any Garbage Collector or Finalizer whatsoever

I haven't done much testing yet, but this seems to work for simple tests.
But when it comes to multithreading (or even if I just enable the garbage 
collector), God knows what happens in there. I am currently trying to 
execute a couple of threads that just keep printing their names, but 
eventually one of them just raises a NullPointerException and dies. 
Sometimes both of them do, the machine crashes and so on.

I am not into POSIX or Kaffe that much (actually I barely know their
names), so any suggestion as what to try next would be more than
appreciated. For instance: what should I double check about the target
machine? Like if the stack grows up or down? Or should I test the pthreads
library somehow?  Anything that might get corrupted during a context
switch? Stack sizes? Alignments? Should I stick to unix-pthreads or should
I switch to jthreads (there are rumours that the pthreads library actually

BTW, I am cross-compiling and using a simulated environment on top of
Linux/i386 to test the machine. And since I have no proof that the
libraries and system calls I am using (e.g. sleep, pthread_* and so on)
*actually work*, I can't take anything for granted. Also, I don't have any 
debugger available for the target platform.
Last thing I tried was to implement the run() method of the class 
implementing Runnable as a native method (infinite dprintf C loop), 
which yielded the expected output of "A-B" interleaved printouts.
So my impression is that threads seem to work after all. There must be 
something wrong with context switches, or perhaps those separate threads 
are sharing some memory they are not supposed to. 

I really have no idea what this could be, so please don't spare me any 
suggestion even if it's the most obvious or stupid thing in the world. 

Lastly, one direct question: if I were to execute

System.out.println("Hello World!");

from within a native method, how would I do that?
I suppose I should get class System, then take static 
field out, and then call method println on it... How?

Thanks a lot for reading this far!

More information about the kaffe mailing list