Main Page | Namespace List | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

class.h File Reference


Detailed Description

Definition of the java.lang.Class structure in this real machine implementation.

The definition of a class index is found here, as is the definition of a class. When initializing an class, the following activities happen in the class array:

(1) Its class index is used to address an empty slot in the class storage area.

(2) Since it is not a jvm_class_index_null value, its status is set to CLASS_STATUS_INUSE, with an | OBJECT_STATUS_ARRAY if it is an array type. All other bits are clear.

(3) Allocate an object table slot that references this class table slot. This a class definition can be references using an object hash.

(4) Recursively define array class types.

Control

$URL: https://svn.apache.org/path/name/class.h $ $Id: class.h 0 09/28/2005 dlydick $

Copyright 2005 The Apache Software Foundation or its licensors, as applicable.

Licensed under the Apache License, Version 2.0 ("the License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and limitations under the License.

Version:
$LastChangedRevision: 0 $
Date:
$LastChangedDate: 09/28/2005 $
Author:
$LastChangedBy: dlydick $ Original code contributed by Daniel Lydick on 09/28/2005.

Reference

Definition in file class.h.

#include "object.h"

Go to the source code of this file.

Data Structures

struct  rclass
 General class slot definition. More...

Class status bits

Bitwise status bits for the status of a class slot.

These class status bits have direct OBJECT_STATUS_xxx equivalents and a few THREAD_STATUS_xxx equivalents also. There are no overloaded bit positions between them (for ease of diagnostics).

#define CLASS_STATUS_2000   0x2000
 not used
#define CLASS_STATUS_4000   0x4000
 not used
#define CLASS_STATUS_8000   0x8000
 not used
#define CLASS_STATUS_ARRAY   0x0008
 Class is an array type where arraydims contains number of dimensions.
#define CLASS_STATUS_CLINIT   0x1000
 Class loaded, initialized, and ready to allocate instances.
#define CLASS_STATUS_DOCLINIT   0x0800
 Class loaded, needs <clinit>.
#define CLASS_STATUS_EMPTY   0x0000
 This slot is available for use.
#define CLASS_STATUS_GCREQ   0x0004
 Class may be garbage collected.
#define CLASS_STATUS_INUSE   0x0001
 This slot contains a class.
#define CLASS_STATUS_LINKED   0x0400
 Class linkages completed.
#define CLASS_STATUS_NULL   0x0002
 NULL class slot.
#define CLASS_STATUS_PRIMATIVE   0x0200
 Primative for java.lang.Class.
#define CLASS_STATUS_REFERENCE   0x0080
 Class variable is a reference.

Defines

#define CLASS(clsidx)   pjvm->class[clsidx]
 Access structures of class table at certain index.

Functions

 ARCH_COPYRIGHT_APACHE (class, h,"$URL: https://svn.apache.org/path/name/class.h $ $Id: class.h 0 09/28/2005 dlydick $")
jvm_class_index class_find_by_cp_entry (cp_info_dup *clsname)
 Scan class table using CP table entry for presence of a class of specific name and number of dimensions.
jvm_class_index class_find_by_prchar (rchar *clsname)
 Retrieve by (rchar *) name a class index to a class.
u2 class_get_num_object_instance_fields (ClassFile *pcfs)
 Report number of object instance fields are in a class file.
u2 class_get_num_static_fields (ClassFile *pcfs)
 Report number of class static fields are in a class file.
jvalueclass_get_object_instance_field_data (jvm_class_index clsidx, jvm_object_hash objhash, ClassFile *pcfs)
 Load the field data table for object instance fields in this class.
jvm_class_indexclass_get_object_instance_field_lookups (ClassFile *pcfs)
 Load the field lookup table for object instance fields in this class.
jvalueclass_get_static_field_data (jvm_class_index clsidx, ClassFile *pcfs)
 Load the field data table for class static fields in this class.
jvm_class_indexclass_get_static_field_lookups (ClassFile *pcfs)
 Load the field lookup table for class static fields in this class.
rvoid class_init (rvoid)
jvm_class_index class_load_from_cp_entry_utf (cp_info_dup *clsname, rboolean find_registerNatives, jint *arraylength)
jvm_class_index class_load_from_prchar (rchar *clsname, rboolean find_registerNatives, jint *arraylength)
jvm_class_index class_load_primative (u1 basetype)
 Load primative classes for java.lang.Class.
jvm_class_index class_load_resolve_clinit (rchar *clsname, jvm_thread_index thridx, rboolean usesystemthread, rboolean find_registerNatives)
 All-purpose class loading, load, resolve, <clinit> , each step only run if needed.
jvm_class_index class_reload (jvm_class_index clsidxOLD)
 Reload a class in the class table after java.lang.String has become available.
rvoid class_shutdown_1 (rvoid)
rvoid class_shutdown_2 (rvoid)
jvm_class_index class_static_delete (jvm_class_index clsidx, rboolean rmref)
 Un-reserve a slot from the class table.
jvm_class_index class_static_new (rushort status_req, ClassFile *pcfs, jvm_array_dim arraydims, jint *arraylength, jvm_class_index lower_dim_array)
 Load a class into ad class table slot and load up its associated class definition object.
jvm_class_index classutil_jobject2clsidx (jvm_object_hash objhash)


Define Documentation

#define CLASS clsidx   )     pjvm->class[clsidx]
 

Access structures of class table at certain index.

The class table, being an array of slots, provides space for one class definition per slot. This macro references one of them using the clsidx index.

Parameters:
clsidx Class table index into the global rjvm.class[] array (via pjvm->class[]).
Returns:
pointer to a class slot

Definition at line 84 of file class.h.

Referenced by class_allocate_slot(), class_get_object_instance_field_data(), class_load_from_prchar(), class_static_delete(), class_static_setup(), field_index_get_class_static_lookup(), field_index_get_class_static_pjvalue(), field_index_get_object_instance_lookup(), field_index_get_object_instance_pjvalue(), field_index_is_class_static(), field_index_is_object_instance(), field_index_put_class_static_pjvalue(), field_index_put_object_instance_pjvalue(), gc_run_stub(), jlClass_isArray(), jlObject_getClass(), linkage_resolve_class(), and opcode_run().

#define CLASS_STATUS_EMPTY   0x0000
 

This slot is available for use.

Definition at line 109 of file class.h.

#define CLASS_STATUS_INUSE   0x0001
 

This slot contains a class.

Definition at line 111 of file class.h.

Referenced by class_allocate_slot(), class_static_setup(), gc_run_stub(), and linkage_resolve_class().

#define CLASS_STATUS_NULL   0x0002
 

NULL class slot.

Exactly on exists in normal use, any else besides the JVMCFG_NULL_CLASS is a class slot now being initialized.

Definition at line 112 of file class.h.

Referenced by class_allocate_slot(), class_get_object_instance_field_data(), class_static_setup(), and gc_run_stub().

#define CLASS_STATUS_GCREQ   0x0004
 

Class may be garbage collected.

Definition at line 122 of file class.h.

Referenced by gc_run_stub().

#define CLASS_STATUS_ARRAY   0x0008
 

Class is an array type where arraydims contains number of dimensions.

Definition at line 124 of file class.h.

Referenced by jlClass_isArray(), and opcode_run().

#define CLASS_STATUS_REFERENCE   0x0080
 

Class variable is a reference.

This is the same definition as for OBJECT_STATUS_REFERENCE and for LOCAL_STATUS_REFERENCE, the local variable reference bit for variables on the stack frame, where the GC algorithm implements it.

Definition at line 131 of file class.h.

#define CLASS_STATUS_PRIMATIVE   0x0200
 

Primative for java.lang.Class.

Definition at line 148 of file class.h.

#define CLASS_STATUS_LINKED   0x0400
 

Class linkages completed.

Definition at line 150 of file class.h.

Referenced by linkage_resolve_class().

#define CLASS_STATUS_DOCLINIT   0x0800
 

Class loaded, needs <clinit>.

Definition at line 151 of file class.h.

#define CLASS_STATUS_CLINIT   0x1000
 

Class loaded, initialized, and ready to allocate instances.

Definition at line 153 of file class.h.

Referenced by class_load_from_prchar().

#define CLASS_STATUS_2000   0x2000
 

not used

Definition at line 159 of file class.h.

#define CLASS_STATUS_4000   0x4000
 

not used

Definition at line 160 of file class.h.

#define CLASS_STATUS_8000   0x8000
 

not used

Definition at line 161 of file class.h.


Function Documentation

ARCH_COPYRIGHT_APACHE class  ,
,
"$URL: https://svn.apache.org/path/name/class.h $ $Id: class.h 0 09/28/2005 dlydick $" 
 

rvoid class_init rvoid   ) 
 

