---
spec: JVMS
title: "The Java Virtual Machine Specification"
edition: "Java SE 27 Edition"
java_version: 27
chapter: "Chapter 4. The class File Format"
section: "4.10.1.1"
heading: "4.10.1.1. Accessors for Java Virtual Machine Artifacts"
parent: "4.10.1. Verification by Type Checking"
source: https://docs.oracle.com/javase/specs/jvms/se27/html/jvms-4.html#jvms-4.10.1.1
id: "4.10.1.1"
url: https://jvm.obfuscated.software/jvms/se27/4.10.1.1.html
raw: https://jvm.obfuscated.software/jvms/se27/4.10.1.1.md
---

# 4.10.1.1. Accessors for Java Virtual Machine Artifacts

We stipulate the existence of 17 Prolog predicates ("accessors") that have certain expected behavior but whose formal definitions are not given in this specification. The Prolog term `Class`, as used here, represents a binary class or interface that has been successfully loaded ([§5.3](5.3.md)); the Prolog term `Method` represents a method of a `Class`; and the Prolog term `Loader` represents a class loader of a `Class`. This specification does not mandate a precise structure for these entities.

- **classClassName(Class, ClassName)**

  Extracts the name, `ClassName`, of the class `Class`.

- **classIsInterface(Class)**

  True iff the class, `Class`, is an interface.

- **classSuperClassName(Class, SuperClassName)**

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

- **classInterfaceNames(Class, InterfaceNames)**

  Extracts a list, `InterfaceNames`, of the names of the direct superinterfaces of the class `Class`.

- **classDeclaresMember(Class, MemberName, MemberDescriptor)**

  Asserts that a class, `Class`, declares a field or method with name `MemberName` and descriptor `MemberDescriptor`. This assertion does not consider members declared in the superclasses or superinterfaces of `Class`.

- **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`.

- **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](4.10.1.2.md)).

  The verification type derived from descriptor types `byte`, `short`, `boolean`, and `char`, when not used as array component types, is `int`.

- **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.

  The verification type derived from descriptor types `byte`, `short`, `boolean`, and `char`, when not used as array component types, is `int`. A void return is represented with the special symbol `void`.

- **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](4.10.1.3.md) and [§4.10.1.4](4.10.1.4.md).

- **samePackageName(Class1, Class2)**

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

The above accessors are used to define `loadedSuperclasses`, which produces a list of a class's superclasses by recurring on each class's direct superclass until `Object`, which has no superclass, is reached.

```
loadedSuperclasses(Class, [ Superclass | Rest ]) :-
    classSuperClassName(Class, SuperclassName),
    classDefiningLoader(Class, L),
    loadedClass(SuperclassName, L, Superclass),
    loadedSuperclasses(Superclass, Rest).

loadedSuperclasses(Class, []) :-
    \+ classSuperClassName(Class, _).
```

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 (or `void`)
- 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).

currentClassLoader(Environment, Loader) :-
    Environment = environment(Class, _Method, _ReturnType,
                              _Instructions, _, _),
    classDefiningLoader(Class, Loader).

thisClass(Environment, Class) :-
    Environment = environment(Class, _Method, _ReturnType,
                              _Instructions, _, _).

thisType(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, _, _).

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

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.
