Changeset 12941


Ignore:
Timestamp:
10/03/10 08:47:49 (12 years ago)
Author:
ehuelsmann
Message:

Add ANALYZE-LOCALS, which should have been on the
generic-class-file branch before merge-back.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/src/org/armedbear/lisp/jvm-instructions.lisp

    r12918 r12941  
    22;;;
    33;;; Copyright (C) 2003-2006 Peter Graves
     4;;; Copyright (C) 2010 Erik Huelsmann
    45;;; $Id$
    56;;;
     
    3940(defconst *opcodes* (make-hash-table :test 'equalp))
    4041
    41 (defstruct jvm-opcode name number size stack-effect)
    42 
    43 (defun %define-opcode (name number size stack-effect)
     42(defstruct jvm-opcode name number size stack-effect register-used)
     43
     44(defun %define-opcode (name number size stack-effect register)
    4445  (declare (type fixnum number size))
    4546  (let* ((name (string name))
     
    4748                                  :number number
    4849                                  :size size
    49                                   :stack-effect stack-effect)))
     50                                  :stack-effect stack-effect
     51                                  :register-used register)))
    5052     (setf (svref *opcode-table* number) opcode)
    5153     (setf (gethash name *opcodes*) opcode)
    5254     (setf (gethash number *opcodes*) opcode)))
    5355
    54 (defmacro define-opcode (name number size stack-effect)
    55   `(%define-opcode ',name ,number ,size ,stack-effect))
    56 
    57 ;; name number size stack-effect (nil if unknown)
    58 (define-opcode nop 0 1 0)
    59 (define-opcode aconst_null 1 1 1)
    60 (define-opcode iconst_m1 2 1 1)
    61 (define-opcode iconst_0 3 1 1)
    62 (define-opcode iconst_1 4 1 1)
    63 (define-opcode iconst_2 5 1 1)
    64 (define-opcode iconst_3 6 1 1)
    65 (define-opcode iconst_4 7 1 1)
    66 (define-opcode iconst_5 8 1 1)
    67 (define-opcode lconst_0 9 1 2)
    68 (define-opcode lconst_1 10 1 2)
    69 (define-opcode fconst_0 11 1 1)
    70 (define-opcode fconst_1 12 1 1)
    71 (define-opcode fconst_2 13 1 1)
    72 (define-opcode dconst_0 14 1 2)
    73 (define-opcode dconst_1 15 1 2)
    74 (define-opcode bipush 16 2 1)
    75 (define-opcode sipush 17 3 1)
    76 (define-opcode ldc 18 2 1)
    77 (define-opcode ldc_w 19 3 1)
    78 (define-opcode ldc2_w 20 3 2)
    79 (define-opcode iload 21 2 1)
    80 (define-opcode lload 22 2 2)
    81 (define-opcode fload 23 2 nil)
    82 (define-opcode dload 24 2 nil)
    83 (define-opcode aload 25 2 1)
    84 (define-opcode iload_0 26 1 1)
    85 (define-opcode iload_1 27 1 1)
    86 (define-opcode iload_2 28 1 1)
    87 (define-opcode iload_3 29 1 1)
    88 (define-opcode lload_0 30 1 2)
    89 (define-opcode lload_1 31 1 2)
    90 (define-opcode lload_2 32 1 2)
    91 (define-opcode lload_3 33 1 2)
    92 (define-opcode fload_0 34 1 nil)
    93 (define-opcode fload_1 35 1 nil)
    94 (define-opcode fload_2 36 1 nil)
    95 (define-opcode fload_3 37 1 nil)
    96 (define-opcode dload_0 38 1 nil)
    97 (define-opcode dload_1 39 1 nil)
    98 (define-opcode dload_2 40 1 nil)
    99 (define-opcode dload_3 41 1 nil)
    100 (define-opcode aload_0 42 1 1)
    101 (define-opcode aload_1 43 1 1)
    102 (define-opcode aload_2 44 1 1)
    103 (define-opcode aload_3 45 1 1)
    104 (define-opcode iaload 46 1 -1)
    105 (define-opcode laload 47 1 0)
    106 (define-opcode faload 48 1 -1)
    107 (define-opcode daload 49 1 0)
    108 (define-opcode aaload 50 1 -1)
    109 (define-opcode baload 51 1 nil)
    110 (define-opcode caload 52 1 nil)
    111 (define-opcode saload 53 1 nil)
    112 (define-opcode istore 54 2 -1)
    113 (define-opcode lstore 55 2 -2)
    114 (define-opcode fstore 56 2 nil)
    115 (define-opcode dstore 57 2 nil)
    116 (define-opcode astore 58 2 -1)
    117 (define-opcode istore_0 59 1 -1)
    118 (define-opcode istore_1 60 1 -1)
    119 (define-opcode istore_2 61 1 -1)
    120 (define-opcode istore_3 62 1 -1)
    121 (define-opcode lstore_0 63 1 -2)
    122 (define-opcode lstore_1 64 1 -2)
    123 (define-opcode lstore_2 65 1 -2)
    124 (define-opcode lstore_3 66 1 -2)
    125 (define-opcode fstore_0 67 1 nil)
    126 (define-opcode fstore_1 68 1 nil)
    127 (define-opcode fstore_2 69 1 nil)
    128 (define-opcode fstore_3 70 1 nil)
    129 (define-opcode dstore_0 71 1 nil)
    130 (define-opcode dstore_1 72 1 nil)
    131 (define-opcode dstore_2 73 1 nil)
    132 (define-opcode dstore_3 74 1 nil)
    133 (define-opcode astore_0 75 1 -1)
    134 (define-opcode astore_1 76 1 -1)
    135 (define-opcode astore_2 77 1 -1)
    136 (define-opcode astore_3 78 1 -1)
    137 (define-opcode iastore 79 1 -3)
    138 (define-opcode lastore 80 1 -4)
    139 (define-opcode fastore 81 1 -3)
    140 (define-opcode dastore 82 1 -4)
    141 (define-opcode aastore 83 1 -3)
    142 (define-opcode bastore 84 1 nil)
    143 (define-opcode castore 85 1 nil)
    144 (define-opcode sastore 86 1 nil)
    145 (define-opcode pop 87 1 -1)
    146 (define-opcode pop2 88 1 -2)
    147 (define-opcode dup 89 1 1)
    148 (define-opcode dup_x1 90 1 1)
    149 (define-opcode dup_x2 91 1 1)
    150 (define-opcode dup2 92 1 2)
    151 (define-opcode dup2_x1 93 1 2)
    152 (define-opcode dup2_x2 94 1 2)
    153 (define-opcode swap 95 1 0)
    154 (define-opcode iadd 96 1 -1)
    155 (define-opcode ladd 97 1 -2)
    156 (define-opcode fadd 98 1 -1)
    157 (define-opcode dadd 99 1 -2)
    158 (define-opcode isub 100 1 -1)
    159 (define-opcode lsub 101 1 -2)
    160 (define-opcode fsub 102 1 -1)
    161 (define-opcode dsub 103 1 -2)
    162 (define-opcode imul 104 1 -1)
    163 (define-opcode lmul 105 1 -2)
    164 (define-opcode fmul 106 1 -1)
    165 (define-opcode dmul 107 1 -2)
    166 (define-opcode idiv 108 1 nil)
    167 (define-opcode ldiv 109 1 nil)
    168 (define-opcode fdiv 110 1 nil)
    169 (define-opcode ddiv 111 1 nil)
    170 (define-opcode irem 112 1 nil)
    171 (define-opcode lrem 113 1 nil)
    172 (define-opcode frem 114 1 nil)
    173 (define-opcode drem 115 1 nil)
    174 (define-opcode ineg 116 1 0)
    175 (define-opcode lneg 117 1 0)
    176 (define-opcode fneg 118 1 0)
    177 (define-opcode dneg 119 1 0)
    178 (define-opcode ishl 120 1 -1)
    179 (define-opcode lshl 121 1 -1)
    180 (define-opcode ishr 122 1 -1)
    181 (define-opcode lshr 123 1 -1)
    182 (define-opcode iushr 124 1 nil)
    183 (define-opcode lushr 125 1 nil)
    184 (define-opcode iand 126 1 -1)
    185 (define-opcode land 127 1 -2)
    186 (define-opcode ior 128 1 -1)
    187 (define-opcode lor 129 1 -2)
    188 (define-opcode ixor 130 1 -1)
    189 (define-opcode lxor 131 1 -2)
    190 (define-opcode iinc 132 3 0)
    191 (define-opcode i2l 133 1 1)
    192 (define-opcode i2f 134 1 0)
    193 (define-opcode i2d 135 1 1)
    194 (define-opcode l2i 136 1 -1)
    195 (define-opcode l2f 137 1 -1)
    196 (define-opcode l2d 138 1 0)
    197 (define-opcode f2i 139 1 nil)
    198 (define-opcode f2l 140 1 nil)
    199 (define-opcode f2d 141 1 1)
    200 (define-opcode d2i 142 1 nil)
    201 (define-opcode d2l 143 1 nil)
    202 (define-opcode d2f 144 1 -1)
    203 (define-opcode i2b 145 1 nil)
    204 (define-opcode i2c 146 1 nil)
    205 (define-opcode i2s 147 1 nil)
    206 (define-opcode lcmp 148 1 -3)
    207 (define-opcode fcmpl 149 1 -1)
    208 (define-opcode fcmpg 150 1 -1)
    209 (define-opcode dcmpl 151 1 -3)
    210 (define-opcode dcmpg 152 1 -3)
    211 (define-opcode ifeq 153 3 -1)
    212 (define-opcode ifne 154 3 -1)
    213 (define-opcode iflt 155 3 -1)
    214 (define-opcode ifge 156 3 -1)
    215 (define-opcode ifgt 157 3 -1)
    216 (define-opcode ifle 158 3 -1)
    217 (define-opcode if_icmpeq 159 3 -2)
    218 (define-opcode if_icmpne 160 3 -2)
    219 (define-opcode if_icmplt 161 3 -2)
    220 (define-opcode if_icmpge 162 3 -2)
    221 (define-opcode if_icmpgt 163 3 -2)
    222 (define-opcode if_icmple 164 3 -2)
    223 (define-opcode if_acmpeq 165 3 -2)
    224 (define-opcode if_acmpne 166 3 -2)
    225 (define-opcode goto 167 3 0)
     56(defmacro define-opcode (name number size stack-effect register)
     57  `(%define-opcode ',name ,number ,size ,stack-effect ,register))
     58
     59;; name number size stack-effect register-used
     60(define-opcode nop 0 1 0 nil)
     61(define-opcode aconst_null 1 1 1 nil)
     62(define-opcode iconst_m1 2 1 1 nil)
     63(define-opcode iconst_0 3 1 1 nil)
     64(define-opcode iconst_1 4 1 1 nil)
     65(define-opcode iconst_2 5 1 1 nil)
     66(define-opcode iconst_3 6 1 1 nil)
     67(define-opcode iconst_4 7 1 1 nil)
     68(define-opcode iconst_5 8 1 1 nil)
     69(define-opcode lconst_0 9 1 2 nil)
     70(define-opcode lconst_1 10 1 2 nil)
     71(define-opcode fconst_0 11 1 1 nil)
     72(define-opcode fconst_1 12 1 1 nil)
     73(define-opcode fconst_2 13 1 1 nil)
     74(define-opcode dconst_0 14 1 2 nil)
     75(define-opcode dconst_1 15 1 2 nil)
     76(define-opcode bipush 16 2 1 nil)
     77(define-opcode sipush 17 3 1 nil)
     78(define-opcode ldc 18 2 1 nil)
     79(define-opcode ldc_w 19 3 1 nil)
     80(define-opcode ldc2_w 20 3 2 nil)
     81(define-opcode iload 21 2 1 t)
     82(define-opcode lload 22 2 2 t)
     83(define-opcode fload 23 2 nil t)
     84(define-opcode dload 24 2 nil t)
     85(define-opcode aload 25 2 1 t)
     86(define-opcode iload_0 26 1 1 0)
     87(define-opcode iload_1 27 1 1 1)
     88(define-opcode iload_2 28 1 1 2)
     89(define-opcode iload_3 29 1 1 3)
     90(define-opcode lload_0 30 1 2 0)
     91(define-opcode lload_1 31 1 2 1)
     92(define-opcode lload_2 32 1 2 2)
     93(define-opcode lload_3 33 1 2 3)
     94(define-opcode fload_0 34 1 nil 0)
     95(define-opcode fload_1 35 1 nil 1)
     96(define-opcode fload_2 36 1 nil 2)
     97(define-opcode fload_3 37 1 nil 3)
     98(define-opcode dload_0 38 1 nil 0)
     99(define-opcode dload_1 39 1 nil 1)
     100(define-opcode dload_2 40 1 nil 2)
     101(define-opcode dload_3 41 1 nil 3)
     102(define-opcode aload_0 42 1 1 0)
     103(define-opcode aload_1 43 1 1 1)
     104(define-opcode aload_2 44 1 1 2)
     105(define-opcode aload_3 45 1 1 3)
     106(define-opcode iaload 46 1 -1 nil)
     107(define-opcode laload 47 1 0 nil)
     108(define-opcode faload 48 1 -1 nil)
     109(define-opcode daload 49 1 0 nil)
     110(define-opcode aaload 50 1 -1 nil)
     111(define-opcode baload 51 1 nil nil)
     112(define-opcode caload 52 1 nil nil)
     113(define-opcode saload 53 1 nil nil)
     114(define-opcode istore 54 2 -1 t)
     115(define-opcode lstore 55 2 -2 t)
     116(define-opcode fstore 56 2 nil t)
     117(define-opcode dstore 57 2 nil t)
     118(define-opcode astore 58 2 -1 t)
     119(define-opcode istore_0 59 1 -1 0)
     120(define-opcode istore_1 60 1 -1 1)
     121(define-opcode istore_2 61 1 -1 2)
     122(define-opcode istore_3 62 1 -1 3)
     123(define-opcode lstore_0 63 1 -2 0)
     124(define-opcode lstore_1 64 1 -2 1)
     125(define-opcode lstore_2 65 1 -2 2)
     126(define-opcode lstore_3 66 1 -2 3)
     127(define-opcode fstore_0 67 1 nil 0)
     128(define-opcode fstore_1 68 1 nil 1)
     129(define-opcode fstore_2 69 1 nil 2)
     130(define-opcode fstore_3 70 1 nil 3)
     131(define-opcode dstore_0 71 1 nil 0)
     132(define-opcode dstore_1 72 1 nil 1)
     133(define-opcode dstore_2 73 1 nil 2)
     134(define-opcode dstore_3 74 1 nil 3)
     135(define-opcode astore_0 75 1 -1 0)
     136(define-opcode astore_1 76 1 -1 1)
     137(define-opcode astore_2 77 1 -1 2)
     138(define-opcode astore_3 78 1 -1 3)
     139(define-opcode iastore 79 1 -3 nil)
     140(define-opcode lastore 80 1 -4 nil)
     141(define-opcode fastore 81 1 -3 nil)
     142(define-opcode dastore 82 1 -4 nil)
     143(define-opcode aastore 83 1 -3 nil)
     144(define-opcode bastore 84 1 nil nil)
     145(define-opcode castore 85 1 nil nil)
     146(define-opcode sastore 86 1 nil nil)
     147(define-opcode pop 87 1 -1 nil)
     148(define-opcode pop2 88 1 -2 nil)
     149(define-opcode dup 89 1 1 nil)
     150(define-opcode dup_x1 90 1 1 nil)
     151(define-opcode dup_x2 91 1 1 nil)
     152(define-opcode dup2 92 1 2 nil)
     153(define-opcode dup2_x1 93 1 2 nil)
     154(define-opcode dup2_x2 94 1 2 nil)
     155(define-opcode swap 95 1 0 nil)
     156(define-opcode iadd 96 1 -1 nil)
     157(define-opcode ladd 97 1 -2 nil)
     158(define-opcode fadd 98 1 -1 nil)
     159(define-opcode dadd 99 1 -2 nil)
     160(define-opcode isub 100 1 -1 nil)
     161(define-opcode lsub 101 1 -2 nil)
     162(define-opcode fsub 102 1 -1 nil)
     163(define-opcode dsub 103 1 -2 nil)
     164(define-opcode imul 104 1 -1 nil)
     165(define-opcode lmul 105 1 -2 nil)
     166(define-opcode fmul 106 1 -1 nil)
     167(define-opcode dmul 107 1 -2 nil)
     168(define-opcode idiv 108 1 nil nil)
     169(define-opcode ldiv 109 1 nil nil)
     170(define-opcode fdiv 110 1 nil nil)
     171(define-opcode ddiv 111 1 nil nil)
     172(define-opcode irem 112 1 nil nil)
     173(define-opcode lrem 113 1 nil nil)
     174(define-opcode frem 114 1 nil nil)
     175(define-opcode drem 115 1 nil nil)
     176(define-opcode ineg 116 1 0 nil)
     177(define-opcode lneg 117 1 0 nil)
     178(define-opcode fneg 118 1 0 nil)
     179(define-opcode dneg 119 1 0 nil)
     180(define-opcode ishl 120 1 -1 nil)
     181(define-opcode lshl 121 1 -1 nil)
     182(define-opcode ishr 122 1 -1 nil)
     183(define-opcode lshr 123 1 -1 nil)
     184(define-opcode iushr 124 1 nil nil)
     185(define-opcode lushr 125 1 nil nil)
     186(define-opcode iand 126 1 -1 nil)
     187(define-opcode land 127 1 -2 nil)
     188(define-opcode ior 128 1 -1 nil)
     189(define-opcode lor 129 1 -2 nil)
     190(define-opcode ixor 130 1 -1 nil)
     191(define-opcode lxor 131 1 -2 nil)
     192(define-opcode iinc 132 3 0 t)
     193(define-opcode i2l 133 1 1 nil)
     194(define-opcode i2f 134 1 0 nil)
     195(define-opcode i2d 135 1 1 nil)
     196(define-opcode l2i 136 1 -1 nil)
     197(define-opcode l2f 137 1 -1 nil)
     198(define-opcode l2d 138 1 0 nil)
     199(define-opcode f2i 139 1 nil nil)
     200(define-opcode f2l 140 1 nil nil)
     201(define-opcode f2d 141 1 1 nil)
     202(define-opcode d2i 142 1 nil nil)
     203(define-opcode d2l 143 1 nil nil)
     204(define-opcode d2f 144 1 -1 nil)
     205(define-opcode i2b 145 1 nil nil)
     206(define-opcode i2c 146 1 nil nil)
     207(define-opcode i2s 147 1 nil nil)
     208(define-opcode lcmp 148 1 -3 nil)
     209(define-opcode fcmpl 149 1 -1 nil)
     210(define-opcode fcmpg 150 1 -1 nil)
     211(define-opcode dcmpl 151 1 -3 nil)
     212(define-opcode dcmpg 152 1 -3 nil)
     213(define-opcode ifeq 153 3 -1 nil)
     214(define-opcode ifne 154 3 -1 nil)
     215(define-opcode iflt 155 3 -1 nil)
     216(define-opcode ifge 156 3 -1 nil)
     217(define-opcode ifgt 157 3 -1 nil)
     218(define-opcode ifle 158 3 -1 nil)
     219(define-opcode if_icmpeq 159 3 -2 nil)
     220(define-opcode if_icmpne 160 3 -2 nil)
     221(define-opcode if_icmplt 161 3 -2 nil)
     222(define-opcode if_icmpge 162 3 -2 nil)
     223(define-opcode if_icmpgt 163 3 -2 nil)
     224(define-opcode if_icmple 164 3 -2 nil)
     225(define-opcode if_acmpeq 165 3 -2 nil)
     226(define-opcode if_acmpne 166 3 -2 nil)
     227(define-opcode goto 167 3 0 nil)
    226228;;(define-opcode jsr 168 3 1) Don't use these 2 opcodes: deprecated
    227229;;(define-opcode ret 169 2 0) their use results in JVM verifier errors
    228 (define-opcode tableswitch 170 0 nil)
    229 (define-opcode lookupswitch 171 0 nil)
    230 (define-opcode ireturn 172 1 nil)
    231 (define-opcode lreturn 173 1 nil)
    232 (define-opcode freturn 174 1 nil)
    233 (define-opcode dreturn 175 1 nil)
    234 (define-opcode areturn 176 1 -1)
    235 (define-opcode return 177 1 0)
    236 (define-opcode getstatic 178 3 1)
    237 (define-opcode putstatic 179 3 -1)
    238 (define-opcode getfield 180 3 0)
    239 (define-opcode putfield 181 3 -2)
    240 (define-opcode invokevirtual 182 3 nil)
    241 (define-opcode invokespecial 183 3 nil)
    242 (define-opcode invokestatic 184 3 nil)
    243 (define-opcode invokeinterface 185 5 nil)
    244 (define-opcode unused 186 0 nil)
    245 (define-opcode new 187 3 1)
    246 (define-opcode newarray 188 2 nil)
    247 (define-opcode anewarray 189 3 0)
    248 (define-opcode arraylength 190 1 0)
    249 (define-opcode athrow 191 1 0)
    250 (define-opcode checkcast 192 3 0)
    251 (define-opcode instanceof 193 3 0)
    252 (define-opcode monitorenter 194 1 -1)
    253 (define-opcode monitorexit 195 1 -1)
    254 (define-opcode wide 196 0 nil)
    255 (define-opcode multianewarray 197 4 nil)
    256 (define-opcode ifnull 198 3 -1)
    257 (define-opcode ifnonnull 199 3 nil)
    258 (define-opcode goto_w 200 5 nil)
     230(define-opcode tableswitch 170 0 nil nil)
     231(define-opcode lookupswitch 171 0 nil nil)
     232(define-opcode ireturn 172 1 nil nil)
     233(define-opcode lreturn 173 1 nil nil)
     234(define-opcode freturn 174 1 nil nil)
     235(define-opcode dreturn 175 1 nil nil)
     236(define-opcode areturn 176 1 -1 nil)
     237(define-opcode return 177 1 0 nil)
     238(define-opcode getstatic 178 3 1 nil)
     239(define-opcode putstatic 179 3 -1 nil)
     240(define-opcode getfield 180 3 0 nil)
     241(define-opcode putfield 181 3 -2 nil)
     242(define-opcode invokevirtual 182 3 nil nil)
     243(define-opcode invokespecial 183 3 nil nil)
     244(define-opcode invokestatic 184 3 nil nil)
     245(define-opcode invokeinterface 185 5 nil nil)
     246(define-opcode unused 186 0 nil nil)
     247(define-opcode new 187 3 1 nil)
     248(define-opcode newarray 188 2 nil nil)
     249(define-opcode anewarray 189 3 0 nil)
     250(define-opcode arraylength 190 1 0 nil)
     251(define-opcode athrow 191 1 0 nil)
     252(define-opcode checkcast 192 3 0 nil)
     253(define-opcode instanceof 193 3 0 nil)
     254(define-opcode monitorenter 194 1 -1 nil)
     255(define-opcode monitorexit 195 1 -1 nil)
     256(define-opcode wide 196 0 nil nil)
     257(define-opcode multianewarray 197 4 nil nil)
     258(define-opcode ifnull 198 3 -1 nil)
     259(define-opcode ifnonnull 199 3 nil nil)
     260(define-opcode goto_w 200 5 nil nil)
    259261;; (define-opcode jsr_w 201 5 nil) Don't use: deprecated
    260 (define-opcode label 202 0 0)  ;; virtual: does not exist in the JVM
     262(define-opcode label 202 0 0 nil)  ;; virtual: does not exist in the JVM
    261263;; (define-opcode push-value 203 nil 1)
    262264;; (define-opcode store-value 204 nil -1)
    263 (define-opcode clear-values 205 0 0)  ;; virtual: does not exist in the JVM
     265(define-opcode clear-values 205 0 0 t)  ;; virtual: does not exist in the JVM
    264266;;(define-opcode var-ref 206 0 0)
    265267
     
    768770      max-stack)))
    769771
     772(defun analyze-locals (code)
     773  (let ((code-length (length code))
     774        (max-local 0))
     775    (dotimes (i code-length max-local)
     776      (let* ((instruction (aref code i))
     777             (opcode (instruction-opcode instruction)))
     778        (setf max-local
     779              (max max-local
     780                   (or (let ((opcode-register
     781                                (jvm-opcode-register-used opcode)))
     782                         (if (eq t opcode-register)
     783                             (car (instruction-args instruction))
     784                             opcode-register))
     785                       0)))))))
    770786
    771787(defun delete-unused-labels (code handler-labels)
Note: See TracChangeset for help on using the changeset viewer.