rvoid class_shutdown_1 rvoid   ) 
 

rvoid class_shutdown_2 rvoid   ) 
 

jvm_class_index class_static_new rushort  special_cls,
ClassFile pcfs,
jvm_array_dim  arraydims,
jint arraylength,
jvm_class_index  lower_dim_array
 

Load a class into ad class table slot and load up its associated class definition object.

Create a Java class itself (and NOT a new instance of a class!). The following three mutially exclusive variations are available using the special_cls modifier:

  • (1) CLASS_STATUS_EMPTY: Normal class, no special treatment.

  • (2) CLASS_STATUS_ARRAY: Treat class instance creation as a dimension of an array instead of as a normal class load. The recursion will eventually load its base class and superclasses. When allocating an array class, DO NOT EVER INVOKE THIS FUNCTION FOR A PRIMATIVE ARRAY!

  • (3) CLASS_STATUS_PRIMATIVE: Treat class instance creation as loading a primative pseudo-class for use by java.lang.Class. A related Classfile structure will be generated for this pseudo-class.

No verification of special_cls is performed, only these values are assumed.

Use a simple circular slot allocation mechanism to report where most recent class was allocated. The search for the next slot will begin from here and go all the way around the array to this same slot. If not successful, throw error, but do not return.

Parameters:
special_cls Bit-mapped request for various special considerations for class construction. If not needed, use CLASS_STATUS_EMPTY. If used, the values are:
  • CLASS_STATUS_ARRAY create new array class instead of class instance

  • CLASS_STATUS_PRIMATIVE create special class instance of a Java primative for use by java.lang.Class

