From: <ta...@us...> - 2008-11-07 02:22:15
|
Revision: 6679 http://x10.svn.sourceforge.net/x10/?rev=6679&view=rev Author: tardieu Date: 2008-11-07 01:35:42 +0000 (Fri, 07 Nov 2008) Log Message: ----------- revised x10 app startup code Modified Paths: -------------- trunk/x10.compiler.p3/data/Main.xcd trunk/x10.dist/bin/x10.in trunk/x10.runtime.17/src-java/x10/runtime/impl/java/Runtime.java trunk/x10.runtime.17/src-java/x10/runtime/impl/java/Thread.java trunk/x10.runtime.17/src-x10/x10/lang/Place.x10 trunk/x10.runtime.17/src-x10/x10/runtime/Pool.x10 trunk/x10.runtime.17/src-x10/x10/runtime/Runtime.x10 trunk/x10.runtime.17/src-x10/x10/runtime/kernel/Thread.x10 Removed Paths: ------------- trunk/x10.runtime.17/src-java/x10/runtime/impl/java/NativeHashMap.java trunk/x10.runtime.17/src-java/x10/runtime/impl/java/NativeStack.java Modified: trunk/x10.compiler.p3/data/Main.xcd =================================================================== --- trunk/x10.compiler.p3/data/Main.xcd 2008-11-06 22:53:56 UTC (rev 6678) +++ trunk/x10.compiler.p3/data/Main.xcd 2008-11-07 01:35:42 UTC (rev 6679) @@ -1,36 +1,24 @@ // SYNOPSIS: main(#0) #1 -public static class Main implements java.lang.Runnable { - private final x10.core.Rail<java.lang.String> rail; - - public Main(java.lang.String[] args) { - rail = x10.core.RailFactory.<java.lang.String>makeRailFromJavaArray(args); - } +public static void main(final java.lang.String[] args) { - public void run() { - // initialize places and attach current thread to first place - x10.runtime.impl.java.Thread.currentThread().place(x10.lang.Place.FIRST_PLACE); + // create places; start native runtime; start main x10 thread + x10.runtime.impl.java.Runtime.start(x10.lang.Place.FIRST_PLACE, new java.lang.Runnable() { + public void run() { - // run main activity - x10.runtime.Runtime.runMain(new x10.runtime.Activity() { - public void runX10Task() { - main(rail); - } - }); - } + // start XRX in main x10 thread + x10.runtime.Runtime.start(new x10.runtime.Activity() { + public void runX10Task() { + + // run main + main(x10.core.RailFactory.<java.lang.String>makeRailFromJavaArray(args)); + } + }); + } + }); } -public static void main(java.lang.String[] args) { - java.lang.System.err.println("Please use the 'x10' script to invoke X10 programs, or see the generated"); - java.lang.System.err.println("Java code for alternate invocation instructions."); - java.lang.System.exit(128); -} - // the original app-main method public static void main(#0) { #1 } - -// How to invoke? Use the following general command: -// java $(javaArgs) x10.runtime.impl.java.Runtime $(x10Args) ClassName $(x10AppArgs) - Modified: trunk/x10.dist/bin/x10.in =================================================================== --- trunk/x10.dist/bin/x10.in 2008-11-06 22:53:56 UTC (rev 6678) +++ trunk/x10.dist/bin/x10.in 2008-11-07 01:35:42 UTC (rev 6679) @@ -9,13 +9,7 @@ java_args="" args="" -parse=true while [ -n "$1" ]; do - if [ -z "$parse" ]; then - args="$args '$1'" - shift - continue - fi case "$1" in -h|-help|--help) help="1"; break;; -v|-verbose|--verbose) verbose="1";; @@ -32,8 +26,9 @@ -config) shift; config="$1.cfg";; -dev) dev="true";; -J*) java_args="${java_args} '${1##-J}'";; - --) parse=;; - *) args="$args '$1'";; + -*) java_args="${java_args} -Dx10.${1##-}";; + *.x10) args="$args ${1%%.x10}";; + *) args="$args $*"; break;; esac shift done @@ -49,12 +44,10 @@ -D<name>=<value> set system property <name> to <value> -classpath <path> search path for class files -libpath <path> search path for native libraries - -config <conf> read configuration <conf> from etc${FILE_SEP}<conf>.cfg + -config <conf> (IGNORED) read configuration from etc${FILE_SEP}<conf>.cfg -dev developer mode (use unpackaged X10 libraries) -J<arg> [USE WITH CAUTION] pass <arg> directly to java. e.g., use -J-verbose to make java execution verbose. - - Use "x10 -- -help" to get help on X10 runtime configuration options EOF exit 1 fi @@ -85,7 +78,7 @@ fi java_args="${java_args} ${defs}" -command="\"$JAVA\" $java_args $config x10.runtime.impl.java.Runtime $args" +command="\"$JAVA\" $java_args $config $args" [ -n "$verbose" ] && echo "$command" Deleted: trunk/x10.runtime.17/src-java/x10/runtime/impl/java/NativeHashMap.java =================================================================== --- trunk/x10.runtime.17/src-java/x10/runtime/impl/java/NativeHashMap.java 2008-11-06 22:53:56 UTC (rev 6678) +++ trunk/x10.runtime.17/src-java/x10/runtime/impl/java/NativeHashMap.java 2008-11-07 01:35:42 UTC (rev 6679) @@ -1,13 +0,0 @@ -/* - * - * (C) Copyright IBM Corporation 2006-2008 - * - * This file is part of X10 Language. - * - */ -package x10.runtime.impl.java; - -public class NativeHashMap<K,V> extends java.util.HashMap<K,V> { - // HACK discard type parameters - public NativeHashMap(Object typeK, Object typeV) { super(); } -} Deleted: trunk/x10.runtime.17/src-java/x10/runtime/impl/java/NativeStack.java =================================================================== --- trunk/x10.runtime.17/src-java/x10/runtime/impl/java/NativeStack.java 2008-11-06 22:53:56 UTC (rev 6678) +++ trunk/x10.runtime.17/src-java/x10/runtime/impl/java/NativeStack.java 2008-11-07 01:35:42 UTC (rev 6679) @@ -1,13 +0,0 @@ -/* - * - * (C) Copyright IBM Corporation 2006-2008 - * - * This file is part of X10 Language. - * - */ -package x10.runtime.impl.java; - -public class NativeStack<T> extends java.util.Stack<T> { - // HACK discard type parameter - public NativeStack(Object typeT) { super(); } -} Modified: trunk/x10.runtime.17/src-java/x10/runtime/impl/java/Runtime.java =================================================================== --- trunk/x10.runtime.17/src-java/x10/runtime/impl/java/Runtime.java 2008-11-06 22:53:56 UTC (rev 6678) +++ trunk/x10.runtime.17/src-java/x10/runtime/impl/java/Runtime.java 2008-11-07 01:35:42 UTC (rev 6679) @@ -7,78 +7,38 @@ */ package x10.runtime.impl.java; -import java.lang.reflect.Constructor; - -import x10.config.ConfigurationError; -import x10.runtime.util.ShowUsageNotification; - public class Runtime { - public static void main(String[] args) { - if (args.length == 0) { - System.err.println("usage: java x10.runtime.Runtime MainClass [args]"); - System.exit(1); - } - try { - String[] strippedArgs = Configuration.parseCommandLine(args); - loadAndInitLibs(); - run(strippedArgs); - } catch (ShowUsageNotification e) { - Usage.usage(System.out, null); - } catch (ConfigurationError e) { - Usage.usage(System.err, e); - } - } - /** - * Load and init shared library + * Execute main x10 thread */ - private static void loadAndInitLibs() { - if (null != Configuration.LOAD) { - String[] libs = Configuration.LOAD.split(":"); - for (int i=libs.length-1; i>=0; i--) System.loadLibrary(libs[i]); + public static void start(final Object place, final Runnable runnable) { + // load libraries + String property = System.getProperty("x10.LOAD"); + if (null != property) { + String[] libs = property.split(":"); + for (int i = libs.length-1; i>=0; i--) System.loadLibrary(libs[i]); } - } - public static final int MAX_PLACES = Configuration.NUMBER_OF_LOCAL_PLACES; - - public static final int INIT_THREADS_PER_PLACE = Configuration.INIT_THREADS_PER_PLACE; - - private static int exitCode = 0; - - private static final Class[] STRING_ARRAYS = new Class[] { String[].class }; - - /** - * Instantiate and run main activity - */ - private static void run(String[] strippedArgs) { - // instantiation using reflection - Runnable r; - try { - java.lang.Object[] args = { strippedArgs }; - Class main = Class.forName(Configuration.MAIN_CLASS_NAME + "$Main"); - Constructor ctor = main.getDeclaredConstructor(STRING_ARRAYS); - r = (Runnable) ctor.newInstance(args); - if (Configuration.PRELOAD_CLASSES) { - PreLoader.preLoad(main, Configuration.PRELOAD_STRINGS); + Runnable r = new Runnable() { + public void run() { + // preload classes + if (Boolean.getBoolean("x10.PRELOAD_CLASSES")) { + PreLoader.preLoad(runnable.getClass().getEnclosingClass(), + Boolean.getBoolean("x10.PRELOAD_STRINGS")); + } + // execute thread body + runnable.run(); } - } catch (ClassNotFoundException e) { - System.err.println("Could not find main class '" - + Configuration.MAIN_CLASS_NAME + "$Main" + "'!"); - throw new Error(e); - } catch (Exception e) { - System.err.println("Could not find constructor of main class '" - + Configuration.MAIN_CLASS_NAME + "$Main" + "'!"); - throw new Error(e); - } - // run the main activity in its own thread - Thread t = new Thread(r, "main"); - t.start(); - try { t.join(); } catch (InterruptedException e) {} - + }; + Thread thread = new Thread(place, r, "thread-main"); + thread.start(); + try { thread.join(); } catch (InterruptedException e) {} System.exit(exitCode); } + private static int exitCode = 0; + public static void setExitCode(int code) { exitCode = code; } Modified: trunk/x10.runtime.17/src-java/x10/runtime/impl/java/Thread.java =================================================================== --- trunk/x10.runtime.17/src-java/x10/runtime/impl/java/Thread.java 2008-11-06 22:53:56 UTC (rev 6678) +++ trunk/x10.runtime.17/src-java/x10/runtime/impl/java/Thread.java 2008-11-07 01:35:42 UTC (rev 6679) @@ -21,14 +21,11 @@ private Object place; // the current place private Object activity; // the current activity - public Thread(Runnable r) { - super(r); + public Thread(Object place, Runnable runnable, String name) { + super(runnable, name); + this.place = place; } - public Thread(Runnable r, String name) { - super(r, name); - } - public void activity(Object activity) { this.activity = activity; } Modified: trunk/x10.runtime.17/src-x10/x10/lang/Place.x10 =================================================================== --- trunk/x10.runtime.17/src-x10/x10/lang/Place.x10 2008-11-06 22:53:56 UTC (rev 6678) +++ trunk/x10.runtime.17/src-x10/x10/lang/Place.x10 2008-11-07 01:35:42 UTC (rev 6679) @@ -14,7 +14,7 @@ * @author tardieu */ public final value Place(id: nat) { - public const MAX_PLACES = x10.runtime.kernel.Runtime.MAX_PLACES; + public const MAX_PLACES = Int.getInteger("x10.NUMBER_OF_LOCAL_PLACES", 4); public const places = Rail.makeVal[Place](MAX_PLACES, ((id: nat) => new Place(id))); public const FIRST_PLACE = place(0); Modified: trunk/x10.runtime.17/src-x10/x10/runtime/Pool.x10 =================================================================== --- trunk/x10.runtime.17/src-x10/x10/runtime/Pool.x10 2008-11-06 22:53:56 UTC (rev 6678) +++ trunk/x10.runtime.17/src-x10/x10/runtime/Pool.x10 2008-11-07 01:35:42 UTC (rev 6679) @@ -31,7 +31,7 @@ /** * Pool size */ - private var size: int; + private var count: int; /** * Number of blocked activities in the pool @@ -39,11 +39,11 @@ private var busy: int = 0; /** - * Start nb threads + * Start count threads */ - def this(nb: nat) { - size = nb; - for(var i: int = 0; i<nb; i++) allocate(); + def this(count: nat) { + this.count = count; + for(var i: int = 0; i<count; i++) allocate(i); } /** @@ -76,13 +76,8 @@ /** * Start a new thread */ - def allocate(): void { - val thread = new Thread(new Worker(this)); - - // must attach the thread to a place here! - thread.place(Place.FIRST_PLACE); - - thread.start(); + def allocate(id: int): void { + new Thread(Place.FIRST_PLACE, new Worker(this), "thread-" + id.toString()).start(); } /** @@ -90,12 +85,7 @@ */ def increase(): void { monitor.lock(); - if (++busy >= size) { - - // enlarge pool - size++; - allocate(); - } + if (++busy >= count) allocate(count++); monitor.unlock(); } Modified: trunk/x10.runtime.17/src-x10/x10/runtime/Runtime.x10 =================================================================== --- trunk/x10.runtime.17/src-x10/x10/runtime/Runtime.x10 2008-11-06 22:53:56 UTC (rev 6678) +++ trunk/x10.runtime.17/src-x10/x10/runtime/Runtime.x10 2008-11-07 01:35:42 UTC (rev 6679) @@ -29,7 +29,7 @@ /** * The common thread pool */ - private const pool = new Pool(x10.runtime.kernel.Runtime.INIT_THREADS_PER_PLACE); + private const pool = new Pool(Int.getInteger("x10.INIT_THREADS_PER_PLACE", 3)); /** * Notify the thread pool that one activity is about to block @@ -69,15 +69,12 @@ /** * Run the main activity in a finish */ - public static def runMain(activity: Activity): void { - try { - val state = new FinishState(); - activity.finishState(state); - pool.execute(new Job(activity, Place.FIRST_PLACE)); - state.waitForFinish(); - } catch (t: Throwable) { - t.printStackTrace(); - } + public static def start(activity: Activity): void { + Thread.currentThread().activity(activity); + val state = new FinishState(); + activity.finishState(state); + activity.run(); + state.waitForFinish(); } /** Modified: trunk/x10.runtime.17/src-x10/x10/runtime/kernel/Thread.x10 =================================================================== --- trunk/x10.runtime.17/src-x10/x10/runtime/kernel/Thread.x10 2008-11-06 22:53:56 UTC (rev 6678) +++ trunk/x10.runtime.17/src-x10/x10/runtime/kernel/Thread.x10 2008-11-07 01:35:42 UTC (rev 6679) @@ -28,10 +28,8 @@ @NativeRep("java", "x10.runtime.impl.java.Thread", null, null) public class Thread { - public native def this(task:Runnable):Thread; + public native def this(place:Object, runnable:Runnable, name:String):Thread; - public native def this(task:Runnable, name:String):Thread; - @Native("java", "#0.currentThread()") public static native def currentThread():Thread; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |