1 /*******************************************************************************
2 * Copyright (c) 2000, 2001, 2002 International Business Machines Corp. and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v0.5
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v05.html
9 * IBM Corporation - initial API and implementation
10 ******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.codegen;
13 import net.sourceforge.phpdt.internal.compiler.*;
15 import net.sourceforge.phpdt.internal.compiler.impl.*;
16 import net.sourceforge.phpdt.internal.compiler.ast.*;
17 import net.sourceforge.phpdt.internal.compiler.classfmt.*;
18 import net.sourceforge.phpdt.internal.compiler.flow.*;
19 import net.sourceforge.phpdt.internal.compiler.lookup.*;
21 public class CodeStream implements OperatorIds, ClassFileConstants, Opcodes, BaseTypes, TypeConstants, TypeIds {
22 // It will be responsible for the following items.
24 // -> Tracking Max Stack.
26 public int stackMax; // Use Ints to keep from using extra bc when adding
27 public int stackDepth; // Use Ints to keep from using extra bc when adding
29 public static final int max = 100; // Maximum size of the code array
30 public static final int growFactor = 400;
31 public static final int LABELS_INCREMENT = 5;
32 public byte[] bCodeStream;
33 public int pcToSourceMapSize;
34 public int[] pcToSourceMap = new int[24];
35 public int lastEntryPC; // last entry recorded
36 public int[] lineSeparatorPositions;
37 public int position; // So when first set can be incremented
38 public int classFileOffset;
39 public int startingClassFileOffset; // I need to keep the starting point inside the byte array
40 public ConstantPool constantPool;
41 // The constant pool used to generate bytecodes that need to store information into the constant pool
42 public ClassFile classFile; // The current classfile it is associated to.
43 // local variable attributes output
44 public static final int LOCALS_INCREMENT = 10;
45 public LocalVariableBinding[] locals = new LocalVariableBinding[LOCALS_INCREMENT];
46 static LocalVariableBinding[] noLocals = new LocalVariableBinding[LOCALS_INCREMENT];
47 public LocalVariableBinding[] visibleLocals = new LocalVariableBinding[LOCALS_INCREMENT];
48 static LocalVariableBinding[] noVisibleLocals = new LocalVariableBinding[LOCALS_INCREMENT];
49 int visibleLocalsCount;
50 public AbstractMethodDeclaration methodDeclaration;
51 public ExceptionLabel[] exceptionHandlers = new ExceptionLabel[LABELS_INCREMENT];
52 static ExceptionLabel[] noExceptionHandlers = new ExceptionLabel[LABELS_INCREMENT];
53 public int exceptionHandlersNumber;
54 public static FieldBinding[] ImplicitThis = new FieldBinding[] {
56 public boolean generateLineNumberAttributes;
57 public boolean generateLocalVariableTableAttributes;
58 public boolean preserveUnusedLocals;
59 // store all the labels placed at the current position to be able to optimize
60 // a jump to the next bytecode.
61 public Label[] labels = new Label[LABELS_INCREMENT];
62 static Label[] noLabels = new Label[LABELS_INCREMENT];
63 public int countLabels;
64 public int allLocalsCounter;
65 public int maxFieldCount;
67 public boolean wideMode = false;
68 public static final CompilationResult RESTART_IN_WIDE_MODE = new CompilationResult((char[]) null, 0, 0, 0);
70 public CodeStream(ClassFile classFile) {
71 generateLineNumberAttributes = (classFile.produceDebugAttributes & CompilerOptions.Lines) != 0;
72 generateLocalVariableTableAttributes = (classFile.produceDebugAttributes & CompilerOptions.Vars) != 0;
73 if (generateLineNumberAttributes) {
74 lineSeparatorPositions = classFile.referenceBinding.scope.referenceCompilationUnit().compilationResult.lineSeparatorPositions;
77 final public void aaload() {
82 bCodeStream[classFileOffset++] = OPC_aaload;
83 } catch (IndexOutOfBoundsException e) {
84 resizeByteArray(OPC_aaload);
87 final public void aastore() {
92 bCodeStream[classFileOffset++] = OPC_aastore;
93 } catch (IndexOutOfBoundsException e) {
94 resizeByteArray(OPC_aastore);
97 final public void aconst_null() {
100 if (stackDepth > stackMax)
101 stackMax = stackDepth;
104 bCodeStream[classFileOffset++] = OPC_aconst_null;
105 } catch (IndexOutOfBoundsException e) {
106 resizeByteArray(OPC_aconst_null);
109 public final void addDefinitelyAssignedVariables(Scope scope, int initStateIndex) {
110 // Required to fix 1PR0XVS: LFRE:WINNT - Compiler: variable table for method appears incorrect
111 if (!generateLocalVariableTableAttributes)
113 /* if (initStateIndex == lastInitStateIndexWhenAddingInits)
115 lastInitStateIndexWhenAddingInits = initStateIndex;
116 if (lastInitStateIndexWhenRemovingInits != initStateIndex){
117 lastInitStateIndexWhenRemovingInits = -2; // reinitialize remove index
118 // remove(1)-add(1)-remove(1) -> ignore second remove
119 // remove(1)-add(2)-remove(1) -> perform second remove
123 for (int i = 0; i < visibleLocalsCount; i++) {
124 LocalVariableBinding localBinding = visibleLocals[i];
125 if (localBinding != null) {
126 // Check if the local is definitely assigned
127 if ((initStateIndex != -1) && isDefinitelyAssigned(scope, initStateIndex, localBinding)) {
128 if ((localBinding.initializationCount == 0)
129 || (localBinding.initializationPCs[((localBinding.initializationCount - 1) << 1) + 1] != -1)) {
130 /* There are two cases:
131 * 1) there is no initialization interval opened ==> add an opened interval
132 * 2) there is already some initialization intervals but the last one is closed ==> add an opened interval
133 * An opened interval means that the value at localBinding.initializationPCs[localBinding.initializationCount - 1][1]
135 * initializationPCs is a collection of pairs of int:
136 * first value is the startPC and second value is the endPC. -1 one for the last value means that the interval
139 localBinding.recordInitializationStartPC(position);
145 public void addLabel(Label aLabel) {
146 if (countLabels == labels.length)
147 System.arraycopy(labels, 0, (labels = new Label[countLabels + LABELS_INCREMENT]), 0, countLabels);
148 labels[countLabels++] = aLabel;
150 public void addVisibleLocalVariable(LocalVariableBinding localBinding) {
151 if (!generateLocalVariableTableAttributes)
154 if (visibleLocalsCount >= visibleLocals.length) {
155 System.arraycopy(visibleLocals, 0, (visibleLocals = new LocalVariableBinding[visibleLocalsCount * 2]), 0, visibleLocalsCount);
157 visibleLocals[visibleLocalsCount++] = localBinding;
159 final public void aload(int iArg) {
162 if (stackDepth > stackMax)
163 stackMax = stackDepth;
164 if (maxLocals <= iArg) {
165 maxLocals = iArg + 1;
167 if (iArg > 255) { // Widen
170 bCodeStream[classFileOffset++] = OPC_wide;
171 } catch (IndexOutOfBoundsException e) {
172 resizeByteArray(OPC_wide);
176 bCodeStream[classFileOffset++] = OPC_aload;
177 } catch (IndexOutOfBoundsException e) {
178 resizeByteArray(OPC_aload);
180 writeUnsignedShort(iArg);
182 // Don't need to use the wide bytecode
185 bCodeStream[classFileOffset++] = OPC_aload;
186 } catch (IndexOutOfBoundsException e) {
187 resizeByteArray(OPC_aload);
191 bCodeStream[classFileOffset++] = (byte) (iArg);
192 } catch (IndexOutOfBoundsException e) {
193 resizeByteArray((byte) iArg);
197 final public void aload_0() {
200 if (stackDepth > stackMax)
201 stackMax = stackDepth;
202 if (maxLocals == 0) {
207 bCodeStream[classFileOffset++] = OPC_aload_0;
208 } catch (IndexOutOfBoundsException e) {
209 resizeByteArray(OPC_aload_0);
212 final public void aload_1() {
215 if (stackDepth > stackMax)
216 stackMax = stackDepth;
217 if (maxLocals <= 1) {
222 bCodeStream[classFileOffset++] = OPC_aload_1;
223 } catch (IndexOutOfBoundsException e) {
224 resizeByteArray(OPC_aload_1);
227 final public void aload_2() {
230 if (stackDepth > stackMax)
231 stackMax = stackDepth;
232 if (maxLocals <= 2) {
237 bCodeStream[classFileOffset++] = OPC_aload_2;
238 } catch (IndexOutOfBoundsException e) {
239 resizeByteArray(OPC_aload_2);
242 final public void aload_3() {
245 if (stackDepth > stackMax)
246 stackMax = stackDepth;
247 if (maxLocals <= 3) {
252 bCodeStream[classFileOffset++] = OPC_aload_3;
253 } catch (IndexOutOfBoundsException e) {
254 resizeByteArray(OPC_aload_3);
257 public final void anewarray(TypeBinding typeBinding) {
261 bCodeStream[classFileOffset++] = OPC_anewarray;
262 } catch (IndexOutOfBoundsException e) {
263 resizeByteArray(OPC_anewarray);
265 writeUnsignedShort(constantPool.literalIndex(typeBinding));
267 public void anewarrayJavaLangClass() {
268 // anewarray: java.lang.Class
272 bCodeStream[classFileOffset++] = OPC_anewarray;
273 } catch (IndexOutOfBoundsException e) {
274 resizeByteArray(OPC_anewarray);
276 writeUnsignedShort(constantPool.literalIndexForJavaLangClass());
278 public void anewarrayJavaLangObject() {
279 // anewarray: java.lang.Object
283 bCodeStream[classFileOffset++] = OPC_anewarray;
284 } catch (IndexOutOfBoundsException e) {
285 resizeByteArray(OPC_anewarray);
287 writeUnsignedShort(constantPool.literalIndexForJavaLangObject());
289 final public void areturn() {
292 // the stackDepth should be equal to 0
295 bCodeStream[classFileOffset++] = OPC_areturn;
296 } catch (IndexOutOfBoundsException e) {
297 resizeByteArray(OPC_areturn);
300 public void arrayAt(int typeBindingID) {
301 switch (typeBindingID) {
328 public void arrayAtPut(int elementTypeID, boolean valueRequired) {
329 switch (elementTypeID) {
372 final public void arraylength() {
376 bCodeStream[classFileOffset++] = OPC_arraylength;
377 } catch (IndexOutOfBoundsException e) {
378 resizeByteArray(OPC_arraylength);
381 final public void astore(int iArg) {
384 if (maxLocals <= iArg) {
385 maxLocals = iArg + 1;
387 if (iArg > 255) { // Widen
390 bCodeStream[classFileOffset++] = OPC_wide;
391 } catch (IndexOutOfBoundsException e) {
392 resizeByteArray(OPC_wide);
396 bCodeStream[classFileOffset++] = OPC_astore;
397 } catch (IndexOutOfBoundsException e) {
398 resizeByteArray(OPC_astore);
400 writeUnsignedShort(iArg);
404 bCodeStream[classFileOffset++] = OPC_astore;
405 } catch (IndexOutOfBoundsException e) {
406 resizeByteArray(OPC_astore);
410 bCodeStream[classFileOffset++] = (byte) iArg;
411 } catch (IndexOutOfBoundsException e) {
412 resizeByteArray((byte) iArg);
416 final public void astore_0() {
419 if (maxLocals == 0) {
424 bCodeStream[classFileOffset++] = OPC_astore_0;
425 } catch (IndexOutOfBoundsException e) {
426 resizeByteArray(OPC_astore_0);
429 final public void astore_1() {
432 if (maxLocals <= 1) {
437 bCodeStream[classFileOffset++] = OPC_astore_1;
438 } catch (IndexOutOfBoundsException e) {
439 resizeByteArray(OPC_astore_1);
442 final public void astore_2() {
445 if (maxLocals <= 2) {
450 bCodeStream[classFileOffset++] = OPC_astore_2;
451 } catch (IndexOutOfBoundsException e) {
452 resizeByteArray(OPC_astore_2);
455 final public void astore_3() {
458 if (maxLocals <= 3) {
463 bCodeStream[classFileOffset++] = OPC_astore_3;
464 } catch (IndexOutOfBoundsException e) {
465 resizeByteArray(OPC_astore_3);
468 final public void athrow() {
473 bCodeStream[classFileOffset++] = OPC_athrow;
474 } catch (IndexOutOfBoundsException e) {
475 resizeByteArray(OPC_athrow);
478 final public void baload() {
483 bCodeStream[classFileOffset++] = OPC_baload;
484 } catch (IndexOutOfBoundsException e) {
485 resizeByteArray(OPC_baload);
488 final public void bastore() {
493 bCodeStream[classFileOffset++] = OPC_bastore;
494 } catch (IndexOutOfBoundsException e) {
495 resizeByteArray(OPC_bastore);
498 final public void bipush(byte b) {
501 if (stackDepth > stackMax)
502 stackMax = stackDepth;
505 bCodeStream[classFileOffset++] = OPC_bipush;
506 } catch (IndexOutOfBoundsException e) {
507 resizeByteArray(OPC_bipush);
511 final public void caload() {
516 bCodeStream[classFileOffset++] = OPC_caload;
517 } catch (IndexOutOfBoundsException e) {
518 resizeByteArray(OPC_caload);
521 final public void castore() {
526 bCodeStream[classFileOffset++] = OPC_castore;
527 } catch (IndexOutOfBoundsException e) {
528 resizeByteArray(OPC_castore);
531 public final void checkcast(TypeBinding typeBinding) {
535 bCodeStream[classFileOffset++] = OPC_checkcast;
536 } catch (IndexOutOfBoundsException e) {
537 resizeByteArray(OPC_checkcast);
539 writeUnsignedShort(constantPool.literalIndex(typeBinding));
541 public final void checkcastJavaLangError() {
545 bCodeStream[classFileOffset++] = OPC_checkcast;
546 } catch (IndexOutOfBoundsException e) {
547 resizeByteArray(OPC_checkcast);
549 writeUnsignedShort(constantPool.literalIndexForJavaLangError());
551 final public void d2f() {
556 bCodeStream[classFileOffset++] = OPC_d2f;
557 } catch (IndexOutOfBoundsException e) {
558 resizeByteArray(OPC_d2f);
561 final public void d2i() {
566 bCodeStream[classFileOffset++] = OPC_d2i;
567 } catch (IndexOutOfBoundsException e) {
568 resizeByteArray(OPC_d2i);
571 final public void d2l() {
575 bCodeStream[classFileOffset++] = OPC_d2l;
576 } catch (IndexOutOfBoundsException e) {
577 resizeByteArray(OPC_d2l);
580 final public void dadd() {
585 bCodeStream[classFileOffset++] = OPC_dadd;
586 } catch (IndexOutOfBoundsException e) {
587 resizeByteArray(OPC_dadd);
590 final public void daload() {
594 bCodeStream[classFileOffset++] = OPC_daload;
595 } catch (IndexOutOfBoundsException e) {
596 resizeByteArray(OPC_daload);
599 final public void dastore() {
604 bCodeStream[classFileOffset++] = OPC_dastore;
605 } catch (IndexOutOfBoundsException e) {
606 resizeByteArray(OPC_dastore);
609 final public void dcmpg() {
614 bCodeStream[classFileOffset++] = OPC_dcmpg;
615 } catch (IndexOutOfBoundsException e) {
616 resizeByteArray(OPC_dcmpg);
619 final public void dcmpl() {
624 bCodeStream[classFileOffset++] = OPC_dcmpl;
625 } catch (IndexOutOfBoundsException e) {
626 resizeByteArray(OPC_dcmpl);
629 final public void dconst_0() {
632 if (stackDepth > stackMax)
633 stackMax = stackDepth;
636 bCodeStream[classFileOffset++] = OPC_dconst_0;
637 } catch (IndexOutOfBoundsException e) {
638 resizeByteArray(OPC_dconst_0);
641 final public void dconst_1() {
644 if (stackDepth > stackMax)
645 stackMax = stackDepth;
648 bCodeStream[classFileOffset++] = OPC_dconst_1;
649 } catch (IndexOutOfBoundsException e) {
650 resizeByteArray(OPC_dconst_1);
653 final public void ddiv() {
658 bCodeStream[classFileOffset++] = OPC_ddiv;
659 } catch (IndexOutOfBoundsException e) {
660 resizeByteArray(OPC_ddiv);
663 public void decrStackSize(int offset) {
664 stackDepth -= offset;
666 final public void dload(int iArg) {
669 if (stackDepth > stackMax)
670 stackMax = stackDepth;
671 if (maxLocals < iArg + 2) {
672 maxLocals = iArg + 2; // + 2 because it is a double
674 if (iArg > 255) { // Widen
677 bCodeStream[classFileOffset++] = OPC_wide;
678 } catch (IndexOutOfBoundsException e) {
679 resizeByteArray(OPC_wide);
683 bCodeStream[classFileOffset++] = OPC_dload;
684 } catch (IndexOutOfBoundsException e) {
685 resizeByteArray(OPC_dload);
687 writeUnsignedShort(iArg);
689 // Don't need to use the wide bytecode
692 bCodeStream[classFileOffset++] = OPC_dload;
693 } catch (IndexOutOfBoundsException e) {
694 resizeByteArray(OPC_dload);
698 bCodeStream[classFileOffset++] = (byte) iArg;
699 } catch (IndexOutOfBoundsException e) {
700 resizeByteArray((byte) iArg);
704 final public void dload_0() {
707 if (stackDepth > stackMax)
708 stackMax = stackDepth;
714 bCodeStream[classFileOffset++] = OPC_dload_0;
715 } catch (IndexOutOfBoundsException e) {
716 resizeByteArray(OPC_dload_0);
719 final public void dload_1() {
722 if (stackDepth > stackMax)
723 stackMax = stackDepth;
729 bCodeStream[classFileOffset++] = OPC_dload_1;
730 } catch (IndexOutOfBoundsException e) {
731 resizeByteArray(OPC_dload_1);
734 final public void dload_2() {
737 if (stackDepth > stackMax)
738 stackMax = stackDepth;
744 bCodeStream[classFileOffset++] = OPC_dload_2;
745 } catch (IndexOutOfBoundsException e) {
746 resizeByteArray(OPC_dload_2);
749 final public void dload_3() {
752 if (stackDepth > stackMax)
753 stackMax = stackDepth;
759 bCodeStream[classFileOffset++] = OPC_dload_3;
760 } catch (IndexOutOfBoundsException e) {
761 resizeByteArray(OPC_dload_3);
764 final public void dmul() {
769 bCodeStream[classFileOffset++] = OPC_dmul;
770 } catch (IndexOutOfBoundsException e) {
771 resizeByteArray(OPC_dmul);
774 final public void dneg() {
778 bCodeStream[classFileOffset++] = OPC_dneg;
779 } catch (IndexOutOfBoundsException e) {
780 resizeByteArray(OPC_dneg);
783 final public void drem() {
788 bCodeStream[classFileOffset++] = OPC_drem;
789 } catch (IndexOutOfBoundsException e) {
790 resizeByteArray(OPC_drem);
793 final public void dreturn() {
796 // the stackDepth should be equal to 0
799 bCodeStream[classFileOffset++] = OPC_dreturn;
800 } catch (IndexOutOfBoundsException e) {
801 resizeByteArray(OPC_dreturn);
804 final public void dstore(int iArg) {
807 if (maxLocals <= iArg + 1) {
808 maxLocals = iArg + 2;
810 if (iArg > 255) { // Widen
813 bCodeStream[classFileOffset++] = OPC_wide;
814 } catch (IndexOutOfBoundsException e) {
815 resizeByteArray(OPC_wide);
819 bCodeStream[classFileOffset++] = OPC_dstore;
820 } catch (IndexOutOfBoundsException e) {
821 resizeByteArray(OPC_dstore);
823 writeUnsignedShort(iArg);
827 bCodeStream[classFileOffset++] = OPC_dstore;
828 } catch (IndexOutOfBoundsException e) {
829 resizeByteArray(OPC_dstore);
833 bCodeStream[classFileOffset++] = (byte) iArg;
834 } catch (IndexOutOfBoundsException e) {
835 resizeByteArray((byte) iArg);
839 final public void dstore_0() {
847 bCodeStream[classFileOffset++] = OPC_dstore_0;
848 } catch (IndexOutOfBoundsException e) {
849 resizeByteArray(OPC_dstore_0);
852 final public void dstore_1() {
860 bCodeStream[classFileOffset++] = OPC_dstore_1;
861 } catch (IndexOutOfBoundsException e) {
862 resizeByteArray(OPC_dstore_1);
865 final public void dstore_2() {
873 bCodeStream[classFileOffset++] = OPC_dstore_2;
874 } catch (IndexOutOfBoundsException e) {
875 resizeByteArray(OPC_dstore_2);
878 final public void dstore_3() {
886 bCodeStream[classFileOffset++] = OPC_dstore_3;
887 } catch (IndexOutOfBoundsException e) {
888 resizeByteArray(OPC_dstore_3);
891 final public void dsub() {
896 bCodeStream[classFileOffset++] = OPC_dsub;
897 } catch (IndexOutOfBoundsException e) {
898 resizeByteArray(OPC_dsub);
901 final public void dup() {
904 if (stackDepth > stackMax)
905 stackMax = stackDepth;
908 bCodeStream[classFileOffset++] = OPC_dup;
909 } catch (IndexOutOfBoundsException e) {
910 resizeByteArray(OPC_dup);
913 final public void dup_x1() {
916 if (stackDepth > stackMax)
917 stackMax = stackDepth;
920 bCodeStream[classFileOffset++] = OPC_dup_x1;
921 } catch (IndexOutOfBoundsException e) {
922 resizeByteArray(OPC_dup_x1);
925 final public void dup_x2() {
928 if (stackDepth > stackMax)
929 stackMax = stackDepth;
932 bCodeStream[classFileOffset++] = OPC_dup_x2;
933 } catch (IndexOutOfBoundsException e) {
934 resizeByteArray(OPC_dup_x2);
937 final public void dup2() {
940 if (stackDepth > stackMax)
941 stackMax = stackDepth;
944 bCodeStream[classFileOffset++] = OPC_dup2;
945 } catch (IndexOutOfBoundsException e) {
946 resizeByteArray(OPC_dup2);
949 final public void dup2_x1() {
952 if (stackDepth > stackMax)
953 stackMax = stackDepth;
956 bCodeStream[classFileOffset++] = OPC_dup2_x1;
957 } catch (IndexOutOfBoundsException e) {
958 resizeByteArray(OPC_dup2_x1);
961 final public void dup2_x2() {
964 if (stackDepth > stackMax)
965 stackMax = stackDepth;
968 bCodeStream[classFileOffset++] = OPC_dup2_x2;
969 } catch (IndexOutOfBoundsException e) {
970 resizeByteArray(OPC_dup2_x2);
973 public void exitUserScope(BlockScope blockScope) {
974 // mark all the scope's locals as loosing their definite assignment
976 if (!generateLocalVariableTableAttributes)
978 for (int i = 0; i < visibleLocalsCount; i++) {
979 LocalVariableBinding visibleLocal = visibleLocals[i];
980 if ((visibleLocal != null) && (visibleLocal.declaringScope == blockScope)) {
981 // there maybe some some preserved locals never initialized
982 if (visibleLocal.initializationCount > 0) {
983 visibleLocals[i].recordInitializationEndPC(position);
985 visibleLocals[i] = null; // this variable is no longer visible afterwards
989 final public void f2d() {
992 if (stackDepth > stackMax)
993 stackMax = stackDepth;
996 bCodeStream[classFileOffset++] = OPC_f2d;
997 } catch (IndexOutOfBoundsException e) {
998 resizeByteArray(OPC_f2d);
1001 final public void f2i() {
1005 bCodeStream[classFileOffset++] = OPC_f2i;
1006 } catch (IndexOutOfBoundsException e) {
1007 resizeByteArray(OPC_f2i);
1010 final public void f2l() {
1013 if (stackDepth > stackMax)
1014 stackMax = stackDepth;
1017 bCodeStream[classFileOffset++] = OPC_f2l;
1018 } catch (IndexOutOfBoundsException e) {
1019 resizeByteArray(OPC_f2l);
1022 final public void fadd() {
1027 bCodeStream[classFileOffset++] = OPC_fadd;
1028 } catch (IndexOutOfBoundsException e) {
1029 resizeByteArray(OPC_fadd);
1032 final public void faload() {
1037 bCodeStream[classFileOffset++] = OPC_faload;
1038 } catch (IndexOutOfBoundsException e) {
1039 resizeByteArray(OPC_faload);
1042 final public void fastore() {
1047 bCodeStream[classFileOffset++] = OPC_fastore;
1048 } catch (IndexOutOfBoundsException e) {
1049 resizeByteArray(OPC_fastore);
1052 final public void fcmpg() {
1057 bCodeStream[classFileOffset++] = OPC_fcmpg;
1058 } catch (IndexOutOfBoundsException e) {
1059 resizeByteArray(OPC_fcmpg);
1062 final public void fcmpl() {
1067 bCodeStream[classFileOffset++] = OPC_fcmpl;
1068 } catch (IndexOutOfBoundsException e) {
1069 resizeByteArray(OPC_fcmpl);
1072 final public void fconst_0() {
1075 if (stackDepth > stackMax)
1076 stackMax = stackDepth;
1079 bCodeStream[classFileOffset++] = OPC_fconst_0;
1080 } catch (IndexOutOfBoundsException e) {
1081 resizeByteArray(OPC_fconst_0);
1084 final public void fconst_1() {
1087 if (stackDepth > stackMax)
1088 stackMax = stackDepth;
1091 bCodeStream[classFileOffset++] = OPC_fconst_1;
1092 } catch (IndexOutOfBoundsException e) {
1093 resizeByteArray(OPC_fconst_1);
1096 final public void fconst_2() {
1099 if (stackDepth > stackMax)
1100 stackMax = stackDepth;
1103 bCodeStream[classFileOffset++] = OPC_fconst_2;
1104 } catch (IndexOutOfBoundsException e) {
1105 resizeByteArray(OPC_fconst_2);
1108 final public void fdiv() {
1113 bCodeStream[classFileOffset++] = OPC_fdiv;
1114 } catch (IndexOutOfBoundsException e) {
1115 resizeByteArray(OPC_fdiv);
1118 final public void fload(int iArg) {
1121 if (maxLocals <= iArg) {
1122 maxLocals = iArg + 1;
1124 if (stackDepth > stackMax)
1125 stackMax = stackDepth;
1126 if (iArg > 255) { // Widen
1129 bCodeStream[classFileOffset++] = OPC_wide;
1130 } catch (IndexOutOfBoundsException e) {
1131 resizeByteArray(OPC_wide);
1135 bCodeStream[classFileOffset++] = OPC_fload;
1136 } catch (IndexOutOfBoundsException e) {
1137 resizeByteArray(OPC_fload);
1139 writeUnsignedShort(iArg);
1143 bCodeStream[classFileOffset++] = OPC_fload;
1144 } catch (IndexOutOfBoundsException e) {
1145 resizeByteArray(OPC_fload);
1149 bCodeStream[classFileOffset++] = (byte) iArg;
1150 } catch (IndexOutOfBoundsException e) {
1151 resizeByteArray((byte) iArg);
1155 final public void fload_0() {
1158 if (maxLocals == 0) {
1161 if (stackDepth > stackMax)
1162 stackMax = stackDepth;
1165 bCodeStream[classFileOffset++] = OPC_fload_0;
1166 } catch (IndexOutOfBoundsException e) {
1167 resizeByteArray(OPC_fload_0);
1170 final public void fload_1() {
1173 if (maxLocals <= 1) {
1176 if (stackDepth > stackMax)
1177 stackMax = stackDepth;
1180 bCodeStream[classFileOffset++] = OPC_fload_1;
1181 } catch (IndexOutOfBoundsException e) {
1182 resizeByteArray(OPC_fload_1);
1185 final public void fload_2() {
1188 if (maxLocals <= 2) {
1191 if (stackDepth > stackMax)
1192 stackMax = stackDepth;
1195 bCodeStream[classFileOffset++] = OPC_fload_2;
1196 } catch (IndexOutOfBoundsException e) {
1197 resizeByteArray(OPC_fload_2);
1200 final public void fload_3() {
1203 if (maxLocals <= 3) {
1206 if (stackDepth > stackMax)
1207 stackMax = stackDepth;
1210 bCodeStream[classFileOffset++] = OPC_fload_3;
1211 } catch (IndexOutOfBoundsException e) {
1212 resizeByteArray(OPC_fload_3);
1215 final public void fmul() {
1220 bCodeStream[classFileOffset++] = OPC_fmul;
1221 } catch (IndexOutOfBoundsException e) {
1222 resizeByteArray(OPC_fmul);
1225 final public void fneg() {
1229 bCodeStream[classFileOffset++] = OPC_fneg;
1230 } catch (IndexOutOfBoundsException e) {
1231 resizeByteArray(OPC_fneg);
1234 final public void frem() {
1239 bCodeStream[classFileOffset++] = OPC_frem;
1240 } catch (IndexOutOfBoundsException e) {
1241 resizeByteArray(OPC_frem);
1244 final public void freturn() {
1247 // the stackDepth should be equal to 0
1250 bCodeStream[classFileOffset++] = OPC_freturn;
1251 } catch (IndexOutOfBoundsException e) {
1252 resizeByteArray(OPC_freturn);
1255 final public void fstore(int iArg) {
1258 if (maxLocals <= iArg) {
1259 maxLocals = iArg + 1;
1261 if (iArg > 255) { // Widen
1264 bCodeStream[classFileOffset++] = OPC_wide;
1265 } catch (IndexOutOfBoundsException e) {
1266 resizeByteArray(OPC_wide);
1270 bCodeStream[classFileOffset++] = OPC_fstore;
1271 } catch (IndexOutOfBoundsException e) {
1272 resizeByteArray(OPC_fstore);
1274 writeUnsignedShort(iArg);
1278 bCodeStream[classFileOffset++] = OPC_fstore;
1279 } catch (IndexOutOfBoundsException e) {
1280 resizeByteArray(OPC_fstore);
1284 bCodeStream[classFileOffset++] = (byte) iArg;
1285 } catch (IndexOutOfBoundsException e) {
1286 resizeByteArray((byte) iArg);
1290 final public void fstore_0() {
1293 if (maxLocals == 0) {
1298 bCodeStream[classFileOffset++] = OPC_fstore_0;
1299 } catch (IndexOutOfBoundsException e) {
1300 resizeByteArray(OPC_fstore_0);
1303 final public void fstore_1() {
1306 if (maxLocals <= 1) {
1311 bCodeStream[classFileOffset++] = OPC_fstore_1;
1312 } catch (IndexOutOfBoundsException e) {
1313 resizeByteArray(OPC_fstore_1);
1316 final public void fstore_2() {
1319 if (maxLocals <= 2) {
1324 bCodeStream[classFileOffset++] = OPC_fstore_2;
1325 } catch (IndexOutOfBoundsException e) {
1326 resizeByteArray(OPC_fstore_2);
1329 final public void fstore_3() {
1332 if (maxLocals <= 3) {
1337 bCodeStream[classFileOffset++] = OPC_fstore_3;
1338 } catch (IndexOutOfBoundsException e) {
1339 resizeByteArray(OPC_fstore_3);
1342 final public void fsub() {
1347 bCodeStream[classFileOffset++] = OPC_fsub;
1348 } catch (IndexOutOfBoundsException e) {
1349 resizeByteArray(OPC_fsub);
1353 * Macro for building a class descriptor object
1355 public void generateClassLiteralAccessForType(TypeBinding accessedType, FieldBinding syntheticFieldBinding) {
1357 ExceptionLabel anyExceptionHandler;
1359 if (accessedType.isBaseType() && accessedType != NullBinding) {
1360 this.getTYPE(accessedType.id);
1363 endLabel = new Label(this);
1365 if (syntheticFieldBinding != null) { // non interface case
1366 this.getstatic(syntheticFieldBinding);
1368 this.ifnonnull(endLabel);
1372 /* Macro for building a class descriptor object... using or not a field cache to store it into...
1373 this sequence is responsible for building the actual class descriptor.
1375 If the fieldCache is set, then it is supposed to be the body of a synthetic access method
1376 factoring the actual descriptor creation out of the invocation site (saving space).
1377 If the fieldCache is nil, then we are dumping the bytecode on the invocation site, since
1378 we have no way to get a hand on the field cache to do better. */
1380 // Wrap the code in an exception handler to convert a ClassNotFoundException into a NoClassDefError
1382 anyExceptionHandler = new ExceptionLabel(this, TypeBinding.NullBinding /* represents ClassNotFoundException*/
1384 this.ldc(accessedType == TypeBinding.NullBinding ? "java.lang.Object" : String.valueOf(accessedType.constantPoolName()).replace('/', '.')); //$NON-NLS-1$
1385 this.invokeClassForName();
1387 /* We need to protect the runtime code from binary inconsistencies
1388 in case the accessedType is missing, the ClassNotFoundException has to be converted
1389 into a NoClassDefError(old ex message), we thus need to build an exception handler for this one. */
1390 anyExceptionHandler.placeEnd();
1392 if (syntheticFieldBinding != null) { // non interface case
1394 this.putstatic(syntheticFieldBinding);
1396 this.goto_(endLabel);
1398 // Generate the body of the exception handler
1399 saveStackSize = stackDepth;
1401 /* ClassNotFoundException on stack -- the class literal could be doing more things
1402 on the stack, which means that the stack may not be empty at this point in the
1403 above code gen. So we save its state and restart it from 1. */
1405 anyExceptionHandler.place();
1407 // Transform the current exception, and repush and throw a
1408 // NoClassDefFoundError(ClassNotFound.getMessage())
1410 this.newNoClassDefFoundError();
1414 // Retrieve the message from the old exception
1415 this.invokeThrowableGetMessage();
1417 // Send the constructor taking a message string as an argument
1418 this.invokeNoClassDefFoundErrorStringConstructor();
1421 stackDepth = saveStackSize;
1424 * This method returns the exception handler to be able to generate the exception handler
1427 final public int[] generateCodeAttributeForProblemMethod(String errorName, String problemMessage) {
1431 * throw ((Error) (Class.forName(errorName).getConstructor(new Class[] {Class.forName("java.lang.String")})).newInstance(new Object[] {problemMessage}));
1432 * } catch (Exception e) {
1433 * throw (NullPointerException) null;
1436 int endPC, handlerPC;
1438 invokeClassForName();
1440 anewarrayJavaLangClass();
1443 ldc("java.lang.String"); //$NON-NLS-1$
1444 invokeClassForName();
1446 invokeConstructorGetConstructor();
1448 anewarrayJavaLangObject();
1451 ldc(problemMessage);
1453 invokeObjectNewInstance();
1454 checkcastJavaLangError();
1456 endPC = handlerPC = position;
1461 return new int[] { 0, endPC, handlerPC };
1463 public void generateConstant(Constant constant, int implicitConversionCode) {
1464 int targetTypeID = implicitConversionCode >> 4;
1465 switch (targetTypeID) {
1467 generateInlinedValue(constant.booleanValue());
1470 generateInlinedValue(constant.charValue());
1473 generateInlinedValue(constant.byteValue());
1476 generateInlinedValue(constant.shortValue());
1479 generateInlinedValue(constant.intValue());
1482 generateInlinedValue(constant.longValue());
1485 generateInlinedValue(constant.floatValue());
1488 generateInlinedValue(constant.doubleValue());
1491 this.ldc(constant.stringValue());
1493 default : //reference object (constant can be from T_null or T_String)
1494 if (constant.typeID() == T_String)
1495 ldc(constant.stringValue());
1501 * @param implicitConversionCode int
1503 public void generateImplicitConversion(int implicitConversionCode) {
1504 switch (implicitConversionCode) {
1602 public void generateInlinedValue(byte inlinedValue) {
1603 switch (inlinedValue) {
1626 if ((-128 <= inlinedValue) && (inlinedValue <= 127)) {
1627 this.bipush((byte) inlinedValue);
1632 public void generateInlinedValue(char inlinedValue) {
1633 switch (inlinedValue) {
1653 if ((6 <= inlinedValue) && (inlinedValue <= 127)) {
1654 this.bipush((byte) inlinedValue);
1657 if ((128 <= inlinedValue) && (inlinedValue <= 32767)) {
1658 this.sipush(inlinedValue);
1661 this.ldc(inlinedValue);
1664 public void generateInlinedValue(double inlinedValue) {
1665 if (inlinedValue == 0.0) {
1666 if (Double.doubleToLongBits(inlinedValue) != 0L)
1667 this.ldc2_w(inlinedValue);
1672 if (inlinedValue == 1.0) {
1676 this.ldc2_w(inlinedValue);
1678 public void generateInlinedValue(float inlinedValue) {
1679 if (inlinedValue == 0.0f) {
1680 if (Float.floatToIntBits(inlinedValue) != 0)
1681 this.ldc(inlinedValue);
1686 if (inlinedValue == 1.0f) {
1690 if (inlinedValue == 2.0f) {
1694 this.ldc(inlinedValue);
1696 public void generateInlinedValue(int inlinedValue) {
1697 switch (inlinedValue) {
1720 if ((-128 <= inlinedValue) && (inlinedValue <= 127)) {
1721 this.bipush((byte) inlinedValue);
1724 if ((-32768 <= inlinedValue) && (inlinedValue <= 32767)) {
1725 this.sipush(inlinedValue);
1728 this.ldc(inlinedValue);
1731 public void generateInlinedValue(long inlinedValue) {
1732 if (inlinedValue == 0) {
1736 if (inlinedValue == 1) {
1740 this.ldc2_w(inlinedValue);
1742 public void generateInlinedValue(short inlinedValue) {
1743 switch (inlinedValue) {
1766 if ((-128 <= inlinedValue) && (inlinedValue <= 127)) {
1767 this.bipush((byte) inlinedValue);
1770 this.sipush(inlinedValue);
1773 public void generateInlinedValue(boolean inlinedValue) {
1779 public void generateOuterAccess(Object[] mappingSequence, AstNode invocationSite, Scope scope) {
1780 if (mappingSequence == null)
1782 if (mappingSequence == BlockScope.EmulationPathToImplicitThis) {
1783 if (scope.methodScope().isConstructorCall) {
1784 scope.problemReporter().errorThisSuperInStatic(invocationSite);
1789 if (mappingSequence[0] instanceof FieldBinding) {
1790 FieldBinding fieldBinding = (FieldBinding) mappingSequence[0];
1791 if (scope.methodScope().isConstructorCall) {
1792 scope.problemReporter().errorThisSuperInStatic(invocationSite);
1795 this.getfield(fieldBinding);
1797 load((LocalVariableBinding) mappingSequence[0]);
1799 for (int i = 1, length = mappingSequence.length; i < length; i++) {
1800 if (mappingSequence[i] instanceof FieldBinding) {
1801 FieldBinding fieldBinding = (FieldBinding) mappingSequence[i];
1802 this.getfield(fieldBinding);
1804 this.invokestatic((MethodBinding) mappingSequence[i]);
1809 * The equivalent code performs a string conversion:
1811 * @param oper1 org.eclipse.jdt.internal.compiler.lookup.BlockScope
1812 * @param oper1 org.eclipse.jdt.internal.compiler.ast.Expression
1813 * @param oper2 org.eclipse.jdt.internal.compiler.ast.Expression
1815 public void generateStringAppend(BlockScope blockScope, Expression oper1, Expression oper2) {
1817 if (oper1 == null) {
1818 /* Operand is already on the stack, and maybe nil:
1819 note type1 is always to java.lang.String here.*/
1820 this.newStringBuffer();
1823 // If argument is reference type, need to transform it
1824 // into a string (handles null case)
1825 this.invokeStringValueOf(T_Object);
1826 this.invokeStringBufferStringConstructor();
1829 oper1.generateOptimizedStringBufferCreation(blockScope, this, oper1.implicitConversion & 0xF);
1830 this.recordPositionsFrom(pc, oper1.sourceStart);
1833 oper2.generateOptimizedStringBuffer(blockScope, this, oper2.implicitConversion & 0xF);
1834 this.recordPositionsFrom(pc, oper2.sourceStart);
1835 this.invokeStringBufferToString();
1838 * Code responsible to generate the suitable code to supply values for the synthetic arguments of
1839 * a constructor invocation of a nested type.
1841 public void generateSyntheticArgumentValues(
1842 BlockScope currentScope,
1843 ReferenceBinding targetType,
1844 Expression enclosingInstance,
1845 AstNode invocationSite) {
1847 // perform some emulation work in case there is some and we are inside a local type only
1848 ReferenceBinding[] syntheticArgumentTypes;
1850 // generate the enclosing instance first
1851 if ((syntheticArgumentTypes = targetType.syntheticEnclosingInstanceTypes()) != null) {
1853 ReferenceBinding targetEnclosingType =
1854 targetType.isAnonymousType()
1855 ? targetType.superclass().enclosingType() // supplying enclosing instance for the anonymous type's superclass
1856 : targetType.enclosingType();
1858 for (int i = 0, max = syntheticArgumentTypes.length; i < max; i++) {
1859 ReferenceBinding syntheticArgType = syntheticArgumentTypes[i];
1860 if (enclosingInstance != null && i == 0) {
1861 if (syntheticArgType != targetEnclosingType) {
1862 currentScope.problemReporter().unnecessaryEnclosingInstanceSpecification(enclosingInstance, targetType);
1864 //if (currentScope.environment().options.complianceLevel >= CompilerOptions.JDK1_4){
1865 enclosingInstance.generateCode(currentScope, this, true);
1866 if (syntheticArgType == targetEnclosingType) {
1869 this.invokeObjectGetClass(); // causes null check for all explicit enclosing instances
1872 // enclosingInstance.generateCode(currentScope, this, syntheticArgType == targetEnclosingType);
1875 Object[] emulationPath = currentScope.getCompatibleEmulationPath(syntheticArgType);
1876 if (emulationPath == null) {
1877 currentScope.problemReporter().missingEnclosingInstanceSpecification(syntheticArgType, invocationSite);
1879 this.generateOuterAccess(emulationPath, invocationSite, currentScope);
1883 } else { // we may still have an enclosing instance to consider
1884 if (enclosingInstance != null) {
1885 currentScope.problemReporter().unnecessaryEnclosingInstanceSpecification(enclosingInstance, targetType);
1886 //if (currentScope.environment().options.complianceLevel >= CompilerOptions.JDK1_4){
1887 enclosingInstance.generateCode(currentScope, this, true);
1888 this.invokeObjectGetClass(); // causes null check for all explicit enclosing instances
1891 // enclosingInstance.generateCode(currentScope, this, false); // do not want the value
1895 // generate the synthetic outer arguments then
1896 SyntheticArgumentBinding syntheticArguments[];
1897 if ((syntheticArguments = targetType.syntheticOuterLocalVariables()) != null) {
1898 for (int i = 0, max = syntheticArguments.length; i < max; i++) {
1899 VariableBinding[] emulationPath = currentScope.getEmulationPath(syntheticArguments[i].actualOuterLocalVariable);
1900 if (emulationPath == null) {
1901 // could not emulate a path to a given outer local variable (internal error)
1902 currentScope.problemReporter().needImplementation();
1904 this.generateOuterAccess(emulationPath, invocationSite, currentScope);
1910 * @param parameters org.eclipse.jdt.internal.compiler.lookup.TypeBinding[]
1911 * @param constructorBinding org.eclipse.jdt.internal.compiler.lookup.MethodBinding
1913 public void generateSyntheticBodyForConstructorAccess(SyntheticAccessMethodBinding accessBinding) {
1915 initializeMaxLocals(accessBinding);
1917 MethodBinding constructorBinding = accessBinding.targetMethod;
1918 TypeBinding[] parameters = constructorBinding.parameters;
1919 int length = parameters.length;
1920 int resolvedPosition = 1;
1922 if (constructorBinding.declaringClass.isNestedType()) {
1923 NestedTypeBinding nestedType = (NestedTypeBinding) constructorBinding.declaringClass;
1924 SyntheticArgumentBinding[] syntheticArguments = nestedType.syntheticEnclosingInstances();
1925 for (int i = 0; i < (syntheticArguments == null ? 0 : syntheticArguments.length); i++) {
1927 load((type = syntheticArguments[i].type), resolvedPosition);
1928 if ((type == DoubleBinding) || (type == LongBinding))
1929 resolvedPosition += 2;
1933 syntheticArguments = nestedType.syntheticOuterLocalVariables();
1934 for (int i = 0; i < (syntheticArguments == null ? 0 : syntheticArguments.length); i++) {
1936 load((type = syntheticArguments[i].type), resolvedPosition);
1937 if ((type == DoubleBinding) || (type == LongBinding))
1938 resolvedPosition += 2;
1943 for (int i = 0; i < length; i++) {
1944 load(parameters[i], resolvedPosition);
1945 if ((parameters[i] == DoubleBinding) || (parameters[i] == LongBinding))
1946 resolvedPosition += 2;
1950 this.invokespecial(constructorBinding);
1953 public void generateSyntheticBodyForFieldReadAccess(SyntheticAccessMethodBinding accessBinding) {
1954 initializeMaxLocals(accessBinding);
1955 FieldBinding fieldBinding = accessBinding.targetReadField;
1957 if (fieldBinding.isStatic())
1958 this.getstatic(fieldBinding);
1961 this.getfield(fieldBinding);
1963 if ((type = fieldBinding.type).isBaseType()) {
1964 if (type == IntBinding)
1966 else if (type == FloatBinding)
1968 else if (type == LongBinding)
1970 else if (type == DoubleBinding)
1977 public void generateSyntheticBodyForFieldWriteAccess(SyntheticAccessMethodBinding accessBinding) {
1978 initializeMaxLocals(accessBinding);
1979 FieldBinding fieldBinding = accessBinding.targetWriteField;
1980 if (fieldBinding.isStatic()) {
1981 load(fieldBinding.type, 0);
1982 this.putstatic(fieldBinding);
1985 load(fieldBinding.type, 1);
1986 this.putfield(fieldBinding);
1990 public void generateSyntheticBodyForMethodAccess(SyntheticAccessMethodBinding accessBinding) {
1992 initializeMaxLocals(accessBinding);
1993 MethodBinding methodBinding = accessBinding.targetMethod;
1994 TypeBinding[] parameters = methodBinding.parameters;
1995 int length = parameters.length;
1996 int resolvedPosition;
1997 if (methodBinding.isStatic())
1998 resolvedPosition = 0;
2001 resolvedPosition = 1;
2003 for (int i = 0; i < length; i++) {
2004 load(parameters[i], resolvedPosition);
2005 if ((parameters[i] == DoubleBinding) || (parameters[i] == LongBinding))
2006 resolvedPosition += 2;
2011 if (methodBinding.isStatic())
2012 this.invokestatic(methodBinding);
2014 if (methodBinding.isConstructor()
2015 || methodBinding.isPrivate() // qualified super "X.super.foo()" targets methods from superclass
2016 || (methodBinding.declaringClass != methodDeclaration.binding.declaringClass)) {
2017 this.invokespecial(methodBinding);
2019 if (methodBinding.declaringClass.isInterface()) {
2020 this.invokeinterface(methodBinding);
2022 this.invokevirtual(methodBinding);
2026 if ((type = methodBinding.returnType).isBaseType())
2027 if (type == VoidBinding)
2029 else if (type == IntBinding)
2031 else if (type == FloatBinding)
2033 else if (type == LongBinding)
2035 else if (type == DoubleBinding)
2042 final public byte[] getContents() {
2044 System.arraycopy(bCodeStream, 0, contents = new byte[position], 0, position);
2047 final public void getfield(FieldBinding fieldBinding) {
2049 if ((fieldBinding.type.id == T_double) || (fieldBinding.type.id == T_long)) {
2050 if (++stackDepth > stackMax)
2051 stackMax = stackDepth;
2055 bCodeStream[classFileOffset++] = OPC_getfield;
2056 } catch (IndexOutOfBoundsException e) {
2057 resizeByteArray(OPC_getfield);
2059 writeUnsignedShort(constantPool.literalIndex(fieldBinding));
2061 final public void getstatic(FieldBinding fieldBinding) {
2063 if ((fieldBinding.type.id == T_double) || (fieldBinding.type.id == T_long))
2067 if (stackDepth > stackMax)
2068 stackMax = stackDepth;
2071 bCodeStream[classFileOffset++] = OPC_getstatic;
2072 } catch (IndexOutOfBoundsException e) {
2073 resizeByteArray(OPC_getstatic);
2075 writeUnsignedShort(constantPool.literalIndex(fieldBinding));
2077 public void getSystemOut() {
2079 if (++stackDepth > stackMax)
2080 stackMax = stackDepth;
2083 bCodeStream[classFileOffset++] = OPC_getstatic;
2084 } catch (IndexOutOfBoundsException e) {
2085 resizeByteArray(OPC_getstatic);
2087 writeUnsignedShort(constantPool.literalIndexForJavaLangSystemOut());
2089 public void getTYPE(int baseTypeID) {
2091 if (++stackDepth > stackMax)
2092 stackMax = stackDepth;
2095 bCodeStream[classFileOffset++] = OPC_getstatic;
2096 } catch (IndexOutOfBoundsException e) {
2097 resizeByteArray(OPC_getstatic);
2099 switch (baseTypeID) {
2100 // getstatic: java.lang.Byte.TYPE
2102 writeUnsignedShort(constantPool.literalIndexForJavaLangByteTYPE());
2104 // getstatic: java.lang.Short.TYPE
2106 writeUnsignedShort(constantPool.literalIndexForJavaLangShortTYPE());
2108 // getstatic: java.lang.Character.TYPE
2110 writeUnsignedShort(constantPool.literalIndexForJavaLangCharacterTYPE());
2112 // getstatic: java.lang.Integer.TYPE
2114 writeUnsignedShort(constantPool.literalIndexForJavaLangIntegerTYPE());
2116 // getstatic: java.lang.Long.TYPE
2118 writeUnsignedShort(constantPool.literalIndexForJavaLangLongTYPE());
2120 // getstatic: java.lang.Float.TYPE
2122 writeUnsignedShort(constantPool.literalIndexForJavaLangFloatTYPE());
2124 // getstatic: java.lang.Double.TYPE
2126 writeUnsignedShort(constantPool.literalIndexForJavaLangDoubleTYPE());
2128 // getstatic: java.lang.Boolean.TYPE
2130 writeUnsignedShort(constantPool.literalIndexForJavaLangBooleanTYPE());
2132 // getstatic: java.lang.Void.TYPE
2134 writeUnsignedShort(constantPool.literalIndexForJavaLangVoidTYPE());
2139 * We didn't call it goto, because there is a conflit with the goto keyword
2141 final public void goto_(Label lbl) {
2142 if (this.wideMode) {
2147 lbl.inlineForwardReferencesFromLabelsTargeting(position);
2149 Possible optimization for code such as:
2150 public Object foo() {
2162 The goto around the else block for the first if will
2163 be unreachable, because the thenClause of the second if
2165 See inlineForwardReferencesFromLabelsTargeting defined
2166 on the Label class for the remaining part of this
2168 if (!lbl.isBranchTarget(position)) {
2169 switch(bCodeStream[classFileOffset-1]) {
2176 bCodeStream[classFileOffset++] = OPC_goto;
2177 } catch (IndexOutOfBoundsException e) {
2178 resizeByteArray(OPC_goto);
2184 * We didn't call it goto, because there is a conflit with the goto keyword
2186 final public void internal_goto_(Label lbl) {
2188 lbl.inlineForwardReferencesFromLabelsTargeting(position);
2190 Possible optimization for code such as:
2191 public Object foo() {
2203 The goto around the else block for the first if will
2204 be unreachable, because the thenClause of the second if
2206 See inlineForwardReferencesFromLabelsTargeting defined
2207 on the Label class for the remaining part of this
2209 if (!lbl.isBranchTarget(position)) {
2210 switch(bCodeStream[classFileOffset-1]) {
2217 bCodeStream[classFileOffset++] = OPC_goto;
2218 } catch (IndexOutOfBoundsException e) {
2219 resizeByteArray(OPC_goto);
2223 final public void goto_w(Label lbl) {
2226 bCodeStream[classFileOffset++] = OPC_goto_w;
2227 } catch (IndexOutOfBoundsException e) {
2228 resizeByteArray(OPC_goto_w);
2232 final public void i2b() {
2236 bCodeStream[classFileOffset++] = OPC_i2b;
2237 } catch (IndexOutOfBoundsException e) {
2238 resizeByteArray(OPC_i2b);
2241 final public void i2c() {
2245 bCodeStream[classFileOffset++] = OPC_i2c;
2246 } catch (IndexOutOfBoundsException e) {
2247 resizeByteArray(OPC_i2c);
2250 final public void i2d() {
2253 if (stackDepth > stackMax)
2254 stackMax = stackDepth;
2257 bCodeStream[classFileOffset++] = OPC_i2d;
2258 } catch (IndexOutOfBoundsException e) {
2259 resizeByteArray(OPC_i2d);
2262 final public void i2f() {
2266 bCodeStream[classFileOffset++] = OPC_i2f;
2267 } catch (IndexOutOfBoundsException e) {
2268 resizeByteArray(OPC_i2f);
2271 final public void i2l() {
2274 if (stackDepth > stackMax)
2275 stackMax = stackDepth;
2278 bCodeStream[classFileOffset++] = OPC_i2l;
2279 } catch (IndexOutOfBoundsException e) {
2280 resizeByteArray(OPC_i2l);
2283 final public void i2s() {
2287 bCodeStream[classFileOffset++] = OPC_i2s;
2288 } catch (IndexOutOfBoundsException e) {
2289 resizeByteArray(OPC_i2s);
2292 final public void iadd() {
2297 bCodeStream[classFileOffset++] = OPC_iadd;
2298 } catch (IndexOutOfBoundsException e) {
2299 resizeByteArray(OPC_iadd);
2302 final public void iaload() {
2307 bCodeStream[classFileOffset++] = OPC_iaload;
2308 } catch (IndexOutOfBoundsException e) {
2309 resizeByteArray(OPC_iaload);
2312 final public void iand() {
2317 bCodeStream[classFileOffset++] = OPC_iand;
2318 } catch (IndexOutOfBoundsException e) {
2319 resizeByteArray(OPC_iand);
2322 final public void iastore() {
2327 bCodeStream[classFileOffset++] = OPC_iastore;
2328 } catch (IndexOutOfBoundsException e) {
2329 resizeByteArray(OPC_iastore);
2332 final public void iconst_0() {
2335 if (stackDepth > stackMax)
2336 stackMax = stackDepth;
2339 bCodeStream[classFileOffset++] = OPC_iconst_0;
2340 } catch (IndexOutOfBoundsException e) {
2341 resizeByteArray(OPC_iconst_0);
2344 final public void iconst_1() {
2347 if (stackDepth > stackMax)
2348 stackMax = stackDepth;
2351 bCodeStream[classFileOffset++] = OPC_iconst_1;
2352 } catch (IndexOutOfBoundsException e) {
2353 resizeByteArray(OPC_iconst_1);
2356 final public void iconst_2() {
2359 if (stackDepth > stackMax)
2360 stackMax = stackDepth;
2363 bCodeStream[classFileOffset++] = OPC_iconst_2;
2364 } catch (IndexOutOfBoundsException e) {
2365 resizeByteArray(OPC_iconst_2);
2368 final public void iconst_3() {
2371 if (stackDepth > stackMax)
2372 stackMax = stackDepth;
2375 bCodeStream[classFileOffset++] = OPC_iconst_3;
2376 } catch (IndexOutOfBoundsException e) {
2377 resizeByteArray(OPC_iconst_3);
2380 final public void iconst_4() {
2383 if (stackDepth > stackMax)
2384 stackMax = stackDepth;
2387 bCodeStream[classFileOffset++] = OPC_iconst_4;
2388 } catch (IndexOutOfBoundsException e) {
2389 resizeByteArray(OPC_iconst_4);
2392 final public void iconst_5() {
2395 if (stackDepth > stackMax)
2396 stackMax = stackDepth;
2399 bCodeStream[classFileOffset++] = OPC_iconst_5;
2400 } catch (IndexOutOfBoundsException e) {
2401 resizeByteArray(OPC_iconst_5);
2404 final public void iconst_m1() {
2407 if (stackDepth > stackMax)
2408 stackMax = stackDepth;
2411 bCodeStream[classFileOffset++] = OPC_iconst_m1;
2412 } catch (IndexOutOfBoundsException e) {
2413 resizeByteArray(OPC_iconst_m1);
2416 final public void idiv() {
2421 bCodeStream[classFileOffset++] = OPC_idiv;
2422 } catch (IndexOutOfBoundsException e) {
2423 resizeByteArray(OPC_idiv);
2426 final public void if_acmpeq(Label lbl) {
2429 if (this.wideMode) {
2430 generateWideConditionalBranch(OPC_if_acmpeq, lbl);
2434 bCodeStream[classFileOffset++] = OPC_if_acmpeq;
2435 } catch (IndexOutOfBoundsException e) {
2436 resizeByteArray(OPC_if_acmpeq);
2441 final public void if_acmpne(Label lbl) {
2444 if (this.wideMode) {
2445 generateWideConditionalBranch(OPC_if_acmpne, lbl);
2449 bCodeStream[classFileOffset++] = OPC_if_acmpne;
2450 } catch (IndexOutOfBoundsException e) {
2451 resizeByteArray(OPC_if_acmpne);
2456 final public void if_icmpeq(Label lbl) {
2459 if (this.wideMode) {
2460 generateWideConditionalBranch(OPC_if_icmpeq, lbl);
2464 bCodeStream[classFileOffset++] = OPC_if_icmpeq;
2465 } catch (IndexOutOfBoundsException e) {
2466 resizeByteArray(OPC_if_icmpeq);
2471 final public void if_icmpge(Label lbl) {
2474 if (this.wideMode) {
2475 generateWideConditionalBranch(OPC_if_icmpge, lbl);
2479 bCodeStream[classFileOffset++] = OPC_if_icmpge;
2480 } catch (IndexOutOfBoundsException e) {
2481 resizeByteArray(OPC_if_icmpge);
2486 final public void if_icmpgt(Label lbl) {
2489 if (this.wideMode) {
2490 generateWideConditionalBranch(OPC_if_icmpgt, lbl);
2494 bCodeStream[classFileOffset++] = OPC_if_icmpgt;
2495 } catch (IndexOutOfBoundsException e) {
2496 resizeByteArray(OPC_if_icmpgt);
2501 final public void if_icmple(Label lbl) {
2504 if (this.wideMode) {
2505 generateWideConditionalBranch(OPC_if_icmple, lbl);
2509 bCodeStream[classFileOffset++] = OPC_if_icmple;
2510 } catch (IndexOutOfBoundsException e) {
2511 resizeByteArray(OPC_if_icmple);
2516 final public void if_icmplt(Label lbl) {
2519 if (this.wideMode) {
2520 generateWideConditionalBranch(OPC_if_icmplt, lbl);
2524 bCodeStream[classFileOffset++] = OPC_if_icmplt;
2525 } catch (IndexOutOfBoundsException e) {
2526 resizeByteArray(OPC_if_icmplt);
2531 final public void if_icmpne(Label lbl) {
2534 if (this.wideMode) {
2535 generateWideConditionalBranch(OPC_if_icmpne, lbl);
2539 bCodeStream[classFileOffset++] = OPC_if_icmpne;
2540 } catch (IndexOutOfBoundsException e) {
2541 resizeByteArray(OPC_if_icmpne);
2546 final public void ifeq(Label lbl) {
2549 if (this.wideMode) {
2550 generateWideConditionalBranch(OPC_ifeq, lbl);
2554 bCodeStream[classFileOffset++] = OPC_ifeq;
2555 } catch (IndexOutOfBoundsException e) {
2556 resizeByteArray(OPC_ifeq);
2561 final public void ifge(Label lbl) {
2564 if (this.wideMode) {
2565 generateWideConditionalBranch(OPC_ifge, lbl);
2569 bCodeStream[classFileOffset++] = OPC_ifge;
2570 } catch (IndexOutOfBoundsException e) {
2571 resizeByteArray(OPC_ifge);
2576 final public void ifgt(Label lbl) {
2579 if (this.wideMode) {
2580 generateWideConditionalBranch(OPC_ifgt, lbl);
2584 bCodeStream[classFileOffset++] = OPC_ifgt;
2585 } catch (IndexOutOfBoundsException e) {
2586 resizeByteArray(OPC_ifgt);
2591 final public void ifle(Label lbl) {
2594 if (this.wideMode) {
2595 generateWideConditionalBranch(OPC_ifle, lbl);
2599 bCodeStream[classFileOffset++] = OPC_ifle;
2600 } catch (IndexOutOfBoundsException e) {
2601 resizeByteArray(OPC_ifle);
2606 final public void iflt(Label lbl) {
2609 if (this.wideMode) {
2610 generateWideConditionalBranch(OPC_iflt, lbl);
2614 bCodeStream[classFileOffset++] = OPC_iflt;
2615 } catch (IndexOutOfBoundsException e) {
2616 resizeByteArray(OPC_iflt);
2621 final public void ifne(Label lbl) {
2624 if (this.wideMode) {
2625 generateWideConditionalBranch(OPC_ifne, lbl);
2629 bCodeStream[classFileOffset++] = OPC_ifne;
2630 } catch (IndexOutOfBoundsException e) {
2631 resizeByteArray(OPC_ifne);
2636 final public void ifnonnull(Label lbl) {
2639 if (this.wideMode) {
2640 generateWideConditionalBranch(OPC_ifnonnull, lbl);
2644 bCodeStream[classFileOffset++] = OPC_ifnonnull;
2645 } catch (IndexOutOfBoundsException e) {
2646 resizeByteArray(OPC_ifnonnull);
2651 final public void ifnull(Label lbl) {
2654 if (this.wideMode) {
2655 generateWideConditionalBranch(OPC_ifnull, lbl);
2659 bCodeStream[classFileOffset++] = OPC_ifnull;
2660 } catch (IndexOutOfBoundsException e) {
2661 resizeByteArray(OPC_ifnull);
2666 final public void iinc(int index, int value) {
2668 if ((index > 255) || (value < -128 || value > 127)) { // have to widen
2671 bCodeStream[classFileOffset++] = OPC_wide;
2672 } catch (IndexOutOfBoundsException e) {
2673 resizeByteArray(OPC_wide);
2677 bCodeStream[classFileOffset++] = OPC_iinc;
2678 } catch (IndexOutOfBoundsException e) {
2679 resizeByteArray(OPC_iinc);
2681 writeUnsignedShort(index);
2682 writeSignedShort(value);
2686 bCodeStream[classFileOffset++] = OPC_iinc;
2687 } catch (IndexOutOfBoundsException e) {
2688 resizeByteArray(OPC_iinc);
2690 writeUnsignedByte(index);
2691 writeSignedByte(value);
2694 final public void iload(int iArg) {
2697 if (maxLocals <= iArg) {
2698 maxLocals = iArg + 1;
2700 if (stackDepth > stackMax)
2701 stackMax = stackDepth;
2702 if (iArg > 255) { // Widen
2705 bCodeStream[classFileOffset++] = OPC_wide;
2706 } catch (IndexOutOfBoundsException e) {
2707 resizeByteArray(OPC_wide);
2711 bCodeStream[classFileOffset++] = OPC_iload;
2712 } catch (IndexOutOfBoundsException e) {
2713 resizeByteArray(OPC_iload);
2715 writeUnsignedShort(iArg);
2719 bCodeStream[classFileOffset++] = OPC_iload;
2720 } catch (IndexOutOfBoundsException e) {
2721 resizeByteArray(OPC_iload);
2725 bCodeStream[classFileOffset++] = (byte) iArg;
2726 } catch (IndexOutOfBoundsException e) {
2727 resizeByteArray((byte) iArg);
2731 final public void iload_0() {
2734 if (maxLocals <= 0) {
2737 if (stackDepth > stackMax)
2738 stackMax = stackDepth;
2741 bCodeStream[classFileOffset++] = OPC_iload_0;
2742 } catch (IndexOutOfBoundsException e) {
2743 resizeByteArray(OPC_iload_0);
2746 final public void iload_1() {
2749 if (maxLocals <= 1) {
2752 if (stackDepth > stackMax)
2753 stackMax = stackDepth;
2756 bCodeStream[classFileOffset++] = OPC_iload_1;
2757 } catch (IndexOutOfBoundsException e) {
2758 resizeByteArray(OPC_iload_1);
2761 final public void iload_2() {
2764 if (maxLocals <= 2) {
2767 if (stackDepth > stackMax)
2768 stackMax = stackDepth;
2771 bCodeStream[classFileOffset++] = OPC_iload_2;
2772 } catch (IndexOutOfBoundsException e) {
2773 resizeByteArray(OPC_iload_2);
2776 final public void iload_3() {
2779 if (maxLocals <= 3) {
2782 if (stackDepth > stackMax)
2783 stackMax = stackDepth;
2786 bCodeStream[classFileOffset++] = OPC_iload_3;
2787 } catch (IndexOutOfBoundsException e) {
2788 resizeByteArray(OPC_iload_3);
2791 final public void imul() {
2796 bCodeStream[classFileOffset++] = OPC_imul;
2797 } catch (IndexOutOfBoundsException e) {
2798 resizeByteArray(OPC_imul);
2801 public void incrementTemp(LocalVariableBinding localBinding, int value) {
2802 if (value == (short) value) {
2803 this.iinc(localBinding.resolvedPosition, value);
2809 store(localBinding, false);
2811 public void incrStackSize(int offset) {
2812 if ((stackDepth += offset) > stackMax)
2813 stackMax = stackDepth;
2815 public int indexOfSameLineEntrySincePC(int pc, int line) {
2816 for (int index = pc, max = pcToSourceMapSize; index < max; index += 2) {
2817 if (pcToSourceMap[index + 1] == line)
2822 final public void ineg() {
2826 bCodeStream[classFileOffset++] = OPC_ineg;
2827 } catch (IndexOutOfBoundsException e) {
2828 resizeByteArray(OPC_ineg);
2831 public void init(ClassFile classFile) {
2832 this.classFile = classFile;
2833 this.constantPool = classFile.constantPool;
2834 this.bCodeStream = classFile.contents;
2835 this.classFileOffset = classFile.contentsOffset;
2836 this.startingClassFileOffset = this.classFileOffset;
2837 pcToSourceMapSize = 0;
2839 int length = visibleLocals.length;
2840 if (noVisibleLocals.length < length) {
2841 noVisibleLocals = new LocalVariableBinding[length];
2843 System.arraycopy(noVisibleLocals, 0, visibleLocals, 0, length);
2844 visibleLocalsCount = 0;
2846 length = locals.length;
2847 if (noLocals.length < length) {
2848 noLocals = new LocalVariableBinding[length];
2850 System.arraycopy(noLocals, 0, locals, 0, length);
2851 allLocalsCounter = 0;
2853 length = exceptionHandlers.length;
2854 if (noExceptionHandlers.length < length) {
2855 noExceptionHandlers = new ExceptionLabel[length];
2857 System.arraycopy(noExceptionHandlers, 0, exceptionHandlers, 0, length);
2858 exceptionHandlersNumber = 0;
2860 length = labels.length;
2861 if (noLabels.length < length) {
2862 noLabels = new Label[length];
2864 System.arraycopy(noLabels, 0, labels, 0, length);
2873 * @param methodDeclaration org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration
2874 * @param classFile org.eclipse.jdt.internal.compiler.codegen.ClassFile
2876 public void initializeMaxLocals(MethodBinding methodBinding) {
2878 maxLocals = (methodBinding == null || methodBinding.isStatic()) ? 0 : 1;
2879 // take into account the synthetic parameters
2880 if (methodBinding != null) {
2881 if (methodBinding.isConstructor() && methodBinding.declaringClass.isNestedType()) {
2882 ReferenceBinding enclosingInstanceTypes[];
2883 if ((enclosingInstanceTypes = methodBinding.declaringClass.syntheticEnclosingInstanceTypes()) != null) {
2884 for (int i = 0, max = enclosingInstanceTypes.length; i < max; i++) {
2885 maxLocals++; // an enclosingInstanceType can only be a reference binding. It cannot be
2886 // LongBinding or DoubleBinding
2889 SyntheticArgumentBinding syntheticArguments[];
2890 if ((syntheticArguments = methodBinding.declaringClass.syntheticOuterLocalVariables()) != null) {
2891 for (int i = 0, max = syntheticArguments.length; i < max; i++) {
2892 TypeBinding argType;
2893 if (((argType = syntheticArguments[i].type) == LongBinding) || (argType == DoubleBinding)) {
2901 TypeBinding[] arguments;
2902 if ((arguments = methodBinding.parameters) != null) {
2903 for (int i = 0, max = arguments.length; i < max; i++) {
2904 TypeBinding argType;
2905 if (((argType = arguments[i]) == LongBinding) || (argType == DoubleBinding)) {
2915 * This methods searches for an existing entry inside the pcToSourceMap table with a pc equals to @pc.
2916 * If there is an existing entry it returns -1 (no insertion required).
2917 * Otherwise it returns the index where the entry for the pc has to be inserted.
2918 * This is based on the fact that the pcToSourceMap table is sorted according to the pc.
2923 public static int insertionIndex(int[] pcToSourceMap, int length, int pc) {
2929 // we search only on even indexes
2932 int currentPC = pcToSourceMap[m];
2933 if (pc < currentPC) {
2935 } else if (pc > currentPC) {
2941 if (pc < pcToSourceMap[m])
2946 * We didn't call it instanceof because there is a conflit with the
2947 * instanceof keyword
2949 final public void instance_of(TypeBinding typeBinding) {
2953 bCodeStream[classFileOffset++] = OPC_instanceof;
2954 } catch (IndexOutOfBoundsException e) {
2955 resizeByteArray(OPC_instanceof);
2957 writeUnsignedShort(constantPool.literalIndex(typeBinding));
2959 public void invokeClassForName() {
2960 // invokestatic: java.lang.Class.forName(Ljava.lang.String;)Ljava.lang.Class;
2964 bCodeStream[classFileOffset++] = OPC_invokestatic;
2965 } catch (IndexOutOfBoundsException e) {
2966 resizeByteArray(OPC_invokestatic);
2968 writeUnsignedShort(constantPool.literalIndexForJavaLangClassForName());
2971 public void invokeJavaLangClassDesiredAssertionStatus() {
2972 // invokevirtual: java.lang.Class.desiredAssertionStatus()Z;
2977 bCodeStream[classFileOffset++] = OPC_invokevirtual;
2978 } catch (IndexOutOfBoundsException e) {
2979 resizeByteArray(OPC_invokevirtual);
2981 writeUnsignedShort(constantPool.literalIndexForJavaLangClassDesiredAssertionStatus());
2984 public void invokeConstructorGetConstructor() {
2985 // invokevirtual: java.lang.Class.getConstructor(java.lang.Class[])Ljava.lang.reflect.Constructor;
2990 bCodeStream[classFileOffset++] = OPC_invokevirtual;
2991 } catch (IndexOutOfBoundsException e) {
2992 resizeByteArray(OPC_invokevirtual);
2994 writeUnsignedShort(constantPool.literalIndexForJavaLangClassGetConstructor());
2996 final public void invokeinterface(MethodBinding methodBinding) {
2997 // initialized to 1 to take into account this immediately
3003 bCodeStream[classFileOffset++] = OPC_invokeinterface;
3004 } catch (IndexOutOfBoundsException e) {
3005 resizeByteArray(OPC_invokeinterface);
3007 writeUnsignedShort(constantPool.literalIndex(methodBinding));
3008 for (int i = methodBinding.parameters.length - 1; i >= 0; i--)
3009 if (((id = methodBinding.parameters[i].id) == T_double) || (id == T_long))
3013 writeUnsignedByte(argCount);
3014 // Generate a 0 into the byte array. Like the array is already fill with 0, we just need to increment
3015 // the number of bytes.
3018 if (((id = methodBinding.returnType.id) == T_double) || (id == T_long))
3019 stackDepth += (2 - argCount);
3020 else if (id == T_void)
3021 stackDepth -= argCount;
3023 stackDepth += (1 - argCount);
3024 if (stackDepth > stackMax)
3025 stackMax = stackDepth;
3027 public void invokeJavaLangErrorConstructor() {
3028 // invokespecial: java.lang.Error<init>(Ljava.lang.String;)V
3032 bCodeStream[classFileOffset++] = OPC_invokespecial;
3033 } catch (IndexOutOfBoundsException e) {
3034 resizeByteArray(OPC_invokespecial);
3037 writeUnsignedShort(constantPool.literalIndexForJavaLangErrorConstructor());
3039 public void invokeNoClassDefFoundErrorStringConstructor() {
3040 // invokespecial: java.lang.NoClassDefFoundError.<init>(Ljava.lang.String;)V
3044 bCodeStream[classFileOffset++] = OPC_invokespecial;
3045 } catch (IndexOutOfBoundsException e) {
3046 resizeByteArray(OPC_invokespecial);
3048 writeUnsignedShort(constantPool.literalIndexForJavaLangNoClassDefFoundErrorStringConstructor());
3051 public void invokeObjectNewInstance() {
3052 // invokevirtual: java.lang.reflect.Constructor.newInstance(java.lang.Object[])Ljava.lang.Object;
3057 bCodeStream[classFileOffset++] = OPC_invokevirtual;
3058 } catch (IndexOutOfBoundsException e) {
3059 resizeByteArray(OPC_invokevirtual);
3061 writeUnsignedShort(constantPool.literalIndexForJavaLangReflectConstructorNewInstance());
3064 public void invokeObjectGetClass() {
3065 // invokevirtual: java.lang.Object.getClass()Ljava.lang.Class;
3069 bCodeStream[classFileOffset++] = OPC_invokevirtual;
3070 } catch (IndexOutOfBoundsException e) {
3071 resizeByteArray(OPC_invokevirtual);
3073 writeUnsignedShort(constantPool.literalIndexForJavaLangObjectGetClass());
3076 final public void invokespecial(MethodBinding methodBinding) {
3077 // initialized to 1 to take into account this immediately
3083 bCodeStream[classFileOffset++] = OPC_invokespecial;
3084 } catch (IndexOutOfBoundsException e) {
3085 resizeByteArray(OPC_invokespecial);
3087 writeUnsignedShort(constantPool.literalIndex(methodBinding));
3088 if (methodBinding.isConstructor() && methodBinding.declaringClass.isNestedType()) {
3089 // enclosing instances
3090 TypeBinding[] syntheticArgumentTypes = methodBinding.declaringClass.syntheticEnclosingInstanceTypes();
3091 if (syntheticArgumentTypes != null) {
3092 for (int i = 0, max = syntheticArgumentTypes.length; i < max; i++) {
3093 if (((id = syntheticArgumentTypes[i].id) == T_double) || (id == T_long)) {
3100 // outer local variables
3101 SyntheticArgumentBinding[] syntheticArguments = methodBinding.declaringClass.syntheticOuterLocalVariables();
3102 if (syntheticArguments != null) {
3103 for (int i = 0, max = syntheticArguments.length; i < max; i++) {
3104 if (((id = syntheticArguments[i].type.id) == T_double) || (id == T_long)) {
3112 for (int i = methodBinding.parameters.length - 1; i >= 0; i--)
3113 if (((id = methodBinding.parameters[i].id) == T_double) || (id == T_long))
3117 if (((id = methodBinding.returnType.id) == T_double) || (id == T_long))
3118 stackDepth += (2 - argCount);
3119 else if (id == T_void)
3120 stackDepth -= argCount;
3122 stackDepth += (1 - argCount);
3123 if (stackDepth > stackMax)
3124 stackMax = stackDepth;
3126 final public void invokestatic(MethodBinding methodBinding) {
3127 // initialized to 0 to take into account that there is no this for
3134 bCodeStream[classFileOffset++] = OPC_invokestatic;
3135 } catch (IndexOutOfBoundsException e) {
3136 resizeByteArray(OPC_invokestatic);
3138 writeUnsignedShort(constantPool.literalIndex(methodBinding));
3139 for (int i = methodBinding.parameters.length - 1; i >= 0; i--)
3140 if (((id = methodBinding.parameters[i].id) == T_double) || (id == T_long))
3144 if (((id = methodBinding.returnType.id) == T_double) || (id == T_long))
3145 stackDepth += (2 - argCount);
3146 else if (id == T_void)
3147 stackDepth -= argCount;
3149 stackDepth += (1 - argCount);
3150 if (stackDepth > stackMax)
3151 stackMax = stackDepth;
3154 * The equivalent code performs a string conversion of the TOS
3155 * @param typeID <CODE>int</CODE>
3157 public void invokeStringBufferAppendForType(int typeID) {
3160 if (typeID == T_null)
3161 usedTypeID = T_String;
3163 usedTypeID = typeID;
3167 bCodeStream[classFileOffset++] = OPC_invokevirtual;
3168 } catch (IndexOutOfBoundsException e) {
3169 resizeByteArray(OPC_invokevirtual);
3171 writeUnsignedShort(constantPool.literalIndexForJavaLangStringBufferAppend(typeID));
3172 if ((usedTypeID == T_long) || (usedTypeID == T_double))
3178 public void invokeJavaLangAssertionErrorConstructor(int typeBindingID) {
3179 // invokespecial: java.lang.AssertionError.<init>(typeBindingID)V
3183 bCodeStream[classFileOffset++] = OPC_invokespecial;
3184 } catch (IndexOutOfBoundsException e) {
3185 resizeByteArray(OPC_invokespecial);
3187 writeUnsignedShort(constantPool.literalIndexForJavaLangAssertionErrorConstructor(typeBindingID));
3191 public void invokeJavaLangAssertionErrorDefaultConstructor() {
3192 // invokespecial: java.lang.AssertionError.<init>()V
3196 bCodeStream[classFileOffset++] = OPC_invokespecial;
3197 } catch (IndexOutOfBoundsException e) {
3198 resizeByteArray(OPC_invokespecial);
3200 writeUnsignedShort(constantPool.literalIndexForJavaLangAssertionErrorDefaultConstructor());
3204 public void invokeStringBufferDefaultConstructor() {
3205 // invokespecial: java.lang.StringBuffer.<init>()V
3209 bCodeStream[classFileOffset++] = OPC_invokespecial;
3210 } catch (IndexOutOfBoundsException e) {
3211 resizeByteArray(OPC_invokespecial);
3213 writeUnsignedShort(constantPool.literalIndexForJavaLangStringBufferDefaultConstructor());
3216 public void invokeStringBufferStringConstructor() {
3217 // invokespecial: java.lang.StringBuffer.<init>(Ljava.lang.String;)V
3221 bCodeStream[classFileOffset++] = OPC_invokespecial;
3222 } catch (IndexOutOfBoundsException e) {
3223 resizeByteArray(OPC_invokespecial);
3225 writeUnsignedShort(constantPool.literalIndexForJavaLangStringBufferConstructor());
3229 public void invokeStringBufferToString() {
3230 // invokevirtual: StringBuffer.toString()Ljava.lang.String;
3234 bCodeStream[classFileOffset++] = OPC_invokevirtual;
3235 } catch (IndexOutOfBoundsException e) {
3236 resizeByteArray(OPC_invokevirtual);
3238 writeUnsignedShort(constantPool.literalIndexForJavaLangStringBufferToString());
3240 public void invokeStringIntern() {
3241 // invokevirtual: java.lang.String.intern()
3245 bCodeStream[classFileOffset++] = OPC_invokevirtual;
3246 } catch (IndexOutOfBoundsException e) {
3247 resizeByteArray(OPC_invokevirtual);
3249 writeUnsignedShort(constantPool.literalIndexForJavaLangStringIntern());
3251 public void invokeStringValueOf(int typeID) {
3252 // invokestatic: java.lang.String.valueOf(argumentType)
3256 bCodeStream[classFileOffset++] = OPC_invokestatic;
3257 } catch (IndexOutOfBoundsException e) {
3258 resizeByteArray(OPC_invokestatic);
3260 writeUnsignedShort(constantPool.literalIndexForJavaLangStringValueOf(typeID));
3262 public void invokeSystemExit() {
3263 // invokestatic: java.lang.System.exit(I)
3267 bCodeStream[classFileOffset++] = OPC_invokestatic;
3268 } catch (IndexOutOfBoundsException e) {
3269 resizeByteArray(OPC_invokestatic);
3271 writeUnsignedShort(constantPool.literalIndexForJavaLangSystemExitInt());
3272 stackDepth--; // int argument
3274 public void invokeThrowableGetMessage() {
3275 // invokevirtual: java.lang.Throwable.getMessage()Ljava.lang.String;
3279 bCodeStream[classFileOffset++] = OPC_invokevirtual;
3280 } catch (IndexOutOfBoundsException e) {
3281 resizeByteArray(OPC_invokevirtual);
3283 writeUnsignedShort(constantPool.literalIndexForJavaLangThrowableGetMessage());
3285 final public void invokevirtual(MethodBinding methodBinding) {
3286 // initialized to 1 to take into account this immediately
3292 bCodeStream[classFileOffset++] = OPC_invokevirtual;
3293 } catch (IndexOutOfBoundsException e) {
3294 resizeByteArray(OPC_invokevirtual);
3296 writeUnsignedShort(constantPool.literalIndex(methodBinding));
3297 for (int i = methodBinding.parameters.length - 1; i >= 0; i--)
3298 if (((id = methodBinding.parameters[i].id) == T_double) || (id == T_long))
3302 if (((id = methodBinding.returnType.id) == T_double) || (id == T_long))
3303 stackDepth += (2 - argCount);
3304 else if (id == T_void)
3305 stackDepth -= argCount;
3307 stackDepth += (1 - argCount);
3308 if (stackDepth > stackMax)
3309 stackMax = stackDepth;
3311 final public void ior() {
3316 bCodeStream[classFileOffset++] = OPC_ior;
3317 } catch (IndexOutOfBoundsException e) {
3318 resizeByteArray(OPC_ior);
3321 final public void irem() {
3326 bCodeStream[classFileOffset++] = OPC_irem;
3327 } catch (IndexOutOfBoundsException e) {
3328 resizeByteArray(OPC_irem);
3331 final public void ireturn() {
3334 // the stackDepth should be equal to 0
3337 bCodeStream[classFileOffset++] = OPC_ireturn;
3338 } catch (IndexOutOfBoundsException e) {
3339 resizeByteArray(OPC_ireturn);
3342 public boolean isDefinitelyAssigned(Scope scope, int initStateIndex, LocalVariableBinding local) {
3343 // Dependant of UnconditionalFlowInfo.isDefinitelyAssigned(..)
3344 if (initStateIndex == -1)
3346 if (local.isArgument) {
3349 int position = local.id + maxFieldCount;
3350 MethodScope methodScope = scope.methodScope();
3352 if (position < UnconditionalFlowInfo.BitCacheSize) {
3353 return (methodScope.definiteInits[initStateIndex] & (1L << position)) != 0; // use bits
3356 long[] extraInits = methodScope.extraDefiniteInits[initStateIndex];
3357 if (extraInits == null)
3358 return false; // if vector not yet allocated, then not initialized
3360 if ((vectorIndex = (position / UnconditionalFlowInfo.BitCacheSize) - 1) >= extraInits.length)
3361 return false; // if not enough room in vector, then not initialized
3362 return ((extraInits[vectorIndex]) & (1L << (position % UnconditionalFlowInfo.BitCacheSize))) != 0;
3364 final public void ishl() {
3369 bCodeStream[classFileOffset++] = OPC_ishl;
3370 } catch (IndexOutOfBoundsException e) {
3371 resizeByteArray(OPC_ishl);
3374 final public void ishr() {
3379 bCodeStream[classFileOffset++] = OPC_ishr;
3380 } catch (IndexOutOfBoundsException e) {
3381 resizeByteArray(OPC_ishr);
3384 final public void istore(int iArg) {
3387 if (maxLocals <= iArg) {
3388 maxLocals = iArg + 1;
3390 if (iArg > 255) { // Widen
3393 bCodeStream[classFileOffset++] = OPC_wide;
3394 } catch (IndexOutOfBoundsException e) {
3395 resizeByteArray(OPC_wide);
3399 bCodeStream[classFileOffset++] = OPC_istore;
3400 } catch (IndexOutOfBoundsException e) {
3401 resizeByteArray(OPC_istore);
3403 writeUnsignedShort(iArg);
3407 bCodeStream[classFileOffset++] = OPC_istore;
3408 } catch (IndexOutOfBoundsException e) {
3409 resizeByteArray(OPC_istore);
3413 bCodeStream[classFileOffset++] = (byte) iArg;
3414 } catch (IndexOutOfBoundsException e) {
3415 resizeByteArray((byte) iArg);
3419 final public void istore_0() {
3422 if (maxLocals == 0) {
3427 bCodeStream[classFileOffset++] = OPC_istore_0;
3428 } catch (IndexOutOfBoundsException e) {
3429 resizeByteArray(OPC_istore_0);
3432 final public void istore_1() {
3435 if (maxLocals <= 1) {
3440 bCodeStream[classFileOffset++] = OPC_istore_1;
3441 } catch (IndexOutOfBoundsException e) {
3442 resizeByteArray(OPC_istore_1);
3445 final public void istore_2() {
3448 if (maxLocals <= 2) {
3453 bCodeStream[classFileOffset++] = OPC_istore_2;
3454 } catch (IndexOutOfBoundsException e) {
3455 resizeByteArray(OPC_istore_2);
3458 final public void istore_3() {
3461 if (maxLocals <= 3) {
3466 bCodeStream[classFileOffset++] = OPC_istore_3;
3467 } catch (IndexOutOfBoundsException e) {
3468 resizeByteArray(OPC_istore_3);
3471 final public void isub() {
3476 bCodeStream[classFileOffset++] = OPC_isub;
3477 } catch (IndexOutOfBoundsException e) {
3478 resizeByteArray(OPC_isub);
3481 final public void iushr() {
3486 bCodeStream[classFileOffset++] = OPC_iushr;
3487 } catch (IndexOutOfBoundsException e) {
3488 resizeByteArray(OPC_iushr);
3491 final public void ixor() {
3496 bCodeStream[classFileOffset++] = OPC_ixor;
3497 } catch (IndexOutOfBoundsException e) {
3498 resizeByteArray(OPC_ixor);
3501 final public void jsr(Label lbl) {
3505 bCodeStream[classFileOffset++] = OPC_jsr;
3506 } catch (IndexOutOfBoundsException e) {
3507 resizeByteArray(OPC_jsr);
3511 final public void jsr_w(Label lbl) {
3515 bCodeStream[classFileOffset++] = OPC_jsr_w;
3516 } catch (IndexOutOfBoundsException e) {
3517 resizeByteArray(OPC_jsr_w);
3521 final public void l2d() {
3525 bCodeStream[classFileOffset++] = OPC_l2d;
3526 } catch (IndexOutOfBoundsException e) {
3527 resizeByteArray(OPC_l2d);
3530 final public void l2f() {
3535 bCodeStream[classFileOffset++] = OPC_l2f;
3536 } catch (IndexOutOfBoundsException e) {
3537 resizeByteArray(OPC_l2f);
3540 final public void l2i() {
3545 bCodeStream[classFileOffset++] = OPC_l2i;
3546 } catch (IndexOutOfBoundsException e) {
3547 resizeByteArray(OPC_l2i);
3550 final public void ladd() {
3555 bCodeStream[classFileOffset++] = OPC_ladd;
3556 } catch (IndexOutOfBoundsException e) {
3557 resizeByteArray(OPC_ladd);
3560 final public void laload() {
3564 bCodeStream[classFileOffset++] = OPC_laload;
3565 } catch (IndexOutOfBoundsException e) {
3566 resizeByteArray(OPC_laload);
3569 final public void land() {
3574 bCodeStream[classFileOffset++] = OPC_land;
3575 } catch (IndexOutOfBoundsException e) {
3576 resizeByteArray(OPC_land);
3579 final public void lastore() {
3584 bCodeStream[classFileOffset++] = OPC_lastore;
3585 } catch (IndexOutOfBoundsException e) {
3586 resizeByteArray(OPC_lastore);
3589 final public void lcmp() {
3594 bCodeStream[classFileOffset++] = OPC_lcmp;
3595 } catch (IndexOutOfBoundsException e) {
3596 resizeByteArray(OPC_lcmp);
3599 final public void lconst_0() {
3602 if (stackDepth > stackMax)
3603 stackMax = stackDepth;
3606 bCodeStream[classFileOffset++] = OPC_lconst_0;
3607 } catch (IndexOutOfBoundsException e) {
3608 resizeByteArray(OPC_lconst_0);
3611 final public void lconst_1() {
3614 if (stackDepth > stackMax)
3615 stackMax = stackDepth;
3618 bCodeStream[classFileOffset++] = OPC_lconst_1;
3619 } catch (IndexOutOfBoundsException e) {
3620 resizeByteArray(OPC_lconst_1);
3623 final public void ldc(float constant) {
3625 int index = constantPool.literalIndex(constant);
3627 if (stackDepth > stackMax)
3628 stackMax = stackDepth;
3633 bCodeStream[classFileOffset++] = OPC_ldc_w;
3634 } catch (IndexOutOfBoundsException e) {
3635 resizeByteArray(OPC_ldc_w);
3637 writeUnsignedShort(index);
3642 bCodeStream[classFileOffset++] = OPC_ldc;
3643 } catch (IndexOutOfBoundsException e) {
3644 resizeByteArray(OPC_ldc);
3646 writeUnsignedByte(index);
3649 final public void ldc(int constant) {
3651 int index = constantPool.literalIndex(constant);
3653 if (stackDepth > stackMax)
3654 stackMax = stackDepth;
3659 bCodeStream[classFileOffset++] = OPC_ldc_w;
3660 } catch (IndexOutOfBoundsException e) {
3661 resizeByteArray(OPC_ldc_w);
3663 writeUnsignedShort(index);
3668 bCodeStream[classFileOffset++] = OPC_ldc;
3669 } catch (IndexOutOfBoundsException e) {
3670 resizeByteArray(OPC_ldc);
3672 writeUnsignedByte(index);
3675 final public void ldc(String constant) {
3677 int currentConstantPoolIndex = constantPool.currentIndex;
3678 int currentConstantPoolOffset = constantPool.currentOffset;
3679 int currentCodeStreamPosition = position;
3680 int index = constantPool.literalIndexForLdc(constant.toCharArray());
3682 // the string already exists inside the constant pool
3683 // we reuse the same index
3685 if (stackDepth > stackMax)
3686 stackMax = stackDepth;
3691 bCodeStream[classFileOffset++] = OPC_ldc_w;
3692 } catch (IndexOutOfBoundsException e) {
3693 resizeByteArray(OPC_ldc_w);
3695 writeUnsignedShort(index);
3700 bCodeStream[classFileOffset++] = OPC_ldc;
3701 } catch (IndexOutOfBoundsException e) {
3702 resizeByteArray(OPC_ldc);
3704 writeUnsignedByte(index);
3707 // the string is too big to be utf8-encoded in one pass.
3708 // we have to split it into different pieces.
3709 // first we clean all side-effects due to the code above
3710 // this case is very rare, so we can afford to lose time to handle it
3711 char[] constantChars = constant.toCharArray();
3712 position = currentCodeStreamPosition;
3713 constantPool.currentIndex = currentConstantPoolIndex;
3714 constantPool.currentOffset = currentConstantPoolOffset;
3715 constantPool.stringCache.remove(constantChars);
3716 constantPool.UTF8Cache.remove(constantChars);
3719 int constantLength = constant.length();
3720 byte[] utf8encoding = new byte[Math.min(constantLength + 100, 65535)];
3721 int utf8encodingLength = 0;
3722 while ((length < 65532) && (i < constantLength)) {
3723 char current = constantChars[i];
3724 // we resize the byte array immediately if necessary
3725 if (length + 3 > (utf8encodingLength = utf8encoding.length)) {
3726 System.arraycopy(utf8encoding, 0, (utf8encoding = new byte[Math.min(utf8encodingLength + 100, 65535)]), 0, length);
3728 if ((current >= 0x0001) && (current <= 0x007F)) {
3729 // we only need one byte: ASCII table
3730 utf8encoding[length++] = (byte) current;
3732 if (current > 0x07FF) {
3734 utf8encoding[length++] = (byte) (0xE0 | ((current >> 12) & 0x0F)); // 0xE0 = 1110 0000
3735 utf8encoding[length++] = (byte) (0x80 | ((current >> 6) & 0x3F)); // 0x80 = 1000 0000
3736 utf8encoding[length++] = (byte) (0x80 | (current & 0x3F)); // 0x80 = 1000 0000
3738 // we can be 0 or between 0x0080 and 0x07FF
3739 // In that case we only need 2 bytes
3740 utf8encoding[length++] = (byte) (0xC0 | ((current >> 6) & 0x1F)); // 0xC0 = 1100 0000
3741 utf8encoding[length++] = (byte) (0x80 | (current & 0x3F)); // 0x80 = 1000 0000
3746 // check if all the string is encoded (PR 1PR2DWJ)
3747 // the string is too big to be encoded in one pass
3750 // write the first part
3751 char[] subChars = new char[i];
3752 System.arraycopy(constantChars, 0, subChars, 0, i);
3753 System.arraycopy(utf8encoding, 0, (utf8encoding = new byte[length]), 0, length);
3754 index = constantPool.literalIndex(subChars, utf8encoding);
3756 if (stackDepth > stackMax)
3757 stackMax = stackDepth;
3762 bCodeStream[classFileOffset++] = OPC_ldc_w;
3763 } catch (IndexOutOfBoundsException e) {
3764 resizeByteArray(OPC_ldc_w);
3766 writeUnsignedShort(index);
3771 bCodeStream[classFileOffset++] = OPC_ldc;
3772 } catch (IndexOutOfBoundsException e) {
3773 resizeByteArray(OPC_ldc);
3775 writeUnsignedByte(index);
3777 // write the remaining part
3778 invokeStringBufferStringConstructor();
3779 while (i < constantLength) {
3781 utf8encoding = new byte[Math.min(constantLength - i + 100, 65535)];
3783 while ((length < 65532) && (i < constantLength)) {
3784 char current = constantChars[i];
3785 // we resize the byte array immediately if necessary
3786 if (constantLength + 2 > (utf8encodingLength = utf8encoding.length)) {
3787 System.arraycopy(utf8encoding, 0, (utf8encoding = new byte[Math.min(utf8encodingLength + 100, 65535)]), 0, length);
3789 if ((current >= 0x0001) && (current <= 0x007F)) {
3790 // we only need one byte: ASCII table
3791 utf8encoding[length++] = (byte) current;
3793 if (current > 0x07FF) {
3795 utf8encoding[length++] = (byte) (0xE0 | ((current >> 12) & 0x0F)); // 0xE0 = 1110 0000
3796 utf8encoding[length++] = (byte) (0x80 | ((current >> 6) & 0x3F)); // 0x80 = 1000 0000
3797 utf8encoding[length++] = (byte) (0x80 | (current & 0x3F)); // 0x80 = 1000 0000
3799 // we can be 0 or between 0x0080 and 0x07FF
3800 // In that case we only need 2 bytes
3801 utf8encoding[length++] = (byte) (0xC0 | ((current >> 6) & 0x1F)); // 0xC0 = 1100 0000
3802 utf8encoding[length++] = (byte) (0x80 | (current & 0x3F)); // 0x80 = 1000 0000
3807 // the next part is done
3808 subChars = new char[i - startIndex];
3809 System.arraycopy(constantChars, startIndex, subChars, 0, i - startIndex);
3810 System.arraycopy(utf8encoding, 0, (utf8encoding = new byte[length]), 0, length);
3811 index = constantPool.literalIndex(subChars, utf8encoding);
3813 if (stackDepth > stackMax)
3814 stackMax = stackDepth;
3819 bCodeStream[classFileOffset++] = OPC_ldc_w;
3820 } catch (IndexOutOfBoundsException e) {
3821 resizeByteArray(OPC_ldc_w);
3823 writeUnsignedShort(index);
3828 bCodeStream[classFileOffset++] = OPC_ldc;
3829 } catch (IndexOutOfBoundsException e) {
3830 resizeByteArray(OPC_ldc);
3832 writeUnsignedByte(index);
3834 // now on the stack it should be a StringBuffer and a string.
3835 invokeStringBufferAppendForType(T_String);
3837 invokeStringBufferToString();
3838 invokeStringIntern();
3841 final public void ldc2_w(double constant) {
3843 int index = constantPool.literalIndex(constant);
3845 if (stackDepth > stackMax)
3846 stackMax = stackDepth;
3847 // Generate a ldc2_w
3850 bCodeStream[classFileOffset++] = OPC_ldc2_w;
3851 } catch (IndexOutOfBoundsException e) {
3852 resizeByteArray(OPC_ldc2_w);
3854 writeUnsignedShort(index);
3856 final public void ldc2_w(long constant) {
3858 int index = constantPool.literalIndex(constant);
3860 if (stackDepth > stackMax)
3861 stackMax = stackDepth;
3862 // Generate a ldc2_w
3865 bCodeStream[classFileOffset++] = OPC_ldc2_w;
3866 } catch (IndexOutOfBoundsException e) {
3867 resizeByteArray(OPC_ldc2_w);
3869 writeUnsignedShort(index);
3871 final public void ldiv() {
3876 bCodeStream[classFileOffset++] = OPC_ldiv;
3877 } catch (IndexOutOfBoundsException e) {
3878 resizeByteArray(OPC_ldiv);
3881 final public void lload(int iArg) {
3884 if (maxLocals <= iArg + 1) {
3885 maxLocals = iArg + 2;
3887 if (stackDepth > stackMax)
3888 stackMax = stackDepth;
3889 if (iArg > 255) { // Widen
3892 bCodeStream[classFileOffset++] = OPC_wide;
3893 } catch (IndexOutOfBoundsException e) {
3894 resizeByteArray(OPC_wide);
3898 bCodeStream[classFileOffset++] = OPC_lload;
3899 } catch (IndexOutOfBoundsException e) {
3900 resizeByteArray(OPC_lload);
3902 writeUnsignedShort(iArg);
3906 bCodeStream[classFileOffset++] = OPC_lload;
3907 } catch (IndexOutOfBoundsException e) {
3908 resizeByteArray(OPC_lload);
3912 bCodeStream[classFileOffset++] = (byte) iArg;
3913 } catch (IndexOutOfBoundsException e) {
3914 resizeByteArray((byte) iArg);
3918 final public void lload_0() {
3921 if (maxLocals < 2) {
3924 if (stackDepth > stackMax)
3925 stackMax = stackDepth;
3928 bCodeStream[classFileOffset++] = OPC_lload_0;
3929 } catch (IndexOutOfBoundsException e) {
3930 resizeByteArray(OPC_lload_0);
3933 final public void lload_1() {
3936 if (maxLocals < 3) {
3939 if (stackDepth > stackMax)
3940 stackMax = stackDepth;
3943 bCodeStream[classFileOffset++] = OPC_lload_1;
3944 } catch (IndexOutOfBoundsException e) {
3945 resizeByteArray(OPC_lload_1);
3948 final public void lload_2() {
3951 if (maxLocals < 4) {
3954 if (stackDepth > stackMax)
3955 stackMax = stackDepth;
3958 bCodeStream[classFileOffset++] = OPC_lload_2;
3959 } catch (IndexOutOfBoundsException e) {
3960 resizeByteArray(OPC_lload_2);
3963 final public void lload_3() {
3966 if (maxLocals < 5) {
3969 if (stackDepth > stackMax)
3970 stackMax = stackDepth;
3973 bCodeStream[classFileOffset++] = OPC_lload_3;
3974 } catch (IndexOutOfBoundsException e) {
3975 resizeByteArray(OPC_lload_3);
3978 final public void lmul() {
3983 bCodeStream[classFileOffset++] = OPC_lmul;
3984 } catch (IndexOutOfBoundsException e) {
3985 resizeByteArray(OPC_lmul);
3988 final public void lneg() {
3992 bCodeStream[classFileOffset++] = OPC_lneg;
3993 } catch (IndexOutOfBoundsException e) {
3994 resizeByteArray(OPC_lneg);
3997 public final void load(LocalVariableBinding localBinding) {
3999 TypeBinding typeBinding = localBinding.type;
4000 int resolvedPosition = localBinding.resolvedPosition;
4001 // Using dedicated int bytecode
4002 if (typeBinding == IntBinding) {
4003 switch (resolvedPosition) {
4017 this.iload(resolvedPosition);
4021 // Using dedicated float bytecode
4022 if (typeBinding == FloatBinding) {
4023 switch (resolvedPosition) {
4037 this.fload(resolvedPosition);
4041 // Using dedicated long bytecode
4042 if (typeBinding == LongBinding) {
4043 switch (resolvedPosition) {
4057 this.lload(resolvedPosition);
4061 // Using dedicated double bytecode
4062 if (typeBinding == DoubleBinding) {
4063 switch (resolvedPosition) {
4077 this.dload(resolvedPosition);
4081 // boolean, byte, char and short are handled as int
4082 if ((typeBinding == ByteBinding)
4083 || (typeBinding == CharBinding)
4084 || (typeBinding == BooleanBinding)
4085 || (typeBinding == ShortBinding)) {
4086 switch (resolvedPosition) {
4100 this.iload(resolvedPosition);
4106 switch (resolvedPosition) {
4120 this.aload(resolvedPosition);
4123 public final void load(TypeBinding typeBinding, int resolvedPosition) {
4125 // Using dedicated int bytecode
4126 if (typeBinding == IntBinding) {
4127 switch (resolvedPosition) {
4141 this.iload(resolvedPosition);
4145 // Using dedicated float bytecode
4146 if (typeBinding == FloatBinding) {
4147 switch (resolvedPosition) {
4161 this.fload(resolvedPosition);
4165 // Using dedicated long bytecode
4166 if (typeBinding == LongBinding) {
4167 switch (resolvedPosition) {
4181 this.lload(resolvedPosition);
4185 // Using dedicated double bytecode
4186 if (typeBinding == DoubleBinding) {
4187 switch (resolvedPosition) {
4201 this.dload(resolvedPosition);
4205 // boolean, byte, char and short are handled as int
4206 if ((typeBinding == ByteBinding)
4207 || (typeBinding == CharBinding)
4208 || (typeBinding == BooleanBinding)
4209 || (typeBinding == ShortBinding)) {
4210 switch (resolvedPosition) {
4224 this.iload(resolvedPosition);
4230 switch (resolvedPosition) {
4244 this.aload(resolvedPosition);
4247 public final void loadInt(int resolvedPosition) {
4248 // Using dedicated int bytecode
4249 switch (resolvedPosition) {
4263 this.iload(resolvedPosition);
4266 public final void loadObject(int resolvedPosition) {
4267 switch (resolvedPosition) {
4281 this.aload(resolvedPosition);
4284 final public void lookupswitch(CaseLabel defaultLabel, int[] keys, int[] sortedIndexes, CaseLabel[] casesLabel) {
4287 int length = keys.length;
4289 defaultLabel.placeInstruction();
4290 for (int i = 0; i < length; i++) {
4291 casesLabel[i].placeInstruction();
4295 bCodeStream[classFileOffset++] = OPC_lookupswitch;
4296 } catch (IndexOutOfBoundsException e) {
4297 resizeByteArray(OPC_lookupswitch);
4299 for (int i = (3 - (pos % 4)); i > 0; i--) {
4300 position++; // Padding
4303 defaultLabel.branch();
4304 writeSignedWord(length);
4305 for (int i = 0; i < length; i++) {
4306 writeSignedWord(keys[sortedIndexes[i]]);
4307 casesLabel[sortedIndexes[i]].branch();
4310 final public void lor() {
4315 bCodeStream[classFileOffset++] = OPC_lor;
4316 } catch (IndexOutOfBoundsException e) {
4317 resizeByteArray(OPC_lor);
4320 final public void lrem() {
4325 bCodeStream[classFileOffset++] = OPC_lrem;
4326 } catch (IndexOutOfBoundsException e) {
4327 resizeByteArray(OPC_lrem);
4330 final public void lreturn() {
4333 // the stackDepth should be equal to 0
4336 bCodeStream[classFileOffset++] = OPC_lreturn;
4337 } catch (IndexOutOfBoundsException e) {
4338 resizeByteArray(OPC_lreturn);
4341 final public void lshl() {
4346 bCodeStream[classFileOffset++] = OPC_lshl;
4347 } catch (IndexOutOfBoundsException e) {
4348 resizeByteArray(OPC_lshl);
4351 final public void lshr() {
4356 bCodeStream[classFileOffset++] = OPC_lshr;
4357 } catch (IndexOutOfBoundsException e) {
4358 resizeByteArray(OPC_lshr);
4361 final public void lstore(int iArg) {
4364 if (maxLocals <= iArg + 1) {
4365 maxLocals = iArg + 2;
4367 if (iArg > 255) { // Widen
4370 bCodeStream[classFileOffset++] = OPC_wide;
4371 } catch (IndexOutOfBoundsException e) {
4372 resizeByteArray(OPC_wide);
4376 bCodeStream[classFileOffset++] = OPC_lstore;
4377 } catch (IndexOutOfBoundsException e) {
4378 resizeByteArray(OPC_lstore);
4380 writeUnsignedShort(iArg);
4384 bCodeStream[classFileOffset++] = OPC_lstore;
4385 } catch (IndexOutOfBoundsException e) {
4386 resizeByteArray(OPC_lstore);
4390 bCodeStream[classFileOffset++] = (byte) iArg;
4391 } catch (IndexOutOfBoundsException e) {
4392 resizeByteArray((byte) iArg);
4396 final public void lstore_0() {
4399 if (maxLocals < 2) {
4404 bCodeStream[classFileOffset++] = OPC_lstore_0;
4405 } catch (IndexOutOfBoundsException e) {
4406 resizeByteArray(OPC_lstore_0);
4409 final public void lstore_1() {
4412 if (maxLocals < 3) {
4417 bCodeStream[classFileOffset++] = OPC_lstore_1;
4418 } catch (IndexOutOfBoundsException e) {
4419 resizeByteArray(OPC_lstore_1);
4422 final public void lstore_2() {
4425 if (maxLocals < 4) {
4430 bCodeStream[classFileOffset++] = OPC_lstore_2;
4431 } catch (IndexOutOfBoundsException e) {
4432 resizeByteArray(OPC_lstore_2);
4435 final public void lstore_3() {
4438 if (maxLocals < 5) {
4443 bCodeStream[classFileOffset++] = OPC_lstore_3;
4444 } catch (IndexOutOfBoundsException e) {
4445 resizeByteArray(OPC_lstore_3);
4448 final public void lsub() {
4453 bCodeStream[classFileOffset++] = OPC_lsub;
4454 } catch (IndexOutOfBoundsException e) {
4455 resizeByteArray(OPC_lsub);
4458 final public void lushr() {
4463 bCodeStream[classFileOffset++] = OPC_lushr;
4464 } catch (IndexOutOfBoundsException e) {
4465 resizeByteArray(OPC_lushr);
4468 final public void lxor() {
4473 bCodeStream[classFileOffset++] = OPC_lxor;
4474 } catch (IndexOutOfBoundsException e) {
4475 resizeByteArray(OPC_lxor);
4478 final public void monitorenter() {
4483 bCodeStream[classFileOffset++] = OPC_monitorenter;
4484 } catch (IndexOutOfBoundsException e) {
4485 resizeByteArray(OPC_monitorenter);
4488 final public void monitorexit() {
4493 bCodeStream[classFileOffset++] = OPC_monitorexit;
4494 } catch (IndexOutOfBoundsException e) {
4495 resizeByteArray(OPC_monitorexit);
4498 final public void multianewarray(TypeBinding typeBinding, int dimensions) {
4500 stackDepth += (1 - dimensions);
4503 bCodeStream[classFileOffset++] = OPC_multianewarray;
4504 } catch (IndexOutOfBoundsException e) {
4505 resizeByteArray(OPC_multianewarray);
4507 writeUnsignedShort(constantPool.literalIndex(typeBinding));
4508 writeUnsignedByte(dimensions);
4510 public static void needImplementation() {
4513 * We didn't call it new, because there is a conflit with the new keyword
4515 final public void new_(TypeBinding typeBinding) {
4518 if (stackDepth > stackMax)
4519 stackMax = stackDepth;
4522 bCodeStream[classFileOffset++] = OPC_new;
4523 } catch (IndexOutOfBoundsException e) {
4524 resizeByteArray(OPC_new);
4526 writeUnsignedShort(constantPool.literalIndex(typeBinding));
4528 final public void newarray(int array_Type) {
4532 bCodeStream[classFileOffset++] = OPC_newarray;
4533 } catch (IndexOutOfBoundsException e) {
4534 resizeByteArray(OPC_newarray);
4536 writeUnsignedByte(array_Type);
4538 public void newArray(Scope scope, ArrayBinding arrayBinding) {
4539 TypeBinding component = arrayBinding.elementsType(scope);
4540 switch (component.id) {
4566 this.anewarray(component);
4569 public void newJavaLangError() {
4570 // new: java.lang.Error
4573 if (stackDepth > stackMax)
4574 stackMax = stackDepth;
4577 bCodeStream[classFileOffset++] = OPC_new;
4578 } catch (IndexOutOfBoundsException e) {
4579 resizeByteArray(OPC_new);
4581 writeUnsignedShort(constantPool.literalIndexForJavaLangError());
4584 public void newJavaLangAssertionError() {
4585 // new: java.lang.AssertionError
4588 if (stackDepth > stackMax)
4589 stackMax = stackDepth;
4592 bCodeStream[classFileOffset++] = OPC_new;
4593 } catch (IndexOutOfBoundsException e) {
4594 resizeByteArray(OPC_new);
4596 writeUnsignedShort(constantPool.literalIndexForJavaLangAssertionError());
4599 public void newNoClassDefFoundError() { // new: java.lang.NoClassDefFoundError
4602 if (stackDepth > stackMax)
4603 stackMax = stackDepth;
4606 bCodeStream[classFileOffset++] = OPC_new;
4607 } catch (IndexOutOfBoundsException e) {
4608 resizeByteArray(OPC_new);
4610 writeUnsignedShort(constantPool.literalIndexForJavaLangNoClassDefFoundError());
4612 public void newStringBuffer() { // new: java.lang.StringBuffer
4615 if (stackDepth > stackMax)
4616 stackMax = stackDepth;
4619 bCodeStream[classFileOffset++] = OPC_new;
4620 } catch (IndexOutOfBoundsException e) {
4621 resizeByteArray(OPC_new);
4623 writeUnsignedShort(constantPool.literalIndexForJavaLangStringBuffer());
4625 public void newWrapperFor(int typeID) {
4628 if (stackDepth > stackMax)
4629 stackMax = stackDepth;
4632 bCodeStream[classFileOffset++] = OPC_new;
4633 } catch (IndexOutOfBoundsException e) {
4634 resizeByteArray(OPC_new);
4637 case T_int : // new: java.lang.Integer
4638 writeUnsignedShort(constantPool.literalIndexForJavaLangInteger());
4640 case T_boolean : // new: java.lang.Boolean
4641 writeUnsignedShort(constantPool.literalIndexForJavaLangBoolean());
4643 case T_byte : // new: java.lang.Byte
4644 writeUnsignedShort(constantPool.literalIndexForJavaLangByte());
4646 case T_char : // new: java.lang.Character
4647 writeUnsignedShort(constantPool.literalIndexForJavaLangCharacter());
4649 case T_float : // new: java.lang.Float
4650 writeUnsignedShort(constantPool.literalIndexForJavaLangFloat());
4652 case T_double : // new: java.lang.Double
4653 writeUnsignedShort(constantPool.literalIndexForJavaLangDouble());
4655 case T_short : // new: java.lang.Short
4656 writeUnsignedShort(constantPool.literalIndexForJavaLangShort());
4658 case T_long : // new: java.lang.Long
4659 writeUnsignedShort(constantPool.literalIndexForJavaLangLong());
4661 case T_void : // new: java.lang.Void
4662 writeUnsignedShort(constantPool.literalIndexForJavaLangVoid());
4665 final public void nop() {
4669 bCodeStream[classFileOffset++] = OPC_nop;
4670 } catch (IndexOutOfBoundsException e) {
4671 resizeByteArray(OPC_nop);
4674 final public void pop() {
4679 bCodeStream[classFileOffset++] = OPC_pop;
4680 } catch (IndexOutOfBoundsException e) {
4681 resizeByteArray(OPC_pop);
4684 final public void pop2() {
4689 bCodeStream[classFileOffset++] = OPC_pop2;
4690 } catch (IndexOutOfBoundsException e) {
4691 resizeByteArray(OPC_pop2);
4694 final public void putfield(FieldBinding fieldBinding) {
4697 if (((id = fieldBinding.type.id) == T_double) || (id == T_long))
4701 if (stackDepth > stackMax)
4702 stackMax = stackDepth;
4705 bCodeStream[classFileOffset++] = OPC_putfield;
4706 } catch (IndexOutOfBoundsException e) {
4707 resizeByteArray(OPC_putfield);
4709 writeUnsignedShort(constantPool.literalIndex(fieldBinding));
4711 final public void putstatic(FieldBinding fieldBinding) {
4714 if (((id = fieldBinding.type.id) == T_double) || (id == T_long))
4718 if (stackDepth > stackMax)
4719 stackMax = stackDepth;
4722 bCodeStream[classFileOffset++] = OPC_putstatic;
4723 } catch (IndexOutOfBoundsException e) {
4724 resizeByteArray(OPC_putstatic);
4726 writeUnsignedShort(constantPool.literalIndex(fieldBinding));
4728 public void record(LocalVariableBinding local) {
4729 if (!generateLocalVariableTableAttributes)
4731 if (allLocalsCounter == locals.length) {
4732 // resize the collection
4733 System.arraycopy(locals, 0, (locals = new LocalVariableBinding[allLocalsCounter + LOCALS_INCREMENT]), 0, allLocalsCounter);
4735 locals[allLocalsCounter++] = local;
4736 local.initializationPCs = new int[4];
4737 local.initializationCount = 0;
4739 public void recordPositionsFrom(int startPC, int sourcePos) {
4741 /* Record positions in the table, only if nothing has
4742 * already been recorded. Since we output them on the way
4743 * up (children first for more specific info)
4744 * The pcToSourceMap table is always sorted.
4747 if (!generateLineNumberAttributes)
4752 // no code generated for this node. e.g. field without any initialization
4753 if (position == startPC)
4756 // Widening an existing entry that already has the same source positions
4757 if (pcToSourceMapSize + 4 > pcToSourceMap.length) {
4758 // resize the array pcToSourceMap
4759 System.arraycopy(pcToSourceMap, 0, (pcToSourceMap = new int[pcToSourceMapSize << 1]), 0, pcToSourceMapSize);
4761 int newLine = ClassFile.searchLineNumber(lineSeparatorPositions, sourcePos);
4762 // lastEntryPC represents the endPC of the lastEntry.
4763 if (pcToSourceMapSize > 0) {
4764 // in this case there is already an entry in the table
4765 if (pcToSourceMap[pcToSourceMapSize - 1] != newLine) {
4766 if (startPC < lastEntryPC) {
4767 // we forgot to add an entry.
4768 // search if an existing entry exists for startPC
4769 int insertionIndex = insertionIndex(pcToSourceMap, pcToSourceMapSize, startPC);
4770 if (insertionIndex != -1) {
4771 // there is no existing entry starting with startPC.
4772 int existingEntryIndex = indexOfSameLineEntrySincePC(startPC, newLine); // index for PC
4773 /* the existingEntryIndex corresponds to en entry with the same line and a PC >= startPC.
4774 in this case it is relevant to widen this entry instead of creating a new one.
4778 with this code we generate each argument. We generate a aload0 to invoke the constructor. There is no entry for this
4779 aload0 bytecode. The first entry is the one for the argument a.
4780 But we want the constructor call to start at the aload0 pc and not just at the pc of the first argument.
4781 So we widen the existing entry (if there is one) or we create a new entry with the startPC.
4783 if (existingEntryIndex != -1) {
4784 // widen existing entry
4785 pcToSourceMap[existingEntryIndex] = startPC;
4787 // we have to add an entry that won't be sorted. So we sort the pcToSourceMap.
4793 pcToSourceMapSize - insertionIndex);
4794 pcToSourceMap[insertionIndex++] = startPC;
4795 pcToSourceMap[insertionIndex] = newLine;
4796 pcToSourceMapSize += 2;
4799 if (position != lastEntryPC) { // no bytecode since last entry pc
4800 pcToSourceMap[pcToSourceMapSize++] = lastEntryPC;
4801 pcToSourceMap[pcToSourceMapSize++] = newLine;
4804 // we can safely add the new entry. The endPC of the previous entry is not in conflit with the startPC of the new entry.
4805 pcToSourceMap[pcToSourceMapSize++] = startPC;
4806 pcToSourceMap[pcToSourceMapSize++] = newLine;
4809 /* the last recorded entry is on the same line. But it could be relevant to widen this entry.
4810 we want to extend this entry forward in case we generated some bytecode before the last entry that are not related to any statement
4812 if (startPC < pcToSourceMap[pcToSourceMapSize - 2]) {
4813 int insertionIndex = insertionIndex(pcToSourceMap, pcToSourceMapSize, startPC);
4814 if (insertionIndex != -1) {
4815 // widen the existing entry
4816 // we have to figure out if we need to move the last entry at another location to keep a sorted table
4817 if ((pcToSourceMapSize > 4) && (pcToSourceMap[pcToSourceMapSize - 4] > startPC)) {
4823 pcToSourceMapSize - 2 - insertionIndex);
4824 pcToSourceMap[insertionIndex++] = startPC;
4825 pcToSourceMap[insertionIndex] = newLine;
4827 pcToSourceMap[pcToSourceMapSize - 2] = startPC;
4832 lastEntryPC = position;
4834 // record the first entry
4835 pcToSourceMap[pcToSourceMapSize++] = startPC;
4836 pcToSourceMap[pcToSourceMapSize++] = newLine;
4837 lastEntryPC = position;
4841 * @param anExceptionLabel org.eclipse.jdt.internal.compiler.codegen.ExceptionLabel
4843 public void registerExceptionHandler(ExceptionLabel anExceptionLabel) {
4845 if (exceptionHandlersNumber >= (length = exceptionHandlers.length)) {
4846 // resize the exception handlers table
4847 System.arraycopy(exceptionHandlers, 0, exceptionHandlers = new ExceptionLabel[length + LABELS_INCREMENT], 0, length);
4849 // no need to resize. So just add the new exception label
4850 exceptionHandlers[exceptionHandlersNumber++] = anExceptionLabel;
4852 public final void removeNotDefinitelyAssignedVariables(Scope scope, int initStateIndex) {
4853 // given some flow info, make sure we did not loose some variables initialization
4854 // if this happens, then we must update their pc entries to reflect it in debug attributes
4855 if (!generateLocalVariableTableAttributes)
4857 /* if (initStateIndex == lastInitStateIndexWhenRemovingInits)
4860 lastInitStateIndexWhenRemovingInits = initStateIndex;
4861 if (lastInitStateIndexWhenAddingInits != initStateIndex){
4862 lastInitStateIndexWhenAddingInits = -2;// reinitialize add index
4863 // add(1)-remove(1)-add(1) -> ignore second add
4864 // add(1)-remove(2)-add(1) -> perform second add
4866 for (int i = 0; i < visibleLocalsCount; i++) {
4867 LocalVariableBinding localBinding = visibleLocals[i];
4868 if (localBinding != null) {
4869 if (initStateIndex == -1 || !isDefinitelyAssigned(scope, initStateIndex, localBinding)) {
4870 if (localBinding.initializationCount > 0) {
4871 localBinding.recordInitializationEndPC(position);
4878 * @param methodDeclaration org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration
4879 * @param classFile org.eclipse.jdt.internal.compiler.codegen.ClassFile
4881 public void reset(AbstractMethodDeclaration methodDeclaration, ClassFile classFile) {
4883 this.methodDeclaration = methodDeclaration;
4884 preserveUnusedLocals = methodDeclaration.scope.problemReporter().options.preserveAllLocalVariables;
4885 initializeMaxLocals(methodDeclaration.binding);
4888 * @param methodDeclaration org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration
4889 * @param classFile org.eclipse.jdt.internal.compiler.codegen.ClassFile
4891 public void resetForProblemClinit(ClassFile classFile) {
4895 protected final void resizeByteArray() {
4896 int actualLength = bCodeStream.length;
4897 int requiredSize = actualLength + growFactor;
4898 if (classFileOffset > requiredSize) {
4899 requiredSize = classFileOffset + growFactor;
4901 System.arraycopy(bCodeStream, 0, (bCodeStream = new byte[requiredSize]), 0, actualLength);
4904 * This method is used to resize the internal byte array in
4905 * case of a ArrayOutOfBoundsException when adding the value b.
4906 * Resize and add the new byte b inside the array.
4909 protected final void resizeByteArray(byte b) {
4911 bCodeStream[classFileOffset - 1] = b;
4913 final public void ret(int index) {
4915 if (index > 255) { // Widen
4918 bCodeStream[classFileOffset++] = OPC_wide;
4919 } catch (IndexOutOfBoundsException e) {
4920 resizeByteArray(OPC_wide);
4924 bCodeStream[classFileOffset++] = OPC_ret;
4925 } catch (IndexOutOfBoundsException e) {
4926 resizeByteArray(OPC_ret);
4928 writeUnsignedShort(index);
4929 } else { // Don't Widen
4932 bCodeStream[classFileOffset++] = OPC_ret;
4933 } catch (IndexOutOfBoundsException e) {
4934 resizeByteArray(OPC_ret);
4938 bCodeStream[classFileOffset++] = (byte) index;
4939 } catch (IndexOutOfBoundsException e) {
4940 resizeByteArray((byte) index);
4944 final public void return_() {
4946 // the stackDepth should be equal to 0
4949 bCodeStream[classFileOffset++] = OPC_return;
4950 } catch (IndexOutOfBoundsException e) {
4951 resizeByteArray(OPC_return);
4954 final public void saload() {
4959 bCodeStream[classFileOffset++] = OPC_saload;
4960 } catch (IndexOutOfBoundsException e) {
4961 resizeByteArray(OPC_saload);
4964 final public void sastore() {
4969 bCodeStream[classFileOffset++] = OPC_sastore;
4970 } catch (IndexOutOfBoundsException e) {
4971 resizeByteArray(OPC_sastore);
4975 * @param operatorConstant int
4976 * @param type_ID int
4978 public void sendOperator(int operatorConstant, int type_ID) {
4985 switch (operatorConstant) {
5007 case UNSIGNED_RIGHT_SHIFT :
5022 switch (operatorConstant) {
5044 case UNSIGNED_RIGHT_SHIFT :
5059 switch (operatorConstant) {
5077 switch (operatorConstant) {
5095 final public void sipush(int s) {
5098 if (stackDepth > stackMax)
5099 stackMax = stackDepth;
5102 bCodeStream[classFileOffset++] = OPC_sipush;
5103 } catch (IndexOutOfBoundsException e) {
5104 resizeByteArray(OPC_sipush);
5106 writeSignedShort(s);
5108 public static final void sort(int[] tab, int lo0, int hi0, int[] result) {
5113 /* Arbitrarily establishing partition element as the midpoint of
5116 mid = tab[(lo0 + hi0) / 2];
5117 // loop through the array until indices cross
5119 /* find the first element that is greater than or equal to
5120 * the partition element starting from the left Index.
5122 while ((lo < hi0) && (tab[lo] < mid))
5124 /* find an element that is smaller than or equal to
5125 * the partition element starting from the right Index.
5127 while ((hi > lo0) && (tab[hi] > mid))
5129 // if the indexes have not crossed, swap
5131 swap(tab, lo, hi, result);
5136 /* If the right index has not reached the left side of array
5137 * must now sort the left partition.
5140 sort(tab, lo0, hi, result);
5141 /* If the left index has not reached the right side of array
5142 * must now sort the right partition.
5145 sort(tab, lo, hi0, result);
5148 public final void store(LocalVariableBinding localBinding, boolean valueRequired) {
5149 TypeBinding type = localBinding.type;
5150 int position = localBinding.resolvedPosition;
5151 // Using dedicated int bytecode
5152 if ((type == IntBinding)
5153 || (type == CharBinding)
5154 || (type == ByteBinding)
5155 || (type == ShortBinding)
5156 || (type == BooleanBinding)) {
5173 this.istore(position);
5177 // Using dedicated float bytecode
5178 if (type == FloatBinding) {
5195 this.fstore(position);
5199 // Using dedicated long bytecode
5200 if (type == LongBinding) {
5217 this.lstore(position);
5221 // Using dedicated double bytecode
5222 if (type == DoubleBinding) {
5239 this.dstore(position);
5260 this.astore(position);
5263 public final void store(TypeBinding type, int position) {
5264 // Using dedicated int bytecode
5265 if ((type == IntBinding)
5266 || (type == CharBinding)
5267 || (type == ByteBinding)
5268 || (type == ShortBinding)
5269 || (type == BooleanBinding)) {
5284 this.istore(position);
5288 // Using dedicated float bytecode
5289 if (type == FloatBinding) {
5304 this.fstore(position);
5308 // Using dedicated long bytecode
5309 if (type == LongBinding) {
5324 this.lstore(position);
5328 // Using dedicated double bytecode
5329 if (type == DoubleBinding) {
5344 this.dstore(position);
5363 this.astore(position);
5366 public final void storeInt(int position) {
5381 this.istore(position);
5384 public final void storeObject(int position) {
5399 this.astore(position);
5402 final public void swap() {
5406 bCodeStream[classFileOffset++] = OPC_swap;
5407 } catch (IndexOutOfBoundsException e) {
5408 resizeByteArray(OPC_swap);
5411 private static final void swap(int a[], int i, int j, int result[]) {
5417 result[j] = result[i];
5420 final public void tableswitch(
5421 CaseLabel defaultLabel,
5425 int[] sortedIndexes,
5426 CaseLabel[] casesLabel) {
5429 int length = casesLabel.length;
5431 defaultLabel.placeInstruction();
5432 for (int i = 0; i < length; i++)
5433 casesLabel[i].placeInstruction();
5436 bCodeStream[classFileOffset++] = OPC_tableswitch;
5437 } catch (IndexOutOfBoundsException e) {
5438 resizeByteArray(OPC_tableswitch);
5440 for (int i = (3 - (pos % 4)); i > 0; i--) {
5441 position++; // Padding
5444 defaultLabel.branch();
5445 writeSignedWord(low);
5446 writeSignedWord(high);
5447 int i = low, j = low;
5448 // the index j is used to know if the index i is one of the missing entries in case of an
5449 // optimized tableswitch
5452 int key = keys[index = sortedIndexes[j - low]];
5454 casesLabel[index].branch();
5457 break; // if high is maxint, then avoids wrapping to minint.
5459 defaultLabel.branch();
5464 public String toString() {
5465 StringBuffer buffer = new StringBuffer("( position:"); //$NON-NLS-1$
5466 buffer.append(position);
5467 buffer.append(",\nstackDepth:"); //$NON-NLS-1$
5468 buffer.append(stackDepth);
5469 buffer.append(",\nmaxStack:"); //$NON-NLS-1$
5470 buffer.append(stackMax);
5471 buffer.append(",\nmaxLocals:"); //$NON-NLS-1$
5472 buffer.append(maxLocals);
5473 buffer.append(")"); //$NON-NLS-1$
5474 return buffer.toString();
5476 public void updateLastRecordedEndPC(int pos) {
5478 /* Tune positions in the table, this is due to some
5479 * extra bytecodes being
5480 * added to some user code (jumps). */
5482 if (!generateLineNumberAttributes)
5484 pcToSourceMap[pcToSourceMapSize - 1][1] = position;
5485 // need to update the initialization endPC in case of generation of local variable attributes.
5486 updateLocalVariablesAttribute(pos);
5489 if (!generateLineNumberAttributes)
5491 // need to update the initialization endPC in case of generation of local variable attributes.
5492 updateLocalVariablesAttribute(pos);
5494 public void updateLocalVariablesAttribute(int pos) {
5495 // need to update the initialization endPC in case of generation of local variable attributes.
5496 if (generateLocalVariableTableAttributes) {
5497 for (int i = 0, max = locals.length; i < max; i++) {
5498 LocalVariableBinding local = locals[i];
5499 if ((local != null) && (local.initializationCount > 0)) {
5500 if (local.initializationPCs[((local.initializationCount - 1) << 1) + 1] == pos) {
5501 local.initializationPCs[((local.initializationCount - 1) << 1) + 1] = position;
5507 final public void wide() {
5511 bCodeStream[classFileOffset++] = OPC_wide;
5512 } catch (IndexOutOfBoundsException e) {
5513 resizeByteArray(OPC_wide);
5516 public final void writeByte(byte b) {
5519 bCodeStream[classFileOffset++] = b;
5520 } catch (IndexOutOfBoundsException e) {
5524 public final void writeByteAtPos(int pos, byte b) {
5526 bCodeStream[pos] = b;
5527 } catch (IndexOutOfBoundsException ex) {
5529 bCodeStream[pos] = b;
5533 * Write a unsigned 8 bits value into the byte array
5534 * @param b the signed byte
5536 public final void writeSignedByte(int b) {
5539 bCodeStream[classFileOffset++] = (byte) b;
5540 } catch (IndexOutOfBoundsException e) {
5541 resizeByteArray((byte) b);
5545 * Write a signed 16 bits value into the byte array
5546 * @param b the signed short
5548 public final void writeSignedShort(int b) {
5551 bCodeStream[classFileOffset++] = (byte) (b >> 8);
5552 } catch (IndexOutOfBoundsException e) {
5553 resizeByteArray((byte) (b >> 8));
5557 bCodeStream[classFileOffset++] = (byte) b;
5558 } catch (IndexOutOfBoundsException e) {
5559 resizeByteArray((byte) b);
5562 public final void writeSignedShort(int pos, int b) {
5563 int currentOffset = startingClassFileOffset + pos;
5565 bCodeStream[currentOffset] = (byte) (b >> 8);
5566 } catch (IndexOutOfBoundsException e) {
5568 bCodeStream[currentOffset] = (byte) (b >> 8);
5571 bCodeStream[currentOffset + 1] = (byte) b;
5572 } catch (IndexOutOfBoundsException e) {
5574 bCodeStream[currentOffset + 1] = (byte) b;
5577 public final void writeSignedWord(int value) {
5580 bCodeStream[classFileOffset++] = (byte) ((value & 0xFF000000) >> 24);
5581 } catch (IndexOutOfBoundsException e) {
5582 resizeByteArray((byte) ((value & 0xFF000000) >> 24));
5586 bCodeStream[classFileOffset++] = (byte) ((value & 0xFF0000) >> 16);
5587 } catch (IndexOutOfBoundsException e) {
5588 resizeByteArray((byte) ((value & 0xFF0000) >> 16));
5592 bCodeStream[classFileOffset++] = (byte) ((value & 0xFF00) >> 8);
5593 } catch (IndexOutOfBoundsException e) {
5594 resizeByteArray((byte) ((value & 0xFF00) >> 8));
5598 bCodeStream[classFileOffset++] = (byte) (value & 0xFF);
5599 } catch (IndexOutOfBoundsException e) {
5600 resizeByteArray((byte) (value & 0xFF));
5603 public final void writeSignedWord(int pos, int value) {
5604 int currentOffset = startingClassFileOffset + pos;
5606 bCodeStream[currentOffset++] = (byte) ((value & 0xFF000000) >> 24);
5607 } catch (IndexOutOfBoundsException e) {
5609 bCodeStream[currentOffset - 1] = (byte) ((value & 0xFF000000) >> 24);
5612 bCodeStream[currentOffset++] = (byte) ((value & 0xFF0000) >> 16);
5613 } catch (IndexOutOfBoundsException e) {
5615 bCodeStream[currentOffset - 1] = (byte) ((value & 0xFF0000) >> 16);
5618 bCodeStream[currentOffset++] = (byte) ((value & 0xFF00) >> 8);
5619 } catch (IndexOutOfBoundsException e) {
5621 bCodeStream[currentOffset - 1] = (byte) ((value & 0xFF00) >> 8);
5624 bCodeStream[currentOffset++] = (byte) (value & 0xFF);
5625 } catch (IndexOutOfBoundsException e) {
5627 bCodeStream[currentOffset - 1] = (byte) (value & 0xFF);
5631 * Write a unsigned 8 bits value into the byte array
5632 * @param b the unsigned byte
5634 public final void writeUnsignedByte(int b) {
5637 bCodeStream[classFileOffset++] = (byte) b;
5638 } catch (IndexOutOfBoundsException e) {
5639 resizeByteArray((byte) b);
5643 * Write a unsigned 16 bits value into the byte array
5644 * @param b the unsigned short
5646 public final void writeUnsignedShort(int b) {
5649 bCodeStream[classFileOffset++] = (byte) (b >>> 8);
5650 } catch (IndexOutOfBoundsException e) {
5651 resizeByteArray((byte) (b >>> 8));
5655 bCodeStream[classFileOffset++] = (byte) b;
5656 } catch (IndexOutOfBoundsException e) {
5657 resizeByteArray((byte) b);
5661 * Write a unsigned 32 bits value into the byte array
5662 * @param value the unsigned word
5664 public final void writeUnsignedWord(int value) {
5667 bCodeStream[classFileOffset++] = (byte) (value >>> 24);
5668 } catch (IndexOutOfBoundsException e) {
5669 resizeByteArray((byte) (value >>> 24));
5673 bCodeStream[classFileOffset++] = (byte) (value >>> 16);
5674 } catch (IndexOutOfBoundsException e) {
5675 resizeByteArray((byte) (value >>> 16));
5679 bCodeStream[classFileOffset++] = (byte) (value >>> 8);
5680 } catch (IndexOutOfBoundsException e) {
5681 resizeByteArray((byte) (value >>> 8));
5685 bCodeStream[classFileOffset++] = (byte) value;
5686 } catch (IndexOutOfBoundsException e) {
5687 resizeByteArray((byte) value);
5691 public void generateWideConditionalBranch(byte opcode, Label lbl) {
5692 /* we handle the goto_w problem inside an if.... with some macro expansion
5693 * at the bytecode level
5699 * l1 gotow <l3> // l3 is a wide target
5702 Label l1 = new Label(this);
5705 bCodeStream[classFileOffset++] = opcode;
5706 } catch (IndexOutOfBoundsException e) {
5707 resizeByteArray(opcode);
5710 Label l2 = new Label(this);
5711 this.internal_goto_(l2);