Parameters:
pcfs Pointer to ClassFile area which contains this class, rnull for CLASS_STATUS_PRIMATIVE requests.
arraydims Number of array dimensions for this class, or zero if not an array class.
arraylength Array of length arraydims containing the length of array in each of those dimensions. E.g., arraydims is 4 for new X[7][3][9][2] so this parameter will be a 4-element array containing the numbers {7, 3, 9, 2}
lower_dim_array Class index of this array class' next lower dimension, e.g. if this is a 3-dim array [[[L then need index it as [[L .
Returns:
Class index value of allocation. Throw error if no slots.
Exceptions:
JVMCLASS_JAVA_LANG_OUTOFMEMORYERROR if no slots are available..
< Primative for java.lang.Class < This slot is available for use

< Primative for java.lang.Class < Class loaded, initialized, and ready to allocate instances

< Class is an array type where arraydims contains number of dimensions

< This object is a class definition instead of an object instance

< Class is an array type where arraydims contains number of dimensions

Todo:
Where is this mkref's GC_CLASS_RMREF() ???
< This slot is available for use

< NULL class slot. Exactly on exists in normal use, any else besides the JVMCFG_NULL_CLASS is a class slot now being initialized.

Definition at line 353 of file class.c.

References jvm_class_index_null.

jvm_class_index class_reload jvm_class_index  clsidxOLD  ) 
 

Reload a class in the class table after java.lang.String has become available.

This process does not re-read the class file, only redoes class initialization. The class_objhash does not get deleted.

Parameters:
clsidxOLD Class table index of slot to tear down.
Returns:
New class index of rebuilt class slot. Throw error if no slots.
Exceptions:
JVMCLASS_JAVA_LANG_OUTOFMEMORYERROR if no slots are available..
Todo:
This function needs more testing. Also, is it really needed in the implementation?
< This slot contains a class

