Interface TypeConversions
- All Superinterfaces:
org.objectweb.asm.Opcodes
These conversions are no more than bitwise casts. The underlying bits are unchanged, but the interpretation and/or the way the JVM has tagged them does.
Many of the methods (and also many other bits of the code generator) follow a convention where the input type(s) are passed as parameter(s), and the resulting type is returned. In many cases the desired type is also taken as a parameter. Upon success, we'd expect that desired type to be the exact type returned, but this may not always be the case. This convention ensures all pieces of the generator know the p-code type (and thus JVM type) of the variable at the top of the JVM stack.
Type conversions are applicable at a few boundaries:
- To ensure use-def values conform to the requirements of the operands where they are used and
defined. The
JitTypeModelaims to reduce the number of conversions required by assigning appropriate types to the use-def value nodes, but this will not necessarily eliminate them all. - Within the implementation of an operator, type conversions may be necessary to ensure the p-code types of input operands conform with the JVM types required by the emitted bytecodes, and that the output JVM type conforms to the p-code type of the output operand.
- When loading or storing as bytes from the
state. The conversion from and to bytes is done using JVM integral types, and so the value may be converted if the operand requires a floating-point type.
-
Field Summary
Fields inherited from interface org.objectweb.asm.Opcodes
AALOAD, AASTORE, ACC_ABSTRACT, ACC_ANNOTATION, ACC_BRIDGE, ACC_DEPRECATED, ACC_ENUM, ACC_FINAL, ACC_INTERFACE, ACC_MANDATED, ACC_MODULE, ACC_NATIVE, ACC_OPEN, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_RECORD, ACC_STATIC, ACC_STATIC_PHASE, ACC_STRICT, ACC_SUPER, ACC_SYNCHRONIZED, ACC_SYNTHETIC, ACC_TRANSIENT, ACC_TRANSITIVE, ACC_VARARGS, ACC_VOLATILE, ACONST_NULL, ALOAD, ANEWARRAY, ARETURN, ARRAYLENGTH, ASM10_EXPERIMENTAL, ASM4, ASM5, ASM6, ASM7, ASM8, ASM9, ASTORE, ATHROW, BALOAD, BASTORE, BIPUSH, CALOAD, CASTORE, CHECKCAST, D2F, D2I, D2L, DADD, DALOAD, DASTORE, DCMPG, DCMPL, DCONST_0, DCONST_1, DDIV, DLOAD, DMUL, DNEG, DOUBLE, DREM, DRETURN, DSTORE, DSUB, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, F_APPEND, F_CHOP, F_FULL, F_NEW, F_SAME, F_SAME1, F2D, F2I, F2L, FADD, FALOAD, FASTORE, FCMPG, FCMPL, FCONST_0, FCONST_1, FCONST_2, FDIV, FLOAD, FLOAT, FMUL, FNEG, FREM, FRETURN, FSTORE, FSUB, GETFIELD, GETSTATIC, GOTO, H_GETFIELD, H_GETSTATIC, H_INVOKEINTERFACE, H_INVOKESPECIAL, H_INVOKESTATIC, H_INVOKEVIRTUAL, H_NEWINVOKESPECIAL, H_PUTFIELD, H_PUTSTATIC, I2B, I2C, I2D, I2F, I2L, I2S, IADD, IALOAD, IAND, IASTORE, ICONST_0, ICONST_1, ICONST_2, ICONST_3, ICONST_4, ICONST_5, ICONST_M1, IDIV, IF_ACMPEQ, IF_ACMPNE, IF_ICMPEQ, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ICMPLT, IF_ICMPNE, IFEQ, IFGE, IFGT, IFLE, IFLT, IFNE, IFNONNULL, IFNULL, IINC, ILOAD, IMUL, INEG, INSTANCEOF, INTEGER, INVOKEDYNAMIC, INVOKEINTERFACE, INVOKESPECIAL, INVOKESTATIC, INVOKEVIRTUAL, IOR, IREM, IRETURN, ISHL, ISHR, ISTORE, ISUB, IUSHR, IXOR, JSR, L2D, L2F, L2I, LADD, LALOAD, LAND, LASTORE, LCMP, LCONST_0, LCONST_1, LDC, LDIV, LLOAD, LMUL, LNEG, LONG, LOOKUPSWITCH, LOR, LREM, LRETURN, LSHL, LSHR, LSTORE, LSUB, LUSHR, LXOR, MONITORENTER, MONITOREXIT, MULTIANEWARRAY, NEW, NEWARRAY, NOP, NULL, POP, POP2, PUTFIELD, PUTSTATIC, RET, RETURN, SALOAD, SASTORE, SIPUSH, SOURCE_DEPRECATED, SOURCE_MASK, SWAP, T_BOOLEAN, T_BYTE, T_CHAR, T_DOUBLE, T_FLOAT, T_INT, T_LONG, T_SHORT, TABLESWITCH, TOP, UNINITIALIZED_THIS, V_PREVIEW, V1_1, V1_2, V1_3, V1_4, V1_5, V1_6, V1_7, V1_8, V10, V11, V12, V13, V14, V15, V16, V17, V18, V19, V20, V21, V22, V23, V24, V9 -
Method Summary
Static MethodsModifier and TypeMethodDescriptionstatic voidcheckGenIntMask(JitType from, JitType.IntJitType to, org.objectweb.asm.MethodVisitor mv) Emit anOpcodes.IANDto reduce the number of bits to those permitted in an int of the given size.static voidcheckGenLongMask(JitType from, JitType.LongJitType to, org.objectweb.asm.MethodVisitor mv) Emit anOpcodes.LANDto reduce the number of bits to those permitted in an int of the given size.static JitTypeforceUniformSExt(JitType myType, JitType otherType, org.objectweb.asm.MethodVisitor mv) Do the same asforceUniformZExt(JitType, JitType, MethodVisitor), but with signed values.static JitTypeforceUniformZExt(JitType myType, JitType otherType, org.objectweb.asm.MethodVisitor mv) Select the larger of two types and emit code to convert an unsigned value of the first type to the host JVM type of the selected type.static JitTypegenerate(JitCodeGenerator gen, JitType from, JitType to, org.objectweb.asm.MethodVisitor mv) Emit bytecode to convert the value on top of the JVM stack from one p-code type to another.static JitType.LongJitTypegenerateDoubleToLong(JitType.DoubleJitType from, JitType.LongJitType to, org.objectweb.asm.MethodVisitor mv) static JitType.IntJitTypegenerateFloatToInt(JitType.FloatJitType from, JitType.IntJitType to, org.objectweb.asm.MethodVisitor mv) static voidgenerateIntToBool(JitType from, org.objectweb.asm.MethodVisitor mv) Collapse an mp-int or long to a single int.static JitType.FloatJitTypegenerateIntToFloat(JitType.IntJitType from, JitType.FloatJitType to, org.objectweb.asm.MethodVisitor mv) static JitType.IntJitTypegenerateIntToInt(JitType.IntJitType from, JitType.IntJitType to, org.objectweb.asm.MethodVisitor mv) Emit bytecode to convert one p-code in (in a JVM int) to anotherstatic JitType.LongJitTypegenerateIntToLong(JitType.IntJitType from, JitType.LongJitType to, org.objectweb.asm.MethodVisitor mv) Emit bytecode to convert one p-code int (in a JVM int) to one in a JVM long.static JitType.MpIntJitTypegenerateIntToMpInt(JitType.IntJitType from, JitType.MpIntJitType to, org.objectweb.asm.MethodVisitor mv) Emit bytecode to convert a p-code int that fits in a JVM int to a multi-precision int.static voidgenerateLdcFalse(JitType type, org.objectweb.asm.MethodVisitor mv) Generate a "boolean" false value of the given typestatic voidgenerateLdcTrue(JitType type, org.objectweb.asm.MethodVisitor mv) Generate a "boolean" true value of the given typestatic JitType.DoubleJitTypegenerateLongToDouble(JitType.LongJitType from, JitType.DoubleJitType to, org.objectweb.asm.MethodVisitor mv) static JitType.IntJitTypegenerateLongToInt(JitType.LongJitType from, JitType.IntJitType to, org.objectweb.asm.MethodVisitor mv) Emit bytecode to convert one p-code int (in a JVM long) to one in a JVM int.static JitType.LongJitTypegenerateLongToLong(JitType.LongJitType from, JitType.LongJitType to, org.objectweb.asm.MethodVisitor mv) Emit bytecode to convert one p-code in (in a JVM long) to anotherstatic JitType.MpIntJitTypegenerateLongToMpInt(JitType.LongJitType from, JitType.MpIntJitType to, org.objectweb.asm.MethodVisitor mv) Emit bytecode to convert a p-code int that its int a JVM long to multi-precision int.static JitType.IntJitTypegenerateMpIntToInt(JitType.MpIntJitType from, JitType.IntJitType to, org.objectweb.asm.MethodVisitor mv) Emit bytecode to convert a mult-precision int to a p-code int that fits in a JVM int.static JitType.LongJitTypegenerateMpIntToLong(JitType.MpIntJitType from, JitType.LongJitType to, org.objectweb.asm.MethodVisitor mv) Emit bytecode to convert a mult-precision int to a p-code int that fits in a JVM long.static JitType.MpIntJitTypegenerateMpIntToMpInt(JitCodeGenerator gen, JitType.MpIntJitType from, JitType.MpIntJitType to, org.objectweb.asm.MethodVisitor mv) Emit bytecode to convert a mult-precision int from one size to anotherstatic voidgeneratePop(JitType type, org.objectweb.asm.MethodVisitor mv) Remove a value of the given type from the JVM stack.static JitTypegenerateSExt(JitType type, org.objectweb.asm.MethodVisitor mv) Emit code to extend a signed value of the given type to fill its host JVM type.static JitType.LongJitTypegenerateSExtIntToLong(org.objectweb.asm.MethodVisitor mv) static JitType.DoubleJitTypegenerateToDouble(JitType from, JitType.DoubleJitType to, org.objectweb.asm.MethodVisitor mv) Emit bytecode to convert any (compatible) type to afloat8.static JitType.FloatJitTypegenerateToFloat(JitType from, JitType.FloatJitType to, org.objectweb.asm.MethodVisitor mv) Emit bytecode to convert any (compatible) type to afloat4.static JitType.IntJitTypegenerateToInt(JitType from, JitType.IntJitType to, org.objectweb.asm.MethodVisitor mv) Emit bytecode to convert any (compatible) type to a p-code int that fits in a JVM int.static JitType.LongJitTypegenerateToLong(JitType from, JitType.LongJitType to, org.objectweb.asm.MethodVisitor mv) Emit bytecode to convert any (compatible) type to a p-code that fits in a JVM long.static JitType.MpIntJitTypegenerateToMpInt(JitCodeGenerator gen, JitType from, JitType.MpIntJitType to, org.objectweb.asm.MethodVisitor mv) Emit bytecode to convert any (compatible) type to a p-code int that fits in a JVM int.
-
Method Details
-
checkGenIntMask
static void checkGenIntMask(JitType from, JitType.IntJitType to, org.objectweb.asm.MethodVisitor mv) Emit anOpcodes.IANDto reduce the number of bits to those permitted in an int of the given size.For example to mask from an
int4to anJitType.IntJitType.I2, this would emitiand 0xffff. If the source size is smaller than or equal to that of the destination, nothing is emitted.- Parameters:
from- the source typeto- the destination typemv- the method visitor
-
generateIntToInt
static JitType.IntJitType generateIntToInt(JitType.IntJitType from, JitType.IntJitType to, org.objectweb.asm.MethodVisitor mv) Emit bytecode to convert one p-code in (in a JVM int) to another- Parameters:
from- the source typeto- the destination typemv- the method visitor- Returns:
- the destination type
-
generateLongToInt
static JitType.IntJitType generateLongToInt(JitType.LongJitType from, JitType.IntJitType to, org.objectweb.asm.MethodVisitor mv) Emit bytecode to convert one p-code int (in a JVM long) to one in a JVM int.- Parameters:
from- the source typeto- the destination typemv- the method visitor- Returns:
- the destination type
-
generateFloatToInt
static JitType.IntJitType generateFloatToInt(JitType.FloatJitType from, JitType.IntJitType to, org.objectweb.asm.MethodVisitor mv) -
generateMpIntToInt
static JitType.IntJitType generateMpIntToInt(JitType.MpIntJitType from, JitType.IntJitType to, org.objectweb.asm.MethodVisitor mv) Emit bytecode to convert a mult-precision int to a p-code int that fits in a JVM int.- Parameters:
from- the source typeto- the destination typemv- the method visitor- Returns:
- the destination type
-
generateToInt
static JitType.IntJitType generateToInt(JitType from, JitType.IntJitType to, org.objectweb.asm.MethodVisitor mv) Emit bytecode to convert any (compatible) type to a p-code int that fits in a JVM int.The only acceptable floating-point source type is
float4.- Parameters:
from- the source typeto- the destination typemv- the method visitor- Returns:
- the destination type
-
checkGenLongMask
static void checkGenLongMask(JitType from, JitType.LongJitType to, org.objectweb.asm.MethodVisitor mv) Emit anOpcodes.LANDto reduce the number of bits to those permitted in an int of the given size.For example to mask from a
int8to aJitType.LongJitType.I6, this would emitland 0x0ffffffffffffL. If the source size is smaller than or equal to that of the destination, nothing is emitted.- Parameters:
from- the source typeto- the destination typemv- the method visitor
-
generateIntToLong
static JitType.LongJitType generateIntToLong(JitType.IntJitType from, JitType.LongJitType to, org.objectweb.asm.MethodVisitor mv) Emit bytecode to convert one p-code int (in a JVM int) to one in a JVM long.Care must be taken to ensure conversions to larger types extend with zeros (unsigned).
- Parameters:
from- the source typeto- the destination typemv- the method visitor- Returns:
- the destination type
-
generateLongToLong
static JitType.LongJitType generateLongToLong(JitType.LongJitType from, JitType.LongJitType to, org.objectweb.asm.MethodVisitor mv) Emit bytecode to convert one p-code in (in a JVM long) to another- Parameters:
from- the source typeto- the destination typemv- the method visitor- Returns:
- the destination type
-
generateDoubleToLong
static JitType.LongJitType generateDoubleToLong(JitType.DoubleJitType from, JitType.LongJitType to, org.objectweb.asm.MethodVisitor mv) -
generateMpIntToLong
static JitType.LongJitType generateMpIntToLong(JitType.MpIntJitType from, JitType.LongJitType to, org.objectweb.asm.MethodVisitor mv) Emit bytecode to convert a mult-precision int to a p-code int that fits in a JVM long.- Parameters:
from- the source typeto- the destination typemv- the method visitor- Returns:
- the destination type
-
generateToLong
static JitType.LongJitType generateToLong(JitType from, JitType.LongJitType to, org.objectweb.asm.MethodVisitor mv) Emit bytecode to convert any (compatible) type to a p-code that fits in a JVM long.The only acceptable floating-point source type is
float8.- Parameters:
from- the source typeto- the destination typemv- the method visitor- Returns:
- the destination type
-
generateIntToFloat
static JitType.FloatJitType generateIntToFloat(JitType.IntJitType from, JitType.FloatJitType to, org.objectweb.asm.MethodVisitor mv) -
generateToFloat
static JitType.FloatJitType generateToFloat(JitType from, JitType.FloatJitType to, org.objectweb.asm.MethodVisitor mv) Emit bytecode to convert any (compatible) type to afloat4. -
generateLongToDouble
static JitType.DoubleJitType generateLongToDouble(JitType.LongJitType from, JitType.DoubleJitType to, org.objectweb.asm.MethodVisitor mv) -
generateToDouble
static JitType.DoubleJitType generateToDouble(JitType from, JitType.DoubleJitType to, org.objectweb.asm.MethodVisitor mv) Emit bytecode to convert any (compatible) type to afloat8. -
generateIntToMpInt
static JitType.MpIntJitType generateIntToMpInt(JitType.IntJitType from, JitType.MpIntJitType to, org.objectweb.asm.MethodVisitor mv) Emit bytecode to convert a p-code int that fits in a JVM int to a multi-precision int.- Parameters:
from- the source typeto- the destination typemv- the method visitor- Returns:
- the destination type
-
generateLongToMpInt
static JitType.MpIntJitType generateLongToMpInt(JitType.LongJitType from, JitType.MpIntJitType to, org.objectweb.asm.MethodVisitor mv) Emit bytecode to convert a p-code int that its int a JVM long to multi-precision int.- Parameters:
from- the source typeto- the destination typemv- the method visitor- Returns:
- the destination type
-
generateMpIntToMpInt
static JitType.MpIntJitType generateMpIntToMpInt(JitCodeGenerator gen, JitType.MpIntJitType from, JitType.MpIntJitType to, org.objectweb.asm.MethodVisitor mv) Emit bytecode to convert a mult-precision int from one size to another- Parameters:
gen- the code generatorfrom- the source typeto- the destination typemv- the method visitor- Returns:
- the destination type
-
generateToMpInt
static JitType.MpIntJitType generateToMpInt(JitCodeGenerator gen, JitType from, JitType.MpIntJitType to, org.objectweb.asm.MethodVisitor mv) Emit bytecode to convert any (compatible) type to a p-code int that fits in a JVM int.No floating-point source types are currently acceptable. Support for floats of size other than 4 and 8 bytes is a work in progress.
- Parameters:
gen- the code generatorfrom- the source typeto- the destination typemv- the method visitor- Returns:
- the destination type
-
generate
static JitType generate(JitCodeGenerator gen, JitType from, JitType to, org.objectweb.asm.MethodVisitor mv) Emit bytecode to convert the value on top of the JVM stack from one p-code type to another.If the source and destination are already of the same type, or if conversion between them does not require any bytecode, then no bytecode is emitted.
- Parameters:
gen- the code generatorfrom- the source typeto- the destination typemv- the method visitor- Returns:
- the resulting (destination) type
-
generateIntToBool
Collapse an mp-int or long to a single int.If and only if the input is all zeros will the output also be all zeros. Otherwise, the output can be any non-zero value.
There is no explicit "
boolean" p-code type. Instead, like C, many of the operators take aninttype and require "false" to be represented by the value 0. Any non-zero value is interpreted as "true." That said, conventionally, all p-code booleans ought to be anint1where "true" is represented by 1 and "false" is represented by 0. The p-code operators that output "boolean" values are all implemented to follow this convention, except that size is determined by the Slaspec author.This conversion deals with input operands used as booleans that do not conform to these conventions. If, e.g., a
cbranchis given a condition operand of typeint8, we have to ensure that all bits, not just the lower 32, are considered. This is trivially accomplished by pushing0Land emitting anOpcodes.LCMP, which consumes the JVM long and replaces it with a JVM int representing the same boolean value. For multi-precision ints, we reduce all the legs usingOpcodes.IOR. If a float is used as a boolean, it must be converted to an int first.- Parameters:
from- the type of the value currently on the stackmv- the method visitor- See Also:
-
generatePop
Remove a value of the given type from the JVM stack.Depending on the type, we must emit either
Opcodes.POPorOpcodes.POP2. This is used to ignore an input or drop an output. For example, the boolean operators may short circuit examination of the second operand, in which case it must be popped. Also, if a userop returns a value, but the p-code does not provide an output operand, the return value must be popped.- Parameters:
type- the typemv- the method visitor
-
generateLdcTrue
Generate a "boolean" true value of the given typeThis performs the inverse of
generateIntToBool(JitType, MethodVisitor), but for the constant "true." Instead of loading a constant 1 into anint1and then converting to the desired type, this can just load the constant 1 directly as the desired type.This is often used with conditional jumps to produce a boolean output.
- Parameters:
type- an integer typemv- the method visitor- See Also:
-
generateLdcFalse
Generate a "boolean" false value of the given typeThis performs the inverse of
generateIntToBool(JitType, MethodVisitor), but for the constant "false." Instead of loading a constant 0 into anint1and then converting to the desired type, this can just load the constant 0 directly as the desired type.This is often used with conditional jumps to produce a boolean output.
- Parameters:
type- an integer typemv- the method visitor- See Also:
-
generateSExt
Emit code to extend a signed value of the given type to fill its host JVM type.This is implemented in the same manner as
int_sext.- Parameters:
type- the p-code typemv- the method visitor- Returns:
- the p-code type that exactly fits the host JVM type, i.e., the resulting p-code type.
-
generateSExtIntToLong
Convert a signedint4toint8.Note that if conversion from a smaller int type is needed, the generator must first call
generateSExt(JitType, MethodVisitor).- Parameters:
mv- the method visitor- Returns:
- the resulting type (
int8)
-
forceUniformZExt
static JitType forceUniformZExt(JitType myType, JitType otherType, org.objectweb.asm.MethodVisitor mv) Select the larger of two types and emit code to convert an unsigned value of the first type to the host JVM type of the selected type.JVM bytecodes for binary operators often require that both operands have the same size. Consider that the JVM provides a
Opcodes.IADDand aOpcodes.LADD, but no "ILADD". Both operands must be JVM ints, or both must be JVM longs. This method provides an idiom for converting both operands to the same type. Ideally, we choose the smallest type possible (as opposed to just converting everything to long always), but we must choose a type large enough to accommodate the larger of the two p-code operands.For a binary operator requiring type uniformity, we must apply this method immediately after loading each operand onto the stack. That operand's type is passed as
myTypeand the type of the other operand asotherType. Consider the left operand. We must overrideafterLeftif we're usingBinOpGen. If the left type is the larger, then we select it and we need only extend the left operand to fill its host JVM type. (We'll deal with the right operand in a moment.) If the right type is larger, then we select it and we extend the left to fill the right's host JVM type. We then return the resulting left type so that we'll know what it was when emitting the actual operator bytecodes. Things work similarly for the right operand, which we handle withingenerateBinOpRunCodeif we're using it. The two resulting types should now be equal, and we can examine them and emit the correct bytecodes.- Parameters:
myType- the type of an operand, probably in a binary operatorotherType- the type of the other operand of a binary operatormv- the method visitor- Returns:
- the new type of the operand
-
forceUniformSExt
static JitType forceUniformSExt(JitType myType, JitType otherType, org.objectweb.asm.MethodVisitor mv) Do the same asforceUniformZExt(JitType, JitType, MethodVisitor), but with signed values.- Parameters:
myType- the type of an operand, probably in a binary operatorotherType- the type of the other operand of a binary operatormv- the method visitor- Returns:
- the new type of the operand
-