Changeset 6ff08d8 for doc/theses


Ignore:
Timestamp:
Jul 12, 2021, 1:44:35 PM (4 years ago)
Author:
caparsons <caparson@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
605673f, 9345684
Parents:
cf444b6 (diff), a953c2e3 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
doc/theses
Files:
1 added
21 edited
4 moved

Legend:

Unmodified
Added
Removed
  • doc/theses/andrew_beach_MMath/code/CondCatch.java

    rcf444b6 r6ff08d8  
    33class EmptyException extends Exception {}
    44
    5 public class CondMatch {
     5public class CondCatch {
    66        static boolean should_catch = false;
    77
     
    2020        }
    2121
    22         public static void main(String[] args) {
    23                 int times = 1;
    24                 int total_frames = 1;
    25                 if (0 < args.length) {
    26                         times = Integer.parseInt(args[0]);
    27                 }
    28                 if (1 < args.length) {
    29                         total_frames = Integer.parseInt(args[1]);
    30                 }
    31 
     22        private static long loop(int times) {
     23                long startTime = System.nanoTime();
    3224                for (int count = 0 ; count < times ; ++count) {
    3325                        try {
     
    3729                        }
    3830                }
     31                long endTime = System.nanoTime();
     32                return endTime - startTime;
     33        }
     34
     35        public static void main(String[] args) {
     36                int times = 1;
     37                if (0 < args.length) {
     38                        times = Integer.parseInt(args[0]);
     39                }
     40                if (1 < args.length) {
     41                        should_catch = 0 != Integer.parseInt(args[1]);
     42                }
     43
     44                // Warm-Up:
     45                loop(1000);
     46
     47                long time = loop(times);
     48                System.out.println("Run-Time (ns): " + time);
    3949        }
    4050}
  • doc/theses/andrew_beach_MMath/code/CrossCatch.java

    rcf444b6 r6ff08d8  
    44
    55public class CrossCatch {
    6         public static void main(String[] args) {
    7                 int times = 1;
    8                 boolean shouldThrow = false;
    9                 if (0 < args.length) {
    10                         times = Integer.parseInt(args[0]);
    11                 }
     6        private static boolean shouldThrow = false;
    127
     8        private static long loop(int times) {
     9                long startTime = System.nanoTime();
    1310                for (int count = 0 ; count < times ; ++count) {
    1411                        try {
     
    2017                        }
    2118                }
     19                long endTime = System.nanoTime();
     20                return endTime - startTime;
     21        }
     22
     23        public static void main(String[] args) {
     24                int times = 1;
     25                if (0 < args.length) {
     26                        times = Integer.parseInt(args[0]);
     27                }
     28
     29                // Warm-Up:
     30                loop(1000);
     31
     32                long time = loop(times);
     33                System.out.println("Run-Time (ns): " + time);
    2234        }
    2335}
  • doc/theses/andrew_beach_MMath/code/CrossFinally.java

    rcf444b6 r6ff08d8  
    22
    33public class CrossFinally {
    4         public static void main(String[] args) {
    5                 int times = 1;
    6                 boolean shouldThrow = false;
    7                 if (0 < args.length) {
    8                         times = Integer.parseInt(args[0]);
    9                 }
     4        private static boolean shouldThrow = false;
    105
     6        private static long loop(int times) {
     7                long startTime = System.nanoTime();
    118                for (int count = 0 ; count < times ; ++count) {
    129                        try {
     
    1613                        }
    1714                }
     15                long endTime = System.nanoTime();
     16                return endTime - startTime;
     17        }
     18
     19        public static void main(String[] args) {
     20                int times = 1;
     21                if (0 < args.length) {
     22                        times = Integer.parseInt(args[0]);
     23                }
     24
     25                // Warm-Up:
     26                loop(1000);
     27
     28                long time = loop(times);
     29                System.out.println("Run-Time (ns): " + time);
    1830        }
    1931}
  • doc/theses/andrew_beach_MMath/code/ThrowEmpty.java

    rcf444b6 r6ff08d8  
    1212        }
    1313
     14        private static long loop(int times, int total_frames) {
     15                long startTime = System.nanoTime();
     16                for (int count = 0 ; count < times ; ++count) {
     17                        try {
     18                                unwind_empty(total_frames);
     19                        } catch (EmptyException e) {
     20                                // ...
     21                        }
     22                }
     23                long endTime = System.nanoTime();
     24                return endTime - startTime;
     25        }
     26
    1427        public static void main(String[] args) {
    1528                int times = 1;
     
    2235                }
    2336
    24                 for (int count = 0 ; count < times ; ++count) {
    25                         try {
    26                                 unwind_empty(total_frames);
    27                         } catch (EmptyException e) {
    28                                 // ...
    29                         }
    30                 }
     37                // Warm-Up:
     38                loop(1000, total_frames);
     39
     40                long time = loop(times, total_frames);
     41                System.out.println("Run-Time (ns): " + time);
    3142        }
    3243}
  • doc/theses/andrew_beach_MMath/code/ThrowFinally.java

    rcf444b6 r6ff08d8  
    1313        }
    1414
     15        private static long loop(int times, int total_frames) {
     16                long startTime = System.nanoTime();
     17                for (int count = 0 ; count < times ; ++count) {
     18                        try {
     19                                unwind_finally(total_frames);
     20                        } catch (EmptyException e) {
     21                                // ...
     22                        }
     23                }
     24                long endTime = System.nanoTime();
     25                return endTime - startTime;
     26        }
     27
    1528        public static void main(String[] args) {
    1629                int times = 1;
     
    2336                }
    2437
    25                 for (int count = 0 ; count < times ; ++count) {
    26                         try {
    27                                 unwind_finally(total_frames);
    28                         } catch (EmptyException e) {
    29                                 // ...
    30                         }
    31                 }
     38                // Warm-Up:
     39                loop(1000, total_frames);
     40
     41                long time = loop(times, total_frames);
     42                System.out.println("Run-Time (ns): " + time);
    3243        }
    3344}
  • doc/theses/andrew_beach_MMath/code/ThrowOther.java

    rcf444b6 r6ff08d8  
    2424        }
    2525
     26        private static long loop(int times, int total_frames) {
     27                long startTime = System.nanoTime();
     28                for (int count = 0 ; count < times ; ++count) {
     29                        try {
     30                                unwind_other(total_frames);
     31                        } catch (EmptyException e) {
     32                                // ...
     33                        } catch (NotRaisedException e) {
     34                                // ...
     35                        }
     36                }
     37                long endTime = System.nanoTime();
     38                return endTime - startTime;
     39        }
     40
    2641        public static void main(String[] args) {
    2742                int times = 1;
     
    3449                }
    3550
    36                 for (int count = 0 ; count < times ; ++count) {
    37                         try {
    38                                 unwind_other(total_frames);
    39                         } catch (EmptyException e) {
    40                                 // ...
    41                         } catch (NotRaisedException e) {
    42                                 // ...
    43                         }
    44                 }
     51                // Warm-Up:
     52                loop(1000, total_frames);
     53
     54                long time = loop(times, total_frames);
     55                System.out.println("Run-Time (ns): " + time);
    4556        }
    4657}
  • doc/theses/andrew_beach_MMath/code/cond-catch.cfa

    rcf444b6 r6ff08d8  
    11// Conditional Match (or Re-Raise)
     2#include <clock.hfa>
    23#include <exception.hfa>
     4#include <fstream.hfa>
    35#include <stdlib.h>
    46
     
    2325int main(int argc, char * argv[]) {
    2426        unsigned int times = 1;
    25         if (2 < argc) {
     27        if (1 < argc) {
    2628                times = strtol(argv[1], 0p, 10);
    2729        }
     30        if (2 < argc) {
     31                should_catch = strtol(argv[2], 0p, 10);
     32        }
    2833
     34        Time start_time = timeHiRes();
    2935        for (unsigned int count = 0 ; count < times ; ++count) {
    3036                try {
     
    3440                }
    3541        }
     42        Time end_time = timeHiRes();
     43        sout | "Run-Time (ns): " | (end_time - start_time)`ns;
    3644}
  • doc/theses/andrew_beach_MMath/code/cond-catch.cpp

    rcf444b6 r6ff08d8  
    11// Conditional Match (or Re-Raise)
     2#include <chrono>
     3#include <cstdlib>
    24#include <exception>
    3 #include <cstdlib>
     5#include <iostream>
     6
     7using namespace std::chrono;
    48
    59struct EmptyException : public std::exception {};
     
    2327int main(int argc, char * argv[]) {
    2428        unsigned int times = 1;
    25         unsigned int total_frames = 1;
    26         if (2 < argc) {
     29        if (1 < argc) {
    2730                times = strtol(argv[1], nullptr, 10);
    2831        }
    29         if (3 < argc) {
    30                 total_frames = strtol(argv[2], nullptr, 10);
     32        if (2 < argc) {
     33                should_catch = strtol(argv[2], nullptr, 10);
    3134        }
    3235
     36        time_point<steady_clock> start_time = steady_clock::now();
    3337    for (unsigned int count = 0 ; count < times ; ++count) {
    3438        try {
     
    3842                }
    3943    }
     44        time_point<steady_clock> end_time = steady_clock::now();
     45        nanoseconds duration = duration_cast<nanoseconds>(end_time - start_time);
     46        std::cout << "Run-Time (ns): " << duration.count() << std::endl;
    4047}
  • doc/theses/andrew_beach_MMath/code/cond-fixup.cfa

    rcf444b6 r6ff08d8  
    11// Conditional Match (or Re-Raise)
     2#include <clock.hfa>
    23#include <exception.hfa>
     4#include <fstream.hfa>
    35#include <stdlib.hfa>
    46
     
    2325int main(int argc, char * argv[]) {
    2426        unsigned int times = 1;
    25         unsigned int total_frames = 1;
    26         if (2 < argc) {
     27        if (1 < argc) {
    2728                times = strtol(argv[1], 0p, 10);
    2829        }
    29         if (3 < argc) {
    30                 total_frames = strtol(argv[2], 0p, 10);
     30        if (2 < argc) {
     31                should_catch = strtol(argv[2], 0p, 10);
    3132        }
    3233
     34        Time start_time = timeHiRes();
    3335        for (unsigned int count = 0 ; count < times ; ++count) {
    3436                try {
     
    3840                }
    3941        }
     42        Time end_time = timeHiRes();
     43        sout | "Run-Time (ns): " | (end_time - start_time)`ns;
    4044}
  • doc/theses/andrew_beach_MMath/code/cross-catch.cfa

    rcf444b6 r6ff08d8  
    11// Cross a Try Statement with a Termination Handler
     2#include <clock.hfa>
    23#include <exception.hfa>
     4#include <fstream.hfa>
    35#include <stdlib.hfa>
    46
     
    810        unsigned int times = 1;
    911        unsigned int total_frames = 1;
    10         if (2 < argc) {
     12        if (1 < argc) {
    1113                times = strtol(argv[1], 0p, 10);
    1214        }
    13         if (3 < argc) {
     15        if (2 < argc) {
    1416                total_frames = strtol(argv[2], 0p, 10);
    1517        }
    1618
     19        Time start_time = timeHiRes();
    1720        for (unsigned int count = 0 ; count < times ; ++count) {
    1821                try {
     
    2225                }
    2326        }
     27        Time end_time = timeHiRes();
     28        sout | "Run-Time (ns): " | (end_time - start_time)`ns;
    2429}
  • doc/theses/andrew_beach_MMath/code/cross-catch.cpp

    rcf444b6 r6ff08d8  
    11// Cross a Try Statement with a Termination Handler
     2#include <chrono>
     3#include <cstdlib>
    24#include <exception>
    3 #include <cstdlib>
     5#include <iostream>
     6
     7using namespace std::chrono;
    48
    59struct NotRaisedException : public std::exception {};
     
    711int main(int argc, char * argv[]) {
    812        unsigned int times = 1;
    9         if (2 < argc) {
     13        if (1 < argc) {
    1014                times = strtol(argv[1], nullptr, 10);
    1115        }
    1216
     17        time_point<steady_clock> start_time = steady_clock::now();
    1318        for (unsigned int count = 0 ; count < times ; ++count) {
    1419                try {
     
    1823                }
    1924        }
     25        time_point<steady_clock> end_time = steady_clock::now();
     26        nanoseconds duration = duration_cast<nanoseconds>(end_time - start_time);
     27        std::cout << "Run-Time (ns): " << duration.count() << std::endl;
    2028}
  • doc/theses/andrew_beach_MMath/code/cross-finally.cfa

    rcf444b6 r6ff08d8  
    11// Cross a Try Statement With Finally Clause
     2#include <clock.hfa>
    23#include <exception.hfa>
     4#include <fstream.hfa>
    35#include <stdlib.hfa>
    46
     
    68        unsigned int times = 1;
    79        unsigned int total_frames = 1;
    8         if (2 < argc) {
     10        if (1 < argc) {
    911                times = strtol(argv[1], 0p, 10);
    1012        }
    11         if (3 < argc) {
     13        if (2 < argc) {
    1214                total_frames = strtol(argv[2], 0p, 10);
    1315        }
    1416
     17        Time start_time = timeHiRes();
    1518        for (unsigned int count = 0 ; count < times ; ++count) {
    1619                 try {
     
    2023                }
    2124        }
     25        Time end_time = timeHiRes();
     26        sout | "Run-Time (ns): " | (end_time - start_time)`ns;
    2227}
  • doc/theses/andrew_beach_MMath/code/cross-resume.cfa

    rcf444b6 r6ff08d8  
    11// Cross a Try Statement With Finally Clause
     2#include <clock.hfa>
    23#include <exception.hfa>
     4#include <fstream.hfa>
    35#include <stdlib.hfa>
    46
     
    810        unsigned int times = 1;
    911        unsigned int total_frames = 1;
    10         if (2 < argc) {
     12        if (1 < argc) {
    1113                times = strtol(argv[1], 0p, 10);
    1214        }
    13         if (3 < argc) {
     15        if (2 < argc) {
    1416                total_frames = strtol(argv[2], 0p, 10);
    1517        }
    1618
     19        Time start_time = timeHiRes();
    1720        for (unsigned int count = 0 ; count < times ; ++count) {
    1821                try {
     
    2225                }
    2326        }
     27        Time end_time = timeHiRes();
     28        sout | "Run-Time (ns): " | (end_time - start_time)`ns;
    2429}
  • doc/theses/andrew_beach_MMath/code/resume-detor.cfa

    rcf444b6 r6ff08d8  
    11// Throw Across Destructor
     2#include <clock.hfa>
    23#include <exception.hfa>
     4#include <fstream.hfa>
    35#include <stdlib.hfa>
    46
     
    2628        unsigned int times = 1;
    2729        unsigned int total_frames = 1;
    28         if (2 < argc) {
     30        if (1 < argc) {
    2931                times = strtol(argv[1], 0p, 10);
    3032        }
    31         if (3 < argc) {
     33        if (2 < argc) {
    3234                total_frames = strtol(argv[2], 0p, 10);
    3335        }
    3436
     37        Time start_time = timeHiRes();
    3538    for (int count = 0 ; count < times ; ++count) {
    3639        try {
     
    4043        }
    4144    }
     45        Time end_time = timeHiRes();
     46        sout | "Run-Time (ns): " | (end_time - start_time)`ns;
    4247}
  • doc/theses/andrew_beach_MMath/code/resume-empty.cfa

    rcf444b6 r6ff08d8  
    11// Resume Across Empty Function
     2#include <clock.hfa>
    23#include <exception.hfa>
     4#include <fstream.hfa>
    35#include <stdlib.hfa>
    46
     
    911void unwind_empty(unsigned int frames) {
    1012        if (frames) {
    11 
    1213                unwind_empty(frames - 1);
    1314        } else {
     
    1920        unsigned int times = 1;
    2021        unsigned int total_frames = 1;
    21         if (2 < argc) {
     22        if (1 < argc) {
    2223                times = strtol(argv[1], 0p, 10);
    2324        }
    24         if (3 < argc) {
     25        if (2 < argc) {
    2526                total_frames = strtol(argv[2], 0p, 10);
    2627        }
    2728
     29        Time start_time = timeHiRes();
    2830        for (int count = 0 ; count < times ; ++count) {
    2931                try {
     
    3335                }
    3436        }
     37        Time end_time = timeHiRes();
     38        sout | "Run-Time (ns): " | (end_time - start_time)`ns;
    3539}
  • doc/theses/andrew_beach_MMath/code/resume-finally.cfa

    rcf444b6 r6ff08d8  
    11// Throw Across Finally
     2#include <clock.hfa>
    23#include <exception.hfa>
     4#include <fstream.hfa>
    35#include <stdlib.hfa>
    46
     
    2224        unsigned int times = 1;
    2325        unsigned int total_frames = 1;
    24         if (2 < argc) {
     26        if (1 < argc) {
    2527                times = strtol(argv[1], 0p, 10);
    2628        }
    27         if (3 < argc) {
     29        if (2 < argc) {
    2830                total_frames = strtol(argv[2], 0p, 10);
    2931        }
    3032
     33        Time start_time = timeHiRes();
    3134        for (int count = 0 ; count < times ; ++count) {
    3235                try {
     
    3639                }
    3740        }
     41        Time end_time = timeHiRes();
     42        sout | "Run-Time (ns): " | (end_time - start_time)`ns;
    3843}
  • doc/theses/andrew_beach_MMath/code/resume-other.cfa

    rcf444b6 r6ff08d8  
    11// Resume Across Other Handler
     2#include <clock.hfa>
    23#include <exception.hfa>
     4#include <fstream.hfa>
    35#include <stdlib.hfa>
    46
     
    2426        unsigned int times = 1;
    2527        unsigned int total_frames = 1;
    26         if (2 < argc) {
     28        if (1 < argc) {
    2729                times = strtol(argv[1], 0p, 10);
    2830        }
    29         if (3 < argc) {
     31        if (2 < argc) {
    3032                total_frames = strtol(argv[2], 0p, 10);
    3133        }
    3234
     35        Time start_time = timeHiRes();
    3336        for (int count = 0 ; count < times ; ++count) {
    3437                try {
     
    3841                }
    3942        }
     43        Time end_time = timeHiRes();
     44        sout | "Run-Time (ns): " | (end_time - start_time)`ns;
    4045}
  • doc/theses/andrew_beach_MMath/code/throw-detor.cfa

    rcf444b6 r6ff08d8  
    11// Throw Across Destructor
     2#include <clock.hfa>
    23#include <exception.hfa>
     4#include <fstream.hfa>
    35#include <stdlib.hfa>
    46
     
    2527        unsigned int times = 1;
    2628        unsigned int total_frames = 1;
    27         if (2 < argc) {
     29        if (1 < argc) {
    2830                times = strtol(argv[1], 0p, 10);
    2931        }
    30         if (3 < argc) {
     32        if (2 < argc) {
    3133                total_frames = strtol(argv[2], 0p, 10);
    3234        }
    3335
     36        Time start_time = timeHiRes();
    3437        for (int count = 0 ; count < times ; ++count) {
    3538                try {
     
    3942                }
    4043        }
     44        Time end_time = timeHiRes();
     45        sout | "Run-Time (ns): " | (end_time - start_time)`ns;
    4146}
  • doc/theses/andrew_beach_MMath/code/throw-detor.cpp

    rcf444b6 r6ff08d8  
    11// Throw Across Destructor
     2#include <chrono>
     3#include <cstdlib>
    24#include <exception>
    3 #include <cstdlib>
     5#include <iostream>
     6
     7using namespace std::chrono;
    48
    59struct EmptyException : public std::exception {};
     
    2125        unsigned int times = 1;
    2226        unsigned int total_frames = 1;
    23         if (2 < argc) {
     27        if (1 < argc) {
    2428                times = strtol(argv[1], nullptr, 10);
    2529        }
    26         if (3 < argc) {
     30        if (2 < argc) {
    2731                total_frames = strtol(argv[2], nullptr, 10);
    2832        }
    2933
     34        time_point<steady_clock> start_time = steady_clock::now();
    3035        for (int count = 0 ; count < times ; ++count) {
    3136                try {
     
    3540                }
    3641        }
     42        time_point<steady_clock> end_time = steady_clock::now();
     43        nanoseconds duration = duration_cast<nanoseconds>(end_time - start_time);
     44        std::cout << "Run-Time (ns): " << duration.count() << std::endl;
    3745}
  • doc/theses/andrew_beach_MMath/code/throw-empty.cfa

    rcf444b6 r6ff08d8  
    11// Throw Across Empty Function
     2#include <clock.hfa>
    23#include <exception.hfa>
     4#include <fstream.hfa>
    35#include <stdlib.hfa>
    46
     
    1820        unsigned int times = 1;
    1921        unsigned int total_frames = 1;
    20         if (2 < argc) {
     22        if (1 < argc) {
    2123                times = strtol(argv[1], 0p, 10);
    2224        }
    23         if (3 < argc) {
     25        if (2 < argc) {
    2426                total_frames = strtol(argv[2], 0p, 10);
    2527        }
    2628
     29        Time start_time = timeHiRes();
    2730        for (unsigned int count = 0 ; count < times ; ++count) {
    2831                try {
     
    3235                }
    3336        }
     37        Time end_time = timeHiRes();
     38        sout | "Run-Time (ns): " | (end_time - start_time)`ns;
    3439}
  • doc/theses/andrew_beach_MMath/code/throw-empty.cpp

    rcf444b6 r6ff08d8  
    11// Throw Across Empty Function
     2#include <chrono>
     3#include <cstdlib>
    24#include <exception>
    3 #include <cstdlib>
     5#include <iostream>
     6
     7using namespace std::chrono;
    48
    59struct EmptyException : public std::exception {};
     
    1620        unsigned int times = 1;
    1721        unsigned int total_frames = 1;
    18         if (2 < argc) {
     22        if (1 < argc) {
    1923                times = strtol(argv[1], nullptr, 10);
    2024        }
    21         if (3 < argc) {
     25        if (2 < argc) {
    2226                total_frames = strtol(argv[2], nullptr, 10);
    2327        }
    2428
     29        time_point<steady_clock> start_time = steady_clock::now();
    2530        for (unsigned int count = 0 ; count < times ; ++count) {
    2631                try {
     
    3035                }
    3136        }
     37        time_point<steady_clock> end_time = steady_clock::now();
     38        nanoseconds duration = duration_cast<nanoseconds>(end_time - start_time);
     39        std::cout << "Run-Time (ns): " << duration.count() << std::endl;
    3240}
  • doc/theses/andrew_beach_MMath/code/throw-finally.cfa

    rcf444b6 r6ff08d8  
    11// Throw Across Finally
     2#include <clock.hfa>
    23#include <exception.hfa>
     4#include <fstream.hfa>
    35#include <stdlib.hfa>
    46
     
    2224        unsigned int times = 1;
    2325        unsigned int total_frames = 1;
    24         if (2 < argc) {
     26        if (1 < argc) {
    2527                times = strtol(argv[1], 0p, 10);
    2628        }
    27         if (3 < argc) {
     29        if (2 < argc) {
    2830                total_frames = strtol(argv[2], 0p, 10);
    2931        }
    3032
     33        Time start_time = timeHiRes();
    3134        for (int count = 0 ; count < times ; ++count) {
    3235                try {
     
    3639                }
    3740        }
     41        Time end_time = timeHiRes();
     42        sout | "Run-Time (ns): " | (end_time - start_time)`ns;
    3843}
  • doc/theses/andrew_beach_MMath/code/throw-other.cfa

    rcf444b6 r6ff08d8  
    11// Throw Across Other Handler
     2#include <clock.hfa>
    23#include <exception.hfa>
     4#include <fstream.hfa>
    35#include <stdlib.hfa>
    46
     
    2426        unsigned int times = 1;
    2527        unsigned int total_frames = 1;
    26         if (2 < argc) {
     28        if (1 < argc) {
    2729                times = strtol(argv[1], 0p, 10);
    2830        }
    29         if (3 < argc) {
     31        if (2 < argc) {
    3032                total_frames = strtol(argv[2], 0p, 10);
    3133        }
    3234
     35        Time start_time = timeHiRes();
    3336        for (int count = 0 ; count < times ; ++count) {
    3437                try {
     
    3841                }
    3942        }
     43        Time end_time = timeHiRes();
     44        sout | "Run-Time (ns): " | (end_time - start_time)`ns;
    4045}
  • doc/theses/andrew_beach_MMath/code/throw-other.cpp

    rcf444b6 r6ff08d8  
    11// Throw Across Other Handler
     2#include <chrono>
     3#include <cstdlib>
    24#include <exception>
    3 #include <cstdlib>
     5#include <iostream>
     6
     7using namespace std::chrono;
    48
    59struct EmptyException : public std::exception {};
     
    2226        unsigned int times = 1;
    2327        unsigned int total_frames = 1;
    24         if (2 < argc) {
     28        if (1 < argc) {
    2529                times = strtol(argv[1], nullptr, 10);
    2630        }
    27         if (3 < argc) {
     31        if (2 < argc) {
    2832                total_frames = strtol(argv[2], nullptr, 10);
    2933        }
    3034
     35        time_point<steady_clock> start_time = steady_clock::now();
    3136        for (int count = 0 ; count < times ; ++count) {
    3237                try {
     
    3641                }
    3742        }
     43        time_point<steady_clock> end_time = steady_clock::now();
     44        nanoseconds duration = duration_cast<nanoseconds>(end_time - start_time);
     45        std::cout << "Run-Time (ns): " << duration.count() << std::endl;
    3846}
  • doc/theses/mubeen_zulfiqar_MMath/allocator.tex

    rcf444b6 r6ff08d8  
    4444
    4545\subsection{Design philosophy}
    46 
     46The objective of uHeapLmmm's new design was to fulfill following requirements:
     47\begin{itemize}
     48\item It should be concurrent to be used in multi-threaded programs.
     49\item It should avoid global locks, on resources shared across all threads, as much as possible.
     50\item It's performance (FIX ME: cite performance benchmarks) should be comparable to the commonly used allocators (FIX ME: cite common allocators).
     51\item It should be a lightweight memory allocator.
     52\end{itemize}
    4753
    4854%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    4955
    5056\section{Background and previous design of uHeapLmmm}
    51 
     57uHeapLmmm was originally designed by X in X (FIX ME: add original author after confirming with Peter).
     58(FIX ME: make and add figure of previous design with description)
    5259
    5360%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    5461
    5562\section{Distributed design of uHeapLmmm}
     63uHeapLmmm's design was reviewed and changed to fulfill new requirements (FIX ME: cite allocator philosophy). For this purpose, following two designs of uHeapLmm were proposed:
    5664
     65\paragraph{Design 1: Decentralized}
     66Fixed number of heaps: shard the heap into N heaps each with a bump-area allocated from the @sbrk@ area.
     67Kernel threads (KT) are assigned to the N heaps.
     68When KTs $\le$ N, the heaps are uncontented.
     69When KTs $>$ N, the heaps are contented.
     70By adjusting N, this approach reduces storage at the cost of speed due to contention.
     71In all cases, a thread acquires/releases a lock, contented or uncontented.
     72\begin{cquote}
     73\centering
     74\input{AllocDS1}
     75\end{cquote}
     76Problems: need to know when a KT is created and destroyed to know when to assign/un-assign a heap to the KT.
     77
     78\paragraph{Design 2: Centralized}
     79One heap, but lower bucket sizes are N-shared across KTs.
     80This design leverages the fact that 95\% of allocation requests are less than 512 bytes and there are only 3--5 different request sizes.
     81When KTs $\le$ N, the important bucket sizes are uncontented.
     82When KTs $>$ N, the free buckets are contented.
     83Therefore, threads are only contending for a small number of buckets, which are distributed among them to reduce contention.
     84\begin{cquote}
     85\centering
     86\input{AllocDS2}
     87\end{cquote}
     88Problems: need to know when a kernel thread (KT) is created and destroyed to know when to assign a shared bucket-number.
     89When no thread is assigned a bucket number, its free storage is unavailable. All KTs will be contended for one lock on sbrk for their initial allocations (before free-lists gets populated).
     90
     91Out of the two designs, Design 1 was chosen because it's concurrency is better across all bucket-sizes as design-2 shards a few buckets of selected sizes while design-1 shards all the buckets. Design-2 shards the whole heap which has all the buckets with the addition of sharding sbrk area.
    5792
    5893\subsection{Advantages of distributed design}
     94The distributed design of uHeapLmmm is concurrent to work in multi-threaded applications.
    5995
     96Some key benefits of the distributed design of uHeapLmmm are as follows:
     97
     98\begin{itemize}
     99\item
     100The bump allocation is concurrent as memory taken from sbrk is sharded across all heaps as bump allocation reserve. The lock on bump allocation (on memory taken from sbrk) will only be contended if KTs > N. The contention on sbrk area is less likely as it will only happen in the case if heaps assigned to two KTs get short of bump allocation reserve simultanously.
     101\item
     102N heaps are created at the start of the program and destroyed at the end of program. When a KT is created, we only assign it to one of the heaps. When a KT is destroyed, we only dissociate it from the assigned heap but we do not destroy that heap. That heap will go back to our pool-of-heaps, ready to be used by some new KT. And if that heap was shared among multiple KTs (like the case of KTs > N) then, on deletion of one KT, that heap will be still in-use of the other KTs. This will prevent creation and deletion of heaps during run-time as heaps are re-usable which helps in keeping low-memory footprint.
     103\item
     104It is possible to use sharing and stealing techniques to share/find unused storage, when a free list is unused or empty.
     105\item
     106Distributed design avoids unnecassry locks on resources shared across all KTs.
     107\end{itemize}
     108
     109FIX ME: Cite performance comparison of the two heap designs if required
    60110
    61111%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     
    72122Why did we need it?
    73123The added benefits.
    74 
    75 
    76 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    77 % Following is added by Peter
    78 
    79 \noindent
    80 ====================
    81 
    82 \newpage
    83 \paragraph{Design 1: Decentralized}
    84 Fixed number of heaps: shard the heap into N heaps each with a bump-area allocated from the @sbrk@ area.
    85 Kernel threads (KT) are assigned to the N heaps.
    86 When KTs $\le$ N, the heaps are uncontented.
    87 When KTs $>$ N, the heaps are contented.
    88 By adjusting N, this approach reduces storage at the cost of speed due to contention.
    89 In all cases, a thread acquires/releases a lock, contented or uncontented.
    90 \begin{cquote}
    91 \centering
    92 \input{AllocDS1}
    93 \end{cquote}
    94 Problems: need to know when a KT is created and destroyed to know when to create/delete the KT's heap.
    95 On KT deletion, its heap freed-storage needs to be distributed somewhere.
    96 
    97 \paragraph{Design 2: Centralized}
    98 
    99 One heap, but lower bucket sizes are N-shared across KTs.
    100 This design leverages the fact that 95\% of allocation requests are less than 512 bytes and there are only 3--5 different request sizes.
    101 When KTs $\le$ N, the important bucket sizes are uncontented.
    102 When KTs $>$ N, the free buckets are contented.
    103 Therefore, threads are only contending for a small number of buckets, which are distributed among them to reduce contention.
    104 \begin{cquote}
    105 \centering
    106 \input{AllocDS2}
    107 \end{cquote}
    108 Problems: need to know when a kernel thread (KT) is created and destroyed to know when to assign a shared bucket-number.
    109 When no thread is assigned a bucket number, its free storage is unavailable.
    110 It is possible to use sharing and stealing techniques to share/find unused storage, when a free list is unused or empty.
Note: See TracChangeset for help on using the changeset viewer.