< NULL class slot. Exactly on exists in normal use, any else besides the JVMCFG_NULL_CLASS is a class slot now being initialized.

< This slot is available for use

< NULL class slot. Exactly on exists in normal use, any else besides the JVMCFG_NULL_CLASS is a class slot now being initialized.

Definition at line 553 of file class.c.

jvm_class_index class_static_delete jvm_class_index  clsidx,
rboolean  rmref
 

Un-reserve a slot from the class table.

This is the reverse of the process of class_static_new() above. Only tear down the heap allocations and mark the slot as empty. Leave the rest of the data in place for post-mortem. When the slot gets allocated again, any zeroing out of values will just get overwritten again, so don't bother.

Todo:
Make sure all objects of this class type have been destroyed before destroying this class itself!
Todo:
This function may be used to declutter the class table when a class has not been used for some period of time (including any static methods and fields, watch out for static final constants), so as to free up its slot for other purposes.
Parameters:
clsidx Class index value of allocation.
rmref rtrue if class references should be removed, which is NOT SO during JVM shutdown. Regardless of this value, object references are always removed.
Returns:
Same class index as input if slot was freed, else jvm_class_index_null if slot was already free.
< This slot contains a class

Todo:
Determine what to do, if anything, when rfalse is returned from linkage_unresolve_class(). Is the class slot unusable? Should class_static_delete() proceed?

Todo:
Is there anything equivalent to calling java.lang.Object.finalize() for an object that must be invoked before unloading a class?
< This slot contains a class

Definition at line 732 of file class.c.

References CLASS, GC_CLASS_FIELD_RMREF, and HEAP_FREE_DATA.

jvm_class_index class_find_by_cp_entry cp_info_dup clsname  ) 
 

Scan class table using CP table entry for presence of a class of specific name and number of dimensions.

Parameters:
clsname UTF8 string pointer to a class name, possibly with array dimensions: [[Lsome/class/path/SomeClassname; has two array dimensions. Can also accept classes that are null-terminated strings without class formatting. Such strings may start with L but will not end with ; .
Returns:
its index in pjvm->class if present, else jvm_class_index_null.
< This slot contains a class

< NULL class slot. Exactly on exists in normal use, any else besides the JVMCFG_NULL_CLASS is a class slot now being initialized.

Definition at line 839 of file class.c.

References class_find_by_cp_entry(), HEAP_FREE_DATA, and nts_prchar2utf().

Referenced by class_find_by_cp_entry(), class_load_primative(), and linkage_resolve_class().

jvm_class_index class_find_by_prchar rchar clsname  ) 
 

Retrieve by (rchar *) name a class index to a class.

Parameters:
clsname Null-terminated string of name of class.
Returns:
class index of located class, otherwise jvm_class_index_null.

Definition at line 898 of file class.c.

Referenced by opcode_run(), and thread_new().

jvm_class_index class_load_primative u1  basetype  ) 
 

Load primative classes for java.lang.Class.

Load primative classes as opposed to a real class LSome/Package/Name/SomeClassName; . These will be known by their primative types: I for "integer", S for "short", etc.

Classes loaded with this method will typically never have any references to them except from their class object created within class_static_new(), yet are completely valid and are used intensively by class type processing. Because they never have references removed, they will never be marked for garbage collection, either. In this way, they are permanently available to the JVM for class type processing.

Parameters:
basetype One of the primative base types BASETYPE_CHAR_x
Returns:
class table index to loaded primative [pseudo-]class, ready for use. Throw error if could not load.
Exceptions:
JVMCLASS_JAVA_LANG_OUTOFMEMORYERROR if no slots are available..
< Primative for java.lang.Class < Not stated in spec, but implied

Definition at line 940 of file class.c.

References class_find_by_cp_entry(), class_load_from_prchar(), CONSTANT_Utf8, EXIT_JVM_INTERNAL, exit_throw_exception(), jvm_class_index_null, JVMCLASS_JAVA_LANG_INTERNALERROR, LOCAL_CONSTANT_NO_ARRAY_DIMS, PTR_THIS_CP_Utf8, rnull, utf_get_utf_arraydims(), and utf_utf2prchar().

