Hi,

i'm trying to write my first x10 program and to debug a
NullPointerException in there. The Exception is thrown in the following
method, which should generate a ring graph (each node having one
successor).

  static def generateGraph() : Rail[Node] {
    var graph:Rail[Node] = Rail.make[Node](GRAPH_SIZE);
    for(var i:int=0; i<GRAPH_SIZE; i++) {
      graph(i) = new Node(0);
      if (i>0) { graph(i-1).successors.add(graph(i)); };
    }
    graph(GRAPH_SIZE-1).successors.add(graph(0));
    return graph;
  }

Here is compilation and execution. The backtrace seems not very useful,
though:

$ x10c++ DataFlowExample.x10 && runx10 a.out
x10c++: 7 dynamically checked calls or field accesses.
Uncaught exception at place 0: x10.lang.NullPointerException
x10.lang.NullPointerException
        at x10::lang::Throwable::fillInStackTrace()
        at x10aux::throwException(x10aux::ref<x10::lang::Throwable>)
        at void x10aux::throwException<x10::lang::BadPlaceException>()
        at x10aux::throwBPE()
        at x10aux::ref<x10::util::ArrayList<x10aux::ref<DataFlowExample__Node>
> >
x10aux::nullCheck<x10::util::ArrayList<x10aux::ref<DataFlowExample__Node> > 
>(x10aux::ref<x10::util::ArrayList<x10aux::ref<DataFlowExample__Node> > >)
        at DataFlowExample::generateGraph()
        at
DataFlowExample::main(x10aux::ref<x10::lang::Rail<x10aux::ref<x10::lang::String>
 > >)
        at x10aux::BootStrapClosure::apply()
        at x10_lang_Runtime__closure__1::apply()
        at x10::lang::Activity::run()
        at x10_lang_Runtime__Worker__closure__0::apply()
        at x10::lang::Runtime::runAtLocal(int,
x10aux::ref<x10::lang::VoidFun_0_0>)
        at
x10::lang::Runtime__Worker::loop(x10aux::ref<x10::lang::Runtime__Latch>,
bool)
        at x10::lang::Runtime__Worker::apply()
        at x10::lang::Runtime__Pool::apply()
        at x10::lang::Runtime::start(x10aux::ref<x10::lang::VoidFun_0_0>,
x10aux::ref<x10::lang::VoidFun_0_0>)
        at int x10aux::template_main<x10::lang::Runtime, DataFlowExample>(int,
char**)
        at main
        at __libc_start_main
        at a.out() [0x805dac1]

So i take gdb for some more detailed debugging:

$ runx10 gdb a.out 
GNU gdb (GDB) 7.1-ubuntu
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show
copying"
and "show warranty" for details.
This GDB was configured as "i486-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols
from /afs/info.uni-karlsruhe.de/user/zwinkau/dev/invasic_examples/a.out...done.
(gdb) catch throw
Catchpoint 1 (throw)
(gdb) r
Starting
program: /afs/info.uni-karlsruhe.de/user/zwinkau/dev/invasic_examples/a.out 
[Thread debugging using libthread_db enabled]
[New Thread 0xb6efcb70 (LWP 22389)]
[New Thread 0xb66fbb70 (LWP 22397)]
[New Thread 0xb5ed9b70 (LWP 22399)]

Program received signal SIGPWR, Power fail/restart.
0xb7fe2430 in __kernel_vsyscall ()
(gdb) c
Continuing.

Program received signal SIGXCPU, CPU time limit exceeded.
0xb7fe2430 in __kernel_vsyscall ()
(gdb) c
Continuing.
Catchpoint 1 (exception thrown), 0xb7168575 in __cxa_throw ()
from /usr/lib/libstdc++.so.6
(gdb) bt
#0  0xb7168575 in __cxa_throw () from /usr/lib/libstdc++.so.6
#1  0x08064508 in x10aux::throwException (e=...)

