to run Task.execute method outside of transaction
authorjihoonl <jihoonl>
Thu, 1 Oct 2009 18:52:56 +0000 (18:52 +0000)
committerjihoonl <jihoonl>
Thu, 1 Oct 2009 18:52:56 +0000 (18:52 +0000)
Robust/src/Analysis/Locality/LocalityAnalysis.java
Robust/src/IR/Flat/BuildCode.java
Robust/src/IR/TypeUtil.java

index 96040b536f3fe4b5ec56bc44be660a7c7772b56c..07cfb310ed58da97a5d28531cd2b61686b3799bc 100644 (file)
@@ -24,6 +24,7 @@ public class LocalityAnalysis {
   Hashtable<MethodDescriptor, Set<LocalityBinding>> methodtolb;
   private LocalityBinding lbmain;
   private LocalityBinding lbrun;
+  private LocalityBinding lbexecute;
 
   CallGraph callgraph;
   TypeUtil typeutil;
@@ -192,8 +193,10 @@ public class LocalityAnalysis {
     Stack<LocalityBinding> lbstack=new Stack<LocalityBinding>();
     lbstack.add(lbmain);
     lbstack.add(lbrun);
+    lbstack.add(lbexecute);
     lbset.add(lbmain);
     lbset.add(lbrun);
+    lbset.add(lbexecute);
     while(!lbstack.isEmpty()) {
       LocalityBinding lb=lbstack.pop();
       if (calldep.containsKey(lb)) {
@@ -693,6 +696,19 @@ public class LocalityAnalysis {
       methodtolb.put(lbrun.getMethod(), new HashSet<LocalityBinding>());
     methodtolb.get(lbrun.getMethod()).add(lbrun);
 
+    lbexecute = new LocalityBinding(typeutil.getExecute(), false);
+    lbexecute.setGlobalReturn(EITHER);
+    lbexecute.setGlobalThis(GLOBAL);
+    lbtovisit.add(lbexecute);
+    discovered.put(lbexecute, lbexecute);
+    if (!classtolb.containsKey(lbexecute.getMethod().getClassDesc()))
+      classtolb.put(lbexecute.getMethod().getClassDesc(), new HashSet<LocalityBinding>());
+    classtolb.get(lbexecute.getMethod().getClassDesc()).add(lbexecute);
+
+    if (!methodtolb.containsKey(lbexecute.getMethod()))
+      methodtolb.put(lbexecute.getMethod(), new HashSet<LocalityBinding>());
+    methodtolb.get(lbexecute.getMethod()).add(lbexecute);
+
     while(!lbtovisit.isEmpty()) {
       LocalityBinding lb=(LocalityBinding) lbtovisit.iterator().next();
       lbtovisit.remove(lb);
@@ -766,6 +782,7 @@ public class LocalityAnalysis {
        }
       }
       atomictable.put(fn, atomicstate);
+
       // Process this node
       switch(fn.kind()) {
       case FKind.FlatAtomicEnterNode:
@@ -871,6 +888,7 @@ public class LocalityAnalysis {
     MethodDescriptor nodemd=fc.getMethod();
     Set methodset=null;
     Set runmethodset=null;
+    Set executemethodset=null;
 
     if (nodemd.isStatic()||nodemd.getReturnType()==null) {
       methodset=new HashSet();
@@ -881,20 +899,44 @@ public class LocalityAnalysis {
       if (nodemd.getClassDesc().getSymbol().equals(TypeUtil.ThreadClass)&&
           nodemd.getSymbol().equals("start")&&!nodemd.getModifiers().isStatic()&&
           nodemd.numParameters()==1&&nodemd.getParamType(0).isInt()) {
-       assert(nodemd.getModifiers().isNative());
+       assert(nodemd.getModifiers().isNative());
 
-       MethodDescriptor runmd=null;
-       for(Iterator methodit=nodemd.getClassDesc().getMethodTable().getSet("run").iterator(); methodit.hasNext();) {
-         MethodDescriptor md=(MethodDescriptor) methodit.next();
-         if (md.numParameters()!=0||md.getModifiers().isStatic())
-           continue;
-         runmd=md;
-         break;
-       }
-       if (runmd!=null) {
-         runmethodset=callgraph.getMethods(runmd,fc.getThis().getType());
-         methodset.addAll(runmethodset);
-       } else throw new Error("Can't find run method");
+       MethodDescriptor runmd=null;
+
+        for(Iterator methodit=nodemd.getClassDesc().getMethodTable().getSet("run").iterator(); methodit.hasNext();) {
+         MethodDescriptor md=(MethodDescriptor) methodit.next();
+      
+          if (md.numParameters()!=0||md.getModifiers().isStatic())
+           continue;
+         runmd=md;
+         break;
+             }
+       if (runmd!=null) {
+         runmethodset=callgraph.getMethods(runmd,fc.getThis().getType());
+         methodset.addAll(runmethodset);
+       } else throw new Error("Can't find run method");
+      }
+    
+      if (nodemd.getClassDesc().getSymbol().equals(TypeUtil.TaskClass) &&
+          nodemd.getSymbol().equals("execution") && !nodemd.getModifiers().isStatic() &&
+          nodemd.numParameters() == 0) {
+        assert(nodemd.getModifiers().isNative());
+        
+        MethodDescriptor exemd = null;
+
+        for(Iterator methodit=nodemd.getClassDesc().getMethodTable().getSet("execute").iterator(); methodit.hasNext();) {
+          MethodDescriptor md = (MethodDescriptor) methodit.next();
+
+          if (md.numParameters() != 0 || md.getModifiers().isStatic())
+            continue;
+          exemd = md;
+          break;
+        }
+
+        if (exemd != null) {
+          executemethodset = callgraph.getMethods(exemd, fc.getThis().getType());
+          methodset.addAll(executemethodset);
+        } else throw new Error("Can't find execute method");
       }
     }
 
@@ -917,8 +959,9 @@ public class LocalityAnalysis {
       if (isnative&&isatomic) {
        System.out.println("Don't call native methods in atomic blocks!"+currlb.getMethod());
       }
-      if (runmethodset==null||!runmethodset.contains(md)) {
-       //Skip this part if it is a run method
+
+  if ((runmethodset==null||!runmethodset.contains(md)) &&( executemethodset == null || !executemethodset.contains(md))) {
+       //Skip this part if it is a run method or execute method
        for(int i=0; i<fc.numArgs(); i++) {
          TempDescriptor arg=fc.getArg(i);
          if(isnative&&(currtable.get(arg).equals(GLOBAL)||
@@ -934,15 +977,15 @@ public class LocalityAnalysis {
        if (thistype==null)
          thistype=EITHER;
 
-       if(runmethodset!=null&&runmethodset.contains(md)&&thistype.equals(LOCAL))
+       if(runmethodset!=null&&runmethodset.contains(md)&&thistype.equals(LOCAL) && executemethodset != null && executemethodset.contains(md))
          throw new Error("Starting thread on local object not allowed in context:\n"+currlb.getExplanation());
        if(isjoin&&thistype.equals(LOCAL))
          throw new Error("Joining thread on local object not allowed in context:\n"+currlb.getExplanation());
        if(thistype.equals(CONFLICT))
          throw new Error("Using type that can be either local or global in context:\n"+currlb.getExplanation());
-       if(runmethodset==null&&thistype.equals(GLOBAL)&&!isatomic && !isjoin)
+       if(runmethodset==null&&thistype.equals(GLOBAL)&&!isatomic && !isjoin && executemethodset == null)
          throw new Error("Using global object outside of transaction in context:\n"+currlb.getExplanation());
-       if (runmethodset==null&&isnative&&thistype.equals(GLOBAL) && !isjoin && !isObjectgetType && !isObjecthashCode)
+       if (runmethodset==null&&isnative&&thistype.equals(GLOBAL) && !isjoin && executemethodset == null && !isObjectgetType && !isObjecthashCode)
          throw new Error("Potential call to native method "+md+" on global objects:\n"+currlb.getExplanation());
        lb.setGlobalThis(thistype);
       }
index 8afb168e31dd753348b3340d152e662e49a0c915..31f3a482dac3dfbc9198ae1569179b28cd7c082e 100644 (file)
@@ -526,12 +526,18 @@ public class BuildCode {
      * numbers for various objects it needs */
     outstructs.println("#define MAXCOUNT "+maxcount);
     if (state.DSM||state.SINGLETM) {
-      LocalityBinding lb=new LocalityBinding(typeutil.getRun(), false);
-      if (state.DSM)
-       lb.setGlobalThis(LocalityAnalysis.GLOBAL);
-      else if (state.SINGLETM)
-       lb.setGlobalThis(LocalityAnalysis.NORMAL);
-      outstructs.println("#define RUNMETHOD "+virtualcalls.getLocalityNumber(lb));
+      LocalityBinding lbrun=new LocalityBinding(typeutil.getRun(), false);
+      LocalityBinding lbexecute = new LocalityBinding(typeutil.getExecute(), false);
+      if (state.DSM) {
+       lbrun.setGlobalThis(LocalityAnalysis.GLOBAL);
+  lbexecute.setGlobalThis(LocalityAnalysis.GLOBAL);
+      }
+      else if (state.SINGLETM) {
+       lbrun.setGlobalThis(LocalityAnalysis.NORMAL);
+  lbexecute.setGlobalThis(LocalityAnalysis.NORMAL);
+      }
+      outstructs.println("#define EXECUTEMETHOD " + virtualcalls.getLocalityNumber(lbexecute));
+      outstructs.println("#define RUNMETHOD "+virtualcalls.getLocalityNumber(lbrun));
     }
 
     outstructs.println("#define STRINGARRAYTYPE "+
index df0a163e32a299fdf9fc7505938fece1e85fbc95..ce0ead6fe2060017d3627412b23612b1b7a99166 100644 (file)
@@ -10,6 +10,7 @@ public class TypeUtil {
   public static final String StartupClass="StartupObject";
   public static final String TagClass="TagDescriptor";
   public static final String ThreadClass="Thread";
+  public static final String TaskClass="Task";
   State state;
   Hashtable supertable;
   Hashtable subclasstable;
@@ -82,6 +83,18 @@ public class TypeUtil {
     }
     throw new Error("Can't find Thread.run");
   }
+  
+  public MethodDescriptor getExecute() {
+    ClassDescriptor cd = getClass(TypeUtil.TaskClass);
+    for(Iterator methodit = cd.getMethodTable().getSet("execute").iterator(); methodit.hasNext();) {
+      MethodDescriptor md = (MethodDescriptor) methodit.next();
+      if (md.numParameters()!=0 || md.getModifiers().isStatic())
+        continue;
+      return md;
+    }
+    throw new Error("Can't find Task.execute");
+  }
+
 
   public MethodDescriptor getMain() {
     ClassDescriptor cd=getMainClass();