Changes in / [fe8aa21:d00d581]


Ignore:
Files:
13 added
23 deleted
24 edited

Legend:

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

    rfe8aa21 rd00d581  
    66        static boolean should_catch = false;
    77
     8        static void throw_exception() throws EmptyException {
     9                throw new EmptyException();
     10        }
     11
     12        static void cond_catch() throws EmptyException {
     13                try {
     14                        throw_exception();
     15                } catch (EmptyException exc) {
     16                        if (!should_catch) {
     17                                throw exc;
     18                        }
     19                }
     20        }
     21
    822        private static long loop(int times) {
    923                long startTime = System.nanoTime();
    1024                for (int count = 0 ; count < times ; ++count) {
    1125                        try {
    12                                 try {
    13                                         throw new EmptyException();
    14                                 } catch (EmptyException exc) {
    15                                         if (!should_catch) {
    16                                                 throw exc;
    17                                         }
    18                                 }
     26                                cond_catch();
    1927                        } catch (EmptyException exc) {
    2028                                // ...
     
    3846
    3947                long time = loop(times);
    40                 System.out.format("Run-Time (s): %.1f%n", time / 1_000_000_000.);
     48                System.out.println("Run-Time (ns): " + time);
    4149        }
    4250}
  • doc/theses/andrew_beach_MMath/code/ThrowEmpty.java

    rfe8aa21 rd00d581  
    3939
    4040                long time = loop(times, total_frames);
    41                 System.out.format("Run-Time (s): %.1f%n", time / 1_000_000_000.);
     41                System.out.println("Run-Time (ns): " + time);
    4242        }
    4343}
  • doc/theses/andrew_beach_MMath/code/ThrowFinally.java

    rfe8aa21 rd00d581  
    4444
    4545                long time = loop(times, total_frames);
    46                 System.out.format("Run-Time (s): %.1f%n", time / 1_000_000_000.);
     46                System.out.println("Run-Time (ns): " + time);
    4747        }
    4848}
  • doc/theses/andrew_beach_MMath/code/ThrowOther.java

    rfe8aa21 rd00d581  
    5252
    5353                long time = loop(times, total_frames);
    54                 System.out.format("Run-Time (s): %.1f%n", time / 1_000_000_000.);
     54                System.out.println("Run-Time (ns): " + time);
    5555        }
    5656}
  • doc/theses/andrew_beach_MMath/code/cond-catch.cfa

    rfe8aa21 rd00d581  
    33#include <exception.hfa>
    44#include <fstream.hfa>
    5 #include <stdlib.hfa>                                                                   // strto
     5#include <stdlib.h>
    66
    7 exception empty_exception;
    8 vtable(empty_exception) empty_vt;
     7EHM_EXCEPTION(empty_exception)();
     8
     9EHM_VIRTUAL_TABLE(empty_exception, empty_vt);
    910
    1011bool should_catch = false;
     12
     13void throw_exception() {
     14        throw (empty_exception){&empty_vt};
     15}
     16
     17void cond_catch() {
     18        try {
     19                throw_exception();
     20        } catch (empty_exception * exc ; should_catch) {
     21                asm volatile ("# catch block (conditional)");
     22        }
     23}
    1124
    1225int main(int argc, char * argv[]) {
    1326        unsigned int times = 1;
    1427        if (1 < argc) {
    15                 times = strto(argv[1], 0p, 10);
     28                times = strtol(argv[1], 0p, 10);
    1629        }
    1730        if (2 < argc) {
    18                 should_catch = (unsigned int)strto(argv[2], 0p, 2);
     31                should_catch = strtol(argv[2], 0p, 10);
    1932        }
    2033
     
    2235        for (unsigned int count = 0 ; count < times ; ++count) {
    2336                try {
    24                         throw (empty_exception){&empty_vt};
    25                 } catch (empty_exception * exc ; should_catch) {
    26                         asm volatile ("# catch block (conditional)");
     37                        cond_catch();
    2738                } catch (empty_exception * exc) {
    2839                        asm volatile ("# catch block (unconditional)");
     
    3041        }
    3142        Time end_time = timeHiRes();
    32         sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.);
     43        sout | "Run-Time (ns): " | (end_time - start_time)`ns;
    3344}
  • doc/theses/andrew_beach_MMath/code/cond-catch.cpp

    rfe8aa21 rd00d581  
    44#include <exception>
    55#include <iostream>
    6 #include <iomanip>
    76
    8 using namespace std;
    97using namespace std::chrono;
    108
     
    1210
    1311bool should_catch = false;
     12
     13void throw_exception() {
     14        throw EmptyException();
     15}
     16
     17void cond_catch() {
     18        try {
     19                throw_exception();
     20        } catch (EmptyException & exc) {
     21                if (!should_catch) {
     22                        throw;
     23                }
     24                asm volatile ("# catch block (conditional)");
     25        }
     26}
    1427
    1528int main(int argc, char * argv[]) {
     
    2538    for (unsigned int count = 0 ; count < times ; ++count) {
    2639        try {
    27                         try {
    28                                 throw EmptyException();
    29                         } catch (EmptyException & exc) {
    30                                 if (!should_catch) {
    31                                         throw;
    32                                 }
    33                                 asm volatile ("# catch block (conditional)");
    34                         }
     40                        cond_catch();
    3541                } catch (EmptyException &) {
    3642                        asm volatile ("# catch block (unconditional)");
     
    3945        time_point<steady_clock> end_time = steady_clock::now();
    4046        nanoseconds duration = duration_cast<nanoseconds>(end_time - start_time);
    41         cout << "Run-Time (s): " << fixed << setprecision(1) << duration.count() / 1'000'000'000. << endl;
     47        std::cout << "Run-Time (ns): " << duration.count() << std::endl;
    4248}
  • doc/theses/andrew_beach_MMath/code/cond-fixup.cfa

    rfe8aa21 rd00d581  
    33#include <exception.hfa>
    44#include <fstream.hfa>
    5 #include <stdlib.hfa>                                                                   // strto
     5#include <stdlib.hfa>
    66
    7 exception empty_exception;
    8 vtable(empty_exception) empty_vt;
     7EHM_EXCEPTION(empty_exception)();
     8
     9EHM_VIRTUAL_TABLE(empty_exception, empty_vt);
    910
    1011bool should_catch = false;
     12
     13void throw_exception() {
     14        throwResume (empty_exception){&empty_vt};
     15}
     16
     17void cond_catch() {
     18        try {
     19                throw_exception();
     20        } catchResume (empty_exception * exc ; should_catch) {
     21                asm volatile ("# fixup block (conditional)");
     22        }
     23}
    1124
    1225int main(int argc, char * argv[]) {
    1326        unsigned int times = 1;
    1427        if (1 < argc) {
    15                 times = strto(argv[1], 0p, 10);
     28                times = strtol(argv[1], 0p, 10);
    1629        }
    1730        if (2 < argc) {
    18                 should_catch = (unsigned int)strto(argv[2], 0p, 2);
     31                should_catch = strtol(argv[2], 0p, 10);
    1932        }
    2033
     
    2235        for (unsigned int count = 0 ; count < times ; ++count) {
    2336                try {
    24                         throwResume (empty_exception){&empty_vt};
    25                 } catchResume (empty_exception * exc ; should_catch) {
    26                         asm volatile ("# fixup block (conditional)");
     37                        cond_catch();
    2738                } catchResume (empty_exception * exc) {
    2839                        asm volatile ("# fixup block (unconditional)");
     
    3041        }
    3142        Time end_time = timeHiRes();
    32         sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.);
     43        sout | "Run-Time (ns): " | (end_time - start_time)`ns;
    3344}
  • doc/theses/andrew_beach_MMath/code/resume-detor.cfa

    rfe8aa21 rd00d581  
    33#include <exception.hfa>
    44#include <fstream.hfa>
    5 #include <stdlib.hfa>                                                                   // strto
     5#include <stdlib.hfa>
    66
    7 exception empty_exception;
    8 vtable(empty_exception) empty_vt;
     7EHM_EXCEPTION(empty_exception)();
     8
     9EHM_VIRTUAL_TABLE(empty_exception, empty_vt);
    910
    1011struct WithDestructor {};
     
    1617void unwind_destructor(unsigned int frames) {
    1718        if (frames) {
     19
    1820                WithDestructor object;
    1921                unwind_destructor(frames - 1);
     
    2729        unsigned int total_frames = 1;
    2830        if (1 < argc) {
    29                 times = strto(argv[1], 0p, 10);
     31                times = strtol(argv[1], 0p, 10);
    3032        }
    3133        if (2 < argc) {
    32                 total_frames = strto(argv[2], 0p, 10);
     34                total_frames = strtol(argv[2], 0p, 10);
    3335        }
    3436
     
    4244        }
    4345        Time end_time = timeHiRes();
    44         sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.);
     46        sout | "Run-Time (ns): " | (end_time - start_time)`ns;
    4547}
  • doc/theses/andrew_beach_MMath/code/resume-empty.cfa

    rfe8aa21 rd00d581  
    33#include <exception.hfa>
    44#include <fstream.hfa>
    5 #include <stdlib.hfa>                                                                   // strto
     5#include <stdlib.hfa>
    66
    7 exception empty_exception;
    8 vtable(empty_exception) empty_vt;
     7EHM_EXCEPTION(empty_exception)();
    98
    10 void nounwind_empty(unsigned int frames) {
     9EHM_VIRTUAL_TABLE(empty_exception, empty_vt);
     10
     11void unwind_empty(unsigned int frames) {
    1112        if (frames) {
    12                 nounwind_empty(frames - 1);
     13                unwind_empty(frames - 1);
    1314        } else {
    1415                throwResume (empty_exception){&empty_vt};
     
    2021        unsigned int total_frames = 1;
    2122        if (1 < argc) {
    22                 times = strto(argv[1], 0p, 10);
     23                times = strtol(argv[1], 0p, 10);
    2324        }
    2425        if (2 < argc) {
    25                 total_frames = strto(argv[2], 0p, 10);
     26                total_frames = strtol(argv[2], 0p, 10);
    2627        }
    2728
    2829        Time start_time = timeHiRes();
    29         for (unsigned int count = 0 ; count < times ; ++count) {
     30        for (int count = 0 ; count < times ; ++count) {
    3031                try {
    31                         nounwind_empty(total_frames);
     32                        unwind_empty(total_frames);
    3233                } catchResume (empty_exception *) {
    3334                        asm volatile ("# fixup block");
     
    3536        }
    3637        Time end_time = timeHiRes();
    37         sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.);
     38        sout | "Run-Time (ns): " | (end_time - start_time)`ns;
    3839}
  • doc/theses/andrew_beach_MMath/code/resume-finally.cfa

    rfe8aa21 rd00d581  
    33#include <exception.hfa>
    44#include <fstream.hfa>
    5 #include <stdlib.hfa>                                                                   // strto
     5#include <stdlib.hfa>
    66
    7 exception empty_exception;
    8 vtable(empty_exception) empty_vt;
     7EHM_EXCEPTION(empty_exception)();
     8
     9EHM_VIRTUAL_TABLE(empty_exception, empty_vt);
    910
    1011void unwind_finally(unsigned int frames) {
     
    2425        unsigned int total_frames = 1;
    2526        if (1 < argc) {
    26                 times = strto(argv[1], 0p, 10);
     27                times = strtol(argv[1], 0p, 10);
    2728        }
    2829        if (2 < argc) {
    29                 total_frames = strto(argv[2], 0p, 10);
     30                total_frames = strtol(argv[2], 0p, 10);
    3031        }
    3132
     
    3940        }
    4041        Time end_time = timeHiRes();
    41         sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.);
     42        sout | "Run-Time (ns): " | (end_time - start_time)`ns;
    4243}
  • doc/theses/andrew_beach_MMath/code/resume-other.cfa

    rfe8aa21 rd00d581  
    33#include <exception.hfa>
    44#include <fstream.hfa>
    5 #include <stdlib.hfa>                                                                   // strto
     5#include <stdlib.hfa>
    66
    7 exception empty_exception;
    8 vtable(empty_exception) empty_vt;
    9 exception not_raised_exception;
     7EHM_EXCEPTION(empty_exception)();
    108
    11 void nounwind_other(unsigned int frames) {
     9EHM_VIRTUAL_TABLE(empty_exception, empty_vt);
     10
     11EHM_EXCEPTION(not_raised_exception)();
     12
     13void unwind_other(unsigned int frames) {
    1214        if (frames) {
    1315                try {
    14                         nounwind_other(frames - 1);
     16                        unwind_other(frames - 1);
    1517                } catchResume (not_raised_exception *) {
    1618                        asm volatile ("# fixup block (stack)");
     
    2527        unsigned int total_frames = 1;
    2628        if (1 < argc) {
    27                 times = strto(argv[1], 0p, 10);
     29                times = strtol(argv[1], 0p, 10);
    2830        }
    2931        if (2 < argc) {
    30                 total_frames = strto(argv[2], 0p, 10);
     32                total_frames = strtol(argv[2], 0p, 10);
    3133        }
    3234
     
    3436        for (int count = 0 ; count < times ; ++count) {
    3537                try {
    36                         nounwind_other(total_frames);
     38                        unwind_other(total_frames);
    3739                } catchResume (empty_exception *) {
    3840                        asm volatile ("# fixup block (base)");
     
    4042        }
    4143        Time end_time = timeHiRes();
    42         sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.);
     44        sout | "Run-Time (ns): " | (end_time - start_time)`ns;
    4345}
  • doc/theses/andrew_beach_MMath/code/run.sh

    rfe8aa21 rd00d581  
    11#!/usr/bin/env bash
    22
    3 readonly ALL_TESTS=(raise-{empty,detor,finally,other} try-{catch,finally} cond-match-{all,none} \
    4                     raise-{fixup-empty,fixup-other})
     3readonly ALL_TESTS=(cond-match-{all,none} cross-{catch,finally} \
     4                raise-{detor,empty,finally,other})
    55
    66gen-file-name() (
     
    1818)
    1919
    20 #readonly N=${1:-5}
    21 readonly N=${1:-1}
     20readonly N=${1:-5}
    2221readonly OUT_FILE=$(gen-file-name ${2:-run-%-$N})
    2322
  • doc/theses/andrew_beach_MMath/code/test.sh

    rfe8aa21 rd00d581  
    44# test.sh LANGUAGE TEST
    55#   Run the TEST in LANGUAGE.
    6 # test.sh -a
    7 #   Build all tests.
    86# test.sh -b SOURCE_FILE...
    97#   Build a test from SOURCE_FILE(s).
    10 # test.sh -c
    11 #   Clean all executables.
    128# test.sh -v LANGUAGE TEST FILE
    139#   View the result from TEST in LANGUAGE stored in FILE.
    1410
    15 readonly ITERS_1M=1000000 # 1 000 000, one million
    16 readonly ITERS_10M=10000000 # 10 000 000, ten million
    17 readonly ITERS_100M=100000000 # 100 000 000, hundred million
    18 readonly ITERS_1000M=1000000000 # 1 000 000 000, billion
     11readonly ITERATIONS=1000000 # 1 000 000, one million
    1912readonly STACK_HEIGHT=100
    2013
     
    3124        *.cfa)
    3225                # Requires a symbolic link.
    33                 mmake "${1%.cfa}" "$1" cfa -DNDEBUG -nodebug -O3 "$1" -o "${1%.cfa}"
     26                mmake "${1%.cfa}" "$1" ./cfa -DNDEBUG -nodebug -O3 "$1" -o "${1%.cfa}"
    3427                ;;
    3528        *.cpp)
    36                 mmake "${1%.cpp}-cpp" "$1" g++-10 -DNDEBUG -O3 "$1" -o "${1%.cpp}-cpp"
     29                mmake "${1%.cpp}-cpp" "$1" g++ -DNDEBUG -O3 "$1" -o "${1%.cpp}-cpp"
    3730                ;;
    3831        *.java)
     
    4639)
    4740
    48 if [ "-a" = "$1" ]; then                        # build all
    49         for file in *.cfa *.cpp *.java; do
    50                 build $file
    51         done
    52         exit 0
    53 elif [ "-b" = "$1" ]; then                      # build given
     41if [ "-b" = "$1" ]; then
    5442        for file in "${@:2}"; do
    5543                build $file
    5644        done
    5745        exit 0
    58 elif [ "-c" = "$1" ]; then                      # clean all
    59         rm -f `basename -s ".cfa" -a *.cfa`
    60         rm -f `basename -s ".cpp" -a *.cpp`
    61         rm -f *-cpp
    62         rm -f *.class
    63         exit 0
    6446elif [ "-v" = "$1" -a 4 = "$#" ]; then
    65         TEST_LANG="$2"
    66         TEST_CASE="$3"
    67         VIEW_FILE="$4"
     47    TEST_LANG="$2"
     48    TEST_CASE="$3"
     49    VIEW_FILE="$4"
    6850elif [ 2 -eq "$#" ]; then
    6951        TEST_LANG="$1"
     
    8163
    8264case "$TEST_CASE" in
    83 raise-empty)
    84         CFAT="./throw-empty $ITERS_1M $STACK_HEIGHT"
    85 # see resume-fixup-empty-r      CFAR="./resume-empty $ITERS_1M $STACK_HEIGHT"
    86         CPP="./throw-empty-cpp $ITERS_1M $STACK_HEIGHT"
    87         JAVA="java ThrowEmpty $ITERS_1M $STACK_HEIGHT"
    88         PYTHON="./throw-empty.py $ITERS_1M $STACK_HEIGHT"
     65cond-match-all)
     66        CFAT="./cond-catch $ITERATIONS 1"
     67        CFAR="./cond-fixup $ITERATIONS 1"
     68        CPP="./cond-catch-cpp $ITERATIONS 1"
     69        JAVA="java CondCatch $ITERATIONS 1"
     70        PYTHON="./cond_catch.py $ITERATIONS 1"
     71        ;;
     72cond-match-none)
     73        CFAT="./cond-catch $ITERATIONS 0"
     74        CFAR="./cond-fixup $ITERATIONS 0"
     75        CPP="./cond-catch-cpp $ITERATIONS 0"
     76        JAVA="java CondCatch $ITERATIONS 0"
     77        PYTHON="./cond_catch.py $ITERATIONS 0"
     78        ;;
     79cross-catch)
     80        CFAT="./cross-catch $ITERATIONS"
     81        CFAR="./cross-resume $ITERATIONS"
     82        CPP="./cross-catch-cpp $ITERATIONS"
     83        JAVA="java CrossCatch $ITERATIONS"
     84        PYTHON="./cross_catch.py $ITERATIONS"
     85        ;;
     86cross-finally)
     87        CFAT="./cross-finally $ITERATIONS"
     88        CFAR=unsupported
     89        CPP=unsupported
     90        JAVA="java CrossFinally $ITERATIONS"
     91        PYTHON="./cross_finally.py $ITERATIONS"
    8992        ;;
    9093raise-detor)
    91         CFAT="./throw-detor $ITERS_1M $STACK_HEIGHT"
    92 # N/A   CFAR="./resume-detor $ITERS_1M $STACK_HEIGHT"
    93         CPP="./throw-detor-cpp $ITERS_1M $STACK_HEIGHT"
     94        CFAT="./throw-detor $ITERATIONS $STACK_HEIGHT"
     95        CFAR="./resume-detor $ITERATIONS $STACK_HEIGHT"
     96        CPP="./throw-detor-cpp $ITERATIONS $STACK_HEIGHT"
    9497        JAVA=unsupported
    9598        PYTHON=unsupported
    9699        ;;
     100raise-empty)
     101        CFAT="./throw-empty $ITERATIONS $STACK_HEIGHT"
     102        CFAR="./resume-empty $ITERATIONS $STACK_HEIGHT"
     103        CPP="./throw-empty-cpp $ITERATIONS $STACK_HEIGHT"
     104        JAVA="java ThrowEmpty $ITERATIONS $STACK_HEIGHT"
     105        PYTHON="./throw_empty.py $ITERATIONS $STACK_HEIGHT"
     106        ;;
    97107raise-finally)
    98         CFAT="./throw-finally $ITERS_1M $STACK_HEIGHT"
    99 # N/A   CFAR="./resume-finally $ITERS_1M $STACK_HEIGHT"
     108        CFAT="./throw-finally $ITERATIONS $STACK_HEIGHT"
     109        CFAR="./resume-finally $ITERATIONS $STACK_HEIGHT"
    100110        CPP=unsupported
    101         JAVA="java ThrowFinally $ITERS_1M $STACK_HEIGHT"
    102         PYTHON="./throw-finally.py $ITERS_1M $STACK_HEIGHT"
     111        JAVA="java ThrowFinally $ITERATIONS $STACK_HEIGHT"
     112        PYTHON="./throw_finally.py $ITERATIONS $STACK_HEIGHT"
    103113        ;;
    104114raise-other)
    105         CFAT="./throw-other $ITERS_1M $STACK_HEIGHT"
    106 # N/A   CFAR="./resume-other $ITERS_1M $STACK_HEIGHT"
    107         CPP="./throw-other-cpp $ITERS_1M $STACK_HEIGHT"
    108         JAVA="java ThrowOther $ITERS_1M $STACK_HEIGHT"
    109         PYTHON="./throw-other.py $ITERS_1M $STACK_HEIGHT"
    110         ;;
    111 try-catch)
    112         CFAT="./try-catch $ITERS_1000M"
    113         CFAR="./try-resume $ITERS_1000M"
    114         CPP="./try-catch-cpp $ITERS_1000M"
    115         JAVA="java TryCatch $ITERS_1000M"
    116         PYTHON="./try-catch.py $ITERS_1000M"
    117         ;;
    118 try-finally)
    119         CFAT="./try-finally $ITERS_1000M"
    120         CFAR=unsupported
    121         CPP=unsupported
    122         JAVA="java TryFinally $ITERS_1000M"
    123         PYTHON="./try-finally.py $ITERS_1000M"
    124         ;;
    125 cond-match-all)
    126         CFAT="./cond-catch $ITERS_10M 1"
    127         CFAR="./cond-fixup $ITERS_10M 1"
    128         CPP="./cond-catch-cpp $ITERS_10M 1"
    129         JAVA="java CondCatch $ITERS_10M 1"
    130         PYTHON="./cond-catch.py $ITERS_10M 1"
    131         ;;
    132 cond-match-none)
    133         CFAT="./cond-catch $ITERS_10M 0"
    134         CFAR="./cond-fixup $ITERS_10M 0"
    135         CPP="./cond-catch-cpp $ITERS_10M 0"
    136         JAVA="java CondCatch $ITERS_10M 0"
    137         PYTHON="./cond-catch.py $ITERS_10M 0"
    138         ;;
    139 raise-fixup-empty)
    140         CFAT="./resume-fixup-empty-f $ITERS_10M $STACK_HEIGHT"
    141         CFAR="./resume-fixup-empty-r $ITERS_10M $STACK_HEIGHT"
    142         CPP="./resume-fixup-empty-cpp $ITERS_10M $STACK_HEIGHT"
    143         JAVA="java ResumeFixupEmpty $ITERS_10M $STACK_HEIGHT"
    144         PYTHON="./resume-fixup-empty.py $ITERS_10M $STACK_HEIGHT"
    145         ;;
    146 raise-fixup-other)
    147         CFAT="./resume-fixup-other-f $ITERS_10M $STACK_HEIGHT"
    148         CFAR="./resume-fixup-other-r $ITERS_10M $STACK_HEIGHT"
    149         CPP="./resume-fixup-other-cpp $ITERS_10M $STACK_HEIGHT"
    150         JAVA="java ResumeFixupOther $ITERS_10M $STACK_HEIGHT"
    151         PYTHON="./resume-fixup-other.py $ITERS_10M $STACK_HEIGHT"
     115        CFAT="./throw-other $ITERATIONS $STACK_HEIGHT"
     116        CFAR="./resume-other $ITERATIONS $STACK_HEIGHT"
     117        CPP="./throw-other-cpp $ITERATIONS $STACK_HEIGHT"
     118        JAVA="java ThrowOther $ITERATIONS $STACK_HEIGHT"
     119        PYTHON="./throw_other.py $ITERATIONS $STACK_HEIGHT"
    152120        ;;
    153121*)
     
    158126
    159127case "$TEST_LANG" in
    160         cfa-t) CALL="$CFAT";;
    161         cfa-r) CALL="$CFAR";;
    162         cpp) CALL="$CPP";;
    163         java) CALL="$JAVA";;
    164         python) CALL="$PYTHON";;
    165         *)
    166                 echo "No such language: $TEST_LANG" >&2
    167                 exit 2
     128cfa-t) CALL="$CFAT";;
     129cfa-r) CALL="$CFAR";;
     130cpp) CALL="$CPP";;
     131java) CALL="$JAVA";;
     132python) CALL="$PYTHON";;
     133*)
     134        echo "No such language: $TEST_LANG" >&2
     135        exit 2
    168136        ;;
    169137esac
     
    172140
    173141if [ -n "$VIEW_FILE" ]; then
    174         grep -A 1 -B 0 "$CALL" "$VIEW_FILE" | sed -n -e 's!Run-Time (ns): !!;T;p'
    175         exit
     142    grep -A 1 -B 0 "$CALL" "$VIEW_FILE" | sed -n -e 's!Run-Time (ns): !!;T;p'
     143    exit
    176144fi
    177145
  • doc/theses/andrew_beach_MMath/code/throw-detor.cfa

    rfe8aa21 rd00d581  
    33#include <exception.hfa>
    44#include <fstream.hfa>
    5 #include <stdlib.hfa>                                                                   // strto
     5#include <stdlib.hfa>
    66
    7 exception empty_exception;
    8 vtable(empty_exception) empty_vt;
     7EHM_EXCEPTION(empty_exception)();
     8
     9EHM_VIRTUAL_TABLE(empty_exception, empty_vt);
    910
    1011struct WithDestructor {};
     
    2728        unsigned int total_frames = 1;
    2829        if (1 < argc) {
    29                 times = strto(argv[1], 0p, 10);
     30                times = strtol(argv[1], 0p, 10);
    3031        }
    3132        if (2 < argc) {
    32                 total_frames = strto(argv[2], 0p, 10);
     33                total_frames = strtol(argv[2], 0p, 10);
    3334        }
    3435
     
    4243        }
    4344        Time end_time = timeHiRes();
    44         sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.);
     45        sout | "Run-Time (ns): " | (end_time - start_time)`ns;
    4546}
  • doc/theses/andrew_beach_MMath/code/throw-detor.cpp

    rfe8aa21 rd00d581  
    44#include <exception>
    55#include <iostream>
    6 #include <iomanip>
    76
    8 using namespace std;
    97using namespace std::chrono;
    108
     
    4644        time_point<steady_clock> end_time = steady_clock::now();
    4745        nanoseconds duration = duration_cast<nanoseconds>(end_time - start_time);
    48         cout << "Run-Time (s): " << fixed << setprecision(1) << duration.count() / 1'000'000'000. << endl;
     46        std::cout << "Run-Time (ns): " << duration.count() << std::endl;
    4947}
  • doc/theses/andrew_beach_MMath/code/throw-empty.cfa

    rfe8aa21 rd00d581  
    33#include <exception.hfa>
    44#include <fstream.hfa>
    5 #include <stdlib.hfa>                                                                   // strto
     5#include <stdlib.hfa>
    66
    7 exception empty_exception;
    8 vtable(empty_exception) empty_vt;
     7EHM_EXCEPTION(empty_exception)();
     8
     9EHM_VIRTUAL_TABLE(empty_exception, empty_vt);
    910
    1011void unwind_empty(unsigned int frames) {
     
    2021        unsigned int total_frames = 1;
    2122        if (1 < argc) {
    22                 times = strto(argv[1], 0p, 10);
     23                times = strtol(argv[1], 0p, 10);
    2324        }
    2425        if (2 < argc) {
    25                 total_frames = strto(argv[2], 0p, 10);
     26                total_frames = strtol(argv[2], 0p, 10);
    2627        }
    2728
     
    3536        }
    3637        Time end_time = timeHiRes();
    37         sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.);
     38        sout | "Run-Time (ns): " | (end_time - start_time)`ns;
    3839}
  • doc/theses/andrew_beach_MMath/code/throw-empty.cpp

    rfe8aa21 rd00d581  
    44#include <exception>
    55#include <iostream>
    6 #include <iomanip>
    76
    8 using namespace std;
    97using namespace std::chrono;
    108
     
    3937        time_point<steady_clock> end_time = steady_clock::now();
    4038        nanoseconds duration = duration_cast<nanoseconds>(end_time - start_time);
    41         cout << "Run-Time (s): " << fixed << setprecision(1) << duration.count() / 1'000'000'000. << endl;
     39        std::cout << "Run-Time (ns): " << duration.count() << std::endl;
    4240}
  • doc/theses/andrew_beach_MMath/code/throw-finally.cfa

    rfe8aa21 rd00d581  
    33#include <exception.hfa>
    44#include <fstream.hfa>
    5 #include <stdlib.hfa>                                                                   // strto
     5#include <stdlib.hfa>
    66
    7 exception empty_exception;
    8 vtable(empty_exception) empty_vt;
     7EHM_EXCEPTION(empty_exception)();
    98
    10 unsigned int frames;                                                                    // use global because of gcc thunk problem
     9EHM_VIRTUAL_TABLE(empty_exception, empty_vt);
    1110
    12 void unwind_finally(unsigned int dummy) {
     11void unwind_finally(unsigned int frames) {
    1312        if (frames) {
    14                 frames -= 1;
    1513                try {
    16                         unwind_finally(42);
     14                        unwind_finally(frames - 1);
    1715                } finally {
    1816                        asm volatile ("# finally block");
    1917                }
    2018        } else {
    21                 dummy = 42;
    2219                throw (empty_exception){&empty_vt};
    2320        }
     
    2825        unsigned int total_frames = 1;
    2926        if (1 < argc) {
    30                 times = strto(argv[1], 0p, 10);
     27                times = strtol(argv[1], 0p, 10);
    3128        }
    3229        if (2 < argc) {
    33                 total_frames = strto(argv[2], 0p, 10);
     30                total_frames = strtol(argv[2], 0p, 10);
    3431        }
    35         frames = total_frames;
    3632
    3733        Time start_time = timeHiRes();
    3834        for (int count = 0 ; count < times ; ++count) {
    3935                try {
    40                         unwind_finally(42);
     36                        unwind_finally(total_frames);
    4137                } catch (empty_exception *) {
    4238                        asm volatile ("# catch block");
     
    4440        }
    4541        Time end_time = timeHiRes();
    46         sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.);
     42        sout | "Run-Time (ns): " | (end_time - start_time)`ns;
    4743}
  • doc/theses/andrew_beach_MMath/code/throw-other.cfa

    rfe8aa21 rd00d581  
    33#include <exception.hfa>
    44#include <fstream.hfa>
    5 #include <stdlib.hfa>                                                                   // strto
     5#include <stdlib.hfa>
    66
    7 exception empty_exception;
    8 vtable(empty_exception) empty_vt;
    9 exception not_raised_exception;
     7EHM_EXCEPTION(empty_exception)();
    108
    11 unsigned int frames;                                                                    // use global because of gcc thunk problem
     9EHM_VIRTUAL_TABLE(empty_exception, empty_vt);
    1210
    13 void unwind_other(unsigned int dummy) {
     11EHM_EXCEPTION(not_raised_exception)();
     12
     13void unwind_other(unsigned int frames) {
    1414        if (frames) {
    15                 frames -= 1;
    1615                try {
    17                         unwind_other(42);
     16                        unwind_other(frames - 1);
    1817                } catch (not_raised_exception *) {
    1918                        asm volatile ("# catch block (stack)");
    2019                }
    2120        } else {
    22                 dummy = 42;
    2321                throw (empty_exception){&empty_vt};
    2422        }
     
    2927        unsigned int total_frames = 1;
    3028        if (1 < argc) {
    31                 times = strto(argv[1], 0p, 10);
     29                times = strtol(argv[1], 0p, 10);
    3230        }
    3331        if (2 < argc) {
    34                 total_frames = strto(argv[2], 0p, 10);
     32                total_frames = strtol(argv[2], 0p, 10);
    3533        }
    36         frames = total_frames;
    3734
    3835        Time start_time = timeHiRes();
    3936        for (int count = 0 ; count < times ; ++count) {
    4037                try {
    41                         unwind_other(42);
     38                        unwind_other(total_frames);
    4239                } catch (empty_exception *) {
    4340                        asm volatile ("# catch block (base)");
     
    4542        }
    4643        Time end_time = timeHiRes();
    47         sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.);
     44        sout | "Run-Time (ns): " | (end_time - start_time)`ns;
    4845}
  • doc/theses/andrew_beach_MMath/code/throw-other.cpp

    rfe8aa21 rd00d581  
    44#include <exception>
    55#include <iostream>
    6 #include <iomanip>
    76
    8 using namespace std;
    97using namespace std::chrono;
    108
     
    4543        time_point<steady_clock> end_time = steady_clock::now();
    4644        nanoseconds duration = duration_cast<nanoseconds>(end_time - start_time);
    47         cout << "Run-Time (s): " << fixed << setprecision(1) << duration.count() / 1'000'000'000. << endl;
     45        std::cout << "Run-Time (ns): " << duration.count() << std::endl;
    4846}
  • doc/theses/andrew_beach_MMath/performance.tex

    rfe8aa21 rd00d581  
    33
    44Performance is of secondary importance for most of this project.
    5 Instead, the focus was to get the features working. The only performance
     5Instead, the focus is to get the features working. The only performance
    66requirement is to ensure the tests for correctness run in a reasonable
    7 amount of time. Hence, a few basic performance tests were performed to
    8 check this requirement.
     7amount of time.
    98
    109\section{Test Set-Up}
     
    1514C++ is the most comparable language because both it and \CFA use the same
    1615framework, libunwind.
    17 In fact, the comparison is almost entirely a quality of implementation.
    18 Specifically, \CFA's EHM has had significantly less time to be optimized and
     16In fact, the comparison is almost entirely a quality of implementation
     17comparison: \CFA's EHM has had significantly less time to be optimized and
    1918does not generate its own assembly. It does have a slight advantage in that
    2019there are some features it handles directly instead of through utility functions,
    21 but otherwise \Cpp should have a significant advantage.
    22 
    23 Java is a popular language with similar termination semantics, but
    24 it is implemented in a very different environment, a virtual machine with
     20but otherwise \Cpp has a significant advantage.
     21
     22Java is another very popular language with similar termination semantics.
     23It is implemented in a very different environment, a virtual machine with
    2524garbage collection.
    2625It also implements the @finally@ clause on @try@ blocks allowing for a direct
    2726feature-to-feature comparison.
    28 As with \Cpp, Java's implementation is mature, optimized
     27As with \Cpp, Java's implementation is mature, optimizations
    2928and has extra features.
    3029
    31 Python is used as an alternative comparison because of the \CFA EHM's
     30Python is used as an alternative point of comparison because of the \CFA EHM's
    3231current performance goals, which is not to be prohibitively slow while the
    3332features are designed and examined. Python has similar performance goals for
     
    3736resumption exceptions. Even the older programming languages with resumption
    3837seem to be notable only for having resumption.
    39 So instead, resumption is compared to its simulation in other programming
    40 languages using fixup functions that are explicitly passed for correction or
    41 logging purposes.
    42 % So instead, resumption is compared to a less similar but much more familiar
    43 %feature, termination exceptions.
     38So instead, resumption is compared to a less similar but much more familiar
     39feature, termination exceptions.
    4440
    4541All tests are run inside a main loop that repeatedly performs a test.
    4642This approach avoids start-up or tear-down time from
    4743affecting the timing results.
    48 Each test is run a N times (configurable from the command line).
    49 The Java tests runs the main loop 1000 times before
    50 beginning the actual test to ``warm-up" the JVM.
     44Each test is run a million times.
     45The Java versions of the test run this loop an extra 1000 times before
     46beginning to actual test to ``warm-up" the JVM.
    5147
    5248Timing is done internally, with time measured immediately before and
     
    7066
    7167The tests are compiled with gcc-10 for \CFA and g++-10 for \Cpp. Java is
    72 compiled with version 11.0.11. Python with version 3.8. The tests were run on:
     68compiled with 11.0.11. Python with 3.8. The tests were run on:
    7369\begin{itemize}[nosep]
    7470\item
     
    7773AMD 6380 Abu Dhabi 16-core 4$\times$socket \lstinline{@} 2.5 GHz running Linux v5.11.0-25
    7874\end{itemize}
    79 Two kinds of hardware architecture allows discriminating any implementation and
    80 architectural effects.
    81 
    8275
    8376% We don't use catch-alls but if we did:
     
    9184
    9285\paragraph{Raise and Handle}
    93 This group measures the cost of a try statement when exceptions are raised and
    94 the stack is unwound (termination) or not unwound (resumption).  Each test has
    95 has a repeating function like the following
    96 \begin{lstlisting}[language=CFA,{moredelim=**[is][\color{red}]{@}{@}}]
     86The first group measures the cost of a try statement when exceptions are raised
     87and \emph{the stack is unwound}.  Each test has has a repeating function like
     88the following
     89\begin{cfa}
    9790void unwind_empty(unsigned int frames) {
    9891        if (frames) {
    99                 @unwind_empty(frames - 1);@ // AUGMENTED IN OTHER EXPERIMENTS
     92                unwind_empty(frames - 1);
    10093        } else throw (empty_exception){&empty_vt};
    10194}
    102 \end{lstlisting}
    103 which is called N times, where each call recurses to a depth of R (configurable from the command line), an
     95\end{cfa}
     96which is called M times, where each call recurses to a depth of N, an
    10497exception is raised, the stack is a unwound, and the exception caught.
    10598\begin{itemize}[nosep]
    10699\item Empty:
    107 For termination, this test measures the cost of raising (stack walking) an
    108 exception through empty stack frames from the bottom of the recursion to an
    109 empty handler, and unwinding the stack. (see above code)
    110 
    111 \medskip
    112 For resumption, this test measures the same raising cost but does not unwind
    113 the stack. For languages without resumption, a fixup function is to the bottom
    114 of the recursion and called to simulate a fixup operation at that point.
    115 \begin{cfa}
    116 void nounwind_fixup(unsigned int frames, void (*raised_rtn)(int &)) {
    117         if (frames) {
    118                 nounwind_fixup(frames - 1, raised_rtn);
    119         } else {
    120                 int fixup = 17;
    121                 raised_rtn(fixup);
    122         }
    123 }
    124 \end{cfa}
    125 where the passed fixup function is:
    126 \begin{cfa}
    127 void raised(int & fixup) {
    128         fixup = 42;
    129 }
    130 \end{cfa}
    131 For comparison, a \CFA version passing a function is also included.
     100This test measures the cost of raising (stack walking) an exception through empty
     101empty stack frames to an empty handler. (see above)
    132102\item Destructor:
    133 This test measures the cost of raising an exception through non-empty frames,
    134 where each frame has an object requiring destruction, from the bottom of the
    135 recursion to an empty handler. Hence, there are N destructor calls during
    136 unwinding.
    137 
    138 \medskip
    139 This test is not meaningful for resumption because the stack is only unwound as
    140 the recursion returns.
    141 \begin{cfa}
     103
     104This test measures the cost of raising an exception through non-empty frames
     105where each frame has an object requiring destruction, to an empty
     106handler. Hence, there are N destructor calls during unwinding.
     107\begin{cfa}
     108if (frames) {
    142109        WithDestructor object;
    143         unwind_destructor(frames - 1);
     110        unwind_empty(frames - 1);
    144111\end{cfa}
    145112\item Finally:
    146113This test measures the cost of establishing a try block with an empty finally
    147 clause on the front side of the recursion and running the empty finally clauses
    148 during stack unwinding from the bottom of the recursion to an empty handler.
    149 \begin{cfa}
     114clause on the front side of the recursion and running the empty finally clause
     115on the back side of the recursion during stack unwinding.
     116\begin{cfa}
     117if (frames) {
    150118        try {
    151119                unwind_finally(frames - 1);
    152120        } finally {}
    153121\end{cfa}
    154 
    155 \medskip
    156 This test is not meaningful for resumption because the stack is only unwound as
    157 the recursion returns.
    158122\item Other Handler:
    159 For termination, this test is like the finally test but the try block has a
    160 catch clause for an exception that is not raised, so catch matching is executed
    161 during stack unwinding but the match never successes until the catch at the
    162 bottom of the recursion.
    163 \begin{cfa}
     123This test is like the finally test but the try block has a catch clause for an
     124exception that is not raised, so catch matching is executed during stack
     125unwinding but the match never successes until the catch at the bottom of the
     126stack.
     127\begin{cfa}
     128if (frames) {
    164129        try {
    165130                unwind_other(frames - 1);
    166131        } catch (not_raised_exception *) {}
    167132\end{cfa}
    168 
    169 \medskip
    170 For resumption, this test measures the same raising cost but does not unwind
    171 the stack. For languages without resumption, the same fixup function is passed
    172 and called.
    173 \end{itemize}
    174 
    175 \paragraph{Try/Handle/Finally Statement}
    176 This group measures just the cost of executing a try statement so
     133\end{itemize}
     134
     135\paragraph{Cross Try Statement}
     136The next group measures just the cost of executing a try statement so
    177137\emph{there is no stack unwinding}.  Hence, the program main loops N times
    178138around:
     
    183143\begin{itemize}[nosep]
    184144\item Handler:
    185 The try statement has a handler (catch/resume).
     145The try statement has a handler.
    186146\item Finally:
    187 The try statement has a finally clause.
     147The try statement replaces the handler with a finally clause.
    188148\end{itemize}
    189149
    190150\paragraph{Conditional Matching}
    191 This group measures the cost of conditional matching.
     151This final group measures the cost of conditional matching.
    192152Only \CFA implements the language level conditional match,
    193 the other languages mimic with an ``unconditional" match (it still
    194 checks the exception's type) and conditional re-raise if it is not suppose
     153the other languages must mimic with an ``unconditional" match (it still
     154checks the exception's type) and conditional re-raise if it was not supposed
    195155to handle that exception.
    196156\begin{center}
     
    221181\end{itemize}
    222182
    223 \medskip
    224 \noindent
    225 All omitted test code for other languages is functionally identical to the \CFA
    226 tests or simulated, and available online~\cite{CforallExceptionBenchmarks}.
    227 
    228183%\section{Cost in Size}
    229184%Using exceptions also has a cost in the size of the executable.
     
    237192
    238193\section{Results}
    239 One result not directly related to \CFA but important to keep in
    240 mind is that, for exceptions, the standard intuition about which languages
    241 should go faster often does not hold. For example, there are a few cases where Python out-performs
    242 \CFA, \Cpp and Java. The most likely explanation is that, since exceptions are
    243 rarely considered to be the common case, the more optimized languages
    244 make that case expense. In addition, languages with high-level
    245 representations have a much easier time scanning the stack as there is less
    246 to decode.
    247 
    248 Tables~\ref{t:PerformanceTermination} and~\ref{t:PerformanceResumption} show
    249 the test results for termination and resumption, respectively.  In cases where
    250 a feature is not supported by a language, the test is skipped for that language
    251 (marked N/A).  For some Java experiments it was impossible to measure certain
    252 effects because the JIT corrupted the test (marked N/C). No workaround was
    253 possible~\cite{Dice21}.  To get experiments in the range of 1--100 seconds, the
    254 number of times an experiment is run (N) is varied (N is marked beside each
    255 experiment, e.g., 1M $\Rightarrow$ 1 million test iterations).
    256 
    257 An anomaly exists with gcc nested functions used as thunks for implementing
    258 much of the \CFA EHM. If a nested-function closure captures local variables in
    259 its lexical scope, performance dropped by a factor of 10.  Specifically, in try
    260 statements of the form:
    261 \begin{cfa}
    262         try {
    263                 unwind_other(frames - 1);
    264         } catch (not_raised_exception *) {}
    265 \end{cfa}
    266 the try block is hoisted into a nested function and the variable @frames@ is
    267 the local parameter to the recursive function, which triggers the anomaly. The
    268 workaround is to remove the recursion parameter and make it a global variable
    269 that is explicitly decremented outside of the try block (marked with a ``*''):
    270 \begin{cfa}
    271         frames -= 1;
    272         try {
    273                 unwind_other();
    274         } catch (not_raised_exception *) {}
    275 \end{cfa}
    276 To make comparisons fair, a dummy parameter is added and the dummy value passed
    277 in the recursion. Note, nested functions in gcc are rarely used (if not
    278 completely unknown) and must follow the C calling convention, unlike \Cpp
    279 lambdas, so it is not surprising if there are performance issues efficiently
    280 capturing closures.
    281 
    282 % Similarly, if a test does not change between resumption
    283 % and termination in \CFA, then only one test is written and the result
    284 % was put into the termination column.
     194In cases where a feature is not supported by a language the test is skipped
     195for that language.
     196\PAB{Report all values.
     197
     198Similarly, if a test does not change between resumption
     199and termination in \CFA, then only one test is written and the result
     200was put into the termination column.
     201}
    285202
    286203% Raw Data:
     
    318235% Match None    & 0.0 & 0.0 &  9476060146 & 0.0 & 0.0 \\
    319236
     237\begin{tabular}{|l|c c c c c|}
     238\hline
     239              & \CFA (Terminate) & \CFA (Resume) & \Cpp & Java & Python \\
     240\hline
     241Raise Empty   & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
     242Raise D'tor   & 0.0 & 0.0 & 0.0 & N/A & N/A \\
     243Raise Finally & 0.0 & 0.0 & N/A & 0.0 & 0.0 \\
     244Raise Other   & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
     245Cross Handler & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
     246Cross Finally & 0.0 & N/A & N/A & 0.0 & 0.0 \\
     247Match All     & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
     248Match None    & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
     249\hline
     250\end{tabular}
     251
    320252% run-plg7a-a.sat
    321253% ---------------
     
    352284% Match None    & 0.0 & 0.0 &  7829059869 & 0.0 & 0.0 \\
    353285
    354 \begin{table}
    355 \centering
    356 \caption{Performance Results Termination (sec)}
    357 \label{t:PerformanceTermination}
    358 \begin{tabular}{|r|*{2}{|r r r r|}}
    359 \hline
    360                         & \multicolumn{4}{c||}{AMD}             & \multicolumn{4}{c|}{ARM}      \\
    361 \cline{2-9}
    362 N\hspace{8pt}           & \multicolumn{1}{c}{\CFA} & \multicolumn{1}{c}{\Cpp} & \multicolumn{1}{c}{Java} & \multicolumn{1}{c||}{Python} &
    363                           \multicolumn{1}{c}{\CFA} & \multicolumn{1}{c}{\Cpp} & \multicolumn{1}{c}{Java} & \multicolumn{1}{c|}{Python} \\
    364 \hline                                                                             
    365 Throw Empty (1M)        & 3.4   & 2.8   & 18.3  & 23.4          & 3.7   & 3.2   & 15.5  & 14.8  \\
    366 Throw D'tor (1M)        & 48.4  & 23.6  & N/A   & N/A           & 64.2  & 29.0  & N/A   & N/A   \\
    367 Throw Finally (1M)      & 3.4*  & N/A   & 17.9  & 29.0          & 4.1*  & N/A   & 15.6  & 19.0  \\
    368 Throw Other (1M)        & 3.6*  & 23.2  & 18.2  & 32.7          & 4.0*  & 24.5  & 15.5  & 21.4  \\
    369 Try/Catch (100M)        & 6.0   & 0.9   & N/C   & 37.4          & 10.0  & 0.8   & N/C   & 32.2  \\
    370 Try/Finally (100M)      & 0.9   & N/A   & N/C   & 44.1          & 0.8   & N/A   & N/C   & 37.3  \\
    371 Match All (10M)         & 32.9  & 20.7  & 13.4  & 4.9           & 36.2  & 24.5  & 12.0  & 3.1   \\
    372 Match None (10M)        & 32.7  & 50.3  & 11.0  & 5.1           & 36.3  & 71.9  & 12.3  & 4.2   \\
     286% PLG7A (in seconds)
     287\begin{tabular}{|l|c c c c c|}
     288\hline
     289              & \CFA (Terminate) & \CFA (Resume) & \Cpp & Java & Python \\
     290\hline
     291Raise Empty   & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
     292Raise D'tor   & 0.0 & 0.0 & 0.0 & N/A & N/A \\
     293Raise Finally & 0.0 & 0.0 & N/A & 0.0 & 0.0 \\
     294Raise Other   & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
     295Cross Handler & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
     296Cross Finally & 0.0 & N/A & N/A & 0.0 & 0.0 \\
     297Match All     & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
     298Match None    & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
    373299\hline
    374300\end{tabular}
    375 \end{table}
    376 
    377 \begin{table}
    378 \centering
    379 \small
    380 \caption{Performance Results Resumption (sec)}
    381 \label{t:PerformanceResumption}
    382 \setlength{\tabcolsep}{5pt}
    383 \begin{tabular}{|r|*{2}{|r r r r|}}
    384 \hline
    385                         & \multicolumn{4}{c||}{AMD}             & \multicolumn{4}{c|}{ARM}      \\
    386 \cline{2-9}
    387 N\hspace{8pt}           & \multicolumn{1}{c}{\CFA (R/F)} & \multicolumn{1}{c}{\Cpp} & \multicolumn{1}{c}{Java} & \multicolumn{1}{c||}{Python} &
    388                           \multicolumn{1}{c}{\CFA (R/F)} & \multicolumn{1}{c}{\Cpp} & \multicolumn{1}{c}{Java} & \multicolumn{1}{c|}{Python} \\
    389 \hline                                                                             
    390 Resume Empty (10M)      & 3.8/3.5       & 14.7  & 2.3   & 176.1 & 0.3/0.1       & 8.9   & 1.2   & 119.9 \\
    391 Resume Other (10M)      & 4.0*/0.1*     & 21.9  & 6.2   & 381.0 & 0.3*/0.1*     & 13.2  & 5.0   & 290.7 \\
    392 Try/Resume (100M)       & 8.8           & N/A   & N/A   & N/A   & 12.3          & N/A   & N/A   & N/A   \\
    393 Match All (10M)         & 0.3           & N/A   & N/A   & N/A   & 0.3           & N/A   & N/A   & N/A   \\
    394 Match None (10M)        & 0.3           & N/A   & N/A   & N/A   & 0.4           & N/A   & N/A   & N/A   \\
    395 \hline
    396 \end{tabular}
    397 \end{table}
    398 
    399 As stated, the performance tests are not attempting to compare exception
    400 handling across languages.  The only performance requirement is to ensure the
    401 \CFA EHM implementation runs in a reasonable amount of time, given its
    402 constraints. In general, the \CFA implement did very well. Each of the tests is
    403 analysed.
    404 \begin{description}
    405 \item[Throw/Resume Empty]
    406 For termination, \CFA is close to \Cpp, where other languages have a higher cost.
    407 
    408 For resumption, \CFA is better than the fixup simulations in the other languages, except Java.
    409 The \CFA results on the ARM computer for both resumption and function simulation are particularly low;
    410 I have no explanation for this anomaly, except the optimizer has managed to remove part of the experiment.
    411 Python has a high cost for passing the lambda during the recursion.
    412 
    413 \item[Throw D'tor]
    414 For termination, \CFA is twice the cost of \Cpp.
    415 The higher cost for \CFA must be related to how destructors are handled.
    416 
    417 \item[Throw Finally]
    418 \CFA is better than the other languages with a @finally@ clause, which is the
    419 same for termination and resumption.
    420 
    421 \item[Throw/Resume Other]
    422 For termination, \CFA is better than the other languages.
    423 
    424 For resumption, \CFA is equal to or better the other languages.
    425 Again, the \CFA results on the ARM computer for both resumption and function simulation are particularly low.
    426 Python has a high cost for passing the lambda during the recursion.
    427 
    428 \item[Try/Catch/Resume]
    429 For termination, installing a try statement is more expressive than \Cpp
    430 because the try components are hoisted into local functions.  At runtime, these
    431 functions are than passed to libunwind functions to set up the try statement.
    432 \Cpp zero-cost try-entry accounts for its performance advantage.
    433 
    434 For resumption, there are similar costs to termination to set up the try
    435 statement but libunwind is not used.
    436 
    437 \item[Try/Finally]
    438 Setting up a try finally is less expensive in \CFA than setting up handlers,
    439 and is significantly less than other languages.
    440 
    441 \item[Throw/Resume Match All]
    442 For termination, \CFA is close to the other language simulations.
    443 
    444 For resumption, the stack unwinding is much faster because it does not use
    445 libunwind.  Instead resumption is just traversing a linked list with each node
    446 being the next stack frame with the try block.
    447 
    448 \item[Throw/Resume Match None]
    449 The same results as for Match All.
    450 \end{description}
    451 
    452 \begin{comment}
    453 This observation means that while \CFA does not actually keep up with Python in
    454 every case, it is usually no worse than roughly half the speed of \Cpp. This
    455 performance is good enough for the prototyping purposes of the project.
     301
     302One result not directly related to \CFA but important to keep in
     303mind is that, for exceptions, the standard intuition about which languages
     304should go faster often does not hold. For example, there are cases where Python out-performs
     305\Cpp and Java. The most likely explanation is that, since exceptions are
     306rarely considered to be the common case, the more optimized languages
     307make that case expense. In addition, languages with high-level
     308representations have a much easier time scanning the stack as there is less
     309to decode.
     310
     311This observation means that while \CFA does not actually keep up with Python in every
     312case, it is usually no worse than roughly half the speed of \Cpp. This performance is good
     313enough for the prototyping purposes of the project.
    456314
    457315The test case where \CFA falls short is Raise Other, the case where the
    458316stack is unwound including a bunch of non-matching handlers.
    459317This slowdown seems to come from missing optimizations.
     318
     319Importantly, there is a huge slowdown in \Cpp's results bringing that brings
     320\CFA's performance back in that roughly half speed area. However many other
     321\CFA benchmarks increase their run-time by a similar amount falling far
     322behind their \Cpp counter-parts.
    460323
    461324This suggests that the performance issue in Raise Other is just an
     
    501364The difference in relative performance does show that there are savings to
    502365be made by performing the check without catching the exception.
    503 \end{comment}
    504 
    505 
    506 \begin{comment}
    507 From: Dave Dice <dave.dice@oracle.com>
    508 To: "Peter A. Buhr" <pabuhr@uwaterloo.ca>
    509 Subject: Re: [External] : JIT
    510 Date: Mon, 16 Aug 2021 01:21:56 +0000
    511 
    512 > On 2021-8-15, at 7:14 PM, Peter A. Buhr <pabuhr@uwaterloo.ca> wrote:
    513 >
    514 > My student is trying to measure the cost of installing a try block with a
    515 > finally clause in Java.
    516 >
    517 > We tried the random trick (see below). But if the try block is comment out, the
    518 > results are the same. So the program measures the calls to the random number
    519 > generator and there is no cost for installing the try block.
    520 >
    521 > Maybe there is no cost for a try block with an empty finally, i.e., the try is
    522 > optimized away from the get-go.
    523 
    524 There's quite a bit of optimization magic behind the HotSpot curtains for
    525 try-finally.  (I sound like the proverbial broken record (:>)).
    526 
    527 In many cases we can determine that the try block can't throw any exceptions,
    528 so we can elide all try-finally plumbing.  In other cases, we can convert the
    529 try-finally to normal if-then control flow, in the case where the exception is
    530 thrown into the same method.  This makes exceptions _almost cost-free.  If we
    531 actually need to "physically" rip down stacks, then things get expensive,
    532 impacting both the throw cost, and inhibiting other useful optimizations at the
    533 catch point.  Such "true" throws are not just expensive, they're _very
    534 expensive.  The extremely aggressive inlining used by the JIT helps, because we
    535 can convert cases where a heavy rip-down would normally needed back into simple
    536 control flow.
    537 
    538 Other quirks involve the thrown exception object.  If it's never accessed then
    539 we're apply a nice set of optimizations to avoid its construction.  If it's
    540 accessed but never escapes the catch frame (common) then we can also cheat.
    541 And if we find we're hitting lots of heavy rip-down cases, the JIT will
    542 consider recompilation - better inlining -- to see if we can merge the throw
    543 and catch into the same physical frame, and shift to simple branches.
    544 
    545 In your example below, System.out.print() can throw, I believe.  (I could be
    546 wrong, but most IO can throw).  Native calls that throw will "unwind" normally
    547 in C++ code until they hit the boundary where they reenter java emitted code,
    548 at which point the JIT-ed code checks for a potential pending exception.  So in
    549 a sense the throw point is implicitly after the call to the native method, so
    550 we can usually make those cases efficient.
    551 
    552 Also, when we're running in the interpreter and warming up, we'll notice that
    553 the == 42 case never occurs, and so when we start to JIT the code, we elide the
    554 call to System.out.print(), replacing it (and anything else which appears in
    555 that if x == 42 block) with a bit of code we call an "uncommon trap".  I'm
    556 presuming we encounter 42 rarely.  So if we ever hit the x == 42 case, control
    557 hits the trap, which triggers synchronous recompilation of the method, this
    558 time with the call to System.out.print() and, because of that, we now to adapt
    559 the new code to handle any traps thrown by print().  This is tricky stuff, as
    560 we may need to rebuild stack frames to reflect the newly emitted method.  And
    561 we have to construct a weird bit of "thunk" code that allows us to fall back
    562 directly into the newly emitted "if" block.  So there's a large one-time cost
    563 when we bump into the uncommon trap and recompile, and subsequent execution
    564 might get slightly slower as the exception could actually be generated, whereas
    565 before we hit the trap, we knew the exception could never be raised.
    566 
    567 Oh, and things also get expensive if we need to actually fill in the stack
    568 trace associated with the exception object.  Walking stacks is hellish.
    569 
    570 Quite a bit of effort was put into all this as some of the specjvm benchmarks
    571 showed significant benefit.
    572 
    573 It's hard to get sensible measurements as the JIT is working against you at
    574 every turn.  What's good for the normal user is awful for anybody trying to
    575 benchmark.  Also, all the magic results in fairly noisy and less reproducible
    576 results.
    577 
    578 Regards
    579 Dave
    580 
    581 p.s., I think I've mentioned this before, but throwing in C++ is grim as
    582 unrelated throws in different threads take common locks, so nothing scales as
    583 you might expect.
    584 \end{comment}
  • doc/theses/andrew_beach_MMath/uw-ethesis.bib

    rfe8aa21 rd00d581  
    22% For use with BibTeX
    33
    4 @misc{Dice21,
    5     author      = {Dave Dice},
    6     year        = 2021,
    7     month       = aug,
    8     howpublished= {personal communication}
     4@book{goossens.book,
     5        author =        "Michel Goossens and Frank Mittelbach and
     6                         Alexander Samarin",
     7        title =         "The \LaTeX\ Companion",
     8        year =          "1994",
     9        publisher =     "Addison-Wesley",
     10        address =       "Reading, Massachusetts"
    911}
    1012
    11 @misc{CforallExceptionBenchmarks,
    12     contributer = {pabuhr@plg},
    13     key         = {Cforall Exception Benchmarks},
    14     author      = {{\textsf{C}{$\mathbf{\forall}$} Exception Benchmarks}},
    15     howpublished= {\href{https://github.com/cforall/ExceptionBenchmarks_SPE20}{https://\-github.com/\-cforall/\-ExceptionBenchmarks\_SPE20}},
     13@book{knuth.book,
     14        author =        "Donald Knuth",
     15        title =         "The \TeX book",
     16        year =          "1986",
     17        publisher =     "Addison-Wesley",
     18        address =       "Reading, Massachusetts"
    1619}
     20
     21@book{lamport.book,
     22        author =        "Leslie Lamport",
     23        title =         "\LaTeX\ --- A Document Preparation System",
     24        edition =       "Second",
     25        year =          "1994",
     26        publisher =     "Addison-Wesley",
     27        address =       "Reading, Massachusetts"
     28}
  • libcfa/prelude/builtins.c

    rfe8aa21 rd00d581  
    1010// Created On       : Fri Jul 21 16:21:03 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Aug 14 08:45:54 2021
    13 // Update Count     : 133
     12// Last Modified On : Wed Jul 21 13:31:34 2021
     13// Update Count     : 129
    1414//
    1515
     
    107107#endif // __SIZEOF_INT128__
    108108
    109 // for-control index constraints
    110 // forall( T | { void ?{}( T &, zero_t ); void ?{}( T &, one_t ); T ?+=?( T &, T ); T ?-=?( T &, T ); int ?<?( T, T ); } )
    111 // static inline T __for_control_index_constraints__( T t ) { return t; }
    112 
    113109// exponentiation operator implementation
    114110
  • src/Parser/parser.yy

    rfe8aa21 rd00d581  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Aug  8 09:14:44 2021
    13 // Update Count     : 5038
     12// Last Modified On : Tue Jul 20 22:03:04 2021
     13// Update Count     : 5031
    1414//
    1515
     
    185185                type = new ExpressionNode( new CastExpr( maybeMoveBuild<Expression>(type), new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ) );
    186186        } // if
    187 //      type = new ExpressionNode( build_func( new ExpressionNode( build_varref( new string( "__for_control_index_constraints__" ) ) ), type ) );
    188187        return new ForCtrl(
    189188                distAttr( DeclarationNode::newTypeof( type, true ), DeclarationNode::newName( index )->addInitializer( new InitializerNode( start ) ) ),
Note: See TracChangeset for help on using the changeset viewer.