2
public java.lang.Object invoke(java.lang.Object);
                                     Code:
                                      Stack=8, Locals=8, Args_size=2
                                      0:   aload_1
                                      1:   aconst_null
                                      2:   astore_1
                                      3:   invokestatic   #65; //Method clojure/lang
                                      6:   lstore_2
                                      7:   lconst_1
                                      8:   lstore 4
                                      10: lload_2
                                      11: lconst_0
                                      12: lcmp
                                      13: ifne      25
                                      16: lload     4
                                      18: invokestatic    #71; //Method clojure/lang
                                      21: goto      38
                                      24: pop
                                      25: lload_2
                                      26: lconst_1
                                      27: lsub
                                      28: lload_2
                                      29: lload     4
(defn fact [n]                        31: lmul
  (loop [n (long n), a 1]             32: lstore 4
    (if (== n 0)                      34: lstore_2
      a                               35: goto      10
      (recur (dec n) (* n a)))))      38: areturn


                                                                                   3
(def fact
  (fn-iasm [n]
    (aload_1)
    (checkcast Integer)
    (invokevirtual ^int Integer/intValue [])
    (istore_2)
    (iconst_1)
    (istore_3)
    :loop
    (iload_2)
    (ifeq :end)
    (ilaod_2)
    (iload_3)
    (imul)
    (istore_3)
    (iinc 2 -1)
    (goto :loop)
    :end
    (iload_3)
    (invokestatic ^Integer Integer/valueOf [int])
    (areturn)))


                                                    4
