You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ge...@apache.org on 2005/10/08 06:29:29 UTC
svn commit: r307257 [13/24] - in
/incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm: ./ bootJVM/
bootJVM/jni/ bootJVM/jni/src/ bootJVM/jni/src/gnu/
bootJVM/jni/src/gnu/classpath/ bootJVM/jni/src/gnu/classpath/0.16/
bootJVM/jni/src/gnu/classpath...
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src/gc_stub.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src/gc_stub.c?rev=307257&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src/gc_stub.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src/gc_stub.c Fri Oct 7 21:27:56 2005
@@ -0,0 +1,901 @@
+/*!
+ * @file gc_stub.c
+ *
+ * @brief JVM @b stub garbage collector,
+ * performs role of @c @b System.gc() .
+ *
+ * The logic of these structures and functions is empty, pending
+ * a memory allocation and garbage collection design for the project.
+ *
+ * This is the first of hopefully a number of garbage collection
+ * schemes. Others should be named @b gc_somename.c .
+ *
+ * The common header file @link jvm/src/gc.h gc.h@endlink defines
+ * the prototypes for all garbage collection implementations by way
+ * of the @link #CONFIG_GC_TYPE_STUB CONFIG_GC_TYPE_xxx@endlink
+ * symbol definitions.
+ *
+ *
+ * @section Control
+ *
+ * \$URL: https://svn.apache.org/path/name/gc_stub.c $ \$Id: gc_stub.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.
+ *
+ * @section Reference
+ *
+ */
+
+#include "arch.h"
+ARCH_COPYRIGHT_APACHE(gc_stub, c, "$URL: https://svn.apache.org/path/name/gc_stub.c $ $Id: gc_stub.c 0 09/28/2005 dlydick $");
+
+#if defined(CONFIG_GC_TYPE_STUB) || defined(CONFIG_COMPILE_ALL_OPTIONS)
+
+
+#include "jvmcfg.h"
+#include "classfile.h"
+#include "jvm.h"
+
+/*!
+ * @name Garbage collection accounting areas
+ *
+ * @brief Type definition for references to garbage collection
+ * in several major JVM structure areas, namely classes,
+ * objects, and stack frames.
+ *
+ */
+
+/*@{ */ /* Begin grouped definitions */
+
+/*!
+ * @struct gc_class_stub
+ *
+ * @brief Type definition for references to garbage collection
+ * in Java classes.
+ */
+
+typedef struct
+{
+ rint dummy; /*!< place holder for implementation details. */
+
+} gc_class_stub;
+
+
+/*!
+ * @struct gc_object_stub
+ *
+ * @brief Type definition for references to garbage collection
+ * in Java objects.
+ */
+
+typedef struct
+{
+ rint dummy; /*!< place holder for implementation details. */
+
+} gc_object_stub;
+
+
+/*!
+ * @struct gc_stack_stub
+ *
+ * @brief Type definition for references to garbage collection
+ * in Java stacks.
+ */
+
+typedef struct
+{
+ rint dummy; /*!< place holder for implementation details. */
+
+} gc_stack_stub;
+
+/*@} */ /* End of grouped definitions */
+
+
+/*!
+ * @brief Initialize garbage collection
+ *
+ *
+ * @b Parameters: @link #rvoid rvoid@endlink
+ *
+ *
+ * @returns @link #rvoid rvoid@endlink
+ *
+ */
+rvoid gc_init_stub()
+{
+ /* Nothing to do in this model */
+
+ return;
+
+} /* END of gc_init_stub() */
+
+
+/*!
+ * @brief Review collection status of all objects and clean them up.
+ *
+ * Scan through object table for objects that need
+ * be deallocated and free up those resources for
+ * reuse by the JVM.
+ *
+ *
+ * @param rmref @link #rtrue rtrue@endlink when class and object
+ * references are to be removed during processing.
+ * This is @link #rfalse rfalse@endlink during
+ * JVM shutdown.
+ *
+ *
+ * @returns @link #rvoid rvoid@endlink
+ *
+ */
+
+rvoid gc_run_stub(rboolean rmref)
+{
+ jvm_class_index clsidx;
+
+ for (clsidx = jvm_class_index_null;
+ clsidx < JVMCFG_MAX_CLASSES;
+ clsidx++)
+ {
+ rushort status = CLASS(clsidx).status;
+
+ /* Skip free object table slots */
+ if (!(CLASS_STATUS_INUSE & status))
+ {
+ continue;
+ }
+
+ /* Skip null slots (the JVMCFG_NULL_CLASS and any slot that
+ is currently being intialized. */
+ if (CLASS_STATUS_NULL & status)
+ {
+ continue;
+ }
+
+ /* Look only at slots marked as ready for garbage collection */
+ if (CLASS_STATUS_GCREQ & status)
+ {
+ /*! @todo Write the object GC algorithm */
+ continue;
+ }
+
+ } /* for clsidx */
+
+ jvm_object_hash objhash;
+
+ for (objhash = jvm_object_hash_null;
+ objhash < JVMCFG_MAX_OBJECTS;
+ objhash++)
+ {
+ rushort status = OBJECT(objhash).status;
+
+ /* Skip free object table slots */
+ if (!(OBJECT_STATUS_INUSE & status))
+ {
+ continue;
+ }
+
+ /* Skip null slots (the JVMCFG_NULL_OBJECT and any slot that
+ is currently being intialized). */
+ if (OBJECT_STATUS_NULL & status)
+ {
+ continue;
+ }
+
+ /* Look only at slots marked as ready for garbage collection */
+ if (OBJECT_STATUS_GCREQ & status)
+ {
+ /*! @todo Write the object GC algorithm */
+ continue;
+ }
+
+ } /* for objhash */
+
+ /* Done with this pass */
+ return;
+
+} /* END of gc_run_stub() */
+
+
+/*!
+ * @brief Start up garbage collection for a class.
+ *
+ * Initialize garbage collection for a new class static
+ * instance, as set up in class_static_new(). The reverse of
+ * gc_class_delete_stub().
+ *
+ *
+ * @param clsidxNEW Class table index of new class static instance.
+ *
+ *
+ * @returns @link #rtrue rtrue@endlink if garbage
+ * collection was initialized for this class static instance,
+ * otherwise @link #rfalse rfalse@endlink.
+ *
+ *
+ * @throws JVMCLASS_JAVA_LANG_INTERNALERROR
+ @link #JVMCLASS_JAVA_LANG_INTERNALERROR
+ if null class index or if a garbage collection
+ accounting area has already been
+ allocated for this class@endlink.
+ *
+ *
+ */
+rboolean gc_class_new_stub(jvm_class_index clsidxNEW)
+{
+ return(rfalse);
+
+} /* END of gc_class_new_stub() */
+
+
+/*!
+ * @brief Shut down and restart garbage collection for a class.
+ *
+ * Reinitialize garbage collection for a reloaded class static instance,
+ * as set up in class_reload().
+ *
+ *
+ * @param clsidxOLD Class table index of old class static instance.
+ *
+ * @param clsidxNEW Class table index of reloaded class static
+ * instance.
+ *
+ *
+ * @returns @link #rtrue rtrue@endlink if garbage collection was
+ * reinitialized for this reloaded class static instance,
+ * otherwise @link #rfalse rfalse@endlink.
+ *
+ *
+ * @throws JVMCLASS_JAVA_LANG_INTERNALERROR
+ @link #JVMCLASS_JAVA_LANG_INTERNALERROR
+ if null target class index@endlink.
+ *
+ */
+rboolean gc_class_reload_stub(jvm_class_index clsidxOLD,
+ jvm_class_index clsidxNEW)
+{
+ return(rfalse);
+
+} /* END of gc_class_reload_stub() */
+
+
+/*!
+ * @brief Add a class static reference to a class.
+ *
+ * Mark class as having another class static instance reference to it,
+ * namely a @b lower_dim_array or @b initiating_ClassLoader or
+ * @b defining_ClasslLoader The reverse of
+ * gc_class_rmref_from_class_stub().
+ *
+ *
+ * @param clsidxFROM Class table index of source class static instance.
+ * If @link #jvm_class_index_null
+ jvm_class_index_null@endlink, this is the class
+ * table entry itself.
+ *
+ * @param clsidxTO Class table index of target class static instance.
+ *
+ *
+ * @returns @link #rtrue rtrue@endlink if class static instance was
+ * marked, otherwise @link #rfalse rfalse@endlink.
+ *
+ *
+ * @throws JVMCLASS_JAVA_LANG_INTERNALERROR
+ @link #JVMCLASS_JAVA_LANG_INTERNALERROR
+ if null target class index@endlink.
+ *
+ */
+rboolean gc_class_mkref_from_class_stub(jvm_class_index clsidxFROM,
+ jvm_class_index clsidxTO)
+{
+ return(rfalse);
+
+} /* END of gc_class_mkref_from_class_stub() */
+
+
+/*!
+ * @brief Add an object instance reference to a class.
+ *
+ * Mark class as having another class object instance reference to it,
+ * namely where OBJECT_STATUS_CLASS is set for that object. (Usually
+ * marked only one time over the life of the class.)
+ * The reverse of gc_class_rmref_from_object_stub().
+ *
+ *
+ * @param objhashFROM Object hash of source object instance.
+ *
+ * @param clsidxTO Class table index of target class static instance
+ *
+ *
+ * @returns @link #rtrue rtrue@endlink if class static instance was
+ * marked, otherwise @link #rfalse rfalse@endlink.
+ *
+ *
+ * @throws JVMCLASS_JAVA_LANG_INTERNALERROR
+ @link #JVMCLASS_JAVA_LANG_INTERNALERROR
+ if null target class index@endlink.
+ *
+ */
+rboolean gc_class_mkref_from_object_stub(jvm_object_hash objhashFROM,
+ jvm_class_index clsidxTO)
+{
+ return(rfalse);
+
+} /* END of gc_class_mkref_from_object_stub() */
+
+
+/*!
+ * @brief Remove a class static reference from a class.
+ *
+ * Unmark class as having a class static instance reference to it.
+ * The reverse of gc_class_mkref_from_class_stub().
+ *
+ *
+ * @param clsidxFROM Class table index of source class static instance.
+ * If @link #jvm_class_index_null
+ jvm_class_index_null@endlink, this is the class
+ * table entry itself.
+ *
+ * @param clsidxTO Class table index of target class static instance.
+ *
+ *
+ * @returns @link #rtrue rtrue@endlink if class static instance was
+ * unmarked, otherwise @link #rfalse rfalse@endlink.
+ *
+ *
+ * @throws JVMCLASS_JAVA_LANG_INTERNALERROR
+ @link #JVMCLASS_JAVA_LANG_INTERNALERROR
+ if null target class index@endlink.
+ *
+ */
+rboolean gc_class_rmref_from_class_stub(jvm_class_index clsidxFROM,
+ jvm_class_index clsidxTO)
+{
+ return(rfalse);
+
+} /* END of gc_class_rmref_from_class_stub() */
+
+
+/*!
+ * @brief Remove an object instance reference from a class.
+ *
+ * Unmark class as having a class object reference to it, namely
+ * where OBJECT_STATUS_CLASS is set for that object. (Usually marked
+ * only one time over the life of the class, so this will effectively
+ * mark the class itself as being ready for garbage collection.)
+ * The reverse of gc_class_mkref_stub().
+ *
+ *
+ * @param objhashFROM Object hash of source object instance.
+ *
+ * @param clsidxTO Class table index of target class static instance
+ *
+ *
+ * @returns @link #rtrue rtrue@endlink if class static instance was
+ * unmarked, otherwise @link #rfalse rfalse@endlink.
+ *
+ *
+ * @throws JVMCLASS_JAVA_LANG_INTERNALERROR
+ @link #JVMCLASS_JAVA_LANG_INTERNALERROR
+ if null target class index@endlink.
+ *
+ */
+rboolean gc_class_rmref_from_object_stub(jvm_object_hash objhashFROM,
+ jvm_class_index clsidxTO)
+{
+ return(rfalse);
+
+} /* END of gc_class_rmref_from_object_stub() */
+
+
+/*!
+ * @brief Add a class static field reference to a class.
+ *
+ * Mark class static field as being a reference type (typically
+ * after loading the class). The reverse of
+ * gc_class_field_rmref_stub().
+ *
+ *
+ * @param clsidxTO Class table index of target class static instance.
+ *
+ * @param csflidxTO Class static field lookup index to field in
+ * target class static instance.
+ *
+ *
+ * @returns @link #rtrue rtrue@endlink if class static field was marked,
+ * otherwise @link #rfalse rfalse@endlink.
+ *
+ *
+ * @throws JVMCLASS_JAVA_LANG_INTERNALERROR
+ @link #JVMCLASS_JAVA_LANG_INTERNALERROR
+ if null target class index@endlink.
+ *
+ */
+rboolean gc_class_field_mkref_stub(jvm_class_index clsidxTO,
+ jvm_field_lookup_index csflidxTO)
+{
+ return(rfalse);
+
+} /* END of gc_class_field_mkref_stub() */
+
+
+/*!
+ * @brief Remove a class static field reference from a class.
+ *
+ * Mark class static field as @e not being a reference type (typically
+ * before unloading the class. The reverse of
+ * gc_class_field_mkref_stub().
+ *
+ *
+ * @param clsidxTO Class table index of target class static instance.
+ *
+ * @param csflidxTO Class static field lookup index to field in
+ * target class.
+ *
+ *
+ * @returns @link #rtrue rtrue@endlink if class static field was marked,
+ * otherwise @link #rfalse rfalse@endlink.
+ *
+ *
+ * @throws JVMCLASS_JAVA_LANG_INTERNALERROR
+ @link #JVMCLASS_JAVA_LANG_INTERNALERROR
+ if null class index@endlink.
+ *
+ */
+rboolean gc_class_field_rmref_stub(jvm_class_index clsidxTO,
+ jvm_field_lookup_index csflidxTO)
+{
+ return(rfalse);
+
+} /* END of gc_class_field_rmref_stub() */
+
+
+/*!
+ * @brief Garbage collect a class static instance.
+ *
+ * Finalize garbage collection for a class static instance that will
+ * no longer be used, as set up in class_static_delete(). If there
+ * are any outstanding references to this class, those must first
+ * be removed, at which time gc_run_stub() will perform the
+ * finalization instead. The reverse of gc_class_new_stub().
+ *
+ * @note Since this function is the reverse of gc_class_new_stub(),
+ * the @link #rclass.pgarbage rclass.pgarbage@endlink pointer must
+ * be freed by @link #HEAP_DATA_FREE() HEAP_DATA_FREE@endlink.
+ *
+ *
+ * @param clsidxOLD Class table index of defunct class static
+ * instance.
+ *
+ * @param delete_class If @link #rtrue rtrue@endlink, attempt
+ * class_static_delete() when finished with
+ * garbage collection.
+ *
+ *
+ * @returns @link #rtrue rtrue@endlink if garbage collection was
+ * finalized for this class static instance, otherwise
+ * @link #rfalse rfalse@endlink.
+ *
+ *
+ * @throws JVMCLASS_JAVA_LANG_INTERNALERROR
+ @link #JVMCLASS_JAVA_LANG_INTERNALERROR
+ if null source source class index@endlink.
+ *
+ */
+rboolean gc_class_delete_stub(jvm_class_index clsidxOLD,
+ rboolean delete_class)
+{
+ return(rfalse);
+
+} /* END of gc_class_delete_stub() */
+
+
+/*!
+ * @brief Start up garbage collection for an object.
+ *
+ * Initialize garbage collection for a new object instance, as
+ * set up in object_new(). The reverse of gc_object_delete_stub().
+ *
+ *
+ * @param objhashNEW Object table hash of new object instance.
+ *
+ *
+ * @returns @link #rtrue rtrue@endlink if garbage collection was
+ * initialized for this object instance, otherwise
+ * @link #rfalse rfalse@endlink.
+ *
+ *
+ * @throws JVMCLASS_JAVA_LANG_INTERNALERROR
+ @link #JVMCLASS_JAVA_LANG_INTERNALERROR
+ if null object hash@endlink.
+ *
+ */
+rboolean gc_object_new_stub(jvm_object_hash objhashNEW)
+{
+ return(rfalse);
+
+} /* END of gc_object_new_stub() */
+
+
+/*!
+ * @brief Add a class static reference to an object.
+ *
+ * Mark object as having another class static instance reference to it.
+ * The reverse of gc_object_rmref_from_class_stub().
+ *
+ *
+ * @param clsidxFROM Class table index of source class static instance.
+ *
+ * @param objhashTO Object table hash of target object instance
+ *
+ *
+ * @returns @link #rtrue rtrue@endlink if object instance was marked,
+ * otherwise @link #rfalse rfalse@endlink.
+ *
+ *
+ * @throws JVMCLASS_JAVA_LANG_INTERNALERROR
+ @link #JVMCLASS_JAVA_LANG_INTERNALERROR
+ if null target object hash@endlink.
+ *
+ */
+rboolean gc_object_mkref_from_class_stub(jvm_class_index clsidxFROM,
+ jvm_object_hash objhashTO)
+{
+ return(rfalse);
+
+} /* END of gc_object_mkref_from_class_stub() */
+
+
+/*!
+ * @brief Add an object instance reference to an object.
+ *
+ * Mark object as having another object instance reference to it.
+ * The reverse of gc_object_rmref_from_object_stub().
+ *
+ *
+ * @param objhashFROM Object table hash of source object instance.
+ * If @link #jvm_object_hash_null
+ jvm_object_hash_null@endlink, this is the object
+ * table entry itself.
+ *
+ * @param objhashTO Object table hash of target object instance
+ *
+ *
+ * @returns @link #rtrue rtrue@endlink if object instance was marked,
+ * otherwise @link #rfalse rfalse@endlink.
+ *
+ *
+ * @throws JVMCLASS_JAVA_LANG_INTERNALERROR
+ @link #JVMCLASS_JAVA_LANG_INTERNALERROR
+ if null target object hash@endlink.
+ *
+ */
+rboolean gc_object_mkref_from_object_stub(jvm_object_hash objhashFROM,
+ jvm_object_hash objhashTO)
+{
+ return(rfalse);
+
+} /* END of gc_object_mkref_from_object_stub() */
+
+
+/*!
+ * @brief Remove a class static reference from an object.
+ *
+ * Unmark object as having a class static instance reference to it.
+ * The reverse of gc_object_mkref_from_class_stub().
+ *
+ *
+ * @param clsidxFROM Class table index of source class static instance.
+ *
+ * @param objhashTO Object table hash of target object instance
+ *
+ *
+ * @returns @link #rtrue rtrue@endlink if class static instance was
+ * unmarked, otherwise @link #rfalse rfalse@endlink.
+ *
+ *
+ * @throws JVMCLASS_JAVA_LANG_INTERNALERROR
+ @link #JVMCLASS_JAVA_LANG_INTERNALERROR
+ if null target object hash@endlink.
+ *
+ */
+rboolean gc_object_rmref_from_class_stub(jvm_class_index clsidxFROM,
+ jvm_object_hash objhashTO)
+{
+ return(rfalse);
+
+} /* END of gc_object_rmref_from_class_stub() */
+
+
+/*!
+ * @brief Remove an object instance reference from an object.
+ *
+ * Unmark object as having an object instance reference to it.
+ * The reverse of gc_object_mkref_from_object_stub().
+ *
+ *
+ * @param objhashFROM Object table hash of source object instance.
+ * If @link #jvm_object_hash_null
+ jvm_object_hash_null@endlink, this is the object
+ * table entry itself.
+ *
+ * @param objhashTO Object table hash of target object instance
+ *
+ *
+ * @returns @link #rtrue rtrue@endlink if object instance was
+ * unmarked, otherwise @link #rfalse rfalse@endlink.
+ *
+ *
+ * @throws JVMCLASS_JAVA_LANG_INTERNALERROR
+ @link #JVMCLASS_JAVA_LANG_INTERNALERROR
+ if null target object hash@endlink.
+ *
+ */
+rboolean gc_object_rmref_from_object_stub(jvm_object_hash objhashFROM,
+ jvm_object_hash objhashTO)
+{
+ return(rfalse);
+
+} /* END of gc_object_rmref_from_object_stub() */
+
+
+/*!
+ * @brief Add an object instance field reference to an object.
+ *
+ * Mark object instance field as being a reference type (typically
+ * after loading the class and instantiating an object of that
+ * class type). The reverse of gc_object_field_rmref_stub().
+ *
+ *
+ * @param objhashTO Object table hash of target object instance.
+ *
+ * @param oiflidxTO Object instance field lookup index to field
+ * in target object instance.
+ *
+ *
+ * @returns @link #rtrue rtrue@endlink if object instance field was
+ * marked, otherwise @link #rfalse rfalse@endlink.
+ *
+ *
+ * @throws JVMCLASS_JAVA_LANG_INTERNALERROR
+ @link #JVMCLASS_JAVA_LANG_INTERNALERROR
+ if null target object hash@endlink.
+ *
+ */
+rboolean gc_object_field_mkref_stub(jvm_object_hash objhashTO,
+ jvm_field_lookup_index oiflidxTO)
+{
+ return(rfalse);
+
+} /* END of gc_object_field_mkref_stub() */
+
+
+/*!
+ * @brief Add an object instance field reference to an object.
+ *
+ * Mark object instance field as @e not being a reference type any more
+ * (typically before unloading the class). The reverse of
+ * gc_object_field_rmref_stub().
+ *
+ *
+ * @param objhashTO Object table hash of target object instance.
+ *
+ * @param oiflidxTO Object instance field lookup index to field
+ * in target object instance.
+ *
+ *
+ * @returns @link #rtrue rtrue@endlink if class static field was
+ * unmarked, otherwise @link #rfalse rfalse@endlink.
+ *
+ *
+ * @throws JVMCLASS_JAVA_LANG_INTERNALERROR
+ @link #JVMCLASS_JAVA_LANG_INTERNALERROR
+ if null target object hash@endlink.
+ *
+ */
+rboolean gc_object_field_rmref_stub(jvm_object_hash objhashTO,
+ jvm_field_lookup_index oiflidxTO)
+{
+ return(rfalse);
+
+} /* END of gc_object_field_rmref_stub() */
+
+
+/*!
+ * @brief Garbage collect an object instance.
+ *
+ * Finalize garbage collection for an object instance that will no
+ * longer be used, as set up in object_instance_delete(). If there
+ * are any outstanding references to this class, those must first
+ * be removed, at which time gc_run_stub() will perform the
+ * finalization instead. The reverse of gc_object_new_stub().
+ *
+ * @note Since this function is the reverse of gc_object_new_stub(), the
+ * @link #rclass.pgarbage rclass.pgarbage@endlink pointer must be
+ * freed by @link #HEAP_DATA_FREE() HEAP_DATA_FREE@endlink.
+ *
+ *
+ * @param objhashOLD Object table hash of defunct object instance.
+ *
+ *
+ * @returns @link #rtrue rtrue@endlink if garbage collection was
+ * finalized for this object instance, otherwise
+ * @link #rfalse rfalse@endlink.
+ *
+ *
+ * @throws JVMCLASS_JAVA_LANG_INTERNALERROR
+ @link #JVMCLASS_JAVA_LANG_INTERNALERROR
+ if null object hash@endlink.
+ *
+ */
+rboolean gc_object_delete_stub(jvm_object_hash objhashOLD)
+{
+ return(rfalse);
+
+} /* END of gc_object_delete_stub() */
+
+
+/*!
+ * @brief Start up garbage collection for a new Java virtual
+ * method stack frame.
+ *
+ * Initialize garbage collection for a new stack frame for a
+ * virtual Java method invocation, as set up in PUSH_GC().
+ * The reverse of gc_stack_delete_stub().
+ *
+ *
+ * @param thridxNEW Thread table index to thread that is setting
+ * up a new stack frame for a method invocation.
+ *
+ * @param num_locals Number of local variables in this method.
+ *
+ *
+ * @returns Pointer to (gc_stack) for this object instance
+ *
+ *
+ * @attention Due to the fact that there may be any number of garbage
+ * collection algorithms implemented for the JVM, and with
+ * the need to keep the API to the GC system constant, this
+ * return value is @b not defined to be related to
+ * any particular type of GC. Instead it is a simple
+ * @link #rvoid rvoid@endlink pointer.
+ *
+ */
+rvoid *gc_stack_new_stub(jvm_thread_index thridxNEW, rint num_locals)
+{
+ return((rvoid *) rnull);
+
+} /* END of gc_stack_new_stub() */
+
+
+/*!
+ * @brief Add local variable reference to an object.
+ *
+ * Mark object as having another local variable instance reference
+ * to it. The reverse of gc_stack_rmref_stub().
+ *
+ *
+ * @param thridxFROM Thread table index to thread that is setting
+ * up new stack from for a method invocation.
+ *
+ * @param frmidxTO Index into current frame of local variable
+ * that is an object reference.
+ *
+ *
+ * @returns @link #rtrue rtrue@endlink if object instance was marked,
+ * otherwise @link #rfalse rfalse@endlink.
+ *
+ *
+ * @throws JVMCLASS_JAVA_LANG_INTERNALERROR
+ @link #JVMCLASS_JAVA_LANG_INTERNALERROR
+ if null thread index@endlink.
+ *
+ */
+rboolean gc_stack_mkref_from_jvm_stub(jvm_thread_index thridxFROM,
+ jint frmidxTO)
+{
+ return(rfalse);
+
+} /* END of gc_stack_mkref_from_jvm_stub() */
+
+
+/*!
+ * @brief Remove local variable reference from an object.
+ *
+ * Unmark object from having another local variable instance
+ * reference to it. The reverse of gc_stack_mkref_stub().
+ *
+ *
+ * @param thridxFROM Thread table index to thread that is setting
+ * up new stack from for a method invocation.
+ *
+ * @param frmidxTO Index into current frame of local variable
+ * that is an object reference.
+ *
+ *
+ * @returns @link #rtrue rtrue@endlink if object instance was marked,
+ * otherwise @link #rfalse rfalse@endlink.
+ *
+ *
+ * @throws JVMCLASS_JAVA_LANG_INTERNALERROR
+ @link #JVMCLASS_JAVA_LANG_INTERNALERROR
+ if null thread index@endlink.
+ *
+ */
+rboolean gc_stack_rmref_from_jvm_stub(jvm_thread_index thridxFROM,
+ jint frmidxTO)
+{
+ return(rfalse);
+
+} /* END of gc_stack_rmref_from_jvm_stub() */
+
+
+/*!
+ * @brief Garbage collect a Java virtual method stack frame.
+ *
+ * Finalize garbage collection for a stack frame that will no
+ * longer be used by a virtual Java method, as set up in PUSH_GC().
+ * This function is called from POP_GC(). It is the reverse
+ * of gc_stack_new_stub().
+ *
+ *
+ * @param thridxOLD Thread table index to thread that is tearing
+ * down an old stack frame from a method invocation.
+ *
+ * @param ppgcs Pointer to GC stack area pointer for this frame
+ *
+ * @param plocal_teardown Pointer to local area of partially popped
+ * frame.
+ *
+ *
+ * @returns @link #rtrue rtrue@endlink if garbage collection was
+ * finalized for this method return, otherwise
+ * @link #rfalse rfalse@endlink.
+ *
+ *
+ * @throws JVMCLASS_JAVA_LANG_INTERNALERROR
+ @link #JVMCLASS_JAVA_LANG_INTERNALERROR
+ if null thread index@endlink.
+ *
+ *
+ * @attention Due to the fact that there may be any number of garbage
+ * collection algorithms implemented for the JVM, and with
+ * the need to keep the API to the GC system constant, the
+ * parameter @b ppgcs is @b not defined to be related to
+ * any particular type of GC. Instead it is a simple
+ * @link #rvoid rvoid@endlink pointer.
+ *
+ */
+rboolean gc_stack_delete_stub(jvm_thread_index thridxOLD,
+ rvoid **ppgcs,
+ jint *plocal_teardown)
+{
+ return(rfalse);
+
+} /* END of gc_stack_delete_stub() */
+
+#endif /* CONFIG_GC_TYPE_STUB || CONFIG_OPTIONS_COMPILE_ALL */
+
+
+/* EOF */
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src/heap.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src/heap.h?rev=307257&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src/heap.h (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src/heap.h Fri Oct 7 21:27:56 2005
@@ -0,0 +1,123 @@
+#ifndef _heap_h_included_
+#define _heap_h_included_
+
+/*!
+ * @file heap.h
+ *
+ * @brief Heap management API
+ *
+ * The two examples of modular development here are the two heap
+ * management schemes,
+ * @link jvm/src/heap_simple.c heap_simple.c@endlink
+ * and @link jvm/src/heap_bimodal.c heap_bimodal.c@endlink.
+ * This common header file defines the prototypes for both by way
+ * of the @link #CONFIG_HEAP_TYPE_SIMPLE CONFIG_HEAP_TYPE_xxx@endlink
+ * symbol definition.
+ *
+ * Each heap allocation algorithm will have a section just like
+ * those defined here in this file so that these macros will expand
+ * to point to the API as implemented by that algoritm. Simply
+ * replicate one of the definition sections and change the function
+ * names from @b _simple (et al) to @b _newalgorithm .
+ *
+ *
+ * @section Control
+ *
+ * \$URL: https://svn.apache.org/path/name/heap.h $ \$Id: heap.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.
+ *
+ * @section Reference
+ *
+ */
+
+ARCH_COPYRIGHT_APACHE(heap, h, "$URL: https://svn.apache.org/path/name/heap.h $ $Id: heap.h 0 09/28/2005 dlydick $");
+
+#ifdef CONFIG_HEAP_TYPE_SIMPLE
+/*!
+ * @name Simple heap model definitions
+ *
+ * @brief Expand the @b HEAP_xxx() macros into the simple heap model as
+ * implemented by @link jvm/src/heap_simple.c heap_simple.c@endlink.
+ *
+ */
+
+/*@{ */ /* Begin grouped definitions */
+
+#define HEAP_INIT heap_init_simple
+#define HEAP_SHUTDOWN heap_shutdown_simple
+#define HEAP_GET_METHOD heap_get_method_simple
+#define HEAP_GET_STACK heap_get_stack_simple
+#define HEAP_GET_DATA heap_get_data_simple
+#define HEAP_FREE_METHOD heap_free_method_simple
+#define HEAP_FREE_STACK heap_free_stack_simple
+#define HEAP_FREE_DATA heap_free_data_simple
+#define HEAP_GET_ERROR heap_get_error_simple
+
+/*@} */ /* End of grouped definitions */
+#endif
+
+#ifdef CONFIG_HEAP_TYPE_BIMODAL
+/*!
+ * @name Bimodal heap model definitions
+ *
+ * @brief Expand the @b HEAP_xxx() macros into the bimidal heap model as
+ * implemented by
+ * @link jvm/src/heap_bimodal.c heap_bimodal.c@endlink.
+ *
+ */
+
+/*@{ */ /* Begin grouped definitions */
+
+#define HEAP_INIT heap_init_bimodal
+#define HEAP_SHUTDOWN heap_shutdown_bimodal
+#define HEAP_GET_METHOD heap_get_method_bimodal
+#define HEAP_GET_STACK heap_get_stack_bimodal
+#define HEAP_GET_DATA heap_get_data_bimodal
+#define HEAP_FREE_METHOD heap_free_method_bimodal
+#define HEAP_FREE_STACK heap_free_stack_bimodal
+#define HEAP_FREE_DATA heap_free_data_bimodal
+#define HEAP_GET_ERROR heap_get_error_bimodal
+
+/*@} */ /* End of grouped definitions */
+#endif
+
+extern rvoid HEAP_INIT(rvoid);
+extern rvoid HEAP_SHUTDOWN(rvoid);
+
+extern rvoid *HEAP_GET_METHOD(int size, rboolean clrmem_flag);
+extern rvoid *HEAP_GET_STACK(int size, rboolean clrmem_flag);
+extern rvoid *HEAP_GET_DATA(int size, rboolean clrmem_flag);
+
+extern rvoid HEAP_FREE_METHOD(rvoid *heap_block);
+extern rvoid HEAP_FREE_STACK(rvoid *heap_block);
+extern rvoid HEAP_FREE_DATA(rvoid *heap_block);
+
+extern int HEAP_GET_ERROR(rvoid *badptr);
+
+#endif /* _heap_h_included_ */
+
+
+/* EOF */
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src/heap_bimodal.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src/heap_bimodal.c?rev=307257&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src/heap_bimodal.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src/heap_bimodal.c Fri Oct 7 21:27:56 2005
@@ -0,0 +1,847 @@
+/*!
+ * @file heap_bimodal.c
+ *
+ * @brief @b bimodal heap management functions
+ *
+ * This is the second of two implementations of heap management.
+ * It extends the simple malloc/free scheme by adding a single
+ * large allocation for requests smaller tha a certain size.
+ * This was added due to an apparent internal limit in @c @b malloc(3)
+ * or perhaps a kernel limit that after a certain number of
+ * calls and/or bytes of allocation and freeing, returns NULL
+ * for no apparent reason.
+ *
+ * The common header file @link jvm/src/heap.h gc.h@endlink defines
+ * the prototypes for all heap allocation implementations by way
+ * of the @link #CONFIG_HEAP_TYPE_SIMPLE CONFIG_HEAP_TYPE_xxx@endlink
+ * symbol definitions.
+ *
+ *
+ * Here is a note taken from the original project
+ * @link ./README README@endlink file:
+ *
+ * <i>(16) When nearing the end of the initial development, I ran
+ * across what is probably a memory configuration limit on my
+ * Solaris platform, which I did not bother to track down, but
+ * rather work around. It seems that when calling malloc(3C) or
+ * malloc(3MALLOC), after 2,280 malloc() allocations and 612 free()
+ * invocations, there is something under the covers that does a
+ * @b SIGSEGV, and it can happen in either routine. I therefore
+ * extended the heap mechanism to allocate 1M slots of 'n' bytes
+ * for small allocations up to this size. Everything else still
+ * uses malloc(). In this way, I was able to finish development
+ * on the JVM and release it to the ASF in a more timely manner.
+ * In other words, I will let the team fix it! I am not sure that
+ * the real project wants a static 'n + 1' MB data area just
+ * hanging around the runtime just because I did not take time to
+ * tune the system configuration!</i>
+ *
+ * This modified algorithm makes exactly two @b malloc() calls, one for
+ * an array of fixed size slots of (@link #rbyte rbyte@endlink)
+ * and the other for an array of (@link #rboolean rboolean@endlink)
+ * for @link #rtrue rtrue@endlink/@link #rfalse rfalse@endlink on
+ * whether a fixed-size memory slot is in use or not.
+ *
+ *
+ * @section Control
+ *
+ * \$URL: https://svn.apache.org/path/name/heap_bimodal.c $ \$Id: heap_bimodal.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.
+ *
+ * @section Reference
+ *
+ */
+
+#include "arch.h"
+ARCH_COPYRIGHT_APACHE(heap_bimodal, c, "$URL: https://svn.apache.org/path/name/heap_bimodal.c $ $Id: heap_bimodal.c 0 09/28/2005 dlydick $");
+
+#if defined(CONFIG_HEAP_TYPE_BIMODAL) || defined(CONFIG_COMPILE_ALL_OPTIONS)
+
+
+#include <errno.h>
+#include <stdlib.h>
+
+#include "jvmcfg.h"
+#include "exit.h"
+#include "gc.h"
+#include "heap.h"
+#include "jvmclass.h"
+#include "util.h"
+
+
+/*!
+ * @brief Small heap allocation area.
+ *
+ * For allocations up to @b n bytes, use this instead of system
+ * allocation and thus minimize number of calls to @b malloc()
+ * and @b free(). After 2,280 calls to @b malloc(3C) and 612 to
+ * @b free(3C), the library would kick out a @b SIGSEGV for no apparent
+ * reason. Use of @b malloc(3MALLOC) and @b free(3MALLOC) did
+ * the same thing, with @b -lmalloc. Use of @b -lbsdmalloc was
+ * at an even lower number. Therefore, it seems best to delay the
+ * issue (See quotation above from @link ./README README@endlink file.)
+ *
+ * The value of the @link #HEAP_SLOT_SIZE HEAP_SLOT_SIZE@endlink
+ * definition <b>ABSOLUTELY MUST BE A MULTIPLE of 4!!! </b>
+ * (prefer 8 for future 64-bit implementation). This is
+ * <b><code>sizeof(rvoid *)</code></b> and must be such to always
+ * fundamentally avoid @b SIGSEGV on 4-byte accesses.
+ */
+#define HEAP_SLOT_SIZE 160
+
+/*!
+ * @brief Number of slots of this size.
+ *
+ * Any number of slots is possible, up to the reasonable
+ * resource limits of the machine.
+ */
+#define HEAP_NUMBER_OF_SLOTS 1048576
+
+
+/*!
+ * @brief Pointer for physical allocation for slots in use.
+ */
+static rboolean *pheap_slot_in_use;
+
+/*!
+ * @brief Pointer for physical allocation of heap block to manage.
+ */
+static rbyte *pheap_slot;
+
+/*!
+ * @brief Start up heap management methodology.
+ *
+ * In a malloc/free scheme, there is nothing
+ * to do, but here, the two blocks @link #pheap_slot_in_use@endlink
+ * and @link #pheap_slot pheap_slot@endlink must be allocated and
+ * initialized.
+ *
+ *
+ * @b Parameters: @link #rvoid rvoid@endlink
+ *
+ *
+ * @return @link #rvoid rvoid@endlink
+ *
+ */
+rvoid heap_init_bimodal()
+{
+ rlong heapidx;
+
+ /* Set up slot flags */
+ pheap_slot_in_use =
+ malloc(sizeof(rboolean) * HEAP_NUMBER_OF_SLOTS);
+
+ if (rnull == pheap_slot_in_use)
+ {
+ sysErrMsg("heap_init", "Cannot allocate slot flag storage");
+ exit_jvm(EXIT_HEAP_ALLOC);
+/*NOTREACHED*/
+ }
+
+ /* Initialize flag array to @link #rfalse rfalse@endlink */
+ for (heapidx = 0;
+ heapidx < HEAP_NUMBER_OF_SLOTS;
+ heapidx++)
+ {
+ pheap_slot_in_use[heapidx] = rfalse;
+ }
+
+
+ /* Set up slot storage itself, do not need to initialize */
+ pheap_slot =
+ malloc(sizeof(rbyte) *
+ HEAP_SLOT_SIZE *
+ HEAP_NUMBER_OF_SLOTS);
+
+ if (rnull == pheap_slot)
+ {
+ free(pheap_slot_in_use);
+
+ sysErrMsg("heap_init", "Cannot allocate slot storage");
+ exit_jvm(EXIT_HEAP_ALLOC);
+/*NOTREACHED*/
+ }
+
+ /* Declare this module initialized */
+ jvm_heap_initialized = rtrue;
+
+ return;
+
+} /* END of heap_init_bimodal() */
+
+
+/*!
+ * @brief Most recent error code from @c @b malloc(3), for use
+ * by heap_get_error_bimodal().
+ */
+static int heap_last_errno = ERROR0;
+
+
+/*!
+ * @brief Number of calls to @c @b malloc(3).
+ *
+ * One of four global variables providing rudimentary statistics
+ * for heap allocation history.
+ *
+ * @see heap_free_count
+ * @see malloc_free_count
+ * @see slot_free_count
+ */
+static rlong heap_malloc_count = 0;
+
+/*!
+ * @brief Number of calls to @c @b free(3).
+ *
+ * One of four global variables providing rudimentary statistics
+ * for heap allocation history.
+ *
+ * @see heap_malloc_count
+ * @see malloc_free_count
+ * @see slot_free_count
+ */
+static rlong heap_free_count = 0;
+
+/*!
+ * @brief Number of allocations made from pheap_slot.
+ *
+ * One of four global variables providing rudimentary statistics
+ * for heap allocation history.
+ *
+ * @see heap_malloc_count
+ * @see heap_free_count
+ * @see slot_free_count
+ */
+static rlong slot_alloc_count = 0;
+
+/*!
+ * @brief Number of allocations freed from pheap_slot.
+ *
+ * One of four global variables providing rudimentary statistics
+ * for heap allocation history.
+ *
+ * @see heap_malloc_count
+ * @see heap_free_count
+ * @see slot_malloc_count
+ */
+static rlong slot_free_count = 0;
+
+
+/*!
+ * @brief Original heap allocation method that uses
+ * @e only @c @b malloc(3) and @c @b free(3).
+ *
+ *
+ * @param size Number of bytes to allocate
+ *
+ * @param clrmem_flag Set memory to all zeroes
+ * (@link #rtrue rtrue@endlink) or not
+ * (@link #rfalse rfalse@endlink).
+ * If @link #rtrue rtrue@endlink,
+ * clear the allocated block, otherwise
+ * return it with its existing contents.
+ *
+ *
+ * @return (@link #rvoid rvoid@endlink *) to allocated area.
+ * This pointer may be cast to any desired data type. If
+ * size of zero bytes is requested, return
+ * @link #rnull rnull@endlink and let caller croak
+ * on @b SIGSEGV. If no memory is available
+ * or some OS system call error happened, throw error,
+ * but do @e not return.
+ *
+ *
+ * @throws JVMCLASS_JAVA_LANG_OUTOFMEMORYERROR
+ * @link #JVMCLASS_JAVA_LANG_OUTOFMEMORYERROR
+ * if no memory is available@endlink.
+ *
+ * @throws JVMCLASS_JAVA_LANG_INTERNALERROR
+ @link #JVMCLASS_JAVA_LANG_INTERNALERROR
+ * if other allocation error@endlink.
+ *
+ */
+static rvoid *heap_get_common_simple_bimodal(int size,
+ rboolean clrmem_flag)
+{
+ rvoid *rc;
+
+ rc = malloc(size);
+
+ /*
+ * If specific errors are returned, GC could free up some heap,
+ * so run it and try again-- ONCE. If it fails a second time,
+ * so be it. Let the application deal with the problem.
+ */
+ if (rnull == rc)
+ {
+ switch(errno)
+ {
+ case ENOMEM:
+ case EAGAIN:
+ GC_RUN(rtrue);
+ rc = malloc(size);
+
+ if (rnull == rc)
+ {
+ switch(errno)
+ {
+ case ENOMEM:
+ case EAGAIN:
+ exit_throw_exception(EXIT_HEAP_ALLOC,
+ JVMCLASS_JAVA_LANG_OUTOFMEMORYERROR);
+/*NOTREACHED*/
+ default:
+ /*
+ * Preserve errno for later inspection.
+ * By doing it this way, other OS system
+ * calls will not interfere with its value
+ * and it can be inspected at leisure.
+ */
+ heap_last_errno = errno;
+
+ exit_throw_exception(EXIT_HEAP_ALLOC,
+ JVMCLASS_JAVA_LANG_INTERNALERROR);
+/*NOTREACHED*/
+ }
+ }
+ break;
+
+ default:
+ /*
+ * Preserve errno for later inspection.
+ * By doing it this way, other OS system
+ * calls will not interfere with its value
+ * and it can be inspected at leisure.
+ */
+ heap_last_errno = errno;
+
+ exit_throw_exception(EXIT_HEAP_ALLOC,
+ JVMCLASS_JAVA_LANG_INTERNALERROR);
+/*NOTREACHED*/
+ }
+ }
+
+ /* Clear block if requested */
+ if (rtrue == clrmem_flag)
+ {
+ rbyte *pb = (rbyte *) rc;
+
+ int i;
+ for (i = 0; i < size; i++)
+ {
+ pb[i] = '\0';
+ }
+ }
+
+ heap_malloc_count++;
+
+ return(rc);
+
+} /* END of heap_get_common_simple_bimodal() */
+
+
+/*!
+ * @brief Allocate memory from heap to caller, judging which mode
+ * to use for allocation.
+ *
+ * When finished, this pointer should be sent back to
+ * @link #heap_free_data_bimodal() heap_free_xxxx_bimodal()@endlink
+ * for reallocation.
+ *
+ * @warning Much of the JVM initialization ABSOLUTELY DEPENDS on
+ * setting of the @b clrmem_flag value to
+ * @link #rtrue rtrue@endlink so that allocated
+ * structures contain all zeroes. If the heap
+ * allocation scheme changes, this functionality needs
+ * to be brought forward or change much of the code, not
+ * only init code, but throughout the whole corpus.
+ *
+ * @remarks If @c @b malloc(3) returns an error other than out of
+ * memory errors, then the system @b errno is saved out
+ * into @link #heap_last_errno heap_last_errno@endlink
+ * for retrieval by @c @b perror(3) or other user response.
+ * This is typically useful for system-level debugging
+ * when the OS or OS resources, security, etc., may be
+ * getting in the way of proper allocation.
+ *
+ *
+ * @param size Number of bytes to allocate
+ *
+ * @param clrmem_flag Set memory to all zeroes
+ * (@link #rtrue rtrue@endlink) or
+ * not (@link #rfalse rfalse@endlink).
+ * If @link #rtrue rtrue@endlink,
+ * clear the allocated block, otherwise
+ * return it with its existing contents.
+ *
+ *
+ * @return (@link #rvoid rvoid@endlink *) to allocated area.
+ * This pointer may be cast to any desired data type. If
+ * size of zero bytes is requested, return
+ * @link #rnull rnull@endlink and let caller croak
+ * on @b SIGSEGV. If no memory is available
+ * or some OS system call error happened, throw error,
+ * but do @e not return.
+ *
+ *
+ * @throws JVMCLASS_JAVA_LANG_OUTOFMEMORYERROR
+ * @link #JVMCLASS_JAVA_LANG_OUTOFMEMORYERROR
+ * if no memory is available@endlink.
+ *
+ * @throws JVMCLASS_JAVA_LANG_INTERNALERROR
+ @link #JVMCLASS_JAVA_LANG_INTERNALERROR
+ * if other allocation error@endlink.
+ *
+ */
+static rvoid *heap_get_common_bimodal(int size, rboolean clrmem_flag)
+{
+ rvoid *rc; /* Separate LOCATE_SLOT calc. from return() for debug */
+ rc = (rvoid *) rnull;
+
+ /*
+ * Return rnull pointer when zero size requested.
+ * Let caller fix that problem.
+ */
+ if (0 == size)
+ {
+ return((rvoid *) rnull);
+ }
+
+ errno = ERROR0; /* Clear out error code before calling */
+
+
+ /* Use pre-allocated area for small requests */
+ if (HEAP_SLOT_SIZE >= size)
+ {
+ /* Mark last allocated-- faster than always starting at 0 */
+ static rlong heapidxLAST = HEAP_NUMBER_OF_SLOTS - 1;
+
+ rlong heapidx; /* Just in case of large number of slots */
+ rlong count;
+
+ /* Scan flag array for first open slot */
+
+ /* Study heap twice, before and after GC,and use same code*/
+#define LOCATE_SLOT \
+ \
+ for (count = 0, heapidx = 1 + heapidxLAST; \
+ count < HEAP_NUMBER_OF_SLOTS; \
+ count++, heapidx++) \
+ { \
+ /* Wrap around last allocation to beginning */ \
+ if (HEAP_NUMBER_OF_SLOTS == heapidx) \
+ { \
+ heapidx = 0; \
+ } \
+ \
+ if (rfalse == pheap_slot_in_use[heapidx]) \
+ { \
+ /* Reserve a slot, return its data area pointer */ \
+ pheap_slot_in_use[heapidx] = rtrue; \
+ \
+ /* Also report which slot was last allocated */ \
+ heapidxLAST = heapidx; \
+ \
+ /* Count slot allocations */ \
+ slot_alloc_count++; \
+ \
+ rc = (rvoid *) \
+ &pheap_slot[heapidx * \
+ sizeof(rbyte) * \
+ HEAP_SLOT_SIZE]; \
+ /* Clear block if requested */ \
+ if (rtrue == clrmem_flag) \
+ { \
+ rbyte *pb = (rbyte *) rc; \
+ \
+ rint i; \
+ for (i = 0; i < size; i++) \
+ { \
+ pb[i] = '\0'; \
+ } \
+ } \
+ break; \
+ } \
+ }
+
+ LOCATE_SLOT;
+ if (rnull != rc)
+ {
+ return(rc);
+ }
+
+ /* If could not allocate, do one retry after GC */
+ GC_RUN(rtrue);
+
+ /* Scan flag array a second time for first open slot */
+
+ LOCATE_SLOT;
+
+ if (rnull != rc)
+ {
+ return(rc);
+ }
+
+ /* Sorry, nothing available, throw error */
+
+ heap_last_errno = ERROR0; /* No OS error */
+
+ exit_throw_exception(EXIT_HEAP_ALLOC,
+ JVMCLASS_JAVA_LANG_OUTOFMEMORYERROR);
+ }
+ else
+ {
+ return(heap_get_common_simple_bimodal(size, clrmem_flag));
+ }
+/*NOTREACHED*/
+ return((rvoid *) rnull); /* Satisfy compiler */
+
+} /* END of heap_get_common_bimodal() */
+
+
+/*!
+ * @brief Allocate memory for a @b method from heap to caller.
+ *
+ * When finished, this pointer should be sent back to
+ * @link #heap_free_method_bimodal() heap_free_method_bimodal()@endlink
+ * for reallocation.
+ *
+ * @remarks This implementation makes no distinction betwen
+ * "method area heap" and any other usage. Other
+ * implementations may choose to implement the
+ * JVM Spec section 3.5.4 more rigorously.
+ *
+ *
+ * @param size Number of bytes to allocate
+ *
+ * @param clrmem_flag Set memory to all zeroes
+ * (@link #rtrue rtrue@endlink) or
+ * not (@link #rfalse rfalse@endlink)
+ *
+ *
+ * @return (@link #rvoid rvoid@endlink *) to allocated area.
+ * This pointer may be cast to any desired data type. If
+ * size of zero bytes is requested, return
+ * @link #rnull rnull@endlink and let
+ * caller croak on @b SIGSEGV. If no memory is available
+ * or some OS system call error happened, throw error,
+ * but do @e not return.
+ *
+ *
+ * @throws JVMCLASS_JAVA_LANG_OUTOFMEMORYERROR
+ * @link #JVMCLASS_JAVA_LANG_OUTOFMEMORYERROR
+ * if no memory is available@endlink.
+ *
+ * @throws JVMCLASS_JAVA_LANG_INTERNALERROR
+ @link #JVMCLASS_JAVA_LANG_INTERNALERROR
+ * if other allocation error@endlink.
+ *
+ */
+rvoid *heap_get_method_bimodal(int size, rboolean clrmem_flag)
+{
+ return(heap_get_common_bimodal(size, clrmem_flag));
+
+} /* END of heap_get_method_bimodal() */
+
+
+/*!
+ * @brief Allocate memory for a @b stack area from heap to caller.
+ *
+ * When finished, this pointer should be sent back
+ * to @link #heap_free_stack_bimodal() heap_free_stack_bimodal()@endlink
+ * for reallocation.
+ *
+ *
+ * @param size Number of bytes to allocate
+ *
+ * @param clrmem_flag Set memory to all zeroes
+ * (@link #rtrue rtrue@endlink) or
+ * not (@link #rfalse rfalse@endlink)
+ *
+ *
+ * @return (@link #rvoid rvoid@endlink *) to allocated area.
+ * This pointer may be cast to any desired data type. If
+ * size of zero bytes is requested, return
+ * @link #rnull rnull@endlink and let
+ * caller croak on @b SIGSEGV. If no memory is available
+ * or some OS system call error happened, throw error,
+ * but do @e not return.
+ *
+ *
+ * @throws JVMCLASS_JAVA_LANG_OUTOFMEMORYERROR
+ * @link #JVMCLASS_JAVA_LANG_OUTOFMEMORYERROR
+ * if no memory is available@endlink.
+ *
+ * @throws JVMCLASS_JAVA_LANG_INTERNALERROR
+ @link #JVMCLASS_JAVA_LANG_INTERNALERROR
+ * if other allocation error@endlink.
+ *
+ *
+ *
+ */
+rvoid *heap_get_stack_bimodal(int size, rboolean clrmem_flag)
+{
+ return(heap_get_common_bimodal(size, clrmem_flag));
+
+} /* END of heap_get_stack_bimodal() */
+
+
+/*!
+ * @brief Allocate memory for a @b data area from heap to caller.
+ *
+ * When finished, this pointer should be sent back
+ * to @link #heap_free_data_bimodal() heap_free_data_bimodal()@endlink
+ * for reallocation.
+ *
+ *
+ * @param size Number of bytes to allocate
+ *
+ * @param clrmem_flag Set memory to all zeroes
+ * (@link #rtrue rtrue@endlink) or
+ * not (@link #rfalse rfalse@endlink)
+ *
+ *
+ * @return (@link #rvoid rvoid@endlink *) to allocated area.
+ * This pointer may be cast to any desired data type. If
+ * size of zero bytes is requested, return
+ * @link #rnull rnull@endlink and let
+ * caller croak on @b SIGSEGV. If no memory is available
+ * or some OS system call error happened, throw error,
+ * but do @e not return.
+ *
+ *
+ * @throws JVMCLASS_JAVA_LANG_OUTOFMEMORYERROR
+ * @link #JVMCLASS_JAVA_LANG_OUTOFMEMORYERROR
+ * if no memory is available@endlink.
+ *
+ * @throws JVMCLASS_JAVA_LANG_INTERNALERROR
+ @link #JVMCLASS_JAVA_LANG_INTERNALERROR
+ * if other allocation error@endlink.
+ *
+ *
+ *
+ */
+rvoid *heap_get_data_bimodal(int size, rboolean clrmem_flag)
+{
+ return(heap_get_common_bimodal(size, clrmem_flag));
+
+} /* END of heap_get_data_bimodal() */
+
+
+/*********************************************************************/
+/*!
+ * @brief Release a previously allocated block back into the heap for
+ * future reallocation.
+ *
+ * If a @link #rnull rnull@endlink pointer is passed in, ignore
+ * the request.
+ *
+ *
+ * @param pheap_block An (@link #rvoid rvoid@endlink *) previously
+ * returned by one of the
+ * @link #heap_get_data_bimodal()
+ heap_get_XXX_bimodal()@endlink functions.
+ *
+ *
+ * @return @link #rvoid rvoid@endlink
+ *
+ *
+ */
+static rvoid heap_free_common_bimodal(rvoid *pheap_block)
+{
+ /* Ignore @link #rnull rnull@endlink pointer */
+ if (rnull != pheap_block)
+ {
+ /*
+ * Free pre-allocated area from deallocation of
+ * small requests, all of which were allocated
+ * in this block
+ */
+ if ((((rbyte *) &pheap_slot[0]) <= ((rbyte *) pheap_block))
+ &&
+ (((rbyte *)
+ &pheap_slot[sizeof(rbyte) *
+ HEAP_SLOT_SIZE *
+ HEAP_NUMBER_OF_SLOTS]) >
+ ((rbyte *) pheap_block)))
+ {
+ rlong heapidx =
+ (((rbyte *) pheap_block) - &pheap_slot[0]) /
+ HEAP_SLOT_SIZE;
+
+ pheap_slot_in_use[heapidx] = rfalse;
+
+ /* Count slots freed */
+ slot_free_count++;
+
+ return;
+ }
+ else
+ {
+ /* Free larger requests */
+ heap_free_count++;
+
+ free(pheap_block);
+
+ return;
+ }
+ }
+
+ return;
+
+} /* END of heap_free_common_bimodal() */
+
+
+/*!
+ * @brief Release a previously allocated @b method block back into
+ * the heap for future reallocation.
+ *
+ * @remarks This implementation makes no distinction between
+ * <b>method area heap</b> and any other usage. Other
+ * implementations may choose to implement the
+ * JVM Spec section 3.5.4 more rigorously.
+ *
+ *
+ * @param pheap_block An (@link #rvoid rvoid@endlink *) previously
+ * returned by @link #heap_get_method_bimodal()
+ heap_get_method_bimodal()@endlink
+ *
+ *
+ * @return @link #rvoid rvoid@endlink
+ *
+ */
+rvoid heap_free_method_bimodal(rvoid *pheap_block)
+{
+ heap_free_common_bimodal(pheap_block);
+
+} /* END of heap_free_method_bimodal() */
+
+
+/*!
+ * @brief Release a previously allocated @b stack block back into
+ * the heap for future reallocation.
+ *
+ *
+ * @param pheap_block An (@link #rvoid rvoid@endlink *) previously
+ * returned by @link #heap_get_stack_bimodal()
+ heap_get_stack_bimodal()@endlink
+ *
+ *
+ * @return @link #rvoid rvoid@endlink
+ *
+ */
+rvoid heap_free_stack_bimodal(rvoid *pheap_block)
+{
+ heap_free_common_bimodal(pheap_block);
+
+} /* END of heap_free_stack_bimodal() */
+
+
+/*!
+ * @brief Release a previously allocated @b data block back
+ * into the heap for future reallocation.
+ *
+ *
+ * @param pheap_block An (@link #rvoid rvoid@endlink *) previously
+ * returned by @link #heap_get_data_bimodal()
+ heap_get_data_bimodal()@endlink
+ *
+ *
+ * @return @link #rvoid rvoid@endlink
+ *
+ */
+rvoid heap_free_data_bimodal(rvoid *pheap_block)
+{
+ heap_free_common_bimodal(pheap_block);
+
+} /* END of heap_free_data_bimodal() */
+
+
+/*!
+ * @brief Allocation failure diagnostic.
+ *
+ * Returns an @b errno value per @b "errno.h" if a
+ * @link #rnull rnull@endlink pointer
+ * is passed in, namely from the most recent call to a heap
+ * allocation function. It may only be called once before the
+ * value is cleared. If a non-null pointer is passed in,
+ * @link #ERROR0 ERROR0@endlink is returned and the error status is
+ * again cleared.
+ *
+ *
+ * @param badptr Return value from heap allocation function.
+ *
+ *
+ * @returns @link #ERROR0 ERROR0@endlink when no error was found
+ * or non-null @b badptr given.
+ * @link #heap_last_errno heap_last_errno@endlink
+ * value otherwise.
+ *
+ */
+int heap_get_error_bimodal(rvoid *badptr)
+{
+ int rc;
+
+ if (rnull == badptr)
+ {
+ rc = heap_last_errno;
+ heap_last_errno = ERROR0;
+ return(rc);
+ }
+ else
+ {
+ heap_last_errno = ERROR0;
+
+ return(ERROR0);
+ }
+
+} /* END of heap_get_error_bimodal() */
+
+
+/*!
+ * @brief Shut down up heap management after JVM execution is finished.
+ *
+ *
+ * @b Parameters: @link #rvoid rvoid@endlink
+ *
+ *
+ * @return @link #rvoid rvoid@endlink
+ *
+ */
+rvoid heap_shutdown_bimodal()
+{
+ heap_last_errno = ERROR0;
+
+ /* Declare this module uninitialized */
+ jvm_heap_initialized = rfalse;
+
+ return;
+
+} /* END of heap_shutdown_bimodal() */
+
+#endif /* CONFIG_HEAP_TYPE_BIMODAL || CONFIG_OPTIONS_COMPILE_ALL */
+
+
+/* EOF */
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src/heap_simple.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src/heap_simple.c?rev=307257&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src/heap_simple.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src/heap_simple.c Fri Oct 7 21:27:56 2005
@@ -0,0 +1,530 @@
+/*!
+ * @file heap_simple.c
+ *
+ * @brief @b simple heap management functions
+ *
+ * This is the first of probably several implementations of heap
+ * management for this JVM implementation. It uses the simple
+ * OS/stdlib resources of @c @b malloc(3)/free(3) as the foundation
+ * for its management scheme. The memory allocation pointer is
+ * generated by @c @b malloc(3). Calling @c @b free(3) with this
+ * same pointer marks the block of memory as available for
+ * other allocation.
+ *
+ * The common header file @link jvm/src/heap.h gc.h@endlink defines
+ * the prototypes for all heap allocation implementations by way
+ * of the @link #CONFIG_HEAP_TYPE_SIMPLE CONFIG_HEAP_TYPE_xxx@endlink
+ * symbol definitions.
+ *
+ *
+ * @section Control
+ *
+ * \$URL: https://svn.apache.org/path/name/heap_simple.c $ \$Id: heap_simple.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.
+ *
+ * @section Reference
+ *
+ */
+
+#include "arch.h"
+ARCH_COPYRIGHT_APACHE(heap_simple, c, "$URL: https://svn.apache.org/path/name/heap_simple.c $ $Id: heap_simple.c 0 09/28/2005 dlydick $");
+
+#if defined(CONFIG_HEAP_TYPE_SIMPLE) || defined(CONFIG_COMPILE_ALL_OPTIONS)
+
+#include <errno.h>
+#include <stdlib.h>
+
+#include "jvmcfg.h"
+#include "exit.h"
+#include "gc.h"
+#include "heap.h"
+#include "jvmclass.h"
+#include "util.h"
+
+
+/*!
+ * @brief Start up heap management methodology.
+ *
+ * In a @b malloc/free scheme, there is nothing
+ * to do, but in other methods there might be.
+ *
+ *
+ * @b Parameters: @link #rvoid rvoid@endlink
+ *
+ *
+ * @returns @link #rvoid rvoid@endlink
+ *
+ */
+rvoid heap_init_simple()
+{
+ ; /* Nothing to do in this methodology */
+
+ /* Declare this module initialized */
+ jvm_heap_initialized = rtrue;
+
+ return;
+
+} /* END of heap_init_simple() */
+
+
+/*!
+ * @brief Most recent error code from @c @b malloc(3), for use
+ * by heap_get_error_simple().
+ */
+static int heap_last_errno = ERROR0;
+
+
+/*!
+ * @brief Number of calls to @c @b malloc(3).
+ *
+ * One of two global variables providing rudimentary statistics
+ * for heap allocation history.
+ *
+ * @see heap_free_count
+ */
+static rlong heap_malloc_count = 0;
+
+/*!
+ * @brief Number of calls to @c @b free(3).
+ *
+ * One of two global variables providing rudimentary statistics
+ * for heap allocation history.
+ *
+ * @see heap_malloc_count
+ */
+static rlong heap_free_count = 0;
+
+/*!
+ * @brief Simple heap allocation method that uses only @c @b malloc(3)
+ * and @c @b free(3).
+ *
+ *
+ * @param size Number of bytes to allocate
+ *
+ * @param clrmem_flag Set memory to all zeroes
+ * (@link #rtrue rtrue@endlink) or not
+ * (@link #rfalse rfalse@endlink).
+ * If @link #rtrue rtrue@endlink, clear the
+ * allocated block, otherwise
+ * return it with its existing contents.
+ *
+ *
+ * @returns (@link #rvoid rvoid@endlink *) to allocated area.
+ * This pointer may be cast to any desired data type.
+ * If size of zero bytes is requested, return
+ * @link #rnull rnull@endlink and let caller croak
+ * on @b SIGSEGV. If no memory is available
+ * or some OS system call error happened, throw error, but
+ * do @e not return.
+ *
+ *
+ * @throws JVMCLASS_JAVA_LANG_OUTOFMEMORYERROR
+ * @link #JVMCLASS_JAVA_LANG_OUTOFMEMORYERROR
+ * if no memory is available.@endlink.
+ *
+ * @throws JVMCLASS_JAVA_LANG_INTERNALERROR
+ @link #JVMCLASS_JAVA_LANG_INTERNALERROR
+ * if other allocation error@endlink.
+ *
+ */
+static rvoid *heap_get_common_simple(int size, rboolean clrmem_flag)
+{
+ rvoid *rc;
+
+ rc = malloc(size);
+
+ /*
+ * If specific errors are returned, GC could free up some heap,
+ * so run it and try again-- ONCE. If it fails a second time,
+ * so be it. Let the application deal with the problem.
+ */
+ if (rnull == rc)
+ {
+ switch(errno)
+ {
+ case ENOMEM:
+ case EAGAIN:
+ GC_RUN(rtrue);
+ rc = malloc(size);
+
+ if (rnull == rc)
+ {
+ switch(errno)
+ {
+ case ENOMEM:
+ case EAGAIN:
+ exit_throw_exception(EXIT_HEAP_ALLOC,
+ JVMCLASS_JAVA_LANG_OUTOFMEMORYERROR);
+/*NOTREACHED*/
+ default:
+ /*
+ * Preserve errno for later inspection.
+ * By doing it this way, other OS system
+ * calls will not interfere with its value
+ * and it can be inspected at leisure.
+ */
+ heap_last_errno = errno;
+
+ exit_throw_exception(EXIT_HEAP_ALLOC,
+ JVMCLASS_JAVA_LANG_INTERNALERROR);
+/*NOTREACHED*/
+ }
+ }
+ break;
+
+ default:
+ /*
+ * Preserve errno for later inspection.
+ * By doing it this way, other OS system
+ * calls will not interfere with its value
+ * and it can be inspected at leisure.
+ */
+ heap_last_errno = errno;
+
+ exit_throw_exception(EXIT_HEAP_ALLOC,
+ JVMCLASS_JAVA_LANG_INTERNALERROR);
+/*NOTREACHED*/
+ }
+ }
+
+ /* Clear block if requested */
+ if (rtrue == clrmem_flag)
+ {
+ rbyte *pb = (rbyte *) rc;
+
+ int i;
+ for (i = 0; i < size; i++)
+ {
+ pb[i] = '\0';
+ }
+ }
+
+ heap_malloc_count++;
+
+ return(rc);
+
+} /* END of heap_get_common_simple() */
+
+
+/*!
+ * @brief Allocate memory for a method from heap to caller.
+ *
+ * When finished, this pointer should be sent back
+ * to @link #heap_free_method_simple() heap_free_method_simple()@endlink
+ * for reallocation.
+ *
+ * @note This implementation makes no distinction betwen
+ * <b>method area heap </b> and any other usage. Other
+ * implementations may choose to implement the
+ * JVM Spec section 3.5.4 more rigorously.
+ *
+ *
+ * @param size Number of bytes to allocate
+ *
+ * @param clrmem_flag Set memory to all zeroes
+ * (@link #rtrue rtrue@endlink) or
+ * not (@link #rfalse rfalse@endlink)
+ *
+ *
+ * @returns (@link #rvoid rvoid@endlink *) to allocated area.
+ * This pointer may be cast to any desired data type.
+ * If size of zero bytes is requested, return
+ * @link #rnull rnull@endlink and
+ * let caller croak on @b SIGSEGV. If no memory is available
+ * or some OS system call error happened, throw error, but
+ * do @e not return.
+ *
+ *
+ * @throws JVMCLASS_JAVA_LANG_OUTOFMEMORYERROR
+ * @link #JVMCLASS_JAVA_LANG_OUTOFMEMORYERROR
+ * if no memory is available@endlink.
+ *
+ * @throws JVMCLASS_JAVA_LANG_INTERNALERROR
+ @link #JVMCLASS_JAVA_LANG_INTERNALERROR
+ * if other allocation error@endlink.
+ *
+ */
+rvoid *heap_get_method_simple(int size, rboolean clrmem_flag)
+{
+ return(heap_get_common_simple(size, clrmem_flag));
+
+} /* END of heap_get_method_simple() */
+
+
+/*!
+ * @brief Allocate memory for a stack area from heap to caller.
+ *
+ * When finished, this pointer should be sent back
+ * to @link #heap_free_stack_simple() heap_free_stack_simple()@endlink
+ * for reallocation.
+ *
+ *
+ * @param size Number of bytes to allocate
+ *
+ * @param clrmem_flag Set memory to all zeroes
+ * (@link #rtrue rtrue@endlink) or
+ * not (@link #rfalse rfalse@endlink)
+ *
+ *
+ * @returns (@link #rvoid rvoid@endlink *) to allocated area.
+ * This pointer may be cast to any desired data type.
+ * If size of zero bytes is requested, return
+ * @link #rnull rnull@endlink and
+ * let caller croak on @b SIGSEGV. If no memory is available
+ * or some OS system call error happened, throw error, but
+ * do @e not return.
+ *
+ *
+ * @throws JVMCLASS_JAVA_LANG_OUTOFMEMORYERROR
+ * @link #JVMCLASS_JAVA_LANG_OUTOFMEMORYERROR
+ * if no memory is available@endlink.
+ *
+ * @throws JVMCLASS_JAVA_LANG_INTERNALERROR
+ @link #JVMCLASS_JAVA_LANG_INTERNALERROR
+ * if other allocation error@endlink.
+ *
+ *
+ *
+ */
+rvoid *heap_get_stack_simple(int size, rboolean clrmem_flag)
+{
+ return(heap_get_common_simple(size, clrmem_flag));
+
+} /* END of heap_get_stack_simple() */
+
+
+/*!
+ * @brief Allocate memory for a data area from heap to caller.
+ *
+ * When finished, this pointer should be sent back
+ * to @link #heap_free_data_simple() heap_free_data_simple()@endlink
+ * for reallocation.
+ *
+ *
+ * @param size Number of bytes to allocate
+ *
+ * @param clrmem_flag Set memory to all zeroes
+ * (@link #rtrue rtrue@endlink) or
+ * not (@link #rfalse rfalse@endlink)
+ *
+ *
+ * @returns (@link #rvoid rvoid@endlink *) to allocated area.
+ * This pointer may be cast to any desired data type.
+ * If size of zero bytes is requested, return
+ * @link #rnull rnull@endlink and
+ * let caller croak on @b SIGSEGV. If no memory is available
+ * or some OS system call error happened, throw error, but
+ * do @e not return.
+ *
+ *
+ * @throws JVMCLASS_JAVA_LANG_OUTOFMEMORYERROR
+ * @link #JVMCLASS_JAVA_LANG_OUTOFMEMORYERROR
+ * if no memory is available@endlink.
+ *
+ * @throws JVMCLASS_JAVA_LANG_INTERNALERROR
+ @link #JVMCLASS_JAVA_LANG_INTERNALERROR
+ * if other allocation error@endlink.
+ *
+ *
+ *
+ */
+rvoid *heap_get_data_simple(int size, rboolean clrmem_flag)
+{
+ return(heap_get_common_simple(size, clrmem_flag));
+
+} /* END of heap_get_data_simple() */
+
+
+/*********************************************************************/
+/*!
+ * @brief Release a previously allocated block back into the heap for
+ * future reallocation.
+ *
+ * If a @link #rnull rnull@endlink pointer is passed in, ignore
+ * the request.
+ *
+ *
+ * @param pheap_block An (@link #rvoid rvoid@endlink *) previously
+ * returned by one of the
+ @link #heap_get_data_simple()
+ heap_get_XXX_simple()@endlink
+ * functions.
+ *
+ *
+ * @returns @link #rvoid rvoid@endlink
+ *
+ *
+ */
+static rvoid heap_free_common_simple(rvoid *pheap_block)
+{
+ /* Ignore @link #rnull rnull@endlink pointer */
+ if (rnull != pheap_block)
+ {
+ /* Free larger requests */
+ heap_free_count++;
+
+ free(pheap_block);
+ }
+
+ return;
+
+} /* END of heap_free_common_simple() */
+
+
+/*!
+ * @brief Release a previously allocated @b method block back into
+ * the heap for future reallocation.
+ *
+ * @note This implementation makes no distinction betwen
+ * <b>method area heap</b> and any other usage. Other
+ * implementations may choose to implement the
+ * JVM Spec section 3.5.4 more rigorously.
+ *
+ *
+ * @param pheap_block An (@link #rvoid rvoid@endlink *) previously
+ * returned by
+ * @link #heap_get_method_simple()
+ heap_get_method_simple()@endlink
+ *
+ *
+ * @returns @link #rvoid rvoid@endlink
+ *
+ */
+rvoid heap_free_method_simple(rvoid *pheap_block)
+{
+ heap_free_common_simple(pheap_block);
+
+} /* END of heap_free_method_simple() */
+
+
+/*!
+ * @brief Release a previously allocated @b stack block back into
+ * the heap for future reallocation.
+ *
+ *
+ * @param pheap_block An (@link #rvoid rvoid@endlink *) previously
+ * returned by
+ * @link #heap_get_stack_simple()
+ heap_get_stack_simple()@endlink
+ *
+ *
+ * @returns @link #rvoid rvoid@endlink
+ *
+ */
+rvoid heap_free_stack_simple(rvoid *pheap_block)
+{
+ heap_free_common_simple(pheap_block);
+
+} /* END of heap_free_stack_simple() */
+
+
+/*!
+ * @brief Release a previously allocated @b data block back
+ * into the heap for future reallocation.
+ *
+ *
+ * @param pheap_block An (@link #rvoid rvoid@endlink *) previously
+ * returned by
+ * @link #heap_get_data_simple()
+ heap_get_data_simple()@endlink
+ *
+ *
+ * @returns @link #rvoid rvoid@endlink
+ *
+ */
+rvoid heap_free_data_simple(rvoid *pheap_block)
+{
+ heap_free_common_simple(pheap_block);
+
+} /* END of heap_free_data_simple() */
+
+
+/*!
+ * @brief Allocation failure diagnostic.
+ *
+ * Returns an @b errno value per @b "errno.h" if a
+ * @link #rnull rnull@endlink pointer
+ * is passed in, namely from the most recent call to a heap
+ * allocation function. It may only be called once before the
+ * value is cleared. If a non-null pointer is passed in,
+ * @link #ERROR0 ERROR0@endlink is returned and the error status is
+ * again cleared.
+ *
+ *
+ * @param badptr Return value from heap allocation function.
+ *
+ *
+ * @returns @link #ERROR0 ERROR0@endlink when no error was found
+ * or non-null @b badptr given.
+ * @link #heap_last_errno heap_last_errno@endlink
+ * value otherwise.
+ *
+ */
+int heap_get_error_simple(rvoid *badptr)
+{
+ int rc;
+
+ if (rnull == badptr)
+ {
+ rc = heap_last_errno;
+ heap_last_errno = ERROR0;
+ return(rc);
+ }
+ else
+ {
+ heap_last_errno = ERROR0;
+
+ return(ERROR0);
+ }
+
+} /* END of heap_get_error_simple() */
+
+
+/*!
+ * @brief Shut down up heap management after JVM execution is finished.
+ *
+ *
+ * @b Parameters: @link #rvoid rvoid@endlink
+ *
+ *
+ * @returns @link #rvoid rvoid@endlink
+ *
+ */
+rvoid heap_shutdown_simple()
+{
+ heap_last_errno = ERROR0;
+
+ /* Declare this module uninitialized */
+ jvm_heap_initialized = rfalse;
+
+ return;
+
+} /* END of heap_shutdown_simple() */
+
+#endif /* CONFIG_HEAP_TYPE_SIMPLE || CONFIG_OPTIONS_COMPILE_ALL */
+
+
+/* EOF */
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src/jlClass.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src/jlClass.c?rev=307257&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src/jlClass.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src/jlClass.c Fri Oct 7 21:27:56 2005
@@ -0,0 +1,140 @@
+/*!
+ * @file jlClass.c
+ *
+ * @brief Native implementation of @c @b java.lang.Class
+ *
+ *
+ * @section Control
+ *
+ * \$URL: https://svn.apache.org/path/name/jlClass.c $ \$Id: jlClass.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.
+ *
+ * @section Reference
+ *
+ */
+
+#include "arch.h"
+ARCH_COPYRIGHT_APACHE(jlClass, c, "$URL: https://svn.apache.org/path/name/jlClass.c $ $Id: jlClass.c 0 09/28/2005 dlydick $");
+
+
+#include "jvmcfg.h"
+#include "classfile.h"
+#include "linkage.h"
+#include "jvm.h"
+
+
+/*!
+ * @name Native implementation of class static functions.
+ *
+ * The class index of the current class is always passed
+ * as the first parameter.
+ *
+ * @note These @c @b java.lang.Class methods are unusual in that
+ * they does not require a @c @b jobject (in parlance of this
+ * implementation, a @link #jvm_object_hash jvm_object_hash@endlink)
+ * to run because they are declared as @c @b static methods. As
+ * implemented here, the usual @b objhashthis parameter is therefore
+ * replaced by * @b clsidxthis. The thread context is located in
+ * @link #CURRENT_THREAD CURRENT_THREAD@endlink.
+ *
+ */
+
+/*@{ */ /* Begin grouped definitions */
+
+/*@} */ /* End of grouped definitions */
+
+
+/*!
+ * @name Native implementation of object instance functions.
+ *
+ * The object hash of @c @b this object is always passed
+ * as the first parameter.
+ *
+ */
+
+/*@{ */ /* Begin grouped definitions */
+
+/*!
+ * @brief Native implementation
+ * of @c @b java.lang.Class.isArray()
+ *
+ *
+ * @param objhashthis Object table hash of @c @b this object.
+ *
+ *
+ * @returns @link #jtrue jtrue@endlink if this class is an array,
+ * else @link #jfalse jfalse@endlink.
+ *
+ */
+
+jboolean jlClass_isArray(jvm_object_hash objhashthis)
+{
+ jvm_class_index clsidx = OBJECT_CLASS_LINKAGE(objhashthis)->clsidx;
+
+ if (jvm_class_index_null == clsidx)
+ {
+ return(jfalse);
+ }
+
+ return((CLASS(clsidx).status & CLASS_STATUS_ARRAY)
+ ? jtrue
+ : jfalse);
+
+} /* END of jlClass_isArray() */
+
+
+/*!
+ * @brief Native implementation
+ * of @c @b java.lang.Class.isPrimative()
+ *
+ *
+ * @param objhashthis Object table hash of @c @b this object.
+ *
+ *
+ * @returns @link #jtrue jtrue@endlink if this class is a primative,
+ * else @link #jfalse jfalse@endlink.
+ *
+ */
+
+jboolean jlClass_isPrimative(jvm_object_hash objhashthis)
+{
+ jvm_class_index clsidx = OBJECT_CLASS_LINKAGE(objhashthis)->clsidx;
+
+ if (jvm_class_index_null == clsidx)
+ {
+ return(jfalse);
+ }
+
+ return((CLASS(clsidx).status & CLASS_STATUS_PRIMATIVE)
+ ? jtrue
+ : jfalse);
+
+} /* END of jlClass_isPrimative() */
+
+/*@} */ /* End of grouped definitions */
+
+
+/* EOF */
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src/jlObject.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src/jlObject.c?rev=307257&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src/jlObject.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src/jlObject.c Fri Oct 7 21:27:56 2005
@@ -0,0 +1,271 @@
+/*!
+ * @file jlObject.c
+ *
+ * @brief Native implementation of @c @b java.lang.Object
+ *
+ * @todo Perform intelligent check on input parameter
+ * @b objhash range for all functions.
+ *
+ * @todo In real life, the @b objhashthis values and @b clsidxthis
+ * values will be valid or these functions could not be
+ * invoked since these data types are @e mandatory for
+ * referencing them. This probably means that the parameter
+ * valididty checking could probably be relaxed.
+ *
+ *
+ * @section Control
+ *
+ * \$URL: https://svn.apache.org/path/name/jlObject.c $ \$Id: jlObject.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.
+ *
+ * @section Reference
+ *
+ */
+
+#include "arch.h"
+ARCH_COPYRIGHT_APACHE(jlObject, c, "$URL: https://svn.apache.org/path/name/jlObject.c $ $Id: jlObject.c 0 09/28/2005 dlydick $");
+
+
+#include "jvmcfg.h"
+#include "classfile.h"
+#include "jvm.h"
+#include "linkage.h"
+#include "jvmclass.h"
+
+
+/*!
+ * @name Native implementation of class static functions.
+ *
+ * The class index of the current class is always passed
+ * as the first parameter.
+ *
+ * @note These @c @b java.lang.Object methods are unusual in that
+ * they does not require a @c @b jobject (in parlance of this
+ * implementation, a @link #jvm_object_hash jvm_object_hash@endlink)
+ * to run because they are declared as @c @b static methods. As
+ * implemented here, the usual @b objhashthis parameter is therefore
+ * replaced by * @b clsidxthis. The thread context is located in
+ * @link #CURRENT_THREAD CURRENT_THREAD@endlink.
+ *
+ */
+
+/*@{ */ /* Begin grouped definitions */
+
+/*@} */ /* End of grouped definitions */
+
+
+/*!
+ * @name Native implementation of object instance functions.
+ *
+ * The object hash of @c @b this object is always passed
+ * as the first parameter.
+ *
+ */
+
+
+/*@{ */ /* Begin grouped definitions */
+
+/*!
+ * @brief Native implementation
+ * of @c @b java.lang.Object.getClass()
+ *
+ *
+ * @param objhashthis Object table hash of @c @b this object.
+ *
+ *
+ * @returns @c @b java.lang.Object of OBJECT(objhashthis)
+ *
+ */
+jvm_object_hash jlObject_getClass(jvm_object_hash objhashthis)
+{
+ return(
+ CLASS(OBJECT_CLASS_LINKAGE(objhashthis)->clsidx).class_objhash);
+
+} /* END of jlObject_getClass() */
+
+
+/*!
+ * @brief Native implementation
+ * of @c @b java.lang.Object.hashCode()
+ *
+ *
+ * @param objhashthis Object table hash of @c @b this object.
+ *
+ *
+ * @returns input @b objhashthis by definition
+ *
+ */
+jvm_object_hash jlObject_hashCode(jvm_object_hash objhashthis)
+{
+ return(objhashthis);
+
+} /* END of jlObject_hashCode() */
+
+
+/*!
+ * @name Native implementations of java.lang.Object.wait() functions.
+ *
+ * @brief Implementation of related functions
+ * @c @b java.lang.Object.wait() and
+ * @c @b java.lang.Object.wait(jlong) .
+ *
+ * If this thread is not @link #THREAD_STATUS_INUSE
+ THREAD_STATUS_INUSE@endlink, result is @link #jfalse jfalse@endlink.
+ * Results are undefined if thread has the @b SLEEP, @b JOIN4EVER,
+ * @b JOINTIMED, or @b INTERRUPTIBLEIO status or if thread has
+ * been @b NOTIFIED or @b INTERRUPTED.
+ *
+ * This will only succeed if thread is in @b RUNNING state.
+ *
+ * It will fail of thread did not hold the object's monitor lock
+ * so it could release it here.
+ *
+ * @param objhashthis Object table hash of @c @b this object.
+ *
+ * @param sleeptime Number of timer ticks (milliseconds) to sleep.
+ *
+ *
+ * @returns @link #jvoid jvoid@endlink
+ *
+ *
+ * @throws JVMCLASS_JAVA_LANG_INTERRUPTEDEXCEPTION
+ * @link #JVMCLASS_JAVA_LANG_INTERRUPTEDEXCEPTION
+ if another thread had interrupted this thread@endlink.
+ *
+ * @throws JVMCLASS_JAVA_LANG_ILLEGALMONITORSTATEEXCEPTION
+ * @link #JVMCLASS_JAVA_LANG_ILLEGALMONITORSTATEEXCEPTION
+ if current thread does not own the object's monitor lock@endlink.
+ *
+ *
+ * @todo Make sure thread interruption logic below here is working.
+ *
+ */
+
+/*@{ */ /* Begin grouped definitions */
+
+/*!
+ * @brief Wait until object monitor lock is released.
+ *
+ */
+
+jvoid jlObject_wait4ever(jvm_object_hash objhashthis)
+{
+ if (((rtrue == VERIFY_OBJECT_THREAD_LINKAGE(objhashthis)) &&
+ (rtrue == VERIFY_THREAD_LINKAGE(
+ OBJECT_THREAD_LINKAGE(objhashthis)->thridx))) &&
+ (OBJECT_STATUS_MLOCK & OBJECT(objhashthis).status) &&
+ (CURRENT_THREAD == (OBJECT(objhashthis).mlock_thridx)))
+ {
+ jvm_thread_index thridx =
+ OBJECT_CLASS_LINKAGE(objhashthis)->thridx;
+
+ THREAD(thridx).status |= THREAD_STATUS_WAIT4EVER;
+ (rvoid) objectutil_release(objhashthis, thridx);
+
+ return;
+ }
+
+ /* This thread does not own the object's monitor lock */
+ thread_throw_exception(CURRENT_THREAD,
+ THREAD_STATUS_THREW_EXCEPTION,
+ JVMCLASS_JAVA_LANG_ILLEGALMONITORSTATEEXCEPTION);
+/*NOTREACHED*/
+ return; /* Satisfy compiler */
+
+} /* END of JlObject_wait4ever() */
+
+
+/*!
+ * @brief Wait until object monitor lock is released or a timeout
+ * period has expired.
+ *
+ */
+
+jvoid jlObject_waittimed(jvm_object_hash objhashthis,
+ jlong sleeptime)
+{
+ if (((rtrue == VERIFY_OBJECT_THREAD_LINKAGE(objhashthis)) &&
+ (rtrue == VERIFY_THREAD_LINKAGE(
+ OBJECT_THREAD_LINKAGE(objhashthis)->thridx))) &&
+ (OBJECT_STATUS_MLOCK & OBJECT(objhashthis).status) &&
+ (CURRENT_THREAD == (OBJECT(objhashthis).mlock_thridx)))
+ {
+ jvm_thread_index thridxthis =
+ OBJECT_CLASS_LINKAGE(objhashthis)->thridx;
+ THREAD(thridxthis).status |= THREAD_STATUS_JOINTIMED;
+ THREAD(thridxthis).sleeptime = sleeptime;
+ (rvoid) objectutil_release(objhashthis, thridxthis);
+
+ return;
+ }
+
+ /* This thread does not own the object's monitor lock */
+ thread_throw_exception(CURRENT_THREAD,
+ THREAD_STATUS_THREW_EXCEPTION,
+ JVMCLASS_JAVA_LANG_ILLEGALMONITORSTATEEXCEPTION);
+/*NOTREACHED*/
+ return; /* Satisfy compiler */
+
+} /* END of JlObject_waittimed() */
+
+/*@} */ /* End of grouped definitions */
+
+
+#if 0
+/*!
+ * @brief Native implementation of @c @b java.lang.Object.clone()
+ *
+ *
+ * @param objhashthis Object table hash of @c @b this object.
+ *
+ *
+ * @returns object hash of object clone.
+ *
+ * @todo then need to throw SecurityException in
+ * outer JVM loop when @link #jfalse jfalse@endlink.
+ *
+ */
+
+jvm_object_hash jlObject_clone(jvm_object_hash objhashthis)
+{
+ if ((rtrue == VERIFY_OBJECT_THREAD_LINKAGE(objhashthis)) &&
+ (rtrue == VERIFY_THREAD_LINKAGE(
+ OBJECT_THREAD_LINKAGE(objhashthis)->thridx)))
+ {
+ /* @todo Need to finish this implementation */
+
+ return(jvm_object_hash_null);
+ }
+ return(jvm_object_hash_null);
+
+} /* END of jlObject_clone() */
+#endif
+
+/*@} */ /* End of grouped definitions */
+
+
+
+/* EOF */