-
Notifications
You must be signed in to change notification settings - Fork 5.2k
/
Code.java
2453 lines (2255 loc) · 74.5 KB
/
Code.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.javac.jvm;
import com.sun.tools.javac.code.*;
import com.sun.tools.javac.code.Symbol.*;
import com.sun.tools.javac.resources.CompilerProperties.Errors;
import com.sun.tools.javac.util.*;
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
import java.util.function.ToIntBiFunction;
import java.util.function.ToIntFunction;
import static com.sun.tools.javac.code.TypeTag.BOT;
import static com.sun.tools.javac.code.TypeTag.INT;
import static com.sun.tools.javac.jvm.ByteCodes.*;
import static com.sun.tools.javac.jvm.ClassFile.CONSTANT_Class;
import static com.sun.tools.javac.jvm.ClassFile.CONSTANT_Double;
import static com.sun.tools.javac.jvm.ClassFile.CONSTANT_Fieldref;
import static com.sun.tools.javac.jvm.ClassFile.CONSTANT_Float;
import static com.sun.tools.javac.jvm.ClassFile.CONSTANT_Integer;
import static com.sun.tools.javac.jvm.ClassFile.CONSTANT_InterfaceMethodref;
import static com.sun.tools.javac.jvm.ClassFile.CONSTANT_Long;
import static com.sun.tools.javac.jvm.ClassFile.CONSTANT_MethodHandle;
import static com.sun.tools.javac.jvm.ClassFile.CONSTANT_MethodType;
import static com.sun.tools.javac.jvm.ClassFile.CONSTANT_Methodref;
import static com.sun.tools.javac.jvm.ClassFile.CONSTANT_String;
import static com.sun.tools.javac.jvm.UninitializedType.*;
import static com.sun.tools.javac.jvm.ClassWriter.StackMapTableFrame;
import java.util.Arrays;
/** An internal structure that corresponds to the code attribute of
* methods in a classfile. The class also provides some utility operations to
* generate bytecode instructions.
*
* <p><b>This is NOT part of any supported API.
* If you write code that depends on this, you do so at your own risk.
* This code and its internal interfaces are subject to change or
* deletion without notice.</b>
*/
public class Code {
public final boolean debugCode;
public final boolean needStackMap;
public enum StackMapFormat {
NONE,
CLDC {
Name getAttributeName(Names names) {
return names.StackMap;
}
},
JSR202 {
Name getAttributeName(Names names) {
return names.StackMapTable;
}
};
Name getAttributeName(Names names) {
return names.empty;
}
}
final Types types;
final Symtab syms;
final PoolWriter poolWriter;
/*---------- classfile fields: --------------- */
/** The maximum stack size.
*/
public int max_stack = 0;
/** The maximum number of local variable slots.
*/
public int max_locals = 0;
/** The code buffer.
*/
public byte[] code = new byte[64];
/** the current code pointer.
*/
public int cp = 0;
/** Check the code against VM spec limits; if
* problems report them and return true.
*/
public boolean checkLimits(DiagnosticPosition pos, Log log) {
if (cp > ClassFile.MAX_CODE) {
log.error(pos, Errors.LimitCode);
return true;
}
if (max_locals > ClassFile.MAX_LOCALS) {
log.error(pos, Errors.LimitLocals);
return true;
}
if (max_stack > ClassFile.MAX_STACK) {
log.error(pos, Errors.LimitStack);
return true;
}
return false;
}
/** A buffer for expression catch data. Each enter is a vector
* of four unsigned shorts.
*/
ListBuffer<char[]> catchInfo = new ListBuffer<>();
/** A buffer for line number information. Each entry is a vector
* of two unsigned shorts.
*/
List<char[]> lineInfo = List.nil(); // handled in stack fashion
/** The CharacterRangeTable
*/
public CRTable crt;
/*---------- internal fields: --------------- */
/** Are we generating code with jumps ≥ 32K?
*/
public boolean fatcode;
/** Code generation enabled?
*/
private boolean alive = true;
/** The current machine state (registers and stack).
*/
State state;
/** Is it forbidden to compactify code, because something is
* pointing to current location?
*/
private boolean fixedPc = false;
/** The next available register.
*/
public int nextreg = 0;
/** A chain for jumps to be resolved before the next opcode is emitted.
* We do this lazily to avoid jumps to jumps.
*/
Chain pendingJumps = null;
/** The position of the currently statement, if we are at the
* start of this statement, NOPOS otherwise.
* We need this to emit line numbers lazily, which we need to do
* because of jump-to-jump optimization.
*/
int pendingStatPos = Position.NOPOS;
/** Set true when a stackMap is needed at the current PC. */
boolean pendingStackMap = false;
/** The stack map format to be generated. */
StackMapFormat stackMap;
/** Switch: emit variable debug info.
*/
boolean varDebugInfo;
/** Switch: emit line number info.
*/
boolean lineDebugInfo;
/** Emit line number info if map supplied
*/
Position.LineMap lineMap;
final MethodSymbol meth;
private int letExprStackPos = 0;
/** Construct a code object, given the settings of the fatcode,
* debugging info switches and the CharacterRangeTable.
*/
public Code(MethodSymbol meth,
boolean fatcode,
Position.LineMap lineMap,
boolean varDebugInfo,
StackMapFormat stackMap,
boolean debugCode,
CRTable crt,
Symtab syms,
Types types,
PoolWriter poolWriter) {
this.meth = meth;
this.fatcode = fatcode;
this.lineMap = lineMap;
this.lineDebugInfo = lineMap != null;
this.varDebugInfo = varDebugInfo;
this.crt = crt;
this.syms = syms;
this.types = types;
this.poolWriter = poolWriter;
this.debugCode = debugCode;
this.stackMap = stackMap;
switch (stackMap) {
case CLDC:
case JSR202:
this.needStackMap = true;
break;
default:
this.needStackMap = false;
}
state = new State();
lvar = new LocalVar[20];
}
/* **************************************************************************
* Typecodes & related stuff
****************************************************************************/
/** Given a type, return its type code (used implicitly in the
* JVM architecture).
*/
public static int typecode(Type type) {
switch (type.getTag()) {
case BYTE: return BYTEcode;
case SHORT: return SHORTcode;
case CHAR: return CHARcode;
case INT: return INTcode;
case LONG: return LONGcode;
case FLOAT: return FLOATcode;
case DOUBLE: return DOUBLEcode;
case BOOLEAN: return BYTEcode;
case VOID: return VOIDcode;
case CLASS:
case ARRAY:
case METHOD:
case BOT:
case TYPEVAR:
case UNINITIALIZED_THIS:
case UNINITIALIZED_OBJECT:
return OBJECTcode;
default: throw new AssertionError("typecode " + type.getTag());
}
}
/** Collapse type code for subtypes of int to INTcode.
*/
public static int truncate(int tc) {
switch (tc) {
case BYTEcode: case SHORTcode: case CHARcode: return INTcode;
default: return tc;
}
}
/** The width in bytes of objects of the type.
*/
public static int width(int typecode) {
switch (typecode) {
case LONGcode: case DOUBLEcode: return 2;
case VOIDcode: return 0;
default: return 1;
}
}
public static int width(Type type) {
return type == null ? 1 : width(typecode(type));
}
/** The total width taken up by a vector of objects.
*/
public static int width(List<Type> types) {
int w = 0;
for (List<Type> l = types; l.nonEmpty(); l = l.tail)
w = w + width(l.head);
return w;
}
/** Given a type, return its code for allocating arrays of that type.
*/
public static int arraycode(Type type) {
switch (type.getTag()) {
case BYTE: return 8;
case BOOLEAN: return 4;
case SHORT: return 9;
case CHAR: return 5;
case INT: return 10;
case LONG: return 11;
case FLOAT: return 6;
case DOUBLE: return 7;
case CLASS: return 0;
case ARRAY: return 1;
default: throw new AssertionError("arraycode " + type);
}
}
/* **************************************************************************
* Emit code
****************************************************************************/
/** The current output code pointer.
*/
public int curCP() {
/*
* This method has side-effects because calling it can indirectly provoke
* extra code generation, like goto instructions, depending on the context
* where it's called.
* Use with care or even better avoid using it.
*/
if (pendingJumps != null) {
resolvePending();
}
if (pendingStatPos != Position.NOPOS) {
markStatBegin();
}
fixedPc = true;
return cp;
}
/** Emit a byte of code.
*/
private void emit1(int od) {
if (!alive) return;
code = ArrayUtils.ensureCapacity(code, cp);
code[cp++] = (byte)od;
}
/** Emit two bytes of code.
*/
private void emit2(int od) {
if (!alive) return;
if (cp + 2 > code.length) {
emit1(od >> 8);
emit1(od);
} else {
code[cp++] = (byte)(od >> 8);
code[cp++] = (byte)od;
}
}
/** Emit four bytes of code.
*/
public void emit4(int od) {
if (!alive) return;
if (cp + 4 > code.length) {
emit1(od >> 24);
emit1(od >> 16);
emit1(od >> 8);
emit1(od);
} else {
code[cp++] = (byte)(od >> 24);
code[cp++] = (byte)(od >> 16);
code[cp++] = (byte)(od >> 8);
code[cp++] = (byte)od;
}
}
/** Emit an opcode.
*/
private void emitop(int op) {
if (pendingJumps != null) resolvePending();
if (alive) {
if (pendingStatPos != Position.NOPOS)
markStatBegin();
if (pendingStackMap) {
pendingStackMap = false;
emitStackMap();
}
if (debugCode)
System.err.println("emit@" + cp + " stack=" +
state.stacksize + ": " +
mnem(op));
emit1(op);
}
}
void postop() {
Assert.check(alive || isStatementStart());
}
/** Emit a ldc (or ldc_w) instruction, taking into account operand size
*/
public void emitLdc(LoadableConstant constant) {
int od = poolWriter.putConstant(constant);
if (od <= 255) {
emitop1(ldc1, od, constant);
}
else {
emitop2(ldc2, od, constant);
}
}
/** Emit a multinewarray instruction.
*/
public void emitMultianewarray(int ndims, int type, Type arrayType) {
emitop(multianewarray);
if (!alive) return;
emit2(type);
emit1(ndims);
state.pop(ndims);
state.push(arrayType);
}
/** Emit newarray.
*/
public void emitNewarray(int elemcode, Type arrayType) {
emitop(newarray);
if (!alive) return;
emit1(elemcode);
state.pop(1); // count
state.push(arrayType);
}
/** Emit anewarray.
*/
public void emitAnewarray(int od, Type arrayType) {
emitop(anewarray);
if (!alive) return;
emit2(od);
state.pop(1);
state.push(arrayType);
}
/** Emit an invokeinterface instruction.
*/
public void emitInvokeinterface(Symbol member, Type mtype) {
int argsize = width(mtype.getParameterTypes());
emitop(invokeinterface);
if (!alive) return;
emit2(poolWriter.putMember(member));
emit1(argsize + 1);
emit1(0);
state.pop(argsize + 1);
state.push(mtype.getReturnType());
}
/** Emit an invokespecial instruction.
*/
public void emitInvokespecial(Symbol member, Type mtype) {
int argsize = width(mtype.getParameterTypes());
emitop(invokespecial);
if (!alive) return;
emit2(poolWriter.putMember(member));
state.pop(argsize);
if (member.isConstructor())
state.markInitialized((UninitializedType)state.peek());
state.pop(1);
state.push(mtype.getReturnType());
}
/** Emit an invokestatic instruction.
*/
public void emitInvokestatic(Symbol member, Type mtype) {
int argsize = width(mtype.getParameterTypes());
emitop(invokestatic);
if (!alive) return;
emit2(poolWriter.putMember(member));
state.pop(argsize);
state.push(mtype.getReturnType());
}
/** Emit an invokevirtual instruction.
*/
public void emitInvokevirtual(Symbol member, Type mtype) {
int argsize = width(mtype.getParameterTypes());
emitop(invokevirtual);
if (!alive) return;
emit2(poolWriter.putMember(member));
state.pop(argsize + 1);
state.push(mtype.getReturnType());
}
/** Emit an invokedynamic instruction.
*/
public void emitInvokedynamic(DynamicMethodSymbol dynMember, Type mtype) {
int argsize = width(mtype.getParameterTypes());
emitop(invokedynamic);
if (!alive) return;
emit2(poolWriter.putDynamic(dynMember));
emit2(0);
state.pop(argsize);
state.push(mtype.getReturnType());
}
/** Emit an opcode with no operand field.
*/
public void emitop0(int op) {
emitop(op);
if (!alive) return;
switch (op) {
case aaload: {
state.pop(1);// index
Type a = state.stack[state.stacksize-1];
Assert.check(!a.hasTag(BOT)); // null type as is cannot be indexed.
state.pop(1);
state.push(types.erasure(types.elemtype(a))); }
break;
case goto_:
markDead();
break;
case nop:
case ineg:
case lneg:
case fneg:
case dneg:
break;
case aconst_null:
state.push(syms.botType);
break;
case iconst_m1:
case iconst_0:
case iconst_1:
case iconst_2:
case iconst_3:
case iconst_4:
case iconst_5:
case iload_0:
case iload_1:
case iload_2:
case iload_3:
state.push(syms.intType);
break;
case lconst_0:
case lconst_1:
case lload_0:
case lload_1:
case lload_2:
case lload_3:
state.push(syms.longType);
break;
case fconst_0:
case fconst_1:
case fconst_2:
case fload_0:
case fload_1:
case fload_2:
case fload_3:
state.push(syms.floatType);
break;
case dconst_0:
case dconst_1:
case dload_0:
case dload_1:
case dload_2:
case dload_3:
state.push(syms.doubleType);
break;
case aload_0:
state.push(lvar[0].sym.type);
break;
case aload_1:
state.push(lvar[1].sym.type);
break;
case aload_2:
state.push(lvar[2].sym.type);
break;
case aload_3:
state.push(lvar[3].sym.type);
break;
case iaload:
case baload:
case caload:
case saload:
state.pop(2);
state.push(syms.intType);
break;
case laload:
state.pop(2);
state.push(syms.longType);
break;
case faload:
state.pop(2);
state.push(syms.floatType);
break;
case daload:
state.pop(2);
state.push(syms.doubleType);
break;
case istore_0:
case istore_1:
case istore_2:
case istore_3:
case fstore_0:
case fstore_1:
case fstore_2:
case fstore_3:
case astore_0:
case astore_1:
case astore_2:
case astore_3:
case pop:
case lshr:
case lshl:
case lushr:
state.pop(1);
break;
case areturn:
case ireturn:
case freturn:
Assert.check(state.nlocks == 0);
state.pop(1);
markDead();
break;
case athrow:
state.pop(1);
markDead();
break;
case lstore_0:
case lstore_1:
case lstore_2:
case lstore_3:
case dstore_0:
case dstore_1:
case dstore_2:
case dstore_3:
case pop2:
state.pop(2);
break;
case lreturn:
case dreturn:
Assert.check(state.nlocks == 0);
state.pop(2);
markDead();
break;
case dup:
state.push(state.stack[state.stacksize-1]);
break;
case return_:
Assert.check(state.nlocks == 0);
markDead();
break;
case arraylength:
state.pop(1);
state.push(syms.intType);
break;
case isub:
case iadd:
case imul:
case idiv:
case imod:
case ishl:
case ishr:
case iushr:
case iand:
case ior:
case ixor:
state.pop(1);
// state.pop(1);
// state.push(syms.intType);
break;
case aastore:
state.pop(3);
break;
case land:
case lor:
case lxor:
case lmod:
case ldiv:
case lmul:
case lsub:
case ladd:
state.pop(2);
break;
case lcmp:
state.pop(4);
state.push(syms.intType);
break;
case l2i:
state.pop(2);
state.push(syms.intType);
break;
case i2l:
state.pop(1);
state.push(syms.longType);
break;
case i2f:
state.pop(1);
state.push(syms.floatType);
break;
case i2d:
state.pop(1);
state.push(syms.doubleType);
break;
case l2f:
state.pop(2);
state.push(syms.floatType);
break;
case l2d:
state.pop(2);
state.push(syms.doubleType);
break;
case f2i:
state.pop(1);
state.push(syms.intType);
break;
case f2l:
state.pop(1);
state.push(syms.longType);
break;
case f2d:
state.pop(1);
state.push(syms.doubleType);
break;
case d2i:
state.pop(2);
state.push(syms.intType);
break;
case d2l:
state.pop(2);
state.push(syms.longType);
break;
case d2f:
state.pop(2);
state.push(syms.floatType);
break;
case tableswitch:
case lookupswitch:
state.pop(1);
// the caller is responsible for patching up the state
break;
case dup_x1: {
Type val1 = state.pop1();
Type val2 = state.pop1();
state.push(val1);
state.push(val2);
state.push(val1);
break;
}
case bastore:
state.pop(3);
break;
case int2byte:
case int2char:
case int2short:
break;
case fmul:
case fadd:
case fsub:
case fdiv:
case fmod:
state.pop(1);
break;
case castore:
case iastore:
case fastore:
case sastore:
state.pop(3);
break;
case lastore:
case dastore:
state.pop(4);
break;
case dup2:
if (state.stack[state.stacksize-1] != null) {
Type value1 = state.pop1();
Type value2 = state.pop1();
state.push(value2);
state.push(value1);
state.push(value2);
state.push(value1);
} else {
Type value = state.pop2();
state.push(value);
state.push(value);
}
break;
case dup2_x1:
if (state.stack[state.stacksize-1] != null) {
Type value1 = state.pop1();
Type value2 = state.pop1();
Type value3 = state.pop1();
state.push(value2);
state.push(value1);
state.push(value3);
state.push(value2);
state.push(value1);
} else {
Type value1 = state.pop2();
Type value2 = state.pop1();
state.push(value1);
state.push(value2);
state.push(value1);
}
break;
case dup2_x2:
if (state.stack[state.stacksize-1] != null) {
Type value1 = state.pop1();
Type value2 = state.pop1();
if (state.stack[state.stacksize-1] != null) {
// form 1
Type value3 = state.pop1();
Type value4 = state.pop1();
state.push(value2);
state.push(value1);
state.push(value4);
state.push(value3);
state.push(value2);
state.push(value1);
} else {
// form 3
Type value3 = state.pop2();
state.push(value2);
state.push(value1);
state.push(value3);
state.push(value2);
state.push(value1);
}
} else {
Type value1 = state.pop2();
if (state.stack[state.stacksize-1] != null) {
// form 2
Type value2 = state.pop1();
Type value3 = state.pop1();
state.push(value1);
state.push(value3);
state.push(value2);
state.push(value1);
} else {
// form 4
Type value2 = state.pop2();
state.push(value1);
state.push(value2);
state.push(value1);
}
}
break;
case dup_x2: {
Type value1 = state.pop1();
if (state.stack[state.stacksize-1] != null) {
// form 1
Type value2 = state.pop1();
Type value3 = state.pop1();
state.push(value1);
state.push(value3);
state.push(value2);
state.push(value1);
} else {
// form 2
Type value2 = state.pop2();
state.push(value1);
state.push(value2);
state.push(value1);
}
}
break;
case fcmpl:
case fcmpg:
state.pop(2);
state.push(syms.intType);
break;
case dcmpl:
case dcmpg:
state.pop(4);
state.push(syms.intType);
break;
case swap: {
Type value1 = state.pop1();
Type value2 = state.pop1();
state.push(value1);
state.push(value2);
break;
}
case dadd:
case dsub:
case dmul:
case ddiv:
case dmod:
state.pop(2);
break;
case ret:
markDead();
break;
case wide:
// must be handled by the caller.
return;
case monitorenter:
case monitorexit:
state.pop(1);
break;
default:
throw new AssertionError(mnem(op));
}
postop();
}
/** Emit an opcode with a one-byte operand field.
*/
public void emitop1(int op, int od) {
emitop1(op, od, null);
}
public void emitop1(int op, int od, PoolConstant data) {
emitop(op);
if (!alive) return;
emit1(od);
switch (op) {
case bipush:
state.push(syms.intType);
break;
case ldc1:
state.push(types.constantType((LoadableConstant)data));
break;
default:
throw new AssertionError(mnem(op));
}
postop();
}
/** Emit an opcode with a one-byte operand field;
* widen if field does not fit in a byte.
*/
public void emitop1w(int op, int od) {
if (od > 0xFF) {
emitop(wide);
emitop(op);
emit2(od);
} else {
emitop(op);
emit1(od);
}
if (!alive) return;
switch (op) {
case iload:
state.push(syms.intType);
break;
case lload:
state.push(syms.longType);
break;
case fload:
state.push(syms.floatType);
break;
case dload:
state.push(syms.doubleType);
break;
case aload:
state.push(lvar[od].sym.type);
break;
case lstore:
case dstore:
state.pop(2);
break;
case istore:
case fstore:
case astore:
state.pop(1);
break;
case ret:
markDead();
break;
default:
throw new AssertionError(mnem(op));
}
postop();
}
/** Emit an opcode with two one-byte operand fields;
* widen if either field does not fit in a byte.
*/
public void emitop1w(int op, int od1, int od2) {
if (od1 > 0xFF || od2 < -128 || od2 > 127) {
emitop(wide);
emitop(op);
emit2(od1);
emit2(od2);
} else {
emitop(op);
emit1(od1);
emit1(od2);
}
if (!alive) return;
switch (op) {
case iinc:
break;
default:
throw new AssertionError(mnem(op));
}
}
/** Emit an opcode with a two-byte operand field.
*/