< prev index next >

## src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java

Print this page

     920         }
     921
     922         // return statement
     923         emitReturn(onStack);
     924
     925         methodEpilogue();
     926     }
     927
     928     /*
     929      * @throws BytecodeGenerationException if something goes wrong when
     930      *         generating the byte code
     931      */
     932     private byte[] toByteArray() {
     933         try {
     934             return cw.toByteArray();
     935         } catch (RuntimeException e) {
     936             throw new BytecodeGenerationException(e);
     937         }
     938     }
     939

     940     @SuppressWarnings("serial")
     941     static final class BytecodeGenerationException extends RuntimeException {
     942         BytecodeGenerationException(Exception cause) {
     943             super(cause);
     944         }
     945     }
     946
     947     void emitArrayLoad(Name name)   { emitArrayOp(name, Opcodes.AALOAD);      }
     948     void emitArrayStore(Name name)  { emitArrayOp(name, Opcodes.AASTORE);     }
     949     void emitArrayLength(Name name) { emitArrayOp(name, Opcodes.ARRAYLENGTH); }
     950
     951     void emitArrayOp(Name name, int arrayOpcode) {
     952         assert arrayOpcode == Opcodes.AALOAD || arrayOpcode == Opcodes.AASTORE || arrayOpcode == Opcodes.ARRAYLENGTH;
     953         Class<?> elementType = name.function.methodType().parameterType(0).getComponentType();
     954         assert elementType != null;
     955         emitPushArguments(name, 0);
     956         if (arrayOpcode != Opcodes.ARRAYLENGTH && elementType.isPrimitive()) {
     957             Wrapper w = Wrapper.forPrimitiveType(elementType);
     958             arrayOpcode = arrayInsnOpcode(arrayTypeCode(w), arrayOpcode);
     959         }
     920         }
     921
     922         // return statement
     923         emitReturn(onStack);
     924
     925         methodEpilogue();
     926     }
     927
     928     /*
     929      * @throws BytecodeGenerationException if something goes wrong when
     930      *         generating the byte code
     931      */
     932     private byte[] toByteArray() {
     933         try {
     934             return cw.toByteArray();
     935         } catch (RuntimeException e) {
     936             throw new BytecodeGenerationException(e);
     937         }
     938     }
     939
     940     /**
     941      * The BytecodeGenerationException.
     942      */
     943     @SuppressWarnings("serial")
     944     static final class BytecodeGenerationException extends RuntimeException {
     945         BytecodeGenerationException(Exception cause) {
     946             super(cause);
     947         }
     948     }
     949
     950     void emitArrayLoad(Name name)   { emitArrayOp(name, Opcodes.AALOAD);      }
     951     void emitArrayStore(Name name)  { emitArrayOp(name, Opcodes.AASTORE);     }
     952     void emitArrayLength(Name name) { emitArrayOp(name, Opcodes.ARRAYLENGTH); }
     953
     954     void emitArrayOp(Name name, int arrayOpcode) {
     955         assert arrayOpcode == Opcodes.AALOAD || arrayOpcode == Opcodes.AASTORE || arrayOpcode == Opcodes.ARRAYLENGTH;
     956         Class<?> elementType = name.function.methodType().parameterType(0).getComponentType();
     957         assert elementType != null;
     958         emitPushArguments(name, 0);
     959         if (arrayOpcode != Opcodes.ARRAYLENGTH && elementType.isPrimitive()) {
     960             Wrapper w = Wrapper.forPrimitiveType(elementType);
     961             arrayOpcode = arrayInsnOpcode(arrayTypeCode(w), arrayOpcode);
     962         }

< prev index next >