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; // The constant pool used to generate bytecodes that need to store information into the constant pool
41 public ClassFile classFile; // The current classfile it is associated to.
42 // local variable attributes output
43 public static final int LOCALS_INCREMENT = 10;
44 public LocalVariableBinding[] locals = new LocalVariableBinding[LOCALS_INCREMENT];
45 static LocalVariableBinding[] noLocals = new LocalVariableBinding[LOCALS_INCREMENT];
46 public LocalVariableBinding[] visibleLocals = new LocalVariableBinding[LOCALS_INCREMENT];
47 static LocalVariableBinding[] noVisibleLocals = new LocalVariableBinding[LOCALS_INCREMENT];
48 int visibleLocalsCount;
49 public AbstractMethodDeclaration methodDeclaration;
50 public ExceptionLabel[] exceptionHandlers = new ExceptionLabel[LABELS_INCREMENT];
51 static ExceptionLabel[] noExceptionHandlers = new ExceptionLabel[LABELS_INCREMENT];
52 public int exceptionHandlersNumber;
53 public static FieldBinding[] ImplicitThis = new FieldBinding[] {};
54 public boolean generateLineNumberAttributes;
55 public boolean generateLocalVariableTableAttributes;
56 public boolean preserveUnusedLocals;
57 // store all the labels placed at the current position to be able to optimize
58 // a jump to the next bytecode.
59 public Label[] labels = new Label[LABELS_INCREMENT];
60 static Label[] noLabels = new Label[LABELS_INCREMENT];
61 public int countLabels;
62 public int allLocalsCounter;
63 public int maxFieldCount;
65 public boolean wideMode = false;
66 public static final CompilationResult RESTART_IN_WIDE_MODE = new CompilationResult((char[])null, 0, 0, 0);
68 public CodeStream(ClassFile classFile) {
69 generateLineNumberAttributes = (classFile.produceDebugAttributes & CompilerOptions.Lines) != 0;
70 generateLocalVariableTableAttributes = (classFile.produceDebugAttributes & CompilerOptions.Vars) != 0;
71 if (generateLineNumberAttributes) {
72 lineSeparatorPositions = classFile.referenceBinding.scope.referenceCompilationUnit().compilationResult.lineSeparatorPositions;
75 final public void aaload() {
80 bCodeStream[classFileOffset++] = OPC_aaload;
81 } catch (IndexOutOfBoundsException e) {
82 resizeByteArray(OPC_aaload);
85 final public void aastore() {
90 bCodeStream[classFileOffset++] = OPC_aastore;
91 } catch (IndexOutOfBoundsException e) {
92 resizeByteArray(OPC_aastore);
95 final public void aconst_null() {
98 if (stackDepth > stackMax)
99 stackMax = stackDepth;
102 bCodeStream[classFileOffset++] = OPC_aconst_null;
103 } catch (IndexOutOfBoundsException e) {
104 resizeByteArray(OPC_aconst_null);
107 public final void addDefinitelyAssignedVariables(Scope scope, int initStateIndex) {
108 // Required to fix 1PR0XVS: LFRE:WINNT - Compiler: variable table for method appears incorrect
109 if (!generateLocalVariableTableAttributes)
111 /* if (initStateIndex == lastInitStateIndexWhenAddingInits)
113 lastInitStateIndexWhenAddingInits = initStateIndex;
114 if (lastInitStateIndexWhenRemovingInits != initStateIndex){
115 lastInitStateIndexWhenRemovingInits = -2; // reinitialize remove index
116 // remove(1)-add(1)-remove(1) -> ignore second remove
117 // remove(1)-add(2)-remove(1) -> perform second remove
120 */ for (int i = 0; i < visibleLocalsCount; i++) {
121 LocalVariableBinding localBinding = visibleLocals[i];
122 if (localBinding != null) {
123 // Check if the local is definitely assigned
124 if ((initStateIndex != -1) && isDefinitelyAssigned(scope, initStateIndex, localBinding)) {
125 if ((localBinding.initializationCount == 0) || (localBinding.initializationPCs[((localBinding.initializationCount - 1) << 1) + 1] != -1)) {
126 /* There are two cases:
127 * 1) there is no initialization interval opened ==> add an opened interval
128 * 2) there is already some initialization intervals but the last one is closed ==> add an opened interval
129 * An opened interval means that the value at localBinding.initializationPCs[localBinding.initializationCount - 1][1]
131 * initializationPCs is a collection of pairs of int:
132 * first value is the startPC and second value is the endPC. -1 one for the last value means that the interval
135 localBinding.recordInitializationStartPC(position);
141 public void addLabel(Label aLabel) {
142 if (countLabels == labels.length)
143 System.arraycopy(labels, 0, (labels = new Label[countLabels + LABELS_INCREMENT]), 0, countLabels);
144 labels[countLabels++] = aLabel;
146 public void addVisibleLocalVariable(LocalVariableBinding localBinding) {
147 if (!generateLocalVariableTableAttributes)
150 if (visibleLocalsCount >= visibleLocals.length) {
151 System.arraycopy(visibleLocals, 0, (visibleLocals = new LocalVariableBinding[visibleLocalsCount * 2]), 0, visibleLocalsCount);
153 visibleLocals[visibleLocalsCount++] = localBinding;
155 final public void aload(int iArg) {
158 if (stackDepth > stackMax)
159 stackMax = stackDepth;
160 if (maxLocals <= iArg) {
161 maxLocals = iArg + 1;
163 if (iArg > 255) { // Widen
166 bCodeStream[classFileOffset++] = OPC_wide;
167 } catch (IndexOutOfBoundsException e) {
168 resizeByteArray(OPC_wide);
172 bCodeStream[classFileOffset++] = OPC_aload;
173 } catch (IndexOutOfBoundsException e) {
174 resizeByteArray(OPC_aload);
176 writeUnsignedShort(iArg);
178 // Don't need to use the wide bytecode
181 bCodeStream[classFileOffset++] = OPC_aload;
182 } catch (IndexOutOfBoundsException e) {
183 resizeByteArray(OPC_aload);
187 bCodeStream[classFileOffset++] = (byte) (iArg);
188 } catch (IndexOutOfBoundsException e) {
189 resizeByteArray((byte) iArg);
193 final public void aload_0() {
196 if (stackDepth > stackMax)
197 stackMax = stackDepth;
198 if (maxLocals == 0) {
203 bCodeStream[classFileOffset++] = OPC_aload_0;
204 } catch (IndexOutOfBoundsException e) {
205 resizeByteArray(OPC_aload_0);
208 final public void aload_1() {
211 if (stackDepth > stackMax)
212 stackMax = stackDepth;
213 if (maxLocals <= 1) {
218 bCodeStream[classFileOffset++] = OPC_aload_1;
219 } catch (IndexOutOfBoundsException e) {
220 resizeByteArray(OPC_aload_1);
223 final public void aload_2() {
226 if (stackDepth > stackMax)
227 stackMax = stackDepth;
228 if (maxLocals <= 2) {
233 bCodeStream[classFileOffset++] = OPC_aload_2;
234 } catch (IndexOutOfBoundsException e) {
235 resizeByteArray(OPC_aload_2);
238 final public void aload_3() {
241 if (stackDepth > stackMax)
242 stackMax = stackDepth;
243 if (maxLocals <= 3) {
248 bCodeStream[classFileOffset++] = OPC_aload_3;
249 } catch (IndexOutOfBoundsException e) {
250 resizeByteArray(OPC_aload_3);
253 public final void anewarray(TypeBinding typeBinding) {
257 bCodeStream[classFileOffset++] = OPC_anewarray;
258 } catch (IndexOutOfBoundsException e) {
259 resizeByteArray(OPC_anewarray);
261 writeUnsignedShort(constantPool.literalIndex(typeBinding));
263 public void anewarrayJavaLangClass() {
264 // anewarray: java.lang.Class
268 bCodeStream[classFileOffset++] = OPC_anewarray;
269 } catch (IndexOutOfBoundsException e) {
270 resizeByteArray(OPC_anewarray);
272 writeUnsignedShort(constantPool.literalIndexForJavaLangClass());
274 public void anewarrayJavaLangObject() {
275 // anewarray: java.lang.Object
279 bCodeStream[classFileOffset++] = OPC_anewarray;
280 } catch (IndexOutOfBoundsException e) {
281 resizeByteArray(OPC_anewarray);
283 writeUnsignedShort(constantPool.literalIndexForJavaLangObject());
285 final public void areturn() {
288 // the stackDepth should be equal to 0
291 bCodeStream[classFileOffset++] = OPC_areturn;
292 } catch (IndexOutOfBoundsException e) {
293 resizeByteArray(OPC_areturn);
296 public void arrayAt(int typeBindingID) {
297 switch (typeBindingID) {
324 public void arrayAtPut(int elementTypeID, boolean valueRequired) {
325 switch (elementTypeID) {
368 final public void arraylength() {
372 bCodeStream[classFileOffset++] = OPC_arraylength;
373 } catch (IndexOutOfBoundsException e) {
374 resizeByteArray(OPC_arraylength);
377 final public void astore(int iArg) {
380 if (maxLocals <= iArg) {
381 maxLocals = iArg + 1;
383 if (iArg > 255) { // Widen
386 bCodeStream[classFileOffset++] = OPC_wide;
387 } catch (IndexOutOfBoundsException e) {
388 resizeByteArray(OPC_wide);
392 bCodeStream[classFileOffset++] = OPC_astore;
393 } catch (IndexOutOfBoundsException e) {
394 resizeByteArray(OPC_astore);
396 writeUnsignedShort(iArg);
400 bCodeStream[classFileOffset++] = OPC_astore;
401 } catch (IndexOutOfBoundsException e) {
402 resizeByteArray(OPC_astore);
406 bCodeStream[classFileOffset++] = (byte) iArg;
407 } catch (IndexOutOfBoundsException e) {
408 resizeByteArray((byte) iArg);
412 final public void astore_0() {
415 if (maxLocals == 0) {
420 bCodeStream[classFileOffset++] = OPC_astore_0;
421 } catch (IndexOutOfBoundsException e) {
422 resizeByteArray(OPC_astore_0);
425 final public void astore_1() {
428 if (maxLocals <= 1) {
433 bCodeStream[classFileOffset++] = OPC_astore_1;
434 } catch (IndexOutOfBoundsException e) {
435 resizeByteArray(OPC_astore_1);
438 final public void astore_2() {
441 if (maxLocals <= 2) {
446 bCodeStream[classFileOffset++] = OPC_astore_2;
447 } catch (IndexOutOfBoundsException e) {
448 resizeByteArray(OPC_astore_2);
451 final public void astore_3() {
454 if (maxLocals <= 3) {
459 bCodeStream[classFileOffset++] = OPC_astore_3;
460 } catch (IndexOutOfBoundsException e) {
461 resizeByteArray(OPC_astore_3);
464 final public void athrow() {
469 bCodeStream[classFileOffset++] = OPC_athrow;
470 } catch (IndexOutOfBoundsException e) {
471 resizeByteArray(OPC_athrow);
474 final public void baload() {
479 bCodeStream[classFileOffset++] = OPC_baload;
480 } catch (IndexOutOfBoundsException e) {
481 resizeByteArray(OPC_baload);
484 final public void bastore() {
489 bCodeStream[classFileOffset++] = OPC_bastore;
490 } catch (IndexOutOfBoundsException e) {
491 resizeByteArray(OPC_bastore);
494 final public void bipush(byte b) {
497 if (stackDepth > stackMax)
498 stackMax = stackDepth;
501 bCodeStream[classFileOffset++] = OPC_bipush;
502 } catch (IndexOutOfBoundsException e) {
503 resizeByteArray(OPC_bipush);
507 final public void caload() {
512 bCodeStream[classFileOffset++] = OPC_caload;
513 } catch (IndexOutOfBoundsException e) {
514 resizeByteArray(OPC_caload);
517 final public void castore() {
522 bCodeStream[classFileOffset++] = OPC_castore;
523 } catch (IndexOutOfBoundsException e) {
524 resizeByteArray(OPC_castore);
527 public final void checkcast(TypeBinding typeBinding) {
531 bCodeStream[classFileOffset++] = OPC_checkcast;
532 } catch (IndexOutOfBoundsException e) {
533 resizeByteArray(OPC_checkcast);
535 writeUnsignedShort(constantPool.literalIndex(typeBinding));
537 public final void checkcastJavaLangError() {
541 bCodeStream[classFileOffset++] = OPC_checkcast;
542 } catch (IndexOutOfBoundsException e) {
543 resizeByteArray(OPC_checkcast);
545 writeUnsignedShort(constantPool.literalIndexForJavaLangError());
547 final public void d2f() {
552 bCodeStream[classFileOffset++] = OPC_d2f;
553 } catch (IndexOutOfBoundsException e) {
554 resizeByteArray(OPC_d2f);
557 final public void d2i() {
562 bCodeStream[classFileOffset++] = OPC_d2i;
563 } catch (IndexOutOfBoundsException e) {
564 resizeByteArray(OPC_d2i);
567 final public void d2l() {
571 bCodeStream[classFileOffset++] = OPC_d2l;
572 } catch (IndexOutOfBoundsException e) {
573 resizeByteArray(OPC_d2l);
576 final public void dadd() {
581 bCodeStream[classFileOffset++] = OPC_dadd;
582 } catch (IndexOutOfBoundsException e) {
583 resizeByteArray(OPC_dadd);
586 final public void daload() {
590 bCodeStream[classFileOffset++] = OPC_daload;
591 } catch (IndexOutOfBoundsException e) {
592 resizeByteArray(OPC_daload);
595 final public void dastore() {
600 bCodeStream[classFileOffset++] = OPC_dastore;
601 } catch (IndexOutOfBoundsException e) {
602 resizeByteArray(OPC_dastore);
605 final public void dcmpg() {
610 bCodeStream[classFileOffset++] = OPC_dcmpg;
611 } catch (IndexOutOfBoundsException e) {
612 resizeByteArray(OPC_dcmpg);
615 final public void dcmpl() {
620 bCodeStream[classFileOffset++] = OPC_dcmpl;
621 } catch (IndexOutOfBoundsException e) {
622 resizeByteArray(OPC_dcmpl);
625 final public void dconst_0() {
628 if (stackDepth > stackMax)
629 stackMax = stackDepth;
632 bCodeStream[classFileOffset++] = OPC_dconst_0;
633 } catch (IndexOutOfBoundsException e) {
634 resizeByteArray(OPC_dconst_0);
637 final public void dconst_1() {
640 if (stackDepth > stackMax)
641 stackMax = stackDepth;
644 bCodeStream[classFileOffset++] = OPC_dconst_1;
645 } catch (IndexOutOfBoundsException e) {
646 resizeByteArray(OPC_dconst_1);
649 final public void ddiv() {
654 bCodeStream[classFileOffset++] = OPC_ddiv;
655 } catch (IndexOutOfBoundsException e) {
656 resizeByteArray(OPC_ddiv);
659 public void decrStackSize(int offset) {
660 stackDepth -= offset;
662 final public void dload(int iArg) {
665 if (stackDepth > stackMax)
666 stackMax = stackDepth;
667 if (maxLocals < iArg + 2) {
668 maxLocals = iArg + 2; // + 2 because it is a double
670 if (iArg > 255) { // Widen
673 bCodeStream[classFileOffset++] = OPC_wide;
674 } catch (IndexOutOfBoundsException e) {
675 resizeByteArray(OPC_wide);
679 bCodeStream[classFileOffset++] = OPC_dload;
680 } catch (IndexOutOfBoundsException e) {
681 resizeByteArray(OPC_dload);
683 writeUnsignedShort(iArg);
685 // Don't need to use the wide bytecode
688 bCodeStream[classFileOffset++] = OPC_dload;
689 } catch (IndexOutOfBoundsException e) {
690 resizeByteArray(OPC_dload);
694 bCodeStream[classFileOffset++] = (byte) iArg;
695 } catch (IndexOutOfBoundsException e) {
696 resizeByteArray((byte) iArg);
700 final public void dload_0() {
703 if (stackDepth > stackMax)
704 stackMax = stackDepth;
710 bCodeStream[classFileOffset++] = OPC_dload_0;
711 } catch (IndexOutOfBoundsException e) {
712 resizeByteArray(OPC_dload_0);
715 final public void dload_1() {
718 if (stackDepth > stackMax)
719 stackMax = stackDepth;
725 bCodeStream[classFileOffset++] = OPC_dload_1;
726 } catch (IndexOutOfBoundsException e) {
727 resizeByteArray(OPC_dload_1);
730 final public void dload_2() {
733 if (stackDepth > stackMax)
734 stackMax = stackDepth;
740 bCodeStream[classFileOffset++] = OPC_dload_2;
741 } catch (IndexOutOfBoundsException e) {
742 resizeByteArray(OPC_dload_2);
745 final public void dload_3() {
748 if (stackDepth > stackMax)
749 stackMax = stackDepth;
755 bCodeStream[classFileOffset++] = OPC_dload_3;
756 } catch (IndexOutOfBoundsException e) {
757 resizeByteArray(OPC_dload_3);
760 final public void dmul() {
765 bCodeStream[classFileOffset++] = OPC_dmul;
766 } catch (IndexOutOfBoundsException e) {
767 resizeByteArray(OPC_dmul);
770 final public void dneg() {
774 bCodeStream[classFileOffset++] = OPC_dneg;
775 } catch (IndexOutOfBoundsException e) {
776 resizeByteArray(OPC_dneg);
779 final public void drem() {
784 bCodeStream[classFileOffset++] = OPC_drem;
785 } catch (IndexOutOfBoundsException e) {
786 resizeByteArray(OPC_drem);
789 final public void dreturn() {
792 // the stackDepth should be equal to 0
795 bCodeStream[classFileOffset++] = OPC_dreturn;
796 } catch (IndexOutOfBoundsException e) {
797 resizeByteArray(OPC_dreturn);
800 final public void dstore(int iArg) {
803 if (maxLocals <= iArg + 1) {
804 maxLocals = iArg + 2;
806 if (iArg > 255) { // Widen
809 bCodeStream[classFileOffset++] = OPC_wide;
810 } catch (IndexOutOfBoundsException e) {
811 resizeByteArray(OPC_wide);
815 bCodeStream[classFileOffset++] = OPC_dstore;
816 } catch (IndexOutOfBoundsException e) {
817 resizeByteArray(OPC_dstore);
819 writeUnsignedShort(iArg);
823 bCodeStream[classFileOffset++] = OPC_dstore;
824 } catch (IndexOutOfBoundsException e) {
825 resizeByteArray(OPC_dstore);
829 bCodeStream[classFileOffset++] = (byte) iArg;
830 } catch (IndexOutOfBoundsException e) {
831 resizeByteArray((byte) iArg);
835 final public void dstore_0() {
843 bCodeStream[classFileOffset++] = OPC_dstore_0;
844 } catch (IndexOutOfBoundsException e) {
845 resizeByteArray(OPC_dstore_0);
848 final public void dstore_1() {
856 bCodeStream[classFileOffset++] = OPC_dstore_1;
857 } catch (IndexOutOfBoundsException e) {
858 resizeByteArray(OPC_dstore_1);
861 final public void dstore_2() {
869 bCodeStream[classFileOffset++] = OPC_dstore_2;
870 } catch (IndexOutOfBoundsException e) {
871 resizeByteArray(OPC_dstore_2);
874 final public void dstore_3() {
882 bCodeStream[classFileOffset++] = OPC_dstore_3;
883 } catch (IndexOutOfBoundsException e) {
884 resizeByteArray(OPC_dstore_3);
887 final public void dsub() {
892 bCodeStream[classFileOffset++] = OPC_dsub;
893 } catch (IndexOutOfBoundsException e) {
894 resizeByteArray(OPC_dsub);
897 final public void dup() {
900 if (stackDepth > stackMax)
901 stackMax = stackDepth;
904 bCodeStream[classFileOffset++] = OPC_dup;
905 } catch (IndexOutOfBoundsException e) {
906 resizeByteArray(OPC_dup);
909 final public void dup_x1() {
912 if (stackDepth > stackMax)
913 stackMax = stackDepth;
916 bCodeStream[classFileOffset++] = OPC_dup_x1;
917 } catch (IndexOutOfBoundsException e) {
918 resizeByteArray(OPC_dup_x1);
921 final public void dup_x2() {
924 if (stackDepth > stackMax)
925 stackMax = stackDepth;
928 bCodeStream[classFileOffset++] = OPC_dup_x2;
929 } catch (IndexOutOfBoundsException e) {
930 resizeByteArray(OPC_dup_x2);
933 final public void dup2() {
936 if (stackDepth > stackMax)
937 stackMax = stackDepth;
940 bCodeStream[classFileOffset++] = OPC_dup2;
941 } catch (IndexOutOfBoundsException e) {
942 resizeByteArray(OPC_dup2);
945 final public void dup2_x1() {
948 if (stackDepth > stackMax)
949 stackMax = stackDepth;
952 bCodeStream[classFileOffset++] = OPC_dup2_x1;
953 } catch (IndexOutOfBoundsException e) {
954 resizeByteArray(OPC_dup2_x1);
957 final public void dup2_x2() {
960 if (stackDepth > stackMax)
961 stackMax = stackDepth;
964 bCodeStream[classFileOffset++] = OPC_dup2_x2;
965 } catch (IndexOutOfBoundsException e) {
966 resizeByteArray(OPC_dup2_x2);
969 public void exitUserScope(BlockScope blockScope) {
970 // mark all the scope's locals as loosing their definite assignment
972 if (!generateLocalVariableTableAttributes)
974 for (int i = 0; i < visibleLocalsCount; i++) {
975 LocalVariableBinding visibleLocal = visibleLocals[i];
976 if ((visibleLocal != null) && (visibleLocal.declaringScope == blockScope)) {
977 // there maybe some some preserved locals never initialized
978 if (visibleLocal.initializationCount > 0){
979 visibleLocals[i].recordInitializationEndPC(position);
981 visibleLocals[i] = null; // this variable is no longer visible afterwards
985 final public void f2d() {
988 if (stackDepth > stackMax)
989 stackMax = stackDepth;
992 bCodeStream[classFileOffset++] = OPC_f2d;
993 } catch (IndexOutOfBoundsException e) {
994 resizeByteArray(OPC_f2d);
997 final public void f2i() {
1001 bCodeStream[classFileOffset++] = OPC_f2i;
1002 } catch (IndexOutOfBoundsException e) {
1003 resizeByteArray(OPC_f2i);
1006 final public void f2l() {
1009 if (stackDepth > stackMax)
1010 stackMax = stackDepth;
1013 bCodeStream[classFileOffset++] = OPC_f2l;
1014 } catch (IndexOutOfBoundsException e) {
1015 resizeByteArray(OPC_f2l);
1018 final public void fadd() {
1023 bCodeStream[classFileOffset++] = OPC_fadd;
1024 } catch (IndexOutOfBoundsException e) {
1025 resizeByteArray(OPC_fadd);
1028 final public void faload() {
1033 bCodeStream[classFileOffset++] = OPC_faload;
1034 } catch (IndexOutOfBoundsException e) {
1035 resizeByteArray(OPC_faload);
1038 final public void fastore() {
1043 bCodeStream[classFileOffset++] = OPC_fastore;
1044 } catch (IndexOutOfBoundsException e) {
1045 resizeByteArray(OPC_fastore);
1048 final public void fcmpg() {
1053 bCodeStream[classFileOffset++] = OPC_fcmpg;
1054 } catch (IndexOutOfBoundsException e) {
1055 resizeByteArray(OPC_fcmpg);
1058 final public void fcmpl() {
1063 bCodeStream[classFileOffset++] = OPC_fcmpl;
1064 } catch (IndexOutOfBoundsException e) {
1065 resizeByteArray(OPC_fcmpl);
1068 final public void fconst_0() {
1071 if (stackDepth > stackMax)
1072 stackMax = stackDepth;
1075 bCodeStream[classFileOffset++] = OPC_fconst_0;
1076 } catch (IndexOutOfBoundsException e) {
1077 resizeByteArray(OPC_fconst_0);
1080 final public void fconst_1() {
1083 if (stackDepth > stackMax)
1084 stackMax = stackDepth;
1087 bCodeStream[classFileOffset++] = OPC_fconst_1;
1088 } catch (IndexOutOfBoundsException e) {
1089 resizeByteArray(OPC_fconst_1);
1092 final public void fconst_2() {
1095 if (stackDepth > stackMax)
1096 stackMax = stackDepth;
1099 bCodeStream[classFileOffset++] = OPC_fconst_2;
1100 } catch (IndexOutOfBoundsException e) {
1101 resizeByteArray(OPC_fconst_2);
1104 final public void fdiv() {
1109 bCodeStream[classFileOffset++] = OPC_fdiv;
1110 } catch (IndexOutOfBoundsException e) {
1111 resizeByteArray(OPC_fdiv);
1114 final public void fload(int iArg) {
1117 if (maxLocals <= iArg) {
1118 maxLocals = iArg + 1;
1120 if (stackDepth > stackMax)
1121 stackMax = stackDepth;
1122 if (iArg > 255) { // Widen
1125 bCodeStream[classFileOffset++] = OPC_wide;
1126 } catch (IndexOutOfBoundsException e) {
1127 resizeByteArray(OPC_wide);
1131 bCodeStream[classFileOffset++] = OPC_fload;
1132 } catch (IndexOutOfBoundsException e) {
1133 resizeByteArray(OPC_fload);
1135 writeUnsignedShort(iArg);
1139 bCodeStream[classFileOffset++] = OPC_fload;
1140 } catch (IndexOutOfBoundsException e) {
1141 resizeByteArray(OPC_fload);
1145 bCodeStream[classFileOffset++] = (byte) iArg;
1146 } catch (IndexOutOfBoundsException e) {
1147 resizeByteArray((byte) iArg);
1151 final public void fload_0() {
1154 if (maxLocals == 0) {
1157 if (stackDepth > stackMax)
1158 stackMax = stackDepth;
1161 bCodeStream[classFileOffset++] = OPC_fload_0;
1162 } catch (IndexOutOfBoundsException e) {
1163 resizeByteArray(OPC_fload_0);
1166 final public void fload_1() {
1169 if (maxLocals <= 1) {
1172 if (stackDepth > stackMax)
1173 stackMax = stackDepth;
1176 bCodeStream[classFileOffset++] = OPC_fload_1;
1177 } catch (IndexOutOfBoundsException e) {
1178 resizeByteArray(OPC_fload_1);
1181 final public void fload_2() {
1184 if (maxLocals <= 2) {
1187 if (stackDepth > stackMax)
1188 stackMax = stackDepth;
1191 bCodeStream[classFileOffset++] = OPC_fload_2;
1192 } catch (IndexOutOfBoundsException e) {
1193 resizeByteArray(OPC_fload_2);
1196 final public void fload_3() {
1199 if (maxLocals <= 3) {
1202 if (stackDepth > stackMax)
1203 stackMax = stackDepth;
1206 bCodeStream[classFileOffset++] = OPC_fload_3;
1207 } catch (IndexOutOfBoundsException e) {
1208 resizeByteArray(OPC_fload_3);
1211 final public void fmul() {
1216 bCodeStream[classFileOffset++] = OPC_fmul;
1217 } catch (IndexOutOfBoundsException e) {
1218 resizeByteArray(OPC_fmul);
1221 final public void fneg() {
1225 bCodeStream[classFileOffset++] = OPC_fneg;
1226 } catch (IndexOutOfBoundsException e) {
1227 resizeByteArray(OPC_fneg);
1230 final public void frem() {
1235 bCodeStream[classFileOffset++] = OPC_frem;
1236 } catch (IndexOutOfBoundsException e) {
1237 resizeByteArray(OPC_frem);
1240 final public void freturn() {
1243 // the stackDepth should be equal to 0
1246 bCodeStream[classFileOffset++] = OPC_freturn;
1247 } catch (IndexOutOfBoundsException e) {
1248 resizeByteArray(OPC_freturn);
1251 final public void fstore(int iArg) {
1254 if (maxLocals <= iArg) {
1255 maxLocals = iArg + 1;
1257 if (iArg > 255) { // Widen
1260 bCodeStream[classFileOffset++] = OPC_wide;
1261 } catch (IndexOutOfBoundsException e) {
1262 resizeByteArray(OPC_wide);
1266 bCodeStream[classFileOffset++] = OPC_fstore;
1267 } catch (IndexOutOfBoundsException e) {
1268 resizeByteArray(OPC_fstore);
1270 writeUnsignedShort(iArg);
1274 bCodeStream[classFileOffset++] = OPC_fstore;
1275 } catch (IndexOutOfBoundsException e) {
1276 resizeByteArray(OPC_fstore);
1280 bCodeStream[classFileOffset++] = (byte) iArg;
1281 } catch (IndexOutOfBoundsException e) {
1282 resizeByteArray((byte) iArg);
1286 final public void fstore_0() {
1289 if (maxLocals == 0) {
1294 bCodeStream[classFileOffset++] = OPC_fstore_0;
1295 } catch (IndexOutOfBoundsException e) {
1296 resizeByteArray(OPC_fstore_0);
1299 final public void fstore_1() {
1302 if (maxLocals <= 1) {
1307 bCodeStream[classFileOffset++] = OPC_fstore_1;
1308 } catch (IndexOutOfBoundsException e) {
1309 resizeByteArray(OPC_fstore_1);
1312 final public void fstore_2() {
1315 if (maxLocals <= 2) {
1320 bCodeStream[classFileOffset++] = OPC_fstore_2;
1321 } catch (IndexOutOfBoundsException e) {
1322 resizeByteArray(OPC_fstore_2);
1325 final public void fstore_3() {
1328 if (maxLocals <= 3) {
1333 bCodeStream[classFileOffset++] = OPC_fstore_3;
1334 } catch (IndexOutOfBoundsException e) {
1335 resizeByteArray(OPC_fstore_3);
1338 final public void fsub() {
1343 bCodeStream[classFileOffset++] = OPC_fsub;
1344 } catch (IndexOutOfBoundsException e) {
1345 resizeByteArray(OPC_fsub);
1349 * Macro for building a class descriptor object
1351 public void generateClassLiteralAccessForType(TypeBinding accessedType, FieldBinding syntheticFieldBinding) {
1353 ExceptionLabel anyExceptionHandler;
1355 if (accessedType.isBaseType() && accessedType != NullBinding) {
1356 this.getTYPE(accessedType.id);
1359 endLabel = new Label(this);
1361 if (syntheticFieldBinding != null) { // non interface case
1362 this.getstatic(syntheticFieldBinding);
1364 this.ifnonnull(endLabel);
1368 /* Macro for building a class descriptor object... using or not a field cache to store it into...
1369 this sequence is responsible for building the actual class descriptor.
1371 If the fieldCache is set, then it is supposed to be the body of a synthetic access method
1372 factoring the actual descriptor creation out of the invocation site (saving space).
1373 If the fieldCache is nil, then we are dumping the bytecode on the invocation site, since
1374 we have no way to get a hand on the field cache to do better. */
1377 // Wrap the code in an exception handler to convert a ClassNotFoundException into a NoClassDefError
1379 anyExceptionHandler = new ExceptionLabel(this, TypeBinding.NullBinding /* represents ClassNotFoundException*/);
1380 this.ldc(accessedType == TypeBinding.NullBinding ? "java.lang.Object" : String.valueOf(accessedType.constantPoolName()).replace('/', '.')); //$NON-NLS-1$
1381 this.invokeClassForName();
1383 /* We need to protect the runtime code from binary inconsistencies
1384 in case the accessedType is missing, the ClassNotFoundException has to be converted
1385 into a NoClassDefError(old ex message), we thus need to build an exception handler for this one. */
1386 anyExceptionHandler.placeEnd();
1388 if (syntheticFieldBinding != null) { // non interface case
1390 this.putstatic(syntheticFieldBinding);
1392 this.goto_(endLabel);
1395 // Generate the body of the exception handler
1396 saveStackSize = stackDepth;
1398 /* ClassNotFoundException on stack -- the class literal could be doing more things
1399 on the stack, which means that the stack may not be empty at this point in the
1400 above code gen. So we save its state and restart it from 1. */
1402 anyExceptionHandler.place();
1404 // Transform the current exception, and repush and throw a
1405 // NoClassDefFoundError(ClassNotFound.getMessage())
1407 this.newNoClassDefFoundError();
1411 // Retrieve the message from the old exception
1412 this.invokeThrowableGetMessage();
1414 // Send the constructor taking a message string as an argument
1415 this.invokeNoClassDefFoundErrorStringConstructor();
1418 stackDepth = saveStackSize;
1421 * This method returns the exception handler to be able to generate the exception handler
1424 final public int[] generateCodeAttributeForProblemMethod(String errorName, String problemMessage) {
1428 * throw ((Error) (Class.forName(errorName).getConstructor(new Class[] {Class.forName("java.lang.String")})).newInstance(new Object[] {problemMessage}));
1429 * } catch (Exception e) {
1430 * throw (NullPointerException) null;
1433 int endPC, handlerPC;
1435 invokeClassForName();
1437 anewarrayJavaLangClass();
1440 ldc("java.lang.String"); //$NON-NLS-1$
1441 invokeClassForName();
1443 invokeConstructorGetConstructor();
1445 anewarrayJavaLangObject();
1448 ldc(problemMessage);
1450 invokeObjectNewInstance();
1451 checkcastJavaLangError();
1453 endPC = handlerPC = position;
1458 return new int[] {0, endPC, handlerPC};
1460 public void generateConstant(Constant constant, int implicitConversionCode) {
1461 int targetTypeID = implicitConversionCode >> 4;
1462 switch (targetTypeID) {
1464 generateInlinedValue(constant.booleanValue());
1467 generateInlinedValue(constant.charValue());
1470 generateInlinedValue(constant.byteValue());
1473 generateInlinedValue(constant.shortValue());
1476 generateInlinedValue(constant.intValue());
1479 generateInlinedValue(constant.longValue());
1482 generateInlinedValue(constant.floatValue());
1485 generateInlinedValue(constant.doubleValue());
1488 this.ldc(constant.stringValue());
1490 default : //reference object (constant can be from T_null or T_String)
1491 if (constant.typeID() == T_String)
1492 ldc(constant.stringValue());
1498 * @param implicitConversionCode int
1500 public void generateImplicitConversion(int implicitConversionCode) {
1501 switch (implicitConversionCode) {
1599 public void generateInlinedValue(byte inlinedValue) {
1600 switch (inlinedValue) {
1623 if ((-128 <= inlinedValue) && (inlinedValue <= 127)) {
1624 this.bipush((byte) inlinedValue);
1629 public void generateInlinedValue(char inlinedValue) {
1630 switch (inlinedValue) {
1650 if ((6 <= inlinedValue) && (inlinedValue <= 127)) {
1651 this.bipush((byte) inlinedValue);
1654 if ((128 <= inlinedValue) && (inlinedValue <= 32767)) {
1655 this.sipush(inlinedValue);
1658 this.ldc(inlinedValue);
1661 public void generateInlinedValue(double inlinedValue) {
1662 if (inlinedValue == 0.0) {
1663 if (Double.doubleToLongBits(inlinedValue) != 0L)
1664 this.ldc2_w(inlinedValue);
1669 if (inlinedValue == 1.0) {
1673 this.ldc2_w(inlinedValue);
1675 public void generateInlinedValue(float inlinedValue) {
1676 if (inlinedValue == 0.0f) {
1677 if (Float.floatToIntBits(inlinedValue) != 0)
1678 this.ldc(inlinedValue);
1683 if (inlinedValue == 1.0f) {
1687 if (inlinedValue == 2.0f) {
1691 this.ldc(inlinedValue);
1693 public void generateInlinedValue(int inlinedValue) {
1694 switch (inlinedValue) {
1717 if ((-128 <= inlinedValue) && (inlinedValue <= 127)) {
1718 this.bipush((byte) inlinedValue);
1721 if ((-32768 <= inlinedValue) && (inlinedValue <= 32767)) {
1722 this.sipush(inlinedValue);
1725 this.ldc(inlinedValue);
1728 public void generateInlinedValue(long inlinedValue) {
1729 if (inlinedValue == 0) {
1733 if (inlinedValue == 1) {
1737 this.ldc2_w(inlinedValue);
1739 public void generateInlinedValue(short inlinedValue) {
1740 switch (inlinedValue) {
1763 if ((-128 <= inlinedValue) && (inlinedValue <= 127)) {
1764 this.bipush((byte) inlinedValue);
1767 this.sipush(inlinedValue);
1770 public void generateInlinedValue(boolean inlinedValue) {
1776 public void generateOuterAccess(Object[] mappingSequence, AstNode invocationSite, Scope scope) {
1777 if (mappingSequence == null)
1779 if (mappingSequence == BlockScope.EmulationPathToImplicitThis) {
1780 if (scope.methodScope().isConstructorCall){
1781 scope.problemReporter().errorThisSuperInStatic(invocationSite);
1786 if (mappingSequence[0] instanceof FieldBinding) {
1787 FieldBinding fieldBinding = (FieldBinding) mappingSequence[0];
1788 if (scope.methodScope().isConstructorCall){
1789 scope.problemReporter().errorThisSuperInStatic(invocationSite);
1792 this.getfield(fieldBinding);
1794 load((LocalVariableBinding) mappingSequence[0]);
1796 for (int i = 1, length = mappingSequence.length; i < length; i++) {
1797 if (mappingSequence[i] instanceof FieldBinding) {
1798 FieldBinding fieldBinding = (FieldBinding) mappingSequence[i];
1799 this.getfield(fieldBinding);
1801 this.invokestatic((MethodBinding) mappingSequence[i]);
1806 * The equivalent code performs a string conversion:
1808 * @param oper1 org.eclipse.jdt.internal.compiler.lookup.BlockScope
1809 * @param oper1 org.eclipse.jdt.internal.compiler.ast.Expression
1810 * @param oper2 org.eclipse.jdt.internal.compiler.ast.Expression
1812 public void generateStringAppend(BlockScope blockScope, Expression oper1, Expression oper2) {
1814 if (oper1 == null) {
1815 /* Operand is already on the stack, and maybe nil:
1816 note type1 is always to java.lang.String here.*/
1817 this.newStringBuffer();
1820 // If argument is reference type, need to transform it
1821 // into a string (handles null case)
1822 this.invokeStringValueOf(T_Object);
1823 this.invokeStringBufferStringConstructor();
1826 oper1.generateOptimizedStringBufferCreation(blockScope, this, oper1.implicitConversion & 0xF);
1827 this.recordPositionsFrom(pc, oper1.sourceStart);
1830 oper2.generateOptimizedStringBuffer(blockScope, this, oper2.implicitConversion & 0xF);
1831 this.recordPositionsFrom(pc, oper2.sourceStart);
1832 this.invokeStringBufferToString();
1835 * Code responsible to generate the suitable code to supply values for the synthetic arguments of
1836 * a constructor invocation of a nested type.
1838 public void generateSyntheticArgumentValues(BlockScope currentScope, ReferenceBinding targetType, Expression enclosingInstance, AstNode invocationSite) {
1840 // perform some emulation work in case there is some and we are inside a local type only
1841 ReferenceBinding[] syntheticArgumentTypes;
1843 // generate the enclosing instance first
1844 if ((syntheticArgumentTypes = targetType.syntheticEnclosingInstanceTypes()) != null) {
1846 ReferenceBinding targetEnclosingType = targetType.isAnonymousType() ?
1847 targetType.superclass().enclosingType() // supplying enclosing instance for the anonymous type's superclass
1848 : targetType.enclosingType();
1850 for (int i = 0, max = syntheticArgumentTypes.length; i < max; i++) {
1851 ReferenceBinding syntheticArgType = syntheticArgumentTypes[i];
1852 if (enclosingInstance != null && i == 0) {
1853 if (syntheticArgType != targetEnclosingType) {
1854 currentScope.problemReporter().unnecessaryEnclosingInstanceSpecification(enclosingInstance, targetType);
1856 //if (currentScope.environment().options.complianceLevel >= CompilerOptions.JDK1_4){
1857 enclosingInstance.generateCode(currentScope, this, true);
1858 if (syntheticArgType == targetEnclosingType){
1861 this.invokeObjectGetClass(); // causes null check for all explicit enclosing instances
1864 // enclosingInstance.generateCode(currentScope, this, syntheticArgType == targetEnclosingType);
1867 Object[] emulationPath = currentScope.getCompatibleEmulationPath(syntheticArgType);
1868 if (emulationPath == null) {
1869 currentScope.problemReporter().missingEnclosingInstanceSpecification(syntheticArgType, invocationSite);
1871 this.generateOuterAccess(emulationPath, invocationSite, currentScope);
1875 } else { // we may still have an enclosing instance to consider
1876 if (enclosingInstance != null) {
1877 currentScope.problemReporter().unnecessaryEnclosingInstanceSpecification(enclosingInstance, targetType);
1878 //if (currentScope.environment().options.complianceLevel >= CompilerOptions.JDK1_4){
1879 enclosingInstance.generateCode(currentScope, this, true);
1880 this.invokeObjectGetClass(); // causes null check for all explicit enclosing instances
1883 // enclosingInstance.generateCode(currentScope, this, false); // do not want the value
1887 // generate the synthetic outer arguments then
1888 SyntheticArgumentBinding syntheticArguments[];
1889 if ((syntheticArguments = targetType.syntheticOuterLocalVariables()) != null) {
1890 for (int i = 0, max = syntheticArguments.length; i < max; i++) {
1891 VariableBinding[] emulationPath = currentScope.getEmulationPath(syntheticArguments[i].actualOuterLocalVariable);
1892 if (emulationPath == null) {
1893 // could not emulate a path to a given outer local variable (internal error)
1894 currentScope.problemReporter().needImplementation();
1896 this.generateOuterAccess(emulationPath, invocationSite, currentScope);
1902 * @param parameters org.eclipse.jdt.internal.compiler.lookup.TypeBinding[]
1903 * @param constructorBinding org.eclipse.jdt.internal.compiler.lookup.MethodBinding
1905 public void generateSyntheticBodyForConstructorAccess(SyntheticAccessMethodBinding accessBinding) {
1907 initializeMaxLocals(accessBinding);
1909 MethodBinding constructorBinding = accessBinding.targetMethod;
1910 TypeBinding[] parameters = constructorBinding.parameters;
1911 int length = parameters.length;
1912 int resolvedPosition = 1;
1914 if (constructorBinding.declaringClass.isNestedType()) {
1915 NestedTypeBinding nestedType = (NestedTypeBinding) constructorBinding.declaringClass;
1916 SyntheticArgumentBinding[] syntheticArguments = nestedType.syntheticEnclosingInstances();
1917 for (int i = 0; i < (syntheticArguments == null ? 0 : syntheticArguments.length); i++) {
1919 load((type = syntheticArguments[i].type), resolvedPosition);
1920 if ((type == DoubleBinding) || (type == LongBinding))
1921 resolvedPosition += 2;
1925 syntheticArguments = nestedType.syntheticOuterLocalVariables();
1926 for (int i = 0; i < (syntheticArguments == null ? 0 : syntheticArguments.length); i++) {
1928 load((type = syntheticArguments[i].type), resolvedPosition);
1929 if ((type == DoubleBinding) || (type == LongBinding))
1930 resolvedPosition += 2;
1935 for (int i = 0; i < length; i++) {
1936 load(parameters[i], resolvedPosition);
1937 if ((parameters[i] == DoubleBinding) || (parameters[i] == LongBinding))
1938 resolvedPosition += 2;
1942 this.invokespecial(constructorBinding);
1945 public void generateSyntheticBodyForFieldReadAccess(SyntheticAccessMethodBinding accessBinding) {
1946 initializeMaxLocals(accessBinding);
1947 FieldBinding fieldBinding = accessBinding.targetReadField;
1949 if (fieldBinding.isStatic())
1950 this.getstatic(fieldBinding);
1953 this.getfield(fieldBinding);
1955 if ((type = fieldBinding.type).isBaseType()) {
1956 if (type == IntBinding)
1959 if (type == FloatBinding)
1962 if (type == LongBinding)
1965 if (type == DoubleBinding)
1972 public void generateSyntheticBodyForFieldWriteAccess(SyntheticAccessMethodBinding accessBinding) {
1973 initializeMaxLocals(accessBinding);
1974 FieldBinding fieldBinding = accessBinding.targetWriteField;
1975 if (fieldBinding.isStatic()) {
1976 load(fieldBinding.type, 0);
1977 this.putstatic(fieldBinding);
1980 load(fieldBinding.type, 1);
1981 this.putfield(fieldBinding);
1985 public void generateSyntheticBodyForMethodAccess(SyntheticAccessMethodBinding accessBinding) {
1987 initializeMaxLocals(accessBinding);
1988 MethodBinding methodBinding = accessBinding.targetMethod;
1989 TypeBinding[] parameters = methodBinding.parameters;
1990 int length = parameters.length;
1991 int resolvedPosition;
1992 if (methodBinding.isStatic())
1993 resolvedPosition = 0;
1996 resolvedPosition = 1;
1998 for (int i = 0; i < length; i++) {
1999 load(parameters[i], resolvedPosition);
2000 if ((parameters[i] == DoubleBinding) || (parameters[i] == LongBinding))
2001 resolvedPosition += 2;
2006 if (methodBinding.isStatic())
2007 this.invokestatic(methodBinding);
2009 if (methodBinding.isConstructor()
2010 || methodBinding.isPrivate()
2011 // qualified super "X.super.foo()" targets methods from superclass
2012 || (methodBinding.declaringClass != methodDeclaration.binding.declaringClass)){
2013 this.invokespecial(methodBinding);
2015 if (methodBinding.declaringClass.isInterface()){
2016 this.invokeinterface(methodBinding);
2018 this.invokevirtual(methodBinding);
2022 if ((type = methodBinding.returnType).isBaseType())
2023 if (type == VoidBinding)
2026 if (type == IntBinding)
2029 if (type == FloatBinding)
2032 if (type == LongBinding)
2035 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) {
2936 if (pc > currentPC) {
2942 if (pc < pcToSourceMap[m])
2947 * We didn't call it instanceof because there is a conflit with the
2948 * instanceof keyword
2950 final public void instance_of(TypeBinding typeBinding) {
2954 bCodeStream[classFileOffset++] = OPC_instanceof;
2955 } catch (IndexOutOfBoundsException e) {
2956 resizeByteArray(OPC_instanceof);
2958 writeUnsignedShort(constantPool.literalIndex(typeBinding));
2960 public void invokeClassForName() {
2961 // invokestatic: java.lang.Class.forName(Ljava.lang.String;)Ljava.lang.Class;
2965 bCodeStream[classFileOffset++] = OPC_invokestatic;
2966 } catch (IndexOutOfBoundsException e) {
2967 resizeByteArray(OPC_invokestatic);
2969 writeUnsignedShort(constantPool.literalIndexForJavaLangClassForName());
2972 public void invokeJavaLangClassDesiredAssertionStatus() {
2973 // invokevirtual: java.lang.Class.desiredAssertionStatus()Z;
2978 bCodeStream[classFileOffset++] = OPC_invokevirtual;
2979 } catch (IndexOutOfBoundsException e) {
2980 resizeByteArray(OPC_invokevirtual);
2982 writeUnsignedShort(constantPool.literalIndexForJavaLangClassDesiredAssertionStatus());
2985 public void invokeConstructorGetConstructor() {
2986 // invokevirtual: java.lang.Class.getConstructor(java.lang.Class[])Ljava.lang.reflect.Constructor;
2991 bCodeStream[classFileOffset++] = OPC_invokevirtual;
2992 } catch (IndexOutOfBoundsException e) {
2993 resizeByteArray(OPC_invokevirtual);
2995 writeUnsignedShort(constantPool.literalIndexForJavaLangClassGetConstructor());
2997 final public void invokeinterface(MethodBinding methodBinding) {
2998 // initialized to 1 to take into account this immediately
3004 bCodeStream[classFileOffset++] = OPC_invokeinterface;
3005 } catch (IndexOutOfBoundsException e) {
3006 resizeByteArray(OPC_invokeinterface);
3008 writeUnsignedShort(constantPool.literalIndex(methodBinding));
3009 for (int i = methodBinding.parameters.length - 1; i >= 0; i--)
3010 if (((id = methodBinding.parameters[i].id) == T_double) || (id == T_long))
3014 writeUnsignedByte(argCount);
3015 // Generate a 0 into the byte array. Like the array is already fill with 0, we just need to increment
3016 // the number of bytes.
3019 if (((id = methodBinding.returnType.id) == T_double) || (id == T_long))
3020 stackDepth += (2 - argCount);
3023 stackDepth -= argCount;
3025 stackDepth += (1 - argCount);
3026 if (stackDepth > stackMax)
3027 stackMax = stackDepth;
3029 public void invokeJavaLangErrorConstructor() {
3030 // invokespecial: java.lang.Error<init>(Ljava.lang.String;)V
3034 bCodeStream[classFileOffset++] = OPC_invokespecial;
3035 } catch (IndexOutOfBoundsException e) {
3036 resizeByteArray(OPC_invokespecial);
3039 writeUnsignedShort(constantPool.literalIndexForJavaLangErrorConstructor());
3041 public void invokeNoClassDefFoundErrorStringConstructor() {
3042 // invokespecial: java.lang.NoClassDefFoundError.<init>(Ljava.lang.String;)V
3046 bCodeStream[classFileOffset++] = OPC_invokespecial;
3047 } catch (IndexOutOfBoundsException e) {
3048 resizeByteArray(OPC_invokespecial);
3050 writeUnsignedShort(constantPool.literalIndexForJavaLangNoClassDefFoundErrorStringConstructor());
3053 public void invokeObjectNewInstance() {
3054 // invokevirtual: java.lang.reflect.Constructor.newInstance(java.lang.Object[])Ljava.lang.Object;
3059 bCodeStream[classFileOffset++] = OPC_invokevirtual;
3060 } catch (IndexOutOfBoundsException e) {
3061 resizeByteArray(OPC_invokevirtual);
3063 writeUnsignedShort(constantPool.literalIndexForJavaLangReflectConstructorNewInstance());
3066 public void invokeObjectGetClass() {
3067 // invokevirtual: java.lang.Object.getClass()Ljava.lang.Class;
3071 bCodeStream[classFileOffset++] = OPC_invokevirtual;
3072 } catch (IndexOutOfBoundsException e) {
3073 resizeByteArray(OPC_invokevirtual);
3075 writeUnsignedShort(constantPool.literalIndexForJavaLangObjectGetClass());
3078 final public void invokespecial(MethodBinding methodBinding) {
3079 // initialized to 1 to take into account this immediately
3085 bCodeStream[classFileOffset++] = OPC_invokespecial;
3086 } catch (IndexOutOfBoundsException e) {
3087 resizeByteArray(OPC_invokespecial);
3089 writeUnsignedShort(constantPool.literalIndex(methodBinding));
3090 if (methodBinding.isConstructor() && methodBinding.declaringClass.isNestedType()) {
3091 // enclosing instances
3092 TypeBinding[] syntheticArgumentTypes = methodBinding.declaringClass.syntheticEnclosingInstanceTypes();
3093 if (syntheticArgumentTypes != null) {
3094 for (int i = 0, max = syntheticArgumentTypes.length; i < max; i++) {
3095 if (((id = syntheticArgumentTypes[i].id) == T_double) || (id == T_long)) {
3102 // outer local variables
3103 SyntheticArgumentBinding[] syntheticArguments = methodBinding.declaringClass.syntheticOuterLocalVariables();
3104 if (syntheticArguments != null) {
3105 for (int i = 0, max = syntheticArguments.length; i < max; i++) {
3106 if (((id = syntheticArguments[i].type.id) == T_double) || (id == T_long)) {
3114 for (int i = methodBinding.parameters.length - 1; i >= 0; i--)
3115 if (((id = methodBinding.parameters[i].id) == T_double) || (id == T_long))
3119 if (((id = methodBinding.returnType.id) == T_double) || (id == T_long))
3120 stackDepth += (2 - argCount);
3123 stackDepth -= argCount;
3125 stackDepth += (1 - argCount);
3126 if (stackDepth > stackMax)
3127 stackMax = stackDepth;
3129 final public void invokestatic(MethodBinding methodBinding) {
3130 // initialized to 0 to take into account that there is no this for
3137 bCodeStream[classFileOffset++] = OPC_invokestatic;
3138 } catch (IndexOutOfBoundsException e) {
3139 resizeByteArray(OPC_invokestatic);
3141 writeUnsignedShort(constantPool.literalIndex(methodBinding));
3142 for (int i = methodBinding.parameters.length - 1; i >= 0; i--)
3143 if (((id = methodBinding.parameters[i].id) == T_double) || (id == T_long))
3147 if (((id = methodBinding.returnType.id) == T_double) || (id == T_long))
3148 stackDepth += (2 - argCount);
3151 stackDepth -= argCount;
3153 stackDepth += (1 - argCount);
3154 if (stackDepth > stackMax)
3155 stackMax = stackDepth;
3158 * The equivalent code performs a string conversion of the TOS
3159 * @param typeID <CODE>int</CODE>
3161 public void invokeStringBufferAppendForType(int typeID) {
3164 if (typeID == T_null)
3165 usedTypeID = T_String;
3167 usedTypeID = typeID;
3171 bCodeStream[classFileOffset++] = OPC_invokevirtual;
3172 } catch (IndexOutOfBoundsException e) {
3173 resizeByteArray(OPC_invokevirtual);
3175 writeUnsignedShort(constantPool.literalIndexForJavaLangStringBufferAppend(typeID));
3176 if ((usedTypeID == T_long) || (usedTypeID == T_double))
3182 public void invokeJavaLangAssertionErrorConstructor(int typeBindingID) {
3183 // invokespecial: java.lang.AssertionError.<init>(typeBindingID)V
3187 bCodeStream[classFileOffset++] = OPC_invokespecial;
3188 } catch (IndexOutOfBoundsException e) {
3189 resizeByteArray(OPC_invokespecial);
3191 writeUnsignedShort(constantPool.literalIndexForJavaLangAssertionErrorConstructor(typeBindingID));
3195 public void invokeJavaLangAssertionErrorDefaultConstructor() {
3196 // invokespecial: java.lang.AssertionError.<init>()V
3200 bCodeStream[classFileOffset++] = OPC_invokespecial;
3201 } catch (IndexOutOfBoundsException e) {
3202 resizeByteArray(OPC_invokespecial);
3204 writeUnsignedShort(constantPool.literalIndexForJavaLangAssertionErrorDefaultConstructor());
3208 public void invokeStringBufferDefaultConstructor() {
3209 // invokespecial: java.lang.StringBuffer.<init>()V
3213 bCodeStream[classFileOffset++] = OPC_invokespecial;
3214 } catch (IndexOutOfBoundsException e) {
3215 resizeByteArray(OPC_invokespecial);
3217 writeUnsignedShort(constantPool.literalIndexForJavaLangStringBufferDefaultConstructor());
3220 public void invokeStringBufferStringConstructor() {
3221 // invokespecial: java.lang.StringBuffer.<init>(Ljava.lang.String;)V
3225 bCodeStream[classFileOffset++] = OPC_invokespecial;
3226 } catch (IndexOutOfBoundsException e) {
3227 resizeByteArray(OPC_invokespecial);
3229 writeUnsignedShort(constantPool.literalIndexForJavaLangStringBufferConstructor());
3233 public void invokeStringBufferToString() {
3234 // invokevirtual: StringBuffer.toString()Ljava.lang.String;
3238 bCodeStream[classFileOffset++] = OPC_invokevirtual;
3239 } catch (IndexOutOfBoundsException e) {
3240 resizeByteArray(OPC_invokevirtual);
3242 writeUnsignedShort(constantPool.literalIndexForJavaLangStringBufferToString());
3244 public void invokeStringIntern() {
3245 // invokevirtual: java.lang.String.intern()
3249 bCodeStream[classFileOffset++] = OPC_invokevirtual;
3250 } catch (IndexOutOfBoundsException e) {
3251 resizeByteArray(OPC_invokevirtual);
3253 writeUnsignedShort(constantPool.literalIndexForJavaLangStringIntern());
3255 public void invokeStringValueOf(int typeID) {
3256 // invokestatic: java.lang.String.valueOf(argumentType)
3260 bCodeStream[classFileOffset++] = OPC_invokestatic;
3261 } catch (IndexOutOfBoundsException e) {
3262 resizeByteArray(OPC_invokestatic);
3264 writeUnsignedShort(constantPool.literalIndexForJavaLangStringValueOf(typeID));
3266 public void invokeSystemExit() {
3267 // invokestatic: java.lang.System.exit(I)
3271 bCodeStream[classFileOffset++] = OPC_invokestatic;
3272 } catch (IndexOutOfBoundsException e) {
3273 resizeByteArray(OPC_invokestatic);
3275 writeUnsignedShort(constantPool.literalIndexForJavaLangSystemExitInt());
3276 stackDepth--; // int argument
3278 public void invokeThrowableGetMessage() {
3279 // invokevirtual: java.lang.Throwable.getMessage()Ljava.lang.String;
3283 bCodeStream[classFileOffset++] = OPC_invokevirtual;
3284 } catch (IndexOutOfBoundsException e) {
3285 resizeByteArray(OPC_invokevirtual);
3287 writeUnsignedShort(constantPool.literalIndexForJavaLangThrowableGetMessage());
3289 final public void invokevirtual(MethodBinding methodBinding) {
3290 // initialized to 1 to take into account this immediately
3296 bCodeStream[classFileOffset++] = OPC_invokevirtual;
3297 } catch (IndexOutOfBoundsException e) {
3298 resizeByteArray(OPC_invokevirtual);
3300 writeUnsignedShort(constantPool.literalIndex(methodBinding));
3301 for (int i = methodBinding.parameters.length - 1; i >= 0; i--)
3302 if (((id = methodBinding.parameters[i].id) == T_double) || (id == T_long))
3306 if (((id = methodBinding.returnType.id) == T_double) || (id == T_long))
3307 stackDepth += (2 - argCount);
3310 stackDepth -= argCount;
3312 stackDepth += (1 - argCount);
3313 if (stackDepth > stackMax)
3314 stackMax = stackDepth;
3316 final public void ior() {
3321 bCodeStream[classFileOffset++] = OPC_ior;
3322 } catch (IndexOutOfBoundsException e) {
3323 resizeByteArray(OPC_ior);
3326 final public void irem() {
3331 bCodeStream[classFileOffset++] = OPC_irem;
3332 } catch (IndexOutOfBoundsException e) {
3333 resizeByteArray(OPC_irem);
3336 final public void ireturn() {
3339 // the stackDepth should be equal to 0
3342 bCodeStream[classFileOffset++] = OPC_ireturn;
3343 } catch (IndexOutOfBoundsException e) {
3344 resizeByteArray(OPC_ireturn);
3347 public boolean isDefinitelyAssigned(Scope scope, int initStateIndex, LocalVariableBinding local) {
3348 // Dependant of UnconditionalFlowInfo.isDefinitelyAssigned(..)
3349 if (initStateIndex == -1)
3351 if (local.isArgument) {
3354 int position = local.id + maxFieldCount;
3355 MethodScope methodScope = scope.methodScope();
3357 if (position < UnconditionalFlowInfo.BitCacheSize) {
3358 return (methodScope.definiteInits[initStateIndex] & (1L << position)) != 0; // use bits
3361 long[] extraInits = methodScope.extraDefiniteInits[initStateIndex];
3362 if (extraInits == null)
3363 return false; // if vector not yet allocated, then not initialized
3365 if ((vectorIndex = (position / UnconditionalFlowInfo.BitCacheSize) - 1) >= extraInits.length)
3366 return false; // if not enough room in vector, then not initialized
3367 return ((extraInits[vectorIndex]) & (1L << (position % UnconditionalFlowInfo.BitCacheSize))) != 0;
3369 final public void ishl() {
3374 bCodeStream[classFileOffset++] = OPC_ishl;
3375 } catch (IndexOutOfBoundsException e) {
3376 resizeByteArray(OPC_ishl);
3379 final public void ishr() {
3384 bCodeStream[classFileOffset++] = OPC_ishr;
3385 } catch (IndexOutOfBoundsException e) {
3386 resizeByteArray(OPC_ishr);
3389 final public void istore(int iArg) {
3392 if (maxLocals <= iArg) {
3393 maxLocals = iArg + 1;
3395 if (iArg > 255) { // Widen
3398 bCodeStream[classFileOffset++] = OPC_wide;
3399 } catch (IndexOutOfBoundsException e) {
3400 resizeByteArray(OPC_wide);
3404 bCodeStream[classFileOffset++] = OPC_istore;
3405 } catch (IndexOutOfBoundsException e) {
3406 resizeByteArray(OPC_istore);
3408 writeUnsignedShort(iArg);
3412 bCodeStream[classFileOffset++] = OPC_istore;
3413 } catch (IndexOutOfBoundsException e) {
3414 resizeByteArray(OPC_istore);
3418 bCodeStream[classFileOffset++] = (byte) iArg;
3419 } catch (IndexOutOfBoundsException e) {
3420 resizeByteArray((byte) iArg);
3424 final public void istore_0() {
3427 if (maxLocals == 0) {
3432 bCodeStream[classFileOffset++] = OPC_istore_0;
3433 } catch (IndexOutOfBoundsException e) {
3434 resizeByteArray(OPC_istore_0);
3437 final public void istore_1() {
3440 if (maxLocals <= 1) {
3445 bCodeStream[classFileOffset++] = OPC_istore_1;
3446 } catch (IndexOutOfBoundsException e) {
3447 resizeByteArray(OPC_istore_1);
3450 final public void istore_2() {
3453 if (maxLocals <= 2) {
3458 bCodeStream[classFileOffset++] = OPC_istore_2;
3459 } catch (IndexOutOfBoundsException e) {
3460 resizeByteArray(OPC_istore_2);
3463 final public void istore_3() {
3466 if (maxLocals <= 3) {
3471 bCodeStream[classFileOffset++] = OPC_istore_3;
3472 } catch (IndexOutOfBoundsException e) {
3473 resizeByteArray(OPC_istore_3);
3476 final public void isub() {
3481 bCodeStream[classFileOffset++] = OPC_isub;
3482 } catch (IndexOutOfBoundsException e) {
3483 resizeByteArray(OPC_isub);
3486 final public void iushr() {
3491 bCodeStream[classFileOffset++] = OPC_iushr;
3492 } catch (IndexOutOfBoundsException e) {
3493 resizeByteArray(OPC_iushr);
3496 final public void ixor() {
3501 bCodeStream[classFileOffset++] = OPC_ixor;
3502 } catch (IndexOutOfBoundsException e) {
3503 resizeByteArray(OPC_ixor);
3506 final public void jsr(Label lbl) {
3510 bCodeStream[classFileOffset++] = OPC_jsr;
3511 } catch (IndexOutOfBoundsException e) {
3512 resizeByteArray(OPC_jsr);
3516 final public void jsr_w(Label lbl) {
3520 bCodeStream[classFileOffset++] = OPC_jsr_w;
3521 } catch (IndexOutOfBoundsException e) {
3522 resizeByteArray(OPC_jsr_w);
3526 final public void l2d() {
3530 bCodeStream[classFileOffset++] = OPC_l2d;
3531 } catch (IndexOutOfBoundsException e) {
3532 resizeByteArray(OPC_l2d);
3535 final public void l2f() {
3540 bCodeStream[classFileOffset++] = OPC_l2f;
3541 } catch (IndexOutOfBoundsException e) {
3542 resizeByteArray(OPC_l2f);
3545 final public void l2i() {
3550 bCodeStream[classFileOffset++] = OPC_l2i;
3551 } catch (IndexOutOfBoundsException e) {
3552 resizeByteArray(OPC_l2i);
3555 final public void ladd() {
3560 bCodeStream[classFileOffset++] = OPC_ladd;
3561 } catch (IndexOutOfBoundsException e) {
3562 resizeByteArray(OPC_ladd);
3565 final public void laload() {
3569 bCodeStream[classFileOffset++] = OPC_laload;
3570 } catch (IndexOutOfBoundsException e) {
3571 resizeByteArray(OPC_laload);
3574 final public void land() {
3579 bCodeStream[classFileOffset++] = OPC_land;
3580 } catch (IndexOutOfBoundsException e) {
3581 resizeByteArray(OPC_land);
3584 final public void lastore() {
3589 bCodeStream[classFileOffset++] = OPC_lastore;
3590 } catch (IndexOutOfBoundsException e) {
3591 resizeByteArray(OPC_lastore);
3594 final public void lcmp() {
3599 bCodeStream[classFileOffset++] = OPC_lcmp;
3600 } catch (IndexOutOfBoundsException e) {
3601 resizeByteArray(OPC_lcmp);
3604 final public void lconst_0() {
3607 if (stackDepth > stackMax)
3608 stackMax = stackDepth;
3611 bCodeStream[classFileOffset++] = OPC_lconst_0;
3612 } catch (IndexOutOfBoundsException e) {
3613 resizeByteArray(OPC_lconst_0);
3616 final public void lconst_1() {
3619 if (stackDepth > stackMax)
3620 stackMax = stackDepth;
3623 bCodeStream[classFileOffset++] = OPC_lconst_1;
3624 } catch (IndexOutOfBoundsException e) {
3625 resizeByteArray(OPC_lconst_1);
3628 final public void ldc(float constant) {
3630 int index = constantPool.literalIndex(constant);
3632 if (stackDepth > stackMax)
3633 stackMax = stackDepth;
3638 bCodeStream[classFileOffset++] = OPC_ldc_w;
3639 } catch (IndexOutOfBoundsException e) {
3640 resizeByteArray(OPC_ldc_w);
3642 writeUnsignedShort(index);
3647 bCodeStream[classFileOffset++] = OPC_ldc;
3648 } catch (IndexOutOfBoundsException e) {
3649 resizeByteArray(OPC_ldc);
3651 writeUnsignedByte(index);
3654 final public void ldc(int constant) {
3656 int index = constantPool.literalIndex(constant);
3658 if (stackDepth > stackMax)
3659 stackMax = stackDepth;
3664 bCodeStream[classFileOffset++] = OPC_ldc_w;
3665 } catch (IndexOutOfBoundsException e) {
3666 resizeByteArray(OPC_ldc_w);
3668 writeUnsignedShort(index);
3673 bCodeStream[classFileOffset++] = OPC_ldc;
3674 } catch (IndexOutOfBoundsException e) {
3675 resizeByteArray(OPC_ldc);
3677 writeUnsignedByte(index);
3680 final public void ldc(String constant) {
3682 int currentConstantPoolIndex = constantPool.currentIndex;
3683 int currentConstantPoolOffset = constantPool.currentOffset;
3684 int currentCodeStreamPosition = position;
3685 int index = constantPool.literalIndexForLdc(constant.toCharArray());
3687 // the string already exists inside the constant pool
3688 // we reuse the same index
3690 if (stackDepth > stackMax)
3691 stackMax = stackDepth;
3696 bCodeStream[classFileOffset++] = OPC_ldc_w;
3697 } catch (IndexOutOfBoundsException e) {
3698 resizeByteArray(OPC_ldc_w);
3700 writeUnsignedShort(index);
3705 bCodeStream[classFileOffset++] = OPC_ldc;
3706 } catch (IndexOutOfBoundsException e) {
3707 resizeByteArray(OPC_ldc);
3709 writeUnsignedByte(index);
3712 // the string is too big to be utf8-encoded in one pass.
3713 // we have to split it into different pieces.
3714 // first we clean all side-effects due to the code above
3715 // this case is very rare, so we can afford to lose time to handle it
3716 char[] constantChars = constant.toCharArray();
3717 position = currentCodeStreamPosition;
3718 constantPool.currentIndex = currentConstantPoolIndex;
3719 constantPool.currentOffset = currentConstantPoolOffset;
3720 constantPool.stringCache.remove(constantChars);
3721 constantPool.UTF8Cache.remove(constantChars);
3724 int constantLength = constant.length();
3725 byte[] utf8encoding = new byte[Math.min(constantLength + 100, 65535)];
3726 int utf8encodingLength = 0;
3727 while ((length < 65532) && (i < constantLength)) {
3728 char current = constantChars[i];
3729 // we resize the byte array immediately if necessary
3730 if (length + 3 > (utf8encodingLength = utf8encoding.length)) {
3731 System.arraycopy(utf8encoding, 0, (utf8encoding = new byte[Math.min(utf8encodingLength + 100, 65535)]), 0, length);
3733 if ((current >= 0x0001) && (current <= 0x007F)) {
3734 // we only need one byte: ASCII table
3735 utf8encoding[length++] = (byte) current;
3737 if (current > 0x07FF) {
3739 utf8encoding[length++] = (byte) (0xE0 | ((current >> 12) & 0x0F)); // 0xE0 = 1110 0000
3740 utf8encoding[length++] = (byte) (0x80 | ((current >> 6) & 0x3F)); // 0x80 = 1000 0000
3741 utf8encoding[length++] = (byte) (0x80 | (current & 0x3F)); // 0x80 = 1000 0000
3743 // we can be 0 or between 0x0080 and 0x07FF
3744 // In that case we only need 2 bytes
3745 utf8encoding[length++] = (byte) (0xC0 | ((current >> 6) & 0x1F)); // 0xC0 = 1100 0000
3746 utf8encoding[length++] = (byte) (0x80 | (current & 0x3F)); // 0x80 = 1000 0000
3751 // check if all the string is encoded (PR 1PR2DWJ)
3752 // the string is too big to be encoded in one pass
3755 // write the first part
3756 char[] subChars = new char[i];
3757 System.arraycopy(constantChars, 0, subChars, 0, i);
3758 System.arraycopy(utf8encoding, 0, (utf8encoding = new byte[length]), 0, length);
3759 index = constantPool.literalIndex(subChars, utf8encoding);
3761 if (stackDepth > stackMax)
3762 stackMax = stackDepth;
3767 bCodeStream[classFileOffset++] = OPC_ldc_w;
3768 } catch (IndexOutOfBoundsException e) {
3769 resizeByteArray(OPC_ldc_w);
3771 writeUnsignedShort(index);
3776 bCodeStream[classFileOffset++] = OPC_ldc;
3777 } catch (IndexOutOfBoundsException e) {
3778 resizeByteArray(OPC_ldc);
3780 writeUnsignedByte(index);
3782 // write the remaining part
3783 invokeStringBufferStringConstructor();
3784 while (i < constantLength) {
3786 utf8encoding = new byte[Math.min(constantLength - i + 100, 65535)];
3788 while ((length < 65532) && (i < constantLength)) {
3789 char current = constantChars[i];
3790 // we resize the byte array immediately if necessary
3791 if (constantLength + 2 > (utf8encodingLength = utf8encoding.length)) {
3792 System.arraycopy(utf8encoding, 0, (utf8encoding = new byte[Math.min(utf8encodingLength + 100, 65535)]), 0, length);
3794 if ((current >= 0x0001) && (current <= 0x007F)) {
3795 // we only need one byte: ASCII table
3796 utf8encoding[length++] = (byte) current;
3798 if (current > 0x07FF) {
3800 utf8encoding[length++] = (byte) (0xE0 | ((current >> 12) & 0x0F)); // 0xE0 = 1110 0000
3801 utf8encoding[length++] = (byte) (0x80 | ((current >> 6) & 0x3F)); // 0x80 = 1000 0000
3802 utf8encoding[length++] = (byte) (0x80 | (current & 0x3F)); // 0x80 = 1000 0000
3804 // we can be 0 or between 0x0080 and 0x07FF
3805 // In that case we only need 2 bytes
3806 utf8encoding[length++] = (byte) (0xC0 | ((current >> 6) & 0x1F)); // 0xC0 = 1100 0000
3807 utf8encoding[length++] = (byte) (0x80 | (current & 0x3F)); // 0x80 = 1000 0000
3812 // the next part is done
3813 subChars = new char[i - startIndex];
3814 System.arraycopy(constantChars, startIndex, subChars, 0, i - startIndex);
3815 System.arraycopy(utf8encoding, 0, (utf8encoding = new byte[length]), 0, length);
3816 index = constantPool.literalIndex(subChars, utf8encoding);
3818 if (stackDepth > stackMax)
3819 stackMax = stackDepth;
3824 bCodeStream[classFileOffset++] = OPC_ldc_w;
3825 } catch (IndexOutOfBoundsException e) {
3826 resizeByteArray(OPC_ldc_w);
3828 writeUnsignedShort(index);
3833 bCodeStream[classFileOffset++] = OPC_ldc;
3834 } catch (IndexOutOfBoundsException e) {
3835 resizeByteArray(OPC_ldc);
3837 writeUnsignedByte(index);
3839 // now on the stack it should be a StringBuffer and a string.
3840 invokeStringBufferAppendForType(T_String);
3842 invokeStringBufferToString();
3843 invokeStringIntern();
3846 final public void ldc2_w(double constant) {
3848 int index = constantPool.literalIndex(constant);
3850 if (stackDepth > stackMax)
3851 stackMax = stackDepth;
3852 // Generate a ldc2_w
3855 bCodeStream[classFileOffset++] = OPC_ldc2_w;
3856 } catch (IndexOutOfBoundsException e) {
3857 resizeByteArray(OPC_ldc2_w);
3859 writeUnsignedShort(index);
3861 final public void ldc2_w(long constant) {
3863 int index = constantPool.literalIndex(constant);
3865 if (stackDepth > stackMax)
3866 stackMax = stackDepth;
3867 // Generate a ldc2_w
3870 bCodeStream[classFileOffset++] = OPC_ldc2_w;
3871 } catch (IndexOutOfBoundsException e) {
3872 resizeByteArray(OPC_ldc2_w);
3874 writeUnsignedShort(index);
3876 final public void ldiv() {
3881 bCodeStream[classFileOffset++] = OPC_ldiv;
3882 } catch (IndexOutOfBoundsException e) {
3883 resizeByteArray(OPC_ldiv);
3886 final public void lload(int iArg) {
3889 if (maxLocals <= iArg + 1) {
3890 maxLocals = iArg + 2;
3892 if (stackDepth > stackMax)
3893 stackMax = stackDepth;
3894 if (iArg > 255) { // Widen
3897 bCodeStream[classFileOffset++] = OPC_wide;
3898 } catch (IndexOutOfBoundsException e) {
3899 resizeByteArray(OPC_wide);
3903 bCodeStream[classFileOffset++] = OPC_lload;
3904 } catch (IndexOutOfBoundsException e) {
3905 resizeByteArray(OPC_lload);
3907 writeUnsignedShort(iArg);
3911 bCodeStream[classFileOffset++] = OPC_lload;
3912 } catch (IndexOutOfBoundsException e) {
3913 resizeByteArray(OPC_lload);
3917 bCodeStream[classFileOffset++] = (byte) iArg;
3918 } catch (IndexOutOfBoundsException e) {
3919 resizeByteArray((byte) iArg);
3923 final public void lload_0() {
3926 if (maxLocals < 2) {
3929 if (stackDepth > stackMax)
3930 stackMax = stackDepth;
3933 bCodeStream[classFileOffset++] = OPC_lload_0;
3934 } catch (IndexOutOfBoundsException e) {
3935 resizeByteArray(OPC_lload_0);
3938 final public void lload_1() {
3941 if (maxLocals < 3) {
3944 if (stackDepth > stackMax)
3945 stackMax = stackDepth;
3948 bCodeStream[classFileOffset++] = OPC_lload_1;
3949 } catch (IndexOutOfBoundsException e) {
3950 resizeByteArray(OPC_lload_1);
3953 final public void lload_2() {
3956 if (maxLocals < 4) {
3959 if (stackDepth > stackMax)
3960 stackMax = stackDepth;
3963 bCodeStream[classFileOffset++] = OPC_lload_2;
3964 } catch (IndexOutOfBoundsException e) {
3965 resizeByteArray(OPC_lload_2);
3968 final public void lload_3() {
3971 if (maxLocals < 5) {
3974 if (stackDepth > stackMax)
3975 stackMax = stackDepth;
3978 bCodeStream[classFileOffset++] = OPC_lload_3;
3979 } catch (IndexOutOfBoundsException e) {
3980 resizeByteArray(OPC_lload_3);
3983 final public void lmul() {
3988 bCodeStream[classFileOffset++] = OPC_lmul;
3989 } catch (IndexOutOfBoundsException e) {
3990 resizeByteArray(OPC_lmul);
3993 final public void lneg() {
3997 bCodeStream[classFileOffset++] = OPC_lneg;
3998 } catch (IndexOutOfBoundsException e) {
3999 resizeByteArray(OPC_lneg);
4002 public final void load(LocalVariableBinding localBinding) {
4004 TypeBinding typeBinding = localBinding.type;
4005 int resolvedPosition = localBinding.resolvedPosition;
4006 // Using dedicated int bytecode
4007 if (typeBinding == IntBinding) {
4008 switch (resolvedPosition) {
4022 this.iload(resolvedPosition);
4026 // Using dedicated float bytecode
4027 if (typeBinding == FloatBinding) {
4028 switch (resolvedPosition) {
4042 this.fload(resolvedPosition);
4046 // Using dedicated long bytecode
4047 if (typeBinding == LongBinding) {
4048 switch (resolvedPosition) {
4062 this.lload(resolvedPosition);
4066 // Using dedicated double bytecode
4067 if (typeBinding == DoubleBinding) {
4068 switch (resolvedPosition) {
4082 this.dload(resolvedPosition);
4086 // boolean, byte, char and short are handled as int
4087 if ((typeBinding == ByteBinding) || (typeBinding == CharBinding) || (typeBinding == BooleanBinding) || (typeBinding == ShortBinding)) {
4088 switch (resolvedPosition) {
4102 this.iload(resolvedPosition);
4108 switch (resolvedPosition) {
4122 this.aload(resolvedPosition);
4125 public final void load(TypeBinding typeBinding, int resolvedPosition) {
4127 // Using dedicated int bytecode
4128 if (typeBinding == IntBinding) {
4129 switch (resolvedPosition) {
4143 this.iload(resolvedPosition);
4147 // Using dedicated float bytecode
4148 if (typeBinding == FloatBinding) {
4149 switch (resolvedPosition) {
4163 this.fload(resolvedPosition);
4167 // Using dedicated long bytecode
4168 if (typeBinding == LongBinding) {
4169 switch (resolvedPosition) {
4183 this.lload(resolvedPosition);
4187 // Using dedicated double bytecode
4188 if (typeBinding == DoubleBinding) {
4189 switch (resolvedPosition) {
4203 this.dload(resolvedPosition);
4207 // boolean, byte, char and short are handled as int
4208 if ((typeBinding == ByteBinding) || (typeBinding == CharBinding) || (typeBinding == BooleanBinding) || (typeBinding == ShortBinding)) {
4209 switch (resolvedPosition) {
4223 this.iload(resolvedPosition);
4229 switch (resolvedPosition) {
4243 this.aload(resolvedPosition);
4246 public final void loadInt(int resolvedPosition) {
4247 // Using dedicated int bytecode
4248 switch (resolvedPosition) {
4262 this.iload(resolvedPosition);
4265 public final void loadObject(int resolvedPosition) {
4266 switch (resolvedPosition) {
4280 this.aload(resolvedPosition);
4283 final public void lookupswitch(CaseLabel defaultLabel, int[] keys, int[] sortedIndexes, CaseLabel[] casesLabel) {
4286 int length = keys.length;
4288 defaultLabel.placeInstruction();
4289 for (int i = 0; i < length; i++) {
4290 casesLabel[i].placeInstruction();
4294 bCodeStream[classFileOffset++] = OPC_lookupswitch;
4295 } catch (IndexOutOfBoundsException e) {
4296 resizeByteArray(OPC_lookupswitch);
4298 for (int i = (3 - (pos % 4)); i > 0; i--) {
4299 position++; // Padding
4302 defaultLabel.branch();
4303 writeSignedWord(length);
4304 for (int i = 0; i < length; i++) {
4305 writeSignedWord(keys[sortedIndexes[i]]);
4306 casesLabel[sortedIndexes[i]].branch();
4309 final public void lor() {
4314 bCodeStream[classFileOffset++] = OPC_lor;
4315 } catch (IndexOutOfBoundsException e) {
4316 resizeByteArray(OPC_lor);
4319 final public void lrem() {
4324 bCodeStream[classFileOffset++] = OPC_lrem;
4325 } catch (IndexOutOfBoundsException e) {
4326 resizeByteArray(OPC_lrem);
4329 final public void lreturn() {
4332 // the stackDepth should be equal to 0
4335 bCodeStream[classFileOffset++] = OPC_lreturn;
4336 } catch (IndexOutOfBoundsException e) {
4337 resizeByteArray(OPC_lreturn);
4340 final public void lshl() {
4345 bCodeStream[classFileOffset++] = OPC_lshl;
4346 } catch (IndexOutOfBoundsException e) {
4347 resizeByteArray(OPC_lshl);
4350 final public void lshr() {
4355 bCodeStream[classFileOffset++] = OPC_lshr;
4356 } catch (IndexOutOfBoundsException e) {
4357 resizeByteArray(OPC_lshr);
4360 final public void lstore(int iArg) {
4363 if (maxLocals <= iArg + 1) {
4364 maxLocals = iArg + 2;
4366 if (iArg > 255) { // Widen
4369 bCodeStream[classFileOffset++] = OPC_wide;
4370 } catch (IndexOutOfBoundsException e) {
4371 resizeByteArray(OPC_wide);
4375 bCodeStream[classFileOffset++] = OPC_lstore;
4376 } catch (IndexOutOfBoundsException e) {
4377 resizeByteArray(OPC_lstore);
4379 writeUnsignedShort(iArg);
4383 bCodeStream[classFileOffset++] = OPC_lstore;
4384 } catch (IndexOutOfBoundsException e) {
4385 resizeByteArray(OPC_lstore);
4389 bCodeStream[classFileOffset++] = (byte) iArg;
4390 } catch (IndexOutOfBoundsException e) {
4391 resizeByteArray((byte) iArg);
4395 final public void lstore_0() {
4398 if (maxLocals < 2) {
4403 bCodeStream[classFileOffset++] = OPC_lstore_0;
4404 } catch (IndexOutOfBoundsException e) {
4405 resizeByteArray(OPC_lstore_0);
4408 final public void lstore_1() {
4411 if (maxLocals < 3) {
4416 bCodeStream[classFileOffset++] = OPC_lstore_1;
4417 } catch (IndexOutOfBoundsException e) {
4418 resizeByteArray(OPC_lstore_1);
4421 final public void lstore_2() {
4424 if (maxLocals < 4) {
4429 bCodeStream[classFileOffset++] = OPC_lstore_2;
4430 } catch (IndexOutOfBoundsException e) {
4431 resizeByteArray(OPC_lstore_2);
4434 final public void lstore_3() {
4437 if (maxLocals < 5) {
4442 bCodeStream[classFileOffset++] = OPC_lstore_3;
4443 } catch (IndexOutOfBoundsException e) {
4444 resizeByteArray(OPC_lstore_3);
4447 final public void lsub() {
4452 bCodeStream[classFileOffset++] = OPC_lsub;
4453 } catch (IndexOutOfBoundsException e) {
4454 resizeByteArray(OPC_lsub);
4457 final public void lushr() {
4462 bCodeStream[classFileOffset++] = OPC_lushr;
4463 } catch (IndexOutOfBoundsException e) {
4464 resizeByteArray(OPC_lushr);
4467 final public void lxor() {
4472 bCodeStream[classFileOffset++] = OPC_lxor;
4473 } catch (IndexOutOfBoundsException e) {
4474 resizeByteArray(OPC_lxor);
4477 final public void monitorenter() {
4482 bCodeStream[classFileOffset++] = OPC_monitorenter;
4483 } catch (IndexOutOfBoundsException e) {
4484 resizeByteArray(OPC_monitorenter);
4487 final public void monitorexit() {
4492 bCodeStream[classFileOffset++] = OPC_monitorexit;
4493 } catch (IndexOutOfBoundsException e) {
4494 resizeByteArray(OPC_monitorexit);
4497 final public void multianewarray(TypeBinding typeBinding, int dimensions) {
4499 stackDepth += (1 - dimensions);
4502 bCodeStream[classFileOffset++] = OPC_multianewarray;
4503 } catch (IndexOutOfBoundsException e) {
4504 resizeByteArray(OPC_multianewarray);
4506 writeUnsignedShort(constantPool.literalIndex(typeBinding));
4507 writeUnsignedByte(dimensions);
4509 public static void needImplementation() {
4512 * We didn't call it new, because there is a conflit with the new keyword
4514 final public void new_(TypeBinding typeBinding) {
4517 if (stackDepth > stackMax)
4518 stackMax = stackDepth;
4521 bCodeStream[classFileOffset++] = OPC_new;
4522 } catch (IndexOutOfBoundsException e) {
4523 resizeByteArray(OPC_new);
4525 writeUnsignedShort(constantPool.literalIndex(typeBinding));
4527 final public void newarray(int array_Type) {
4531 bCodeStream[classFileOffset++] = OPC_newarray;
4532 } catch (IndexOutOfBoundsException e) {
4533 resizeByteArray(OPC_newarray);
4535 writeUnsignedByte(array_Type);
4537 public void newArray(Scope scope, ArrayBinding arrayBinding) {
4538 TypeBinding component = arrayBinding.elementsType(scope);
4539 switch (component.id) {
4565 this.anewarray(component);
4568 public void newJavaLangError() {
4569 // new: java.lang.Error
4572 if (stackDepth > stackMax)
4573 stackMax = stackDepth;
4576 bCodeStream[classFileOffset++] = OPC_new;
4577 } catch (IndexOutOfBoundsException e) {
4578 resizeByteArray(OPC_new);
4580 writeUnsignedShort(constantPool.literalIndexForJavaLangError());
4583 public void newJavaLangAssertionError() {
4584 // new: java.lang.AssertionError
4587 if (stackDepth > stackMax)
4588 stackMax = stackDepth;
4591 bCodeStream[classFileOffset++] = OPC_new;
4592 } catch (IndexOutOfBoundsException e) {
4593 resizeByteArray(OPC_new);
4595 writeUnsignedShort(constantPool.literalIndexForJavaLangAssertionError());
4598 public void newNoClassDefFoundError() { // new: java.lang.NoClassDefFoundError
4601 if (stackDepth > stackMax)
4602 stackMax = stackDepth;
4605 bCodeStream[classFileOffset++] = OPC_new;
4606 } catch (IndexOutOfBoundsException e) {
4607 resizeByteArray(OPC_new);
4609 writeUnsignedShort(constantPool.literalIndexForJavaLangNoClassDefFoundError());
4611 public void newStringBuffer() { // new: java.lang.StringBuffer
4614 if (stackDepth > stackMax)
4615 stackMax = stackDepth;
4618 bCodeStream[classFileOffset++] = OPC_new;
4619 } catch (IndexOutOfBoundsException e) {
4620 resizeByteArray(OPC_new);
4622 writeUnsignedShort(constantPool.literalIndexForJavaLangStringBuffer());
4624 public void newWrapperFor(int typeID) {
4627 if (stackDepth > stackMax)
4628 stackMax = stackDepth;
4631 bCodeStream[classFileOffset++] = OPC_new;
4632 } catch (IndexOutOfBoundsException e) {
4633 resizeByteArray(OPC_new);
4636 case T_int : // new: java.lang.Integer
4637 writeUnsignedShort(constantPool.literalIndexForJavaLangInteger());
4639 case T_boolean : // new: java.lang.Boolean
4640 writeUnsignedShort(constantPool.literalIndexForJavaLangBoolean());
4642 case T_byte : // new: java.lang.Byte
4643 writeUnsignedShort(constantPool.literalIndexForJavaLangByte());
4645 case T_char : // new: java.lang.Character
4646 writeUnsignedShort(constantPool.literalIndexForJavaLangCharacter());
4648 case T_float : // new: java.lang.Float
4649 writeUnsignedShort(constantPool.literalIndexForJavaLangFloat());
4651 case T_double : // new: java.lang.Double
4652 writeUnsignedShort(constantPool.literalIndexForJavaLangDouble());
4654 case T_short : // new: java.lang.Short
4655 writeUnsignedShort(constantPool.literalIndexForJavaLangShort());
4657 case T_long : // new: java.lang.Long
4658 writeUnsignedShort(constantPool.literalIndexForJavaLangLong());
4660 case T_void : // new: java.lang.Void
4661 writeUnsignedShort(constantPool.literalIndexForJavaLangVoid());
4664 final public void nop() {
4668 bCodeStream[classFileOffset++] = OPC_nop;
4669 } catch (IndexOutOfBoundsException e) {
4670 resizeByteArray(OPC_nop);
4673 final public void pop() {
4678 bCodeStream[classFileOffset++] = OPC_pop;
4679 } catch (IndexOutOfBoundsException e) {
4680 resizeByteArray(OPC_pop);
4683 final public void pop2() {
4688 bCodeStream[classFileOffset++] = OPC_pop2;
4689 } catch (IndexOutOfBoundsException e) {
4690 resizeByteArray(OPC_pop2);
4693 final public void putfield(FieldBinding fieldBinding) {
4696 if (((id = fieldBinding.type.id) == T_double) || (id == T_long))
4700 if (stackDepth > stackMax)
4701 stackMax = stackDepth;
4704 bCodeStream[classFileOffset++] = OPC_putfield;
4705 } catch (IndexOutOfBoundsException e) {
4706 resizeByteArray(OPC_putfield);
4708 writeUnsignedShort(constantPool.literalIndex(fieldBinding));
4710 final public void putstatic(FieldBinding fieldBinding) {
4713 if (((id = fieldBinding.type.id) == T_double) || (id == T_long))
4717 if (stackDepth > stackMax)
4718 stackMax = stackDepth;
4721 bCodeStream[classFileOffset++] = OPC_putstatic;
4722 } catch (IndexOutOfBoundsException e) {
4723 resizeByteArray(OPC_putstatic);
4725 writeUnsignedShort(constantPool.literalIndex(fieldBinding));
4727 public void record(LocalVariableBinding local) {
4728 if (!generateLocalVariableTableAttributes)
4730 if (allLocalsCounter == locals.length) {
4731 // resize the collection
4732 System.arraycopy(locals, 0, (locals = new LocalVariableBinding[allLocalsCounter + LOCALS_INCREMENT]), 0, allLocalsCounter);
4734 locals[allLocalsCounter++] = local;
4735 local.initializationPCs = new int[4];
4736 local.initializationCount = 0;
4738 public void recordPositionsFrom(int startPC, int sourcePos) {
4740 /* Record positions in the table, only if nothing has
4741 * already been recorded. Since we output them on the way
4742 * up (children first for more specific info)
4743 * The pcToSourceMap table is always sorted.
4746 if (!generateLineNumberAttributes)
4751 // no code generated for this node. e.g. field without any initialization
4752 if (position == startPC)
4755 // Widening an existing entry that already has the same source positions
4756 if (pcToSourceMapSize + 4 > pcToSourceMap.length) {
4757 // resize the array pcToSourceMap
4758 System.arraycopy(pcToSourceMap, 0, (pcToSourceMap = new int[pcToSourceMapSize << 1]), 0, pcToSourceMapSize);
4760 int newLine = ClassFile.searchLineNumber(lineSeparatorPositions, sourcePos);
4761 // lastEntryPC represents the endPC of the lastEntry.
4762 if (pcToSourceMapSize > 0) {
4763 // in this case there is already an entry in the table
4764 if (pcToSourceMap[pcToSourceMapSize - 1] != newLine) {
4765 if (startPC < lastEntryPC) {
4766 // we forgot to add an entry.
4767 // search if an existing entry exists for startPC
4768 int insertionIndex = insertionIndex(pcToSourceMap, pcToSourceMapSize, startPC);
4769 if (insertionIndex != -1) {
4770 // there is no existing entry starting with startPC.
4771 int existingEntryIndex = indexOfSameLineEntrySincePC(startPC, newLine); // index for PC
4772 /* the existingEntryIndex corresponds to en entry with the same line and a PC >= startPC.
4773 in this case it is relevant to widen this entry instead of creating a new one.
4777 with this code we generate each argument. We generate a aload0 to invoke the constructor. There is no entry for this
4778 aload0 bytecode. The first entry is the one for the argument a.
4779 But we want the constructor call to start at the aload0 pc and not just at the pc of the first argument.
4780 So we widen the existing entry (if there is one) or we create a new entry with the startPC.
4782 if (existingEntryIndex != -1) {
4783 // widen existing entry
4784 pcToSourceMap[existingEntryIndex] = startPC;
4786 // we have to add an entry that won't be sorted. So we sort the pcToSourceMap.
4787 System.arraycopy(pcToSourceMap, insertionIndex, pcToSourceMap, insertionIndex + 2, pcToSourceMapSize - insertionIndex);
4788 pcToSourceMap[insertionIndex++] = startPC;
4789 pcToSourceMap[insertionIndex] = newLine;
4790 pcToSourceMapSize += 2;
4793 if (position != lastEntryPC) { // no bytecode since last entry pc
4794 pcToSourceMap[pcToSourceMapSize++] = lastEntryPC;
4795 pcToSourceMap[pcToSourceMapSize++] = newLine;
4798 // we can safely add the new entry. The endPC of the previous entry is not in conflit with the startPC of the new entry.
4799 pcToSourceMap[pcToSourceMapSize++] = startPC;
4800 pcToSourceMap[pcToSourceMapSize++] = newLine;
4803 /* the last recorded entry is on the same line. But it could be relevant to widen this entry.
4804 we want to extend this entry forward in case we generated some bytecode before the last entry that are not related to any statement
4806 if (startPC < pcToSourceMap[pcToSourceMapSize - 2]) {
4807 int insertionIndex = insertionIndex(pcToSourceMap, pcToSourceMapSize, startPC);
4808 if (insertionIndex != -1) {
4809 // widen the existing entry
4810 // we have to figure out if we need to move the last entry at another location to keep a sorted table
4811 if ((pcToSourceMapSize > 4) && (pcToSourceMap[pcToSourceMapSize - 4] > startPC)) {
4812 System.arraycopy(pcToSourceMap, insertionIndex, pcToSourceMap, insertionIndex + 2, pcToSourceMapSize - 2 - insertionIndex);
4813 pcToSourceMap[insertionIndex++] = startPC;
4814 pcToSourceMap[insertionIndex] = newLine;
4816 pcToSourceMap[pcToSourceMapSize - 2] = startPC;
4821 lastEntryPC = position;
4823 // record the first entry
4824 pcToSourceMap[pcToSourceMapSize++] = startPC;
4825 pcToSourceMap[pcToSourceMapSize++] = newLine;
4826 lastEntryPC = position;
4830 * @param anExceptionLabel org.eclipse.jdt.internal.compiler.codegen.ExceptionLabel
4832 public void registerExceptionHandler(ExceptionLabel anExceptionLabel) {
4834 if (exceptionHandlersNumber >= (length = exceptionHandlers.length)) {
4835 // resize the exception handlers table
4836 System.arraycopy(exceptionHandlers, 0, exceptionHandlers = new ExceptionLabel[length + LABELS_INCREMENT], 0, length);
4838 // no need to resize. So just add the new exception label
4839 exceptionHandlers[exceptionHandlersNumber++] = anExceptionLabel;
4841 public final void removeNotDefinitelyAssignedVariables(Scope scope, int initStateIndex) {
4842 // given some flow info, make sure we did not loose some variables initialization
4843 // if this happens, then we must update their pc entries to reflect it in debug attributes
4844 if (!generateLocalVariableTableAttributes)
4846 /* if (initStateIndex == lastInitStateIndexWhenRemovingInits)
4849 lastInitStateIndexWhenRemovingInits = initStateIndex;
4850 if (lastInitStateIndexWhenAddingInits != initStateIndex){
4851 lastInitStateIndexWhenAddingInits = -2;// reinitialize add index
4852 // add(1)-remove(1)-add(1) -> ignore second add
4853 // add(1)-remove(2)-add(1) -> perform second add
4855 for (int i = 0; i < visibleLocalsCount; i++) {
4856 LocalVariableBinding localBinding = visibleLocals[i];
4857 if (localBinding != null) {
4858 if (initStateIndex == -1 || !isDefinitelyAssigned(scope, initStateIndex, localBinding)) {
4859 if (localBinding.initializationCount > 0) {
4860 localBinding.recordInitializationEndPC(position);
4867 * @param methodDeclaration org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration
4868 * @param classFile org.eclipse.jdt.internal.compiler.codegen.ClassFile
4870 public void reset(AbstractMethodDeclaration methodDeclaration, ClassFile classFile) {
4872 this.methodDeclaration = methodDeclaration;
4873 preserveUnusedLocals = methodDeclaration.scope.problemReporter().options.preserveAllLocalVariables;
4874 initializeMaxLocals(methodDeclaration.binding);
4877 * @param methodDeclaration org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration
4878 * @param classFile org.eclipse.jdt.internal.compiler.codegen.ClassFile
4880 public void resetForProblemClinit(ClassFile classFile) {
4884 protected final void resizeByteArray() {
4885 int actualLength = bCodeStream.length;
4886 int requiredSize = actualLength + growFactor;
4887 if (classFileOffset > requiredSize) {
4888 requiredSize = classFileOffset + growFactor;
4890 System.arraycopy(bCodeStream, 0, (bCodeStream = new byte[requiredSize]), 0, actualLength);
4893 * This method is used to resize the internal byte array in
4894 * case of a ArrayOutOfBoundsException when adding the value b.
4895 * Resize and add the new byte b inside the array.
4898 protected final void resizeByteArray(byte b) {
4900 bCodeStream[classFileOffset - 1] = b;
4902 final public void ret(int index) {
4904 if (index > 255) { // Widen
4907 bCodeStream[classFileOffset++] = OPC_wide;
4908 } catch (IndexOutOfBoundsException e) {
4909 resizeByteArray(OPC_wide);
4913 bCodeStream[classFileOffset++] = OPC_ret;
4914 } catch (IndexOutOfBoundsException e) {
4915 resizeByteArray(OPC_ret);
4917 writeUnsignedShort(index);
4918 } else { // Don't Widen
4921 bCodeStream[classFileOffset++] = OPC_ret;
4922 } catch (IndexOutOfBoundsException e) {
4923 resizeByteArray(OPC_ret);
4927 bCodeStream[classFileOffset++] = (byte) index;
4928 } catch (IndexOutOfBoundsException e) {
4929 resizeByteArray((byte) index);
4933 final public void return_() {
4935 // the stackDepth should be equal to 0
4938 bCodeStream[classFileOffset++] = OPC_return;
4939 } catch (IndexOutOfBoundsException e) {
4940 resizeByteArray(OPC_return);
4943 final public void saload() {
4948 bCodeStream[classFileOffset++] = OPC_saload;
4949 } catch (IndexOutOfBoundsException e) {
4950 resizeByteArray(OPC_saload);
4953 final public void sastore() {
4958 bCodeStream[classFileOffset++] = OPC_sastore;
4959 } catch (IndexOutOfBoundsException e) {
4960 resizeByteArray(OPC_sastore);
4964 * @param operatorConstant int
4965 * @param type_ID int
4967 public void sendOperator(int operatorConstant, int type_ID) {
4974 switch (operatorConstant) {
4996 case UNSIGNED_RIGHT_SHIFT :
5011 switch (operatorConstant) {
5033 case UNSIGNED_RIGHT_SHIFT :
5048 switch (operatorConstant) {
5066 switch (operatorConstant) {
5084 final public void sipush(int s) {
5087 if (stackDepth > stackMax)
5088 stackMax = stackDepth;
5091 bCodeStream[classFileOffset++] = OPC_sipush;
5092 } catch (IndexOutOfBoundsException e) {
5093 resizeByteArray(OPC_sipush);
5095 writeSignedShort(s);
5097 public static final void sort(int[] tab, int lo0, int hi0, int[] result) {
5102 /* Arbitrarily establishing partition element as the midpoint of
5105 mid = tab[ (lo0 + hi0) / 2];
5106 // loop through the array until indices cross
5108 /* find the first element that is greater than or equal to
5109 * the partition element starting from the left Index.
5111 while ((lo < hi0) && (tab[lo] < mid))
5113 /* find an element that is smaller than or equal to
5114 * the partition element starting from the right Index.
5116 while ((hi > lo0) && (tab[hi] > mid))
5118 // if the indexes have not crossed, swap
5120 swap(tab, lo, hi, result);
5125 /* If the right index has not reached the left side of array
5126 * must now sort the left partition.
5129 sort(tab, lo0, hi, result);
5130 /* If the left index has not reached the right side of array
5131 * must now sort the right partition.
5134 sort(tab, lo, hi0, result);
5137 public final void store(LocalVariableBinding localBinding, boolean valueRequired) {
5138 TypeBinding type = localBinding.type;
5139 int position = localBinding.resolvedPosition;
5140 // Using dedicated int bytecode
5141 if ((type == IntBinding) || (type == CharBinding) || (type == ByteBinding) || (type == ShortBinding) || (type == BooleanBinding)) {
5158 this.istore(position);
5162 // Using dedicated float bytecode
5163 if (type == FloatBinding) {
5180 this.fstore(position);
5184 // Using dedicated long bytecode
5185 if (type == LongBinding) {
5202 this.lstore(position);
5206 // Using dedicated double bytecode
5207 if (type == DoubleBinding) {
5224 this.dstore(position);
5245 this.astore(position);
5248 public final void store(TypeBinding type, int position) {
5249 // Using dedicated int bytecode
5250 if ((type == IntBinding) || (type == CharBinding) || (type == ByteBinding) || (type == ShortBinding) || (type == BooleanBinding)) {
5265 this.istore(position);
5269 // Using dedicated float bytecode
5270 if (type == FloatBinding) {
5285 this.fstore(position);
5289 // Using dedicated long bytecode
5290 if (type == LongBinding) {
5305 this.lstore(position);
5309 // Using dedicated double bytecode
5310 if (type == DoubleBinding) {
5325 this.dstore(position);
5344 this.astore(position);
5347 public final void storeInt(int position) {
5362 this.istore(position);
5365 public final void storeObject(int position) {
5380 this.astore(position);
5383 final public void swap() {
5387 bCodeStream[classFileOffset++] = OPC_swap;
5388 } catch (IndexOutOfBoundsException e) {
5389 resizeByteArray(OPC_swap);
5392 private static final void swap(int a[], int i, int j, int result[]) {
5398 result[j] = result[i];
5401 final public void tableswitch(CaseLabel defaultLabel, int low, int high, int[] keys, int[] sortedIndexes, CaseLabel[] casesLabel) {
5404 int length = casesLabel.length;
5406 defaultLabel.placeInstruction();
5407 for (int i = 0; i < length; i++)
5408 casesLabel[i].placeInstruction();
5411 bCodeStream[classFileOffset++] = OPC_tableswitch;
5412 } catch (IndexOutOfBoundsException e) {
5413 resizeByteArray(OPC_tableswitch);
5415 for (int i = (3 - (pos % 4)); i > 0; i--) {
5416 position++; // Padding
5419 defaultLabel.branch();
5420 writeSignedWord(low);
5421 writeSignedWord(high);
5422 int i = low, j = low;
5423 // the index j is used to know if the index i is one of the missing entries in case of an
5424 // optimized tableswitch
5427 int key = keys[index = sortedIndexes[j - low]];
5429 casesLabel[index].branch();
5431 if (i == high) break; // if high is maxint, then avoids wrapping to minint.
5433 defaultLabel.branch();
5438 public String toString() {
5439 StringBuffer buffer = new StringBuffer("( position:"); //$NON-NLS-1$
5440 buffer.append(position);
5441 buffer.append(",\nstackDepth:"); //$NON-NLS-1$
5442 buffer.append(stackDepth);
5443 buffer.append(",\nmaxStack:"); //$NON-NLS-1$
5444 buffer.append(stackMax);
5445 buffer.append(",\nmaxLocals:"); //$NON-NLS-1$
5446 buffer.append(maxLocals);
5447 buffer.append(")"); //$NON-NLS-1$
5448 return buffer.toString();
5450 public void updateLastRecordedEndPC(int pos) {
5452 /* Tune positions in the table, this is due to some
5453 * extra bytecodes being
5454 * added to some user code (jumps). */
5456 if (!generateLineNumberAttributes)
5458 pcToSourceMap[pcToSourceMapSize - 1][1] = position;
5459 // need to update the initialization endPC in case of generation of local variable attributes.
5460 updateLocalVariablesAttribute(pos);
5463 if (!generateLineNumberAttributes)
5465 // need to update the initialization endPC in case of generation of local variable attributes.
5466 updateLocalVariablesAttribute(pos);
5468 public void updateLocalVariablesAttribute(int pos) {
5469 // need to update the initialization endPC in case of generation of local variable attributes.
5470 if (generateLocalVariableTableAttributes) {
5471 for (int i = 0, max = locals.length; i < max; i++) {
5472 LocalVariableBinding local = locals[i];
5473 if ((local != null) && (local.initializationCount > 0)) {
5474 if (local.initializationPCs[((local.initializationCount - 1) << 1) + 1] == pos) {
5475 local.initializationPCs[((local.initializationCount - 1) << 1) + 1] = position;
5481 final public void wide() {
5485 bCodeStream[classFileOffset++] = OPC_wide;
5486 } catch (IndexOutOfBoundsException e) {
5487 resizeByteArray(OPC_wide);
5490 public final void writeByte(byte b) {
5493 bCodeStream[classFileOffset++] = b;
5494 } catch (IndexOutOfBoundsException e) {
5498 public final void writeByteAtPos(int pos, byte b) {
5500 bCodeStream[pos] = b;
5501 } catch (IndexOutOfBoundsException ex) {
5503 bCodeStream[pos] = b;
5507 * Write a unsigned 8 bits value into the byte array
5508 * @param b the signed byte
5510 public final void writeSignedByte(int b) {
5513 bCodeStream[classFileOffset++] = (byte) b;
5514 } catch (IndexOutOfBoundsException e) {
5515 resizeByteArray((byte) b);
5519 * Write a signed 16 bits value into the byte array
5520 * @param b the signed short
5522 public final void writeSignedShort(int b) {
5525 bCodeStream[classFileOffset++] = (byte) (b >> 8);
5526 } catch (IndexOutOfBoundsException e) {
5527 resizeByteArray((byte) (b >> 8));
5531 bCodeStream[classFileOffset++] = (byte) b;
5532 } catch (IndexOutOfBoundsException e) {
5533 resizeByteArray((byte) b);
5536 public final void writeSignedShort(int pos, int b) {
5537 int currentOffset = startingClassFileOffset + pos;
5539 bCodeStream[currentOffset] = (byte) (b >> 8);
5540 } catch (IndexOutOfBoundsException e) {
5542 bCodeStream[currentOffset] = (byte) (b >> 8);
5545 bCodeStream[currentOffset + 1] = (byte) b;
5546 } catch (IndexOutOfBoundsException e) {
5548 bCodeStream[currentOffset + 1] = (byte) b;
5551 public final void writeSignedWord(int value) {
5554 bCodeStream[classFileOffset++] = (byte) ((value & 0xFF000000) >> 24);
5555 } catch (IndexOutOfBoundsException e) {
5556 resizeByteArray((byte) ((value & 0xFF000000) >> 24));
5560 bCodeStream[classFileOffset++] = (byte) ((value & 0xFF0000) >> 16);
5561 } catch (IndexOutOfBoundsException e) {
5562 resizeByteArray((byte) ((value & 0xFF0000) >> 16));
5566 bCodeStream[classFileOffset++] = (byte) ((value & 0xFF00) >> 8);
5567 } catch (IndexOutOfBoundsException e) {
5568 resizeByteArray((byte) ((value & 0xFF00) >> 8));
5572 bCodeStream[classFileOffset++] = (byte) (value & 0xFF);
5573 } catch (IndexOutOfBoundsException e) {
5574 resizeByteArray((byte) (value & 0xFF));
5577 public final void writeSignedWord(int pos, int value) {
5578 int currentOffset = startingClassFileOffset + pos;
5580 bCodeStream[currentOffset++] = (byte) ((value & 0xFF000000) >> 24);
5581 } catch (IndexOutOfBoundsException e) {
5583 bCodeStream[currentOffset-1] = (byte) ((value & 0xFF000000) >> 24);
5586 bCodeStream[currentOffset++] = (byte) ((value & 0xFF0000) >> 16);
5587 } catch (IndexOutOfBoundsException e) {
5589 bCodeStream[currentOffset-1] = (byte) ((value & 0xFF0000) >> 16);
5592 bCodeStream[currentOffset++] = (byte) ((value & 0xFF00) >> 8);
5593 } catch (IndexOutOfBoundsException e) {
5595 bCodeStream[currentOffset-1] = (byte) ((value & 0xFF00) >> 8);
5598 bCodeStream[currentOffset++] = (byte) (value & 0xFF);
5599 } catch (IndexOutOfBoundsException e) {
5601 bCodeStream[currentOffset-1] = (byte) (value & 0xFF);
5605 * Write a unsigned 8 bits value into the byte array
5606 * @param b the unsigned byte
5608 public final void writeUnsignedByte(int b) {
5611 bCodeStream[classFileOffset++] = (byte) b;
5612 } catch (IndexOutOfBoundsException e) {
5613 resizeByteArray((byte) b);
5617 * Write a unsigned 16 bits value into the byte array
5618 * @param b the unsigned short
5620 public final void writeUnsignedShort(int b) {
5623 bCodeStream[classFileOffset++] = (byte) (b >>> 8);
5624 } catch (IndexOutOfBoundsException e) {
5625 resizeByteArray((byte) (b >>> 8));
5629 bCodeStream[classFileOffset++] = (byte) b;
5630 } catch (IndexOutOfBoundsException e) {
5631 resizeByteArray((byte) b);
5635 * Write a unsigned 32 bits value into the byte array
5636 * @param value the unsigned word
5638 public final void writeUnsignedWord(int value) {
5641 bCodeStream[classFileOffset++] = (byte) (value >>> 24);
5642 } catch (IndexOutOfBoundsException e) {
5643 resizeByteArray((byte) (value >>> 24));
5647 bCodeStream[classFileOffset++] = (byte) (value >>> 16);
5648 } catch (IndexOutOfBoundsException e) {
5649 resizeByteArray((byte) (value >>> 16));
5653 bCodeStream[classFileOffset++] = (byte) (value >>> 8);
5654 } catch (IndexOutOfBoundsException e) {
5655 resizeByteArray((byte) (value >>> 8));
5659 bCodeStream[classFileOffset++] = (byte) value;
5660 } catch (IndexOutOfBoundsException e) {
5661 resizeByteArray((byte) value);
5665 public void generateWideConditionalBranch(byte opcode, Label lbl) {
5666 /* we handle the goto_w problem inside an if.... with some macro expansion
5667 * at the bytecode level
5673 * l1 gotow <l3> // l3 is a wide target
5676 Label l1 = new Label(this);
5679 bCodeStream[classFileOffset++] = opcode;
5680 } catch (IndexOutOfBoundsException e) {
5681 resizeByteArray(opcode);
5684 Label l2 = new Label(this);
5685 this.internal_goto_(l2);