jvm_class_index class_load_from_prchar rchar clsname,
rboolean  find_registerNatives,
jint arraylength
 

Definition at line 1318 of file class.c.

References CLASS, class_load_from_prchar(), CLASS_OBJECT_LINKAGE, CLASS_STATUS_CLINIT, method_info::LOCAL_method_binding::codeatridxJVM, jvm_attribute_index_bad, jvm_method_index_bad, jvm_thread_index_null, linkage_resolve_class(), LOCAL_CONSTANT_UTF8_CLASS_CONSTRUCTOR, LOCAL_CONSTANT_UTF8_CLASS_CONSTRUCTOR_PARMS, method_info::LOCAL_method_binding, method_find_by_prchar(), ClassFile::methods, and rnull.

Referenced by class_load_from_prchar(), class_load_primative(), and thread_new().

jvm_class_index class_load_from_cp_entry_utf cp_info_dup clsname,
rboolean  find_registerNatives,
jint arraylength
 

< Not stated in spec, but implied

< Not stated in spec, but implied

< Not stated in spec, but implied

< This slot is available for use

< Class is an array type where arraydims contains number of dimensions

< Convenient alias for DML5

< Convenient alias for DML5

Todo:
Throw UnsupportedClassVersionError
< This slot is available for use

< Not stated in spec, but implied

< Convenient alias for DML5

For internal use only.

Load superclass

Todo:
(The <clinit> procedure is run when the JVM virtual machine execution engine moves a new class from the START state into the RUNNABLE state.)

WATCH OUT! RECURSIVE CALL! This will recurse until super_class is a java.lang.Object, where ClassFile.super_class is 0 (per JVM spec. Throw error if could not load superclass. Don't care about its class index, as that is also available in other places.

Todo:
Make sure that this superclass and all of its superclasses are not only loaded, but also linked and have <clinit> run also.
< Class loaded, needs <clinit>

Definition at line 1071 of file class.c.

jvm_class_index class_load_resolve_clinit rchar clsname,
jvm_thread_index  thridx,
rboolean  usesystemthread,
rboolean  find_registerNatives
 

All-purpose class loading, load, resolve, <clinit> , each step only run if needed.

Load a class into the JVM, resolve its linkages, and run its <clinit> method, if any, typically on the system thread. All three steps are optional and will be invoked only if needed. Therefore it is possible that none of the steps will be run. However, if any step needs to performed, that step will be run.

Parameters:
clsname Null-terminated string of unformatted class name.(Formatting is okay, but don't pass an array class)
thridx If a non-null thread index is passed in, use the current state of that thread to load the class and run its <clinit> . If null thread index is passed in, use the usesystemthread parameter to further clarify which thread to load up with class <clinit> .
usesystemthread Load onto system thread when rtrue, use an available thread otherwise.
find_registerNatives When rtrue, will return the ordinal for JVMCFG_JLOBJECT_NMO_REGISTER and JVMCFG_JLOBJECT_NMO_UNREGISTER as well as the other ordinals. Once JVM initialization is complete, this should always be rfalse because all future classes should never have local ordinals.
Returns:
class index of loaded class, whether or not a <clinit> method was available. Throw error if not slots available.
Exceptions:
JVMCLASS_JAVA_LANG_OUTOFMEMORYERROR if no slots are available..
JVMCLASS_JAVA_LANG_INTERNALERROR if invalid clsidx
JVMCLASS_JAVA_LANG_NOSUCHFIELDERROR if invalid field linked by class
JVMCLASS_JAVA_LANG_NOSUCHMETHODERROR if invalid method linked by class
Todo:
Any JAR file passed in here that has a [ in its first one or more characters may be interpreted as an array class. I have not tested this, and it is an oddball, but somebody needs to make sure that either, (a) such a name is never passed in, which is preferred due to standard industry file naming practices, and/or (b) that no array processing happens in the lower levels.
< Class loaded, initialized, and ready to allocate instances

For internal use only.

see similar logic for loading a new stack frame and PC in thread_new_common()

Todo:
Currently, return valid class index even if no <clinit> was available. Is this correct? Or should it throw a VerifyError since a method was declared, yet had no code area? Take the easy way out for now, evaluate and maybe fix later.
alias

< Start PC location

< Class loaded, needs <clinit> < Class loaded, initialized, and ready to allocate instances

Definition at line 1445 of file class.c.

Referenced by opcode_load_run_throwable(), and opcode_run().

u2 class_get_num_static_fields ClassFile pcfs  ) 
 

Report number of class static fields are in a class file.

Parameters:
pcfs Pointer to ClassFile area
Returns:
number of fields marked ACC_STATIC.
< Declared static .

Definition at line 1887 of file class.c.

References class_get_num_static_fields(), HEAP_GET_DATA, and rtrue.

Referenced by class_get_num_static_fields().

jvm_class_index* class_get_static_field_lookups ClassFile pcfs  ) 
 

Load the field lookup table for class static fields in this class.

Parameters:
pcfs Pointer to ClassFile area
Returns:
array of field indices in ClassFile fields table for all static fields in this class or rnull if no values to initialize or heap allocation error. The size of the array is determined by the result of class_get_num_static_fields().
< Declared static .

Definition at line 1921 of file class.c.

References ACC_STATIC, field_info::access_flags, class_get_constant_field_attribute(), ClassFile::fields, jvm_object_hash_null, and rtrue.

jvalue* class_get_static_field_data jvm_class_index  clsidx,
ClassFile pcfs
 

Load the field data table for class static fields in this class.

Parameters:
clsidx Class table index of slot having class loaded
pcfs Pointer to ClassFile area
Returns:
array of data values corresponding to each field index as returned from class_get_static_field_lookups() or rnull if no values to initialize or heap allocation error. The size of the array is determined by the result of class_get_num_static_fields().
< Declared static .

Definition at line 1968 of file class.c.

References ACC_STATIC, field_info::access_flags, class_get_num_object_instance_fields(), ClassFile::fields, HEAP_GET_DATA, and rfalse.

u2 class_get_num_object_instance_fields ClassFile pcfs  ) 
 

