Hi all,
I have a problem with an example program I have written. The program
compiles fine when compiled without "-O" flag:
$> x10c++ ResilientHelloWorld.x10 -o ResilientHelloWorld
$>
But when compiled with "-O", I get a NullPointerException:
$> x10c++ ResilientHelloWorld.x10 -O -o ResilientHelloWorld
Exception in thread "main" java.lang.NullPointerException
at x10.visit.CodeCleanUp.leaveCall(CodeCleanUp.java:125)
at
polyglot.visit.ErrorHandlingVisitor.leave(ErrorHandlingVisitor.java:292)
at polyglot.visit.ContextVisitor.leave(ContextVisitor.java:151)
at
polyglot.visit.NodeVisitor.visitEdgeNoOverride(NodeVisitor.java:265)
at polyglot.visit.NodeVisitor.visitEdge(NodeVisitor.java:224)
at polyglot.ast.Node_c.visitChild(Node_c.java:186)
at polyglot.ast.Eval_c.visitChildren(Eval_c.java:64)
at polyglot.ast.JL_c.visitChildren(JL_c.java:52)
at x10.extension.X10Del_c.visitChildren(X10Del_c.java:143)
at
polyglot.visit.NodeVisitor.visitEdgeNoOverride(NodeVisitor.java:258)
at polyglot.visit.NodeVisitor.visitEdge(NodeVisitor.java:224)
at polyglot.ast.Node_c.visitChild(Node_c.java:186)
at polyglot.ast.Node_c.visitList(Node_c.java:246)
at
polyglot.ast.AbstractBlock_c.visitChildren(AbstractBlock_c.java:78)
at polyglot.ast.JL_c.visitChildren(JL_c.java:52)
at x10.extension.X10Del_c.visitChildren(X10Del_c.java:143)
at
polyglot.visit.NodeVisitor.visitEdgeNoOverride(NodeVisitor.java:258)
at polyglot.visit.NodeVisitor.visitEdge(NodeVisitor.java:224)
at polyglot.ast.Node_c.visitChild(Node_c.java:186)
at polyglot.ast.MethodDecl_c.visitChildren(MethodDecl_c.java:166)
at polyglot.ast.JL_c.visitChildren(JL_c.java:52)
at x10.extension.X10Del_c.visitChildren(X10Del_c.java:143)
at
polyglot.visit.NodeVisitor.visitEdgeNoOverride(NodeVisitor.java:258)
at polyglot.visit.NodeVisitor.visitEdge(NodeVisitor.java:224)
at polyglot.ast.Node_c.visitChild(Node_c.java:186)
at polyglot.ast.Node_c.visitList(Node_c.java:246)
at x10.ast.X10ClassBody_c.visitChildren(X10ClassBody_c.java:340)
at polyglot.ast.JL_c.visitChildren(JL_c.java:52)
at x10.extension.X10Del_c.visitChildren(X10Del_c.java:143)
at
polyglot.visit.NodeVisitor.visitEdgeNoOverride(NodeVisitor.java:258)
at polyglot.visit.NodeVisitor.visitEdge(NodeVisitor.java:224)
at polyglot.ast.Node_c.visitChild(Node_c.java:186)
at x10.ast.X10ClassDecl_c.visitChildren(X10ClassDecl_c.java:1651)
at polyglot.ast.JL_c.visitChildren(JL_c.java:52)
at x10.extension.X10Del_c.visitChildren(X10Del_c.java:143)
at
polyglot.visit.NodeVisitor.visitEdgeNoOverride(NodeVisitor.java:258)
at polyglot.visit.NodeVisitor.visitEdge(NodeVisitor.java:224)
at polyglot.ast.Node_c.visitChild(Node_c.java:186)
at polyglot.ast.Node_c.visitList(Node_c.java:246)
at polyglot.ast.SourceFile_c.visitChildren(SourceFile_c.java:124)
at polyglot.ast.JL_c.visitChildren(JL_c.java:52)
at x10.extension.X10Del_c.visitChildren(X10Del_c.java:143)
at
polyglot.visit.NodeVisitor.visitEdgeNoOverride(NodeVisitor.java:258)
at polyglot.visit.NodeVisitor.visitEdge(NodeVisitor.java:224)
at polyglot.ast.Node_c.visit(Node_c.java:190)
at polyglot.frontend.VisitorGoal.runTask(VisitorGoal.java:62)
at
x10.ExtensionInfo$X10Scheduler$ValidatingVisitorGoal.runTask(ExtensionInfo.java:1106)
at polyglot.frontend.Scheduler.runPass(Scheduler.java:372)
at x10.ExtensionInfo$X10Scheduler.runPass(ExtensionInfo.java:1250)
at polyglot.frontend.AbstractGoal_c.run(AbstractGoal_c.java:147)
at polyglot.types.LazyRef_c.get(LazyRef_c.java:70)
at polyglot.frontend.AbstractGoal_c.run(AbstractGoal_c.java:89)
at polyglot.types.LazyRef_c.get(LazyRef_c.java:70)
at polyglot.frontend.AbstractGoal_c.run(AbstractGoal_c.java:89)
at polyglot.types.LazyRef_c.get(LazyRef_c.java:70)
at polyglot.frontend.AbstractGoal_c.run(AbstractGoal_c.java:89)
at polyglot.types.LazyRef_c.get(LazyRef_c.java:70)
at polyglot.frontend.AbstractGoal_c.run(AbstractGoal_c.java:89)
at polyglot.types.LazyRef_c.get(LazyRef_c.java:70)
at polyglot.frontend.AbstractGoal_c.run(AbstractGoal_c.java:89)
at polyglot.types.LazyRef_c.get(LazyRef_c.java:70)
at polyglot.frontend.AbstractGoal_c.run(AbstractGoal_c.java:89)
at polyglot.types.LazyRef_c.get(LazyRef_c.java:70)
at polyglot.frontend.AbstractGoal_c.run(AbstractGoal_c.java:89)
at polyglot.types.LazyRef_c.get(LazyRef_c.java:70)
at polyglot.frontend.AbstractGoal_c.run(AbstractGoal_c.java:89)
at polyglot.types.LazyRef_c.get(LazyRef_c.java:70)
at polyglot.frontend.AbstractGoal_c.run(AbstractGoal_c.java:89)
at polyglot.types.LazyRef_c.get(LazyRef_c.java:70)
at polyglot.frontend.AbstractGoal_c.run(AbstractGoal_c.java:89)
at polyglot.types.LazyRef_c.get(LazyRef_c.java:70)
at polyglot.frontend.AbstractGoal_c.run(AbstractGoal_c.java:89)
at polyglot.types.LazyRef_c.get(LazyRef_c.java:70)
at polyglot.frontend.AbstractGoal_c.run(AbstractGoal_c.java:89)
at polyglot.types.LazyRef_c.get(LazyRef_c.java:70)
at polyglot.frontend.Scheduler.attempt(Scheduler.java:272)
at polyglot.frontend.Scheduler.runToCompletion(Scheduler.java:206)
at polyglot.frontend.Scheduler.runToCompletion(Scheduler.java:192)
at polyglot.frontend.Compiler.compile(Compiler.java:284)
at polyglot.frontend.Compiler.compileFiles(Compiler.java:244)
at polyglot.main.Main.start(Main.java:141)
at polyglot.main.Main.start(Main.java:82)
at polyglot.main.Main.main(Main.java:191)
My sample program is attached. Could someone point out, what is going
wrong here?
Cheers,
Marco
import x10.compiler.Volatile;
import x10.util.ArrayList;
import x10.util.Team;
import x10.xrx.Runtime;
public class ResilientHelloWorld {
public static val instance:Rail[ResilientHelloWorld] = new
Rail[ResilientHelloWorld](1);
public static val DEFAULT_MESSAGE:String = "Hello, World!";
public static val START_ITERATION:Long = 0;
private var msg:String;
private var plh:PlaceLocalHandle[ResilientHelloWorld];
private var iteration:Long;
private var newPlaces:ArrayList[Place];
private var addStarted:Long;
public def this():ResilientHelloWorld {
this(DEFAULT_MESSAGE, START_ITERATION);
}
public def this(val msg:String):ResilientHelloWorld {
this(msg, START_ITERATION);
}
public def this(val iteration:Long):ResilientHelloWorld {
this(DEFAULT_MESSAGE, iteration);
}
public def this(val msg:String, val iteration:Long) {
this.msg = msg;
this.iteration = iteration;
this.newPlaces = null;
}
private final def setPlh(val plh:PlaceLocalHandle[ResilientHelloWorld]) {
this.plh = plh;
}
public final def printMessage():void {
Console.OUT.println( here + ": groupSize = " + Place.places().size() + "
in iteration "
+ iteration++ + ", message: " + msg);
}
public def run():void {
if (here.id() == 1 && iteration == 5) {
System.killHere();
}
printMessage();
var cont:Boolean = true;
while (true) {
val allPlaces:PlaceGroup = Place.places().filterDeadPlaces();
val next:Place = allPlaces.next(here);
if (here.id() < next.id()) {
val plh:PlaceLocalHandle[ResilientHelloWorld] = this.plh;
try {
at (next) async {
val instance:ResilientHelloWorld = plh();
if (null != instance) {
instance.run();
}
}
} catch (val e:DeadPlaceException) {
Console.OUT.println(here + ": " + e.place + " died.");
continue;
}
}
break;
}
}
public static def main(val args:Rail[String]):void {
System.registerPlaceAddedHandler((val p:Place) => {
Console.OUT.println(here + ": " + p + " was added.");
registerNewPlace(p);
});
System.registerPlaceRemovedHandler((val p:Place) => {
Console.OUT.println(here + ": " + p + " was removed.");
});
val plh:PlaceLocalHandle[ResilientHelloWorld] = makeInitialPlh();
while (plh().iteration < 100) {
try {
finish {
plh().run();
}
} catch (val e:CheckedThrowable) {
if (e instanceof MultipleExceptions) {
val deadPlaceExceptions:MultipleExceptions = (e as
MultipleExceptions).filterExceptionsOfType[DeadPlaceException](true);
if (null != deadPlaceExceptions) {
for (val ex:CheckedThrowable in deadPlaceExceptions.exceptions) {
Console.OUT.println("MAIN: " + (ex as DeadPlaceException).place +
" died.");
}
}
}
}
val waitStart:Long = System.currentTimeMillis();
var now:Long = -1;
var newPlaces:ArrayList[Place];
while ((now = System.currentTimeMillis()) - waitStart < 1000) {
if (((newPlaces = plh().newPlaces) != null) && (now - plh().addStarted
>= 5000)) {
plh().newPlaces = null;
updatePlh(newPlaces);
plh().addStarted = -1;
continue;
}
Runtime.probe();
}
}
}
public static final def
makeInitialPlh():PlaceLocalHandle[ResilientHelloWorld]{
assert (null == instance(0)):"Multiple calls to makeInitialPlh are not
permitted.";
val plh:PlaceLocalHandle[ResilientHelloWorld]
= PlaceLocalHandle.makeFlat[ResilientHelloWorld](Place.places()
, () => new
ResilientHelloWorld());
instance(0) = plh();
distributePlh(Place.places(), plh);
return (plh);
}
private static final def distributePlh(val group:PlaceGroup
, val
plh:PlaceLocalHandle[ResilientHelloWorld])
:void {
val plhSetter:() => void = () => { plh().setPlh(plh); };
Console.OUT.print("Broadcasting plh...");
group.broadcastFlat(plhSetter);
Console.OUT.println(" done!");
}
public static final def updatePlh(val newPlaces:Iterable[Place]) {
assert (null != instance(0)):"setPlh(...) must be called before calling
updatePlh().";
val plh:PlaceLocalHandle[ResilientHelloWorld] = instance(0).plh;
val iteration:Long = plh().iteration;
for (val p:Place in newPlaces) {
PlaceLocalHandle.addPlace[ResilientHelloWorld](plh, p, () => new
ResilientHelloWorld(iteration));
at (p) async { plh().plh = plh; }
}
}
public static final def registerNewPlace(val p:Place) {
val myInstance:ResilientHelloWorld = instance(0).plh();
val newPlaces:ArrayList[Place];
if (null == myInstance.newPlaces) {
newPlaces = new ArrayList[Place]();
myInstance.newPlaces = newPlaces;
myInstance.addStarted = System.currentTimeMillis();
} else /* if (null != myInstance.newPlaces) */ {
newPlaces = myInstance.newPlaces;
}
newPlaces.add(p);
Console.OUT.println("Place added. newPlaces = " + newPlaces);
}
}
------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity planning
reports.http://sdm.link/zohodev2dev
_______________________________________________
X10-users mailing list
X10-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/x10-users