1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.jdo.impl.enhancer.classfile;
20
21 /***
22 * Description of the VM opcodes
23 */
24 public class VMOp implements VMConstants {
25
26 private int opcodeValue;
27
28
29 private String opcodeName;
30
31
32 private int stackArgs;
33
34
35 private int stackResults;
36
37
38 private String stackArgTypes;
39
40
41 private String stackResultTypes;
42
43
44
45 /***
46 * Return the opcode value
47 */
48 final public int opcode() {
49 return opcodeValue;
50 }
51
52 /***
53 * Return the opcode name
54 */
55 final public String name() {
56 return opcodeName;
57 }
58
59 /***
60 * Return the number of words of stack arguments expected by this operation.
61 * If the number is not a fixed value, return -1;
62 */
63 final public int nStackArgs() {
64 return stackArgs;
65 }
66
67 /***
68 * Return the number of words of stack results produced by this operation.
69 * If the number is not a fixed value, return -1;
70 */
71 final public int nStackResults() {
72 return stackResults;
73 }
74
75 /***
76 * Return the type descriptor for the stack arguments to the operation.
77 */
78 final public String argTypes() {
79 return stackArgTypes;
80 }
81
82 /***
83 * Return the type descriptor for the stack results of the operation.
84 */
85 final public String resultTypes() {
86 return stackResultTypes;
87 }
88
89 /***
90 * constructor for a VMOp
91 */
92
93 public VMOp(int theOpcode, String theOpcodeName, int nArgs, int nResults,
94 String argDescr, String resultDescr) {
95 opcodeValue = theOpcode;
96 opcodeName = theOpcodeName;
97 stackArgs = nArgs;
98 stackResults = nResults;
99 stackArgTypes = argDescr;
100 stackResultTypes = resultDescr;
101 }
102
103 /* package local methods *//package-summary/html">class="comment"> package local methods *//package-summary.html">
104
105 static VMOp[] ops = {
106
107 new VMOp(opc_nop, "nop", 0, 0, "", ""),
108
109 new VMOp(opc_aconst_null, "aconst_null", 0, 1, "", "A"),
110
111 new VMOp(opc_iconst_m1, "iconst_m1", 0, 1, "", "I"),
112
113 new VMOp(opc_iconst_0, "iconst_0", 0, 1, "", "I"),
114
115 new VMOp(opc_iconst_1, "iconst_1", 0, 1, "", "I"),
116
117 new VMOp(opc_iconst_2, "iconst_2", 0, 1, "", "I"),
118
119 new VMOp(opc_iconst_3, "iconst_3", 0, 1, "", "I"),
120
121 new VMOp(opc_iconst_4, "iconst_4", 0, 1, "", "I"),
122
123 new VMOp(opc_iconst_5, "iconst_5", 0, 1, "", "I"),
124
125 new VMOp(opc_lconst_0, "lconst_0", 0, 2, "", "J"),
126
127 new VMOp(opc_lconst_1, "lconst_1", 0, 2, "", "J"),
128
129 new VMOp(opc_fconst_0, "fconst_0", 0, 1, "", "F"),
130
131 new VMOp(opc_fconst_1, "fconst_1", 0, 1, "", "F"),
132
133 new VMOp(opc_fconst_2, "fconst_2", 0, 1, "", "F"),
134
135 new VMOp(opc_dconst_0, "dconst_0", 0, 2, "", "D"),
136
137 new VMOp(opc_dconst_1, "dconst_1", 0, 2, "", "D"),
138
139 new VMOp(opc_bipush, "bipush", 0, 1, "", "I"),
140
141 new VMOp(opc_sipush, "sipush", 0, 1, "", "I"),
142
143 new VMOp(opc_ldc, "ldc", 0, 1, "", "W"),
144
145 new VMOp(opc_ldc_w, "ldc_w", 0, 1, "", "W"),
146
147 new VMOp(opc_ldc2_w, "ldc2_w", 0, 2, "", "X"),
148
149 new VMOp(opc_iload, "iload", 0, 1, "", "I"),
150
151 new VMOp(opc_lload, "lload", 0, 2, "", "J"),
152
153 new VMOp(opc_fload, "fload", 0, 1, "", "F"),
154
155 new VMOp(opc_dload, "dload", 0, 2, "", "D"),
156
157 new VMOp(opc_aload, "aload", 0, 1, "", "A"),
158
159 new VMOp(opc_iload_0, "iload_0", 0, 1, "", "I"),
160
161 new VMOp(opc_iload_1, "iload_1", 0, 1, "", "I"),
162
163 new VMOp(opc_iload_2, "iload_2", 0, 1, "", "I"),
164
165 new VMOp(opc_iload_3, "iload_3", 0, 1, "", "I"),
166
167 new VMOp(opc_lload_0, "lload_0", 0, 2, "", "J"),
168
169 new VMOp(opc_lload_1, "lload_1", 0, 2, "", "J"),
170
171 new VMOp(opc_lload_2, "lload_2", 0, 2, "", "J"),
172
173 new VMOp(opc_lload_3, "lload_3", 0, 2, "", "J"),
174
175 new VMOp(opc_fload_0, "fload_0", 0, 1, "", "F"),
176
177 new VMOp(opc_fload_1, "fload_1", 0, 1, "", "F"),
178
179 new VMOp(opc_fload_2, "fload_2", 0, 1, "", "F"),
180
181 new VMOp(opc_fload_3, "fload_3", 0, 1, "", "F"),
182
183 new VMOp(opc_dload_0, "dload_0", 0, 2, "", "D"),
184
185 new VMOp(opc_dload_1, "dload_1", 0, 2, "", "D"),
186
187 new VMOp(opc_dload_2, "dload_2", 0, 2, "", "D"),
188
189 new VMOp(opc_dload_3, "dload_3", 0, 2, "", "D"),
190
191 new VMOp(opc_aload_0, "aload_0", 0, 1, "", "A"),
192
193 new VMOp(opc_aload_1, "aload_1", 0, 1, "", "A"),
194
195 new VMOp(opc_aload_2, "aload_2", 0, 1, "", "A"),
196
197 new VMOp(opc_aload_3, "aload_3", 0, 1, "", "A"),
198
199 new VMOp(opc_iaload, "iaload", 2, 1, "AI", "I"),
200
201 new VMOp(opc_laload, "laload", 2, 2, "AI", "J"),
202
203 new VMOp(opc_faload, "faload", 2, 1, "AI", "F"),
204
205 new VMOp(opc_daload, "daload", 2, 2, "AI", "D"),
206
207 new VMOp(opc_aaload, "aaload", 2, 1, "AI", "A"),
208
209 new VMOp(opc_baload, "baload", 2, 1, "AI", "I"),
210
211 new VMOp(opc_caload, "caload", 2, 1, "AI", "I"),
212
213 new VMOp(opc_saload, "saload", 2, 1, "AI", "I"),
214
215 new VMOp(opc_istore, "istore", 1, 0, "I", ""),
216
217 new VMOp(opc_lstore, "lstore", 2, 0, "J", ""),
218
219 new VMOp(opc_fstore, "fstore", 1, 0, "F", ""),
220
221 new VMOp(opc_dstore, "dstore", 2, 0, "D", ""),
222
223 new VMOp(opc_astore, "astore", 1, 0, "A", ""),
224
225 new VMOp(opc_istore_0, "istore_0", 1, 0, "I", ""),
226
227 new VMOp(opc_istore_1, "istore_1", 1, 0, "I", ""),
228
229 new VMOp(opc_istore_2, "istore_2", 1, 0, "I", ""),
230
231 new VMOp(opc_istore_3, "istore_3", 1, 0, "I", ""),
232
233 new VMOp(opc_lstore_0, "lstore_0", 2, 0, "J", ""),
234
235 new VMOp(opc_lstore_1, "lstore_1", 2, 0, "J", ""),
236
237 new VMOp(opc_lstore_2, "lstore_2", 2, 0, "J", ""),
238
239 new VMOp(opc_lstore_3, "lstore_3", 2, 0, "J", ""),
240
241 new VMOp(opc_fstore_0, "fstore_0", 1, 0, "F", ""),
242
243 new VMOp(opc_fstore_1, "fstore_1", 1, 0, "F", ""),
244
245 new VMOp(opc_fstore_2, "fstore_2", 1, 0, "F", ""),
246
247 new VMOp(opc_fstore_3, "fstore_3", 1, 0, "F", ""),
248
249 new VMOp(opc_dstore_0, "dstore_0", 2, 0, "D", ""),
250
251 new VMOp(opc_dstore_1, "dstore_1", 2, 0, "D", ""),
252
253 new VMOp(opc_dstore_2, "dstore_2", 2, 0, "D", ""),
254
255 new VMOp(opc_dstore_3, "dstore_3", 2, 0, "D", ""),
256
257 new VMOp(opc_astore_0, "astore_0", 1, 0, "A", ""),
258
259 new VMOp(opc_astore_1, "astore_1", 1, 0, "A", ""),
260
261 new VMOp(opc_astore_2, "astore_2", 1, 0, "A", ""),
262
263 new VMOp(opc_astore_3, "astore_3", 1, 0, "A", ""),
264
265 new VMOp(opc_iastore, "iastore", 3, 0, "AII", ""),
266
267 new VMOp(opc_lastore, "lastore", 4, 0, "AIJ", ""),
268
269 new VMOp(opc_fastore, "fastore", 3, 0, "AIF", ""),
270
271 new VMOp(opc_dastore, "dastore", 4, 0, "AID", ""),
272
273 new VMOp(opc_aastore, "aastore", 3, 0, "AIA", ""),
274
275 new VMOp(opc_bastore, "bastore", 3, 0, "AII", ""),
276
277 new VMOp(opc_castore, "castore", 3, 0, "AII", ""),
278
279 new VMOp(opc_sastore, "sastore", 3, 0, "AII", ""),
280
281 new VMOp(opc_pop, "pop", 1, 0, "W", ""),
282
283 new VMOp(opc_pop2, "pop2", 2, 0, "WW", ""),
284
285 new VMOp(opc_dup, "dup", 1, 2, "W", "WW"),
286
287 new VMOp(opc_dup_x1, "dup_x1", 2, 3, "WW", "WWW"),
288
289 new VMOp(opc_dup_x2, "dup_x2", 3, 4, "WWW", "WWWW"),
290
291 new VMOp(opc_dup2, "dup2", 2, 4, "WW", "WWWW"),
292
293 new VMOp(opc_dup2_x1, "dup2_x1", 3, 5, "WWW", "WWWWW"),
294
295 new VMOp(opc_dup2_x2, "dup2_x2", 4, 6, "WWWW", "WWWWWW"),
296
297 new VMOp(opc_swap, "swap", 2, 2, "WW", "WW"),
298
299 new VMOp(opc_iadd, "iadd", 2, 1, "II", "I"),
300
301 new VMOp(opc_ladd, "ladd", 4, 2, "JJ", "J"),
302
303 new VMOp(opc_fadd, "fadd", 2, 1, "FF", "F"),
304
305 new VMOp(opc_dadd, "dadd", 4, 2, "DD", "D"),
306
307 new VMOp(opc_isub, "isub", 2, 1, "II", "I"),
308
309 new VMOp(opc_lsub, "lsub", 4, 2, "JJ", "J"),
310
311 new VMOp(opc_fsub, "fsub", 2, 1, "FF", "F"),
312
313 new VMOp(opc_dsub, "dsub", 4, 2, "DD", "D"),
314
315 new VMOp(opc_imul, "imul", 2, 1, "II", "I"),
316
317 new VMOp(opc_lmul, "lmul", 4, 2, "JJ", "J"),
318
319 new VMOp(opc_fmul, "fmul", 2, 1, "FF", "F"),
320
321 new VMOp(opc_dmul, "dmul", 4, 2, "DD", "D"),
322
323 new VMOp(opc_idiv, "idiv", 2, 1, "II", "I"),
324
325 new VMOp(opc_ldiv, "ldiv", 4, 2, "JJ", "J"),
326
327 new VMOp(opc_fdiv, "fdiv", 2, 1, "FF", "F"),
328
329 new VMOp(opc_ddiv, "ddiv", 4, 2, "DD", "D"),
330
331 new VMOp(opc_irem, "irem", 2, 1, "II", "I"),
332
333 new VMOp(opc_lrem, "lrem", 4, 2, "JJ", "J"),
334
335 new VMOp(opc_frem, "frem", 2, 1, "FF", "F"),
336
337 new VMOp(opc_drem, "drem", 4, 2, "DD", "D"),
338
339 new VMOp(opc_ineg, "ineg", 1, 1, "I", "I"),
340
341 new VMOp(opc_lneg, "lneg", 2, 2, "J", "J"),
342
343 new VMOp(opc_fneg, "fneg", 1, 1, "F", "F"),
344
345 new VMOp(opc_dneg, "dneg", 2, 2, "D", "D"),
346
347 new VMOp(opc_ishl, "ishl", 2, 1, "II", "I"),
348
349 new VMOp(opc_lshl, "lshl", 3, 2, "JI", "J"),
350
351 new VMOp(opc_ishr, "ishr", 2, 1, "II", "I"),
352
353 new VMOp(opc_lshr, "lshr", 3, 2, "JI", "J"),
354
355 new VMOp(opc_iushr, "iushr", 2, 1, "II", "I"),
356
357 new VMOp(opc_lushr, "lushr", 3, 2, "JI", "J"),
358
359 new VMOp(opc_iand, "iand", 2, 1, "II", "I"),
360
361 new VMOp(opc_land, "land", 4, 2, "JJ", "J"),
362
363 new VMOp(opc_ior, "ior", 2, 1, "II", "I"),
364
365 new VMOp(opc_lor, "lor", 4, 2, "JJ", "J"),
366
367 new VMOp(opc_ixor, "ixor", 2, 1, "II", "I"),
368
369 new VMOp(opc_lxor, "lxor", 4, 2, "JJ", "J"),
370
371 new VMOp(opc_iinc, "iinc", 0, 0, "", ""),
372
373 new VMOp(opc_i2l, "i2l", 1, 2, "I", "J"),
374
375 new VMOp(opc_i2f, "i2f", 1, 1, "I", "F"),
376
377 new VMOp(opc_i2d, "i2d", 1, 2, "I", "D"),
378
379 new VMOp(opc_l2i, "l2i", 2, 1, "J", "I"),
380
381 new VMOp(opc_l2f, "l2f", 2, 1, "J", "F"),
382
383 new VMOp(opc_l2d, "l2d", 2, 2, "J", "D"),
384
385 new VMOp(opc_f2i, "f2i", 1, 1, "F", "I"),
386
387 new VMOp(opc_f2l, "f2l", 1, 2, "F", "J"),
388
389 new VMOp(opc_f2d, "f2d", 1, 2, "F", "D"),
390
391 new VMOp(opc_d2i, "d2i", 2, 1, "D", "I"),
392
393 new VMOp(opc_d2l, "d2l", 2, 2, "D", "J"),
394
395 new VMOp(opc_d2f, "d2f", 2, 1, "D", "F"),
396
397 new VMOp(opc_i2b, "i2b", 1, 1, "I", "I"),
398
399 new VMOp(opc_i2c, "i2c", 1, 1, "I", "I"),
400
401 new VMOp(opc_i2s, "i2s", 1, 1, "I", "I"),
402
403 new VMOp(opc_lcmp, "lcmp", 4, 1, "JJ", "I"),
404
405 new VMOp(opc_fcmpl, "fcmpl", 2, 1, "FF", "I"),
406
407 new VMOp(opc_fcmpg, "fcmpg", 2, 1, "FF", "I"),
408
409 new VMOp(opc_dcmpl, "dcmpl", 4, 1, "DD", "I"),
410
411 new VMOp(opc_dcmpg, "dcmpg", 4, 1, "DD", "I"),
412
413 new VMOp(opc_ifeq, "ifeq", 1, 0, "I", ""),
414
415 new VMOp(opc_ifne, "ifne", 1, 0, "I", ""),
416
417 new VMOp(opc_iflt, "iflt", 1, 0, "I", ""),
418
419 new VMOp(opc_ifge, "ifge", 1, 0, "I", ""),
420
421 new VMOp(opc_ifgt, "ifgt", 1, 0, "I", ""),
422
423 new VMOp(opc_ifle, "ifle", 1, 0, "I", ""),
424
425 new VMOp(opc_if_icmpeq, "if_icmpeq", 2, 0, "II", ""),
426
427 new VMOp(opc_if_icmpne, "if_icmpne", 2, 0, "II", ""),
428
429 new VMOp(opc_if_icmplt, "if_icmplt", 2, 0, "II", ""),
430
431 new VMOp(opc_if_icmpge, "if_icmpge", 2, 0, "II", ""),
432
433 new VMOp(opc_if_icmpgt, "if_icmpgt", 2, 0, "II", ""),
434
435 new VMOp(opc_if_icmple, "if_icmple", 2, 0, "II", ""),
436
437 new VMOp(opc_if_acmpeq, "if_acmpeq", 2, 0, "AA", ""),
438
439 new VMOp(opc_if_acmpne, "if_acmpne", 2, 0, "AA", ""),
440
441 new VMOp(opc_goto, "goto", 0, 0, "", ""),
442
443 new VMOp(opc_jsr, "jsr", 0, 1, "", "W"),
444
445 new VMOp(opc_ret, "ret", 0, 0, "", ""),
446
447 new VMOp(opc_tableswitch, "tableswitch", 1, 0, "I", ""),
448
449 new VMOp(opc_lookupswitch, "lookupswitch", 1, 0, "I", ""),
450
451 new VMOp(opc_ireturn, "ireturn", 1, 0, "I", ""),
452
453 new VMOp(opc_lreturn, "lreturn", 2, 0, "J", ""),
454
455 new VMOp(opc_freturn, "freturn", 1, 0, "F", ""),
456
457 new VMOp(opc_dreturn, "dreturn", 2, 0, "D", ""),
458
459 new VMOp(opc_areturn, "areturn", 1, 0, "A", ""),
460
461 new VMOp(opc_return, "return", 0, 0, "", ""),
462
463 new VMOp(opc_getstatic, "getstatic", 0, -1, "", "?"),
464
465 new VMOp(opc_putstatic, "putstatic", -1, 0, "?", ""),
466
467 new VMOp(opc_getfield, "getfield", 1, -1, "A", "?"),
468
469 new VMOp(opc_putfield, "putfield", -1, 0, "A?", ""),
470
471 new VMOp(opc_invokevirtual, "invokevirtual", -1, -1, "A?", "?"),
472
473 new VMOp(opc_invokespecial, "invokespecial", -1, -1, "A?", "?"),
474
475 new VMOp(opc_invokestatic, "invokestatic", -1, -1, "?", "?"),
476
477 new VMOp(opc_invokeinterface, "invokeinterface", -1, -1, "A?", "?"),
478
479 new VMOp(opc_xxxunusedxxx, "xxxunusedxxx", 0, 0, "", ""),
480
481 new VMOp(opc_new, "new", 0, 1, "", "A"),
482
483 new VMOp(opc_newarray, "newarray", 1, 1, "I", "A"),
484
485 new VMOp(opc_anewarray, "anewarray", 1, 1, "I", "A"),
486
487 new VMOp(opc_arraylength, "arraylength", 1, 1, "A", "I"),
488
489 new VMOp(opc_athrow, "athrow", 1, 0, "A", "?"),
490
491 new VMOp(opc_checkcast, "checkcast", 1, 1, "A", "A"),
492
493 new VMOp(opc_instanceof, "instanceof", 1, 1, "A", "I"),
494
495 new VMOp(opc_monitorenter, "monitorenter", 1, 0, "A", ""),
496
497 new VMOp(opc_monitorexit, "monitorexit", 1, 0, "A", ""),
498
499 new VMOp(opc_wide, "wide", 0, 0, "", ""),
500
501 new VMOp(opc_multianewarray, "multianewarray", -1, 1, "?", "A"),
502
503 new VMOp(opc_ifnull, "ifnull", 1, 0, "A", ""),
504
505 new VMOp(opc_ifnonnull, "ifnonnull", 1, 0, "A", ""),
506
507 new VMOp(opc_goto_w, "goto_w", 0, 0, "", ""),
508
509 new VMOp(opc_jsr_w, "jsr_w", 0, 1, "", "W") };
510
511 /***
512 * Check that each entry in the ops array has a valid VMOp entry
513 */
514 private static void check() {
515 for (int i=0; i<=opc_jsr_w; i++) {
516 VMOp op = ops[i];
517 if (op == null)
518 throw new InsnError ("null VMOp for " + i);
519 if (op.opcode() != i)
520 throw new InsnError ("bad opcode for " + i);
521
522 if (1 == 0) {
523
524 checkTypes(op.argTypes(), op.nStackArgs(), op);
525 checkTypes(op.resultTypes(), op.nStackResults(), op);
526 }
527 }
528 }
529
530 private static void checkTypes(String types, int n, VMOp op) {
531 for (int i=0; i<types.length(); i++) {
532 char c = types.charAt(i);
533 if (c == '?')
534 return;
535 if (c == 'J' || c == 'X' || c == 'D')
536 n -= 2;
537 else
538 n -= 1;
539 }
540 if (n != 0)
541 throw new InsnError ("Bad arg/result for VMOp " + op.opcodeName);
542 }
543
544 static {
545 check();
546 }
547 }