SF.net SVN: jikesrvm:[15741] rvmroot/trunk/MMTk/harness

View: New views
1 Messages — Rating Filter:   Alert me  

SF.net SVN: jikesrvm:[15741] rvmroot/trunk/MMTk/harness

by rgarner :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Revision: 15741
          http://jikesrvm.svn.sourceforge.net/jikesrvm/?rev=15741&view=rev
Author:   rgarner
Date:     2009-07-23 07:29:14 +0000 (Thu, 23 Jul 2009)

Log Message:
-----------
Add support for synchronization barriers in the scripting language

Modified Paths:
--------------
    rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/lang/Intrinsics.java
    rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/lang/parser/GlobalDefs.java
    rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/scheduler/Scheduler.java
    rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/scheduler/ThreadModel.java
    rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/scheduler/javathreads/JavaThreadModel.java
    rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/scheduler/javathreads/Rendezvous.java
    rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/scheduler/rawthreads/RawThreadModel.java

Added Paths:
-----------
    rvmroot/trunk/MMTk/harness/test-scripts/lang/barriers.script

Modified: rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/lang/Intrinsics.java
===================================================================
--- rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/lang/Intrinsics.java 2009-07-23 07:27:01 UTC (rev 15740)
+++ rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/lang/Intrinsics.java 2009-07-23 07:29:14 UTC (rev 15741)
@@ -18,6 +18,7 @@
 import org.mmtk.harness.lang.runtime.PhantomReferenceValue;
 import org.mmtk.harness.lang.runtime.SoftReferenceValue;
 import org.mmtk.harness.lang.runtime.WeakReferenceValue;
+import org.mmtk.harness.scheduler.Scheduler;
 import org.mmtk.vm.Collection;
 import org.mmtk.vm.VM;
 
@@ -163,4 +164,15 @@
       System.err.println("Error processing option "+option);
     }
   }
+
+  /**
+   * A synchronization barrier for script-language threads
+   * @param env
+   * @param name
+   * @param threadCount
+   * @return
+   */
+  public static int barrierWait(Env env, String name, int threadCount) {
+    return Scheduler.mutatorRendezvous(name, threadCount);
+  }
 }

Modified: rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/lang/parser/GlobalDefs.java
===================================================================
--- rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/lang/parser/GlobalDefs.java 2009-07-23 07:27:01 UTC (rev 15740)
+++ rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/lang/parser/GlobalDefs.java 2009-07-23 07:29:14 UTC (rev 15741)
@@ -57,7 +57,9 @@
           new Class<?>[] { ObjectValue.class }),
       new IntrinsicMethod("getPhantomReferent",intrinsics,"getReferent",
           new Class<?>[] { PhantomReferenceValue.class }),
-      new IntrinsicMethod("setOption",intrinsics,"setOption", new Class[] { String.class })
+      new IntrinsicMethod("setOption",intrinsics,"setOption", new Class[] { String.class }),
+      new IntrinsicMethod("barrierWait",intrinsics,"barrierWait",
+          new Class[] { String.class, int.class })
 
   );
 }

Modified: rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/scheduler/Scheduler.java
===================================================================
--- rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/scheduler/Scheduler.java 2009-07-23 07:27:01 UTC (rev 15740)
+++ rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/scheduler/Scheduler.java 2009-07-23 07:29:14 UTC (rev 15741)
@@ -233,6 +233,10 @@
     return model.rendezvous(where);
   }
 
+  public static int mutatorRendezvous(String name, int expected) {
+    return model.mutatorRendezvous(name,expected);
+  }
+
   /**
    * Cause the current thread to wait for a triggered GC to proceed.
    */

Modified: rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/scheduler/ThreadModel.java
===================================================================
--- rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/scheduler/ThreadModel.java 2009-07-23 07:27:01 UTC (rev 15740)
+++ rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/scheduler/ThreadModel.java 2009-07-23 07:29:14 UTC (rev 15741)
@@ -61,6 +61,8 @@
 
   public abstract int rendezvous(int where);
 
+  public abstract int mutatorRendezvous(String where, int expected);
+
   public abstract Collector currentCollector();
 
   public abstract void waitForGC();