(def fact                                           public final java.lang.Object invoke(java.lang.
  (fn-iasm [n]                                        Code:
    (aload_1)                                          Stack=2, Locals=6, Args_size=2
    (checkcast Integer)                                0:   aload_1
    (invokevirtual ^int Integer/intValue [])           1:   checkcast      #25; //class java/lang/I
    (istore_2)                                         4:   invokevirtual #29; //Method java/lang/
    (iconst_1)                                         7:   istore_2
    (istore_3)                                         8:   iconst_1
    :loop                                              9:   istore_3
    (iload_2)                                          10: iload_2
    (ifeq :end)                                        11: ifeq      24
    (ilaod_2)                                          14: iload_2
    (iload_3)                                          15: iload_3
    (imul)                                             16: imul
    (istore_3)                                         17: istore_3
    (iinc 2 -1)                                        18: iinc      2, -1
    (goto :loop)                                       21: goto      10
    :end                                               24: iload_3
    (iload_3)                                          25: invokestatic    #33; //Method java/lang/
    (invokestatic ^Integer Integer/valueOf [int])      28: areturn
    (areturn)))


                                                                                                  4
public java.lang.Object invoke(java.lang.Object);
                                                               Code:
                                                                Stack=8, Locals=8, Args_size=2
                                                                0: aload_1
                                                                1:   aconst_null
                                                                2:   astore_1
                                                                3:   invokestatic   #65; //Method clojure/lang
                                                                6:   lstore_2
                                                                7:   lconst_1
                                                                8:   lstore 4

                                   macro                        10: lload_2
                                                                11: lconst_0
(defn fact [n]
  (loop [n (long n), a 1]          expand   analyze   emit      12: lcmp
                                                                13: ifne      25
    (if (== n 0)
                                                                16: lload     4
      a
                                                                18: invokestatic    #71; //Method clojure/lang
      (recur (dec n) (* n a)))))
                                                                21: goto      38
                                                                24: pop
                                                                25: lload_2
                                                                26: lconst_1
                                                                27: lsub
                                                                28: lload_2
                                                                29: lload     4
                                                                31: lmul
                                                                32: lstore 4
                                                                34: lstore_2
                                                                35: goto      10
                                                                38: areturn




                                                                                                             5
public java.lang.Object invoke(java.lang.Object);
                                                               Code:
                                                                Stack=8, Locals=8, Args_size=2
                                                                0: aload_1
                                                                1:   aconst_null
                                                                2:   astore_1
                                                                3:   invokestatic   #65; //Method clojure/lang
                                                                6:   lstore_2
                                                                7:   lconst_1
                                                                8:   lstore 4

                                   macro                        10: lload_2
                                                                11: lconst_0
(defn fact [n]
  (loop [n (long n), a 1]          expand   analyze   emit      12: lcmp
                                                                13: ifne      25
    (if (== n 0)
                                                                16: lload     4
      a
                                                                18: invokestatic    #71; //Method clojure/lang
      (recur (dec n) (* n a)))))
                                                                21: goto      38
                                                                24: pop
                                                                25: lload_2
                                                                26: lconst_1
                                                                27: lsub
                                                                28: lload_2
                                                                29: lload     4
                                                                31: lmul
                                                                32: lstore 4
                                                                34: lstore_2
                                                                35: goto      10
                                                                38: areturn




                                                                                                             5
public java.lang.Object invoke(java.lang.Object);
                                                               Code:
                                                                Stack=8, Locals=8, Args_size=2
                                                                0: aload_1
                                                                1:   aconst_null
                                                                2:   astore_1
                                                                3:   invokestatic   #65; //Method clojure/lang
                                                                6:   lstore_2
                                                                7:   lconst_1
                                                                8:   lstore 4

                                   macro                        10: lload_2
                                                                11: lconst_0
(defn fact [n]
  (loop [n (long n), a 1]          expand   analyze   emit      12: lcmp
                                                                13: ifne      25
    (if (== n 0)
                                                                16: lload     4
      a
                                                                18: invokestatic    #71; //Method clojure/lang
      (recur (dec n) (* n a)))))
                                                                21: goto      38
                                                                24: pop
                                                                25: lload_2
                                                                26: lconst_1
                                                                27: lsub
                                                                28: lload_2
                                                                29: lload     4
                                                                31: lmul
                                                                32: lstore 4
                                                                34: lstore_2
                                                                35: goto      10
                                                                38: areturn




                                                                                                             5
public java.lang.Object invoke(java.lang.Object);
                                                                                                         Code:
                                                                                                          Stack=8, Locals=8, Args_size=2
                                                                                                          0: aload_1
                                                                                                          1:   aconst_null
                                                                                                          2:   astore_1
                                                                                                          3:   invokestatic   #65; //Method clojure/lang
                                                                                                          6:   lstore_2
                                                                                                          7:   lconst_1
                                                                                                          8:   lstore 4

                                   macro                                                                  10: lload_2
                                                                                                          11: lconst_0
(defn fact [n]
  (loop [n (long n), a 1]          expand                     analyze                           emit      12: lcmp
                                                                                                          13: ifne      25
    (if (== n 0)
                                                                                                          16: lload     4
      a
                                                                                                          18: invokestatic    #71; //Method clojure/lang
      (recur (dec n) (* n a)))))
                                                                                                          21: goto      38
                                                                                                          24: pop
                                                                                                          25: lload_2
                                            public java.lang.Object invoke(java.lang.Object);             26: lconst_1
                                              Code:                                                       27: lsub
                                               Stack=8, Locals=8, Args_size=2                             28: lload_2
                                               0: aload_1                                                 29: lload     4
                                               1:   aconst_null                                           31: lmul
                                               2:   astore_1                                              32: lstore 4
                                               3:   invokestatic   #65; //Method clojure/lang             34: lstore_2
                                               6:   lstore_2                                              35: goto      10
                                               7:   lconst_1                                              38: areturn
                                               8:   lstore 4
                                               10: lload_2
                                               11: lconst_0
                                               12: lcmp
                                               13: ifne      25
                                               16: lload     4
                                               18: invokestatic    #71; //Method clojure/lang
                                               21: goto      38
                                               24: pop
                                               25: lload_2
                                               26: lconst_1
                                               27: lsub
                                               28: lload_2
                                               29: lload     4
                                               31: lmul
                                               32: lstore 4
                                               34: lstore_2
                                               35: goto      10
                                               38: areturn
                                                                                                                                                       5
6
7
0.60

                         Clojure 1.2.1
                         iasm



0.45




0.30




0.15




  0
       100   200   300                   400




                                               9
10
Clojureによるバイトコードプログラミング

Clojureによるバイトコードプログラミング

  • 2.
  • 3.
    public java.lang.Object invoke(java.lang.Object); Code: Stack=8, Locals=8, Args_size=2 0: aload_1 1: aconst_null 2: astore_1 3: invokestatic #65; //Method clojure/lang 6: lstore_2 7: lconst_1 8: lstore 4 10: lload_2 11: lconst_0 12: lcmp 13: ifne 25 16: lload 4 18: invokestatic #71; //Method clojure/lang 21: goto 38 24: pop 25: lload_2 26: lconst_1 27: lsub 28: lload_2 29: lload 4 (defn fact [n] 31: lmul (loop [n (long n), a 1] 32: lstore 4 (if (== n 0) 34: lstore_2 a 35: goto 10 (recur (dec n) (* n a))))) 38: areturn 3
  • 4.
    (def fact (fn-iasm [n] (aload_1) (checkcast Integer) (invokevirtual ^int Integer/intValue []) (istore_2) (iconst_1) (istore_3) :loop (iload_2) (ifeq :end) (ilaod_2) (iload_3) (imul) (istore_3) (iinc 2 -1) (goto :loop) :end (iload_3) (invokestatic ^Integer Integer/valueOf [int]) (areturn))) 4
  • 5.
    (def fact public final java.lang.Object invoke(java.lang. (fn-iasm [n] Code: (aload_1) Stack=2, Locals=6, Args_size=2 (checkcast Integer) 0: aload_1 (invokevirtual ^int Integer/intValue []) 1: checkcast #25; //class java/lang/I (istore_2) 4: invokevirtual #29; //Method java/lang/ (iconst_1) 7: istore_2 (istore_3) 8: iconst_1 :loop 9: istore_3 (iload_2) 10: iload_2 (ifeq :end) 11: ifeq 24 (ilaod_2) 14: iload_2 (iload_3) 15: iload_3 (imul) 16: imul (istore_3) 17: istore_3 (iinc 2 -1) 18: iinc 2, -1 (goto :loop) 21: goto 10 :end 24: iload_3 (iload_3) 25: invokestatic #33; //Method java/lang/ (invokestatic ^Integer Integer/valueOf [int]) 28: areturn (areturn))) 4
  • 6.
    public java.lang.Object invoke(java.lang.Object); Code: Stack=8, Locals=8, Args_size=2 0: aload_1 1: aconst_null 2: astore_1 3: invokestatic #65; //Method clojure/lang 6: lstore_2 7: lconst_1 8: lstore 4 macro 10: lload_2 11: lconst_0 (defn fact [n] (loop [n (long n), a 1] expand analyze emit 12: lcmp 13: ifne 25 (if (== n 0) 16: lload 4 a 18: invokestatic #71; //Method clojure/lang (recur (dec n) (* n a))))) 21: goto 38 24: pop 25: lload_2 26: lconst_1 27: lsub 28: lload_2 29: lload 4 31: lmul 32: lstore 4 34: lstore_2 35: goto 10 38: areturn 5
  • 7.
    public java.lang.Object invoke(java.lang.Object); Code: Stack=8, Locals=8, Args_size=2 0: aload_1 1: aconst_null 2: astore_1 3: invokestatic #65; //Method clojure/lang 6: lstore_2 7: lconst_1 8: lstore 4 macro 10: lload_2 11: lconst_0 (defn fact [n] (loop [n (long n), a 1] expand analyze emit 12: lcmp 13: ifne 25 (if (== n 0) 16: lload 4 a 18: invokestatic #71; //Method clojure/lang (recur (dec n) (* n a))))) 21: goto 38 24: pop 25: lload_2 26: lconst_1 27: lsub 28: lload_2 29: lload 4 31: lmul 32: lstore 4 34: lstore_2 35: goto 10 38: areturn 5
  • 8.
    public java.lang.Object invoke(java.lang.Object); Code: Stack=8, Locals=8, Args_size=2 0: aload_1 1: aconst_null 2: astore_1 3: invokestatic #65; //Method clojure/lang 6: lstore_2 7: lconst_1 8: lstore 4 macro 10: lload_2 11: lconst_0 (defn fact [n] (loop [n (long n), a 1] expand analyze emit 12: lcmp 13: ifne 25 (if (== n 0) 16: lload 4 a 18: invokestatic #71; //Method clojure/lang (recur (dec n) (* n a))))) 21: goto 38 24: pop 25: lload_2 26: lconst_1 27: lsub 28: lload_2 29: lload 4 31: lmul 32: lstore 4 34: lstore_2 35: goto 10 38: areturn 5
  • 9.
    public java.lang.Object invoke(java.lang.Object); Code: Stack=8, Locals=8, Args_size=2 0: aload_1 1: aconst_null 2: astore_1 3: invokestatic #65; //Method clojure/lang 6: lstore_2 7: lconst_1 8: lstore 4 macro 10: lload_2 11: lconst_0 (defn fact [n] (loop [n (long n), a 1] expand analyze emit 12: lcmp 13: ifne 25 (if (== n 0) 16: lload 4 a 18: invokestatic #71; //Method clojure/lang (recur (dec n) (* n a))))) 21: goto 38 24: pop 25: lload_2 public java.lang.Object invoke(java.lang.Object); 26: lconst_1 Code: 27: lsub Stack=8, Locals=8, Args_size=2 28: lload_2 0: aload_1 29: lload 4 1: aconst_null 31: lmul 2: astore_1 32: lstore 4 3: invokestatic #65; //Method clojure/lang 34: lstore_2 6: lstore_2 35: goto 10 7: lconst_1 38: areturn 8: lstore 4 10: lload_2 11: lconst_0 12: lcmp 13: ifne 25 16: lload 4 18: invokestatic #71; //Method clojure/lang 21: goto 38 24: pop 25: lload_2 26: lconst_1 27: lsub 28: lload_2 29: lload 4 31: lmul 32: lstore 4 34: lstore_2 35: goto 10 38: areturn 5
  • 10.
  • 11.
  • 15.
    0.60 Clojure 1.2.1 iasm 0.45 0.30 0.15 0 100 200 300 400 9
  • 16.