JVM Knowledge

We stipulate the existence of 28 Prolog predicates ("accessors") that have certain expected behavior but whose formal definitions are not given in this specification.

  • classClassName(Class, ClassName)

    Extracts the name, ClassName, of the class Class.

  • classIsInterface(Class)

    True iff the class, Class, is an interface.

  • classIsNotFinal(Class)

    True iff the class, Class, is not a final class.

  • classSuperClassName(Class, SuperClassName)

    Extracts the name, SuperClassName, of the superclass of class Class.

  • classInterfaces(Class, Interfaces)

    Extracts a list, Interfaces, of the direct superinterfaces of the class Class.

  • classMethods(Class, Methods)

    Extracts a list, Methods, of the methods declared in the class Class.

  • classAttributes(Class, Attributes)

    Extracts a list, Attributes, of the attributes of the class Class.

    Each attribute is represented as a functor application of the form attribute(AttributeName, AttributeContents), where AttributeName is the name of the attribute. The format of the attribute's contents is unspecified.

  • classDefiningLoader(Class, Loader)

    Extracts the defining class loader, Loader, of the class Class.

  • isBootstrapLoader(Loader)

    True iff the class loader Loader is the bootstrap class loader.

  • loadedClass(Name, InitiatingLoader, ClassDefinition)

    True iff there exists a class named Name whose representation (in accordance with this specification) when loaded by the class loader InitiatingLoader is ClassDefinition.

  • methodName(Method, Name)

    Extracts the name, Name, of the method Method.

  • methodAccessFlags(Method, AccessFlags)

    Extracts the access flags, AccessFlags, of the method Method.

  • methodDescriptor(Method, Descriptor)

    Extracts the descriptor, Descriptor, of the method Method.

  • methodAttributes(Method, Attributes)

    Extracts a list, Attributes, of the attributes of the method Method.

  • isInit(Method)

    True iff Method (regardless of class) is <init>.

  • isNotInit(Method)

    True iff Method (regardless of class) is not <init>.

  • isNotFinal(Method, Class)

    True iff Method in class Class is not final.

  • isStatic(Method, Class)

    True iff Method in class Class is static.

  • isNotStatic(Method, Class)

    True iff Method in class Class is not static.

  • isPrivate(Method, Class)

    True iff Method in class Class is private.

  • isNotPrivate(Method, Class)

    True iff Method in class Class is not private.

  • isProtected(MemberClass, MemberName, MemberDescriptor)

    True iff there is a member named MemberName with descriptor MemberDescriptor in the class MemberClass and it is protected.

  • isNotProtected(MemberClass, MemberName, MemberDescriptor)

    True iff there is a member named MemberName with descriptor MemberDescriptor in the class MemberClass and it is not protected.

  • parseFieldDescriptor(Descriptor, Type)

    Converts a field descriptor, Descriptor, into the corresponding verification type Type (§4.10.1.2).

  • parseMethodDescriptor(Descriptor, ArgTypeList, ReturnType)

    Converts a method descriptor, Descriptor, into a list of verification types, ArgTypeList, corresponding to the method argument types, and a verification type, ReturnType, corresponding to the return type.

  • parseCodeAttribute(Class, Method, FrameSize, MaxStack, ParsedCode, Handlers, StackMap)

    Extracts the instruction stream, ParsedCode, of the method Method in Class, as well as the maximum operand stack size, MaxStack, the maximal number of local variables, FrameSize, the exception handlers, Handlers, and the stack map StackMap.

    The representation of the instruction stream and stack map attribute must be as specified in §4.10.1.3 and §4.10.1.4.

  • samePackageName(Class1, Class2)

    True iff the package names of Class1 and Class2 are the same.

  • differentPackageName(Class1, Class2)

    True iff the package names of Class1 and Class2 are different.

When type checking a method's body, it is convenient to access information about the method. For this purpose, we define an environment, a six-tuple consisting of:

  • a class
  • a method
  • the declared return type of the method
  • the instructions in a method
  • the maximal size of the operand stack
  • a list of exception handlers

We specify accessors to extract information from the environment.

allInstructions(Environment, Instructions) :-
    Environment = environment(_Class, _Method, _ReturnType,
                              Instructions, _, _).

exceptionHandlers(Environment, Handlers) :-
    Environment = environment(_Class, _Method, _ReturnType,
                              _Instructions, _, Handlers).

maxOperandStackLength(Environment, MaxStack) :-
    Environment = environment(_Class, _Method, _ReturnType,
                              _Instructions, MaxStack, _Handlers).

thisClass(Environment, class(ClassName, L)) :-
    Environment = environment(Class, _Method, _ReturnType,
                              _Instructions, _, _),
    classDefiningLoader(Class, L),
    classClassName(Class, ClassName).

thisMethodReturnType(Environment, ReturnType) :-
    Environment = environment(_Class, _Method, ReturnType,
                              _Instructions, _, _).

We specify additional predicates to extract higher-level information from the environment.

offsetStackFrame(Environment, Offset, StackFrame) :-
    allInstructions(Environment, Instructions),
    member(stackMap(Offset, StackFrame), Instructions).

currentClassLoader(Environment, Loader) :-
    thisClass(Environment, class(_, Loader)).

Finally, we specify a general predicate used throughout the type rules:

notMember(_, []).
notMember(X, [A | More]) :- X \= A, notMember(X, More).

The principle guiding the determination as to which accessors are stipulated and which are fully specified is that we do not want to over-specify the representation of the class file. Providing specific accessors to the Class or Method term would force us to completely specify the format for a Prolog term representing the class file.