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