Makefile fixup
[org.ibex.tool.git] / repo / org.ibex.tool / src / org / eclipse / jdt / internal / compiler / codegen / CodeStream.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package org.eclipse.jdt.internal.compiler.codegen;
12
13 import org.eclipse.jdt.internal.compiler.*;
14
15 import org.eclipse.jdt.internal.compiler.impl.*;
16 import org.eclipse.jdt.internal.compiler.ast.*;
17 import org.eclipse.jdt.internal.compiler.classfmt.*;
18 import org.eclipse.jdt.internal.compiler.flow.*;
19 import org.eclipse.jdt.internal.compiler.lookup.*;
20
21 public class CodeStream implements OperatorIds, ClassFileConstants, Opcodes, BaseTypes, TypeConstants, TypeIds {
22
23         public static final boolean DEBUG = false;
24         
25         // It will be responsible for the following items.
26         // -> Tracking Max Stack.
27
28         public int stackMax; // Use Ints to keep from using extra bc when adding
29         public int stackDepth; // Use Ints to keep from using extra bc when adding
30         public int maxLocals;
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;
64         // to handle goto_w
65         public boolean wideMode = false;
66         public static final CompilationResult RESTART_IN_WIDE_MODE = new CompilationResult((char[])null, 0, 0, 0);
67         
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;
73         }
74 }
75 final public void aaload() {
76         if (DEBUG) System.out.println(position + "\t\taaload"); //$NON-NLS-1$
77         countLabels = 0;
78         stackDepth--;
79         if (classFileOffset >= bCodeStream.length) {
80                 resizeByteArray();
81         }
82         position++;
83         bCodeStream[classFileOffset++] = OPC_aaload;
84 }
85 final public void aastore() {
86         if (DEBUG) System.out.println(position + "\t\taastore"); //$NON-NLS-1$
87         countLabels = 0;
88         stackDepth -= 3;
89         if (classFileOffset >= bCodeStream.length) {
90                 resizeByteArray();
91         }
92         position++;
93         bCodeStream[classFileOffset++] = OPC_aastore;
94 }
95 final public void aconst_null() {
96         if (DEBUG) System.out.println(position + "\t\taconst_null"); //$NON-NLS-1$
97         countLabels = 0;
98         stackDepth++;
99         if (stackDepth > stackMax) {
100                 stackMax = stackDepth;
101         }
102         if (classFileOffset >= bCodeStream.length) {
103                 resizeByteArray();
104         }
105         position++;
106         bCodeStream[classFileOffset++] = OPC_aconst_null;
107 }
108 public final void addDefinitelyAssignedVariables(Scope scope, int initStateIndex) {
109         // Required to fix 1PR0XVS: LFRE:WINNT - Compiler: variable table for method appears incorrect
110         if (!generateLocalVariableTableAttributes)
111                 return;
112 /*      if (initStateIndex == lastInitStateIndexWhenAddingInits)
113                 return;
114         lastInitStateIndexWhenAddingInits = initStateIndex;
115         if (lastInitStateIndexWhenRemovingInits != initStateIndex){
116                 lastInitStateIndexWhenRemovingInits = -2; // reinitialize remove index 
117                 // remove(1)-add(1)-remove(1) -> ignore second remove
118                 // remove(1)-add(2)-remove(1) -> perform second remove
119         }
120         
121 */      for (int i = 0; i < visibleLocalsCount; i++) {
122                 LocalVariableBinding localBinding = visibleLocals[i];
123                 if (localBinding != null) {
124                         // Check if the local is definitely assigned
125                         if ((initStateIndex != -1) && isDefinitelyAssigned(scope, initStateIndex, localBinding)) {
126                                 if ((localBinding.initializationCount == 0) || (localBinding.initializationPCs[((localBinding.initializationCount - 1) << 1) + 1] != -1)) {
127                                         /* There are two cases:
128                                          * 1) there is no initialization interval opened ==> add an opened interval
129                                          * 2) there is already some initialization intervals but the last one is closed ==> add an opened interval
130                                          * An opened interval means that the value at localBinding.initializationPCs[localBinding.initializationCount - 1][1]
131                                          * is equals to -1.
132                                          * initializationPCs is a collection of pairs of int:
133                                          *      first value is the startPC and second value is the endPC. -1 one for the last value means that the interval
134                                          *      is not closed yet.
135                                          */
136                                         localBinding.recordInitializationStartPC(position);
137                                 }
138                         }
139                 }
140         }
141 }
142 public void addLabel(Label aLabel) {
143         if (countLabels == labels.length)
144                 System.arraycopy(labels, 0, labels = new Label[countLabels + LABELS_INCREMENT], 0, countLabels);
145         labels[countLabels++] = aLabel;
146 }
147 public void addVisibleLocalVariable(LocalVariableBinding localBinding) {
148         if (!generateLocalVariableTableAttributes)
149                 return;
150
151         if (visibleLocalsCount >= visibleLocals.length)
152                 System.arraycopy(visibleLocals, 0, visibleLocals = new LocalVariableBinding[visibleLocalsCount * 2], 0, visibleLocalsCount);
153         visibleLocals[visibleLocalsCount++] = localBinding;
154 }
155 final public void aload(int iArg) {
156         if (DEBUG) System.out.println(position + "\t\taload:"+iArg); //$NON-NLS-1$
157         countLabels = 0;
158         stackDepth++;
159         if (stackDepth > stackMax)
160                 stackMax = stackDepth;
161         if (maxLocals <= iArg) {
162                 maxLocals = iArg + 1;
163         }
164         if (iArg > 255) { // Widen
165                 if (classFileOffset + 3 >= bCodeStream.length) {
166                         resizeByteArray();
167                 }
168                 position += 2;
169                 bCodeStream[classFileOffset++] = OPC_wide;
170                 bCodeStream[classFileOffset++] = OPC_aload;
171                 writeUnsignedShort(iArg);
172         } else {
173                 // Don't need to use the wide bytecode
174                 if (classFileOffset + 1 >= bCodeStream.length) {
175                         resizeByteArray();
176                 }
177                 position += 2;
178                 bCodeStream[classFileOffset++] = OPC_aload;
179                 bCodeStream[classFileOffset++] = (byte) iArg;
180         }
181 }
182 final public void aload_0() {
183         if (DEBUG) System.out.println(position + "\t\taload_0"); //$NON-NLS-1$
184         countLabels = 0;
185         stackDepth++;
186         if (stackDepth > stackMax) {
187                 stackMax = stackDepth;
188         }
189         if (maxLocals == 0) {
190                 maxLocals = 1;
191         }
192         if (classFileOffset >= bCodeStream.length) {
193                 resizeByteArray();
194         }
195         position++;
196         bCodeStream[classFileOffset++] = OPC_aload_0;
197 }
198 final public void aload_1() {
199         if (DEBUG) System.out.println(position + "\t\taload_1"); //$NON-NLS-1$
200         countLabels = 0;
201         stackDepth++;
202         if (stackDepth > stackMax)
203                 stackMax = stackDepth;
204         if (maxLocals <= 1) {
205                 maxLocals = 2;
206         }
207         if (classFileOffset >= bCodeStream.length) {
208                 resizeByteArray();
209         }
210         position++;
211         bCodeStream[classFileOffset++] = OPC_aload_1;
212 }
213 final public void aload_2() {
214         if (DEBUG) System.out.println(position + "\t\taload_2"); //$NON-NLS-1$
215         countLabels = 0;
216         stackDepth++;
217         if (stackDepth > stackMax)
218                 stackMax = stackDepth;
219         if (maxLocals <= 2) {
220                 maxLocals = 3;
221         }
222         if (classFileOffset >= bCodeStream.length) {
223                 resizeByteArray();
224         }
225         position++;
226         bCodeStream[classFileOffset++] = OPC_aload_2;
227 }
228 final public void aload_3() {
229         if (DEBUG) System.out.println(position + "\t\taload_3"); //$NON-NLS-1$
230         countLabels = 0;
231         stackDepth++;
232         if (stackDepth > stackMax)
233                 stackMax = stackDepth;
234         if (maxLocals <= 3) {
235                 maxLocals = 4;
236         }
237         if (classFileOffset >= bCodeStream.length) {
238                 resizeByteArray();
239         }
240         position++;
241         bCodeStream[classFileOffset++] = OPC_aload_3;
242 }
243 public final void anewarray(TypeBinding typeBinding) {
244         if (DEBUG) System.out.println(position + "\t\tanewarray: " + typeBinding); //$NON-NLS-1$
245         countLabels = 0;
246         if (classFileOffset + 2 >= bCodeStream.length) {
247                 resizeByteArray();
248         }
249         position++;
250         bCodeStream[classFileOffset++] = OPC_anewarray;
251         writeUnsignedShort(constantPool.literalIndex(typeBinding));
252 }
253 final public void areturn() {
254         if (DEBUG) System.out.println(position + "\t\tareturn"); //$NON-NLS-1$
255         countLabels = 0;
256         stackDepth--;
257         // the stackDepth should be equal to 0 
258         if (classFileOffset >= bCodeStream.length) {
259                 resizeByteArray();
260         }
261         position++;
262         bCodeStream[classFileOffset++] = OPC_areturn;
263 }
264 public void arrayAt(int typeBindingID) {
265         switch (typeBindingID) {
266                 case T_int :
267                         this.iaload();
268                         break;
269                 case T_byte :
270                 case T_boolean :
271                         this.baload();
272                         break;
273                 case T_short :
274                         this.saload();
275                         break;
276                 case T_char :
277                         this.caload();
278                         break;
279                 case T_long :
280                         this.laload();
281                         break;
282                 case T_float :
283                         this.faload();
284                         break;
285                 case T_double :
286                         this.daload();
287                         break;
288                 default :
289                         this.aaload();
290         }
291 }
292 public void arrayAtPut(int elementTypeID, boolean valueRequired) {
293         switch (elementTypeID) {
294                 case T_int :
295                         if (valueRequired)
296                                 dup_x2();
297                         iastore();
298                         break;
299                 case T_byte :
300                 case T_boolean :
301                         if (valueRequired)
302                                 dup_x2();
303                         bastore();
304                         break;
305                 case T_short :
306                         if (valueRequired)
307                                 dup_x2();
308                         sastore();
309                         break;
310                 case T_char :
311                         if (valueRequired)
312                                 dup_x2();
313                         castore();
314                         break;
315                 case T_long :
316                         if (valueRequired)
317                                 dup2_x2();
318                         lastore();
319                         break;
320                 case T_float :
321                         if (valueRequired)
322                                 dup_x2();
323                         fastore();
324                         break;
325                 case T_double :
326                         if (valueRequired)
327                                 dup2_x2();
328                         dastore();
329                         break;
330                 default :
331                         if (valueRequired)
332                                 dup_x2();
333                         aastore();
334         }
335 }
336 final public void arraylength() {
337         if (DEBUG) System.out.println(position + "\t\tarraylength"); //$NON-NLS-1$
338         countLabels = 0;
339         if (classFileOffset >= bCodeStream.length) {
340                 resizeByteArray();
341         }
342         position++;
343         bCodeStream[classFileOffset++] = OPC_arraylength;
344 }
345 final public void astore(int iArg) {
346         if (DEBUG) System.out.println(position + "\t\tastore:"+iArg); //$NON-NLS-1$
347         countLabels = 0;
348         stackDepth--;
349         if (maxLocals <= iArg) {
350                 maxLocals = iArg + 1;
351         }
352         if (iArg > 255) { // Widen
353                 if (classFileOffset + 3 >= bCodeStream.length) {
354                         resizeByteArray();
355                 }
356                 position+=2;
357                 bCodeStream[classFileOffset++] = OPC_wide;
358                 bCodeStream[classFileOffset++] = OPC_astore;
359                 writeUnsignedShort(iArg);
360         } else {
361                 if (classFileOffset + 1 >= bCodeStream.length) {
362                         resizeByteArray();
363                 }
364                 position+=2;
365                 bCodeStream[classFileOffset++] = OPC_astore;
366                 bCodeStream[classFileOffset++] = (byte) iArg;
367         }
368 }
369 final public void astore_0() {
370         if (DEBUG) System.out.println(position + "\t\tastore_0"); //$NON-NLS-1$
371         countLabels = 0;
372         stackDepth--;
373         if (maxLocals == 0) {
374                 maxLocals = 1;
375         }
376         if (classFileOffset >= bCodeStream.length) {
377                 resizeByteArray();
378         }
379         position++;
380         bCodeStream[classFileOffset++] = OPC_astore_0;
381 }
382 final public void astore_1() {
383         if (DEBUG) System.out.println(position + "\t\tastore_1"); //$NON-NLS-1$
384         countLabels = 0;
385         stackDepth--;
386         if (maxLocals <= 1) {
387                 maxLocals = 2;
388         }
389         if (classFileOffset >= bCodeStream.length) {
390                 resizeByteArray();
391         }
392         position++;
393         bCodeStream[classFileOffset++] = OPC_astore_1;
394 }
395 final public void astore_2() {
396         if (DEBUG) System.out.println(position + "\t\tastore_2"); //$NON-NLS-1$
397         countLabels = 0;
398         stackDepth--;
399         if (maxLocals <= 2) {
400                 maxLocals = 3;
401         }
402         if (classFileOffset >= bCodeStream.length) {
403                 resizeByteArray();
404         }
405         position++;
406         bCodeStream[classFileOffset++] = OPC_astore_2;
407 }
408 final public void astore_3() {
409         if (DEBUG) System.out.println(position + "\t\tastore_3"); //$NON-NLS-1$
410         countLabels = 0;
411         stackDepth--;
412         if (maxLocals <= 3) {
413                 maxLocals = 4;
414         }
415         if (classFileOffset >= bCodeStream.length) {
416                 resizeByteArray();
417         }
418         position++;
419         bCodeStream[classFileOffset++] = OPC_astore_3;
420 }
421 final public void athrow() {
422         if (DEBUG) System.out.println(position + "\t\tathrow"); //$NON-NLS-1$
423         countLabels = 0;
424         stackDepth--;
425         if (classFileOffset >= bCodeStream.length) {
426                 resizeByteArray();
427         }
428         position++;
429         bCodeStream[classFileOffset++] = OPC_athrow;
430 }
431 final public void baload() {
432         if (DEBUG) System.out.println(position + "\t\tbaload"); //$NON-NLS-1$
433         countLabels = 0;
434         stackDepth--;
435         if (classFileOffset >= bCodeStream.length) {
436                 resizeByteArray();
437         }
438         position++;
439         bCodeStream[classFileOffset++] = OPC_baload;
440 }
441 final public void bastore() {
442         if (DEBUG) System.out.println(position + "\t\tbastore"); //$NON-NLS-1$
443         countLabels = 0;
444         stackDepth -= 3;
445         if (classFileOffset >= bCodeStream.length) {
446                 resizeByteArray();
447         }
448         position++;
449         bCodeStream[classFileOffset++] = OPC_bastore;
450 }
451 final public void bipush(byte b) {
452         if (DEBUG) System.out.println(position + "\t\tbipush "+b); //$NON-NLS-1$
453         countLabels = 0;
454         stackDepth++;
455         if (stackDepth > stackMax)
456                 stackMax = stackDepth;
457         if (classFileOffset + 1 >= bCodeStream.length) {
458                 resizeByteArray();
459         }
460         position += 2;
461         bCodeStream[classFileOffset++] = OPC_bipush;
462         bCodeStream[classFileOffset++] = b;
463 }
464 final public void caload() {
465         if (DEBUG) System.out.println(position + "\t\tcaload"); //$NON-NLS-1$
466         countLabels = 0;
467         stackDepth--;
468         if (classFileOffset >= bCodeStream.length) {
469                 resizeByteArray();
470         }
471         position++;
472         bCodeStream[classFileOffset++] = OPC_caload;
473 }
474 final public void castore() {
475         if (DEBUG) System.out.println(position + "\t\tcastore"); //$NON-NLS-1$
476         countLabels = 0;
477         stackDepth -= 3;
478         if (classFileOffset >= bCodeStream.length) {
479                 resizeByteArray();
480         }
481         position++;
482         bCodeStream[classFileOffset++] = OPC_castore;
483 }
484 public final void checkcast(TypeBinding typeBinding) {
485         if (DEBUG) System.out.println(position + "\t\tcheckcast:"+typeBinding); //$NON-NLS-1$
486         countLabels = 0;
487         if (classFileOffset + 2 >= bCodeStream.length) {
488                 resizeByteArray();
489         }
490         position++;
491         bCodeStream[classFileOffset++] = OPC_checkcast;
492         writeUnsignedShort(constantPool.literalIndex(typeBinding));
493 }
494 final public void d2f() {
495         if (DEBUG) System.out.println(position + "\t\td2f"); //$NON-NLS-1$
496         countLabels = 0;
497         stackDepth--;
498         if (classFileOffset >= bCodeStream.length) {
499                 resizeByteArray();
500         }
501         position++;
502         bCodeStream[classFileOffset++] = OPC_d2f;
503 }
504 final public void d2i() {
505         if (DEBUG) System.out.println(position + "\t\td2i"); //$NON-NLS-1$
506         countLabels = 0;
507         stackDepth--;
508         if (classFileOffset >= bCodeStream.length) {
509                 resizeByteArray();
510         }
511         position++;
512         bCodeStream[classFileOffset++] = OPC_d2i;
513 }
514 final public void d2l() {
515         if (DEBUG) System.out.println(position + "\t\td2l"); //$NON-NLS-1$
516         countLabels = 0;
517         if (classFileOffset >= bCodeStream.length) {
518                 resizeByteArray();
519         }
520         position++;
521         bCodeStream[classFileOffset++] = OPC_d2l;
522 }
523 final public void dadd() {
524         if (DEBUG) System.out.println(position + "\t\tdadd"); //$NON-NLS-1$
525         countLabels = 0;
526         stackDepth -= 2;
527         if (classFileOffset >= bCodeStream.length) {
528                 resizeByteArray();
529         }
530         position++;
531         bCodeStream[classFileOffset++] = OPC_dadd;
532 }
533 final public void daload() {
534         if (DEBUG) System.out.println(position + "\t\tdaload"); //$NON-NLS-1$
535         countLabels = 0;
536         if (classFileOffset >= bCodeStream.length) {
537                 resizeByteArray();
538         }
539         position++;
540         bCodeStream[classFileOffset++] = OPC_daload;
541 }
542 final public void dastore() {
543         if (DEBUG) System.out.println(position + "\t\tdastore"); //$NON-NLS-1$
544         countLabels = 0;
545         stackDepth -= 4;
546         if (classFileOffset >= bCodeStream.length) {
547                 resizeByteArray();
548         }
549         position++;
550         bCodeStream[classFileOffset++] = OPC_dastore;
551 }
552 final public void dcmpg() {
553         if (DEBUG) System.out.println(position + "\t\tdcmpg"); //$NON-NLS-1$
554         countLabels = 0;
555         stackDepth -= 3;
556         if (classFileOffset >= bCodeStream.length) {
557                 resizeByteArray();
558         }
559         position++;
560         bCodeStream[classFileOffset++] = OPC_dcmpg;
561 }
562 final public void dcmpl() {
563         if (DEBUG) System.out.println(position + "\t\tdcmpl"); //$NON-NLS-1$
564         countLabels = 0;
565         stackDepth -= 3;
566         if (classFileOffset >= bCodeStream.length) {
567                 resizeByteArray();
568         }
569         position++;
570         bCodeStream[classFileOffset++] = OPC_dcmpl;
571 }
572 final public void dconst_0() {
573         if (DEBUG) System.out.println(position + "\t\tdconst_0"); //$NON-NLS-1$
574         countLabels = 0;
575         stackDepth += 2;
576         if (stackDepth > stackMax)
577                 stackMax = stackDepth;
578         if (classFileOffset >= bCodeStream.length) {
579                 resizeByteArray();
580         }
581         position++;
582         bCodeStream[classFileOffset++] = OPC_dconst_0;
583 }
584 final public void dconst_1() {
585         if (DEBUG) System.out.println(position + "\t\tdconst_1"); //$NON-NLS-1$
586         countLabels = 0;
587         stackDepth += 2;
588         if (stackDepth > stackMax)
589                 stackMax = stackDepth;
590         if (classFileOffset >= bCodeStream.length) {
591                 resizeByteArray();
592         }
593         position++;
594         bCodeStream[classFileOffset++] = OPC_dconst_1;
595 }
596 final public void ddiv() {
597         if (DEBUG) System.out.println(position + "\t\tddiv"); //$NON-NLS-1$
598         countLabels = 0;
599         stackDepth -= 2;
600         if (classFileOffset >= bCodeStream.length) {
601                 resizeByteArray();
602         }
603         position++;
604         bCodeStream[classFileOffset++] = OPC_ddiv;
605 }
606 public void decrStackSize(int offset) {
607         stackDepth -= offset;
608 }
609 final public void dload(int iArg) {
610         if (DEBUG) System.out.println(position + "\t\tdload:"+iArg); //$NON-NLS-1$
611         countLabels = 0;
612         stackDepth += 2;
613         if (stackDepth > stackMax)
614                 stackMax = stackDepth;
615         if (maxLocals < iArg + 2) {
616                 maxLocals = iArg + 2; // + 2 because it is a double
617         }
618         if (iArg > 255) { // Widen
619                 if (classFileOffset + 3 >= bCodeStream.length) {
620                         resizeByteArray();
621                 }
622                 position += 2;
623                 bCodeStream[classFileOffset++] = OPC_wide;
624                 bCodeStream[classFileOffset++] = OPC_dload;
625                 writeUnsignedShort(iArg);
626         } else {
627                 // Don't need to use the wide bytecode
628                 if (classFileOffset + 1 >= bCodeStream.length) {
629                         resizeByteArray();
630                 }
631                 position += 2;
632                 bCodeStream[classFileOffset++] = OPC_dload;
633                 bCodeStream[classFileOffset++] = (byte) iArg;
634         }
635 }
636 final public void dload_0() {
637         if (DEBUG) System.out.println(position + "\t\tdload_0"); //$NON-NLS-1$
638         countLabels = 0;
639         stackDepth += 2;
640         if (stackDepth > stackMax)
641                 stackMax = stackDepth;
642         if (maxLocals < 2) {
643                 maxLocals = 2;
644         }
645         if (classFileOffset >= bCodeStream.length) {
646                 resizeByteArray();
647         }
648         position++;
649         bCodeStream[classFileOffset++] = OPC_dload_0;
650 }
651 final public void dload_1() {
652         if (DEBUG) System.out.println(position + "\t\tdload_1"); //$NON-NLS-1$
653         countLabels = 0;
654         stackDepth += 2;
655         if (stackDepth > stackMax)
656                 stackMax = stackDepth;
657         if (maxLocals < 3) {
658                 maxLocals = 3;
659         }
660         if (classFileOffset >= bCodeStream.length) {
661                 resizeByteArray();
662         }
663         position++;
664         bCodeStream[classFileOffset++] = OPC_dload_1;
665 }
666 final public void dload_2() {
667         if (DEBUG) System.out.println(position + "\t\tdload_2"); //$NON-NLS-1$
668         countLabels = 0;
669         stackDepth += 2;
670         if (stackDepth > stackMax)
671                 stackMax = stackDepth;
672         if (maxLocals < 4) {
673                 maxLocals = 4;
674         }
675         if (classFileOffset >= bCodeStream.length) {
676                 resizeByteArray();
677         }
678         position++;
679         bCodeStream[classFileOffset++] = OPC_dload_2;
680 }
681 final public void dload_3() {
682         if (DEBUG) System.out.println(position + "\t\tdload_3"); //$NON-NLS-1$
683         countLabels = 0;
684         stackDepth += 2;
685         if (stackDepth > stackMax)
686                 stackMax = stackDepth;
687         if (maxLocals < 5) {
688                 maxLocals = 5;
689         }
690         if (classFileOffset >= bCodeStream.length) {
691                 resizeByteArray();
692         }
693         position++;
694         bCodeStream[classFileOffset++] = OPC_dload_3;
695 }
696 final public void dmul() {
697         if (DEBUG) System.out.println(position + "\t\tdmul"); //$NON-NLS-1$
698         countLabels = 0;
699         stackDepth -= 2;
700         if (classFileOffset >= bCodeStream.length) {
701                 resizeByteArray();
702         }
703         position++;
704         bCodeStream[classFileOffset++] = OPC_dmul;
705 }
706 final public void dneg() {
707         if (DEBUG) System.out.println(position + "\t\tdneg"); //$NON-NLS-1$
708         countLabels = 0;
709         if (classFileOffset >= bCodeStream.length) {
710                 resizeByteArray();
711         }
712         position++;
713         bCodeStream[classFileOffset++] = OPC_dneg;
714 }
715 final public void drem() {
716         if (DEBUG) System.out.println(position + "\t\tdrem"); //$NON-NLS-1$
717         countLabels = 0;
718         stackDepth -= 2;
719         if (classFileOffset >= bCodeStream.length) {
720                 resizeByteArray();
721         }
722         position++;
723         bCodeStream[classFileOffset++] = OPC_drem;
724 }
725 final public void dreturn() {
726         if (DEBUG) System.out.println(position + "\t\tdreturn"); //$NON-NLS-1$
727         countLabels = 0;
728         stackDepth -= 2;
729         // the stackDepth should be equal to 0 
730         if (classFileOffset >= bCodeStream.length) {
731                 resizeByteArray();
732         }
733         position++;
734         bCodeStream[classFileOffset++] = OPC_dreturn;
735 }
736 final public void dstore(int iArg) {
737         if (DEBUG) System.out.println(position + "\t\tdstore:"+iArg); //$NON-NLS-1$
738         countLabels = 0;
739         stackDepth -= 2;
740         if (maxLocals <= iArg + 1) {
741                 maxLocals = iArg + 2;
742         }
743         if (iArg > 255) { // Widen
744                 if (classFileOffset + 3 >= bCodeStream.length) {
745                         resizeByteArray();
746                 }
747                 position += 2;
748                 bCodeStream[classFileOffset++] = OPC_wide;
749                 bCodeStream[classFileOffset++] = OPC_dstore;
750                 writeUnsignedShort(iArg);
751         } else {
752                 if (classFileOffset + 1 >= bCodeStream.length) {
753                         resizeByteArray();
754                 }
755                 position += 2;
756                 bCodeStream[classFileOffset++] = OPC_dstore;
757                 bCodeStream[classFileOffset++] = (byte) iArg;
758         }
759 }
760 final public void dstore_0() {
761         if (DEBUG) System.out.println(position + "\t\tdstore_0"); //$NON-NLS-1$
762         countLabels = 0;
763         stackDepth -= 2;
764         if (maxLocals < 2) {
765                 maxLocals = 2;
766         }
767         if (classFileOffset >= bCodeStream.length) {
768                 resizeByteArray();
769         }
770         position++;
771         bCodeStream[classFileOffset++] = OPC_dstore_0;
772 }
773 final public void dstore_1() {
774         if (DEBUG) System.out.println(position + "\t\tdstore_1"); //$NON-NLS-1$
775         countLabels = 0;
776         stackDepth -= 2;
777         if (maxLocals < 3) {
778                 maxLocals = 3;
779         }
780         if (classFileOffset >= bCodeStream.length) {
781                 resizeByteArray();
782         }
783         position++;
784         bCodeStream[classFileOffset++] = OPC_dstore_1;
785 }
786 final public void dstore_2() {
787         if (DEBUG) System.out.println(position + "\t\tdstore_2"); //$NON-NLS-1$
788         countLabels = 0;
789         stackDepth -= 2;
790         if (maxLocals < 4) {
791                 maxLocals = 4;
792         }
793         if (classFileOffset >= bCodeStream.length) {
794                 resizeByteArray();
795         }
796         position++;
797         bCodeStream[classFileOffset++] = OPC_dstore_2;
798 }
799 final public void dstore_3() {
800         if (DEBUG) System.out.println(position + "\t\tdstore_3"); //$NON-NLS-1$
801         countLabels = 0;
802         stackDepth -= 2;
803         if (maxLocals < 5) {
804                 maxLocals = 5;
805         }
806         if (classFileOffset >= bCodeStream.length) {
807                 resizeByteArray();
808         }
809         position++;
810         bCodeStream[classFileOffset++] = OPC_dstore_3;
811 }
812 final public void dsub() {
813         if (DEBUG) System.out.println(position + "\t\tdsub"); //$NON-NLS-1$
814         countLabels = 0;
815         stackDepth -= 2;
816         if (classFileOffset >= bCodeStream.length) {
817                 resizeByteArray();
818         }
819         position++;
820         bCodeStream[classFileOffset++] = OPC_dsub;
821 }
822 final public void dup() {
823         if (DEBUG) System.out.println(position + "\t\tdup"); //$NON-NLS-1$
824         countLabels = 0;
825         stackDepth++;
826         if (stackDepth > stackMax) {
827                 stackMax = stackDepth;
828         }
829         if (classFileOffset >= bCodeStream.length) {
830                 resizeByteArray();
831         }
832         position++;
833         bCodeStream[classFileOffset++] = OPC_dup;
834 }
835 final public void dup_x1() {
836         if (DEBUG) System.out.println(position + "\t\tdup_x1"); //$NON-NLS-1$
837         countLabels = 0;
838         stackDepth++;
839         if (stackDepth > stackMax)
840                 stackMax = stackDepth;
841         if (classFileOffset >= bCodeStream.length) {
842                 resizeByteArray();
843         }
844         position++;
845         bCodeStream[classFileOffset++] = OPC_dup_x1;
846 }
847 final public void dup_x2() {
848         if (DEBUG) System.out.println(position + "\t\tdup_x2"); //$NON-NLS-1$
849         countLabels = 0;
850         stackDepth++;
851         if (stackDepth > stackMax)
852                 stackMax = stackDepth;
853         if (classFileOffset >= bCodeStream.length) {
854                 resizeByteArray();
855         }
856         position++;
857         bCodeStream[classFileOffset++] = OPC_dup_x2;
858 }
859 final public void dup2() {
860         if (DEBUG) System.out.println(position + "\t\tdup2"); //$NON-NLS-1$
861         countLabels = 0;
862         stackDepth += 2;
863         if (stackDepth > stackMax)
864                 stackMax = stackDepth;
865         if (classFileOffset >= bCodeStream.length) {
866                 resizeByteArray();
867         }
868         position++;
869         bCodeStream[classFileOffset++] = OPC_dup2;
870 }
871 final public void dup2_x1() {
872         if (DEBUG) System.out.println(position + "\t\tdup2_x1"); //$NON-NLS-1$
873         countLabels = 0;
874         stackDepth += 2;
875         if (stackDepth > stackMax)
876                 stackMax = stackDepth;
877         if (classFileOffset >= bCodeStream.length) {
878                 resizeByteArray();
879         }
880         position++;
881         bCodeStream[classFileOffset++] = OPC_dup2_x1;
882 }
883 final public void dup2_x2() {
884         if (DEBUG) System.out.println(position + "\t\tdup2_x2"); //$NON-NLS-1$
885         countLabels = 0;
886         stackDepth += 2;
887         if (stackDepth > stackMax)
888                 stackMax = stackDepth;
889         if (classFileOffset >= bCodeStream.length) {
890                 resizeByteArray();
891         }
892         position++;
893         bCodeStream[classFileOffset++] = OPC_dup2_x2;
894 }
895 public void exitUserScope(BlockScope blockScope) {
896         // mark all the scope's locals as loosing their definite assignment
897
898         if (!generateLocalVariableTableAttributes)
899                 return;
900         for (int i = 0; i < visibleLocalsCount; i++) {
901                 LocalVariableBinding visibleLocal = visibleLocals[i];
902                 if ((visibleLocal != null) && (visibleLocal.declaringScope == blockScope)) { 
903                         // there maybe some some preserved locals never initialized
904                         if (visibleLocal.initializationCount > 0){
905                                 visibleLocals[i].recordInitializationEndPC(position);
906                         }
907                         visibleLocals[i] = null; // this variable is no longer visible afterwards
908                 }
909         }
910 }
911 final public void f2d() {
912         if (DEBUG) System.out.println(position + "\t\tf2d"); //$NON-NLS-1$
913         countLabels = 0;
914         stackDepth++;
915         if (stackDepth > stackMax)
916                 stackMax = stackDepth;
917         if (classFileOffset >= bCodeStream.length) {
918                 resizeByteArray();
919         }
920         position++;
921         bCodeStream[classFileOffset++] = OPC_f2d;
922 }
923 final public void f2i() {
924         if (DEBUG) System.out.println(position + "\t\tf2i"); //$NON-NLS-1$
925         countLabels = 0;
926         if (classFileOffset >= bCodeStream.length) {
927                 resizeByteArray();
928         }
929         position++;
930         bCodeStream[classFileOffset++] = OPC_f2i;
931 }
932 final public void f2l() {
933         if (DEBUG) System.out.println(position + "\t\tf2l"); //$NON-NLS-1$
934         countLabels = 0;
935         stackDepth++;
936         if (stackDepth > stackMax)
937                 stackMax = stackDepth;
938         if (classFileOffset >= bCodeStream.length) {
939                 resizeByteArray();
940         }
941         position++;
942         bCodeStream[classFileOffset++] = OPC_f2l;
943 }
944 final public void fadd() {
945         if (DEBUG) System.out.println(position + "\t\tfadd"); //$NON-NLS-1$
946         countLabels = 0;
947         stackDepth--;
948         if (classFileOffset >= bCodeStream.length) {
949                 resizeByteArray();
950         }
951         position++;
952         bCodeStream[classFileOffset++] = OPC_fadd;
953 }
954 final public void faload() {
955         if (DEBUG) System.out.println(position + "\t\tfaload"); //$NON-NLS-1$
956         countLabels = 0;
957         stackDepth--;
958         if (classFileOffset >= bCodeStream.length) {
959                 resizeByteArray();
960         }
961         position++;
962         bCodeStream[classFileOffset++] = OPC_faload;
963 }
964 final public void fastore() {
965         if (DEBUG) System.out.println(position + "\t\tfaload"); //$NON-NLS-1$
966         countLabels = 0;
967         stackDepth -= 3;
968         if (classFileOffset >= bCodeStream.length) {
969                 resizeByteArray();
970         }
971         position++;
972         bCodeStream[classFileOffset++] = OPC_fastore;
973 }
974 final public void fcmpg() {
975         if (DEBUG) System.out.println(position + "\t\tfcmpg"); //$NON-NLS-1$
976         countLabels = 0;
977         stackDepth--;
978         if (classFileOffset >= bCodeStream.length) {
979                 resizeByteArray();
980         }
981         position++;
982         bCodeStream[classFileOffset++] = OPC_fcmpg;
983 }
984 final public void fcmpl() {
985         if (DEBUG) System.out.println(position + "\t\tfcmpl"); //$NON-NLS-1$
986         countLabels = 0;
987         stackDepth--;
988         if (classFileOffset >= bCodeStream.length) {
989                 resizeByteArray();
990         }
991         position++;
992         bCodeStream[classFileOffset++] = OPC_fcmpl;
993 }
994 final public void fconst_0() {
995         if (DEBUG) System.out.println(position + "\t\tfconst_0"); //$NON-NLS-1$
996         countLabels = 0;
997         stackDepth++;
998         if (stackDepth > stackMax)
999                 stackMax = stackDepth;
1000         if (classFileOffset >= bCodeStream.length) {
1001                 resizeByteArray();
1002         }
1003         position++;
1004         bCodeStream[classFileOffset++] = OPC_fconst_0;
1005 }
1006 final public void fconst_1() {
1007         if (DEBUG) System.out.println(position + "\t\tfconst_1"); //$NON-NLS-1$
1008         countLabels = 0;
1009         stackDepth++;
1010         if (stackDepth > stackMax)
1011                 stackMax = stackDepth;
1012         if (classFileOffset >= bCodeStream.length) {
1013                 resizeByteArray();
1014         }
1015         position++;
1016         bCodeStream[classFileOffset++] = OPC_fconst_1;
1017 }
1018 final public void fconst_2() {
1019         if (DEBUG) System.out.println(position + "\t\tfconst_2"); //$NON-NLS-1$
1020         countLabels = 0;
1021         stackDepth++;
1022         if (stackDepth > stackMax)
1023                 stackMax = stackDepth;
1024         if (classFileOffset >= bCodeStream.length) {
1025                 resizeByteArray();
1026         }
1027         position++;
1028         bCodeStream[classFileOffset++] = OPC_fconst_2;
1029 }
1030 final public void fdiv() {
1031         if (DEBUG) System.out.println(position + "\t\tfdiv"); //$NON-NLS-1$
1032         countLabels = 0;
1033         stackDepth--;
1034         if (classFileOffset >= bCodeStream.length) {
1035                 resizeByteArray();
1036         }
1037         position++;
1038         bCodeStream[classFileOffset++] = OPC_fdiv;
1039 }
1040 final public void fload(int iArg) {
1041         if (DEBUG) System.out.println(position + "\t\tfload:"+iArg); //$NON-NLS-1$
1042         countLabels = 0;
1043         stackDepth++;
1044         if (maxLocals <= iArg) {
1045                 maxLocals = iArg + 1;
1046         }
1047         if (stackDepth > stackMax)
1048                 stackMax = stackDepth;
1049         if (iArg > 255) { // Widen
1050                 if (classFileOffset + 3 >= bCodeStream.length) {
1051                         resizeByteArray();
1052                 }
1053                 position += 2;
1054                 bCodeStream[classFileOffset++] = OPC_wide;
1055                 bCodeStream[classFileOffset++] = OPC_fload;
1056                 writeUnsignedShort(iArg);
1057         } else {
1058                 if (classFileOffset + 1 >= bCodeStream.length) {
1059                         resizeByteArray();
1060                 }
1061                 position += 2;
1062                 bCodeStream[classFileOffset++] = OPC_fload;
1063                 bCodeStream[classFileOffset++] = (byte) iArg;
1064         }
1065 }
1066 final public void fload_0() {
1067         if (DEBUG) System.out.println(position + "\t\tfload_0"); //$NON-NLS-1$
1068         countLabels = 0;
1069         stackDepth++;
1070         if (maxLocals == 0) {
1071                 maxLocals = 1;
1072         }
1073         if (stackDepth > stackMax)
1074                 stackMax = stackDepth;
1075         if (classFileOffset >= bCodeStream.length) {
1076                 resizeByteArray();
1077         }
1078         position++;
1079         bCodeStream[classFileOffset++] = OPC_fload_0;
1080 }
1081 final public void fload_1() {
1082         if (DEBUG) System.out.println(position + "\t\tfload_1"); //$NON-NLS-1$
1083         countLabels = 0;
1084         stackDepth++;
1085         if (maxLocals <= 1) {
1086                 maxLocals = 2;
1087         }
1088         if (stackDepth > stackMax)
1089                 stackMax = stackDepth;
1090         if (classFileOffset >= bCodeStream.length) {
1091                 resizeByteArray();
1092         }
1093         position++;
1094         bCodeStream[classFileOffset++] = OPC_fload_1;
1095 }
1096 final public void fload_2() {
1097         if (DEBUG) System.out.println(position + "\t\tfload_2"); //$NON-NLS-1$
1098         countLabels = 0;
1099         stackDepth++;
1100         if (maxLocals <= 2) {
1101                 maxLocals = 3;
1102         }
1103         if (stackDepth > stackMax)
1104                 stackMax = stackDepth;
1105         if (classFileOffset >= bCodeStream.length) {
1106                 resizeByteArray();
1107         }
1108         position++;
1109         bCodeStream[classFileOffset++] = OPC_fload_2;
1110 }
1111 final public void fload_3() {
1112         if (DEBUG) System.out.println(position + "\t\tfload_3"); //$NON-NLS-1$
1113         countLabels = 0;
1114         stackDepth++;
1115         if (maxLocals <= 3) {
1116                 maxLocals = 4;
1117         }
1118         if (stackDepth > stackMax)
1119                 stackMax = stackDepth;
1120         if (classFileOffset >= bCodeStream.length) {
1121                 resizeByteArray();
1122         }
1123         position++;
1124         bCodeStream[classFileOffset++] = OPC_fload_3;
1125 }
1126 final public void fmul() {
1127         if (DEBUG) System.out.println(position + "\t\tfmul"); //$NON-NLS-1$
1128         countLabels = 0;
1129         stackDepth--;
1130         if (classFileOffset >= bCodeStream.length) {
1131                 resizeByteArray();
1132         }
1133         position++;
1134         bCodeStream[classFileOffset++] = OPC_fmul;
1135 }
1136 final public void fneg() {
1137         if (DEBUG) System.out.println(position + "\t\tfneg"); //$NON-NLS-1$
1138         countLabels = 0;
1139         if (classFileOffset >= bCodeStream.length) {
1140                 resizeByteArray();
1141         }
1142         position++;
1143         bCodeStream[classFileOffset++] = OPC_fneg;
1144 }
1145 final public void frem() {
1146         if (DEBUG) System.out.println(position + "\t\tfrem"); //$NON-NLS-1$
1147         countLabels = 0;
1148         stackDepth--;
1149         if (classFileOffset >= bCodeStream.length) {
1150                 resizeByteArray();
1151         }
1152         position++;
1153         bCodeStream[classFileOffset++] = OPC_frem;
1154 }
1155 final public void freturn() {
1156         if (DEBUG) System.out.println(position + "\t\tfreturn"); //$NON-NLS-1$
1157         countLabels = 0;
1158         stackDepth--;
1159         // the stackDepth should be equal to 0 
1160         if (classFileOffset >= bCodeStream.length) {
1161                 resizeByteArray();
1162         }
1163         position++;
1164         bCodeStream[classFileOffset++] = OPC_freturn;
1165 }
1166 final public void fstore(int iArg) {
1167         if (DEBUG) System.out.println(position + "\t\tfstore:"+iArg); //$NON-NLS-1$
1168         countLabels = 0;
1169         stackDepth--;
1170         if (maxLocals <= iArg) {
1171                 maxLocals = iArg + 1;
1172         }
1173         if (iArg > 255) { // Widen
1174                 if (classFileOffset + 3 >= bCodeStream.length) {
1175                         resizeByteArray();
1176                 }
1177                 position += 2;
1178                 bCodeStream[classFileOffset++] = OPC_wide;
1179                 bCodeStream[classFileOffset++] = OPC_fstore;
1180                 writeUnsignedShort(iArg);
1181         } else {
1182                 if (classFileOffset + 1 >= bCodeStream.length) {
1183                         resizeByteArray();
1184                 }
1185                 position += 2;
1186                 bCodeStream[classFileOffset++] = OPC_fstore;
1187                 bCodeStream[classFileOffset++] = (byte) iArg;
1188         }
1189 }
1190 final public void fstore_0() {
1191         if (DEBUG) System.out.println(position + "\t\tfstore_0"); //$NON-NLS-1$
1192         countLabels = 0;
1193         stackDepth--;
1194         if (maxLocals == 0) {
1195                 maxLocals = 1;
1196         }
1197         if (classFileOffset >= bCodeStream.length) {
1198                 resizeByteArray();
1199         }
1200         position++;
1201         bCodeStream[classFileOffset++] = OPC_fstore_0;
1202 }
1203 final public void fstore_1() {
1204         if (DEBUG) System.out.println(position + "\t\tfstore_1"); //$NON-NLS-1$
1205         countLabels = 0;
1206         stackDepth--;
1207         if (maxLocals <= 1) {
1208                 maxLocals = 2;
1209         }
1210         if (classFileOffset >= bCodeStream.length) {
1211                 resizeByteArray();
1212         }
1213         position++;
1214         bCodeStream[classFileOffset++] = OPC_fstore_1;
1215 }
1216 final public void fstore_2() {
1217         if (DEBUG) System.out.println(position + "\t\tfstore_2"); //$NON-NLS-1$
1218         countLabels = 0;
1219         stackDepth--;
1220         if (maxLocals <= 2) {
1221                 maxLocals = 3;
1222         }
1223         if (classFileOffset >= bCodeStream.length) {
1224                 resizeByteArray();
1225         }
1226         position++;
1227         bCodeStream[classFileOffset++] = OPC_fstore_2;
1228 }
1229 final public void fstore_3() {
1230         if (DEBUG) System.out.println(position + "\t\tfstore_3"); //$NON-NLS-1$
1231         countLabels = 0;
1232         stackDepth--;
1233         if (maxLocals <= 3) {
1234                 maxLocals = 4;
1235         }
1236         if (classFileOffset >= bCodeStream.length) {
1237                 resizeByteArray();
1238         }
1239         position++;
1240         bCodeStream[classFileOffset++] = OPC_fstore_3;
1241 }
1242 final public void fsub() {
1243         if (DEBUG) System.out.println(position + "\t\tfsub"); //$NON-NLS-1$
1244         countLabels = 0;
1245         stackDepth--;
1246         if (classFileOffset >= bCodeStream.length) {
1247                 resizeByteArray();
1248         }
1249         position++;
1250         bCodeStream[classFileOffset++] = OPC_fsub;
1251 }
1252 /**
1253  * Macro for building a class descriptor object
1254  */
1255 public void generateClassLiteralAccessForType(TypeBinding accessedType, FieldBinding syntheticFieldBinding) {
1256         Label endLabel;
1257         ExceptionLabel anyExceptionHandler;
1258         int saveStackSize;
1259         if (accessedType.isBaseType() && accessedType != NullBinding) {
1260                 this.getTYPE(accessedType.id);
1261                 return;
1262         }
1263         endLabel = new Label(this);
1264
1265         if (syntheticFieldBinding != null) { // non interface case
1266                 this.getstatic(syntheticFieldBinding);
1267                 this.dup();
1268                 this.ifnonnull(endLabel);
1269                 this.pop();
1270         }
1271
1272         /* Macro for building a class descriptor object... using or not a field cache to store it into...
1273         this sequence is responsible for building the actual class descriptor.
1274         
1275         If the fieldCache is set, then it is supposed to be the body of a synthetic access method
1276         factoring the actual descriptor creation out of the invocation site (saving space).
1277         If the fieldCache is nil, then we are dumping the bytecode on the invocation site, since
1278         we have no way to get a hand on the field cache to do better. */
1279
1280
1281         // Wrap the code in an exception handler to convert a ClassNotFoundException into a NoClassDefError
1282
1283         anyExceptionHandler = new ExceptionLabel(this, BaseTypes.NullBinding /* represents ClassNotFoundException*/);
1284         this.ldc(accessedType == BaseTypes.NullBinding ? "java.lang.Object" : String.valueOf(accessedType.constantPoolName()).replace('/', '.')); //$NON-NLS-1$
1285         this.invokeClassForName();
1286
1287         /* See https://bugs.eclipse.org/bugs/show_bug.cgi?id=37565
1288         if (accessedType == BaseTypes.NullBinding) {
1289                 this.ldc("java.lang.Object"); //$NON-NLS-1$
1290         } else if (accessedType.isArrayType()) {
1291                 this.ldc(String.valueOf(accessedType.constantPoolName()).replace('/', '.'));
1292         } else {
1293                 // we make it an array type (to avoid class initialization)
1294                 this.ldc("[L" + String.valueOf(accessedType.constantPoolName()).replace('/', '.') + ";"); //$NON-NLS-1$//$NON-NLS-2$
1295         }
1296         this.invokeClassForName();
1297         if (!accessedType.isArrayType()) { // extract the component type, which doesn't initialize the class
1298                 this.invokeJavaLangClassGetComponentType();
1299         }       
1300         */
1301         /* We need to protect the runtime code from binary inconsistencies
1302         in case the accessedType is missing, the ClassNotFoundException has to be converted
1303         into a NoClassDefError(old ex message), we thus need to build an exception handler for this one. */
1304         anyExceptionHandler.placeEnd();
1305
1306         if (syntheticFieldBinding != null) { // non interface case
1307                 this.dup();
1308                 this.putstatic(syntheticFieldBinding);
1309         }
1310         this.goto_(endLabel);
1311
1312
1313         // Generate the body of the exception handler
1314         saveStackSize = stackDepth;
1315         stackDepth = 1;
1316         /* ClassNotFoundException on stack -- the class literal could be doing more things
1317         on the stack, which means that the stack may not be empty at this point in the
1318         above code gen. So we save its state and restart it from 1. */
1319
1320         anyExceptionHandler.place();
1321
1322         // Transform the current exception, and repush and throw a 
1323         // NoClassDefFoundError(ClassNotFound.getMessage())
1324
1325         this.newNoClassDefFoundError();
1326         this.dup_x1();
1327         this.swap();
1328
1329         // Retrieve the message from the old exception
1330         this.invokeThrowableGetMessage();
1331
1332         // Send the constructor taking a message string as an argument
1333         this.invokeNoClassDefFoundErrorStringConstructor();
1334         this.athrow();
1335         endLabel.place();
1336         stackDepth = saveStackSize;
1337 }
1338 /**
1339  * This method generates the code attribute bytecode
1340  */
1341 final public void generateCodeAttributeForProblemMethod(String problemMessage) {
1342         newJavaLangError();
1343         dup();
1344         ldc(problemMessage);
1345         invokeJavaLangErrorConstructor();
1346         athrow();
1347 }
1348 public void generateConstant(Constant constant, int implicitConversionCode) {
1349         int targetTypeID = implicitConversionCode >> 4;
1350         switch (targetTypeID) {
1351                 case T_boolean :
1352                         generateInlinedValue(constant.booleanValue());
1353                         break;
1354                 case T_char :
1355                         generateInlinedValue(constant.charValue());
1356                         break;
1357                 case T_byte :
1358                         generateInlinedValue(constant.byteValue());
1359                         break;
1360                 case T_short :
1361                         generateInlinedValue(constant.shortValue());
1362                         break;
1363                 case T_int :
1364                         generateInlinedValue(constant.intValue());
1365                         break;
1366                 case T_long :
1367                         generateInlinedValue(constant.longValue());
1368                         break;
1369                 case T_float :
1370                         generateInlinedValue(constant.floatValue());
1371                         break;
1372                 case T_double :
1373                         generateInlinedValue(constant.doubleValue());
1374                         break;
1375                 default : //String or Object
1376                         ldc(constant.stringValue());
1377         }
1378 }
1379 /**
1380  * @param implicitConversionCode int
1381  */
1382 public void generateImplicitConversion(int implicitConversionCode) {
1383         switch (implicitConversionCode) {
1384                 case Float2Char :
1385                         this.f2i();
1386                         this.i2c();
1387                         break;
1388                 case Double2Char :
1389                         this.d2i();
1390                         this.i2c();
1391                         break;
1392                 case Int2Char :
1393                 case Short2Char :
1394                 case Byte2Char :
1395                         this.i2c();
1396                         break;
1397                 case Long2Char :
1398                         this.l2i();
1399                         this.i2c();
1400                         break;
1401                 case Char2Float :
1402                 case Short2Float :
1403                 case Int2Float :
1404                 case Byte2Float :
1405                         this.i2f();
1406                         break;
1407                 case Double2Float :
1408                         this.d2f();
1409                         break;
1410                 case Long2Float :
1411                         this.l2f();
1412                         break;
1413                 case Float2Byte :
1414                         this.f2i();
1415                         this.i2b();
1416                         break;
1417                 case Double2Byte :
1418                         this.d2i();
1419                         this.i2b();
1420                         break;
1421                 case Int2Byte :
1422                 case Short2Byte :
1423                 case Char2Byte :
1424                         this.i2b();
1425                         break;
1426                 case Long2Byte :
1427                         this.l2i();
1428                         this.i2b();
1429                         break;
1430                 case Byte2Double :
1431                 case Char2Double :
1432                 case Short2Double :
1433                 case Int2Double :
1434                         this.i2d();
1435                         break;
1436                 case Float2Double :
1437                         this.f2d();
1438                         break;
1439                 case Long2Double :
1440                         this.l2d();
1441                         break;
1442                 case Byte2Short :
1443                 case Char2Short :
1444                 case Int2Short :
1445                         this.i2s();
1446                         break;
1447                 case Double2Short :
1448                         this.d2i();
1449                         this.i2s();
1450                         break;
1451                 case Long2Short :
1452                         this.l2i();
1453                         this.i2s();
1454                         break;
1455                 case Float2Short :
1456                         this.f2i();
1457                         this.i2s();
1458                         break;
1459                 case Double2Int :
1460                         this.d2i();
1461                         break;
1462                 case Float2Int :
1463                         this.f2i();
1464                         break;
1465                 case Long2Int :
1466                         this.l2i();
1467                         break;
1468                 case Int2Long :
1469                 case Char2Long :
1470                 case Byte2Long :
1471                 case Short2Long :
1472                         this.i2l();
1473                         break;
1474                 case Double2Long :
1475                         this.d2l();
1476                         break;
1477                 case Float2Long :
1478                         this.f2l();
1479         }
1480 }
1481 public void generateInlinedValue(byte inlinedValue) {
1482         switch (inlinedValue) {
1483                 case -1 :
1484                         this.iconst_m1();
1485                         break;
1486                 case 0 :
1487                         this.iconst_0();
1488                         break;
1489                 case 1 :
1490                         this.iconst_1();
1491                         break;
1492                 case 2 :
1493                         this.iconst_2();
1494                         break;
1495                 case 3 :
1496                         this.iconst_3();
1497                         break;
1498                 case 4 :
1499                         this.iconst_4();
1500                         break;
1501                 case 5 :
1502                         this.iconst_5();
1503                         break;
1504                 default :
1505                         if ((-128 <= inlinedValue) && (inlinedValue <= 127)) {
1506                                 this.bipush(inlinedValue);
1507                                 return;
1508                         }
1509         }
1510 }
1511 public void generateInlinedValue(char inlinedValue) {
1512         switch (inlinedValue) {
1513                 case 0 :
1514                         this.iconst_0();
1515                         break;
1516                 case 1 :
1517                         this.iconst_1();
1518                         break;
1519                 case 2 :
1520                         this.iconst_2();
1521                         break;
1522                 case 3 :
1523                         this.iconst_3();
1524                         break;
1525                 case 4 :
1526                         this.iconst_4();
1527                         break;
1528                 case 5 :
1529                         this.iconst_5();
1530                         break;
1531                 default :
1532                         if ((6 <= inlinedValue) && (inlinedValue <= 127)) {
1533                                 this.bipush((byte) inlinedValue);
1534                                 return;
1535                         }
1536                         if ((128 <= inlinedValue) && (inlinedValue <= 32767)) {
1537                                 this.sipush(inlinedValue);
1538                                 return;
1539                         }
1540                         this.ldc(inlinedValue);
1541         }
1542 }
1543 public void generateInlinedValue(double inlinedValue) {
1544         if (inlinedValue == 0.0) {
1545                 if (Double.doubleToLongBits(inlinedValue) != 0L)
1546                         this.ldc2_w(inlinedValue);
1547                 else
1548                         this.dconst_0();
1549                 return;
1550         }
1551         if (inlinedValue == 1.0) {
1552                 this.dconst_1();
1553                 return;
1554         }
1555         this.ldc2_w(inlinedValue);
1556 }
1557 public void generateInlinedValue(float inlinedValue) {
1558         if (inlinedValue == 0.0f) {
1559                 if (Float.floatToIntBits(inlinedValue) != 0)
1560                         this.ldc(inlinedValue);
1561                 else
1562                         this.fconst_0();
1563                 return;
1564         }
1565         if (inlinedValue == 1.0f) {
1566                 this.fconst_1();
1567                 return;
1568         }
1569         if (inlinedValue == 2.0f) {
1570                 this.fconst_2();
1571                 return;
1572         }
1573         this.ldc(inlinedValue);
1574 }
1575 public void generateInlinedValue(int inlinedValue) {
1576         switch (inlinedValue) {
1577                 case -1 :
1578                         this.iconst_m1();
1579                         break;
1580                 case 0 :
1581                         this.iconst_0();
1582                         break;
1583                 case 1 :
1584                         this.iconst_1();
1585                         break;
1586                 case 2 :
1587                         this.iconst_2();
1588                         break;
1589                 case 3 :
1590                         this.iconst_3();
1591                         break;
1592                 case 4 :
1593                         this.iconst_4();
1594                         break;
1595                 case 5 :
1596                         this.iconst_5();
1597                         break;
1598                 default :
1599                         if ((-128 <= inlinedValue) && (inlinedValue <= 127)) {
1600                                 this.bipush((byte) inlinedValue);
1601                                 return;
1602                         }
1603                         if ((-32768 <= inlinedValue) && (inlinedValue <= 32767)) {
1604                                 this.sipush(inlinedValue);
1605                                 return;
1606                         }
1607                         this.ldc(inlinedValue);
1608         }
1609 }
1610 public void generateInlinedValue(long inlinedValue) {
1611         if (inlinedValue == 0) {
1612                 this.lconst_0();
1613                 return;
1614         }
1615         if (inlinedValue == 1) {
1616                 this.lconst_1();
1617                 return;
1618         }
1619         this.ldc2_w(inlinedValue);
1620 }
1621 public void generateInlinedValue(short inlinedValue) {
1622         switch (inlinedValue) {
1623                 case -1 :
1624                         this.iconst_m1();
1625                         break;
1626                 case 0 :
1627                         this.iconst_0();
1628                         break;
1629                 case 1 :
1630                         this.iconst_1();
1631                         break;
1632                 case 2 :
1633                         this.iconst_2();
1634                         break;
1635                 case 3 :
1636                         this.iconst_3();
1637                         break;
1638                 case 4 :
1639                         this.iconst_4();
1640                         break;
1641                 case 5 :
1642                         this.iconst_5();
1643                         break;
1644                 default :
1645                         if ((-128 <= inlinedValue) && (inlinedValue <= 127)) {
1646                                 this.bipush((byte) inlinedValue);
1647                                 return;
1648                         }
1649                         this.sipush(inlinedValue);
1650         }
1651 }
1652 public void generateInlinedValue(boolean inlinedValue) {
1653         if (inlinedValue)
1654                 this.iconst_1();
1655         else
1656                 this.iconst_0();
1657 }
1658 public void generateOuterAccess(Object[] mappingSequence, ASTNode invocationSite, Binding target, Scope scope) {
1659         if (mappingSequence == null) {
1660                 if (target instanceof LocalVariableBinding) {
1661                         scope.problemReporter().needImplementation(); //TODO (philippe) should improve local emulation failure reporting
1662                 } else {
1663                         scope.problemReporter().noSuchEnclosingInstance((ReferenceBinding)target, invocationSite, false);
1664                 }
1665                 return;
1666         }
1667         if (mappingSequence == BlockScope.NoEnclosingInstanceInConstructorCall) {
1668                 scope.problemReporter().noSuchEnclosingInstance((ReferenceBinding)target, invocationSite, true);
1669                 return;
1670         } else if (mappingSequence == BlockScope.NoEnclosingInstanceInStaticContext) {
1671                 scope.problemReporter().noSuchEnclosingInstance((ReferenceBinding)target, invocationSite, false);
1672                 return;
1673         }
1674         
1675         if (mappingSequence == BlockScope.EmulationPathToImplicitThis) {
1676                 this.aload_0();
1677                 return;
1678         } else if (mappingSequence[0] instanceof FieldBinding) {
1679                 FieldBinding fieldBinding = (FieldBinding) mappingSequence[0];
1680                 this.aload_0();
1681                 this.getfield(fieldBinding);
1682         } else {
1683                 load((LocalVariableBinding) mappingSequence[0]);
1684         }
1685         for (int i = 1, length = mappingSequence.length; i < length; i++) {
1686                 if (mappingSequence[i] instanceof FieldBinding) {
1687                         FieldBinding fieldBinding = (FieldBinding) mappingSequence[i];
1688                         this.getfield(fieldBinding);
1689                 } else {
1690                         this.invokestatic((MethodBinding) mappingSequence[i]);
1691                 }
1692         }
1693 }
1694
1695 /**
1696  * The equivalent code performs a string conversion:
1697  *
1698  * @param blockScope the given blockScope
1699  * @param oper1 the first expression
1700  * @param oper2 the second expression
1701  */
1702 public void generateStringAppend(BlockScope blockScope, Expression oper1, Expression oper2) {
1703         int pc;
1704         if (oper1 == null) {
1705                 /* Operand is already on the stack, and maybe nil:
1706                 note type1 is always to  java.lang.String here.*/
1707                 this.newStringBuffer();
1708                 this.dup_x1();
1709                 this.swap();
1710                 // If argument is reference type, need to transform it 
1711                 // into a string (handles null case)
1712                 this.invokeStringValueOf(T_Object);
1713                 this.invokeStringBufferStringConstructor();
1714         } else {
1715                 pc = position;
1716                 oper1.generateOptimizedStringBufferCreation(blockScope, this, oper1.implicitConversion & 0xF);
1717                 this.recordPositionsFrom(pc, oper1.sourceStart);
1718         }
1719         pc = position;
1720         oper2.generateOptimizedStringBuffer(blockScope, this, oper2.implicitConversion & 0xF);
1721         this.recordPositionsFrom(pc, oper2.sourceStart);
1722         this.invokeStringBufferToString();
1723 }
1724 /**
1725  * Code responsible to generate the suitable code to supply values for the synthetic enclosing
1726  * instance arguments of a constructor invocation of a nested type.
1727  */
1728 public void generateSyntheticEnclosingInstanceValues(
1729                 BlockScope currentScope, 
1730                 ReferenceBinding targetType, 
1731                 Expression enclosingInstance, 
1732                 ASTNode invocationSite) {
1733
1734         // supplying enclosing instance for the anonymous type's superclass
1735         ReferenceBinding checkedTargetType = targetType.isAnonymousType() ? targetType.superclass() : targetType;
1736         boolean hasExtraEnclosingInstance = enclosingInstance != null;
1737         if (hasExtraEnclosingInstance 
1738                         && (!checkedTargetType.isNestedType() || checkedTargetType.isStatic())) {
1739                 currentScope.problemReporter().unnecessaryEnclosingInstanceSpecification(enclosingInstance, checkedTargetType);
1740                 return;
1741         }
1742
1743         // perform some emulation work in case there is some and we are inside a local type only
1744         ReferenceBinding[] syntheticArgumentTypes;
1745         if ((syntheticArgumentTypes = targetType.syntheticEnclosingInstanceTypes()) != null) {
1746
1747                 ReferenceBinding targetEnclosingType = checkedTargetType.enclosingType();
1748                 boolean complyTo14 = currentScope.environment().options.complianceLevel >= ClassFileConstants.JDK1_4;
1749                 // deny access to enclosing instance argument for allocation and super constructor call (if 1.4)
1750                 boolean ignoreEnclosingArgInConstructorCall = invocationSite instanceof AllocationExpression
1751                                         || (complyTo14 && ((invocationSite instanceof ExplicitConstructorCall && ((ExplicitConstructorCall)invocationSite).isSuperAccess())));
1752                                                 
1753                 for (int i = 0, max = syntheticArgumentTypes.length; i < max; i++) {
1754                         ReferenceBinding syntheticArgType = syntheticArgumentTypes[i];
1755                         if (hasExtraEnclosingInstance && syntheticArgType == targetEnclosingType) {
1756                                 hasExtraEnclosingInstance = false;
1757                                 enclosingInstance.generateCode(currentScope, this, true);
1758                                 if (complyTo14){
1759                                         dup();
1760                                         invokeObjectGetClass(); // will perform null check
1761                                         pop();
1762                                 }
1763                         } else {
1764                                 Object[] emulationPath = currentScope.getEmulationPath(
1765                                                 syntheticArgType, 
1766                                                 false /*not only exact match (that is, allow compatible)*/,
1767                                                 ignoreEnclosingArgInConstructorCall);
1768                                 this.generateOuterAccess(emulationPath, invocationSite, syntheticArgType, currentScope);
1769                         }
1770                 }
1771                 if (hasExtraEnclosingInstance){
1772                         currentScope.problemReporter().unnecessaryEnclosingInstanceSpecification(enclosingInstance, checkedTargetType);
1773                 }
1774         }
1775 }
1776
1777 /**
1778  * Code responsible to generate the suitable code to supply values for the synthetic outer local
1779  * variable arguments of a constructor invocation of a nested type.
1780  * (bug 26122) - synthetic values for outer locals must be passed after user arguments, e.g. new X(i = 1){}
1781  */
1782 public void generateSyntheticOuterArgumentValues(BlockScope currentScope, ReferenceBinding targetType, ASTNode invocationSite) {
1783
1784         // generate the synthetic outer arguments then
1785         SyntheticArgumentBinding syntheticArguments[];
1786         if ((syntheticArguments = targetType.syntheticOuterLocalVariables()) != null) {
1787                 for (int i = 0, max = syntheticArguments.length; i < max; i++) {
1788                         LocalVariableBinding targetVariable = syntheticArguments[i].actualOuterLocalVariable;
1789                         VariableBinding[] emulationPath = currentScope.getEmulationPath(targetVariable);
1790                         this.generateOuterAccess(emulationPath, invocationSite, targetVariable, currentScope);
1791                 }
1792         }
1793 }
1794
1795 /**
1796  * @param accessBinding the access method binding to generate
1797  */
1798 public void generateSyntheticBodyForConstructorAccess(SyntheticAccessMethodBinding accessBinding) {
1799
1800         initializeMaxLocals(accessBinding);
1801
1802         MethodBinding constructorBinding = accessBinding.targetMethod;
1803         TypeBinding[] parameters = constructorBinding.parameters;
1804         int length = parameters.length;
1805         int resolvedPosition = 1;
1806         this.aload_0();
1807         if (constructorBinding.declaringClass.isNestedType()) {
1808                 NestedTypeBinding nestedType = (NestedTypeBinding) constructorBinding.declaringClass;
1809                 SyntheticArgumentBinding[] syntheticArguments = nestedType.syntheticEnclosingInstances();
1810                 for (int i = 0; i < (syntheticArguments == null ? 0 : syntheticArguments.length); i++) {
1811                         TypeBinding type;
1812                         load((type = syntheticArguments[i].type), resolvedPosition);
1813                         if ((type == DoubleBinding) || (type == LongBinding))
1814                                 resolvedPosition += 2;
1815                         else
1816                                 resolvedPosition++;
1817                 }
1818         }
1819         for (int i = 0; i < length; i++) {
1820                 load(parameters[i], resolvedPosition);
1821                 if ((parameters[i] == DoubleBinding) || (parameters[i] == LongBinding))
1822                         resolvedPosition += 2;
1823                 else
1824                         resolvedPosition++;
1825         }
1826         
1827         if (constructorBinding.declaringClass.isNestedType()) {
1828                 NestedTypeBinding nestedType = (NestedTypeBinding) constructorBinding.declaringClass;
1829                 SyntheticArgumentBinding[] syntheticArguments = nestedType.syntheticOuterLocalVariables();
1830                 for (int i = 0; i < (syntheticArguments == null ? 0 : syntheticArguments.length); i++) {
1831                         TypeBinding type;
1832                         load((type = syntheticArguments[i].type), resolvedPosition);
1833                         if ((type == DoubleBinding) || (type == LongBinding))
1834                                 resolvedPosition += 2;
1835                         else
1836                                 resolvedPosition++;
1837                 }
1838         }
1839         this.invokespecial(constructorBinding);
1840         this.return_();
1841 }
1842 public void generateSyntheticBodyForFieldReadAccess(SyntheticAccessMethodBinding accessBinding) {
1843         initializeMaxLocals(accessBinding);
1844         FieldBinding fieldBinding = accessBinding.targetReadField;
1845         TypeBinding type;
1846         if (fieldBinding.isStatic())
1847                 this.getstatic(fieldBinding);
1848         else {
1849                 this.aload_0();
1850                 this.getfield(fieldBinding);
1851         }
1852         if ((type = fieldBinding.type).isBaseType()) {
1853                 if (type == IntBinding)
1854                         this.ireturn();
1855                 else
1856                         if (type == FloatBinding)
1857                                 this.freturn();
1858                         else
1859                                 if (type == LongBinding)
1860                                         this.lreturn();
1861                                 else
1862                                         if (type == DoubleBinding)
1863                                                 this.dreturn();
1864                                         else
1865                                                 this.ireturn();
1866         } else
1867                 this.areturn();
1868 }
1869 public void generateSyntheticBodyForFieldWriteAccess(SyntheticAccessMethodBinding accessBinding) {
1870         initializeMaxLocals(accessBinding);
1871         FieldBinding fieldBinding = accessBinding.targetWriteField;
1872         if (fieldBinding.isStatic()) {
1873                 load(fieldBinding.type, 0);
1874                 this.putstatic(fieldBinding);
1875         } else {
1876                 this.aload_0();
1877                 load(fieldBinding.type, 1);
1878                 this.putfield(fieldBinding);
1879         }
1880         this.return_();
1881 }
1882 public void generateSyntheticBodyForMethodAccess(SyntheticAccessMethodBinding accessBinding) {
1883
1884         initializeMaxLocals(accessBinding);
1885         MethodBinding methodBinding = accessBinding.targetMethod;
1886         TypeBinding[] parameters = methodBinding.parameters;
1887         int length = parameters.length;
1888         int resolvedPosition;
1889         if (methodBinding.isStatic())
1890                 resolvedPosition = 0;
1891         else {
1892                 this.aload_0();
1893                 resolvedPosition = 1;
1894         }
1895         for (int i = 0; i < length; i++) {
1896                 load(parameters[i], resolvedPosition);
1897                 if ((parameters[i] == DoubleBinding) || (parameters[i] == LongBinding))
1898                         resolvedPosition += 2;
1899                 else
1900                         resolvedPosition++;
1901         }
1902         TypeBinding type;
1903         if (methodBinding.isStatic())
1904                 this.invokestatic(methodBinding);
1905         else {
1906                 if (methodBinding.isConstructor()
1907                         || methodBinding.isPrivate()
1908                         // qualified super "X.super.foo()" targets methods from superclass
1909                         || accessBinding.accessType == SyntheticAccessMethodBinding.SuperMethodAccess){
1910                         this.invokespecial(methodBinding);
1911                 } else {
1912                         if (methodBinding.declaringClass.isInterface()){
1913                                 this.invokeinterface(methodBinding);
1914                         } else {
1915                                 this.invokevirtual(methodBinding);
1916                         }
1917                 }
1918         }
1919         if ((type = methodBinding.returnType).isBaseType())
1920                 if (type == VoidBinding)
1921                         this.return_();
1922                 else
1923                         if (type == IntBinding)
1924                                 this.ireturn();
1925                         else
1926                                 if (type == FloatBinding)
1927                                         this.freturn();
1928                                 else
1929                                         if (type == LongBinding)
1930                                                 this.lreturn();
1931                                         else
1932                                                 if (type == DoubleBinding)
1933                                                         this.dreturn();
1934                                                 else
1935                                                         this.ireturn();
1936         else
1937                 this.areturn();
1938 }
1939 final public byte[] getContents() {
1940         byte[] contents;
1941         System.arraycopy(bCodeStream, 0, contents = new byte[position], 0, position);
1942         return contents;
1943 }
1944 final public void getfield(FieldBinding fieldBinding) {
1945         if (DEBUG) System.out.println(position + "\t\tgetfield:"+fieldBinding); //$NON-NLS-1$
1946         countLabels = 0;
1947         if ((fieldBinding.type.id == T_double) || (fieldBinding.type.id == T_long)) {
1948                 if (++stackDepth > stackMax)
1949                         stackMax = stackDepth;
1950         }
1951         if (classFileOffset + 2 >= bCodeStream.length) {
1952                 resizeByteArray();
1953         }
1954         position++;
1955         bCodeStream[classFileOffset++] = OPC_getfield;
1956         writeUnsignedShort(constantPool.literalIndex(fieldBinding));
1957 }
1958 final public void getstatic(FieldBinding fieldBinding) {
1959         if (DEBUG) System.out.println(position + "\t\tgetstatic:"+fieldBinding); //$NON-NLS-1$
1960         countLabels = 0;
1961         if ((fieldBinding.type.id == T_double) || (fieldBinding.type.id == T_long))
1962                 stackDepth += 2;
1963         else
1964                 stackDepth += 1;
1965         if (stackDepth > stackMax)
1966                 stackMax = stackDepth;
1967         if (classFileOffset + 2 >= bCodeStream.length) {
1968                 resizeByteArray();
1969         }
1970         position++;
1971         bCodeStream[classFileOffset++] = OPC_getstatic;
1972         writeUnsignedShort(constantPool.literalIndex(fieldBinding));
1973 }
1974 public void getTYPE(int baseTypeID) {
1975         countLabels = 0;
1976         if (++stackDepth > stackMax)
1977                 stackMax = stackDepth;
1978         if (classFileOffset + 2 >= bCodeStream.length) {
1979                 resizeByteArray();
1980         }
1981         position++;
1982         bCodeStream[classFileOffset++] = OPC_getstatic;
1983         switch (baseTypeID) {
1984                 case T_byte :
1985                         // getstatic: java.lang.Byte.TYPE                       
1986                         if (DEBUG) System.out.println(position + "\t\tgetstatic: java.lang.Byte.TYPE"); //$NON-NLS-1$
1987                         writeUnsignedShort(constantPool.literalIndexForJavaLangByteTYPE());
1988                         break;
1989                 case T_short :
1990                         // getstatic: java.lang.Short.TYPE                      
1991                         if (DEBUG) System.out.println(position + "\t\tgetstatic: java.lang.Short.TYPE"); //$NON-NLS-1$
1992                         writeUnsignedShort(constantPool.literalIndexForJavaLangShortTYPE());
1993                         break;
1994                 case T_char :
1995                         // getstatic: java.lang.Character.TYPE                  
1996                         if (DEBUG) System.out.println(position + "\t\tgetstatic: java.lang.Character.TYPE"); //$NON-NLS-1$
1997                         writeUnsignedShort(constantPool.literalIndexForJavaLangCharacterTYPE());
1998                         break;
1999                 case T_int :
2000                         // getstatic: java.lang.Integer.TYPE                    
2001                         if (DEBUG) System.out.println(position + "\t\tgetstatic: java.lang.Integer.TYPE"); //$NON-NLS-1$
2002                         writeUnsignedShort(constantPool.literalIndexForJavaLangIntegerTYPE());
2003                         break;
2004                 case T_long :
2005                         // getstatic: java.lang.Long.TYPE                       
2006                         if (DEBUG) System.out.println(position + "\t\tgetstatic: java.lang.Long.TYPE"); //$NON-NLS-1$
2007                         writeUnsignedShort(constantPool.literalIndexForJavaLangLongTYPE());
2008                         break;
2009                 case T_float :
2010                         // getstatic: java.lang.Float.TYPE                      
2011                         if (DEBUG) System.out.println(position + "\t\tgetstatic: java.lang.Float.TYPE"); //$NON-NLS-1$
2012                         writeUnsignedShort(constantPool.literalIndexForJavaLangFloatTYPE());
2013                         break;
2014                 case T_double :
2015                         // getstatic: java.lang.Double.TYPE                     
2016                         if (DEBUG) System.out.println(position + "\t\tgetstatic: java.lang.Double.TYPE"); //$NON-NLS-1$
2017                         writeUnsignedShort(constantPool.literalIndexForJavaLangDoubleTYPE());
2018                         break;
2019                 case T_boolean :
2020                         // getstatic: java.lang.Boolean.TYPE                    
2021                         if (DEBUG) System.out.println(position + "\t\tgetstatic: java.lang.Boolean.TYPE"); //$NON-NLS-1$
2022                         writeUnsignedShort(constantPool.literalIndexForJavaLangBooleanTYPE());
2023                         break;
2024                 case T_void :
2025                         // getstatic: java.lang.Void.TYPE
2026                         if (DEBUG) System.out.println(position + "\t\tgetstatic: java.lang.Void.TYPE"); //$NON-NLS-1$
2027                         writeUnsignedShort(constantPool.literalIndexForJavaLangVoidTYPE());
2028                         break;
2029         }
2030 }
2031 /**
2032  * We didn't call it goto, because there is a conflit with the goto keyword
2033  */
2034 final public void goto_(Label label) {
2035         if (this.wideMode) {
2036                 this.goto_w(label);
2037                 return;
2038         }
2039         if (DEBUG) System.out.println(position + "\t\tgoto:"+label); //$NON-NLS-1$
2040         if (classFileOffset >= bCodeStream.length) {
2041                 resizeByteArray();
2042         }
2043         label.inlineForwardReferencesFromLabelsTargeting(position);
2044         /*
2045          Possible optimization for code such as:
2046          public Object foo() {
2047                 boolean b = true;
2048                 if (b) {
2049                         if (b)
2050                                 return null;
2051                 } else {
2052                         if (b) {
2053                                 return null;
2054                         }
2055                 }
2056                 return null;
2057         }
2058         The goto around the else block for the first if will
2059         be unreachable, because the thenClause of the second if
2060         returns.
2061         See inlineForwardReferencesFromLabelsTargeting defined
2062         on the Label class for the remaining part of this
2063         optimization.
2064          if (!lbl.isBranchTarget(position)) {
2065                 switch(bCodeStream[classFileOffset-1]) {
2066                         case OPC_return :
2067                         case OPC_areturn:
2068                                 return;
2069                 }
2070         }*/
2071         position++;
2072         bCodeStream[classFileOffset++] = OPC_goto;
2073         label.branch();
2074 }
2075
2076 final public void goto_w(Label lbl) {
2077         if (DEBUG) System.out.println(position + "\t\tgotow:"+lbl); //$NON-NLS-1$
2078         if (classFileOffset >= bCodeStream.length) {
2079                 resizeByteArray();
2080         }
2081         position++;
2082         bCodeStream[classFileOffset++] = OPC_goto_w;
2083         lbl.branchWide();
2084 }
2085 final public void i2b() {
2086         if (DEBUG) System.out.println(position + "\t\ti2b"); //$NON-NLS-1$
2087         countLabels = 0;
2088         if (classFileOffset >= bCodeStream.length) {
2089                 resizeByteArray();
2090         }
2091         position++;
2092         bCodeStream[classFileOffset++] = OPC_i2b;
2093 }
2094 final public void i2c() {
2095         if (DEBUG) System.out.println(position + "\t\ti2c"); //$NON-NLS-1$
2096         countLabels = 0;
2097         if (classFileOffset >= bCodeStream.length) {
2098                 resizeByteArray();
2099         }
2100         position++;
2101         bCodeStream[classFileOffset++] = OPC_i2c;
2102 }
2103 final public void i2d() {
2104         if (DEBUG) System.out.println(position + "\t\ti2d"); //$NON-NLS-1$
2105         countLabels = 0;
2106         stackDepth++;
2107         if (stackDepth > stackMax)
2108                 stackMax = stackDepth;
2109         if (classFileOffset >= bCodeStream.length) {
2110                 resizeByteArray();
2111         }
2112         position++;
2113         bCodeStream[classFileOffset++] = OPC_i2d;
2114 }
2115 final public void i2f() {
2116         if (DEBUG) System.out.println(position + "\t\ti2f"); //$NON-NLS-1$
2117         countLabels = 0;
2118         if (classFileOffset >= bCodeStream.length) {
2119                 resizeByteArray();
2120         }
2121         position++;
2122         bCodeStream[classFileOffset++] = OPC_i2f;
2123 }
2124 final public void i2l() {
2125         if (DEBUG) System.out.println(position + "\t\ti2l"); //$NON-NLS-1$
2126         countLabels = 0;
2127         stackDepth++;
2128         if (stackDepth > stackMax)
2129                 stackMax = stackDepth;
2130         if (classFileOffset >= bCodeStream.length) {
2131                 resizeByteArray();
2132         }
2133         position++;
2134         bCodeStream[classFileOffset++] = OPC_i2l;
2135 }
2136 final public void i2s() {
2137         if (DEBUG) System.out.println(position + "\t\ti2s"); //$NON-NLS-1$
2138         countLabels = 0;
2139         if (classFileOffset >= bCodeStream.length) {
2140                 resizeByteArray();
2141         }
2142         position++;
2143         bCodeStream[classFileOffset++] = OPC_i2s;
2144 }
2145 final public void iadd() {
2146         if (DEBUG) System.out.println(position + "\t\tiadd"); //$NON-NLS-1$
2147         countLabels = 0;
2148         stackDepth--;
2149         if (classFileOffset >= bCodeStream.length) {
2150                 resizeByteArray();
2151         }
2152         position++;
2153         bCodeStream[classFileOffset++] = OPC_iadd;
2154 }
2155 final public void iaload() {
2156         if (DEBUG) System.out.println(position + "\t\tiaload"); //$NON-NLS-1$
2157         countLabels = 0;
2158         stackDepth--;
2159         if (classFileOffset >= bCodeStream.length) {
2160                 resizeByteArray();
2161         }
2162         position++;
2163         bCodeStream[classFileOffset++] = OPC_iaload;
2164 }
2165 final public void iand() {
2166         if (DEBUG) System.out.println(position + "\t\tiand"); //$NON-NLS-1$
2167         countLabels = 0;
2168         stackDepth--;
2169         if (classFileOffset >= bCodeStream.length) {
2170                 resizeByteArray();
2171         }
2172         position++;
2173         bCodeStream[classFileOffset++] = OPC_iand;
2174 }
2175 final public void iastore() {
2176         if (DEBUG) System.out.println(position + "\t\tiastore"); //$NON-NLS-1$
2177         countLabels = 0;
2178         stackDepth -= 3;
2179         if (classFileOffset >= bCodeStream.length) {
2180                 resizeByteArray();
2181         }
2182         position++;
2183         bCodeStream[classFileOffset++] = OPC_iastore;
2184 }
2185 final public void iconst_0() {
2186         if (DEBUG) System.out.println(position + "\t\ticonst_0"); //$NON-NLS-1$
2187         countLabels = 0;
2188         stackDepth++;
2189         if (stackDepth > stackMax)
2190                 stackMax = stackDepth;
2191         if (classFileOffset >= bCodeStream.length) {
2192                 resizeByteArray();
2193         }
2194         position++;
2195         bCodeStream[classFileOffset++] = OPC_iconst_0;
2196 }
2197 final public void iconst_1() {
2198         if (DEBUG) System.out.println(position + "\t\ticonst_1"); //$NON-NLS-1$
2199         countLabels = 0;
2200         stackDepth++;
2201         if (stackDepth > stackMax)
2202                 stackMax = stackDepth;
2203         if (classFileOffset >= bCodeStream.length) {
2204                 resizeByteArray();
2205         }
2206         position++;
2207         bCodeStream[classFileOffset++] = OPC_iconst_1;
2208 }
2209 final public void iconst_2() {
2210         if (DEBUG) System.out.println(position + "\t\ticonst_2"); //$NON-NLS-1$
2211         countLabels = 0;
2212         stackDepth++;
2213         if (stackDepth > stackMax)
2214                 stackMax = stackDepth;
2215         if (classFileOffset >= bCodeStream.length) {
2216                 resizeByteArray();
2217         }
2218         position++;
2219         bCodeStream[classFileOffset++] = OPC_iconst_2;
2220 }
2221 final public void iconst_3() {
2222         if (DEBUG) System.out.println(position + "\t\ticonst_3"); //$NON-NLS-1$
2223         countLabels = 0;
2224         stackDepth++;
2225         if (stackDepth > stackMax)
2226                 stackMax = stackDepth;
2227         if (classFileOffset >= bCodeStream.length) {
2228                 resizeByteArray();
2229         }
2230         position++;
2231         bCodeStream[classFileOffset++] = OPC_iconst_3;
2232 }
2233 final public void iconst_4() {
2234         if (DEBUG) System.out.println(position + "\t\ticonst_4"); //$NON-NLS-1$
2235         countLabels = 0;
2236         stackDepth++;
2237         if (stackDepth > stackMax)
2238                 stackMax = stackDepth;
2239         if (classFileOffset >= bCodeStream.length) {
2240                 resizeByteArray();
2241         }
2242         position++;
2243         bCodeStream[classFileOffset++] = OPC_iconst_4;
2244 }
2245 final public void iconst_5() {
2246         if (DEBUG) System.out.println(position + "\t\ticonst_5"); //$NON-NLS-1$
2247         countLabels = 0;
2248         stackDepth++;
2249         if (stackDepth > stackMax)
2250                 stackMax = stackDepth;
2251         if (classFileOffset >= bCodeStream.length) {
2252                 resizeByteArray();
2253         }
2254         position++;
2255         bCodeStream[classFileOffset++] = OPC_iconst_5;
2256 }
2257 final public void iconst_m1() {
2258         if (DEBUG) System.out.println(position + "\t\ticonst_m1"); //$NON-NLS-1$
2259         countLabels = 0;
2260         stackDepth++;
2261         if (stackDepth > stackMax)
2262                 stackMax = stackDepth;
2263         if (classFileOffset >= bCodeStream.length) {
2264                 resizeByteArray();
2265         }
2266         position++;
2267         bCodeStream[classFileOffset++] = OPC_iconst_m1;
2268 }
2269 final public void idiv() {
2270         if (DEBUG) System.out.println(position + "\t\tidiv"); //$NON-NLS-1$
2271         countLabels = 0;
2272         stackDepth--;
2273         if (classFileOffset >= bCodeStream.length) {
2274                 resizeByteArray();
2275         }
2276         position++;
2277         bCodeStream[classFileOffset++] = OPC_idiv;
2278 }
2279 final public void if_acmpeq(Label lbl) {
2280         if (DEBUG) System.out.println(position + "\t\tif_acmpeq:"+lbl); //$NON-NLS-1$
2281         countLabels = 0;
2282         stackDepth-=2;
2283         if (this.wideMode) {
2284                 generateWideRevertedConditionalBranch(OPC_if_acmpne, lbl);
2285         } else {        
2286                 if (classFileOffset >= bCodeStream.length) {
2287                         resizeByteArray();
2288                 }
2289                 position++;
2290                 bCodeStream[classFileOffset++] = OPC_if_acmpeq;
2291                 lbl.branch();
2292         }
2293 }
2294 final public void if_acmpne(Label lbl) {
2295         if (DEBUG) System.out.println(position + "\t\tif_acmpne:"+lbl); //$NON-NLS-1$
2296         countLabels = 0;
2297         stackDepth-=2;
2298         if (this.wideMode) {
2299                 generateWideRevertedConditionalBranch(OPC_if_acmpeq, lbl);
2300         } else {        
2301                 if (classFileOffset >= bCodeStream.length) {
2302                         resizeByteArray();
2303                 }
2304                 position++;
2305                 bCodeStream[classFileOffset++] = OPC_if_acmpne;
2306                 lbl.branch();
2307         }
2308 }
2309 final public void if_icmpeq(Label lbl) {
2310         if (DEBUG) System.out.println(position + "\t\tif_cmpeq:"+lbl); //$NON-NLS-1$
2311         countLabels = 0;
2312         stackDepth -= 2;
2313         if (this.wideMode) {
2314                 generateWideRevertedConditionalBranch(OPC_if_icmpne, lbl);
2315         } else {        
2316                 if (classFileOffset >= bCodeStream.length) {
2317                         resizeByteArray();
2318                 }
2319                 position++;
2320                 bCodeStream[classFileOffset++] = OPC_if_icmpeq;
2321                 lbl.branch();
2322         }
2323 }
2324 final public void if_icmpge(Label lbl) {
2325         if (DEBUG) System.out.println(position + "\t\tif_iacmpge:"+lbl); //$NON-NLS-1$
2326         countLabels = 0;
2327         stackDepth -= 2;
2328         if (this.wideMode) {
2329                 generateWideRevertedConditionalBranch(OPC_if_icmplt, lbl);
2330         } else {        
2331                 if (classFileOffset >= bCodeStream.length) {
2332                         resizeByteArray();
2333                 }
2334                 position++;
2335                 bCodeStream[classFileOffset++] = OPC_if_icmpge;
2336                 lbl.branch();
2337         }
2338 }
2339 final public void if_icmpgt(Label lbl) {
2340         if (DEBUG) System.out.println(position + "\t\tif_iacmpgt:"+lbl); //$NON-NLS-1$
2341         countLabels = 0;
2342         stackDepth -= 2;
2343         if (this.wideMode) {
2344                 generateWideRevertedConditionalBranch(OPC_if_icmple, lbl);
2345         } else {        
2346                 if (classFileOffset >= bCodeStream.length) {
2347                         resizeByteArray();
2348                 }
2349                 position++;
2350                 bCodeStream[classFileOffset++] = OPC_if_icmpgt;
2351                 lbl.branch();
2352         }
2353 }
2354 final public void if_icmple(Label lbl) {
2355         if (DEBUG) System.out.println(position + "\t\tif_iacmple:"+lbl); //$NON-NLS-1$
2356         countLabels = 0;
2357         stackDepth -= 2;
2358         if (this.wideMode) {
2359                 generateWideRevertedConditionalBranch(OPC_if_icmpgt, lbl);
2360         } else {        
2361                 if (classFileOffset >= bCodeStream.length) {
2362                         resizeByteArray();
2363                 }
2364                 position++;
2365                 bCodeStream[classFileOffset++] = OPC_if_icmple;
2366                 lbl.branch();
2367         }
2368 }
2369 final public void if_icmplt(Label lbl) {
2370         if (DEBUG) System.out.println(position + "\t\tif_iacmplt:"+lbl); //$NON-NLS-1$
2371         countLabels = 0;
2372         stackDepth -= 2;
2373         if (this.wideMode) {
2374                 generateWideRevertedConditionalBranch(OPC_if_icmpge, lbl);
2375         } else {
2376                 if (classFileOffset >= bCodeStream.length) {
2377                         resizeByteArray();
2378                 }
2379                 position++;
2380                 bCodeStream[classFileOffset++] = OPC_if_icmplt;
2381                 lbl.branch();
2382         }
2383 }
2384 final public void if_icmpne(Label lbl) {
2385         if (DEBUG) System.out.println(position + "\t\tif_iacmpne:"+lbl); //$NON-NLS-1$
2386         countLabels = 0;
2387         stackDepth -= 2;
2388         if (this.wideMode) {
2389                 generateWideRevertedConditionalBranch(OPC_if_icmpeq, lbl);
2390         } else {
2391                 if (classFileOffset >= bCodeStream.length) {
2392                         resizeByteArray();
2393                 }
2394                 position++;
2395                 bCodeStream[classFileOffset++] = OPC_if_icmpne;
2396                 lbl.branch();
2397         }
2398 }
2399 final public void ifeq(Label lbl) {
2400         if (DEBUG) System.out.println(position + "\t\tifeq:"+lbl); //$NON-NLS-1$
2401         countLabels = 0;
2402         stackDepth--;
2403         if (this.wideMode) {
2404                 generateWideRevertedConditionalBranch(OPC_ifne, lbl);
2405         } else {
2406                 if (classFileOffset >= bCodeStream.length) {
2407                         resizeByteArray();
2408                 }
2409                 position++;
2410                 bCodeStream[classFileOffset++] = OPC_ifeq;
2411                 lbl.branch();
2412         }
2413 }
2414 final public void ifge(Label lbl) {
2415         if (DEBUG) System.out.println(position + "\t\tifge:"+lbl); //$NON-NLS-1$
2416         countLabels = 0;
2417         stackDepth--;
2418         if (this.wideMode) {
2419                 generateWideRevertedConditionalBranch(OPC_iflt, lbl);
2420         } else {
2421                 if (classFileOffset >= bCodeStream.length) {
2422                         resizeByteArray();
2423                 }
2424                 position++;
2425                 bCodeStream[classFileOffset++] = OPC_ifge;
2426                 lbl.branch();
2427         }
2428 }
2429 final public void ifgt(Label lbl) {
2430         if (DEBUG) System.out.println(position + "\t\tifgt:"+lbl); //$NON-NLS-1$
2431         countLabels = 0;
2432         stackDepth--;
2433         if (this.wideMode) {
2434                 generateWideRevertedConditionalBranch(OPC_ifle, lbl);
2435         } else {
2436                 if (classFileOffset >= bCodeStream.length) {
2437                         resizeByteArray();
2438                 }
2439                 position++;
2440                 bCodeStream[classFileOffset++] = OPC_ifgt;
2441                 lbl.branch();
2442         }
2443 }
2444 final public void ifle(Label lbl) {
2445         if (DEBUG) System.out.println(position + "\t\tifle:"+lbl); //$NON-NLS-1$
2446         countLabels = 0;
2447         stackDepth--;
2448         if (this.wideMode) {
2449                 generateWideRevertedConditionalBranch(OPC_ifgt, lbl);
2450         } else {
2451                 if (classFileOffset >= bCodeStream.length) {
2452                         resizeByteArray();
2453                 }
2454                 position++;
2455                 bCodeStream[classFileOffset++] = OPC_ifle;
2456                 lbl.branch();
2457         }
2458 }
2459 final public void iflt(Label lbl) {
2460         if (DEBUG) System.out.println(position + "\t\tiflt:"+lbl); //$NON-NLS-1$
2461         countLabels = 0;
2462         stackDepth--;
2463         if (this.wideMode) {
2464                 generateWideRevertedConditionalBranch(OPC_ifge, lbl);
2465         } else {
2466                 if (classFileOffset >= bCodeStream.length) {
2467                         resizeByteArray();
2468                 }
2469                 position++;
2470                 bCodeStream[classFileOffset++] = OPC_iflt;
2471                 lbl.branch();
2472         }
2473 }
2474 final public void ifne(Label lbl) {
2475         if (DEBUG) System.out.println(position + "\t\tifne:"+lbl); //$NON-NLS-1$
2476         countLabels = 0;
2477         stackDepth--;
2478         if (this.wideMode) {
2479                 generateWideRevertedConditionalBranch(OPC_ifeq, lbl);
2480         } else {
2481                 if (classFileOffset >= bCodeStream.length) {
2482                         resizeByteArray();
2483                 }
2484                 position++;
2485                 bCodeStream[classFileOffset++] = OPC_ifne;
2486                 lbl.branch();
2487         }
2488 }
2489 final public void ifnonnull(Label lbl) {
2490         if (DEBUG) System.out.println(position + "\t\tifnonnull:"+lbl); //$NON-NLS-1$
2491         countLabels = 0;
2492         stackDepth--;
2493         if (this.wideMode) {
2494                 generateWideRevertedConditionalBranch(OPC_ifnull, lbl);
2495         } else {
2496                 if (classFileOffset >= bCodeStream.length) {
2497                         resizeByteArray();
2498                 }
2499                 position++;
2500                 bCodeStream[classFileOffset++] = OPC_ifnonnull;
2501                 lbl.branch();
2502         }
2503 }
2504 final public void ifnull(Label lbl) {
2505         if (DEBUG) System.out.println(position + "\t\tifnull:"+lbl); //$NON-NLS-1$
2506         countLabels = 0;
2507         stackDepth--;
2508         if (this.wideMode) {
2509                 generateWideRevertedConditionalBranch(OPC_ifnonnull, lbl);
2510         } else {
2511                 if (classFileOffset >= bCodeStream.length) {
2512                         resizeByteArray();
2513                 }
2514                 position++;
2515                 bCodeStream[classFileOffset++] = OPC_ifnull;
2516                 lbl.branch();
2517         }
2518 }
2519 final public void iinc(int index, int value) {
2520         if (DEBUG) System.out.println(position + "\t\tiinc:"+index+","+value); //$NON-NLS-1$ //$NON-NLS-2$
2521         countLabels = 0;
2522         if ((index > 255) || (value < -128 || value > 127)) { // have to widen
2523                 if (classFileOffset + 3 >= bCodeStream.length) {
2524                         resizeByteArray();
2525                 }
2526                 position += 2;
2527                 bCodeStream[classFileOffset++] = OPC_wide;
2528                 bCodeStream[classFileOffset++] = OPC_iinc;
2529                 writeUnsignedShort(index);
2530                 writeSignedShort(value);
2531         } else {
2532                 if (classFileOffset + 2 >= bCodeStream.length) {
2533                         resizeByteArray();
2534                 }
2535                 position += 3;
2536                 bCodeStream[classFileOffset++] = OPC_iinc;
2537                 bCodeStream[classFileOffset++] = (byte) index;
2538                 bCodeStream[classFileOffset++] = (byte) value;
2539         }
2540 }
2541 final public void iload(int iArg) {
2542         if (DEBUG) System.out.println(position + "\t\tiload:"+iArg); //$NON-NLS-1$
2543         countLabels = 0;
2544         stackDepth++;
2545         if (maxLocals <= iArg) {
2546                 maxLocals = iArg + 1;
2547         }
2548         if (stackDepth > stackMax)
2549                 stackMax = stackDepth;
2550         if (iArg > 255) { // Widen
2551                 if (classFileOffset + 3 >= bCodeStream.length) {
2552                         resizeByteArray();
2553                 }
2554                 position += 2;
2555                 bCodeStream[classFileOffset++] = OPC_wide;
2556                 bCodeStream[classFileOffset++] = OPC_iload;
2557                 writeUnsignedShort(iArg);
2558         } else {
2559                 if (classFileOffset + 1 >= bCodeStream.length) {
2560                         resizeByteArray();
2561                 }
2562                 position += 2;
2563                 bCodeStream[classFileOffset++] = OPC_iload;
2564                 bCodeStream[classFileOffset++] = (byte) iArg;
2565         }
2566 }
2567 final public void iload_0() {
2568         if (DEBUG) System.out.println(position + "\t\tiload_0"); //$NON-NLS-1$
2569         countLabels = 0;
2570         stackDepth++;
2571         if (maxLocals <= 0) {
2572                 maxLocals = 1;
2573         }
2574         if (stackDepth > stackMax)
2575                 stackMax = stackDepth;
2576         if (classFileOffset >= bCodeStream.length) {
2577                 resizeByteArray();
2578         }
2579         position++;
2580         bCodeStream[classFileOffset++] = OPC_iload_0;
2581 }
2582 final public void iload_1() {
2583         if (DEBUG) System.out.println(position + "\t\tiload_1"); //$NON-NLS-1$
2584         countLabels = 0;
2585         stackDepth++;
2586         if (maxLocals <= 1) {
2587                 maxLocals = 2;
2588         }
2589         if (stackDepth > stackMax)
2590                 stackMax = stackDepth;
2591         if (classFileOffset >= bCodeStream.length) {
2592                 resizeByteArray();
2593         }
2594         position++;
2595         bCodeStream[classFileOffset++] = OPC_iload_1;
2596 }
2597 final public void iload_2() {
2598         if (DEBUG) System.out.println(position + "\t\tiload_2"); //$NON-NLS-1$
2599         countLabels = 0;
2600         stackDepth++;
2601         if (maxLocals <= 2) {
2602                 maxLocals = 3;
2603         }
2604         if (stackDepth > stackMax)
2605                 stackMax = stackDepth;
2606         if (classFileOffset >= bCodeStream.length) {
2607                 resizeByteArray();
2608         }
2609         position++;
2610         bCodeStream[classFileOffset++] = OPC_iload_2;
2611 }
2612 final public void iload_3() {
2613         if (DEBUG) System.out.println(position + "\t\tiload_3"); //$NON-NLS-1$
2614         countLabels = 0;
2615         stackDepth++;
2616         if (maxLocals <= 3) {
2617                 maxLocals = 4;
2618         }
2619         if (stackDepth > stackMax)
2620                 stackMax = stackDepth;
2621         if (classFileOffset >= bCodeStream.length) {
2622                 resizeByteArray();
2623         }
2624         position++;
2625         bCodeStream[classFileOffset++] = OPC_iload_3;
2626 }
2627 final public void imul() {
2628         if (DEBUG) System.out.println(position + "\t\timul"); //$NON-NLS-1$
2629         countLabels = 0;
2630         stackDepth--;
2631         if (classFileOffset >= bCodeStream.length) {
2632                 resizeByteArray();
2633         }
2634         position++;
2635         bCodeStream[classFileOffset++] = OPC_imul;
2636 }
2637 public void incrementTemp(LocalVariableBinding localBinding, int value) {
2638         if (value == (short) value) {
2639                 this.iinc(localBinding.resolvedPosition, value);
2640                 return;
2641         }
2642         load(localBinding);
2643         this.ldc(value);
2644         this.iadd();
2645         store(localBinding, false);
2646 }
2647 public void incrStackSize(int offset) {
2648         if ((stackDepth += offset) > stackMax)
2649                 stackMax = stackDepth;
2650 }
2651 public int indexOfSameLineEntrySincePC(int pc, int line) {
2652         for (int index = pc, max = pcToSourceMapSize; index < max; index+=2) {
2653                 if (pcToSourceMap[index+1] == line)
2654                         return index;
2655         }
2656         return -1;
2657 }
2658 final public void ineg() {
2659         if (DEBUG) System.out.println(position + "\t\tineg"); //$NON-NLS-1$
2660         countLabels = 0;
2661         if (classFileOffset >= bCodeStream.length) {
2662                 resizeByteArray();
2663         }
2664         position++;
2665         bCodeStream[classFileOffset++] = OPC_ineg;
2666 }
2667 public void init(ClassFile targetClassFile) {
2668         this.classFile = targetClassFile;
2669         this.constantPool = targetClassFile.constantPool;
2670         this.bCodeStream = targetClassFile.contents;
2671         this.classFileOffset = targetClassFile.contentsOffset;
2672         this.startingClassFileOffset = this.classFileOffset;
2673         pcToSourceMapSize = 0;
2674         lastEntryPC = 0;
2675         int length = visibleLocals.length;
2676         if (noVisibleLocals.length < length) {
2677                 noVisibleLocals = new LocalVariableBinding[length];
2678         }
2679         System.arraycopy(noVisibleLocals, 0, visibleLocals, 0, length);
2680         visibleLocalsCount = 0;
2681         
2682         length = locals.length;
2683         if (noLocals.length < length) {
2684                 noLocals = new LocalVariableBinding[length];
2685         }
2686         System.arraycopy(noLocals, 0, locals, 0, length);
2687         allLocalsCounter = 0;
2688
2689         length = exceptionHandlers.length;
2690         if (noExceptionHandlers.length < length) {
2691                 noExceptionHandlers = new ExceptionLabel[length];
2692         }
2693         System.arraycopy(noExceptionHandlers, 0, exceptionHandlers, 0, length);
2694         exceptionHandlersNumber = 0;
2695         
2696         length = labels.length;
2697         if (noLabels.length < length) {
2698                 noLabels = new Label[length];
2699         }
2700         System.arraycopy(noLabels, 0, labels, 0, length);
2701         countLabels = 0;
2702
2703         stackMax = 0;
2704         stackDepth = 0;
2705         maxLocals = 0;
2706         position = 0;
2707 }
2708 /**
2709  * @param methodBinding the given method binding to initialize the max locals
2710  */
2711 public void initializeMaxLocals(MethodBinding methodBinding) {
2712
2713         maxLocals = (methodBinding == null || methodBinding.isStatic()) ? 0 : 1;
2714         // take into account the synthetic parameters
2715         if (methodBinding != null) {
2716                 if (methodBinding.isConstructor() && methodBinding.declaringClass.isNestedType()) {
2717                         ReferenceBinding enclosingInstanceTypes[];
2718                         if ((enclosingInstanceTypes = methodBinding.declaringClass.syntheticEnclosingInstanceTypes()) != null) {
2719                                 for (int i = 0, max = enclosingInstanceTypes.length; i < max; i++) {
2720                                         maxLocals++; // an enclosingInstanceType can only be a reference binding. It cannot be
2721                                         // LongBinding or DoubleBinding
2722                                 }
2723                         }
2724                         SyntheticArgumentBinding syntheticArguments[];
2725                         if ((syntheticArguments = methodBinding.declaringClass.syntheticOuterLocalVariables()) != null) {
2726                                 for (int i = 0, max = syntheticArguments.length; i < max; i++) {
2727                                         TypeBinding argType;
2728                                         if (((argType = syntheticArguments[i].type) == LongBinding) || (argType == DoubleBinding)) {
2729                                                 maxLocals += 2;
2730                                         } else {
2731                                                 maxLocals++;
2732                                         }
2733                                 }
2734                         }
2735                 }
2736                 TypeBinding[] arguments;
2737                 if ((arguments = methodBinding.parameters) != null) {
2738                         for (int i = 0, max = arguments.length; i < max; i++) {
2739                                 TypeBinding argType;
2740                                 if (((argType = arguments[i]) == LongBinding) || (argType == DoubleBinding)) {
2741                                         maxLocals += 2;
2742                                 } else {
2743                                         maxLocals++;
2744                                 }
2745                         }
2746                 }
2747         }
2748 }
2749 /**
2750  * This methods searches for an existing entry inside the pcToSourceMap table with a pc equals to @pc.
2751  * If there is an existing entry it returns -1 (no insertion required).
2752  * Otherwise it returns the index where the entry for the pc has to be inserted.
2753  * This is based on the fact that the pcToSourceMap table is sorted according to the pc.
2754  *
2755  * @param pcToSourceMap the given pcToSourceMap array
2756  * @param length the given length
2757  * @param pc the given pc
2758  * @return int
2759  */
2760 public static int insertionIndex(int[] pcToSourceMap, int length, int pc) {
2761         int g = 0;
2762         int d = length - 2;
2763         int m = 0;
2764         while (g <= d) {
2765                 m = (g + d) / 2;
2766                 // we search only on even indexes
2767                 if ((m % 2) != 0)
2768                         m--;
2769                 int currentPC = pcToSourceMap[m];
2770                 if (pc < currentPC) {
2771                         d = m - 2;
2772                 } else
2773                         if (pc > currentPC) {
2774                                 g = m + 2;
2775                         } else {
2776                                 return -1;
2777                         }
2778         }
2779         if (pc < pcToSourceMap[m])
2780                 return m;
2781         return m + 2;
2782 }
2783 /**
2784  * We didn't call it instanceof because there is a conflit with the
2785  * instanceof keyword
2786  */
2787 final public void instance_of(TypeBinding typeBinding) {
2788         if (DEBUG) System.out.println(position + "\t\tinstance_of:"+typeBinding); //$NON-NLS-1$
2789         countLabels = 0;
2790         if (classFileOffset + 2 >= bCodeStream.length) {
2791                 resizeByteArray();
2792         }
2793         position++;
2794         bCodeStream[classFileOffset++] = OPC_instanceof;
2795         writeUnsignedShort(constantPool.literalIndex(typeBinding));
2796 }
2797 public void invokeClassForName() {
2798         // invokestatic: java.lang.Class.forName(Ljava.lang.String;)Ljava.lang.Class;
2799         if (DEBUG) System.out.println(position + "\t\tinvokestatic: java.lang.Class.forName(Ljava.lang.String;)Ljava.lang.Class;"); //$NON-NLS-1$
2800         countLabels = 0;
2801         if (classFileOffset + 2 >= bCodeStream.length) {
2802                 resizeByteArray();
2803         }
2804         position++;
2805         bCodeStream[classFileOffset++] = OPC_invokestatic;
2806         writeUnsignedShort(constantPool.literalIndexForJavaLangClassForName());
2807 }
2808
2809 public void invokeJavaLangClassDesiredAssertionStatus() {
2810         // invokevirtual: java.lang.Class.desiredAssertionStatus()Z;
2811         if (DEBUG) System.out.println(position + "\t\tinvokevirtual: java.lang.Class.desiredAssertionStatus()Z;"); //$NON-NLS-1$
2812         countLabels = 0;
2813         stackDepth--;
2814         if (classFileOffset + 2 >= bCodeStream.length) {
2815                 resizeByteArray();
2816         }
2817         position++;
2818         bCodeStream[classFileOffset++] = OPC_invokevirtual;
2819         writeUnsignedShort(constantPool.literalIndexForJavaLangClassDesiredAssertionStatus());
2820 }
2821
2822 public void invokeJavaLangClassGetComponentType() {
2823         // invokevirtual: java.lang.Class.getComponentType()java.lang.Class;
2824         if (DEBUG) System.out.println(position + "\t\tinvokevirtual: java.lang.Class.getComponentType()java.lang.Class;"); //$NON-NLS-1$
2825         countLabels = 0;
2826         if (classFileOffset + 2 >= bCodeStream.length) {
2827                 resizeByteArray();
2828         }
2829         position++;
2830         bCodeStream[classFileOffset++] = OPC_invokevirtual;
2831         writeUnsignedShort(constantPool.literalIndexForJavaLangClassGetComponentType());
2832 }
2833
2834 final public void invokeinterface(MethodBinding methodBinding) {
2835         // initialized to 1 to take into account this  immediately
2836         if (DEBUG) System.out.println(position + "\t\tinvokeinterface: " + methodBinding); //$NON-NLS-1$
2837         countLabels = 0;
2838         int argCount = 1;
2839         int id;
2840         if (classFileOffset + 4 >= bCodeStream.length) {
2841                 resizeByteArray();
2842         }
2843         position += 3;
2844         bCodeStream[classFileOffset++] = OPC_invokeinterface;
2845         writeUnsignedShort(constantPool.literalIndex(methodBinding));
2846         for (int i = methodBinding.parameters.length - 1; i >= 0; i--)
2847                 if (((id = methodBinding.parameters[i].id) == T_double) || (id == T_long))
2848                         argCount += 2;
2849                 else
2850                         argCount += 1;
2851         bCodeStream[classFileOffset++] = (byte) argCount;
2852         // Generate a  0 into the byte array. Like the array is already fill with 0, we just need to increment
2853         // the number of bytes.
2854         bCodeStream[classFileOffset++] = 0;
2855         if (((id = methodBinding.returnType.id) == T_double) || (id == T_long)) {
2856                 stackDepth += (2 - argCount);
2857         } else {
2858                 if (id == T_void) {
2859                         stackDepth -= argCount;
2860                 } else {
2861                         stackDepth += (1 - argCount);
2862                 }
2863         }
2864         if (stackDepth > stackMax) {
2865                 stackMax = stackDepth;
2866         }
2867 }
2868 public void invokeJavaLangErrorConstructor() {
2869         // invokespecial: java.lang.Error<init>(Ljava.lang.String;)V
2870         if (DEBUG) System.out.println(position + "\t\tinvokespecial: java.lang.Error<init>(Ljava.lang.String;)V"); //$NON-NLS-1$
2871         countLabels = 0;
2872         if (classFileOffset + 2 >= bCodeStream.length) {
2873                 resizeByteArray();
2874         }
2875         position++;
2876         bCodeStream[classFileOffset++] = OPC_invokespecial;
2877         stackDepth -= 2;
2878         writeUnsignedShort(constantPool.literalIndexForJavaLangErrorConstructor());
2879 }
2880 public void invokeNoClassDefFoundErrorStringConstructor() {
2881         // invokespecial: java.lang.NoClassDefFoundError.<init>(Ljava.lang.String;)V
2882         if (DEBUG) System.out.println(position + "\t\tinvokespecial: java.lang.NoClassDefFoundError.<init>(Ljava.lang.String;)V"); //$NON-NLS-1$
2883         countLabels = 0;
2884         if (classFileOffset + 2 >= bCodeStream.length) {
2885                 resizeByteArray();
2886         }
2887         position++;
2888         bCodeStream[classFileOffset++] = OPC_invokespecial;
2889         stackDepth -= 2;
2890         writeUnsignedShort(constantPool.literalIndexForJavaLangNoClassDefFoundErrorStringConstructor());
2891 }
2892 public void invokeObjectGetClass() {
2893         // invokevirtual: java.lang.Object.getClass()Ljava.lang.Class;
2894         if (DEBUG) System.out.println(position + "\t\tinvokevirtual: java.lang.Object.getClass()Ljava.lang.Class;"); //$NON-NLS-1$
2895         countLabels = 0;
2896         if (classFileOffset + 2 >= bCodeStream.length) {
2897                 resizeByteArray();
2898         }
2899         position++;
2900         bCodeStream[classFileOffset++] = OPC_invokevirtual;
2901         writeUnsignedShort(constantPool.literalIndexForJavaLangObjectGetClass());
2902 }
2903
2904 final public void invokespecial(MethodBinding methodBinding) {
2905         if (DEBUG) System.out.println(position + "\t\tinvokespecial:"+methodBinding); //$NON-NLS-1$
2906         // initialized to 1 to take into account this  immediately
2907         countLabels = 0;
2908         int argCount = 1;
2909         int id;
2910         if (classFileOffset + 2 >= bCodeStream.length) {
2911                 resizeByteArray();
2912         }
2913         position++;
2914         bCodeStream[classFileOffset++] = OPC_invokespecial;
2915         writeUnsignedShort(constantPool.literalIndex(methodBinding));
2916         if (methodBinding.isConstructor() && methodBinding.declaringClass.isNestedType()) {
2917                 // enclosing instances
2918                 TypeBinding[] syntheticArgumentTypes = methodBinding.declaringClass.syntheticEnclosingInstanceTypes();
2919                 if (syntheticArgumentTypes != null) {
2920                         for (int i = 0, max = syntheticArgumentTypes.length; i < max; i++) {
2921                                 if (((id = syntheticArgumentTypes[i].id) == T_double) || (id == T_long)) {
2922                                         argCount += 2;
2923                                 } else {
2924                                         argCount++;
2925                                 }
2926                         }
2927                 }
2928                 // outer local variables
2929                 SyntheticArgumentBinding[] syntheticArguments = methodBinding.declaringClass.syntheticOuterLocalVariables();
2930                 if (syntheticArguments != null) {
2931                         for (int i = 0, max = syntheticArguments.length; i < max; i++) {
2932                                 if (((id = syntheticArguments[i].type.id) == T_double) || (id == T_long)) {
2933                                         argCount += 2;
2934                                 } else {
2935                                         argCount++;
2936                                 }
2937                         }
2938                 }
2939         }
2940         for (int i = methodBinding.parameters.length - 1; i >= 0; i--)
2941                 if (((id = methodBinding.parameters[i].id) == T_double) || (id == T_long))
2942                         argCount += 2;
2943                 else
2944                         argCount++;
2945         if (((id = methodBinding.returnType.id) == T_double) || (id == T_long))
2946                 stackDepth += (2 - argCount);
2947         else
2948                 if (id == T_void)
2949                         stackDepth -= argCount;
2950                 else
2951                         stackDepth += (1 - argCount);
2952         if (stackDepth > stackMax)
2953                 stackMax = stackDepth;
2954 }
2955 final public void invokestatic(MethodBinding methodBinding) {
2956         if (DEBUG) System.out.println(position + "\t\tinvokestatic:"+methodBinding); //$NON-NLS-1$
2957         // initialized to 0 to take into account that there is no this for
2958         // a static method
2959         countLabels = 0;
2960         int argCount = 0;
2961         int id;
2962         if (classFileOffset + 2 >= bCodeStream.length) {
2963                 resizeByteArray();
2964         }
2965         position++;
2966         bCodeStream[classFileOffset++] = OPC_invokestatic;
2967         writeUnsignedShort(constantPool.literalIndex(methodBinding));
2968         for (int i = methodBinding.parameters.length - 1; i >= 0; i--)
2969                 if (((id = methodBinding.parameters[i].id) == T_double) || (id == T_long))
2970                         argCount += 2;
2971                 else
2972                         argCount += 1;
2973         if (((id = methodBinding.returnType.id) == T_double) || (id == T_long))
2974                 stackDepth += (2 - argCount);
2975         else
2976                 if (id == T_void)
2977                         stackDepth -= argCount;
2978                 else
2979                         stackDepth += (1 - argCount);
2980         if (stackDepth > stackMax)
2981                 stackMax = stackDepth;
2982 }
2983 /**
2984  * The equivalent code performs a string conversion of the TOS
2985  * @param typeID <CODE>int</CODE>
2986  */
2987 public void invokeStringBufferAppendForType(int typeID) {
2988         if (DEBUG) System.out.println(position + "\t\tinvokevirtual: java.lang.StringBuffer.append(...)"); //$NON-NLS-1$
2989         countLabels = 0;
2990         int usedTypeID;
2991         if (typeID == T_null)
2992                 usedTypeID = T_String;
2993         else
2994                 usedTypeID = typeID;
2995         // invokevirtual
2996         if (classFileOffset + 2 >= bCodeStream.length) {
2997                 resizeByteArray();
2998         }
2999         position++;
3000         bCodeStream[classFileOffset++] = OPC_invokevirtual;
3001         writeUnsignedShort(constantPool.literalIndexForJavaLangStringBufferAppend(typeID));
3002         if ((usedTypeID == T_long) || (usedTypeID == T_double))
3003                 stackDepth -= 2;
3004         else
3005                 stackDepth--;
3006 }
3007
3008 public void invokeJavaLangAssertionErrorConstructor(int typeBindingID) {
3009         // invokespecial: java.lang.AssertionError.<init>(typeBindingID)V
3010         if (DEBUG) System.out.println(position + "\t\tinvokespecial: java.lang.AssertionError.<init>(typeBindingID)V"); //$NON-NLS-1$
3011         countLabels = 0;
3012         if (classFileOffset + 2 >= bCodeStream.length) {
3013                 resizeByteArray();
3014         }
3015         position++;
3016         bCodeStream[classFileOffset++] = OPC_invokespecial;
3017         writeUnsignedShort(constantPool.literalIndexForJavaLangAssertionErrorConstructor(typeBindingID));
3018         stackDepth -= 2;
3019 }
3020
3021 public void invokeJavaLangAssertionErrorDefaultConstructor() {
3022         // invokespecial: java.lang.AssertionError.<init>()V
3023         if (DEBUG) System.out.println(position + "\t\tinvokespecial: java.lang.AssertionError.<init>()V"); //$NON-NLS-1$
3024         countLabels = 0;
3025         if (classFileOffset + 2 >= bCodeStream.length) {
3026                 resizeByteArray();
3027         }
3028         position++;
3029         bCodeStream[classFileOffset++] = OPC_invokespecial;
3030         writeUnsignedShort(constantPool.literalIndexForJavaLangAssertionErrorDefaultConstructor());
3031         stackDepth --;
3032 }
3033
3034 public void invokeStringBufferDefaultConstructor() {
3035         // invokespecial: java.lang.StringBuffer.<init>()V
3036         if (DEBUG) System.out.println(position + "\t\tinvokespecial: java.lang.StringBuffer.<init>()V"); //$NON-NLS-1$
3037         countLabels = 0;
3038         if (classFileOffset + 2 >= bCodeStream.length) {
3039                 resizeByteArray();
3040         }
3041         position++;
3042         bCodeStream[classFileOffset++] = OPC_invokespecial;
3043         writeUnsignedShort(constantPool.literalIndexForJavaLangStringBufferDefaultConstructor());
3044         stackDepth--;
3045 }
3046 public void invokeStringBufferStringConstructor() {
3047         // invokespecial: java.lang.StringBuffer.<init>(Ljava.lang.String;)V
3048         if (DEBUG) System.out.println(position + "\t\tjava.lang.StringBuffer.<init>(Ljava.lang.String;)V"); //$NON-NLS-1$
3049         countLabels = 0;
3050         if (classFileOffset + 2 >= bCodeStream.length) {
3051                 resizeByteArray();
3052         }
3053         position++;
3054         bCodeStream[classFileOffset++] = OPC_invokespecial;
3055         writeUnsignedShort(constantPool.literalIndexForJavaLangStringBufferConstructor());
3056         stackDepth -= 2;
3057 }
3058
3059 public void invokeStringBufferToString() {
3060         // invokevirtual: StringBuffer.toString()Ljava.lang.String;
3061         if (DEBUG) System.out.println(position + "\t\tinvokevirtual: StringBuffer.toString()Ljava.lang.String;"); //$NON-NLS-1$
3062         countLabels = 0;
3063         if (classFileOffset + 2 >= bCodeStream.length) {
3064                 resizeByteArray();
3065         }
3066         position++;
3067         bCodeStream[classFileOffset++] = OPC_invokevirtual;
3068         writeUnsignedShort(constantPool.literalIndexForJavaLangStringBufferToString());
3069 }
3070 public void invokeStringIntern() {
3071         // invokevirtual: java.lang.String.intern()
3072         if (DEBUG) System.out.println(position + "\t\tinvokevirtual: java.lang.String.intern()"); //$NON-NLS-1$
3073         countLabels = 0;
3074         if (classFileOffset + 2 >= bCodeStream.length) {
3075                 resizeByteArray();
3076         }
3077         position++;
3078         bCodeStream[classFileOffset++] = OPC_invokevirtual;
3079         writeUnsignedShort(constantPool.literalIndexForJavaLangStringIntern());
3080 }
3081 public void invokeStringValueOf(int typeID) {
3082         // invokestatic: java.lang.String.valueOf(argumentType)
3083         if (DEBUG) System.out.println(position + "\t\tinvokestatic: java.lang.String.valueOf(...)"); //$NON-NLS-1$
3084         countLabels = 0;
3085         if (classFileOffset + 2 >= bCodeStream.length) {
3086                 resizeByteArray();
3087         }
3088         position++;
3089         bCodeStream[classFileOffset++] = OPC_invokestatic;
3090         writeUnsignedShort(constantPool.literalIndexForJavaLangStringValueOf(typeID));
3091 }
3092 public void invokeThrowableGetMessage() {
3093         // invokevirtual: java.lang.Throwable.getMessage()Ljava.lang.String;
3094         if (DEBUG) System.out.println(position + "\t\tinvokevirtual: java.lang.Throwable.getMessage()Ljava.lang.String;"); //$NON-NLS-1$
3095         countLabels = 0;
3096         if (classFileOffset + 2 >= bCodeStream.length) {
3097                 resizeByteArray();
3098         }
3099         position++;
3100         bCodeStream[classFileOffset++] = OPC_invokevirtual;
3101         writeUnsignedShort(constantPool.literalIndexForJavaLangThrowableGetMessage());
3102 }
3103 final public void invokevirtual(MethodBinding methodBinding) {
3104         if (DEBUG) System.out.println(position + "\t\tinvokevirtual:"+methodBinding); //$NON-NLS-1$
3105         // initialized to 1 to take into account this  immediately
3106         countLabels = 0;
3107         int argCount = 1;
3108         int id;
3109         if (classFileOffset + 2 >= bCodeStream.length) {
3110                 resizeByteArray();
3111         }
3112         position++;
3113         bCodeStream[classFileOffset++] = OPC_invokevirtual;
3114         writeUnsignedShort(constantPool.literalIndex(methodBinding));
3115         for (int i = methodBinding.parameters.length - 1; i >= 0; i--)
3116                 if (((id = methodBinding.parameters[i].id) == T_double) || (id == T_long))
3117                         argCount += 2;
3118                 else
3119                         argCount++;
3120         if (((id = methodBinding.returnType.id) == T_double) || (id == T_long))
3121                 stackDepth += (2 - argCount);
3122         else
3123                 if (id == T_void)
3124                         stackDepth -= argCount;
3125                 else
3126                         stackDepth += (1 - argCount);
3127         if (stackDepth > stackMax)
3128                 stackMax = stackDepth;
3129 }
3130 final public void ior() {
3131         if (DEBUG) System.out.println(position + "\t\tior"); //$NON-NLS-1$
3132         countLabels = 0;
3133         stackDepth--;
3134         if (classFileOffset >= bCodeStream.length) {
3135                 resizeByteArray();
3136         }
3137         position++;
3138         bCodeStream[classFileOffset++] = OPC_ior;
3139 }
3140 final public void irem() {
3141         if (DEBUG) System.out.println(position + "\t\tirem"); //$NON-NLS-1$
3142         countLabels = 0;
3143         stackDepth--;
3144         if (classFileOffset >= bCodeStream.length) {
3145                 resizeByteArray();
3146         }
3147         position++;
3148         bCodeStream[classFileOffset++] = OPC_irem;
3149 }
3150 final public void ireturn() {
3151         if (DEBUG) System.out.println(position + "\t\tireturn"); //$NON-NLS-1$
3152         countLabels = 0;
3153         stackDepth--;
3154         // the stackDepth should be equal to 0 
3155         if (classFileOffset >= bCodeStream.length) {
3156                 resizeByteArray();
3157         }
3158         position++;
3159         bCodeStream[classFileOffset++] = OPC_ireturn;
3160 }
3161 public boolean isDefinitelyAssigned(Scope scope, int initStateIndex, LocalVariableBinding local) {
3162         // Dependant of UnconditionalFlowInfo.isDefinitelyAssigned(..)
3163         if (initStateIndex == -1)
3164                 return false;
3165         if (local.isArgument) {
3166                 return true;
3167         }
3168         int localPosition = local.id + maxFieldCount;
3169         MethodScope methodScope = scope.methodScope();
3170         // id is zero-based
3171         if (localPosition < UnconditionalFlowInfo.BitCacheSize) {
3172                 return (methodScope.definiteInits[initStateIndex] & (1L << localPosition)) != 0; // use bits
3173         }
3174         // use extra vector
3175         long[] extraInits = methodScope.extraDefiniteInits[initStateIndex];
3176         if (extraInits == null)
3177                 return false; // if vector not yet allocated, then not initialized
3178         int vectorIndex;
3179         if ((vectorIndex = (localPosition / UnconditionalFlowInfo.BitCacheSize) - 1) >= extraInits.length)
3180                 return false; // if not enough room in vector, then not initialized 
3181         return ((extraInits[vectorIndex]) & (1L << (localPosition % UnconditionalFlowInfo.BitCacheSize))) != 0;
3182 }
3183 final public void ishl() {
3184         if (DEBUG) System.out.println(position + "\t\tishl"); //$NON-NLS-1$
3185         countLabels = 0;
3186         stackDepth--;
3187         if (classFileOffset >= bCodeStream.length) {
3188                 resizeByteArray();
3189         }
3190         position++;
3191         bCodeStream[classFileOffset++] = OPC_ishl;
3192 }
3193 final public void ishr() {
3194         if (DEBUG) System.out.println(position + "\t\tishr"); //$NON-NLS-1$
3195         countLabels = 0;
3196         stackDepth--;
3197         if (classFileOffset >= bCodeStream.length) {
3198                 resizeByteArray();
3199         }
3200         position++;
3201         bCodeStream[classFileOffset++] = OPC_ishr;
3202 }
3203 final public void istore(int iArg) {
3204         if (DEBUG) System.out.println(position + "\t\tistore:"+iArg); //$NON-NLS-1$
3205         countLabels = 0;
3206         stackDepth--;
3207         if (maxLocals <= iArg) {
3208                 maxLocals = iArg + 1;
3209         }
3210         if (iArg > 255) { // Widen
3211                 if (classFileOffset + 3 >= bCodeStream.length) {
3212                         resizeByteArray();
3213                 }
3214                 position += 2;
3215                 bCodeStream[classFileOffset++] = OPC_wide;
3216                 bCodeStream[classFileOffset++] = OPC_istore;
3217                 writeUnsignedShort(iArg);
3218         } else {
3219                 if (classFileOffset + 1 >= bCodeStream.length) {
3220                         resizeByteArray();
3221                 }
3222                 position += 2;
3223                 bCodeStream[classFileOffset++] = OPC_istore;
3224                 bCodeStream[classFileOffset++] = (byte) iArg;
3225         }
3226 }
3227 final public void istore_0() {
3228         if (DEBUG) System.out.println(position + "\t\tistore_0"); //$NON-NLS-1$
3229         countLabels = 0;
3230         stackDepth--;
3231         if (maxLocals == 0) {
3232                 maxLocals = 1;
3233         }
3234         if (classFileOffset >= bCodeStream.length) {
3235                 resizeByteArray();
3236         }
3237         position++;
3238         bCodeStream[classFileOffset++] = OPC_istore_0;
3239 }
3240 final public void istore_1() {
3241         if (DEBUG) System.out.println(position + "\t\tistore_1"); //$NON-NLS-1$
3242         countLabels = 0;
3243         stackDepth--;
3244         if (maxLocals <= 1) {
3245                 maxLocals = 2;
3246         }
3247         if (classFileOffset >= bCodeStream.length) {
3248                 resizeByteArray();
3249         }
3250         position++;
3251         bCodeStream[classFileOffset++] = OPC_istore_1;
3252 }
3253 final public void istore_2() {
3254         if (DEBUG) System.out.println(position + "\t\tistore_2"); //$NON-NLS-1$
3255         countLabels = 0;
3256         stackDepth--;
3257         if (maxLocals <= 2) {
3258                 maxLocals = 3;
3259         }
3260         if (classFileOffset >= bCodeStream.length) {
3261                 resizeByteArray();
3262         }
3263         position++;
3264         bCodeStream[classFileOffset++] = OPC_istore_2;
3265 }
3266 final public void istore_3() {
3267         if (DEBUG) System.out.println(position + "\t\tistore_3"); //$NON-NLS-1$
3268         countLabels = 0;
3269         stackDepth--;
3270         if (maxLocals <= 3) {
3271                 maxLocals = 4;
3272         }
3273         if (classFileOffset >= bCodeStream.length) {
3274                 resizeByteArray();
3275         }
3276         position++;
3277         bCodeStream[classFileOffset++] = OPC_istore_3;
3278 }
3279 final public void isub() {
3280         if (DEBUG) System.out.println(position + "\t\tisub"); //$NON-NLS-1$
3281         countLabels = 0;
3282         stackDepth--;
3283         if (classFileOffset >= bCodeStream.length) {
3284                 resizeByteArray();
3285         }
3286         position++;
3287         bCodeStream[classFileOffset++] = OPC_isub;
3288 }
3289 final public void iushr() {
3290         if (DEBUG) System.out.println(position + "\t\tiushr"); //$NON-NLS-1$
3291         countLabels = 0;
3292         stackDepth--;
3293         if (classFileOffset >= bCodeStream.length) {
3294                 resizeByteArray();
3295         }
3296         position++;
3297         bCodeStream[classFileOffset++] = OPC_iushr;
3298 }
3299 final public void ixor() {
3300         if (DEBUG) System.out.println(position + "\t\tixor"); //$NON-NLS-1$
3301         countLabels = 0;
3302         stackDepth--;
3303         if (classFileOffset >= bCodeStream.length) {
3304                 resizeByteArray();
3305         }
3306         position++;
3307         bCodeStream[classFileOffset++] = OPC_ixor;
3308 }
3309 final public void jsr(Label lbl) {
3310         if (this.wideMode) {
3311                 this.jsr_w(lbl);
3312                 return;
3313         }
3314         if (DEBUG) System.out.println(position + "\t\tjsr"+lbl); //$NON-NLS-1$
3315         countLabels = 0;
3316         if (classFileOffset >= bCodeStream.length) {
3317                 resizeByteArray();
3318         }
3319         position++;
3320         bCodeStream[classFileOffset++] = OPC_jsr;
3321         lbl.branch();
3322 }
3323 final public void jsr_w(Label lbl) {
3324         if (DEBUG) System.out.println(position + "\t\tjsr_w"+lbl); //$NON-NLS-1$
3325         countLabels = 0;
3326         if (classFileOffset >= bCodeStream.length) {
3327                 resizeByteArray();
3328         }
3329         position++;
3330         bCodeStream[classFileOffset++] = OPC_jsr_w;
3331         lbl.branchWide();
3332 }
3333 final public void l2d() {
3334         if (DEBUG) System.out.println(position + "\t\tl2d"); //$NON-NLS-1$
3335         countLabels = 0;
3336         if (classFileOffset >= bCodeStream.length) {
3337                 resizeByteArray();
3338         }
3339         position++;
3340         bCodeStream[classFileOffset++] = OPC_l2d;
3341 }
3342 final public void l2f() {
3343         if (DEBUG) System.out.println(position + "\t\tl2f"); //$NON-NLS-1$
3344         countLabels = 0;
3345         stackDepth--;
3346         if (classFileOffset >= bCodeStream.length) {
3347                 resizeByteArray();
3348         }
3349         position++;
3350         bCodeStream[classFileOffset++] = OPC_l2f;
3351 }
3352 final public void l2i() {
3353         if (DEBUG) System.out.println(position + "\t\tl2i"); //$NON-NLS-1$
3354         countLabels = 0;
3355         stackDepth--;
3356         if (classFileOffset >= bCodeStream.length) {
3357                 resizeByteArray();
3358         }
3359         position++;
3360         bCodeStream[classFileOffset++] = OPC_l2i;
3361 }
3362 final public void ladd() {
3363         if (DEBUG) System.out.println(position + "\t\tladd"); //$NON-NLS-1$
3364         countLabels = 0;
3365         stackDepth -= 2;
3366         if (classFileOffset >= bCodeStream.length) {
3367                 resizeByteArray();
3368         }
3369         position++;
3370         bCodeStream[classFileOffset++] = OPC_ladd;
3371 }
3372 final public void laload() {
3373         if (DEBUG) System.out.println(position + "\t\tlaload"); //$NON-NLS-1$
3374         countLabels = 0;
3375         if (classFileOffset >= bCodeStream.length) {
3376                 resizeByteArray();
3377         }
3378         position++;
3379         bCodeStream[classFileOffset++] = OPC_laload;
3380 }
3381 final public void land() {
3382         if (DEBUG) System.out.println(position + "\t\tland"); //$NON-NLS-1$
3383         countLabels = 0;
3384         stackDepth -= 2;
3385         if (classFileOffset >= bCodeStream.length) {
3386                 resizeByteArray();
3387         }
3388         position++;
3389         bCodeStream[classFileOffset++] = OPC_land;
3390 }
3391 final public void lastore() {
3392         if (DEBUG) System.out.println(position + "\t\tlastore"); //$NON-NLS-1$
3393         countLabels = 0;
3394         stackDepth -= 4;
3395         if (classFileOffset >= bCodeStream.length) {
3396                 resizeByteArray();
3397         }
3398         position++;
3399         bCodeStream[classFileOffset++] = OPC_lastore;
3400 }
3401 final public void lcmp() {
3402         if (DEBUG) System.out.println(position + "\t\tlcmp"); //$NON-NLS-1$
3403         countLabels = 0;
3404         stackDepth -= 3;
3405         if (classFileOffset >= bCodeStream.length) {
3406                 resizeByteArray();
3407         }
3408         position++;
3409         bCodeStream[classFileOffset++] = OPC_lcmp;
3410 }
3411 final public void lconst_0() {
3412         if (DEBUG) System.out.println(position + "\t\tlconst_0"); //$NON-NLS-1$
3413         countLabels = 0;
3414         stackDepth += 2;
3415         if (stackDepth > stackMax)
3416                 stackMax = stackDepth;
3417         if (classFileOffset >= bCodeStream.length) {
3418                 resizeByteArray();
3419         }
3420         position++;
3421         bCodeStream[classFileOffset++] = OPC_lconst_0;
3422 }
3423 final public void lconst_1() {
3424         if (DEBUG) System.out.println(position + "\t\tlconst_1"); //$NON-NLS-1$
3425         countLabels = 0;
3426         stackDepth += 2;
3427         if (stackDepth > stackMax)
3428                 stackMax = stackDepth;
3429         if (classFileOffset >= bCodeStream.length) {
3430                 resizeByteArray();
3431         }
3432         position++;
3433         bCodeStream[classFileOffset++] = OPC_lconst_1;
3434 }
3435 final public void ldc(float constant) {
3436         if (DEBUG) System.out.println(position + "\t\tldc:"+constant); //$NON-NLS-1$
3437         countLabels = 0;
3438         int index = constantPool.literalIndex(constant);
3439         stackDepth++;
3440         if (stackDepth > stackMax)
3441                 stackMax = stackDepth;
3442         if (index > 255) {
3443                 // Generate a ldc_w
3444                 if (classFileOffset + 2 >= bCodeStream.length) {
3445                         resizeByteArray();
3446                 }
3447                 position++;
3448                 bCodeStream[classFileOffset++] = OPC_ldc_w;
3449                 writeUnsignedShort(index);
3450         } else {
3451                 // Generate a ldc
3452                 if (classFileOffset + 1 >= bCodeStream.length) {
3453                         resizeByteArray();
3454                 }
3455                 position += 2;
3456                 bCodeStream[classFileOffset++] = OPC_ldc;
3457                 bCodeStream[classFileOffset++] = (byte) index;
3458         }
3459 }
3460 final public void ldc(int constant) {
3461         if (DEBUG) System.out.println(position + "\t\tldc:"+constant); //$NON-NLS-1$
3462         countLabels = 0;
3463         int index = constantPool.literalIndex(constant);
3464         stackDepth++;
3465         if (stackDepth > stackMax)
3466                 stackMax = stackDepth;
3467         if (index > 255) {
3468                 // Generate a ldc_w
3469                 if (classFileOffset + 2 >= bCodeStream.length) {
3470                         resizeByteArray();
3471                 }
3472                 position++;
3473                 bCodeStream[classFileOffset++] = OPC_ldc_w;
3474                 writeUnsignedShort(index);
3475         } else {
3476                 // Generate a ldc
3477                 if (classFileOffset + 1 >= bCodeStream.length) {
3478                         resizeByteArray();
3479                 }
3480                 position += 2;
3481                 bCodeStream[classFileOffset++] = OPC_ldc;
3482                 bCodeStream[classFileOffset++] = (byte) index;
3483         }
3484 }
3485 final public void ldc(String constant) {
3486         if (DEBUG) System.out.println(position + "\t\tldc:"+constant); //$NON-NLS-1$
3487         countLabels = 0;
3488         int currentConstantPoolIndex = constantPool.currentIndex;
3489         int currentConstantPoolOffset = constantPool.currentOffset;
3490         int currentCodeStreamPosition = position;
3491         int index = constantPool.literalIndexForLdc(constant.toCharArray());
3492         if (index > 0) {
3493                 // the string already exists inside the constant pool
3494                 // we reuse the same index
3495                 stackDepth++;
3496                 if (stackDepth > stackMax)
3497                         stackMax = stackDepth;
3498                 if (index > 255) {
3499                         // Generate a ldc_w
3500                         if (classFileOffset + 2 >= bCodeStream.length) {
3501                                 resizeByteArray();
3502                         }
3503                         position++;
3504                         bCodeStream[classFileOffset++] = OPC_ldc_w;
3505                         writeUnsignedShort(index);
3506                 } else {
3507                         // Generate a ldc
3508                         if (classFileOffset + 1 >= bCodeStream.length) {
3509                                 resizeByteArray();
3510                         }
3511                         position += 2;
3512                         bCodeStream[classFileOffset++] = OPC_ldc;
3513                         bCodeStream[classFileOffset++] = (byte) index;
3514                 }
3515         } else {
3516                 // the string is too big to be utf8-encoded in one pass.
3517                 // we have to split it into different pieces.
3518                 // first we clean all side-effects due to the code above
3519                 // this case is very rare, so we can afford to lose time to handle it
3520                 char[] constantChars = constant.toCharArray();
3521                 position = currentCodeStreamPosition;
3522                 constantPool.currentIndex = currentConstantPoolIndex;
3523                 constantPool.currentOffset = currentConstantPoolOffset;
3524                 constantPool.stringCache.remove(constantChars);
3525                 constantPool.UTF8Cache.remove(constantChars);
3526                 int i = 0;
3527                 int length = 0;
3528                 int constantLength = constant.length();
3529                 byte[] utf8encoding = new byte[Math.min(constantLength + 100, 65535)];
3530                 int utf8encodingLength = 0;
3531                 while ((length < 65532) && (i < constantLength)) {
3532                         char current = constantChars[i];
3533                         // we resize the byte array immediately if necessary
3534                         if (length + 3 > (utf8encodingLength = utf8encoding.length)) {
3535                                 System.arraycopy(utf8encoding, 0, utf8encoding = new byte[Math.min(utf8encodingLength + 100, 65535)], 0, length);
3536                         }
3537                         if ((current >= 0x0001) && (current <= 0x007F)) {
3538                                 // we only need one byte: ASCII table
3539                                 utf8encoding[length++] = (byte) current;
3540                         } else {
3541                                 if (current > 0x07FF) {
3542                                         // we need 3 bytes
3543                                         utf8encoding[length++] = (byte) (0xE0 | ((current >> 12) & 0x0F)); // 0xE0 = 1110 0000
3544                                         utf8encoding[length++] = (byte) (0x80 | ((current >> 6) & 0x3F)); // 0x80 = 1000 0000
3545                                         utf8encoding[length++] = (byte) (0x80 | (current & 0x3F)); // 0x80 = 1000 0000
3546                                 } else {
3547                                         // we can be 0 or between 0x0080 and 0x07FF
3548                                         // In that case we only need 2 bytes
3549                                         utf8encoding[length++] = (byte) (0xC0 | ((current >> 6) & 0x1F)); // 0xC0 = 1100 0000
3550                                         utf8encoding[length++] = (byte) (0x80 | (current & 0x3F)); // 0x80 = 1000 0000
3551                                 }
3552                         }
3553                         i++;
3554                 }
3555                 // check if all the string is encoded (PR 1PR2DWJ)
3556                 // the string is too big to be encoded in one pass
3557                 newStringBuffer();
3558                 dup();
3559                 // write the first part
3560                 char[] subChars = new char[i];
3561                 System.arraycopy(constantChars, 0, subChars, 0, i);
3562                 System.arraycopy(utf8encoding, 0, utf8encoding = new byte[length], 0, length);
3563                 index = constantPool.literalIndex(subChars, utf8encoding);
3564                 stackDepth++;
3565                 if (stackDepth > stackMax)
3566                         stackMax = stackDepth;
3567                 if (index > 255) {
3568                         // Generate a ldc_w
3569                         if (classFileOffset + 2 >= bCodeStream.length) {
3570                                 resizeByteArray();
3571                         }
3572                         position++;
3573                         bCodeStream[classFileOffset++] = OPC_ldc_w;
3574                         writeUnsignedShort(index);
3575                 } else {
3576                         // Generate a ldc
3577                         if (classFileOffset + 1 >= bCodeStream.length) {
3578                                 resizeByteArray();
3579                         }
3580                         position += 2;
3581                         bCodeStream[classFileOffset++] = OPC_ldc;
3582                         bCodeStream[classFileOffset++] = (byte) index;
3583                 }
3584                 // write the remaining part
3585                 invokeStringBufferStringConstructor();
3586                 while (i < constantLength) {
3587                         length = 0;
3588                         utf8encoding = new byte[Math.min(constantLength - i + 100, 65535)];
3589                         int startIndex = i;
3590                         while ((length < 65532) && (i < constantLength)) {
3591                                 char current = constantChars[i];
3592                                 // we resize the byte array immediately if necessary
3593                                 if (constantLength + 2 > (utf8encodingLength = utf8encoding.length)) {
3594                                         System.arraycopy(utf8encoding, 0, utf8encoding = new byte[Math.min(utf8encodingLength + 100, 65535)], 0, length);
3595                                 }
3596                                 if ((current >= 0x0001) && (current <= 0x007F)) {
3597                                         // we only need one byte: ASCII table
3598                                         utf8encoding[length++] = (byte) current;
3599                                 } else {
3600                                         if (current > 0x07FF) {
3601                                                 // we need 3 bytes
3602                                                 utf8encoding[length++] = (byte) (0xE0 | ((current >> 12) & 0x0F)); // 0xE0 = 1110 0000
3603                                                 utf8encoding[length++] = (byte) (0x80 | ((current >> 6) & 0x3F)); // 0x80 = 1000 0000
3604                                                 utf8encoding[length++] = (byte) (0x80 | (current & 0x3F)); // 0x80 = 1000 0000
3605                                         } else {
3606                                                 // we can be 0 or between 0x0080 and 0x07FF
3607                                                 // In that case we only need 2 bytes
3608                                                 utf8encoding[length++] = (byte) (0xC0 | ((current >> 6) & 0x1F)); // 0xC0 = 1100 0000
3609                                                 utf8encoding[length++] = (byte) (0x80 | (current & 0x3F)); // 0x80 = 1000 0000
3610                                         }
3611                                 }
3612                                 i++;
3613                         }
3614                         // the next part is done
3615                         subChars = new char[i - startIndex];
3616                         System.arraycopy(constantChars, startIndex, subChars, 0, i - startIndex);
3617                         System.arraycopy(utf8encoding, 0, utf8encoding = new byte[length], 0, length);
3618                         index = constantPool.literalIndex(subChars, utf8encoding);
3619                         stackDepth++;
3620                         if (stackDepth > stackMax)
3621                                 stackMax = stackDepth;
3622                         if (index > 255) {
3623                                 // Generate a ldc_w
3624                                 if (classFileOffset + 2 >= bCodeStream.length) {
3625                                         resizeByteArray();
3626                                 }
3627                                 position++;
3628                                 bCodeStream[classFileOffset++] = OPC_ldc_w;
3629                                 writeUnsignedShort(index);
3630                         } else {
3631                                 // Generate a ldc
3632                                 if (classFileOffset + 1 >= bCodeStream.length) {
3633                                         resizeByteArray();
3634                                 }
3635                                 position += 2;
3636                                 bCodeStream[classFileOffset++] = OPC_ldc;
3637                                 bCodeStream[classFileOffset++] = (byte) index;
3638                         }
3639                         // now on the stack it should be a StringBuffer and a string.
3640                         invokeStringBufferAppendForType(T_String);
3641                 }
3642                 invokeStringBufferToString();
3643                 invokeStringIntern();
3644         }
3645 }
3646 final public void ldc2_w(double constant) {
3647         if (DEBUG) System.out.println(position + "\t\tldc2_w:"+constant); //$NON-NLS-1$
3648         countLabels = 0;
3649         int index = constantPool.literalIndex(constant);
3650         stackDepth += 2;
3651         if (stackDepth > stackMax)
3652                 stackMax = stackDepth;
3653         // Generate a ldc2_w
3654         if (classFileOffset + 2 >= bCodeStream.length) {
3655                 resizeByteArray();
3656         }
3657         position++;
3658         bCodeStream[classFileOffset++] = OPC_ldc2_w;
3659         writeUnsignedShort(index);
3660 }
3661 final public void ldc2_w(long constant) {
3662         if (DEBUG) System.out.println(position + "\t\tldc2_w:"+constant); //$NON-NLS-1$
3663         countLabels = 0;
3664         int index = constantPool.literalIndex(constant);
3665         stackDepth += 2;
3666         if (stackDepth > stackMax)
3667                 stackMax = stackDepth;
3668         // Generate a ldc2_w
3669         if (classFileOffset + 2 >= bCodeStream.length) {
3670                 resizeByteArray();
3671         }
3672         position++;
3673         bCodeStream[classFileOffset++] = OPC_ldc2_w;
3674         writeUnsignedShort(index);
3675 }
3676 final public void ldiv() {
3677         if (DEBUG) System.out.println(position + "\t\tldiv"); //$NON-NLS-1$
3678         countLabels = 0;
3679         stackDepth -= 2;
3680         if (classFileOffset >= bCodeStream.length) {
3681                 resizeByteArray();
3682         }
3683         position++;
3684         bCodeStream[classFileOffset++] = OPC_ldiv;
3685 }
3686 final public void lload(int iArg) {
3687         if (DEBUG) System.out.println(position + "\t\tlload:"+iArg); //$NON-NLS-1$
3688         countLabels = 0;
3689         stackDepth += 2;
3690         if (maxLocals <= iArg + 1) {
3691                 maxLocals = iArg + 2;
3692         }
3693         if (stackDepth > stackMax)
3694                 stackMax = stackDepth;
3695         if (iArg > 255) { // Widen
3696                 if (classFileOffset + 3 >= bCodeStream.length) {
3697                         resizeByteArray();
3698                 }
3699                 position += 2;
3700                 bCodeStream[classFileOffset++] = OPC_wide;
3701                 bCodeStream[classFileOffset++] = OPC_lload;
3702                 writeUnsignedShort(iArg);
3703         } else {
3704                 if (classFileOffset + 1 >= bCodeStream.length) {
3705                         resizeByteArray();
3706                 }
3707                 position += 2;
3708                 bCodeStream[classFileOffset++] = OPC_lload;
3709                 bCodeStream[classFileOffset++] = (byte) iArg;
3710         }
3711 }
3712 final public void lload_0() {
3713         if (DEBUG) System.out.println(position + "\t\tlload_0"); //$NON-NLS-1$
3714         countLabels = 0;
3715         stackDepth += 2;
3716         if (maxLocals < 2) {
3717                 maxLocals = 2;
3718         }
3719         if (stackDepth > stackMax)
3720                 stackMax = stackDepth;
3721         if (classFileOffset >= bCodeStream.length) {
3722                 resizeByteArray();
3723         }
3724         position++;
3725         bCodeStream[classFileOffset++] = OPC_lload_0;
3726 }
3727 final public void lload_1() {
3728         if (DEBUG) System.out.println(position + "\t\tlload_1"); //$NON-NLS-1$
3729         countLabels = 0;
3730         stackDepth += 2;
3731         if (maxLocals < 3) {
3732                 maxLocals = 3;
3733         }
3734         if (stackDepth > stackMax)
3735                 stackMax = stackDepth;
3736         if (classFileOffset >= bCodeStream.length) {
3737                 resizeByteArray();
3738         }
3739         position++;
3740         bCodeStream[classFileOffset++] = OPC_lload_1;
3741 }
3742 final public void lload_2() {
3743         if (DEBUG) System.out.println(position + "\t\tlload_2"); //$NON-NLS-1$
3744         countLabels = 0;
3745         stackDepth += 2;
3746         if (maxLocals < 4) {
3747                 maxLocals = 4;
3748         }
3749         if (stackDepth > stackMax)
3750                 stackMax = stackDepth;
3751         if (classFileOffset >= bCodeStream.length) {
3752                 resizeByteArray();
3753         }
3754         position++;
3755         bCodeStream[classFileOffset++] = OPC_lload_2;
3756 }
3757 final public void lload_3() {
3758         if (DEBUG) System.out.println(position + "\t\tlload_3"); //$NON-NLS-1$
3759         countLabels = 0;
3760         stackDepth += 2;
3761         if (maxLocals < 5) {
3762                 maxLocals = 5;
3763         }
3764         if (stackDepth > stackMax)
3765                 stackMax = stackDepth;
3766         if (classFileOffset >= bCodeStream.length) {
3767                 resizeByteArray();
3768         }
3769         position++;
3770         bCodeStream[classFileOffset++] = OPC_lload_3;
3771 }
3772 final public void lmul() {
3773         if (DEBUG) System.out.println(position + "\t\tlmul"); //$NON-NLS-1$
3774         countLabels = 0;
3775         stackDepth -= 2;
3776         if (classFileOffset >= bCodeStream.length) {
3777                 resizeByteArray();
3778         }
3779         position++;
3780         bCodeStream[classFileOffset++] = OPC_lmul;
3781 }
3782 final public void lneg() {
3783         if (DEBUG) System.out.println(position + "\t\tlneg"); //$NON-NLS-1$
3784         countLabels = 0;
3785         if (classFileOffset >= bCodeStream.length) {
3786                 resizeByteArray();
3787         }
3788         position++;
3789         bCodeStream[classFileOffset++] = OPC_lneg;
3790 }
3791 public final void load(LocalVariableBinding localBinding) {
3792         countLabels = 0;
3793         TypeBinding typeBinding = localBinding.type;
3794         int resolvedPosition = localBinding.resolvedPosition;
3795         // Using dedicated int bytecode
3796         if (typeBinding == IntBinding) {
3797                 switch (resolvedPosition) {
3798                         case 0 :
3799                                 this.iload_0();
3800                                 break;
3801                         case 1 :
3802                                 this.iload_1();
3803                                 break;
3804                         case 2 :
3805                                 this.iload_2();
3806                                 break;
3807                         case 3 :
3808                                 this.iload_3();
3809                                 break;
3810                         //case -1 :
3811                         // internal failure: trying to load variable not supposed to be generated
3812                         //      break;
3813                         default :
3814                                 this.iload(resolvedPosition);
3815                 }
3816                 return;
3817         }
3818         // Using dedicated float bytecode
3819         if (typeBinding == FloatBinding) {
3820                 switch (resolvedPosition) {
3821                         case 0 :
3822                                 this.fload_0();
3823                                 break;
3824                         case 1 :
3825                                 this.fload_1();
3826                                 break;
3827                         case 2 :
3828                                 this.fload_2();
3829                                 break;
3830                         case 3 :
3831                                 this.fload_3();
3832                                 break;
3833                         default :
3834                                 this.fload(resolvedPosition);
3835                 }
3836                 return;
3837         }
3838         // Using dedicated long bytecode
3839         if (typeBinding == LongBinding) {
3840                 switch (resolvedPosition) {
3841                         case 0 :
3842                                 this.lload_0();
3843                                 break;
3844                         case 1 :
3845                                 this.lload_1();
3846                                 break;
3847                         case 2 :
3848                                 this.lload_2();
3849                                 break;
3850                         case 3 :
3851                                 this.lload_3();
3852                                 break;
3853                         default :
3854                                 this.lload(resolvedPosition);
3855                 }
3856                 return;
3857         }
3858         // Using dedicated double bytecode
3859         if (typeBinding == DoubleBinding) {
3860                 switch (resolvedPosition) {
3861                         case 0 :
3862                                 this.dload_0();
3863                                 break;
3864                         case 1 :
3865                                 this.dload_1();
3866                                 break;
3867                         case 2 :
3868                                 this.dload_2();
3869                                 break;
3870                         case 3 :
3871                                 this.dload_3();
3872                                 break;
3873                         default :
3874                                 this.dload(resolvedPosition);
3875                 }
3876                 return;
3877         }
3878         // boolean, byte, char and short are handled as int
3879         if ((typeBinding == ByteBinding) || (typeBinding == CharBinding) || (typeBinding == BooleanBinding) || (typeBinding == ShortBinding)) {
3880                 switch (resolvedPosition) {
3881                         case 0 :
3882                                 this.iload_0();
3883                                 break;
3884                         case 1 :
3885                                 this.iload_1();
3886                                 break;
3887                         case 2 :
3888                                 this.iload_2();
3889                                 break;
3890                         case 3 :
3891                                 this.iload_3();
3892                                 break;
3893                         default :
3894                                 this.iload(resolvedPosition);
3895                 }
3896                 return;
3897         }
3898
3899         // Reference object
3900         switch (resolvedPosition) {
3901                 case 0 :
3902                         this.aload_0();
3903                         break;
3904                 case 1 :
3905                         this.aload_1();
3906                         break;
3907                 case 2 :
3908                         this.aload_2();
3909                         break;
3910                 case 3 :
3911                         this.aload_3();
3912                         break;
3913                 default :
3914                         this.aload(resolvedPosition);
3915         }
3916 }
3917 public final void load(TypeBinding typeBinding, int resolvedPosition) {
3918         countLabels = 0;
3919         // Using dedicated int bytecode
3920         if (typeBinding == IntBinding) {
3921                 switch (resolvedPosition) {
3922                         case 0 :
3923                                 this.iload_0();
3924                                 break;
3925                         case 1 :
3926                                 this.iload_1();
3927                                 break;
3928                         case 2 :
3929                                 this.iload_2();
3930                                 break;
3931                         case 3 :
3932                                 this.iload_3();
3933                                 break;
3934                         default :
3935                                 this.iload(resolvedPosition);
3936                 }
3937                 return;
3938         }
3939         // Using dedicated float bytecode
3940         if (typeBinding == FloatBinding) {
3941                 switch (resolvedPosition) {
3942                         case 0 :
3943                                 this.fload_0();
3944                                 break;
3945                         case 1 :
3946                                 this.fload_1();
3947                                 break;
3948                         case 2 :
3949                                 this.fload_2();
3950                                 break;
3951                         case 3 :
3952                                 this.fload_3();
3953                                 break;
3954                         default :
3955                                 this.fload(resolvedPosition);
3956                 }
3957                 return;
3958         }
3959         // Using dedicated long bytecode
3960         if (typeBinding == LongBinding) {
3961                 switch (resolvedPosition) {
3962                         case 0 :
3963                                 this.lload_0();
3964                                 break;
3965                         case 1 :
3966                                 this.lload_1();
3967                                 break;
3968                         case 2 :
3969                                 this.lload_2();
3970                                 break;
3971                         case 3 :
3972                                 this.lload_3();
3973                                 break;
3974                         default :
3975                                 this.lload(resolvedPosition);
3976                 }
3977                 return;
3978         }
3979         // Using dedicated double bytecode
3980         if (typeBinding == DoubleBinding) {
3981                 switch (resolvedPosition) {
3982                         case 0 :
3983                                 this.dload_0();
3984                                 break;
3985                         case 1 :
3986                                 this.dload_1();
3987                                 break;
3988                         case 2 :
3989                                 this.dload_2();
3990                                 break;
3991                         case 3 :
3992                                 this.dload_3();
3993                                 break;
3994                         default :
3995                                 this.dload(resolvedPosition);
3996                 }
3997                 return;
3998         }
3999         // boolean, byte, char and short are handled as int
4000         if ((typeBinding == ByteBinding) || (typeBinding == CharBinding) || (typeBinding == BooleanBinding) || (typeBinding == ShortBinding)) {
4001                 switch (resolvedPosition) {
4002                         case 0 :
4003                                 this.iload_0();
4004                                 break;
4005                         case 1 :
4006                                 this.iload_1();
4007                                 break;
4008                         case 2 :
4009                                 this.iload_2();
4010                                 break;
4011                         case 3 :
4012                                 this.iload_3();
4013                                 break;
4014                         default :
4015                                 this.iload(resolvedPosition);
4016                 }
4017                 return;
4018         }
4019
4020         // Reference object
4021         switch (resolvedPosition) {
4022                 case 0 :
4023                         this.aload_0();
4024                         break;
4025                 case 1 :
4026                         this.aload_1();
4027                         break;
4028                 case 2 :
4029                         this.aload_2();
4030                         break;
4031                 case 3 :
4032                         this.aload_3();
4033                         break;
4034                 default :
4035                         this.aload(resolvedPosition);
4036         }
4037 }
4038 public final void loadInt(int resolvedPosition) {
4039         // Using dedicated int bytecode
4040         switch (resolvedPosition) {
4041                 case 0 :
4042                         this.iload_0();
4043                         break;
4044                 case 1 :
4045                         this.iload_1();
4046                         break;
4047                 case 2 :
4048                         this.iload_2();
4049                         break;
4050                 case 3 :
4051                         this.iload_3();
4052                         break;
4053                 default :
4054                         this.iload(resolvedPosition);
4055         }
4056 }
4057 public final void loadObject(int resolvedPosition) {
4058         switch (resolvedPosition) {
4059                 case 0 :
4060                         this.aload_0();
4061                         break;
4062                 case 1 :
4063                         this.aload_1();
4064                         break;
4065                 case 2 :
4066                         this.aload_2();
4067                         break;
4068                 case 3 :
4069                         this.aload_3();
4070                         break;
4071                 default :
4072                         this.aload(resolvedPosition);
4073         }
4074 }
4075 final public void lookupswitch(CaseLabel defaultLabel, int[] keys, int[] sortedIndexes, CaseLabel[] casesLabel) {
4076         if (DEBUG) System.out.println(position + "\t\tlookupswitch"); //$NON-NLS-1$
4077         countLabels = 0;
4078         stackDepth--;
4079         int length = keys.length;
4080         int pos = position;
4081         defaultLabel.placeInstruction();
4082         for (int i = 0; i < length; i++) {
4083                 casesLabel[i].placeInstruction();
4084         }
4085         if (classFileOffset >= bCodeStream.length) {
4086                 resizeByteArray();
4087         }
4088         position++;
4089         bCodeStream[classFileOffset++] = OPC_lookupswitch;
4090         for (int i = (3 - (pos % 4)); i > 0; i--) {
4091                 if (classFileOffset >= bCodeStream.length) {
4092                         resizeByteArray();
4093                 }
4094                 position++;
4095                 bCodeStream[classFileOffset++] = 0;
4096         }
4097         defaultLabel.branch();
4098         writeSignedWord(length);
4099         for (int i = 0; i < length; i++) {
4100                 writeSignedWord(keys[sortedIndexes[i]]);
4101                 casesLabel[sortedIndexes[i]].branch();
4102         }
4103 }
4104 final public void lor() {
4105         if (DEBUG) System.out.println(position + "\t\tlor"); //$NON-NLS-1$
4106         countLabels = 0;
4107         stackDepth -= 2;
4108         if (classFileOffset >= bCodeStream.length) {
4109                 resizeByteArray();
4110         }
4111         position++;
4112         bCodeStream[classFileOffset++] = OPC_lor;
4113 }
4114 final public void lrem() {
4115         if (DEBUG) System.out.println(position + "\t\tlrem"); //$NON-NLS-1$
4116         countLabels = 0;
4117         stackDepth -= 2;
4118         if (classFileOffset >= bCodeStream.length) {
4119                 resizeByteArray();
4120         }
4121         position++;
4122         bCodeStream[classFileOffset++] = OPC_lrem;
4123 }
4124 final public void lreturn() {
4125         if (DEBUG) System.out.println(position + "\t\tlreturn"); //$NON-NLS-1$
4126         countLabels = 0;
4127         stackDepth -= 2;
4128         // the stackDepth should be equal to 0 
4129         if (classFileOffset >= bCodeStream.length) {
4130                 resizeByteArray();
4131         }
4132         position++;
4133         bCodeStream[classFileOffset++] = OPC_lreturn;
4134 }
4135 final public void lshl() {
4136         if (DEBUG) System.out.println(position + "\t\tlshl"); //$NON-NLS-1$
4137         countLabels = 0;
4138         stackDepth--;
4139         if (classFileOffset >= bCodeStream.length) {
4140                 resizeByteArray();
4141         }
4142         position++;
4143         bCodeStream[classFileOffset++] = OPC_lshl;
4144 }
4145 final public void lshr() {
4146         if (DEBUG) System.out.println(position + "\t\tlshr"); //$NON-NLS-1$
4147         countLabels = 0;
4148         stackDepth--;
4149         if (classFileOffset >= bCodeStream.length) {
4150                 resizeByteArray();
4151         }
4152         position++;
4153         bCodeStream[classFileOffset++] = OPC_lshr;
4154 }
4155 final public void lstore(int iArg) {
4156         if (DEBUG) System.out.println(position + "\t\tlstore:"+iArg); //$NON-NLS-1$
4157         countLabels = 0;
4158         stackDepth -= 2;
4159         if (maxLocals <= iArg + 1) {
4160                 maxLocals = iArg + 2;
4161         }
4162         if (iArg > 255) { // Widen
4163                 if (classFileOffset + 3 >= bCodeStream.length) {
4164                         resizeByteArray();
4165                 }
4166                 position += 2;
4167                 bCodeStream[classFileOffset++] = OPC_wide;
4168                 bCodeStream[classFileOffset++] = OPC_lstore;
4169                 writeUnsignedShort(iArg);
4170         } else {
4171                 if (classFileOffset + 1 >= bCodeStream.length) {
4172                         resizeByteArray();
4173                 }
4174                 position += 2;
4175                 bCodeStream[classFileOffset++] = OPC_lstore;
4176                 bCodeStream[classFileOffset++] = (byte) iArg;
4177         }
4178 }
4179 final public void lstore_0() {
4180         if (DEBUG) System.out.println(position + "\t\tlstore_0"); //$NON-NLS-1$
4181         countLabels = 0;
4182         stackDepth -= 2;
4183         if (maxLocals < 2) {
4184                 maxLocals = 2;
4185         }
4186         if (classFileOffset >= bCodeStream.length) {
4187                 resizeByteArray();
4188         }
4189         position++;
4190         bCodeStream[classFileOffset++] = OPC_lstore_0;
4191 }
4192 final public void lstore_1() {
4193         if (DEBUG) System.out.println(position + "\t\tlstore_1"); //$NON-NLS-1$
4194         countLabels = 0;
4195         stackDepth -= 2;
4196         if (maxLocals < 3) {
4197                 maxLocals = 3;
4198         }
4199         if (classFileOffset >= bCodeStream.length) {
4200                 resizeByteArray();
4201         }
4202         position++;
4203         bCodeStream[classFileOffset++] = OPC_lstore_1;
4204 }
4205 final public void lstore_2() {
4206         if (DEBUG) System.out.println(position + "\t\tlstore_2"); //$NON-NLS-1$
4207         countLabels = 0;
4208         stackDepth -= 2;
4209         if (maxLocals < 4) {
4210                 maxLocals = 4;
4211         }
4212         if (classFileOffset >= bCodeStream.length) {
4213                 resizeByteArray();
4214         }
4215         position++;
4216         bCodeStream[classFileOffset++] = OPC_lstore_2;
4217 }
4218 final public void lstore_3() {
4219         if (DEBUG) System.out.println(position + "\t\tlstore_3"); //$NON-NLS-1$
4220         countLabels = 0;
4221         stackDepth -= 2;
4222         if (maxLocals < 5) {
4223                 maxLocals = 5;
4224         }
4225         if (classFileOffset >= bCodeStream.length) {
4226                 resizeByteArray();
4227         }
4228         position++;
4229         bCodeStream[classFileOffset++] = OPC_lstore_3;
4230 }
4231 final public void lsub() {
4232         if (DEBUG) System.out.println(position + "\t\tlsub"); //$NON-NLS-1$
4233         countLabels = 0;
4234         stackDepth -= 2;
4235         if (classFileOffset >= bCodeStream.length) {
4236                 resizeByteArray();
4237         }
4238         position++;
4239         bCodeStream[classFileOffset++] = OPC_lsub;
4240 }
4241 final public void lushr() {
4242         if (DEBUG) System.out.println(position + "\t\tlushr"); //$NON-NLS-1$
4243         countLabels = 0;
4244         stackDepth--;
4245         if (classFileOffset >= bCodeStream.length) {
4246                 resizeByteArray();
4247         }
4248         position++;
4249         bCodeStream[classFileOffset++] = OPC_lushr;
4250 }
4251 final public void lxor() {
4252         if (DEBUG) System.out.println(position + "\t\tlxor"); //$NON-NLS-1$
4253         countLabels = 0;
4254         stackDepth -= 2;
4255         if (classFileOffset >= bCodeStream.length) {
4256                 resizeByteArray();
4257         }
4258         position++;
4259         bCodeStream[classFileOffset++] = OPC_lxor;
4260 }
4261 final public void monitorenter() {
4262         if (DEBUG) System.out.println(position + "\t\tmonitorenter"); //$NON-NLS-1$
4263         countLabels = 0;
4264         stackDepth--;
4265         if (classFileOffset >= bCodeStream.length) {
4266                 resizeByteArray();
4267         }
4268         position++;
4269         bCodeStream[classFileOffset++] = OPC_monitorenter;
4270 }
4271 final public void monitorexit() {
4272         if (DEBUG) System.out.println(position + "\t\tmonitorexit"); //$NON-NLS-1$
4273         countLabels = 0;
4274         stackDepth--;
4275         if (classFileOffset >= bCodeStream.length) {
4276                 resizeByteArray();
4277         }
4278         position++;
4279         bCodeStream[classFileOffset++] = OPC_monitorexit;
4280 }
4281 final public void multianewarray(TypeBinding typeBinding, int dimensions) {
4282         if (DEBUG) System.out.println(position + "\t\tmultinewarray:"+typeBinding+","+dimensions); //$NON-NLS-1$ //$NON-NLS-2$
4283         countLabels = 0;
4284         stackDepth += (1 - dimensions);
4285         if (classFileOffset + 3 >= bCodeStream.length) {
4286                 resizeByteArray();
4287         }
4288         position += 2;
4289         bCodeStream[classFileOffset++] = OPC_multianewarray;
4290         writeUnsignedShort(constantPool.literalIndex(typeBinding));
4291         bCodeStream[classFileOffset++] = (byte) dimensions;
4292 }
4293 /**
4294  * We didn't call it new, because there is a conflit with the new keyword
4295  */
4296 final public void new_(TypeBinding typeBinding) {
4297         if (DEBUG) System.out.println(position + "\t\tnew:"+typeBinding); //$NON-NLS-1$
4298         countLabels = 0;
4299         stackDepth++;
4300         if (stackDepth > stackMax)
4301                 stackMax = stackDepth;
4302         if (classFileOffset + 2 >= bCodeStream.length) {
4303                 resizeByteArray();
4304         }
4305         position++;
4306         bCodeStream[classFileOffset++] = OPC_new;
4307         writeUnsignedShort(constantPool.literalIndex(typeBinding));
4308 }
4309 final public void newarray(int array_Type) {
4310         if (DEBUG) System.out.println(position + "\t\tnewarray:"+array_Type); //$NON-NLS-1$
4311         countLabels = 0;
4312         if (classFileOffset + 1 >= bCodeStream.length) {
4313                 resizeByteArray();
4314         }
4315         position += 2;
4316         bCodeStream[classFileOffset++] = OPC_newarray;
4317         bCodeStream[classFileOffset++] = (byte) array_Type;
4318 }
4319 public void newArray(Scope scope, ArrayBinding arrayBinding) {
4320         TypeBinding component = arrayBinding.elementsType(scope);
4321         switch (component.id) {
4322                 case T_int :
4323                         this.newarray(10);
4324                         break;
4325                 case T_byte :
4326                         this.newarray(8);
4327                         break;
4328                 case T_boolean :
4329                         this.newarray(4);
4330                         break;
4331                 case T_short :
4332                         this.newarray(9);
4333                         break;
4334                 case T_char :
4335                         this.newarray(5);
4336                         break;
4337                 case T_long :
4338                         this.newarray(11);
4339                         break;
4340                 case T_float :
4341                         this.newarray(6);
4342                         break;
4343                 case T_double :
4344                         this.newarray(7);
4345                         break;
4346                 default :
4347                         this.anewarray(component);
4348         }
4349 }
4350 public void newJavaLangError() {
4351         // new: java.lang.Error
4352         if (DEBUG) System.out.println(position + "\t\tnew: java.lang.Error"); //$NON-NLS-1$
4353         countLabels = 0;
4354         stackDepth++;
4355         if (stackDepth > stackMax)
4356                 stackMax = stackDepth;
4357         if (classFileOffset + 2 >= bCodeStream.length) {
4358                 resizeByteArray();
4359         }
4360         position++;
4361         bCodeStream[classFileOffset++] = OPC_new;
4362         writeUnsignedShort(constantPool.literalIndexForJavaLangError());
4363 }
4364
4365 public void newJavaLangAssertionError() {
4366         // new: java.lang.AssertionError
4367         if (DEBUG) System.out.println(position + "\t\tnew: java.lang.AssertionError"); //$NON-NLS-1$
4368         countLabels = 0;
4369         stackDepth++;
4370         if (stackDepth > stackMax)
4371                 stackMax = stackDepth;
4372         if (classFileOffset + 2 >= bCodeStream.length) {
4373                 resizeByteArray();
4374         }
4375         position++;
4376         bCodeStream[classFileOffset++] = OPC_new;
4377         writeUnsignedShort(constantPool.literalIndexForJavaLangAssertionError());
4378 }
4379
4380 public void newNoClassDefFoundError() {
4381         // new: java.lang.NoClassDefFoundError
4382         if (DEBUG) System.out.println(position + "\t\tnew: java.lang.NoClassDefFoundError"); //$NON-NLS-1$
4383         countLabels = 0;
4384         stackDepth++;
4385         if (stackDepth > stackMax)
4386                 stackMax = stackDepth;
4387         if (classFileOffset + 2 >= bCodeStream.length) {
4388                 resizeByteArray();
4389         }
4390         position++;
4391         bCodeStream[classFileOffset++] = OPC_new;
4392         writeUnsignedShort(constantPool.literalIndexForJavaLangNoClassDefFoundError());
4393 }
4394 public void newStringBuffer() {
4395         // new: java.lang.StringBuffer
4396         if (DEBUG) System.out.println(position + "\t\tnew: java.lang.StringBuffer"); //$NON-NLS-1$
4397         countLabels = 0;
4398         stackDepth++;
4399         if (stackDepth > stackMax)
4400                 stackMax = stackDepth;
4401         if (classFileOffset + 2 >= bCodeStream.length) {
4402                 resizeByteArray();
4403         }
4404         position++;
4405         bCodeStream[classFileOffset++] = OPC_new;
4406         writeUnsignedShort(constantPool.literalIndexForJavaLangStringBuffer());
4407 }
4408 public void newWrapperFor(int typeID) {
4409         countLabels = 0;
4410         stackDepth++;
4411         if (stackDepth > stackMax)
4412                 stackMax = stackDepth;
4413         if (classFileOffset + 2 >= bCodeStream.length) {
4414                 resizeByteArray();
4415         }
4416         position++;
4417         bCodeStream[classFileOffset++] = OPC_new;
4418         switch (typeID) {
4419                 case T_int : // new: java.lang.Integer
4420                         if (DEBUG) System.out.println(position + "\t\tnew: java.lang.Integer"); //$NON-NLS-1$
4421                         writeUnsignedShort(constantPool.literalIndexForJavaLangInteger());
4422                         break;
4423                 case T_boolean : // new: java.lang.Boolean
4424                         if (DEBUG) System.out.println(position + "\t\tnew: java.lang.Boolean"); //$NON-NLS-1$
4425                         writeUnsignedShort(constantPool.literalIndexForJavaLangBoolean());
4426                         break;
4427                 case T_byte : // new: java.lang.Byte
4428                         if (DEBUG) System.out.println(position + "\t\tnew: java.lang.Byte"); //$NON-NLS-1$
4429                         writeUnsignedShort(constantPool.literalIndexForJavaLangByte());
4430                         break;
4431                 case T_char : // new: java.lang.Character
4432                         if (DEBUG) System.out.println(position + "\t\tnew: java.lang.Character"); //$NON-NLS-1$
4433                         writeUnsignedShort(constantPool.literalIndexForJavaLangCharacter());
4434                         break;
4435                 case T_float : // new: java.lang.Float
4436                         if (DEBUG) System.out.println(position + "\t\tnew: java.lang.Float"); //$NON-NLS-1$
4437                         writeUnsignedShort(constantPool.literalIndexForJavaLangFloat());
4438                         break;
4439                 case T_double : // new: java.lang.Double
4440                         if (DEBUG) System.out.println(position + "\t\tnew: java.lang.Double"); //$NON-NLS-1$
4441                         writeUnsignedShort(constantPool.literalIndexForJavaLangDouble());
4442                         break;
4443                 case T_short : // new: java.lang.Short
4444                         if (DEBUG) System.out.println(position + "\t\tnew: java.lang.Short"); //$NON-NLS-1$
4445                         writeUnsignedShort(constantPool.literalIndexForJavaLangShort());
4446                         break;
4447                 case T_long : // new: java.lang.Long
4448                         if (DEBUG) System.out.println(position + "\t\tnew: java.lang.Long"); //$NON-NLS-1$
4449                         writeUnsignedShort(constantPool.literalIndexForJavaLangLong());
4450                         break;
4451                 case T_void : // new: java.lang.Void
4452                         if (DEBUG) System.out.println(position + "\t\tnew: java.lang.Void"); //$NON-NLS-1$
4453                         writeUnsignedShort(constantPool.literalIndexForJavaLangVoid());
4454         }
4455 }
4456 final public void nop() {
4457         if (DEBUG) System.out.println(position + "\t\tnop"); //$NON-NLS-1$
4458         countLabels = 0;
4459         if (classFileOffset >= bCodeStream.length) {
4460                 resizeByteArray();
4461         }
4462         position++;
4463         bCodeStream[classFileOffset++] = OPC_nop;
4464 }
4465 final public void pop() {
4466         if (DEBUG) System.out.println(position + "\t\tpop"); //$NON-NLS-1$
4467         countLabels = 0;
4468         stackDepth--;
4469         if (classFileOffset >= bCodeStream.length) {
4470                 resizeByteArray();
4471         }
4472         position++;
4473         bCodeStream[classFileOffset++] = OPC_pop;
4474 }
4475 final public void pop2() {
4476         if (DEBUG) System.out.println(position + "\t\tpop2"); //$NON-NLS-1$
4477         countLabels = 0;
4478         stackDepth -= 2;
4479         if (classFileOffset >= bCodeStream.length) {
4480                 resizeByteArray();
4481         }
4482         position++;
4483         bCodeStream[classFileOffset++] = OPC_pop2;
4484 }
4485 final public void putfield(FieldBinding fieldBinding) {
4486         if (DEBUG) System.out.println(position + "\t\tputfield:"+fieldBinding); //$NON-NLS-1$
4487         countLabels = 0;
4488         int id;
4489         if (((id = fieldBinding.type.id) == T_double) || (id == T_long))
4490                 stackDepth -= 3;
4491         else
4492                 stackDepth -= 2;
4493         if (stackDepth > stackMax)
4494                 stackMax = stackDepth;
4495         if (classFileOffset + 2 >= bCodeStream.length) {
4496                 resizeByteArray();
4497         }
4498         position++;
4499         bCodeStream[classFileOffset++] = OPC_putfield;
4500         writeUnsignedShort(constantPool.literalIndex(fieldBinding));
4501 }
4502 final public void putstatic(FieldBinding fieldBinding) {
4503         if (DEBUG) System.out.println(position + "\t\tputstatic:"+fieldBinding); //$NON-NLS-1$
4504         countLabels = 0;
4505         int id;
4506         if (((id = fieldBinding.type.id) == T_double) || (id == T_long))
4507                 stackDepth -= 2;
4508         else
4509                 stackDepth -= 1;
4510         if (stackDepth > stackMax)
4511                 stackMax = stackDepth;
4512         if (classFileOffset + 2 >= bCodeStream.length) {
4513                 resizeByteArray();
4514         }
4515         position++;
4516         bCodeStream[classFileOffset++] = OPC_putstatic;
4517         writeUnsignedShort(constantPool.literalIndex(fieldBinding));
4518 }
4519 public void record(LocalVariableBinding local) {
4520         if (!generateLocalVariableTableAttributes)
4521                 return;
4522         if (allLocalsCounter == locals.length) {
4523                 // resize the collection
4524                 System.arraycopy(locals, 0, locals = new LocalVariableBinding[allLocalsCounter + LOCALS_INCREMENT], 0, allLocalsCounter);
4525         }
4526         locals[allLocalsCounter++] = local;
4527         local.initializationPCs = new int[4];
4528         local.initializationCount = 0;
4529 }
4530 public void recordPositionsFrom(int startPC, int sourcePos) {
4531
4532         /* Record positions in the table, only if nothing has 
4533          * already been recorded. Since we output them on the way 
4534          * up (children first for more specific info)
4535          * The pcToSourceMap table is always sorted.
4536          */
4537
4538         if (!generateLineNumberAttributes)
4539                 return;
4540         if (sourcePos == 0)
4541                 return;
4542
4543         // no code generated for this node. e.g. field without any initialization
4544         if (position == startPC)
4545                 return;
4546
4547         // Widening an existing entry that already has the same source positions
4548         if (pcToSourceMapSize + 4 > pcToSourceMap.length) {
4549                 // resize the array pcToSourceMap
4550                 System.arraycopy(pcToSourceMap, 0, pcToSourceMap = new int[pcToSourceMapSize << 1], 0, pcToSourceMapSize);
4551         }
4552         int newLine = ClassFile.searchLineNumber(lineSeparatorPositions, sourcePos);
4553         // lastEntryPC represents the endPC of the lastEntry.
4554         if (pcToSourceMapSize > 0) {
4555                 // in this case there is already an entry in the table
4556                 if (pcToSourceMap[pcToSourceMapSize - 1] != newLine) {
4557                         if (startPC < lastEntryPC) {
4558                                 // we forgot to add an entry.
4559                                 // search if an existing entry exists for startPC
4560                                 int insertionIndex = insertionIndex(pcToSourceMap, pcToSourceMapSize, startPC);
4561                                 if (insertionIndex != -1) {
4562                                         // there is no existing entry starting with startPC.
4563                                         int existingEntryIndex = indexOfSameLineEntrySincePC(startPC, newLine); // index for PC
4564                                         /* the existingEntryIndex corresponds to en entry with the same line and a PC >= startPC.
4565                                                 in this case it is relevant to widen this entry instead of creating a new one.
4566                                                 line1: this(a,
4567                                                   b,
4568                                                   c);
4569                                                 with this code we generate each argument. We generate a aload0 to invoke the constructor. There is no entry for this
4570                                                 aload0 bytecode. The first entry is the one for the argument a.
4571                                                 But we want the constructor call to start at the aload0 pc and not just at the pc of the first argument.
4572                                                 So we widen the existing entry (if there is one) or we create a new entry with the startPC.
4573                                         */
4574                                         if (existingEntryIndex != -1) {
4575                                                 // widen existing entry
4576                                                 pcToSourceMap[existingEntryIndex] = startPC;
4577                                         } else {
4578                                                 // we have to add an entry that won't be sorted. So we sort the pcToSourceMap.
4579                                                 System.arraycopy(pcToSourceMap, insertionIndex, pcToSourceMap, insertionIndex + 2, pcToSourceMapSize - insertionIndex);
4580                                                 pcToSourceMap[insertionIndex++] = startPC;
4581                                                 pcToSourceMap[insertionIndex] = newLine;
4582                                                 pcToSourceMapSize += 2;
4583                                         }
4584                                 }
4585                                 if (position != lastEntryPC) { // no bytecode since last entry pc
4586                                         pcToSourceMap[pcToSourceMapSize++] = lastEntryPC;
4587                                         pcToSourceMap[pcToSourceMapSize++] = newLine;
4588                                 }
4589                         } else {
4590                                 // we can safely add the new entry. The endPC of the previous entry is not in conflit with the startPC of the new entry.
4591                                 pcToSourceMap[pcToSourceMapSize++] = startPC;
4592                                 pcToSourceMap[pcToSourceMapSize++] = newLine;
4593                         }
4594                 } else {
4595                         /* the last recorded entry is on the same line. But it could be relevant to widen this entry.
4596                            we want to extend this entry forward in case we generated some bytecode before the last entry that are not related to any statement
4597                         */      
4598                         if (startPC < pcToSourceMap[pcToSourceMapSize - 2]) {
4599                                 int insertionIndex = insertionIndex(pcToSourceMap, pcToSourceMapSize, startPC);
4600                                 if (insertionIndex != -1) {
4601                                         // widen the existing entry
4602                                         // we have to figure out if we need to move the last entry at another location to keep a sorted table
4603                                         /* First we need to check if at the insertion position there is not an existing entry
4604                                          * that includes the one we want to insert. This is the case if pcToSourceMap[insertionIndex - 1] == newLine.
4605                                          * In this case we don't want to change the table. If not, we want to insert a new entry. Prior to insertion
4606                                          * we want to check if it is worth doing an arraycopy. If not we simply update the recorded pc.
4607                                          */
4608                                         if (!((insertionIndex > 1) && (pcToSourceMap[insertionIndex - 1] == newLine))) {
4609                                                 if ((pcToSourceMapSize > 4) && (pcToSourceMap[pcToSourceMapSize - 4] > startPC)) {
4610                                                         System.arraycopy(pcToSourceMap, insertionIndex, pcToSourceMap, insertionIndex + 2, pcToSourceMapSize - 2 - insertionIndex);
4611                                                         pcToSourceMap[insertionIndex++] = startPC;
4612                                                         pcToSourceMap[insertionIndex] = newLine;                                                
4613                                                 } else {
4614                                                         pcToSourceMap[pcToSourceMapSize - 2] = startPC;
4615                                                 }
4616                                         }
4617                                 }
4618                         }
4619                 }
4620                 lastEntryPC = position;
4621         } else {
4622                 // record the first entry
4623                 pcToSourceMap[pcToSourceMapSize++] = startPC;
4624                 pcToSourceMap[pcToSourceMapSize++] = newLine;
4625                 lastEntryPC = position;
4626         }
4627 }
4628 /**
4629  * @param anExceptionLabel org.eclipse.jdt.internal.compiler.codegen.ExceptionLabel
4630  */
4631 public void registerExceptionHandler(ExceptionLabel anExceptionLabel) {
4632         int length;
4633         if (exceptionHandlersNumber >= (length = exceptionHandlers.length)) {
4634                 // resize the exception handlers table
4635                 System.arraycopy(exceptionHandlers, 0, exceptionHandlers = new ExceptionLabel[length + LABELS_INCREMENT], 0, length);
4636         }
4637         // no need to resize. So just add the new exception label
4638         exceptionHandlers[exceptionHandlersNumber++] = anExceptionLabel;
4639 }
4640 public final void removeNotDefinitelyAssignedVariables(Scope scope, int initStateIndex) {
4641         // given some flow info, make sure we did not loose some variables initialization
4642         // if this happens, then we must update their pc entries to reflect it in debug attributes
4643         if (!generateLocalVariableTableAttributes)
4644                 return;
4645 /*      if (initStateIndex == lastInitStateIndexWhenRemovingInits)
4646                 return;
4647                 
4648         lastInitStateIndexWhenRemovingInits = initStateIndex;
4649         if (lastInitStateIndexWhenAddingInits != initStateIndex){
4650                 lastInitStateIndexWhenAddingInits = -2;// reinitialize add index 
4651                 // add(1)-remove(1)-add(1) -> ignore second add
4652                 // add(1)-remove(2)-add(1) -> perform second add
4653         }*/
4654         for (int i = 0; i < visibleLocalsCount; i++) {
4655                 LocalVariableBinding localBinding = visibleLocals[i];
4656                 if (localBinding != null) {
4657                         if (initStateIndex == -1 || !isDefinitelyAssigned(scope, initStateIndex, localBinding)) {
4658                                 if (localBinding.initializationCount > 0) {
4659                                         localBinding.recordInitializationEndPC(position);
4660                                 }
4661                         }
4662                 }
4663         }
4664 }
4665 /**
4666  * @param referenceMethod org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration
4667  * @param targetClassFile org.eclipse.jdt.internal.compiler.codegen.ClassFile
4668  */
4669 public void reset(AbstractMethodDeclaration referenceMethod, ClassFile targetClassFile) {
4670         init(targetClassFile);
4671         this.methodDeclaration = referenceMethod;
4672         preserveUnusedLocals = referenceMethod.scope.problemReporter().options.preserveAllLocalVariables;
4673         initializeMaxLocals(referenceMethod.binding);
4674 }
4675 /**
4676  * @param targetClassFile The given classfile to reset the code stream
4677  */
4678 public void resetForProblemClinit(ClassFile targetClassFile) {
4679         init(targetClassFile);
4680         maxLocals = 0;
4681 }
4682 private final void resizeByteArray() {
4683         int length = bCodeStream.length;
4684         int requiredSize = length + length;
4685         if (classFileOffset > requiredSize) {
4686                 // must be sure to grow by enough
4687                 requiredSize = classFileOffset + length;
4688         }
4689         System.arraycopy(bCodeStream, 0, bCodeStream = new byte[requiredSize], 0, length);
4690 }
4691 final public void ret(int index) {
4692         if (DEBUG) System.out.println(position + "\t\tret:"+index); //$NON-NLS-1$
4693         countLabels = 0;
4694         if (index > 255) { // Widen
4695                 if (classFileOffset + 3 >= bCodeStream.length) {
4696                         resizeByteArray();
4697                 }
4698                 position += 2;
4699                 bCodeStream[classFileOffset++] = OPC_wide;
4700                 bCodeStream[classFileOffset++] = OPC_ret;
4701                 writeUnsignedShort(index);
4702         } else { // Don't Widen
4703                 if (classFileOffset + 1 >= bCodeStream.length) {
4704                         resizeByteArray();
4705                 }
4706                 position += 2;
4707                 bCodeStream[classFileOffset++] = OPC_ret;
4708                 bCodeStream[classFileOffset++] = (byte) index;
4709         }
4710 }
4711 final public void return_() {
4712         if (DEBUG) System.out.println(position + "\t\treturn"); //$NON-NLS-1$
4713         countLabels = 0;
4714         // the stackDepth should be equal to 0 
4715         if (classFileOffset >= bCodeStream.length) {
4716                 resizeByteArray();
4717         }
4718         position++;
4719         bCodeStream[classFileOffset++] = OPC_return;
4720 }
4721 final public void saload() {
4722         if (DEBUG) System.out.println(position + "\t\tsaload"); //$NON-NLS-1$
4723         countLabels = 0;
4724         stackDepth--;
4725         if (classFileOffset >= bCodeStream.length) {
4726                 resizeByteArray();
4727         }
4728         position++;
4729         bCodeStream[classFileOffset++] = OPC_saload;
4730 }
4731 final public void sastore() {
4732         if (DEBUG) System.out.println(position + "\t\tsastore"); //$NON-NLS-1$
4733         countLabels = 0;
4734         stackDepth -= 3;
4735         if (classFileOffset >= bCodeStream.length) {
4736                 resizeByteArray();
4737         }
4738         position++;
4739         bCodeStream[classFileOffset++] = OPC_sastore;
4740 }
4741 /**
4742  * @param operatorConstant int
4743  * @param type_ID int
4744  */
4745 public void sendOperator(int operatorConstant, int type_ID) {
4746         switch (type_ID) {
4747                 case T_int :
4748                 case T_boolean :
4749                 case T_char :
4750                 case T_byte :
4751                 case T_short :
4752                         switch (operatorConstant) {
4753                                 case PLUS :
4754                                         this.iadd();
4755                                         break;
4756                                 case MINUS :
4757                                         this.isub();
4758                                         break;
4759                                 case MULTIPLY :
4760                                         this.imul();
4761                                         break;
4762                                 case DIVIDE :
4763                                         this.idiv();
4764                                         break;
4765                                 case REMAINDER :
4766                                         this.irem();
4767                                         break;
4768                                 case LEFT_SHIFT :
4769                                         this.ishl();
4770                                         break;
4771                                 case RIGHT_SHIFT :
4772                                         this.ishr();
4773                                         break;
4774                                 case UNSIGNED_RIGHT_SHIFT :
4775                                         this.iushr();
4776                                         break;
4777                                 case AND :
4778                                         this.iand();
4779                                         break;
4780                                 case OR :
4781                                         this.ior();
4782                                         break;
4783                                 case XOR :
4784                                         this.ixor();
4785                                         break;
4786                         }
4787                         break;
4788                 case T_long :
4789                         switch (operatorConstant) {
4790                                 case PLUS :
4791                                         this.ladd();
4792                                         break;
4793                                 case MINUS :
4794                                         this.lsub();
4795                                         break;
4796                                 case MULTIPLY :
4797                                         this.lmul();
4798                                         break;
4799                                 case DIVIDE :
4800                                         this.ldiv();
4801                                         break;
4802                                 case REMAINDER :
4803                                         this.lrem();
4804                                         break;
4805                                 case LEFT_SHIFT :
4806                                         this.lshl();
4807                                         break;
4808                                 case RIGHT_SHIFT :
4809                                         this.lshr();
4810                                         break;
4811                                 case UNSIGNED_RIGHT_SHIFT :
4812                                         this.lushr();
4813                                         break;
4814                                 case AND :
4815                                         this.land();
4816                                         break;
4817                                 case OR :
4818                                         this.lor();
4819                                         break;
4820                                 case XOR :
4821                                         this.lxor();
4822                                         break;
4823                         }
4824                         break;
4825                 case T_float :
4826                         switch (operatorConstant) {
4827                                 case PLUS :
4828                                         this.fadd();
4829                                         break;
4830                                 case MINUS :
4831                                         this.fsub();
4832                                         break;
4833                                 case MULTIPLY :
4834                                         this.fmul();
4835                                         break;
4836                                 case DIVIDE :
4837                                         this.fdiv();
4838                                         break;
4839                                 case REMAINDER :
4840                                         this.frem();
4841                         }
4842                         break;
4843                 case T_double :
4844                         switch (operatorConstant) {
4845                                 case PLUS :
4846                                         this.dadd();
4847                                         break;
4848                                 case MINUS :
4849                                         this.dsub();
4850                                         break;
4851                                 case MULTIPLY :
4852                                         this.dmul();
4853                                         break;
4854                                 case DIVIDE :
4855                                         this.ddiv();
4856                                         break;
4857                                 case REMAINDER :
4858                                         this.drem();
4859                         }
4860         }
4861 }
4862 final public void sipush(int s) {
4863         if (DEBUG) System.out.println(position + "\t\tsipush:"+s); //$NON-NLS-1$
4864         countLabels = 0;
4865         stackDepth++;
4866         if (stackDepth > stackMax)
4867                 stackMax = stackDepth;
4868         if (classFileOffset >= bCodeStream.length) {
4869                 resizeByteArray();
4870         }
4871         position++;
4872         bCodeStream[classFileOffset++] = OPC_sipush;
4873         writeSignedShort(s);
4874 }
4875 public static final void sort(int[] tab, int lo0, int hi0, int[] result) {
4876         int lo = lo0;
4877         int hi = hi0;
4878         int mid;
4879         if (hi0 > lo0) {
4880                 /* Arbitrarily establishing partition element as the midpoint of
4881                   * the array.
4882                   */
4883                 mid = tab[ (lo0 + hi0) / 2];
4884                 // loop through the array until indices cross
4885                 while (lo <= hi) {
4886                         /* find the first element that is greater than or equal to 
4887                          * the partition element starting from the left Index.
4888                          */
4889                         while ((lo < hi0) && (tab[lo] < mid))
4890                                 ++lo;
4891                         /* find an element that is smaller than or equal to 
4892                          * the partition element starting from the right Index.
4893                          */
4894                         while ((hi > lo0) && (tab[hi] > mid))
4895                                 --hi;
4896                         // if the indexes have not crossed, swap
4897                         if (lo <= hi) {
4898                                 swap(tab, lo, hi, result);
4899                                 ++lo;
4900                                 --hi;
4901                         }
4902                 }
4903                 /* If the right index has not reached the left side of array
4904                   * must now sort the left partition.
4905                   */
4906                 if (lo0 < hi)
4907                         sort(tab, lo0, hi, result);
4908                 /* If the left index has not reached the right side of array
4909                   * must now sort the right partition.
4910                   */
4911                 if (lo < hi0)
4912                         sort(tab, lo, hi0, result);
4913         }
4914 }
4915
4916 public final void store(LocalVariableBinding localBinding, boolean valueRequired) {
4917         int localPosition = localBinding.resolvedPosition;
4918         // Using dedicated int bytecode
4919         switch(localBinding.type.id) {
4920                 case TypeIds.T_int :
4921                 case TypeIds.T_char :
4922                 case TypeIds.T_byte :
4923                 case TypeIds.T_short :
4924                 case TypeIds.T_boolean :
4925                         if (valueRequired)
4926                                 this.dup();
4927                         switch (localPosition) {
4928                                 case 0 :
4929                                         this.istore_0();
4930                                         break;
4931                                 case 1 :
4932                                         this.istore_1();
4933                                         break;
4934                                 case 2 :
4935                                         this.istore_2();
4936                                         break;
4937                                 case 3 :
4938                                         this.istore_3();
4939                                         break;
4940                                 //case -1 :
4941                                 // internal failure: trying to store into variable not supposed to be generated
4942                                 //      break;
4943                                 default :
4944                                         this.istore(localPosition);
4945                         }
4946                         break;
4947                 case TypeIds.T_float :
4948                         if (valueRequired)
4949                                 this.dup();
4950                         switch (localPosition) {
4951                                 case 0 :
4952                                         this.fstore_0();
4953                                         break;
4954                                 case 1 :
4955                                         this.fstore_1();
4956                                         break;
4957                                 case 2 :
4958                                         this.fstore_2();
4959                                         break;
4960                                 case 3 :
4961                                         this.fstore_3();
4962                                         break;
4963                                 default :
4964                                         this.fstore(localPosition);
4965                         }
4966                         break;
4967                 case TypeIds.T_double :
4968                         if (valueRequired)
4969                                 this.dup2();
4970                         switch (localPosition) {
4971                                 case 0 :
4972                                         this.dstore_0();
4973                                         break;
4974                                 case 1 :
4975                                         this.dstore_1();
4976                                         break;
4977                                 case 2 :
4978                                         this.dstore_2();
4979                                         break;
4980                                 case 3 :
4981                                         this.dstore_3();
4982                                         break;
4983                                 default :
4984                                         this.dstore(localPosition);
4985                         }
4986                         break;
4987                 case TypeIds.T_long :
4988                         if (valueRequired)
4989                                 this.dup2();
4990                         switch (localPosition) {
4991                                 case 0 :
4992                                         this.lstore_0();
4993                                         break;
4994                                 case 1 :
4995                                         this.lstore_1();
4996                                         break;
4997                                 case 2 :
4998                                         this.lstore_2();
4999                                         break;
5000                                 case 3 :
5001                                         this.lstore_3();
5002                                         break;
5003                                 default :
5004                                         this.lstore(localPosition);
5005                         }
5006                         break;
5007                 default:
5008                         // Reference object
5009                         if (valueRequired)
5010                                 this.dup();
5011                         switch (localPosition) {
5012                                 case 0 :
5013                                         this.astore_0();
5014                                         break;
5015                                 case 1 :
5016                                         this.astore_1();
5017                                         break;
5018                                 case 2 :
5019                                         this.astore_2();
5020                                         break;
5021                                 case 3 :
5022                                         this.astore_3();
5023                                         break;
5024                                 default :
5025                                         this.astore(localPosition);
5026                         }
5027         }
5028 }
5029 public final void store(TypeBinding type, int localPosition) {
5030         // Using dedicated int bytecode
5031         if ((type == IntBinding) || (type == CharBinding) || (type == ByteBinding) || (type == ShortBinding) || (type == BooleanBinding)) {
5032                 switch (localPosition) {
5033                         case 0 :
5034                                 this.istore_0();
5035                                 break;
5036                         case 1 :
5037                                 this.istore_1();
5038                                 break;
5039                         case 2 :
5040                                 this.istore_2();
5041                                 break;
5042                         case 3 :
5043                                 this.istore_3();
5044                                 break;
5045                         default :
5046                                 this.istore(localPosition);
5047                 }
5048                 return;
5049         }
5050         // Using dedicated float bytecode
5051         if (type == FloatBinding) {
5052                 switch (localPosition) {
5053                         case 0 :
5054                                 this.fstore_0();
5055                                 break;
5056                         case 1 :
5057                                 this.fstore_1();
5058                                 break;
5059                         case 2 :
5060                                 this.fstore_2();
5061                                 break;
5062                         case 3 :
5063                                 this.fstore_3();
5064                                 break;
5065                         default :
5066                                 this.fstore(localPosition);
5067                 }
5068                 return;
5069         }
5070         // Using dedicated long bytecode
5071         if (type == LongBinding) {
5072                 switch (localPosition) {
5073                         case 0 :
5074                                 this.lstore_0();
5075                                 break;
5076                         case 1 :
5077                                 this.lstore_1();
5078                                 break;
5079                         case 2 :
5080                                 this.lstore_2();
5081                                 break;
5082                         case 3 :
5083                                 this.lstore_3();
5084                                 break;
5085                         default :
5086                                 this.lstore(localPosition);
5087                 }
5088                 return;
5089         }
5090         // Using dedicated double bytecode
5091         if (type == DoubleBinding) {
5092                 switch (localPosition) {
5093                         case 0 :
5094                                 this.dstore_0();
5095                                 break;
5096                         case 1 :
5097                                 this.dstore_1();
5098                                 break;
5099                         case 2 :
5100                                 this.dstore_2();
5101                                 break;
5102                         case 3 :
5103                                 this.dstore_3();
5104                                 break;
5105                         default :
5106                                 this.dstore(localPosition);
5107                 }
5108                 return;
5109         }
5110         // Reference object
5111         switch (localPosition) {
5112                 case 0 :
5113                         this.astore_0();
5114                         break;
5115                 case 1 :
5116                         this.astore_1();
5117                         break;
5118                 case 2 :
5119                         this.astore_2();
5120                         break;
5121                 case 3 :
5122                         this.astore_3();
5123                         break;
5124                 default :
5125                         this.astore(localPosition);
5126         }
5127 }
5128 public final void storeInt(int localPosition) {
5129         switch (localPosition) {
5130                 case 0 :
5131                         this.istore_0();
5132                         break;
5133                 case 1 :
5134                         this.istore_1();
5135                         break;
5136                 case 2 :
5137                         this.istore_2();
5138                         break;
5139                 case 3 :
5140                         this.istore_3();
5141                         break;
5142                 default :
5143                         this.istore(localPosition);
5144         }
5145 }
5146 public final void storeObject(int localPosition) {
5147         switch (localPosition) {
5148                 case 0 :
5149                         this.astore_0();
5150                         break;
5151                 case 1 :
5152                         this.astore_1();
5153                         break;
5154                 case 2 :
5155                         this.astore_2();
5156                         break;
5157                 case 3 :
5158                         this.astore_3();
5159                         break;
5160                 default :
5161                         this.astore(localPosition);
5162         }
5163 }
5164 final public void swap() {
5165         if (DEBUG) System.out.println(position + "\t\tswap"); //$NON-NLS-1$
5166         countLabels = 0;
5167         if (classFileOffset >= bCodeStream.length) {
5168                 resizeByteArray();
5169         }
5170         position++;
5171         bCodeStream[classFileOffset++] = OPC_swap;
5172 }
5173 private static final void swap(int a[], int i, int j, int result[]) {
5174         int T;
5175         T = a[i];
5176         a[i] = a[j];
5177         a[j] = T;
5178         T = result[j];
5179         result[j] = result[i];
5180         result[i] = T;
5181 }
5182 final public void tableswitch(CaseLabel defaultLabel, int low, int high, int[] keys, int[] sortedIndexes, CaseLabel[] casesLabel) {
5183         if (DEBUG) System.out.println(position + "\t\ttableswitch"); //$NON-NLS-1$
5184         countLabels = 0;
5185         stackDepth--;
5186         int length = casesLabel.length;
5187         int pos = position;
5188         defaultLabel.placeInstruction();
5189         for (int i = 0; i < length; i++)
5190                 casesLabel[i].placeInstruction();
5191         if (classFileOffset >= bCodeStream.length) {
5192                 resizeByteArray();
5193         }
5194         position++;
5195         bCodeStream[classFileOffset++] = OPC_tableswitch;
5196         for (int i = (3 - (pos % 4)); i > 0; i--) {
5197                 if (classFileOffset >= bCodeStream.length) {
5198                         resizeByteArray();
5199                 }
5200                 position++;
5201                 bCodeStream[classFileOffset++] = 0;
5202         }
5203         defaultLabel.branch();
5204         writeSignedWord(low);
5205         writeSignedWord(high);
5206         int i = low, j = low;
5207         // the index j is used to know if the index i is one of the missing entries in case of an 
5208         // optimized tableswitch
5209         while (true) {
5210                 int index;
5211                 int key = keys[index = sortedIndexes[j - low]];
5212                 if (key == i) {
5213                         casesLabel[index].branch();
5214                         j++;
5215                         if (i == high) break; // if high is maxint, then avoids wrapping to minint.
5216                 } else {
5217                         defaultLabel.branch();
5218                 }
5219                 i++;
5220         }
5221 }
5222 public String toString() {
5223         StringBuffer buffer = new StringBuffer("( position:"); //$NON-NLS-1$
5224         buffer.append(position);
5225         buffer.append(",\nstackDepth:"); //$NON-NLS-1$
5226         buffer.append(stackDepth);
5227         buffer.append(",\nmaxStack:"); //$NON-NLS-1$
5228         buffer.append(stackMax);
5229         buffer.append(",\nmaxLocals:"); //$NON-NLS-1$
5230         buffer.append(maxLocals);
5231         buffer.append(")"); //$NON-NLS-1$
5232         return buffer.toString();
5233 }
5234 public void updateLastRecordedEndPC(int pos) {
5235
5236         /* Tune positions in the table, this is due to some 
5237          * extra bytecodes being
5238          * added to some user code (jumps). */
5239         /** OLD CODE
5240                 if (!generateLineNumberAttributes)
5241                         return;
5242                 pcToSourceMap[pcToSourceMapSize - 1][1] = position;
5243                 // need to update the initialization endPC in case of generation of local variable attributes.
5244                 updateLocalVariablesAttribute(pos);     
5245         */      
5246
5247         if (!generateLineNumberAttributes)
5248                 return;
5249         this.lastEntryPC = pos;
5250         // need to update the initialization endPC in case of generation of local variable attributes.
5251         updateLocalVariablesAttribute(pos);
5252 }
5253 public void updateLocalVariablesAttribute(int pos) {
5254         // need to update the initialization endPC in case of generation of local variable attributes.
5255         if (generateLocalVariableTableAttributes) {
5256                 for (int i = 0, max = locals.length; i < max; i++) {
5257                         LocalVariableBinding local = locals[i];
5258                         if ((local != null) && (local.initializationCount > 0)) {
5259                                 if (local.initializationPCs[((local.initializationCount - 1) << 1) + 1] == pos) {
5260                                         local.initializationPCs[((local.initializationCount - 1) << 1) + 1] = position;
5261                                 }
5262                         }
5263                 }
5264         }
5265 }
5266 /**
5267  * Write a signed 16 bits value into the byte array
5268  * @param value the signed short
5269  */
5270 public final void writeSignedShort(int value) {
5271         // we keep the resize in here because it is used outside the code stream
5272         if (classFileOffset + 1 >= bCodeStream.length) {
5273                 resizeByteArray();
5274         }
5275         position += 2;
5276         bCodeStream[classFileOffset++] = (byte) (value >> 8);
5277         bCodeStream[classFileOffset++] = (byte) value;
5278 }
5279 public final void writeSignedShort(int pos, int value) {
5280         int currentOffset = startingClassFileOffset + pos;
5281         if (currentOffset + 1 >= bCodeStream.length) {
5282                 resizeByteArray();
5283         }
5284         bCodeStream[currentOffset] = (byte) (value >> 8);
5285         bCodeStream[currentOffset + 1] = (byte) value;
5286 }
5287 public final void writeSignedWord(int value) {
5288         // we keep the resize in here because it is used outside the code stream
5289         if (classFileOffset + 3 >= bCodeStream.length) {
5290                 resizeByteArray();
5291         }
5292         position += 4;
5293         bCodeStream[classFileOffset++] = (byte) ((value & 0xFF000000) >> 24);
5294         bCodeStream[classFileOffset++] = (byte) ((value & 0xFF0000) >> 16);
5295         bCodeStream[classFileOffset++] = (byte) ((value & 0xFF00) >> 8);
5296         bCodeStream[classFileOffset++] = (byte) (value & 0xFF);
5297 }
5298 public final void writeSignedWord(int pos, int value) {
5299         int currentOffset = startingClassFileOffset + pos;
5300         if (currentOffset + 4 >= bCodeStream.length) {
5301                 resizeByteArray();
5302         }
5303         bCodeStream[currentOffset++] = (byte) ((value & 0xFF000000) >> 24);
5304         bCodeStream[currentOffset++] = (byte) ((value & 0xFF0000) >> 16);
5305         bCodeStream[currentOffset++] = (byte) ((value & 0xFF00) >> 8);
5306         bCodeStream[currentOffset++] = (byte) (value & 0xFF);
5307 }
5308 /**
5309  * Write a unsigned 16 bits value into the byte array
5310  * @param value the unsigned short
5311  */
5312 protected final void writeUnsignedShort(int value) {
5313         position += 2;
5314         bCodeStream[classFileOffset++] = (byte) (value >>> 8);
5315         bCodeStream[classFileOffset++] = (byte) value;
5316 }
5317 /*
5318  * Wide conditional branch compare, improved by swapping comparison opcode
5319  *   ifeq WideTarget
5320  * becomes
5321  *    ifne Intermediate
5322  *    gotow WideTarget
5323  *    Intermediate:
5324  */
5325 public void generateWideRevertedConditionalBranch(byte revertedOpcode, Label wideTarget) {
5326                 Label intermediate = new Label(this);
5327                 if (classFileOffset >= bCodeStream.length) {
5328                         resizeByteArray();
5329                 }
5330                 position++;
5331                 bCodeStream[classFileOffset++] = revertedOpcode;
5332                 intermediate.branch();
5333                 this.goto_w(wideTarget);
5334                 intermediate.place();
5335 }
5336 }