Modified: rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/scheduler/javathreads/JavaThreadModel.java
===================================================================
--- rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/scheduler/javathreads/JavaThreadModel.java 2009-07-23 07:27:01 UTC (rev 15740)
+++ rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/scheduler/javathreads/JavaThreadModel.java 2009-07-23 07:29:14 UTC (rev 15741)
@@ -25,6 +25,7 @@
 import org.mmtk.harness.scheduler.ThreadModel;
 import static org.mmtk.harness.scheduler.ThreadModel.State.*;
 import org.mmtk.utility.Log;
+import org.mmtk.vm.VM;
 
 public final class JavaThreadModel extends ThreadModel {
   static {
@@ -269,10 +270,15 @@
 
   @Override
   public int rendezvous(int where) {
-    return Rendezvous.rendezvous(where);
+    return Rendezvous.rendezvous(Integer.toString(where),VM.activePlan.collectorCount());
   }
 
   @Override
+  public int mutatorRendezvous(String where, int expected) {
+    return Rendezvous.rendezvous(where,expected);
+  }
+
+  @Override
   public Collector currentCollector() {
     return collectorThreadLocal.get();
   }

Modified: rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/scheduler/javathreads/Rendezvous.java
===================================================================
--- rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/scheduler/javathreads/Rendezvous.java 2009-07-23 07:27:01 UTC (rev 15740)
+++ rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/scheduler/javathreads/Rendezvous.java 2009-07-23 07:29:14 UTC (rev 15741)
@@ -12,6 +12,11 @@
  */
 package org.mmtk.harness.scheduler.javathreads;
 
+import java.util.HashMap;
+import java.util.Map;
+
+import org.mmtk.vm.VM;
+
 /**
  * Rendezvous of all collector threads in the Java threading model.
  *
@@ -29,59 +34,70 @@
    * (if any) has reached its quota, and the next thread to arrive will start
    * a new rendezvous.
    */
-  private static Rendezvous current = null;
+  //private static Rendezvous current = null;
+  private static final Map<String,Rendezvous> current = new HashMap<String,Rendezvous>();
 
   /**
    * Return the current rendezvous, creating a new one if required.
    * @param where
    * @return
    */
-  private static synchronized Rendezvous current(int where) {
-    if (current == null) {
-      current = new Rendezvous(where);
+  private static synchronized Rendezvous current(String where, int expected) {
+    Rendezvous cur = current.get(where);
+    if (cur == null) {
+      cur = new Rendezvous(where,expected);
+      current.put(where, cur);
     } else {
-      if (where != current.where) {
+      if (!where.equals(cur.where)) {
         /* Logic error - this should never happen */
-        throw new RuntimeException(String.format("Arriving at barrier %d when %d is active",
-            where,current.where));
+        throw new RuntimeException(String.format("Arriving at barrier %d when %s is active",
+            where,cur.where));
       }
+      assert expected == cur.expected :
+        "At barrier "+where+", expected="+expected+", but existing barrier expects "+cur.expected;
     }
-    return current;
+    return cur;
   }
 
   /**
    * Clear the <code>current</code> field atomically.
+   * @param where TODO
    */
-  private static synchronized void clearCurrent() {
-    current = null;
+  private static synchronized void clearCurrent(String where) {
+    current.put(where,null);
   }
 
   /**
    * Create a new rendezvous with the given identifier
    * @param where The rendezvous identifier
    */
-  private Rendezvous(int where) {
+  private Rendezvous(String where, int expected) {
     this.where = where;
+    this.expected = expected;
   }
 
   /** The rendezvous identifier */
-  private final int where;
+  private final String where;
 
   /** The rank that was given to the last thread to arrive at the rendezvous */
   private int currentRank = 0;
 
+  /** The expected number of threads */
+  private final int expected;
+
   /**
    * Rendezvous with all other processors, returning the rank
    * (that is, the order this processor arrived at the barrier).
+   * @param expected TODO
    */
   private synchronized int rendezvous() {
     int rank = ++currentRank;
-    if (currentRank == org.mmtk.vm.VM.activePlan.collectorCount()) {
+    if (currentRank == expected) {
       /* This is no longer the current barrier */
-      clearCurrent();
+      clearCurrent(where);
       notifyAll();
     } else {
-      while (currentRank != org.mmtk.vm.VM.activePlan.collectorCount()) {
+      while (currentRank != expected) {
         try {
           /* Wait for the remaining collectors to arrive */
           wait();
@@ -93,11 +109,20 @@
   }
 
   /**
-   * Dispatch to the current rendezvous object
+   * Dispatch to the current collector rendezvous object
    * @param where
    * @return
    */
-  static int rendezvous(int where) {
-    return current(where).rendezvous();
+  static int rendezvous(String where) {
+    return current(where,VM.activePlan.collectorCount()).rendezvous();
   }
+
+  /**
+   * Dispatch to the named mutator rendezvous object
+   * @param where
+   * @return
+   */
+  static int rendezvous(String where, int expected) {
+    return current("Barrier-"+where,expected).rendezvous();
+  }
 }

Modified: rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/scheduler/rawthreads/RawThreadModel.java
===================================================================
--- rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/scheduler/rawthreads/RawThreadModel.java 2009-07-23 07:27:01 UTC (rev 15740)
+++ rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/scheduler/rawthreads/RawThreadModel.java 2009-07-23 07:29:14 UTC (rev 15741)
@@ -13,8 +13,10 @@
 package org.mmtk.harness.scheduler.rawthreads;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Map;
 
 import org.mmtk.harness.Collector;
 import org.mmtk.harness.Mutator;
@@ -174,7 +176,32 @@
     return current.getOrdinal();
   }
 
+
+  private final Map<String,List<RawThread>> rendezvousQueues = new HashMap<String,List<RawThread>>();
+
   /**
+   * @see org.mmtk.harness.scheduler.ThreadModel#mutatorRendezvous(java.lang.String, int)
+   */
+  @Override
+  public int mutatorRendezvous(String where, int expected) {
+    Trace.trace(Item.SCHEDULER, "%s: rendezvous(%d)", current.getId(), where);
+    List<RawThread> queue = rendezvousQueues.get("Barrier-"+where);
+    if (queue == null) {
+      queue = new ArrayList<RawThread>(expected);
+      rendezvousQueues.put("Barrier-"+where, queue);
+    }
+    current.setOrdinal(queue.size()+1);
+    if (queue.size() == expected-1) {
+      makeRunnable(queue,false);
+      rendezvousQueues.put("Barrier-"+where, null);
+    } else {
+      yield(queue);
+    }
+    Trace.trace(Item.SCHEDULER, "%d: rendezvous(%d) complete: ordinal = %d", current.getId(), where,current.getOrdinal());
+    return current.getOrdinal();
+  }
+
+  /**
    * Create a collector thread
    */
   @Override

Added: rvmroot/trunk/MMTk/harness/test-scripts/lang/barriers.script
===================================================================
--- rvmroot/trunk/MMTk/harness/test-scripts/lang/barriers.script                        (rev 0)
+++ rvmroot/trunk/MMTk/harness/test-scripts/lang/barriers.script 2009-07-23 07:29:14 UTC (rev 15741)
@@ -0,0 +1,33 @@
+/*
+ *  This file is part of the Jikes RVM project (http://jikesrvm.org).
+ *
+ *  This file is licensed to You under the Eclipse Public License (EPL);
+ *  You may not use this file except in compliance with the License. You
+ *  may obtain a copy of the License at
+ *
+ *      http://www.opensource.org/licenses/eclipse-1.0.php
+ *
+ *  See the COPYRIGHT.txt file distributed with this work for information
+ *  regarding copyright ownership.
+ */
+
+/*
+ * Test synchronization barriers
+ */
+void main() {
+  spawn(thread);
+  spawn(thread);
+  barrierWait("finish",3);
+  print("Exit");
+}
+
+
+void thread() {
+  barrierWait("begin",2);
+  print("Reached barrier <begin>");
+  int ordinal = barrierWait("end",2);
+  if (ordinal == 1) {
+    print("First thread");
+  }
+  barrierWait("finish",3);
+}
\ No newline at end of file


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.

------------------------------------------------------------------------------
_______________________________________________
Jikesrvm-commits mailing list
Jikesrvm-commits@...
https://lists.sourceforge.net/lists/listinfo/jikesrvm-commits