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

object.c File Reference


Detailed Description

Create and manage real machine Java object data structures.

An object reference is a simple (jobject ), an integer index into the object table.

Control

$URL: https://svn.apache.org/path/name/object.c $ $Id: object.c 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 object.c.

#include "arch.h"
#include "jvmcfg.h"
#include "cfmacros.h"
#include "classfile.h"
#include "exit.h"
#include "gc.h"
#include "jvm.h"
#include "jvmclass.h"
#include "linkage.h"
#include "method.h"
#include "native.h"
#include "opcode.h"
#include "utf.h"
#include "util.h"

Go to the source code of this file.

Functions

static jvm_object_hash object_allocate_slot (rboolean tryagain)
 Locate and reserve an unused object table slot for a new object instance.
static void object_c_dummy (void)
rvoid object_init ()
 Initialize the object area of the JVM model.
jvm_object_hash object_instance_delete (jvm_object_hash objhash, rboolean rmref)
 Un-reserve a slot from the object area.
rvoid object_instance_finalize (jvm_object_hash objhash, jvm_thread_index thridx)
 Finalize an object instance before deletion.
jvm_object_hash object_instance_new (rushort special_obj, ClassFile *pcfs, jvm_class_index clsidx, jvm_array_dim arraydims, jint *arraylength, rboolean run_init_, jvm_thread_index thridx)
 Create a Java new object instance of a class and optionally run its <init> method with default parameters (none).
rboolean object_locate_pcfs (jvm_object_hash objhash)
 Check whether or not a class file data area is used by at least one other object besides this one.
rvoid object_new_setup (jvm_object_hash objhash)
 Set up an empty object in a given object table slot.
rvoid object_run_method (jvm_class_index clsidx, rchar *mthname, rchar *mthdesc, jvm_thread_index thridx)
 Invoke a method on a thread for any class, either static or instance method, either native or virtual.
rvoid object_shutdown ()
 Shut down the object area of the JVM model after JVM execution.

Variables

static char * object_c_copyright = "\0" "$URL: https://svn.apache.org/path/name/object.c $ $Id: object.c 0 09/28/2005 dlydick $" " " "Copyright 2005 The Apache Software Foundation or its licensors, as applicable."


Function Documentation

static void object_c_dummy void   )  [static]
 

Definition at line 43 of file object.c.

rvoid object_init  ) 
 

Initialize the object area of the JVM model.

Parameters: rvoid

Returns:
rvoid

Definition at line 71 of file object.c.

References jvm_object_hash_null, jvm_object_initialized, rjvm::object_allocate_last, object_new_setup(), pjvm, and rtrue.

rvoid object_run_method jvm_class_index  clsidx,
rchar mthname,
rchar mthdesc,
jvm_thread_index  thridx
 

Invoke a method on a thread for any class, either static or instance method, either native or virtual.

Similar logic may be found in opcode_run() in its uncaught exception handler concerning initiating execution of a JVM method.

Parameters:
clsidx Class table index of method to invoke.
mthname Null-terminated name of method to invoke.
mthdesc Null-terminated description of method parameters and return types.
thridx Thread table index of thread to load and run it on.
Returns:
rvoid
Exceptions:
JVMCLASS_JAVA_LANG_NOSUCHMETHODERROR if the requested method is not found in the class or has no code attribute..
JVMCLASS_JAVA_LANG_INTERNALERROR if null thread index.
alias

< Start PC location

Definition at line 116 of file object.c.

References method_info::attributes, CLASS_OBJECT_LINKAGE, CODE_CONSTRAINT_START_PC, method_info::LOCAL_method_binding::codeatridxJVM, method_info::descriptor_index, method_info::LOCAL_method_binding::excpatridxJVM, exit_jvm(), EXIT_JVM_ATTRIBUTE, EXIT_JVM_METHOD, EXIT_JVM_THREAD, exit_throw_exception(), jvm_attribute_index_bad, jvm_attribute_index_native, jvm_method_index_bad, jvm_thread_index_null, JVMCLASS_JAVA_LANG_INTERNALERROR, JVMCLASS_JAVA_LANG_NOSUCHMETHODERROR, jvmutil_print_stack(), method_info::LOCAL_method_binding, Code_attribute::max_locals, method_find_by_prchar(), ClassFile::methods, method_info::name_index, native_run_method(), opcode_run(), PUSH_FRAME, PUT_PC_IMMEDIATE, rfalse, rnull, sysErrMsg(), and THREAD.

rvoid object_new_setup jvm_object_hash  objhash  ) 
 

Set up an empty object in a given object table slot.

The objhash of JVMCFG_NULL_OBJECT has special properties in that it can ALWAYS be allocated and is NEVER garbage collected! Part of the purpose for this is the JVMCFG_NULL_OBJECT is of value zero, which is widely used throughout the code as a special value. This this slot is not available for anything else.

Parameters:
objhash Object table hash of slot to set up.
Returns:
rvoid
< This slot contains an object