Report number of object instance fields are in a class file.

Parameters:
pcfs Pointer to ClassFile area
Returns:
number of fields not marked ACC_STATIC.
< Declared static .

Definition at line 2020 of file class.c.

References class_get_num_object_instance_fields().

Referenced by class_get_num_object_instance_fields(), and class_get_static_field_data().

jvm_class_index* class_get_object_instance_field_lookups ClassFile pcfs  ) 
 

Load the field lookup table for object instance fields in this class.

Parameters:
pcfs Pointer to ClassFile area
Returns:
array of field indices in ClassFile fields table for all object instance fields in this class or rnull if no values to initialize or heap allocation error. The size of the array is determined by the result of class_get_num_object_instance_fields().
< Declared static .

Definition at line 2055 of file class.c.

jvalue* class_get_object_instance_field_data jvm_class_index  clsidx,
jvm_object_hash  objhash,
ClassFile pcfs
 

Load the field data table for object instance fields in this class.

This initialization is the same for all objects of this class, so this function is still naturally a part of class processing instead of object processing.

Parameters:
clsidx Class table index of slot having class loaded
objhash Object hash of object slot being loaded. This is supplied expressly to mark reference types (that is, CONSTANT_String) during field loading from the class file, otherwise not needed.
pcfs Pointer to ClassFile area
Returns:
array of data values corresponding to each field index as returned from class_get_static_field_lookups() or rnull if no values to initialize or heap allocation error. The size of the array is determined by the result of class_get_num_object_instance_fields().
< Declared static .

Definition at line 2111 of file class.c.

References CLASS, CLASS_STATUS_NULL, GC_CLASS_RMREF_FROM_CLASS, GC_OBJECT_RMREF_FROM_CLASS, and jvm_class_index_null.

jvm_class_index classutil_jobject2clsidx jvm_object_hash  objhash  ) 
 


Generated on Fri Sep 30 18:59:57 2005 by  doxygen 1.4.4