ClassBType

final class ClassBType(val internalName: String) extends RefBType

A ClassBType represents a class or interface type. The necessary information to build a ClassBType is extracted from compiler symbols and types, see BTypesFromSymbols.

The offset and length fields are used to represent the internal name of the class. They are indices into some character array. The internal name can be obtained through the method internalNameString, which is abstract in this component. Name creation is assumed to be hash-consed, so if two ClassBTypes have the same internal name, they NEED to have the same offset and length.

The actual implementation in subclass BTypesFromSymbols uses the global chrs array from the name table. This representation is efficient because the JVM class name is obtained through classSymbol.javaBinaryName. This already adds the necessary string to the chrs array, so it makes sense to reuse the same name table in the backend.

ClassBType is not a case class because we want a custom equals method, and because the extractor extracts the internalName, which is what you typically need.

Companion:
object
trait RefBType
trait BType
class Object
trait Matchable
class Any

Value members

Concrete methods

override def equals(o: Any): Boolean

Custom equals / hashCode: we only compare the name (offset / length)

Custom equals / hashCode: we only compare the name (offset / length)

Definition Classes
Any
override def hashCode: Int

Calculate a hash code value for the object.

Calculate a hash code value for the object.

The default hashing algorithm is platform dependent.

Note that it is allowed for two objects to have identical hash codes (o1.hashCode.equals(o2.hashCode)) yet not be equal (o1.equals(o2) returns false). A degenerate implementation could always return 0. However, it is required that if two objects are equal (o1.equals(o2) returns true) that they have identical hash codes (o1.hashCode.equals(o2.hashCode)). Therefore, when overriding this method, be sure to verify that the behavior is consistent with the equals method.

Returns:

the hash code value for this object.

Definition Classes
Any

Finding the least upper bound in agreement with the bytecode verifier Background: http://gallium.inria.fr/~xleroy/publi/bytecode-verification-JAR.pdf http://comments.gmane.org/gmane.comp.java.vm.languages/2293 https://issues.scala-lang.org/browse/SI-3872

Returns:

The class name without the package prefix

Inherited methods

Inherited from:
BType
Inherited from:
BType
Inherited from:
BType

The class or array type of this reference type. Used for ANEWARRAY, MULTIANEWARRAY, INSTANCEOF and CHECKCAST instructions. Also used for emitting invokevirtual calls to (a: Array[T]).clone() for any T, see genApply.

The class or array type of this reference type. Used for ANEWARRAY, MULTIANEWARRAY, INSTANCEOF and CHECKCAST instructions. Also used for emitting invokevirtual calls to (a: Array[T]).clone() for any T, see genApply.

In contrast to the descriptor, this string does not contain the surrounding 'L' and ';' for class types, for example "java/lang/String". However, for array types, the full descriptor is used, for example "[Ljava/lang/String;".

This can be verified for example using javap or ASMifier.

Inherited from:
RefBType
final def conformsTo(other: BType): Boolean
Inherited from:
BType
final def descriptor: String
Returns:

The Java descriptor of this type. Examples:

  • int: I
  • java.lang.String: Ljava/lang/String;
  • int[]: [I
  • Object m(String s, double d): (Ljava/lang/String;D)Ljava/lang/Object;
Inherited from:
BType
final def isArray: Boolean
Inherited from:
BType
final def isBoxed: Boolean
Inherited from:
BType
final def isClass: Boolean
Inherited from:
BType
Inherited from:
BType
Inherited from:
BType
final def isMethod: Boolean
Inherited from:
BType
Inherited from:
BType
Inherited from:
BType
final def isNullType: Boolean
Inherited from:
BType
Inherited from:
BType
final def isPrimitive: Boolean
Inherited from:
BType
final def isRealType: Boolean
Inherited from:
BType
final def isRef: Boolean
Inherited from:
BType
final def isWideType: Boolean
Inherited from:
BType
final def maxType(other: BType): BType

Compute the upper bound of two types. Takes promotions of numeric primitives into account.

Compute the upper bound of two types. Takes promotions of numeric primitives into account.

Inherited from:
BType
final def size: Int
Returns:

0 for void, 2 for long and double, 1 otherwise

Inherited from:
BType

The asm.Type corresponding to this BType.

The asm.Type corresponding to this BType.

Note about asm.Type.getObjectType (*): For class types, the method expects the internal name, i.e. without the surrounding 'L' and ';'. For array types on the other hand, the method expects a full descriptor, for example "[Ljava/lang/String;".

See method asm.Type.getType that creates a asm.Type from a type descriptor

  • for an OBJECT type, the 'L' and ';' are not part of the range of the created Type
  • for an ARRAY type, the full descriptor is part of the range
Inherited from:
BType
final override def toString: String

Returns a string representation of the object.

Returns a string representation of the object.

The default representation is platform dependent.

Returns:

a string representation of the object.

Definition Classes
BType -> Any
Inherited from:
BType
final def typedOpcode(opcode: Int): Int

Some JVM opcodes have typed variants. This method returns the correct opcode according to the type.

Some JVM opcodes have typed variants. This method returns the correct opcode according to the type.

Value parameters:
opcode

A JVM instruction opcode. This opcode must be one of ILOAD, ISTORE, IALOAD, IASTORE, IADD, ISUB, IMUL, IDIV, IREM, INEG, ISHL, ISHR, IUSHR, IAND, IOR IXOR and IRETURN.

Returns:

The opcode adapted to this java type. For example, if this type is float and opcode is IRETURN, this method returns FRETURN.

Inherited from:
BType

Concrete fields