< NULL object (only 1 exists in normal use, any else besides the JVMCFG_NULL_OBJECT is an object slot now being initialized.)

< Invalid basetype due to malformed tag or other error (not in spec)

< Not stated in spec, but implied

< Not defined, empty (not in spec)

< This slot contains an object

< This slot contains an object

< This slot contains an object

Definition at line 245 of file object.c.

References jvm_class_index_null, jvm_object_hash_null, jvm_thread_index_null, LOCAL_ACC_EMPTY, LOCAL_BASETYPE_ERROR, LOCAL_CONSTANT_NO_ARRAY_DIMS, OBJECT, OBJECT_OBJECT_LINKAGE, OBJECT_STATUS_INUSE, OBJECT_STATUS_NULL, and rnull.

Referenced by object_init().

static jvm_object_hash object_allocate_slot rboolean  tryagain  )  [static]
 

Locate and reserve an unused object table slot for a new object instance.

Parameters:
tryagain If rtrue, run garbage collection once if no empty slots are available so as to try and free up something. Typically, invoke as rtrue, and let recursion call it with rfalse.
Returns:
Object hash of an empty slot. Throw error if no slots.
Exceptions:
JVMCLASS_JAVA_LANG_OUTOFMEMORYERROR if no object slots are available..
< This slot contains an object

< This slot contains an object

< NULL object (only 1 exists in normal use, any else besides the JVMCFG_NULL_OBJECT is an object slot now being initialized.)

Definition at line 329 of file object.c.

References EXIT_JVM_OBJECT, exit_throw_exception(), GC_RUN, JVMCFG_FIRST_OBJECT, JVMCFG_MAX_OBJECTS, JVMCLASS_JAVA_LANG_OUTOFMEMORYERROR, OBJECT, rjvm::object_allocate_last, OBJECT_STATUS_INUSE, OBJECT_STATUS_NULL, pjvm, rfalse, and rtrue.

jvm_object_hash object_instance_new rushort  special_obj,
ClassFile pcfs,
jvm_class_index  clsidx,
jvm_array_dim  arraydims,
jint arraylength,
rboolean  run_init_,
jvm_thread_index  thridx
 

Create a Java new object instance of a class and optionally run its <init> method with default parameters (none).

The following four mutually exclusive variations are available using special_obj modifier:

  • OBJECT_STATUS_EMPTY: Normal object, no special treatment.

  • OBJECT_STATUS_THREAD: Treat the object instance creation as a normal object, but mark it as a java.lang.Thread .

  • OBJECT_STATUS_CLASS: Treat the object instance creation as loading a class instead of instantiating an object and use clsidx as the class table slot value that defines the class.

  • OBJECT_STATUS_ARRAY: Treat the object instance creation as a dimension of an array class instead of instantiating an object of the requested class.

    Plus a fifth for internal use in this function only:

  • OBJECT_STATUS_SUBARRAY: used internally to flag that this object is a subset of a larger array. DO NOT USE this modifier!

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

All fields (or array components) are set to zeroes per JVM spec.

Notice that standard practice is to do new ArrayType[][][] and initialize one dimension at a time. This function can certainly operate in this way, simply set arraydims to 1. But it can initialize a multi-dimensional array all at once.

Use a simple circular slot allocation mechanism to report where most recent object 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, return a jvm_object_hash_null, else the object hash value of the slot.

Even though this function makes types of two recursive calls to itself, there is very little local storage allocated on the stack, and that is mainly fragmented into the if() blocks where such storage is used. Therefore, even though this function may recurse for either (a) number of array dimensions, or (b) number of superclasses, in depth, there should never be any real machine stack overflow problems unless the stack is either, (a) unnaturally restricted to a very small size or, (b) a class file is not checked for CONSTANT_MAX_ARRAY_DIMS or, (c) test for superclass circularity is not working properly or, (d) a class has zillions of legitimate superclasses, such as could be created by an automated JVM regression tester.

Parameters:
special_obj Bit-mapped request for various special considerations for object construction. If not needed, use OBJECT_STATUS_EMPTY. If used, the values are:

Parameters:
pcfs Pointer to ClassFile area.
clsidx Class table index for class object linkage.
arraydims If this is an instance of an array object, specifies the number of array dimensions. Always use LOCAL_CONSTANT_NO_ARRAY_DIMS for non-arrays, that is, when OBJECT_STATUS_ARRAY is not set.
arraylength Array of number of elements in each array dimension. Only meaningful when OBJECT_STATUS_ARRAY is set. Okay to be zero in the first dimension, meaning no data in the object's arraydata member (rnull instead).
run_init_ When rtrue, run the object's <init> method with default parameters, otherwise rfalse.
thridx Thread table index associated with this java.lang.Thread object. Meaningful only when OBJECT_STATUS_THREAD is set or when run_init_ is rtrue.
Returns:
Object hash value of allocation. Throw error if no slots.
Exceptions:
JVMCLASS_JAVA_LANG_OUTOFMEMORYERROR if no object slots are available.
JVMCLASS_JAVA_LANG_UNSUPPORTEDCLASSVERSIONERROR if there is an unrecognized array base type.
< This object is a class definition instead of an object instance

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

