changes
authorPeizhao Ou <peizhaoo@uci.edu>
Fri, 16 Jan 2015 22:27:41 +0000 (14:27 -0800)
committerPeizhao Ou <peizhaoo@uci.edu>
Fri, 16 Jan 2015 22:27:41 +0000 (14:27 -0800)
benchmark/chase-lev-deque-bugfix/deque.h
benchmark/mpmc-queue/mpmc-queue.h
benchmark/ms-queue/my_queue.h
grammer/spec_compiler.jj
src/edu/uci/eecs/specCompiler/codeGenerator/CodeGenerator.java
src/edu/uci/eecs/specCompiler/codeGenerator/CodeVariables.java
src/edu/uci/eecs/specCompiler/specExtraction/SequentialDefineSubConstruct.java

index 7d2df9f..f188a8f 100644 (file)
@@ -36,8 +36,13 @@ typedef struct {
         spec_list *__deque;
         id_tag_t *tag;
         @InitVar:
-            __deque= new_spec_list();
+            __deque = new_spec_list();
             tag = new_id_tag(); // Beginning of available id
+               @Cleanup:
+                       if (__deque)
+                               free_spec_list(__deque);
+                       if (tag)
+                               free_id_tag();
         @DefineFunc:
             tag_elem_t* new_tag_elem(call_id_t id, int data) {
                 tag_elem_t *e = (tag_elem_t*) CMODEL_MALLOC(sizeof(tag_elem_t));
index 1b737bd..6f1bac6 100644 (file)
@@ -62,6 +62,9 @@ public:
                @InitVar:
                        list = new_spec_list();
                        //tag = new_id_tag();
+               @Cleanup:
+                       if (list)
+                               free_spec_list();
        @Happens_before:
                Publish -> Fetch
                Consume -> Prepare
index 6618a52..ce87b1d 100644 (file)
@@ -54,6 +54,11 @@ void init_queue(queue_t *q, int num_threads);
                @InitVar:
                        __queue = new_spec_list();
                        tag = new_id_tag(); // Beginning of available id
+               @Cleanup:
+                       if (__queue)
+                               free_spec_list(__queue);
+                       if (tag)
+                               free_id_tag(tag);
                @DefineFunc:
                        tag_elem_t* new_tag_elem(call_id_t id, unsigned int data) {
                                tag_elem_t *e = (tag_elem_t*) CMODEL_MALLOC(sizeof(tag_elem_t));
index 575dcf3..305eabf 100644 (file)
@@ -366,6 +366,8 @@ SKIP : {
        <DECLARE_VAR: "@DeclareVar:">
 |
        <INIT_VAR: "@InitVar:">
+|
+       <CLEANUP: "@Cleanup:">
 |
        <DEFINE_FUNC: "@DefineFunc:">
 |
@@ -984,7 +986,7 @@ GlobalConstruct Global_construct() :
 
 SequentialDefineSubConstruct Global_define() :
 {
-       ArrayList<String> initVar, defineFunc, code, declareStruct;
+       ArrayList<String> initVar, cleanup, defineFunc, code, declareStruct;
        ArrayList<ArrayList<String>> defineFuncs;
        ArrayList<VariableDeclaration> declareVars;
        ArrayList<ArrayList<String>> declareStructs;
@@ -994,7 +996,8 @@ SequentialDefineSubConstruct Global_define() :
 {
        {
                declareVars = new ArrayList<VariableDeclaration>();
-               initVar = null;
+               initVar = new ArrayList<String>();
+               cleanup = new ArrayList<String>();
                defineFuncs = new ArrayList<ArrayList<String>>();
                declareStructs = new ArrayList<ArrayList<String>>();
        }
@@ -1004,10 +1007,11 @@ SequentialDefineSubConstruct Global_define() :
                (<DECLARE_VAR> ((declareVar = TypeParam() <SEMI_COLON> {
                        declareVars.add(declareVar); } )*))?
        (<INIT_VAR> (code = C_CPP_CODE(null) { initVar = code; } ))?
+       (<CLEANUP> (code = C_CPP_CODE(null) { cleanup = code; } ))?
        (<DEFINE_FUNC> (defineFunc = C_CPP_CODE(null) { defineFuncs.add(defineFunc); }))*
        {
                SequentialDefineSubConstruct res = new
-                       SequentialDefineSubConstruct(declareStructs, declareVars, initVar, defineFuncs);
+                       SequentialDefineSubConstruct(declareStructs, declareVars, initVar, cleanup, defineFuncs);
                //System.out.println(res);
                return res;
        }
index 7ebc101..49299d1 100644 (file)
@@ -328,7 +328,7 @@ public class CodeGenerator {
 //             File[][] sources = { srcLinuxRWLocks,  srcMSQueue, srcRCU,
 //                             srcDeque, srcMCSLock, srcSPSCQueue, srcMPMCQueue, srcHashtable };
 
-                File[][] sources = {srcDeque };
+                File[][] sources = {srcMSQueue };
                // Compile all the benchmarks
                for (int i = 0; i < sources.length; i++) {
                        CodeGenerator gen = new CodeGenerator(sources[i]);
index cdc8771..999221b 100644 (file)
@@ -21,9 +21,12 @@ import edu.uci.eecs.specCompiler.specExtraction.SequentialDefineSubConstruct;
 import edu.uci.eecs.specCompiler.specExtraction.VariableDeclaration;
 
 /**
- * <p> Defines a list of commonly used constant strings. </p>
+ * <p>
+ * Defines a list of commonly used constant strings.
+ * </p>
+ * 
  * @author peizhaoo
- *
+ * 
  */
 public class CodeVariables {
        // C++ code or library
@@ -416,6 +419,22 @@ public class CodeVariables {
                newCode.add("static " + DECLARE(ANNO_HB_INIT + "**", "hb_init_table"));
 
                newCode.add("");
+               
+               // Define the __SPEC_INIT__ function to initialize user-defined
+               // variables
+               newCode.add(COMMENT("Initialization of sequential varialbes"));
+               newCode.add("static void __SPEC_INIT__() {");
+               addAllCodeWithIndent(newCode, construct.code.initVar, "\t");
+               newCode.add("}");
+               newCode.add("");
+
+               // Define the __SPEC_CLEAN__ function for clean-up
+               newCode.add(COMMENT("Cleanup routine of sequential variables"));
+               newCode.add("static void __SPEC_CLEANUP__() {");
+               addAllCodeWithIndent(newCode, construct.code.cleanupCode, "\t");
+               newCode.add("}");
+               newCode.add("");
+               
                newCode.add(COMMENT("Define function for sequential code initialization"));
                newCode.add("inline static void __sequential_init() {");
                // Init func_ptr_table
@@ -441,6 +460,10 @@ public class CodeVariables {
                                + COMMENT("Pass init info, including function table info & HB rules"));
                String structName = "anno_init", anno = "init";
                newCode.add("\t" + STRUCT_NEW_DECLARE_DEFINE(ANNO_INIT, structName));
+               newCode.add("\t"
+                               + ASSIGN_TO_PTR(structName, "init_func", "__SPEC_INIT__"));
+               newCode.add("\t"
+                               + ASSIGN_TO_PTR(structName, "cleanup_func", "__SPEC_CLEANUP__"));
                newCode.add("\t"
                                + ASSIGN_TO_PTR(structName, "func_table", "func_ptr_table"));
                newCode.add("\t"
@@ -456,10 +479,9 @@ public class CodeVariables {
                newCode.add("\t" + ANNOTATE(semantics, anno));
 
                newCode.add("");
-               // Init user-defined variables
-               addAllCodeWithIndent(newCode, construct.code.initVar, "\t");
-
                newCode.add("}");
+               newCode.add("");
+
                newCode.add(COMMENT("End of Global construct generation in class"));
 
                // printCode(newCode);
@@ -597,7 +619,9 @@ public class CodeVariables {
                newCode.add("\t"
                                + ASSIGN_TO_PTR(structName, "interface_num", interfaceNum)
                                + SHORT_COMMENT(construct.name));
-               newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "interface_name", "\"" + construct.name + "\""));
+               newCode.add("\t\t"
+                               + ASSIGN_TO_PTR(structName, "interface_name", "\""
+                                               + construct.name + "\""));
 
                String anno = "annotation_interface_begin";
                newCode.add("\t" + STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
@@ -766,11 +790,15 @@ public class CodeVariables {
                String labelNum = Integer.toString(semantics.commitPointLabel2Num
                                .get(construct.label));
                newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "label_num", labelNum));
-               newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "label_name", "\"" + construct.label + "\""));
+               newCode.add("\t\t"
+                               + ASSIGN_TO_PTR(structName, "label_name", "\""
+                                               + construct.label + "\""));
                if (construct.isAdditionalOrderingPoint) {
-                       newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "is_additional_point", "true"));
+                       newCode.add("\t\t"
+                                       + ASSIGN_TO_PTR(structName, "is_additional_point", "true"));
                } else {
-                       newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "is_additional_point", "false"));
+                       newCode.add("\t\t"
+                                       + ASSIGN_TO_PTR(structName, "is_additional_point", "false"));
                }
                newCode.add("\t\t" + STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
                newCode.add("\t\t"
@@ -781,8 +809,9 @@ public class CodeVariables {
                newCode.add("\t" + "}");
                return newCode;
        }
-       
-       public static String getCPInterfaceNum(SemanticsChecker semantics, String commitPointLabel) {
+
+       public static String getCPInterfaceNum(SemanticsChecker semantics,
+                       String commitPointLabel) {
                HashMap<String, InterfaceConstruct> cp2Interface = semantics.CPLabel2InterfaceConstruct;
                InterfaceConstruct iConstruct = cp2Interface.get(commitPointLabel);
                String interfaceName = iConstruct.name;
@@ -793,8 +822,8 @@ public class CodeVariables {
 
        /**
         * <p>
-        * Commit point define check should be unique to each interface, meaning that they
-        * are not shared between different interfaces
+        * Commit point define check should be unique to each interface, meaning
+        * that they are not shared between different interfaces
         * </p>
         * 
         * @param semantics
@@ -814,7 +843,7 @@ public class CodeVariables {
                                                + construct.label));
                newCode.add("");
                // Add annotation
-               
+
                newCode.add("\t" + "if (" + construct.condition + ") {");
                String structName = "cp_define_check", anno = "annotation_cp_define_check";
                newCode.add("\t\t"
@@ -823,12 +852,17 @@ public class CodeVariables {
                                .get(construct.label));
                String interfaceNum = getCPInterfaceNum(semantics, construct.label);
                newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "label_num", labelNum));
-               newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "label_name", "\"" + construct.label + "\""));
-               newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "interface_num", interfaceNum));
+               newCode.add("\t\t"
+                               + ASSIGN_TO_PTR(structName, "label_name", "\""
+                                               + construct.label + "\""));
+               newCode.add("\t\t"
+                               + ASSIGN_TO_PTR(structName, "interface_num", interfaceNum));
                if (construct.isAdditionalOrderingPoint) {
-                       newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "is_additional_point", "true"));
+                       newCode.add("\t\t"
+                                       + ASSIGN_TO_PTR(structName, "is_additional_point", "true"));
                } else {
-                       newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "is_additional_point", "false"));
+                       newCode.add("\t\t"
+                                       + ASSIGN_TO_PTR(structName, "is_additional_point", "false"));
                }
                newCode.add("\t\t" + STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
                newCode.add("\t\t"
@@ -838,19 +872,19 @@ public class CodeVariables {
                newCode.add("\t" + "}");
                return newCode;
        }
-       
+
        /**
         * <p>
-        * Commit point define check should be unique to each interface, meaning that they
-        * are not shared between different interfaces
+        * Commit point define check should be unique to each interface, meaning
+        * that they are not shared between different interfaces
         * </p>
         * 
         * @param semantics
         * @param construct
         * @return
         */
-       public static ArrayList<String> generateCPClear(
-                       SemanticsChecker semantics, CPClearConstruct construct) {
+       public static ArrayList<String> generateCPClear(SemanticsChecker semantics,
+                       CPClearConstruct construct) {
                ArrayList<String> newCode = new ArrayList<String>();
                // Add atomic return variable if the predicate accesses to it
                if (construct.condition.indexOf(MACRO_ATOMIC_RETURN) != -1) {
@@ -862,16 +896,18 @@ public class CodeVariables {
                                                + construct.label));
                newCode.add("");
                // Add annotation
-               
+
                newCode.add("\t" + "if (" + construct.condition + ") {");
                String structName = "cp_clear", anno = "annotation_cp_clear";
                newCode.add("\t\t"
                                + STRUCT_NEW_DECLARE_DEFINE(ANNO_CP_CLEAR, structName));
-//             String labelNum = Integer.toString(semantics.commitPointLabel2Num
-//                             .get(construct.label));
-//             String interfaceNum = getCPInterfaceNum(semantics, construct.label);
-//             newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "label_num", labelNum));
-//             newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "interface_num", interfaceNum));
+               // String labelNum = Integer.toString(semantics.commitPointLabel2Num
+               // .get(construct.label));
+               // String interfaceNum = getCPInterfaceNum(semantics, construct.label);
+               // newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "label_num",
+               // labelNum));
+               // newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "interface_num",
+               // interfaceNum));
                newCode.add("\t\t" + STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
                newCode.add("\t\t"
                                + ASSIGN_TO_PTR(anno, "type", SPEC_ANNO_TYPE_CP_CLEAR));
@@ -911,16 +947,23 @@ public class CodeVariables {
                                .toString(semantics.commitPointLabel2Num
                                                .get(construct.potentialCPLabel));
                newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "label_num", labelNum));
-               newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "label_name", "\"" + construct.label + "\""));
+               newCode.add("\t\t"
+                               + ASSIGN_TO_PTR(structName, "label_name", "\""
+                                               + construct.label + "\""));
                newCode.add("\t\t"
                                + ASSIGN_TO_PTR(structName, "potential_cp_label_num",
                                                potentialLabelNum));
-               newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "potential_label_name", "\"" + construct.potentialCPLabel + "\""));
-               newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "interface_num", interfaceNum));
+               newCode.add("\t\t"
+                               + ASSIGN_TO_PTR(structName, "potential_label_name", "\""
+                                               + construct.potentialCPLabel + "\""));
+               newCode.add("\t\t"
+                               + ASSIGN_TO_PTR(structName, "interface_num", interfaceNum));
                if (construct.isAdditionalOrderingPoint) {
-                       newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "is_additional_point", "true"));
+                       newCode.add("\t\t"
+                                       + ASSIGN_TO_PTR(structName, "is_additional_point", "true"));
                } else {
-                       newCode.add("\t\t" + ASSIGN_TO_PTR(structName, "is_additional_point", "false"));
+                       newCode.add("\t\t"
+                                       + ASSIGN_TO_PTR(structName, "is_additional_point", "false"));
                }
                newCode.add("\t\t" + STRUCT_NEW_DECLARE_DEFINE(SPEC_ANNOTATION, anno));
                newCode.add("\t\t"
index 9d3bff6..6105620 100644 (file)
@@ -4,6 +4,7 @@ import java.util.ArrayList;
 
 public class SequentialDefineSubConstruct {
        public final ArrayList<String> initVar;
+       public final ArrayList<String> cleanupCode;
        public final ArrayList<ArrayList<String>> defineFuncs;
        public final ArrayList<VariableDeclaration> declareVar;
        public final ArrayList<ArrayList<String>> declareStructs;
@@ -11,10 +12,12 @@ public class SequentialDefineSubConstruct {
        public SequentialDefineSubConstruct(
                        ArrayList<ArrayList<String>> declareStruct,
                        ArrayList<VariableDeclaration> declareVar,
-                       ArrayList<String> initVar, ArrayList<ArrayList<String>> defineFuncs) {
+                       ArrayList<String> initVar, ArrayList<String> cleanupCode,
+                       ArrayList<ArrayList<String>> defineFuncs) {
                this.declareStructs = declareStruct;
                this.declareVar = declareVar;
                this.initVar = initVar;
+               this.cleanupCode = cleanupCode;
                this.defineFuncs = defineFuncs;
        }