001/*
002 *  This file is part of the Jikes RVM project (http://jikesrvm.org).
003 *
004 *  This file is licensed to You under the Eclipse Public License (EPL);
005 *  You may not use this file except in compliance with the License. You
006 *  may obtain a copy of the License at
007 *
008 *      http://www.opensource.org/licenses/eclipse-1.0.php
009 *
010 *  See the COPYRIGHT.txt file distributed with this work for information
011 *  regarding copyright ownership.
012 */
013package org.jikesrvm.classloader;
014
015import org.vmmagic.pragma.Pure;
016
017/**
018 * Information about java byte codes that appear in the "code" attribute
019 * of a .class file.
020 */
021public final class BytecodeConstants {
022  // The following mnemonics are defined in Chapter 10 of The Java Virtual Machine Specification.
023  //
024  public static final int JBC_nop = 0;
025  public static final int JBC_aconst_null = 1;
026  public static final int JBC_iconst_m1 = 2;
027  public static final int JBC_iconst_0 = 3;
028  public static final int JBC_iconst_1 = 4;
029  public static final int JBC_iconst_2 = 5;
030  public static final int JBC_iconst_3 = 6;
031  public static final int JBC_iconst_4 = 7;
032  public static final int JBC_iconst_5 = 8;
033  public static final int JBC_lconst_0 = 9;
034  public static final int JBC_lconst_1 = 10;
035  public static final int JBC_fconst_0 = 11;
036  public static final int JBC_fconst_1 = 12;
037  public static final int JBC_fconst_2 = 13;
038  public static final int JBC_dconst_0 = 14;
039  public static final int JBC_dconst_1 = 15;
040  public static final int JBC_bipush = 16;
041  public static final int JBC_sipush = 17;
042  public static final int JBC_ldc = 18;
043  public static final int JBC_ldc_w = 19;
044  public static final int JBC_ldc2_w = 20;
045  public static final int JBC_iload = 21;
046  public static final int JBC_lload = 22;
047  public static final int JBC_fload = 23;
048  public static final int JBC_dload = 24;
049  public static final int JBC_aload = 25;
050  public static final int JBC_iload_0 = 26;
051  public static final int JBC_iload_1 = 27;
052  public static final int JBC_iload_2 = 28;
053  public static final int JBC_iload_3 = 29;
054  public static final int JBC_lload_0 = 30;
055  public static final int JBC_lload_1 = 31;
056  public static final int JBC_lload_2 = 32;
057  public static final int JBC_lload_3 = 33;
058  public static final int JBC_fload_0 = 34;
059  public static final int JBC_fload_1 = 35;
060  public static final int JBC_fload_2 = 36;
061  public static final int JBC_fload_3 = 37;
062  public static final int JBC_dload_0 = 38;
063  public static final int JBC_dload_1 = 39;
064  public static final int JBC_dload_2 = 40;
065  public static final int JBC_dload_3 = 41;
066  public static final int JBC_aload_0 = 42;
067  public static final int JBC_aload_1 = 43;
068  public static final int JBC_aload_2 = 44;
069  public static final int JBC_aload_3 = 45;
070  public static final int JBC_iaload = 46;
071  public static final int JBC_laload = 47;
072  public static final int JBC_faload = 48;
073  public static final int JBC_daload = 49;
074  public static final int JBC_aaload = 50;
075  public static final int JBC_baload = 51;
076  public static final int JBC_caload = 52;
077  public static final int JBC_saload = 53;
078  public static final int JBC_istore = 54;
079  public static final int JBC_lstore = 55;
080  public static final int JBC_fstore = 56;
081  public static final int JBC_dstore = 57;
082  public static final int JBC_astore = 58;
083  public static final int JBC_istore_0 = 59;
084  public static final int JBC_istore_1 = 60;
085  public static final int JBC_istore_2 = 61;
086  public static final int JBC_istore_3 = 62;
087  public static final int JBC_lstore_0 = 63;
088  public static final int JBC_lstore_1 = 64;
089  public static final int JBC_lstore_2 = 65;
090  public static final int JBC_lstore_3 = 66;
091  public static final int JBC_fstore_0 = 67;
092  public static final int JBC_fstore_1 = 68;
093  public static final int JBC_fstore_2 = 69;
094  public static final int JBC_fstore_3 = 70;
095  public static final int JBC_dstore_0 = 71;
096  public static final int JBC_dstore_1 = 72;
097  public static final int JBC_dstore_2 = 73;
098  public static final int JBC_dstore_3 = 74;
099  public static final int JBC_astore_0 = 75;
100  public static final int JBC_astore_1 = 76;
101  public static final int JBC_astore_2 = 77;
102  public static final int JBC_astore_3 = 78;
103  public static final int JBC_iastore = 79;
104  public static final int JBC_lastore = 80;
105  public static final int JBC_fastore = 81;
106  public static final int JBC_dastore = 82;
107  public static final int JBC_aastore = 83;
108  public static final int JBC_bastore = 84;
109  public static final int JBC_castore = 85;
110  public static final int JBC_sastore = 86;
111  public static final int JBC_pop = 87;
112  public static final int JBC_pop2 = 88;
113  public static final int JBC_dup = 89;
114  public static final int JBC_dup_x1 = 90;
115  public static final int JBC_dup_x2 = 91;
116  public static final int JBC_dup2 = 92;
117  public static final int JBC_dup2_x1 = 93;
118  public static final int JBC_dup2_x2 = 94;
119  public static final int JBC_swap = 95;
120  public static final int JBC_iadd = 96;
121  public static final int JBC_ladd = 97;
122  public static final int JBC_fadd = 98;
123  public static final int JBC_dadd = 99;
124  public static final int JBC_isub = 100;
125  public static final int JBC_lsub = 101;
126  public static final int JBC_fsub = 102;
127  public static final int JBC_dsub = 103;
128  public static final int JBC_imul = 104;
129  public static final int JBC_lmul = 105;
130  public static final int JBC_fmul = 106;
131  public static final int JBC_dmul = 107;
132  public static final int JBC_idiv = 108;
133  public static final int JBC_ldiv = 109;
134  public static final int JBC_fdiv = 110;
135  public static final int JBC_ddiv = 111;
136  public static final int JBC_irem = 112;
137  public static final int JBC_lrem = 113;
138  public static final int JBC_frem = 114;
139  public static final int JBC_drem = 115;
140  public static final int JBC_ineg = 116;
141  public static final int JBC_lneg = 117;
142  public static final int JBC_fneg = 118;
143  public static final int JBC_dneg = 119;
144  public static final int JBC_ishl = 120;
145  public static final int JBC_lshl = 121;
146  public static final int JBC_ishr = 122;
147  public static final int JBC_lshr = 123;
148  public static final int JBC_iushr = 124;
149  public static final int JBC_lushr = 125;
150  public static final int JBC_iand = 126;
151  public static final int JBC_land = 127;
152  public static final int JBC_ior = 128;
153  public static final int JBC_lor = 129;
154  public static final int JBC_ixor = 130;
155  public static final int JBC_lxor = 131;
156  public static final int JBC_iinc = 132;
157  public static final int JBC_i2l = 133;
158  public static final int JBC_i2f = 134;
159  public static final int JBC_i2d = 135;
160  public static final int JBC_l2i = 136;
161  public static final int JBC_l2f = 137;
162  public static final int JBC_l2d = 138;
163  public static final int JBC_f2i = 139;
164  public static final int JBC_f2l = 140;
165  public static final int JBC_f2d = 141;
166  public static final int JBC_d2i = 142;
167  public static final int JBC_d2l = 143;
168  public static final int JBC_d2f = 144;
169  public static final int JBC_int2byte = 145;
170  public static final int JBC_int2char = 146;
171  public static final int JBC_int2short = 147;
172  public static final int JBC_lcmp = 148;
173  public static final int JBC_fcmpl = 149;
174  public static final int JBC_fcmpg = 150;
175  public static final int JBC_dcmpl = 151;
176  public static final int JBC_dcmpg = 152;
177  public static final int JBC_ifeq = 153;
178  public static final int JBC_ifne = 154;
179  public static final int JBC_iflt = 155;
180  public static final int JBC_ifge = 156;
181  public static final int JBC_ifgt = 157;
182  public static final int JBC_ifle = 158;
183  public static final int JBC_if_icmpeq = 159;
184  public static final int JBC_if_icmpne = 160;
185  public static final int JBC_if_icmplt = 161;
186  public static final int JBC_if_icmpge = 162;
187  public static final int JBC_if_icmpgt = 163;
188  public static final int JBC_if_icmple = 164;
189  public static final int JBC_if_acmpeq = 165;
190  public static final int JBC_if_acmpne = 166;
191  public static final int JBC_goto = 167;
192  public static final int JBC_jsr = 168;
193  public static final int JBC_ret = 169;
194  public static final int JBC_tableswitch = 170;
195  public static final int JBC_lookupswitch = 171;
196  public static final int JBC_ireturn = 172;
197  public static final int JBC_lreturn = 173;
198  public static final int JBC_freturn = 174;
199  public static final int JBC_dreturn = 175;
200  public static final int JBC_areturn = 176;
201  public static final int JBC_return = 177;
202  public static final int JBC_getstatic = 178;
203  public static final int JBC_putstatic = 179;
204  public static final int JBC_getfield = 180;
205  public static final int JBC_putfield = 181;
206  public static final int JBC_invokevirtual = 182;
207  public static final int JBC_invokespecial = 183;
208  public static final int JBC_invokestatic = 184;
209  public static final int JBC_invokeinterface = 185;
210  public static final int JBC_invokedynamic = 186;
211  public static final int JBC_new = 187;
212  public static final int JBC_newarray = 188;
213  public static final int JBC_anewarray = 189;
214  public static final int JBC_arraylength = 190;
215  public static final int JBC_athrow = 191;
216  public static final int JBC_checkcast = 192;
217  public static final int JBC_instanceof = 193;
218  public static final int JBC_monitorenter = 194;
219  public static final int JBC_monitorexit = 195;
220  public static final int JBC_wide = 196;
221  public static final int JBC_multianewarray = 197;
222  public static final int JBC_ifnull = 198;
223  public static final int JBC_ifnonnull = 199;
224  public static final int JBC_goto_w = 200;
225  public static final int JBC_jsr_w = 201;
226  public static final int JBC_breakpoint = 202;
227
228  public static final int JBC_impdep1 = 254;
229  public static final int JBC_impdep2 = 255;
230
231  private BytecodeConstants() {
232    // prevent instantiation
233  }
234
235  /**
236   * Returns the length of the given bytecode.
237   *
238   * @param bc a bytecode
239   *
240   * @return length of the bytecode, -1 indicates a variable length instruction,
241   * -2 indicates an unused instruction
242   */
243  @Pure
244  public static int JBC_length(int bc) {
245    return _JBC_length[bc];
246  }
247
248  /**
249   * Length of each instruction introduced by the above bytecodes.
250   * -1 indicates a variable length instruction.
251   * -2 indicates an unused instruction.
252   */
253  private static final byte[] _JBC_length = {
254                       1, // nop
255                       1, // aconst_null
256                       1, // iconst_m1
257                       1, // iconst_0
258                       1, // iconst_1
259                       1, // iconst_2
260                       1, // iconst_3
261                       1, // iconst_4
262                       1, // iconst_5
263                       1, // lconst_0
264                       1, // lconst_1
265                       1, // fconst_0
266                       1, // fconst_1
267                       1, // fconst_2
268                       1, // dconst_0
269                       1, // dconst_1
270                       2, // bipush
271                       3, // sipush
272                       2, // ldc
273                       3, // ldc_w
274                       3, // ldc2_w
275                       2, // iload
276                       2, // lload
277                       2, // fload
278                       2, // dload
279                       2, // aload
280                       1, // iload_0
281                       1, // iload_1
282                       1, // iload_2
283                       1, // iload_3
284                       1, // lload_0
285                       1, // lload_1
286                       1, // lload_2
287                       1, // lload_3
288                       1, // fload_0
289                       1, // fload_1
290                       1, // fload_2
291                       1, // fload_3
292                       1, // dload_0
293                       1, // dload_1
294                       1, // dload_2
295                       1, // dload_3
296                       1, // aload_0
297                       1, // aload_1
298                       1, // aload_2
299                       1, // aload_3
300                       1, // iaload
301                       1, // laload
302                       1, // faload
303                       1, // daload
304                       1, // aaload
305                       1, // baload
306                       1, // caload
307                       1, // saload
308                       2, // istore
309                       2, // lstore
310                       2, // fstore
311                       2, // dstore
312                       2, // astore
313                       1, // istore_0
314                       1, // istore_1
315                       1, // istore_2
316                       1, // istore_3
317                       1, // lstore_0
318                       1, // lstore_1
319                       1, // lstore_2
320                       1, // lstore_3
321                       1, // fstore_0
322                       1, // fstore_1
323                       1, // fstore_2
324                       1, // fstore_3
325                       1, // dstore_0
326                       1, // dstore_1
327                       1, // dstore_2
328                       1, // dstore_3
329                       1, // astore_0
330                       1, // astore_1
331                       1, // astore_2
332                       1, // astore_3
333                       1, // iastore
334                       1, // lastore
335                       1, // fastore
336                       1, // dastore
337                       1, // aastore
338                       1, // bastore
339                       1, // castore
340                       1, // sastore
341                       1, // pop
342                       1, // pop2
343                       1, // dup
344                       1, // dup_x1
345                       1, // dup_x2
346                       1, // dup2
347                       1, // dup2_x1
348                       1, // dup2_x2
349                       1, // swap
350                       1, // iadd
351                       1, // ladd
352                       1, // fadd
353                       1, // dadd
354                       1, // isub
355                       1, // lsub
356                       1, // fsub
357                       1, // dsub
358                       1, // imul
359                       1, // lmul
360                       1, // fmul
361                       1, // dmul
362                       1, // idiv
363                       1, // ldiv
364                       1, // fdiv
365                       1, // ddiv
366                       1, // irem
367                       1, // lrem
368                       1, // frem
369                       1, // drem
370                       1, // ineg
371                       1, // lneg
372                       1, // fneg
373                       1, // dneg
374                       1, // ishl
375                       1, // lshl
376                       1, // ishr
377                       1, // lshr
378                       1, // iushr
379                       1, // lushr
380                       1, // iand
381                       1, // land
382                       1, // ior
383                       1, // lor
384                       1, // ixor
385                       1, // lxor
386                       3, // iinc
387                       1, // i2l
388                       1, // i2f
389                       1, // i2d
390                       1, // l2i
391                       1, // l2f
392                       1, // l2d
393                       1, // f2i
394                       1, // f2l
395                       1, // f2d
396                       1, // d2i
397                       1, // d2l
398                       1, // d2f
399                       1, // int2byte
400                       1, // int2char
401                       1, // int2short
402                       1, // lcmp
403                       1, // fcmpl
404                       1, // fcmpg
405                       1, // dcmpl
406                       1, // dcmpg
407                       3, // ifeq
408                       3, // ifne
409                       3, // iflt
410                       3, // ifge
411                       3, // ifgt
412                       3, // ifle
413                       3, // if_icmpeq
414                       3, // if_icmpne
415                       3, // if_icmplt
416                       3, // if_icmpge
417                       3, // if_icmpgt
418                       3, // if_icmple
419                       3, // if_acmpeq
420                       3, // if_acmpne
421                       3, // goto
422                       3, // jsr
423                       2, // ret
424                       -1, // tableswitch
425                       -1, // lookupswitch
426                       1, // ireturn
427                       1, // lreturn
428                       1, // freturn
429                       1, // dreturn
430                       1, // areturn
431                       1, // return
432                       3, // getstatic
433                       3, // putstatic
434                       3, // getfield
435                       3, // putfield
436                       3, // invokevirtual
437                       3, // invokespecial
438                       3, // invokestatic
439                       5, // invokeinterface
440                       -2, // invokedynamic
441                       3, // new
442                       2, // newarray
443                       3, // anewarray
444                       1, // arraylength
445                       1, // athrow
446                       3, // checkcast
447                       3, // instanceof
448                       1, // monitorenter
449                       1, // monitorexit
450                       -1, // wide
451                       4, // multianewarray
452                       3, // ifnull
453                       3, // ifnonnull
454                       5, // goto_w
455                       5, // jsr_w
456                       -2, // breakpoint
457                       -2, // 203
458                       -2, // 204
459                       -2, // 205
460                       -2, // 206
461                       -2, // 207
462                       -2, // 208
463                       -2, // 209
464                       -2, // 210
465                       -2, // 211
466                       -2, // 212
467                       -2, // 213
468                       -2, // 214
469                       -2, // 215
470                       -2, // 216
471                       -2, // 217
472                       -2, // 218
473                       -2, // 219
474                       -2, // 220
475                       -2, // 221
476                       -2, // 222
477                       -2, // 223
478                       -2, // 224
479                       -2, // 225
480                       -2, // 226
481                       -2, // 227
482                       -2, // 228
483                       -2, // 229
484                       -2, // 230
485                       -2, // 231
486                       -2, // 232
487                       -2, // 233
488                       -2, // 234
489                       -2, // 235
490                       -2, // 236
491                       -2, // 237
492                       -2, // 238
493                       -2, // 239
494                       -2, // 240
495                       -2, // 241
496                       -2, // 242
497                       -2, // 243
498                       -2, // 244
499                       -2, // 245
500                       -2, // 246
501                       -2, // 247
502                       -2, // 248
503                       -2, // 249
504                       -2, // 250
505                       -2, // 251
506                       -2, // 252
507                       -2, // 253
508                       -1, // impdep1  254
509                       -2, // impdep2 255
510  };
511
512  /**
513   * Gets the name of a bytecode (for debugging/printing).
514   *
515   * @param bc a bytecode
516   *
517   * @return name of the bytecode for printing. If the bytecode is
518   *  unknown, the returned string will say so. The return value
519   *  of this method is never null.
520   */
521  @Pure
522  public static String JBC_name(int bc) {
523    if (bc < 0 || bc >= _JBC_name.length) {
524      return "unknown bytecode";
525    } else {
526      return _JBC_name[bc];
527    }
528  }
529
530  /**
531   * Bytecode names (for debugging/printing)
532   */
533  private static final String[] _JBC_name =
534      {"nop",
535       "aconst_null",
536       "iconst_m1",
537       "iconst_0",
538       "iconst_1",
539       "iconst_2",
540       "iconst_3",
541       "iconst_4",
542       "iconst_5",
543       "lconst_0",
544       "lconst_1",
545       "fconst_0",
546       "fconst_1",
547       "fconst_2",
548       "dconst_0",
549       "dconst_1",
550       "bipush",
551       "sipush",
552       "ldc",
553       "ldc_w",
554       "ldc2_w",
555       "iload",
556       "lload",
557       "fload",
558       "dload",
559       "aload",
560       "iload_0",
561       "iload_1",
562       "iload_2",
563       "iload_3",
564       "lload_0",
565       "lload_1",
566       "lload_2",
567       "lload_3",
568       "fload_0",
569       "fload_1",
570       "fload_2",
571       "fload_3",
572       "dload_0",
573       "dload_1",
574       "dload_2",
575       "dload_3",
576       "aload_0",
577       "aload_1",
578       "aload_2",
579       "aload_3",
580       "iaload",
581       "laload",
582       "faload",
583       "daload",
584       "aaload",
585       "baload",
586       "caload",
587       "saload",
588       "istore",
589       "lstore",
590       "fstore",
591       "dstore",
592       "astore",
593       "istore_0",
594       "istore_1",
595       "istore_2",
596       "istore_3",
597       "lstore_0",
598       "lstore_1",
599       "lstore_2",
600       "lstore_3",
601       "fstore_0",
602       "fstore_1",
603       "fstore_2",
604       "fstore_3",
605       "dstore_0",
606       "dstore_1",
607       "dstore_2",
608       "dstore_3",
609       "astore_0",
610       "astore_1",
611       "astore_2",
612       "astore_3",
613       "iastore",
614       "lastore",
615       "fastore",
616       "dastore",
617       "aastore",
618       "bastore",
619       "castore",
620       "sastore",
621       "pop",
622       "pop2",
623       "dup",
624       "dup_x1",
625       "dup_x2",
626       "dup2",
627       "dup2_x1",
628       "dup2_x2",
629       "swap",
630       "iadd",
631       "ladd",
632       "fadd",
633       "dadd",
634       "isub",
635       "lsub",
636       "fsub",
637       "dsub",
638       "imul",
639       "lmul",
640       "fmul",
641       "dmul",
642       "idiv",
643       "ldiv",
644       "fdiv",
645       "ddiv",
646       "irem",
647       "lrem",
648       "frem",
649       "drem",
650       "ineg",
651       "lneg",
652       "fneg",
653       "dneg",
654       "ishl",
655       "lshl",
656       "ishr",
657       "lshr",
658       "iushr",
659       "lushr",
660       "iand",
661       "land",
662       "ior",
663       "lor",
664       "ixor",
665       "lxor",
666       "iinc",
667       "i2l",
668       "i2f",
669       "i2d",
670       "l2i",
671       "l2f",
672       "l2d",
673       "f2i",
674       "f2l",
675       "f2d",
676       "d2i",
677       "d2l",
678       "d2f",
679       "int2byte",
680       "int2char",
681       "int2short",
682       "lcmp",
683       "fcmpl",
684       "fcmpg",
685       "dcmpl",
686       "dcmpg",
687       "ifeq",
688       "ifne",
689       "iflt",
690       "ifge",
691       "ifgt",
692       "ifle",
693       "if_icmpeq",
694       "if_icmpne",
695       "if_icmplt",
696       "if_icmpge",
697       "if_icmpgt",
698       "if_icmple",
699       "if_acmpeq",
700       "if_acmpne",
701       "goto",
702       "jsr",
703       "ret",
704       "tableswitch",
705       "lookupswitch",
706       "ireturn",
707       "lreturn",
708       "freturn",
709       "dreturn",
710       "areturn",
711       "return",
712       "getstatic",
713       "putstatic",
714       "getfield",
715       "putfield",
716       "invokevirtual",
717       "invokespecial",
718       "invokestatic",
719       "invokeinterface",
720       "invokedynamic",
721       "new",
722       "newarray",
723       "anewarray",
724       "arraylength",
725       "athrow",
726       "checkcast",
727       "instanceof",
728       "monitorenter",
729       "monitorexit",
730       "wide",
731       "multianewarray",
732       "ifnull",
733       "ifnonnull",
734       "goto_w",
735       "jsr_w",
736       "breakpoint"
737      };
738}