[kaffe] ColdFire- ThreadGroup.add() dead-loop at init

Jan Sobota hermez@microtech.softax.com.pl
Sat May 17 08:44:33 2003


hai:)

i'm porting kaffe 1.0.7 (intrp) for m68k (ColdFire) with custom RTOS w/o
using standard kaffe's automake system. i use gcc-m68k cross-compiler.

my current step:
  initialiseKaffe() -> initThreads -> createInitialThread ->
  do_execute_java_method -> do_execute_java_method_v -> callMethodV ->
  virtualMachine -> runVirtualMachine [!]

the problem:
 the following code in java.lang.ThreadGroup class generates never ending
loop.

	synchronized void add(Thread thread) {
		int i;
		nthreads++;
		if (threads == null) {
			threads = new Thread[1];
		}

		// [THIS LOOP RUNS AND NEVER ENDS]
	        for (i = 0; i < threads.length; i++) {
			[..]
		}
		[..]
	}

and this is my debug output:
<1>
from thread.c->initThreads().
after threads array init
	unhand(standardGroup)->threads =
	(HArrayOfObject*) newArray(ThreadClass, 0);
[.]
newArray 0x404c22c8 class [Ljava/lang/Thread; count 0
newArray 0x404c22f8 class [Ljava/lang/ThreadGroup; count 0
[.]

<2>
from runVirtualMachine() loop.
taken just before for (;;) loop, using
	printf("[runVirtualMachine 0] group=%p threads=%p\n"
            , unhand(tid)->group
            , unhand(tid)->group->threads
            );
and later bytecode step by step.

[.]
[runVirtualMachine 0] group=0x404c4940 threads=0x404c22c8
begin   RUN   RUN   RUN
- 42 (0x2a) p=0 npc=0 pc=0 insnLen=1 / p=1 npc=1 mjbuf->pc=0
- 89 (0x59) p=1 npc=1 pc=1 insnLen=1 / p=2 npc=2 mjbuf->pc=1
- 180 (0xb4) p=2 npc=2 pc=2 insnLen=3 / p=3 npc=5 mjbuf->pc=2
- 4 (0x4) p=3 npc=5 pc=5 insnLen=1 / p=4 npc=6 mjbuf->pc=5
- 96 (0x60) p=4 npc=6 pc=6 insnLen=1 / p=5 npc=7 mjbuf->pc=6
- 181 (0xb5) p=5 npc=7 pc=7 insnLen=3 / p=6 npc=10 mjbuf->pc=7
- 42 (0x2a) p=6 npc=10 pc=10 insnLen=1 / p=7 npc=11 mjbuf->pc=10
- 180 (0xb4) p=7 npc=11 pc=11 insnLen=3 / p=8 npc=14 mjbuf->pc=11
- 199 (0xc7) p=8 npc=14 pc=14 insnLen=3 / p=9 npc=17 mjbuf->pc=14
- 42 (0x2a) p=9 npc=25 pc=25 insnLen=1 / p=10 npc=26 mjbuf->pc=25
- 180 (0xb4) p=10 npc=26 pc=26 insnLen=3 / p=11 npc=29 mjbuf->pc=26
- 199 (0xc7) p=11 npc=29 pc=29 insnLen=3 / p=12 npc=32 mjbuf->pc=29
- 3 (0x3) p=12 npc=40 pc=40 insnLen=1 / p=13 npc=41 mjbuf->pc=40
- 61 (0x3d) p=13 npc=41 pc=41 insnLen=1 / p=14 npc=42 mjbuf->pc=41
- 167 (0xa7) p=14 npc=42 pc=42 insnLen=3 / p=15 npc=45 mjbuf->pc=42
- 28 (0x1c) p=15 npc=65 pc=65 insnLen=1 / p=16 npc=66 mjbuf->pc=65
- 42 (0x2a) p=16 npc=66 pc=66 insnLen=1 / p=17 npc=67 mjbuf->pc=66
- 180 (0xb4) p=17 npc=67 pc=67 insnLen=3 / p=18 npc=70 mjbuf->pc=67
- 190 (0xbe) p=18 npc=70 pc=70 insnLen=1 / p=19 npc=71 mjbuf->pc=70
ARRAYLENGTH
[m] - stack 0: [0x40330b18] array * 0x404c[3164280]
[ARRAYLENGTH] group=0x404c4940 threads=0x404c22c8
- 161 (0xa1) p=19 npc=71 pc=71 insnLen=3 / p=20 npc=74 mjbuf->pc=71
- 42 (0x2a) p=20 npc=45 pc=45 insnLen=1 / p=21 npc=46 mjbuf->pc=45
- 180 (0xb4) p=21 npc=46 pc=46 insnLen=3 / p=22 npc=49 mjbuf->pc=46
[.]
LATER RUNS until my WATCHDOG stops platform.


the problem is in array size maybe. threads.length = 0, but arraylength
instruction returns 3164280, and it thinks of "threads" pointer to be
0x404c (good value is 0x404c22c8).

my debug is taken inside define_insn(ARRAYLENGTH) in kaffe.def using:

check_stack_array(0);
printf ("[m] - stack %d: [%p] array * %p[%d]\n",
 (0),
 stack(0),
 (void *) stack(0)->v.taddr,
 (int) *(uint32*)(object_array_length+(char*)stack(0)->v.taddr));
printf("[ARRAYLENGTH] group=%p threads=%p tt=%p\n"
 , unhand(tid)->group
 , unhand(tid)->group->threads
 , unhand(tid)->group->tt);


i think problem is somewhere in my port, not in kaffe itself. but could
you DIRECT ME - why stack(0)->v.taddr shows only half_and_moved correct
threads pointer?

when i create arrays Thread[0] inside add() method - arraylength returns
correct values, but bookmarked loop remains bad. any other arrays
encountered before this point behave correctly (size and pointer).

when i added
private Thread[] tt = new Thread[3]; into ThreadGroup class
and initialised it in thread.c->initThreads()
and added code in add() method before my fatal loop:
	if (tt == null) {
		tt = new Thread[4];
	}
        int aa = tt.length;
then my platform hangs (WATCHDOG) inside define_insn(ARRAYLENGTH) opcode
(load_offset_int() hangs).


greetz:))
 J/