Individual bytecode instructions are represented in Prolog as terms whose functor is the name of the instruction and whose arguments are its parsed operands.
For example, an aload instruction is represented as the term aload(N), which includes the index N that is the operand of the instruction.
The instructions as a whole are represented as a list of terms of the form:
instruction(Offset, AnInstruction)
For example, instruction(21, aload(1)).
The order of instructions in this list must be the same as in the class file.
Some instructions have operands that refer to entries in the constant_pool table representing fields, methods, and dynamically-computed call sites. Such entries are represented as functor applications of the form:
-
field(FieldClassName, FieldName, FieldDescriptor)for a constant pool entry that is aCONSTANT_Fieldref_infostructure (§4.4.2).FieldClassNameis the name of the class referenced by theclass_indexitem in the structure.FieldNameandFieldDescriptorcorrespond to the name and field descriptor referenced by thename_and_type_indexitem of the structure. -
method(MethodClassName, MethodName, MethodDescriptor)for a constant pool entry that is aCONSTANT_Methodref_infostructure (§4.4.2).MethodClassNameis the name of the class referenced by theclass_indexitem of the structure.MethodNameandMethodDescriptorcorrespond to the name and method descriptor referenced by thename_and_type_indexitem of the structure. -
imethod(MethodIntfName, MethodName, MethodDescriptor)for a constant pool entry that is aCONSTANT_InterfaceMethodref_infostructure (§4.4.2).MethodIntfNameis the name of the interface referenced by theclass_indexitem of the structure.MethodNameandMethodDescriptorcorrespond to the name and method descriptor referenced by thename_and_type_indexitem of the structure. -
dmethod(CallSiteName, MethodDescriptor)for a constant pool entry that is aCONSTANT_InvokeDynamic_infostructure (§4.4.10).CallSiteNameandMethodDescriptorcorrespond to the name and method descriptor referenced by thename_and_type_indexitem of the structure. (Thebootstrap_method_attr_indexitem is irrelevant to verification.)
For clarity, we assume that field and method descriptors (§4.3.2, §4.3.3) are mapped into more readable names: the leading L and trailing ; are dropped from class names, and the BaseType characters used for primitive types are mapped to the names of those types.
For example, a getfield instruction whose operand refers to a constant pool entry representing a field foo of type F in class Bar would be represented as getfield(field('Bar', 'foo', 'F')).
The ldc instruction, among others, has an operand that refers to a loadable entry in the constant_pool table. There are nine kinds of loadable entry (see Table 4.4-C), represented by functor applications of the following forms:
-
int(Value)for a constant pool entry that is aCONSTANT_Integer_infostructure (§4.4.4).Valueis theintconstant represented by thebytesitem of the structure.For example, an ldc instruction for loading the
intconstant 91 would be represented asldc(int(91)). -
float(Value)for a constant pool entry that is aCONSTANT_Float_infostructure (§4.4.4).Valueis thefloatconstant represented by thebytesitem of the structure. -
long(Value)for a constant pool entry that is aCONSTANT_Long_infostructure (§4.4.5).Valueis thelongconstant represented by thehigh_bytesandlow_bytesitems of the structure. -
double(Value)for a constant pool entry that is aCONSTANT_Double_infostructure (§4.4.5).Valueis thedoubleconstant represented by thehigh_bytesandlow_bytesitems of the structure. -
class(ClassName)for a constant pool entry that is aCONSTANT_Class_infostructure (§4.4.1).ClassNameis the name of the class or interface referenced by thename_indexitem in the structure. -
string(Value)for a constant pool entry that is aCONSTANT_String_infostructure (§4.4.3).Valueis the string referenced by thestring_indexitem of the structure. -
methodHandle(Kind, Reference)for a constant pool entry that is aCONSTANT_MethodHandle_infostructure (§4.4.8).Kindis the value of thereference_kinditem of the structure.Referenceis the value of thereference_indexitem of the structure. -
methodType(MethodDescriptor)for a constant pool entry that is aCONSTANT_MethodType_infostructure (§4.4.9).MethodDescriptoris the method descriptor referenced by thedescriptor_indexitem of the structure. -
dconstant(ConstantName, FieldDescriptor)for a constant pool entry that is aCONSTANT_Dynamic_infostructure (§4.4.10).ConstantNameandFieldDescriptorcorrespond to the name and field descriptor referenced by thename_and_type_indexitem of the structure. (Thebootstrap_method_attr_indexitem is irrelevant to verification.)