at 
/afs/info.uni-karlsruhe.de/user/zwinkau/dev/x10/x10.dist/include/x10aux/throw.h:28
#2  0xb7d93d3a in
x10aux::throwException<x10::lang::NullPointerException> ()
at ./x10aux/throw.h:32
#3  0xb7d93c37 in x10aux::throwNPE () at x10aux/ref.cc:27
#4  0x08065e9d in
x10aux::nullCheck<x10::util::ArrayList<x10aux::ref<DataFlowExample__Node> > > 
(obj=...)

at 
/afs/info.uni-karlsruhe.de/user/zwinkau/dev/x10/x10.dist/include/x10aux/ref.h:185
#5  0x0805ee3e in DataFlowExample::generateGraph () at
DataFlowExample.cc:487
#6  0x0805f7a5 in DataFlowExample::main (id__2=...) at
DataFlowExample.cc:666
#7  0xb7d87154 in x10aux::BootStrapClosure::apply (this=0x80d1fa8)
at ./x10aux/bootstrap.h:91
#8  0xb79dba2c in x10_lang_Runtime__closure__1::apply (this=0x80f5000)
at gen/x10/lang/Runtime.inc:680
#9  0xb798ef4b in x10::lang::Activity::run (this=0x80d5e88) at
gen/x10/lang/Activity.cc:212
#10 0xb7a8fa1b in x10_lang_Runtime__Worker__closure__0::apply
(this=0x810ff90) at gen/x10/lang/Runtime__Worker.inc:157
#11 0xb79cba23 in x10::lang::Runtime::runAtLocal (id=0, body=...) at
gen/x10/lang/Runtime.cc:51
#12 0xb7a8e0a8 in x10::lang::Runtime__Worker::loop (this=0x80f8fc0,
latch=..., block=true)
    at gen/x10/lang/Runtime__Worker.cc:280
#13 0xb7a8daed in x10::lang::Runtime__Worker::apply (this=0x80f8fc0) at
gen/x10/lang/Runtime__Worker.cc:148
#14 0xb787c39e in x10::lang::Runtime__Pool::apply (this=0x80d5f78) at
gen/x10/lang/Runtime__Pool.cc:168
#15 0xb79cc8fd in x10::lang::Runtime::start (init=..., body=...) at
gen/x10/lang/Runtime.cc:392
#16 0x080663d5 in x10aux::template_main<x10::lang::Runtime,
DataFlowExample> (ac=1, av=0xbffff254)

at 
/afs/info.uni-karlsruhe.de/user/zwinkau/dev/x10/x10.dist/include/x10aux/bootstrap.h:151
#17 0x0805f792 in main (ac=1, av=0xbffff254) at DataFlowExample.cc:660
(gdb) f 4
#4  0x08065e9d in
x10aux::nullCheck<x10::util::ArrayList<x10aux::ref<DataFlowExample__Node> > > 
(obj=...)

at 
/afs/info.uni-karlsruhe.de/user/zwinkau/dev/x10/x10.dist/include/x10aux/ref.h:185
185             if (obj.isNull()) throwNPE();
(gdb) p obj
$1 = {<x10aux::__ref> = {<No data fields>}, _val = 0x0}
(gdb) f 5
#5  0x0805ee3e in DataFlowExample::generateGraph () at
DataFlowExample.cc:487
487                             )->apply(i));
(gdb) p i
$2 = 1

Judging from the C++ code the null check is done at the add call within
the if-body. Could graph(i) be null there?

Tangential questions:
What is it about those SIGPWR and SIGXCPU signals? Is this internal x10
behavior? What for?

Any comments how to write this code more elegantly? 

Thanks!

-- 
Andreas Zwinkau

 Karlsruhe Institute of Technology (KIT)
 Institut für Programmstrukturen und Datenorganisation (IPD)
 Lehrstuhl Prof. Snelting
 Adenauerring 20a
 76131 Karlsruhe

Phone:  +49 721 608-8351
Fax:    +49 721 608-8457
Email:  zwin...@kit.edu
Web:    http://pp.info.uni-karlsruhe.de/person.php?id=107

        KIT – University of the State of Baden-Wuerttemberg and
         National Research Center of the Helmholtz Association


------------------------------------------------------------------------------
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
_______________________________________________
X10-users mailing list
X10-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/x10-users

Reply via email to