< Object is an array instead of an object instance

< Primative for java.lang.Class < an instance of class '/class/name'

< Object is an array instead of an object instance

< This is a subset of an array, that is, of smaller dimension

Todo:
case needs testing: 0 == arraylength[0]
< Signed byte

< Unicode character

< Double-precision floating-point value

< Single-precision floating-point value

< Integer

< Long integer

< an instance of class '/class/name'

< Signed short

< Boolean, true or false

< Object is an array instead of an object instance

< This is a subset of an array, that is, of smaller dimension

< Object is a java/Lang/Thread < Object is a java/Lang/Thread < References java.lang.Object < Object is a java/Lang/Thread < This slot is available for use

< Not stated in spec, but implied

< NULL object (only 1 exists in normal use, any else besides the JVMCFG_NULL_OBJECT is an object slot now being initialized.)

< (Not in this section of spec, but very relevant)

Definition at line 545 of file object.c.

Referenced by opcode_load_run_throwable(), and opcode_run().

rvoid object_instance_finalize jvm_object_hash  objhash,
jvm_thread_index  thridx
 

Finalize an object instance before deletion.

This invokes an object's finalize() method, if declared, on the specified thread, or on the system thread if jvm_thread_index_null thread given.

Parameters:
objhash Object hash of object to finalize.
thridx Thread table index of thread to run finalize() on.
Returns:
rvoid
< This slot contains an object

< null-terminated string form of METHOD_CHAR_OPEN_PARM

< null-terminated string form of METHOD_CHAR_OPEN_PARM

< null-terminated string form of METHOD_CHAR_VOID

< null-terminated string form of METHOD_CHAR_OPEN_PARM

< null-terminated string form of METHOD_CHAR_OPEN_PARM

< null-terminated string form of METHOD_CHAR_VOID

Definition at line 871 of file object.c.

References jvm_object_hash_null, JVMCFG_MAX_OBJECTS, OBJECT, OBJECT_OBJECT_LINKAGE, OBJECT_STATUS_INUSE, rnull, and rtrue.

rboolean object_locate_pcfs jvm_object_hash  objhash  ) 
 

Check whether or not a class file data area is used by at least one other object besides this one.

If a jvm_table_linkage.pcfs pointer is rnull, that means that that object has probably already run this function from object_instance_delete(), having found that at least one other object was using this class data. After all other objects have cleared out that pointer, there will only be one reference, and that is the one from this object. Upon return to object_instance_delete(), call classfile_unload_classdata() and clear the pointer to rnull, thus completing the unload process for the class file data area and all its object slot pointers.

Parameters:
objhash Object hash of object to unload its class data
Returns:
rtrue if another object is using this class file, otherwise rfalse.
< This slot contains an object

< This slot contains an object

< This slot contains an object

Definition at line 930 of file object.c.

jvm_object_hash object_instance_delete jvm_object_hash  objhash,
rboolean  rmref
 

Un-reserve a slot from the object area.

This is the reverse of the process of object_instance_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.

The object_instance_finalize() function MUST be run before calling this function!

Parameters:
objhash Object hash value of allocation.
rmref rtrue if object references should be removed, which is NOT SO during JVM shutdown. Regardless of this value, class references are always removed.
Returns:
Same as input if slot was freed, else jvm_object_hash_null.
< This slot contains an object

Todo:
Is the java.lang.Object.finalize() method (or its subclass) invoked by the actual Java code when an object reference is removed? Is this a GC function? Where should this method be called when tearing down this object?
< Object is an array instead of an object instance

< This is a subset of an array, that is, of smaller dimension

< Object is an array instead of an object instance

< This is a subset of an array, that is, of smaller dimension

< This slot contains an object

< This slot contains an object

Definition at line 1016 of file object.c.

References GC_OBJECT_RMREF_FROM_OBJECT, and OBJECT.

rvoid object_shutdown  ) 
 

Shut down the object area of the JVM model after JVM execution.

See also comments on why there are two stages of class shutdown, class_shutdown_1() and class_shutdown_2().

Parameters: rvoid

Returns:
rvoid
< This slot contains an object

< This slot contains an object

< This slot contains an object

< NULL object (only 1 exists in normal use, any else besides the JVMCFG_NULL_OBJECT is an object slot now being initialized.)

Definition at line 1176 of file object.c.


Variable Documentation

char* object_c_copyright = "\0" "$URL: https://svn.apache.org/path/name/object.c $ $Id: object.c 0 09/28/2005 dlydick $" " " "Copyright 2005 The Apache Software Foundation or its licensors, as applicable." [static]
 

Definition at line 43 of file object.c.


Generated on Fri Sep 30 18:50:13 2005 by  doxygen 1.4.4