KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > cojen > classfile > CodeAssembler


1 /*
2  * Copyright 2004 Brian S O'Neill
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.cojen.classfile;
18
19 import java.lang.reflect.Constructor JavaDoc;
20 import java.lang.reflect.Method JavaDoc;
21 import java.util.MissingResourceException JavaDoc;
22
23 /**
24  * CodeAssembler is a high-level interface for assembling Java Virtual Machine
25  * byte code. It can also be used as a visitor to a disassembler.
26  *
27  * @author Brian S O'Neill
28  */

29 public interface CodeAssembler {
30     /** Convert floating point values as normal */
31     public final static int CONVERT_FP_NORMAL = 0;
32     /** Convert floating point values as bits (NaN is canonicalized) */
33     public final static int CONVERT_FP_BITS = 1;
34     /** Convert floating point values as raw bits */
35     public final static int CONVERT_FP_RAW_BITS = 2;
36
37     /**
38      * Returns the amount of parameters that are accepted by the method being
39      * built, not including any "this" reference.
40      */

41     int getParameterCount();
42
43     /**
44      * Returns a specific parameter, whose index lies within 0 to
45      * getParameterCount() - 1. The names of the LocalVariables returned by
46      * this method are initially set to null. It is encouraged that a name be
47      * provided.
48      */

49     LocalVariable getParameter(int index) throws IndexOutOfBoundsException JavaDoc;
50
51     /**
52      * Creates a LocalVariable reference from a name and type. Although name
53      * is optional, it is encouraged that a name be provided. Names do not
54      * need to be unique.
55      *
56      * @param name Optional name for the LocalVariable.
57      * @param type The type of data that the requested LocalVariable can
58      * store.
59      */

60     LocalVariable createLocalVariable(String JavaDoc name, TypeDesc type);
61
62     /**
63      * Creates a label, whose location must be set. To create a label and
64      * locate it here, the following example demonstrates how the call to
65      * setLocation can be chained:
66      *
67      * <pre>
68      * CodeBuilder builder;
69      * ...
70      * Label label = builder.createLabel().setLocation();
71      * </pre>
72      *
73      * @see Label#setLocation
74      */

75     Label createLabel();
76
77     /**
78      * Sets up an exception handler located here, the location of the next
79      * code to be generated.
80      *
81      * @param startLocation Location at the start of the section of
82      * code to be wrapped by an exception handler.
83      * @param endLocation Location directly after the end of the
84      * section of code.
85      * @param catchClassName The class name of exception to be caught;
86      * if null, then catch every object.
87      */

88     void exceptionHandler(Location startLocation,
89                           Location endLocation,
90                           String JavaDoc catchClassName);
91     
92     /**
93      * Map the location of the next code to be generated to a line number
94      * in source code. This enables line numbers in a stack trace from the
95      * generated code.
96      */

97     void mapLineNumber(int lineNumber);
98
99     /**
100      * Allows code to disassembled and copied straight in. The code object
101      * passed in must have a single method named "define" whose arguments match
102      * the type and order of values expected on the operand stack. If a return
103      * value is provided, it will pushed onto the stack. The define method can
104      * have any access modifier.
105      *
106      * @throws IllegalArgumentException if define method not found, or if
107      * multiple are found
108      * @throws MissingResourceException if define code not found
109      */

110     void inline(Object JavaDoc code) throws IllegalArgumentException JavaDoc, MissingResourceException JavaDoc;
111
112     // load-constant-to-stack style instructions
113

114     /**
115      * Generates code that loads a null reference onto the stack.
116      */

117     void loadNull();
118
119     /**
120      * Generates code that loads a constant string value onto the stack. If
121      * value is null, the generated code loads a null onto the stack. Strings
122      * that exceed 65535 UTF encoded bytes in length are loaded by creating a
123      * StringBuffer (or a StringBuilder), appending substrings, and then
124      * converting it to a String.
125      */

126     void loadConstant(String JavaDoc value);
127
128     /**
129      * Generates code that loads a constant class value onto the stack.
130      * If value is null, the generated code loads a null onto the stack.
131      *
132      * @param type any object or primitive type
133      * @throws IllegalStateException if class file target version does not
134      * support this feature
135      */

136     void loadConstant(TypeDesc type) throws IllegalStateException JavaDoc;
137
138     /**
139      * Generates code that loads a constant boolean value onto the stack.
140      */

141     void loadConstant(boolean value);
142
143     /**
144      * Generates code that loads a constant int, char, short or byte value
145      * onto the stack.
146      */

147     void loadConstant(int value);
148
149     /**
150      * Generates code that loads a constant long value onto the stack.
151      */

152     void loadConstant(long value);
153
154     /**
155      * Generates code that loads a constant float value onto the stack.
156      */

157     void loadConstant(float value);
158
159     /**
160      * Generates code that loads a constant double value onto the stack.
161      */

162     void loadConstant(double value);
163
164     // load-local-to-stack style instructions
165

166     /**
167      * Generates code that loads a local variable onto the stack. Parameters
168      * passed to a method and the "this" reference are all considered local
169      * variables, as well as any that were created.
170      *
171      * @param local The local variable reference
172      */

173     void loadLocal(LocalVariable local);
174
175     /**
176      * Loads a reference to "this" onto the stack. Static methods have no
177      * "this" reference, and an exception is thrown when attempting to
178      * generate "this" in a static method.
179      */

180     void loadThis();
181
182     // store-from-stack-to-local style instructions
183

184     /**
185      * Generates code that pops a value off of the stack into a local variable.
186      * Parameters passed to a method and the "this" reference are all
187      * considered local variables, as well as any that were created.
188      *
189      * @param local The local variable reference
190      * @see #getParameter
191      * @see #createLocalVariable
192      */

193     void storeLocal(LocalVariable local);
194
195     // load-to-stack-from-array style instructions
196

197     /**
198      * Generates code that loads a value from an array. An array
199      * reference followed by an index must be on the stack. The array
200      * reference and index are replaced by the value retrieved from the array
201      * after the generated instruction has executed.
202      * <p>
203      * The type doesn't need to be an exact match for objects.
204      * TypeDesc.OBJECT works fine for all objects. For primitive types, use
205      * the appropriate TypeDesc. For an int, the type is TypeDesc.INT.
206      *
207      * @param type The type of data stored in the array.
208      */

209     void loadFromArray(TypeDesc type);
210
211     // store-to-array-from-stack style instructions
212

213     /**
214      * Generates code that stores a value to an array. An array
215      * reference followed by an index, followed by a value (or two if a long
216      * or double) must be on the stack. All items on the stack are gone
217      * after the generated instruction has executed.
218      * <p>
219      * The type doesn't need to be an exact match for objects.
220      * TypeDesc.OBJECT works fine for all objects. For primitive types, use
221      * the appropriate TypeDesc. For an int, the type is TypeDesc.INT.
222      *
223      * @param type The type of data stored in the array.
224      */

225     void storeToArray(TypeDesc type);
226
227     // load-field-to-stack style instructions
228

229     /**
230      * Generates code that loads a value from a field from this class.
231      * An object reference must be on the stack. After the generated code
232      * has executed, the object reference is replaced by the value retrieved
233      * from the field.
234      */

235     void loadField(String JavaDoc fieldName,
236                    TypeDesc type);
237
238     /**
239      * Generates code that loads a value from a field from any class.
240      * An object reference must be on the stack. After the generated code
241      * has executed, the object reference is replaced by the value retrieved
242      * from the field.
243      */

244     void loadField(String JavaDoc className,
245                    String JavaDoc fieldName,
246                    TypeDesc type);
247
248     /**
249      * Generates code that loads a value from a field from any class.
250      * An object reference must be on the stack. After the generated code
251      * has executed, the object reference is replaced by the value retrieved
252      * from the field.
253      *
254      * @throws IllegalArgumentException if classDesc refers to an array or
255      * primitive type
256      */

257     void loadField(TypeDesc classDesc,
258                    String JavaDoc fieldName,
259                    TypeDesc type);
260
261     /**
262      * Generates code that loads a value from a static field from this class.
263      * After the generated code has executed, the value retrieved is placed
264      * on the stack.
265      */

266     void loadStaticField(String JavaDoc fieldName,
267                          TypeDesc type);
268
269     /**
270      * Generates code that loads a value from a static field from any class.
271      * After the generated code has executed, the value retrieved is placed
272      * on the stack.
273      */

274     void loadStaticField(String JavaDoc className,
275                          String JavaDoc fieldName,
276                          TypeDesc type);
277
278     /**
279      * Generates code that loads a value from a static field from any class.
280      * After the generated code has executed, the value retrieved is placed
281      * on the stack.
282      *
283      * @throws IllegalArgumentException if classDesc refers to an array or
284      * primitive type
285      */

286     void loadStaticField(TypeDesc classDesc,
287                          String JavaDoc fieldName,
288                          TypeDesc type);
289
290     // store-to-field-from-stack style instructions
291

292     /**
293      * Generates code that stores a value into a field from this class.
294      * An object reference and value must be on the stack. After the generated
295      * code has executed, the object reference and value are gone from
296      * the stack.
297      */

298     void storeField(String JavaDoc fieldName,
299                     TypeDesc type);
300
301     /**
302      * Generates code that stores a value into a field from any class.
303      * An object reference and value must be on the stack. After the generated
304      * code has executed, the object reference and value are gone from
305      * the stack.
306      */

307     void storeField(String JavaDoc className,
308                     String JavaDoc fieldName,
309                     TypeDesc type);
310
311     /**
312      * Generates code that stores a value into a field from any class.
313      * An object reference and value must be on the stack. After the generated
314      * code has executed, the object reference and value are gone from
315      * the stack.
316      *
317      * @throws IllegalArgumentException if classDesc refers to an array or
318      * primitive type
319      */

320     void storeField(TypeDesc classDesc,
321                     String JavaDoc fieldName,
322                     TypeDesc type);
323
324     /**
325      * Generates code that stores a value into a field from this class.
326      * A value must be on the stack. After the generated
327      * code has executed, the value is gone from the stack.
328      */

329     void storeStaticField(String JavaDoc fieldName,
330                           TypeDesc type);
331
332     /**
333      * Generates code that stores a value into a field from any class.
334      * A value must be on the stack. After the generated
335      * code has executed, the value is gone from the stack.
336      */

337     void storeStaticField(String JavaDoc className,
338                           String JavaDoc fieldName,
339                           TypeDesc type);
340
341     /**
342      * Generates code that stores a value into a field from any class.
343      * A value must be on the stack. After the generated
344      * code has executed, the value is gone from the stack.
345      *
346      * @throws IllegalArgumentException if classDesc refers to an array or
347      * primitive type
348      */

349     void storeStaticField(TypeDesc classDesc,
350                           String JavaDoc fieldName,
351                           TypeDesc type);
352
353     // return style instructions
354

355     /**
356      * Generates code that returns void.
357      */

358     void returnVoid();
359
360     /**
361      * Generates code that returns an object or primitive type. The value to
362      * return must be on the stack.
363      * <p>
364      * The type doesn't need to be an exact match for objects.
365      * TypeDesc.OBJECT works fine for all objects. For primitive types, use
366      * the appropriate TypeDesc. For an int, the type is TypeDesc.INT.
367      */

368     void returnValue(TypeDesc type);
369
370     // numerical conversion style instructions
371

372     /**
373      * Generates code that converts the value of a primitive type already
374      * on the stack. Conversions between all primitive types are supported as
375      * well as boxing and unboxing conversions. Some example conversions:
376      *
377      * <pre>
378      * int to char
379      * byte to double
380      * Double to double
381      * Float to boolean
382      * long to Long
383      * Double to Short
384      * </pre>
385      *
386      * In all, 240 conversions are supported.
387      *
388      * @throws IllegalArgumentException if conversion not supported
389      */

390     void convert(TypeDesc fromType, TypeDesc toType);
391
392     /**
393      * Generates code that converts the value of a primitive type already
394      * on the stack. Conversions between all primitive types are supported as
395      * well as boxing and unboxing conversions. Some example conversions:
396      *
397      * <pre>
398      * int to char
399      * byte to double
400      * Double to double
401      * Float to boolean
402      * long to Long
403      * Double to Short
404      * </pre>
405      *
406      * In all, 240 conversions are supported.
407      *
408      * @param fpConvertMode controls floating point conversion if converting
409      * float &lt;--&gt; int or double &lt;--&gt; long
410      * @throws IllegalArgumentException if conversion not supported
411      */

412     void convert(TypeDesc fromType, TypeDesc toType, int fpConvertMode);
413
414     // invocation style instructions
415

416     /**
417      * Generates code to invoke a method. If the method is static, the method's
418      * argument(s) must be on the stack. If the method is non-static, then the
419      * object reference must also be on the stack, prior to the arguments.
420      */

421     void invoke(Method JavaDoc method);
422
423     /**
424      * Generates code to invoke a virtual method in this class. The object
425      * reference and the method's argument(s) must be on the stack.
426      *
427      * @param ret May be null if method returns void.
428      * @param params May be null if method takes no parameters.
429      */

430     void invokeVirtual(String JavaDoc methodName,
431                        TypeDesc ret,
432                        TypeDesc[] params);
433
434     /**
435      * Generates code to invoke a virtual method in any class. The object
436      * reference and the method's argument(s) must be on the stack.
437      *
438      * @param ret May be null if method returns void.
439      * @param params May be null if method takes no parameters.
440      */

441     void invokeVirtual(String JavaDoc className,
442                        String JavaDoc methodName,
443                        TypeDesc ret,
444                        TypeDesc[] params);
445
446     /**
447      * Generates code to invoke a virtual method in any class. The object
448      * reference and the method's argument(s) must be on the stack.
449      *
450      * @param ret May be null if method returns void.
451      * @param params May be null if method takes no parameters.
452      * @throws IllegalArgumentException if classDesc refers to an array or
453      * primitive type
454      */

455     void invokeVirtual(TypeDesc classDesc,
456                        String JavaDoc methodName,
457                        TypeDesc ret,
458                        TypeDesc[] params);
459
460     /**
461      * Generates code to invoke a static method in this class. The method's
462      * argument(s) must be on the stack.
463      *
464      * @param ret May be null if method returns void.
465      * @param params May be null if method takes no parameters.
466      */

467     void invokeStatic(String JavaDoc methodName,
468                       TypeDesc ret,
469                       TypeDesc[] params);
470
471     /**
472      * Generates code to invoke a static method in any class. The method's
473      * argument(s) must be on the stack.
474      *
475      * @param ret May be null if method returns void.
476      * @param params May be null if method takes no parameters.
477      */

478     void invokeStatic(String JavaDoc className,
479                       String JavaDoc methodName,
480                       TypeDesc ret,
481                       TypeDesc[] params);
482
483     /**
484      * Generates code to invoke a static method in any class. The method's
485      * argument(s) must be on the stack.
486      *
487      * @param ret May be null if method returns void.
488      * @param params May be null if method takes no parameters.
489      * @throws IllegalArgumentException if classDesc refers to an array or
490      * primitive type
491      */

492     void invokeStatic(TypeDesc classDesc,
493                       String JavaDoc methodName,
494                       TypeDesc ret,
495                       TypeDesc[] params);
496
497     /**
498      * Generates code to invoke an interface method in any class. The object
499      * reference and the method's argument(s) must be on the stack.
500      *
501      * @param ret May be null if method returns void.
502      * @param params May be null if method takes no parameters.
503      */

504     void invokeInterface(String JavaDoc className,
505                          String JavaDoc methodName,
506                          TypeDesc ret,
507                          TypeDesc[] params);
508
509     /**
510      * Generates code to invoke an interface method in any class. The object
511      * reference and the method's argument(s) must be on the stack.
512      *
513      * @param ret May be null if method returns void.
514      * @param params May be null if method takes no parameters.
515      * @throws IllegalArgumentException if classDesc refers to an array or
516      * primitive type
517      */

518     void invokeInterface(TypeDesc classDesc,
519                          String JavaDoc methodName,
520                          TypeDesc ret,
521                          TypeDesc[] params);
522
523     /**
524      * Generates code to invoke a private method in this class.
525      * The object reference and the method's argument(s) must be on the stack.
526      *
527      * @param ret May be null if method returns void.
528      * @param params May be null if method takes no parameters.
529      */

530     void invokePrivate(String JavaDoc methodName,
531                        TypeDesc ret,
532                        TypeDesc[] params);
533     
534     /**
535      * Generates code to invoke a method in the super class.
536      * The object reference and the method's argument(s) must be on the stack.
537      */

538     void invokeSuper(Method JavaDoc method);
539
540     /**
541      * Generates code to invoke a method in the super class.
542      * The object reference and the method's argument(s) must be on the stack.
543      *
544      * @param ret May be null if method returns void.
545      * @param params May be null if method takes no parameters.
546      */

547     void invokeSuper(String JavaDoc superClassName,
548                      String JavaDoc methodName,
549                      TypeDesc ret,
550                      TypeDesc[] params);
551
552     /**
553      * Generates code to invoke a method in the super class.
554      * The object reference and the method's argument(s) must be on the stack.
555      *
556      * @param ret May be null if method returns void.
557      * @param params May be null if method takes no parameters.
558      * @throws IllegalArgumentException if superClassDesc refers to an array or
559      * primitive type
560      */

561     void invokeSuper(TypeDesc superClassDesc,
562                      String JavaDoc methodName,
563                      TypeDesc ret,
564                      TypeDesc[] params);
565
566     /**
567      * Generates code to invoke a class constructor in any class. The object
568      * reference and the constructor's argument(s) must be on the stack.
569      */

570     void invoke(Constructor JavaDoc constructor);
571
572     /**
573      * Generates code to invoke a class constructor in this class. The object
574      * reference and the constructor's argument(s) must be on the stack.
575      *
576      * @param params May be null if constructor takes no parameters.
577      */

578     void invokeConstructor(TypeDesc[] params);
579
580     /**
581      * Generates code to invoke a class constructor in any class. The object
582      * reference and the constructor's argument(s) must be on the stack.
583      *
584      * @param params May be null if constructor takes no parameters.
585      */

586     void invokeConstructor(String JavaDoc className, TypeDesc[] params);
587
588     /**
589      * Generates code to invoke a class constructor in any class. The object
590      * reference and the constructor's argument(s) must be on the stack.
591      *
592      * @param params May be null if constructor takes no parameters.
593      * @throws IllegalArgumentException if classDesc refers to an array or
594      * primitive type
595      */

596     void invokeConstructor(TypeDesc classDesc, TypeDesc[] params);
597
598     /**
599      * Generates code to invoke a super class constructor. The object
600      * reference and the constructor's argument(s) must be on the stack.
601      *
602      * @param params May be null if constructor takes no parameters.
603      */

604     void invokeSuperConstructor(TypeDesc[] params);
605
606     // creation style instructions
607

608     /**
609      * Generates code to create a new object. Unless the new object is an
610      * array, it is invalid until a constructor method is invoked on it.
611      * <p>
612      * If the specified type is an array, this call is equivalent to
613      * newObject(type, 1). The size of the dimension must be on the operand
614      * stack. To create multi-dimensional arrays, call
615      * newObject(type, dimensions).
616      *
617      * @see #invokeConstructor
618      */

619     void newObject(TypeDesc type);
620
621     /**
622      * Generates code to create a new array. The type descriptor specifies
623      * the type of array to create. The dimensions parameter specifies the
624      * amount of dimensions that will initialized, which may not be larger than
625      * the amount of dimensions specified in the type.
626      * <p>
627      * For each dimension, its size must be on the operand stack. If the
628      * specified dimensions is 0 and the type is not an array, then this call
629      * is equivalent to newObject(type).
630      */

631     void newObject(TypeDesc type, int dimensions);
632
633     // stack operation style instructions
634

635     /**
636      * Generates code for the dup instruction.
637      */

638     void dup();
639
640     /**
641      * Generates code for the dup_x1 instruction.
642      */

643     void dupX1();
644
645     /**
646      * Generates code for the dup_x2 instruction.
647      */

648     void dupX2();
649
650     /**
651      * Generates code for the dup2 instruction.
652      */

653     void dup2();
654
655     /**
656      * Generates code for the dup2_x1 instruction.
657      */

658     void dup2X1();
659
660     /**
661      * Generates code for the dup2_x2 instruction.
662      */

663     void dup2X2();
664
665     /**
666      * Generates code for the pop instruction.
667      */

668     void pop();
669
670     /**
671      * Generates code for the pop2 instruction.
672      */

673     void pop2();
674
675     /**
676      * Generates code for the swap instruction.
677      */

678     void swap();
679
680     /**
681      * Generates code for a swap2 instruction.
682      */

683     void swap2();
684
685     // flow control instructions
686

687     /**
688      * Generates code that performs an unconditional branch to the specified
689      * location.
690      *
691      * @param location The location to branch to
692      */

693     void branch(Location location);
694
695     /**
696      * Generates code that performs a conditional branch based on the
697      * value of an object on the stack. A branch is performed based on whether
698      * the object reference on the stack is null or not.
699      *
700      * <p>The generated instruction consumes the value on the stack.
701      *
702      * @param location The location to branch to
703      * @param choice If true, do branch when null, else branch when not null
704      */

705     void ifNullBranch(Location location, boolean choice);
706
707     /**
708      * Generates code that performs a conditional branch based on the value of
709      * two object references on the stack. A branch is performed based on
710      * whether the two objects are exactly the same.
711      *
712      * <p>The generated instruction consumes the two values on the stack.
713      *
714      * @param location The location to branch to
715      * @param choice If true, branch when equal, else branch when not equal
716      */

717     void ifEqualBranch(Location location, boolean choice);
718
719     /**
720      * Generates code the performs a conditional branch based on a comparison
721      * between an int value on the stack and zero. The int value on the
722      * stack is on the left side of the comparison expression.
723      *
724      * <p>The generated instruction consumes the value on the stack.
725      *
726      * @param location The location to branch to
727      * @param choice One of "==", "!=", "<", ">=", ">" or "<="
728      * @throws IllegalArgumentException When the choice is not valid
729      */

730     void ifZeroComparisonBranch(Location location, String JavaDoc choice)
731         throws IllegalArgumentException JavaDoc;
732
733     /**
734      * Generates code the performs a conditional branch based on a comparison
735      * between two int values on the stack. The first int value on the stack
736      * is on the left side of the comparison expression.
737      *
738      * <p>The generated instruction consumes the two values on the stack.
739      *
740      * @param location The location to branch to
741      * @param choice One of "==", "!=", "<", ">=", ">" or "<="
742      * @throws IllegalArgumentException When the choice is not valid
743      */

744     void ifComparisonBranch(Location location, String JavaDoc choice)
745         throws IllegalArgumentException JavaDoc;
746
747     /**
748      * Generates code the performs a conditional branch based on a comparison
749      * between two values of the given type on the stack. The first int value
750      * on the stack is on the left side of the comparison expression. When
751      * comparing objects, only an identity comparison is performed.
752      *
753      * <p>When comparing floating point values, treatment of NaN requires
754      * special attention. Ordinarily, it is assumed that the branch location
755      * represents the target of a comparison failure, and that the code to
756      * handle the "true" condition immediately follows the comparison. If this
757      * is not the case, append a 't' suffix to the choice to indicate that the
758      * target location is reached for a "true" condition. This suffix is
759      * ignored if the type is not a float or double.
760      *
761      * <p>The generated instruction(s) consumes the two values on the stack.
762      *
763      * @param location The location to branch to
764
765      * @param choice One of "==", "!=", "<", ">=", ">", "<=", "==t", "!=t",
766      * "<t", ">=t", ">t", or "<=t". Object types can only be compared for
767      * equality.
768      * @param type Type to expect on the stack
769      * @throws IllegalArgumentException When the choice is not valid
770      */

771     void ifComparisonBranch(Location location, String JavaDoc choice, TypeDesc type)
772         throws IllegalArgumentException JavaDoc;
773
774     /**
775      * Generates code for a switch statement. The generated code is either a
776      * lookupswitch or tableswitch. The choice of which switch type to generate
777      * is made based on the amount of bytes to be generated. A tableswitch
778      * is usually smaller, unless the cases are sparse.
779      *
780      * <p>The key value to switch on must already be on the stack when this
781      * instruction executes. It is consumed by the instruction.
782      *
783      * @param cases The values to match on. The array length must be the same
784      * as for locations.
785      * @param locations The locations to branch to for each case.
786      * The array length must be the same as for cases.
787      * @param defaultLocation The location to branch to if the key on
788      * the stack was not matched.
789      */

790     void switchBranch(int[] cases,
791                       Location[] locations, Location defaultLocation);
792
793     /**
794      * Generates code that performs a subroutine branch to the specified
795      * location. The instruction generated is either jsr or jsr_w. It is most
796      * often used for implementing a finally block.
797      *
798      * @param location The location to branch to
799      */

800     void jsr(Location location);
801
802     /**
803      * Generates code that returns from a subroutine invoked by jsr.
804      *
805      * @param local The local variable reference that contains the return
806      * address. The local variable must be of an object type.
807      */

808     void ret(LocalVariable local);
809
810     // math instructions
811

812     /**
813      * Generates code for either a unary or binary math operation on one
814      * or two values pushed on the stack.
815      * <p>
816      * Pass in an opcode from the the Opcode class. The only valid math
817      * opcodes are:
818      *
819      * <pre>
820      * IADD, ISUB, IMUL, IDIV, IREM, INEG, IAND, IOR, IXOR, ISHL, ISHR, IUSHR
821      * LADD, LSUB, LMUL, LDIV, LREM, LNEG, LAND, LOR, LXOR, LSHL, LSHR, LUSHR
822      * FADD, FSUB, FMUL, FDIV, FREM, FNEG
823      * DADD, DSUB, DMUL, DDIV, DREM, DNEG
824      *
825      * LCMP
826      * FCMPG, FCMPL
827      * DCMPG, DCMPL
828      * </pre>
829      *
830      * A not operation (~) is performed by doing a loadConstant with either
831      * -1 or -1L followed by math(Opcode.IXOR) or math(Opcode.LXOR).
832      *
833      * @param opcode An opcode from the Opcode class.
834      * @throws IllegalArgumentException When the opcode selected is not
835      * a math operation.
836      * @see Opcode
837      */

838     void math(byte opcode);
839
840     // miscellaneous instructions
841

842     /**
843      * Generates code for an arraylength instruction. The object to get the
844      * length from must already be on the stack.
845      */

846     void arrayLength();
847
848     /**
849      * Generates code that throws an exception. The object to throw must
850      * already be on the stack.
851      */

852     void throwObject();
853
854     /**
855      * Generates code that performs an object cast operation. The object
856      * to check must already be on the stack.
857      */

858     void checkCast(TypeDesc type);
859
860     /**
861      * Generates code that performs an instanceof operation. The object to
862      * check must already be on the stack.
863      */

864     void instanceOf(TypeDesc type);
865
866     /**
867      * Generates code that increments a local integer variable by a signed
868      * constant amount.
869      */

870     void integerIncrement(LocalVariable local, int amount);
871
872     /**
873      * Generates code to enter the monitor on an object loaded on the stack.
874      */

875     void monitorEnter();
876
877     /**
878      * Generates code to exit the monitor on an object loaded on the stack.
879      */

880     void monitorExit();
881
882     /**
883      * Generates an instruction that does nothing. (No-OPeration)
884      */

885     void nop();
886
887     /**
888      * Generates a breakpoint instruction for use in a debugging environment.
889      */

890     void breakpoint();
891 }
892
Popular Tags