Struct rust_jvm::vm::class::Class [] [src]

pub struct Class {
    pub symref: Class,
    pub access_flags: u16,
    pub superclass: Option<Rc<Class>>,
    constant_pool: RuntimeConstantPool,
    fields: HashMap<Field, u16>,
    field_constants: HashMap<Field, constant_pool_index>,
    methods: HashMap<Method, Method>,
    field_values: RefCell<Option<HashMap<Field, Value>>>,
}

A JVM representation of a class that has been loaded.

Fields

symref

A symbolic reference to the class, comprised of its name (if a scalar type) or element type (if an array class).

access_flags

The access flags for the class.

superclass

The superclass extended by the class. If the class is java/lang/Object, this is None.

constant_pool

The runtime constant pool of the current class, created from the constant pool defined in the .class file that has been loaded.

fields

The fields of this class mapped to their access flags. This map includes both static and non-static fields. We don't separate them because it makes it easier to throw the correct runtime Error when certain invalid conditions are detected.

field_constants

The constants which populate the static final fields of this class. We don't immediately put these values into class_fields because they can include String literals, and we may not have loaded the String class yet. (This is also consistent with the spec, which states that these constants are set at class initialization time.)

methods

The methods of the class, mapped to their method structures.

field_values

The values of the static fields of this class. These are only set at class initialization. §5.5 of the JVM spec requires that initialization occur only at certain specific points, in particular: * When an instance of the class is created with the new instruction * When one of the getstatic, putstatic, or invokestatic instructions refers to one of the static members of the class * When a subclass of the class is initialized * When the VM is about to begin executing the main method in the class containing the overall program entry point Prior to initialization, this structure field contains None. After initialization, this field contains a Some with a HashMap value, which must contain the current values for each static field of this class.

Methods

impl Class

fn new(symref: Class, superclass: Option<Rc<Class>>, constant_pool: RuntimeConstantPool, class_file: ClassFile) -> Self

fn new_array(object_class: Rc<Class>, component_access_flags: u16, component_type: Type) -> Self

Create a new array class for a given element type.

fn get_symref(&self) -> Class

fn get_access_flags(&self) -> u16

fn get_constant_pool(&self) -> &RuntimeConstantPool

fn resolve_method(&self, method_symref: &Method) -> &Method

Find the method in the current class referred to by a given symbolic reference. If the method is not found, panics with a NoSuchMethodError.

fn find_method(&self, method_sig: &Method) -> Option<&Method>

Implements dynamic lookup of a method's signature in the current class. If no method with the given signature is found, then recursively searches the current class's superclasses.

fn dispatch_method(&self, resolved_method: &Method) -> Option<(&Class, &Method)>

Implements dynamic dispatch of a resolved method according to the lookup procedure specified for the invokevirtual instruction. Method resolution depends on whether the method in question overrides a superclass method. (See spec for more information.)

fn is_descendant(&self, other: &Class) -> bool

Returns true if this class is a descendant (direct or indirect subclass) of another class.

fn initialize(&self, class_loader: &mut ClassLoader)

Initialize the class by executing its class or interface initialization method. Prior to initialization, a class or interface must be linked, that is, verified, prepared, and optionally resolved.

fn resolve_and_get_field(&self, symref: &Field, class_loader: &mut ClassLoader) -> Value

Resolves a symbolic reference to a field and reads a value from that field.

fn resolve_and_put_field(&self, symref: &Field, new_value: Value, class_loader: &mut ClassLoader)

Resolves a symbolic reference to a field and writes a new value to that field.

fn collect_instance_fields(&self) -> HashSet<Field>

Returns a set of the signatures of the fields of an instance of this class.

Trait Implementations

Derived Implementations

impl Debug for Class

fn fmt(&self, __arg_0: &mut Formatter) -> Result