diff -ruN ./temp/j2me_cldc/api/src/Asproto/Asproto.java ./final_my_j2me/api/src/Asproto/Asproto.java
--- ./temp/j2me_cldc/api/src/Asproto/Asproto.java	1970-01-01 12:00:00.000000000 +1200
+++ ./final_my_j2me/api/src/Asproto/Asproto.java	2007-05-15 17:48:02.000000000 +1200
@@ -0,0 +1,35 @@
+package Asproto;
+
+public class Asproto {
+	
+		public final static int HDRSIZE = 6;
+		public final static int DATASIZE = 56;
+		public final static int CRCSIZE = 2;
+		public final static int PKTSIZE = HDRSIZE+DATASIZE+CRCSIZE; 
+
+		protected static byte packet[];
+		
+		public Asproto() { 
+			packet = new byte[PKTSIZE]; 
+		}
+		
+		public int getCRC() {
+			return packet[PKTSIZE-2]<<8 + packet[PKTSIZE-1];
+		}
+		
+		public int computeCRC() {
+			int i,crc;
+			for(i=0,crc=0;i<PKTSIZE;i++)
+				crc = (crc ^ packet[i])<<1;
+			return crc;
+		}
+		
+		public void setRaw(int in, byte b){
+			packet[in] = b;
+		}
+		
+		public static void main(String args[]){
+		  System.out.println("Hello World from Java");
+		}
+
+}
diff -ruN ./temp/j2me_cldc/Debug/makefile ./final_my_j2me/Debug/makefile
--- ./temp/j2me_cldc/Debug/makefile	1970-01-01 12:00:00.000000000 +1200
+++ ./final_my_j2me/Debug/makefile	2007-05-15 16:24:23.000000000 +1200
@@ -0,0 +1,84 @@
+CFLAGS = -DALT_DEBUG -O0 -g -Wall
+
+ASFLAGS = -g
+
+LIBS += -lm
+
+RM := rm -rf
+
+PROJECT := j2me
+# Location of this project
+APP_DIR :=/home/amal029/download/d2/my_j2me/j2me
+
+APP_CONFIG := Release
+
+SYSTEM_NAME := j2me_syslib
+SYSTEM_DIR := /home/amal029/download/d2/j2me_syslib
+
+SYS_CONFIG := Debug
+
+PTF := /home/amal029/NIOSCD/DE2_demonstrations/DE2_NET/nios_0.ptf
+
+DO_MAKE_OBJDUMP := 0
+
+space = $(empty) $(empty)
+space-to-question = $(subst $(space),?,$1)
+
+HOST_OS :=  $(shell uname | head -c 3 | tr [:upper:] [:lower:])
+
+SOPC_KIT_NIOS2 := $(strip $(SOPC_KIT_NIOS2))
+ifneq ($(call space-to-question,$(SOPC_KIT_NIOS2)),$(SOPC_KIT_NIOS2))
+# If there is a space in your SOPC_KIT_NIOS2 path, then it must be
+# fixed.
+ifeq ($(HOST_OS),cyg)
+# Use short 8.3 dos path on Windows/Cygwin
+SOPC_KIT_NIOS2 := $(shell cygpath --dos "$(SOPC_KIT_NIOS2)")
+else
+# Use a symlink to a unique dir in /tmp/altera_nios2 dir on Unix
+SHELL := /bin/bash
+USER = $(shell whoami)
+DATE = $(shell date +%Y-%m-%d)
+TMP_DIR = /tmp/altera_nios2-$(USER)
+CREATE_TMP_DIR := $(shell mkdir -p $(TMP_DIR))
+NIOS_VERSION_ID := $(shell nios2-elf-gcc -v 2>&1 | grep Altera | sed -e 's/[^0-9]//g')
+TMP_SOPC_KIT_NIOS2 := $(TMP_DIR)/altera_nios2_kit_tmp-$(DATE)-$(NIOS_VERSION_ID)
+CREATE_TMP_NIOS_DIR_CMD := if [ ! -d $(TMP_SOPC_KIT_NIOS2) ]; then ln -s "$(SOPC_KIT_NIOS2)" "$(TMP_SOPC_KIT_NIOS2)"; fi
+CREATE_TMP_NIOS_DIR := $(shell $(CREATE_TMP_NIOS_DIR_CMD))
+SOPC_KIT_NIOS2 := $(TMP_SOPC_KIT_NIOS2)
+endif
+
+export SOPC_KIT_NIOS2
+endif
+
+#I have changed TOP from ../.. since now the make file is right here correct.
+BUILDDIR=$(shell pwd)
+TOP=../
+PLATFORM=linux
+export LANG=C
+
+UNAME=$(shell uname -a)
+ifneq (,$(findstring Linux,$(UNAME)))
+  export PLATFORM=linux
+endif
+
+#This part is from the linux-build command directory so that I can build everything
+SUBDIRS = \
+  $(TOP)/tools/preverifier/build/linux \
+  $(TOP)/api \
+  $(TOP)/kvm/VmUnix/build \
+
+-include ${patsubst %, %/subdir.mk, $(SUBDIRS)}
+MAKEFILE_LIST += $(patsubst %, %/subdir.mk, $(SUBDIRS))
+
+all clean : FORCE
+	@for i in $(SUBDIRS) ; do \
+	    echo ">>>Recursively making "$$i" "$@"..."; \
+	    cd $$i; $(MAKE) $@ \
+	    || exit 1; cd $(BUILDDIR); \
+	    echo "<<<Finished Recursively making "$$i" "$@"." ; \
+	done
+
+FORCE:
+
+#APP_MAKEFILE := $(SOPC_KIT_NIOS2)/components/altera_hal/build/app.mk
+#include $(APP_MAKEFILE)
\ No newline at end of file
diff -ruN ./temp/j2me_cldc/j2me.c ./final_my_j2me/j2me.c
--- ./temp/j2me_cldc/j2me.c	1970-01-01 12:00:00.000000000 +1200
+++ ./final_my_j2me/j2me.c	2007-05-13 16:08:29.000000000 +1200
@@ -0,0 +1,14 @@
+#include <main.h>
+
+int main (void){
+    printf("Starting JVM");
+    char className[] = "Asproto.Asproto";
+    if(StartJVM(1,className) == 1){
+        printf("Calling the StartJVM\n");
+        return 1;
+    }
+    else{
+        printf("Failed to execute the kvm screwed\n");
+        return -1;  
+    } 
+}
\ No newline at end of file
diff -ruN ./temp/j2me_cldc/kvm/VmCommon/src/events.c ./final_my_j2me/kvm/VmCommon/src/events.c
--- ./temp/j2me_cldc/kvm/VmCommon/src/events.c	2003-02-06 13:55:59.000000000 +1300
+++ ./final_my_j2me/kvm/VmCommon/src/events.c	2007-04-05 19:52:08.000000000 +1200
@@ -20,6 +20,7 @@
  *=======================================================================*/
 
 #include <global.h>
+#include <time.h>
 #if ENABLE_JAVA_DEBUGGER
 #include <debugger.h>
 #endif
@@ -174,13 +175,11 @@
   *=======================================================================*/
 
 void InterpreterHandleEvent(ulong64 wakeupDelta) {
-    bool_t forever = FALSE;     /* The most common value */
+    
+    bool_t forever = FALSE;     
 
     if (ll_zero_ne(wakeupDelta)) {
-        /* wakeupDelta already has the right value.  But change it to
-         * be at most 20ms from now if the Java debugger is being used.
-         * We also do this if asynchronous native functions are in use.
-         */
+        
         if (vmDebugReady || ASYNCHRONOUS_NATIVE_FUNCTIONS) {
             ulong64 max = 20;
             if (ll_compare_ge(wakeupDelta, max)) {
@@ -188,24 +187,13 @@
             }
         }
     } else if (!areActiveThreads()) {
-        /*
-         * At this point, wakeupDelta == 0 AND there are NO active threads
-         * waiting to run.  This state could be caused by the debugger
-         * suspending threads OR there is an active async call that's somewhere
-         * in the OS doing it's thing.  We should therefore determine if there
-         * is a debugger active OR ASYNC functions in which case sleep for
-         * at most 20 ms. so that we can give the OS time to work and then
-         * return back to KVM and check status again
-         */
+        
       if (vmDebugReady || ASYNCHRONOUS_NATIVE_FUNCTIONS) {
           ll_int_to_long(wakeupDelta, 20);
       } else {
-          /* debugger not active AND no ASYNC_NATIVE_FUNCTIONS, wait forever */
+          
           forever = TRUE;
-          /* set wakeupDelta to the max given the current time.
-           * actually 1000 seconds less than the max to avoid any
-           * possibility of rollover 
-           */
+         
           ll_int_to_long(wakeupDelta, -1);
           ll_dec(wakeupDelta, CurrentTime_md());
           ll_dec(wakeupDelta, 1000000);
@@ -213,8 +201,7 @@
     }
 
     if (waitingThread == NULL) {
-        /* Nobody waiting for an event */
-        /* If active threads then just return */
+       
         if (areActiveThreads()) {
             return;
         }
@@ -226,7 +213,14 @@
         ProcessDebugCmds(delta);
 #endif
       } else {
-        SLEEP_FOR(wakeupDelta);
+        while(1){
+          time_t *t1 = NULL; time(t1); time_t t2 = NULL;
+          if(difftime(t2,t1) >= (double)wakeupDelta){
+            break;
+          }
+          else{t2 = NULL;
+            time_t(t2);}
+        }
       }
     } else {
         cell result;
@@ -237,6 +231,7 @@
             waitingThread = NULL;
         }
     }
+    
 }
 
  /*=========================================================================
diff -ruN ./temp/j2me_cldc/kvm/VmCommon/src/garbage.c ./final_my_j2me/kvm/VmCommon/src/garbage.c
--- ./temp/j2me_cldc/kvm/VmCommon/src/garbage.c	2003-02-06 13:55:59.000000000 +1300
+++ ./final_my_j2me/kvm/VmCommon/src/garbage.c	2007-05-15 18:13:50.000000000 +1200
@@ -350,7 +350,7 @@
  *=======================================================================*/
 
 void InitializeMemoryManagement(void)
-{
+{    
     int index;
     gcInProgress = 0;
     InitializeHeap();
diff -ruN ./temp/j2me_cldc/kvm/VmCommon/src/StartJVM.c ./final_my_j2me/kvm/VmCommon/src/StartJVM.c
--- ./temp/j2me_cldc/kvm/VmCommon/src/StartJVM.c	2003-02-06 13:56:00.000000000 +1300
+++ ./final_my_j2me/kvm/VmCommon/src/StartJVM.c	2007-05-15 18:13:46.000000000 +1200
@@ -98,7 +98,7 @@
  *=======================================================================*/
 
 int KVM_Start(int argc, char* argv[])
-{
+{    
     ARRAY arguments;
     INSTANCE_CLASS mainClass = NULL;
     volatile int returnValue = 0; /* Needed to make compiler happy */
@@ -108,7 +108,6 @@
         
             /* If ROMIZING and RELOCATABLE_ROM */
             CreateROMImage();
-
             /* Initialize Floating Point Arithmetic */
             InitializeFloatingPoint();
 
@@ -147,7 +146,9 @@
 
             /* Initialize the event handling system */
             InitializeEvents();
-
+            
+            /*Debugging JVM*/
+            
             /* Load the main application class */
             /* If loading fails, we get a C level exception */
             /* and control is transferred to the CATCH block below */
@@ -201,7 +202,6 @@
     } CATCH(e) {
         /* Any uncaught C-level exception above will transfer control here */
         if (mainClass == NULL) {
-            /* If main class was not found, print special error message */
             char buffer[STRINGBUFFERSIZE];
 
             sprintf(buffer, "%s", getClassName((CLASS)e->ofClass));
@@ -215,8 +215,7 @@
             Log->uncaughtException(e);
             returnValue = UNCAUGHT_EXCEPTION_EXIT_CODE;
         }
-    } END_CATCH
-
+    } END_CATCH    
     return returnValue;
 }
 
@@ -261,13 +260,11 @@
 int StartJVM(int argc, char* argv[])
 {
     volatile int returnValue = 0;
-
-    /* Ensure that we have a class to run */
+    
     if (argc <= 0 || argv[0] == NULL) {
         AlertUser(KVM_MSG_MUST_PROVIDE_CLASS_NAME);
         return -1;
-    }
-
+    }        
     returnValue = KVM_Start(argc, argv);
     KVM_Cleanup();
     return returnValue;
diff -ruN ./temp/j2me_cldc/kvm/VmCommon/src/verifierUtil.c ./final_my_j2me/kvm/VmCommon/src/verifierUtil.c
--- ./temp/j2me_cldc/kvm/VmCommon/src/verifierUtil.c	2003-02-06 13:56:00.000000000 +1300
+++ ./final_my_j2me/kvm/VmCommon/src/verifierUtil.c	2006-12-22 11:37:33.000000000 +1300
@@ -50,6 +50,10 @@
 unsigned short  vFrameSize;
 unsigned short  vSP;
 
+//Just making function declarations
+static int Vfy_verifyMethod(METHOD vMethod);
+static bool_t Vfy_checkNewInstructions(METHOD vMethod);
+
 #if INCLUDEDEBUGCODE
 static int vErrorIp;
 #endif
@@ -543,8 +547,7 @@
  *                fails.
  *=======================================================================*/
 
-int verifyClass(INSTANCE_CLASS thisClass) {
-    static int Vfy_verifyMethod(METHOD vMethod);
+int verifyClass(INSTANCE_CLASS thisClass) {   
     int i;
     int result = 0;
 #if USESTATIC
@@ -1594,8 +1597,7 @@
 
  static int Vfy_verifyMethod(METHOD vMethod) {
 
-    void Vfy_verifyMethodOrAbort(const METHOD vMethod);
-    static bool_t Vfy_checkNewInstructions(METHOD vMethod);
+    void Vfy_verifyMethodOrAbort(const METHOD vMethod);   
     int res;
 
 #if INCLUDEDEBUGCODE
diff -ruN ./temp/j2me_cldc/kvm/VmCommon/src/verifierUtil (copy).c ./final_my_j2me/kvm/VmCommon/src/verifierUtil (copy).c
--- ./temp/j2me_cldc/kvm/VmCommon/src/verifierUtil (copy).c	1970-01-01 12:00:00.000000000 +1200
+++ ./final_my_j2me/kvm/VmCommon/src/verifierUtil (copy).c	2003-02-06 13:56:00.000000000 +1300
@@ -0,0 +1,1702 @@
+/*
+ * Copyright © 2003 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ *
+ */
+
+/*=========================================================================
+ * SYSTEM:    KVM
+ * SUBSYSTEM: Class file verifier (runtime part)
+ * FILE:      verifierUtil.c
+ * OVERVIEW:  Implementation-specific parts of the KVM verifier.
+ * AUTHORS:   Sheng Liang, Frank Yellin, restructured by Nik Shaylor
+ *=======================================================================*/
+
+/*=========================================================================
+ * Include files
+ *=======================================================================*/
+
+#include <stddef.h>
+#include "verifierUtil.h"
+
+/*=========================================================================
+ * Global variables and definitions
+ *=======================================================================*/
+
+/*
+ * This is always the method being verified. (The verifier cannot be called
+ * recursively)
+ */
+METHOD methodBeingVerified;
+
+/*
+ * Pointer to the bytecodes
+ */
+unsigned char *bytecodesBeingVerified;
+
+/*
+ * Holds the return signature
+ */
+static unsigned char *returnSig;
+
+/*
+ * Global variables used by the verifier.
+ */
+VERIFIERTYPE *vStack;
+VERIFIERTYPE *vLocals;
+unsigned long *NEWInstructions;
+bool_t vNeedInitialization;      /* must call a this.<init> or super.<init> */
+unsigned short  vMaxStack;
+unsigned short  vFrameSize;
+unsigned short  vSP;
+
+#if INCLUDEDEBUGCODE
+static int vErrorIp;
+#endif
+
+/*=========================================================================
+ * Old verifier functions (inherited from KVM 1.0.3)
+ *=======================================================================*/
+
+/*=========================================================================
+ * FUNCTION:      initializeVerifier
+ * TYPE:          public global operation
+ * OVERVIEW:      Initialize the bytecode verifier
+ *
+ * INTERFACE:
+ *   parameters:  <nothing>
+ *   returns:     <nothing>
+ *=======================================================================*/
+
+void InitializeVerifier(void) {
+}
+
+/*=========================================================================
+ * FUNCTION:      vIsAssignable
+ * TYPE:          private operation on type keys
+ * OVERVIEW:      Check if a value of one type key can be converted to a
+ *                value of another type key.
+ *
+ * INTERFACE:
+ *   parameters:  fromKey: from type
+ *                toKey: to type
+ *                mergedKeyP: pointer to merged type
+ *   returns:     TRUE: can convert.
+ *                FALSE: cannot convert.
+ *=======================================================================*/
+
+bool_t vIsAssignable(VERIFIERTYPE fromKey, VERIFIERTYPE toKey, VERIFIERTYPE *mergedKeyP) {
+    if (mergedKeyP) {
+        /* Most of the time merged type is toKey */
+        *mergedKeyP = toKey;
+    }
+    if (fromKey == toKey)     /* trivial case */
+        return TRUE;
+    if (toKey == ITEM_Bogus)
+        return TRUE;
+    if (toKey == ITEM_Reference) {
+        return fromKey == ITEM_Null ||
+            fromKey > 255 ||
+            fromKey == ITEM_InitObject ||
+            (fromKey & ITEM_NewObject_Flag);
+    }
+    if ((toKey & ITEM_NewObject_Flag) || (fromKey & ITEM_NewObject_Flag)) {
+        return FALSE;
+    }
+    if (fromKey == ITEM_Null && toKey > 255) {
+        return TRUE;
+    }
+    if (fromKey > 255 && toKey > 255) {
+        CLASS fromClass = change_Key_to_CLASS(Vfy_toClassKey(fromKey));
+        CLASS toClass   = change_Key_to_CLASS(Vfy_toClassKey(toKey));
+        bool_t res = isAssignableTo(fromClass, toClass);
+        /* Interfaces are treated like java.lang.Object in the verifier. */
+        if (toClass->accessFlags & ACC_INTERFACE) {
+            /* Set mergedKey to fromKey for interfaces */
+            if (mergedKeyP) {
+                *mergedKeyP = Vfy_getObjectVerifierType();
+            }
+            return TRUE;
+        }
+        return res;
+    }
+    return FALSE;
+}
+
+/*=========================================================================
+ * FUNCTION:      vIsProtectedAccess
+ * TYPE:          private operation on type keys
+ * OVERVIEW:      Check if the access to a method or field is to
+ *                a protected field/method of a superclass.
+ *
+ * INTERFACE:
+ *   parameters:  thisClass:   The class in question
+ *                index:       Constant pool entry of field or method
+ *                isMethod:    true for method, false for field.
+ *=======================================================================*/
+
+bool_t vIsProtectedAccess(INSTANCE_CLASS thisClass, POOLINDEX index, bool_t isMethod) {
+    CONSTANTPOOL constPool = thisClass->constPool;
+    unsigned short memberClassIndex =
+        constPool->entries[index].method.classIndex;
+    INSTANCE_CLASS memberClass =
+        (INSTANCE_CLASS)constPool->entries[memberClassIndex].clazz;
+    INSTANCE_CLASS tClass;
+    unsigned short nameTypeIndex;
+    unsigned long nameTypeKey;
+
+    /* if memberClass isn't a superclass of this class, then we don't worry
+     * about this case */
+    for (tClass = thisClass; ; tClass = tClass->superClass) {
+        if (tClass == NULL) {
+            return FALSE;
+        } else if (tClass == memberClass) {
+            break;
+        }
+    }
+
+    nameTypeIndex = constPool->entries[index].method.nameTypeIndex;
+    nameTypeKey = constPool->entries[nameTypeIndex].nameTypeKey.i;
+
+    while (memberClass != NULL) {
+        if (isMethod) {
+            FOR_EACH_METHOD(method, memberClass->methodTable)
+                if (method->nameTypeKey.i == nameTypeKey) {
+                    return (((method->accessFlags & ACC_PROTECTED) != 0)
+                          && (memberClass->clazz.packageName !=
+                                thisClass->clazz.packageName));
+                }
+            END_FOR_EACH_METHOD
+        } else {
+            FOR_EACH_FIELD(field, memberClass->fieldTable)
+                if (field->nameTypeKey.i == nameTypeKey) {
+                    return (((field->accessFlags & ACC_PROTECTED) != 0)
+                          && (memberClass->clazz.packageName !=
+                                thisClass->clazz.packageName));
+                }
+            END_FOR_EACH_FIELD
+        }
+        memberClass = memberClass->superClass;
+    }
+    return FALSE;
+}
+
+/*=========================================================================
+ * FUNCTION:      Vfy_getReferenceArrayElementType
+ * TYPE:          private operation on type keys
+ * OVERVIEW:      Obtain the element type key of a given object reference type.
+ *
+ * INTERFACE:
+ *   parameters:  typeKey: object array type key.
+ *   returns:     element type key.
+ *
+ * DANGER:
+ *   Before calling this function, make sure that typeKey in fact is an
+ *   object array.
+ *=======================================================================*/
+
+VERIFIERTYPE Vfy_getReferenceArrayElementType(VERIFIERTYPE arrayType) {
+    CLASSKEY arrayTypeKey = Vfy_toClassKey(arrayType);
+    int n = (arrayTypeKey >> FIELD_KEY_ARRAY_SHIFT);
+    if (arrayTypeKey == ITEM_Null) {
+        return ITEM_Null;
+    } else if (n < MAX_FIELD_KEY_ARRAY_DEPTH) {
+        return ((n - 1) << FIELD_KEY_ARRAY_SHIFT) + (arrayTypeKey & 0x1FFF);
+    } else {
+        CLASS arrayClass           = change_Key_to_CLASS(Vfy_toClassKey(arrayTypeKey));
+        const char* baseNameString = arrayClass->baseName->string;
+        UString baseName           = getUStringX(&baseNameString, 1, arrayClass->baseName->length - 1);
+        UString packageName        = arrayClass->packageName;
+        CLASS elemClass            = change_Name_to_CLASS(packageName, baseName);
+        return Vfy_toVerifierType(elemClass->key);
+    }
+}
+
+/*=========================================================================
+ * FUNCTION:      Vfy_getClassArrayVerifierType
+ * TYPE:          private operation on type keys
+ * OVERVIEW:      Obtain the object array type key whose element type is the
+ *                given element type key.
+ *
+ * INTERFACE:
+ *   parameters:  typeKey: element type key.
+ *   returns:     object array type key.
+ *
+ * DANGER:
+ *   Before calling this function, make sure that typeKey in fact is an
+ *   object type.
+ *=======================================================================*/
+
+VERIFIERTYPE Vfy_getClassArrayVerifierType(CLASSKEY typeKey) {
+    CLASSKEY res;
+    int n = (typeKey >> FIELD_KEY_ARRAY_SHIFT);
+    if (n < MAX_FIELD_KEY_ARRAY_DEPTH - 1) {
+        res = (1 << FIELD_KEY_ARRAY_SHIFT) + typeKey;
+    } else {
+        CLASS elemClass = change_Key_to_CLASS(typeKey);
+        ARRAY_CLASS arrayClass = getObjectArrayClass(elemClass);
+        res = arrayClass->clazz.key;
+    }
+    return Vfy_toVerifierType(res);
+}
+
+/*=========================================================================
+ * FUNCTION:      Vfy_isArrayClassKey
+ * TYPE:          private operation on type keys
+ * OVERVIEW:      Check if the given type key denotes an array type of the
+ *                given dimension.
+ *
+ * INTERFACE:
+ *   parameters:  typeKey: a type key.
+ *                dim: dimension.
+ *   returns:     TRUE if the type key is an array of dim dimension, FALSE
+ *                otherwise.
+ *=======================================================================*/
+
+bool_t Vfy_isArrayClassKey(CLASSKEY typeKey, int dim) {
+    if (typeKey == ITEM_Null) {
+        return TRUE;
+    } else {
+        int n = (typeKey >> FIELD_KEY_ARRAY_SHIFT);
+        /* n is the dimension of the class.  It has the value
+         * 0..MAX_FIELD_KEY_ARRAY_DEPTH, in which the last value means
+         * MAX_FIELD_KEY_ARRAY_DEPTH or more. . .
+         */
+        if (dim <= MAX_FIELD_KEY_ARRAY_DEPTH) {
+            return n >= dim;
+        } if (n < MAX_FIELD_KEY_ARRAY_DEPTH) {
+            /* We are looking for at more than MAX_FIELD_KEY_ARRAY_DEPTH,
+             * dimensions, so n needs to be that value. */
+            return FALSE;
+        } else {
+            CLASS arrayClass = change_Key_to_CLASS(typeKey);
+            char *baseName = arrayClass->baseName->string;
+            /* The first dim characters of baseName must be [ */
+            for ( ; dim > 0; --dim) {
+                if (*baseName++ != '[') {
+                    return FALSE;
+                }
+            }
+            return TRUE;
+        }
+    }
+}
+
+/*=========================================================================
+ * FUNCTION:      change_Field_to_StackType
+ * TYPE:          private operation on type keys
+ * OVERVIEW:      Change an individual field type to a stack type
+ *
+ * INTERFACE:
+ *   parameters:  fieldType: field type
+ *                stackTypeP: pointer for placing the corresponding stack type(s)
+ *   returns:     number of words occupied by the resulting type.
+ *=======================================================================*/
+
+int change_Field_to_StackType(CLASSKEY fieldType, VERIFIERTYPE* stackTypeP) {
+    switch (fieldType) {
+        case 'I':
+        case 'B':
+        case 'Z':
+        case 'C':
+        case 'S':
+            *stackTypeP++ = ITEM_Integer;
+            return 1;
+#if IMPLEMENTS_FLOAT
+        case 'F':
+            *stackTypeP++ = ITEM_Float;
+            return 1;
+        case 'D':
+            *stackTypeP++ = ITEM_Double;
+            *stackTypeP++ = ITEM_Double_2;
+            return 2;
+#endif
+        case 'J':
+            *stackTypeP++ = ITEM_Long;
+            *stackTypeP++ = ITEM_Long_2;
+            return 2;
+        default:
+            *stackTypeP++ = fieldType;
+            return 1;
+    }
+}
+
+/*=========================================================================
+ * FUNCTION:      change_Arg_to_StackType
+ * TYPE:          private operation on type keys
+ * OVERVIEW:      Change an individual method argument type to a stack type
+ *
+ * INTERFACE:
+ *   parameters:  sigP: pointer to method signature.
+ *                type: pointer for placing the corresponding stack type(s)
+ *   returns:     number of words occupied by the resulting type.
+ *=======================================================================*/
+
+int change_Arg_to_StackType(unsigned char** sigP, VERIFIERTYPE* typeP) {
+    unsigned char *sig = *sigP;
+    unsigned short hi, lo;
+
+    hi = *sig++;
+
+    if (hi == 'L') {
+        hi = *sig++;
+        lo = *sig++;
+        *sigP = sig;
+        return change_Field_to_StackType((unsigned short)((hi << 8) + lo), typeP);
+    }
+    if (hi < 'A' || hi > 'Z') {
+        lo = *sig++;
+        *sigP = sig;
+        return change_Field_to_StackType((unsigned short)((hi << 8) + lo), typeP);
+    }
+    *sigP = sig;
+    return change_Field_to_StackType(hi, typeP);
+}
+
+/*=========================================================================
+ * FUNCTION:      getStackType
+ * TYPE:          private operation on type keys
+ * OVERVIEW:      Get the recorded stack map of a given target ip.
+ *
+ * INTERFACE:
+ *   parameters:  thisMethod: method being verified.
+ *                this_ip: current ip (unused for now).
+ *                target_ip: target ip (to look for a recored stack map).
+ *   returns:     a stack map
+ *=======================================================================*/
+
+static unsigned short *getStackMap(METHOD thisMethod, IPINDEX target_ip) {
+    POINTERLIST stackMaps = thisMethod->u.java.stackMaps.verifierMap;
+    unsigned short i;
+    if (stackMaps == NULL) {
+        return NULL;
+    } else {
+        long length = stackMaps->length; /* number of entries */
+        for (i = 0; i < length; i++) {
+            if (target_ip == stackMaps->data[i + length].cell) {
+                return (unsigned short*)stackMaps->data[i].cellp;
+            }
+        }
+    }
+    return NULL;
+}
+
+/*=========================================================================
+ * FUNCTION:      matchStackMap
+ * TYPE:          private operation on type keys
+ * OVERVIEW:      Match two stack maps.
+ *
+ * INTERFACE:
+ *   parameters:  thisMethod: method being verified.
+ *                target_ip: target ip (to look for a recored stack map).
+ *                flags: bit-wise or of the SM_* flags.
+ *   returns:     TRUE if match, FALSE otherwise.
+ *=======================================================================*/
+
+bool_t matchStackMap(METHOD thisMethod, IPINDEX target_ip, int flags) {
+    bool_t result = TRUE;  /* Assume result is TRUE */
+    bool_t target_needs_initialization;
+    unsigned short nstack;
+    unsigned short nlocals;
+    unsigned short i;
+
+    /* Following is volatile, and will disappear at first GC */
+    unsigned short *stackMapBase = getStackMap(thisMethod, target_ip);
+
+#if INCLUDEDEBUGCODE
+    if (traceverifier) {
+        fprintf(stdout, "Match stack maps (this=%ld, target=%ld)%s%s%s\n",
+                (long)vErrorIp, (long)target_ip,
+            (flags & SM_CHECK) ? " CHECK" : "",
+            (flags & SM_MERGE) ? " MERGE" : "",
+            (flags & SM_EXIST) ? " EXIST" : "");
+    }
+#endif
+
+    if (stackMapBase == NULL) {
+#if INCLUDEDEBUGCODE
+        if (traceverifier) {
+            fprintf(stdout, "No recorded stack map at %ld\n", (long)target_ip);
+        }
+#endif
+        return !(flags & SM_EXIST);
+    }
+
+  START_TEMPORARY_ROOTS
+    DECLARE_TEMPORARY_ROOT_FROM_BASE(unsigned short*, stackMap,
+                                     stackMapBase, stackMapBase);
+
+#if INCLUDEDEBUGCODE
+    if (traceverifier) {
+        static void printStackMap(METHOD thisMethod, IPINDEX ip);
+        printStackMap(thisMethod, target_ip);
+    }
+#endif
+
+    nlocals = *stackMap++;
+    /* We implicitly need to still perform initialization if at least
+     * one local or stack variable contains ITEM_InitObject */
+    target_needs_initialization = FALSE;
+
+    for (i = 0; i < nlocals; i++) {
+        unsigned short ty = *stackMap++;
+        unsigned short mergedType = ty;
+        if (ty == ITEM_InitObject) { 
+            target_needs_initialization = TRUE;
+        }
+        if ((SM_CHECK & flags) && !vIsAssignable(vLocals[i], ty, &mergedType)) {
+            result = FALSE;
+            goto done;
+        }
+        if (SM_MERGE & flags) {
+            vLocals[i] = mergedType;
+        }
+    }
+    if (SM_MERGE & flags) {
+        for (i = nlocals; i < vFrameSize; i++) {
+            vLocals[i] = ITEM_Bogus;
+        }
+    }
+
+    nstack = *stackMap++;
+    if ((SM_CHECK & flags) && nstack != vSP) {
+        result = FALSE;
+        goto done;
+    }
+    if (SM_MERGE & flags) {
+        vSP = nstack;
+    }
+    for (i = 0; i < nstack; i++) {
+        unsigned short ty = *stackMap++;
+        unsigned short mergedType = ty;
+        if (ty == ITEM_InitObject) { 
+            target_needs_initialization = TRUE;
+        }
+        if ((SM_CHECK & flags) && !vIsAssignable(vStack[i], ty, &mergedType)) {
+            result = FALSE;
+            goto done;
+        }
+        if (SM_MERGE & flags) {
+            vStack[i] = mergedType;
+        }
+    }
+
+    if (methodBeingVerified->nameTypeKey.nt.nameKey 
+                                     == initNameAndType.nt.nameKey) {
+        if (SM_CHECK & flags) { 
+            if (vNeedInitialization && !target_needs_initialization) { 
+                /* We still need to perform initialization, but we are
+                 * merging into a location that doesn't.
+                 */
+                result = FALSE;
+                goto done;
+            }
+        }
+
+        if (SM_MERGE & flags) { 
+            vNeedInitialization = target_needs_initialization;
+        }
+    }
+
+ done:
+  END_TEMPORARY_ROOTS
+  return result;
+}
+
+/*=========================================================================
+ * FUNCTION:      checkNewObject
+ * TYPE:          private operation on type keys
+ * OVERVIEW:      Check if uninitialized objects exist on backward branches.
+ *
+ * INTERFACE:
+ *   parameters:  this_ip: current ip
+ *                target_ip: branch target ip
+ *   returns:     TRUE if no uninitialized objects exist, FALSE otherwise.
+ *=======================================================================*/
+
+bool_t checkNewObject(IPINDEX this_ip, IPINDEX target_ip) {
+    if (target_ip < this_ip) {
+        int i;
+        for (i = 0; i < vFrameSize; i++) {
+            if (vLocals[i] & ITEM_NewObject_Flag) {
+                return FALSE;
+            }
+        }
+        for (i = 0; i < vSP; i++) {
+            if (vStack[i] & ITEM_NewObject_Flag) {
+                return FALSE;
+            }
+        }
+    }
+    return TRUE;
+}
+
+/*=========================================================================
+ * FUNCTION:      verifyClass
+ * TYPE:          public operation on classes.
+ * OVERVIEW:      Perform byte-code verification of a given class. Iterate
+ *                through all methods.
+ *
+ * INTERFACE:
+ *   parameters:  thisClass: class to be verified.
+ *   returns:     0 if verification succeeds, error code if verification
+ *                fails.
+ *=======================================================================*/
+
+int verifyClass(INSTANCE_CLASS thisClass) {
+    static int Vfy_verifyMethod(METHOD vMethod);
+    int i;
+    int result = 0;
+#if USESTATIC
+    CONSTANTPOOL cp = thisClass->constPool;
+#endif
+    if (thisClass->methodTable) {
+        if (!checkVerifiedClassList(thisClass)) {
+            /* Verify all methods */
+            for (i = 0; i < thisClass->methodTable->length; i++) {
+                METHOD thisMethod = &thisClass->methodTable->methods[i];
+
+                /* Skip special synthesized methods. */
+                if (thisMethod == RunCustomCodeMethod) {
+                    continue;
+                }
+                /* Skip abstract and native methods. */
+                if (thisMethod->accessFlags & (ACC_NATIVE | ACC_ABSTRACT)) {
+                    continue;
+                }
+
+               /*
+                * Call the core routine
+                */
+                result = Vfy_verifyMethod(thisMethod);
+                if (result != 0) {
+                    break;
+                }
+            }
+
+            if (result == 0) {
+                /* Add this newly verified class to verified class list. */
+                appendVerifiedClassList(thisClass);
+            }
+        }
+
+        /* Rewrite the stack maps */
+        for (i = 0; i < thisClass->methodTable->length; i++) {
+            METHOD thisMethod = &thisClass->methodTable->methods[i];
+            if (thisMethod->u.java.stackMaps.verifierMap != NULL) {
+                STACKMAP newStackMap = (result == 0)
+                     ? rewriteVerifierStackMapsAsPointerMaps(thisMethod)
+                     :  NULL;
+#if !USESTATIC
+                thisMethod->u.java.stackMaps.pointerMap = newStackMap;
+#else
+                int offset = (char *)&thisMethod->u.java.stackMaps.pointerMap
+                           - (char *)cp;
+                modifyStaticMemory(cp, offset, &newStackMap, sizeof(STACKMAP));
+#endif
+            }
+        }
+    }
+    if (result == 0) {
+        thisClass->status = CLASS_VERIFIED;
+    } else {
+        START_TEMPORARY_ROOTS
+            DECLARE_TEMPORARY_ROOT(char*, className, getClassName((CLASS)thisClass));
+            thisClass->status = CLASS_ERROR;
+            if (className) {
+                raiseExceptionWithMessage(VerifyError, className);
+            } else {
+                raiseException(VerifyError);
+            }
+        END_TEMPORARY_ROOTS
+    }
+
+    return result;
+}
+
+/*=========================================================================
+ * Debugging and printing operations
+ *=======================================================================*/
+
+/*=========================================================================
+ * FUNCTION:      printStackType, printStackMap
+ * TYPE:          debugging operations
+ * OVERVIEW:      Print verifier-related information
+ *
+ * INTERFACE:
+ *   parameters:  pretty obvious
+ *   returns:
+ *=======================================================================*/
+
+#if INCLUDEDEBUGCODE
+
+/* Print a string, and add padding. */
+static void
+print_str(char *str)
+{
+    int i;
+    fprintf(stdout, "%s", str);
+    i = 30 - strlen(str);
+    while (i > 0) {
+        fprintf(stdout, " ");
+        i--;
+    }
+}
+
+/* Print a type key */
+static void
+printStackType(METHOD thisMethod, unsigned short key)
+{
+    char buf[128];
+    switch (key) {
+    case 0xFFF:
+        print_str("-");
+        return;
+    case ITEM_Bogus:
+        print_str("*");
+        return;
+    case ITEM_Integer:
+        print_str("I");
+        return;
+#if IMPLEMENTS_FLOAT
+    case ITEM_Float:
+        print_str("F");
+        return;
+    case ITEM_Double:
+        print_str("D");
+        return;
+#endif
+    case ITEM_Long:
+        print_str("J");
+        return;
+    case ITEM_Null:
+        print_str("null");
+        return;
+    case ITEM_InitObject:
+        print_str("this");
+        return;
+    case ITEM_Long_2:
+        print_str("J2");
+        return;
+#if IMPLEMENTS_FLOAT
+    case ITEM_Double_2:
+        print_str("D2");
+        return;
+#endif
+    default: /* ITEM_Object and ITEM_NewObject */
+        if (key & ITEM_NewObject_Flag) {
+            sprintf(buf, "new %ld", (long)DECODE_NEWOBJECT(key));
+            print_str(buf);
+        } else {
+            print_str(change_Key_to_FieldSignature(key));
+        }
+        return;
+    }
+}
+
+#define MAX(a,b) ((a) > (b) ? (a) : (b))
+
+/* Print the derived stackmap and recorded stackmap (if it exists) at
+ * a given ip.
+ */
+static void
+printStackMap(METHOD thisMethod, unsigned short ip)
+{
+  START_TEMPORARY_ROOTS
+    unsigned short* stackMapX = getStackMap(thisMethod, ip);
+    DECLARE_TEMPORARY_ROOT_FROM_BASE(unsigned short*, stackMap,
+                                     stackMapX, stackMapX);
+    int nlocals, nstack, i;
+    int lTop;
+
+    for (lTop = vFrameSize; lTop > 0; lTop--) {
+        if (vLocals[lTop - 1] != ITEM_Bogus) {
+            break;
+        }
+    }
+
+    fprintf(stdout, "__SLOT__DERIVED_______________________");
+    if (stackMap) {
+        fprintf(stdout, "RECORDED______________________\n");
+    } else {
+        fprintf(stdout, "\n");
+    }
+
+    nlocals = stackMap ? (*stackMap++) : 0;
+
+    for (i = 0; i < MAX(lTop, nlocals); i++) {
+        unsigned short ty;
+        if (i < 100) {
+            fprintf(stdout, " ");
+            if (i < 10) {
+                fprintf(stdout, " ");
+            }
+        }
+        fprintf(stdout, "L[%ld]  ", (long)i);
+        if (i < lTop) {
+            ty = vLocals[i];
+        } else {
+            ty = 0xFFF;
+        }
+        printStackType(thisMethod, ty);
+        if (stackMap) {
+            if (i < nlocals) {
+                ty = *stackMap++;
+            } else {
+                ty = 0xFFF;
+            }
+            printStackType(thisMethod, ty);
+        }
+        fprintf(stdout, "\n");
+    }
+
+    nstack = stackMap ? (*stackMap++) : 0;
+
+    for (i = 0; i < MAX(vSP, nstack); i++) {
+        unsigned short ty;
+        if (i < 100) {
+            fprintf(stdout, " ");
+            if (i < 10) {
+                fprintf(stdout, " ");
+            }
+        }
+        fprintf(stdout, "S[%ld]  ", (long)i);
+        if (i < vSP) {
+            ty = vStack[i];
+        } else {
+            ty = 0xFFF;
+        }
+        printStackType(thisMethod, ty);
+
+        if (stackMap) {
+            if (i < nstack) {
+                ty = *stackMap++;
+            } else {
+                ty = 0xFFF;
+            }
+            printStackType(thisMethod, ty);
+        }
+        fprintf(stdout, "\n");
+    }
+  END_TEMPORARY_ROOTS
+}
+
+#endif /* INCLUDEDEBUGCODE */
+
+/*=========================================================================
+ * New verifier functions
+ *=======================================================================*/
+
+/* ------------------------------------------------------------------------ *\
+ *                              Initialization                              *
+\* ------------------------------------------------------------------------ */
+
+/*=========================================================================
+ * FUNCTION:      Vfy_initializeLocals
+ * TYPE:          private operation
+ * OVERVIEW:      Initialize the local variable types from the method
+ *                signature
+ *
+ * INTERFACE:
+ *   parameters:  None
+ *   returns:     Nothing
+ *=======================================================================*/
+
+void Vfy_initializeLocals() {
+    /* Fill in the initial derived stack map with argument types. */
+    unsigned char *sig = (unsigned char*) change_Key_to_Name(methodBeingVerified->nameTypeKey.nt.typeKey, NULL);
+
+    int nargs = *sig++;
+    int i;
+    int n;
+
+    n = 0;
+    vNeedInitialization = FALSE;
+    if (!Mth_isStatic(methodBeingVerified)) {
+        /* add one extra argument for instance methods */
+        n++;
+        if (methodBeingVerified->nameTypeKey.nt.nameKey == initNameAndType.nt.nameKey &&
+            methodBeingVerified->ofClass->clazz.key != Vfy_getObjectVerifierType()) {
+            vLocals[0] = ITEM_InitObject;
+            vNeedInitialization = TRUE;
+        } else {
+            vLocals[0] = methodBeingVerified->ofClass->clazz.key;
+        }
+    }
+    for (i = 0; i < nargs; i++) {
+        n += change_Arg_to_StackType(&sig, &vLocals[n]);
+    }
+
+    returnSig = sig;
+}
+
+/* ------------------------------------------------------------------------ *\
+ *                             General functions                            *
+\* ------------------------------------------------------------------------ */
+
+/*=========================================================================
+ * FUNCTION:      Vfy_getOpcode
+ * TYPE:          private operation
+ * OVERVIEW:      Get an opcode from the bytecode array.
+ *                If it is a BREAKPOINT then get
+ *                the real instruction from the debugger
+ *
+ * INTERFACE:
+ *   parameters:  IPINDEX of the bytecode
+ *   returns:     The opcode
+ *=======================================================================*/
+
+int Vfy_getOpcode(IPINDEX ip) {
+    int opcode = Vfy_getUByte(ip);
+#if ENABLE_JAVA_DEBUGGER
+        if (opcode == BREAKPOINT) {
+                opcode = getVerifierBreakpointOpcode(methodBeingVerified, ip);
+        }
+#endif
+    return opcode;
+}
+
+/* ------------------------------------------------------------------------ *\
+ *                          Stack state management                          *
+\* ------------------------------------------------------------------------ */
+
+static unsigned short vSP_bak;
+static VERIFIERTYPE   vStack0_bak;
+
+/*=========================================================================
+ * FUNCTION:      Vfy_saveStackState
+ * TYPE:          private operation
+ * OVERVIEW:      Save and initialize the type stack
+ *
+ * INTERFACE:
+ *   parameters:  None
+ *   returns:     Nothing
+ *=======================================================================*/
+
+void Vfy_saveStackState() {
+    vSP_bak = vSP;
+    vStack0_bak = vStack[0];
+    vSP = 0;
+}
+
+/*=========================================================================
+ * FUNCTION:      Vfy_restoreStackState
+ * TYPE:          private operation
+ * OVERVIEW:      Restore the saved type stack
+ *
+ * INTERFACE:
+ *   parameters:  None
+ *   returns:     Nothing
+ *=======================================================================*/
+
+void Vfy_restoreStackState() {
+    vStack[0] = vStack0_bak;
+    vSP = vSP_bak;
+}
+
+/* ------------------------------------------------------------------------ *\
+ *                              Type checking                               *
+\* ------------------------------------------------------------------------ */
+
+/*=========================================================================
+ * FUNCTION:      Vfy_getLocal
+ * TYPE:          private operation on the virtual local frame
+ * OVERVIEW:      Get a type key from the virtual local frame maintained by
+ *                the verifier. Performs index check and type check.
+ *
+ * INTERFACE:
+ *   parameters:  index: the local index
+ *                typeKey: the type expected.
+ *   returns:     The actual type from the slot
+ *=======================================================================*/
+
+VERIFIERTYPE Vfy_getLocal(SLOTINDEX index, VERIFIERTYPE typeKey) {
+    VERIFIERTYPE k;
+    if (index >= vFrameSize) {
+        Vfy_throw(VE_LOCALS_OVERFLOW);
+    }
+    k = vLocals[index];
+    if (!vIsAssignable(k, typeKey, NULL)) {
+        Vfy_throw(VE_LOCALS_BAD_TYPE);
+    }
+    return k;
+}
+
+/*=========================================================================
+ * FUNCTION:      Vfy_setLocal
+ * TYPE:          private operation on the virtual local frame
+ * OVERVIEW:      Set a type key in the virtual local frame maintained by
+ *                the verifier. Performs index check and type check.
+ *
+ * INTERFACE:
+ *   parameters:  index: local index.
+ *                typeKey: the supplied type.
+ *   returns:     Nothing
+ *=======================================================================*/
+
+void Vfy_setLocal(SLOTINDEX index, VERIFIERTYPE typeKey) {
+    if (index >= vFrameSize) {
+        Vfy_throw(VE_LOCALS_OVERFLOW);
+    }
+
+    if (vLocals[index] == ITEM_Long_2
+#if IMPLEMENTS_FLOAT
+        || vLocals[index] == ITEM_Double_2
+#endif
+        ) {
+        if (index < 1) {
+            Vfy_throw(VE_LOCALS_UNDERFLOW);
+        }
+        vLocals[index - 1] = ITEM_Bogus;
+    }
+
+    if (vLocals[index] == ITEM_Long
+#if IMPLEMENTS_FLOAT
+        || vLocals[index] == ITEM_Double
+#endif
+        ) {
+        if (index >= vFrameSize - 1) {
+            Vfy_throw(VE_LOCALS_OVERFLOW);
+        }
+        vLocals[index + 1] = ITEM_Bogus;
+    }
+    vLocals[index] = typeKey;
+}
+
+/*=========================================================================
+ * FUNCTION:      vPushStack
+ * TYPE:          private operation on the virtual stack
+ * OVERVIEW:      Push a type key onto the virtual stack maintained by
+ *                the verifier. Performs stack overflow check.
+ *
+ * INTERFACE:
+ *   parameters:  typeKey: the type to be pushed.
+ *   returns:     Nothing
+ *=======================================================================*/
+
+void Vfy_push(VERIFIERTYPE typeKey) {
+    if (vSP >= vMaxStack) {
+        Vfy_throw(VE_STACK_OVERFLOW);
+    }
+    vStack[vSP++] = typeKey;
+}
+
+/*=========================================================================
+ * FUNCTION:      Vfy_pop
+ * TYPE:          private operation on the virtual stack
+ * OVERVIEW:      Pop an item from the virtual stack maintained by
+ *                the verifier. Performs stack underflow check and type check.
+ *
+ * INTERFACE:
+ *   parameters:  typeKey: The expected type
+ *   returns:     The actual type popped
+ *=======================================================================*/
+
+VERIFIERTYPE Vfy_pop(VERIFIERTYPE typeKey) {
+    VERIFIERTYPE resultKey;
+
+    if (typeKey == ITEM_DoubleWord || typeKey == ITEM_Category2 || typeKey == ITEM_Category1) {
+        fatalError(KVM_MSG_V_BAD_POPSTACK_TYPE);
+    }
+
+    if (vSP == 0) { /* vSP is unsigned, See bug 4323211 */
+        Vfy_throw(VE_STACK_UNDERFLOW);
+    }
+
+    resultKey = vStack[vSP - 1];
+    vSP--;
+
+    if (!vIsAssignable(resultKey, typeKey, NULL)) {
+        Vfy_throw(VE_STACK_BAD_TYPE);
+    }
+    return resultKey;
+}
+
+/*=========================================================================
+ * FUNCTION:      Vfy_popCategory2_secondWord
+ * TYPE:          private operation on the virtual stack
+ * OVERVIEW:      Pop an the second word of an ITEM_DoubleWord or ITEM_Category2
+ *                from the virtual stack maintained by the verifier.
+ *                Performs stack underflow check and type check.
+ *                (This is always called before vPopStackCategory2_firstWord)
+ *
+ * INTERFACE:
+ *   parameters:  None.
+ *   returns:     The actual type popped
+ *=======================================================================*/
+
+VERIFIERTYPE Vfy_popCategory2_secondWord() {
+    VERIFIERTYPE resultKey;
+    if (vSP <= 1) {
+        Vfy_throw(VE_STACK_UNDERFLOW);
+    }
+
+    resultKey = vStack[vSP - 1];
+    vSP--;
+
+    return resultKey;
+}
+
+/*=========================================================================
+ * FUNCTION:      Vfy_popCategory2_firstWord
+ * TYPE:          private operation on the virtual stack
+ * OVERVIEW:      Pop an the first word of an ITEM_DoubleWord or ITEM_Category2
+ *                from the virtual stack maintained by the verifier.
+ *                Performs stack underflow check and type check.
+ *
+ * INTERFACE:
+ *   parameters:  None.
+ *   returns:     The actual type popped
+ *=======================================================================*/
+
+VERIFIERTYPE Vfy_popCategory2_firstWord() {
+    VERIFIERTYPE resultKey;
+    if (vSP <= 0) {
+        Vfy_throw(VE_STACK_UNDERFLOW);
+    }
+
+    resultKey = vStack[vSP - 1];
+    vSP--;
+
+   /*
+    * The only think known about this operation is that it
+    * cannot result in an ITEM_Long_2 or ITEM_Double_2 being
+    * popped.
+    */
+
+    if ((resultKey == ITEM_Long_2) || (resultKey == ITEM_Double_2)) {
+        Vfy_throw(VE_STACK_BAD_TYPE);
+    }
+
+    return resultKey;
+}
+
+/*=========================================================================
+ * FUNCTION:      Vfy_popCategory1
+ * TYPE:          private operation on the virtual stack
+ * OVERVIEW:      Pop a ITEM_Category1 from the virtual stack maintained by
+ *                the verifier. Performs stack underflow check and type check.
+ *
+ * INTERFACE:
+ *   parameters:  None.
+ *   returns:     The actual type popped
+ *=======================================================================*/
+
+VERIFIERTYPE Vfy_popCategory1() {
+    VERIFIERTYPE resultKey;
+    if (vSP == 0) { /* vSP is unsigned, See bug 4323211 */
+        Vfy_throw(VE_STACK_UNDERFLOW);
+    }
+    resultKey = vStack[vSP - 1];
+    vSP--;
+
+    if (resultKey == ITEM_Integer ||
+#if IMPLEMENTS_FLOAT
+        resultKey == ITEM_Float ||
+#endif
+        resultKey == ITEM_Null ||
+        resultKey > 255 ||
+        resultKey == ITEM_InitObject ||
+       (resultKey & ITEM_NewObject_Flag)) {
+       /* its okay */
+    } else {
+        Vfy_throw(VE_STACK_EXPECT_CAT1);
+    }
+    return resultKey;
+}
+
+/*=========================================================================
+ * FUNCTION:      Vfy_returnVoid
+ * TYPE:          private operation
+ * OVERVIEW:      Check that a return is valid for this method. If the
+ *                method is <init> make sure that 'this' was initialized
+ *
+ * INTERFACE:
+ *   parameters:  None.
+ *   returns:     Nothing.
+ *=======================================================================*/
+
+void Vfy_returnVoid() {
+    if (returnSig[0] != 'V') {
+        Vfy_throw(VE_EXPECT_RETVAL);
+    }
+    if (methodBeingVerified->nameTypeKey.nt.nameKey 
+                       == initNameAndType.nt.nameKey) {
+        if (vNeedInitialization) { 
+            Vfy_throw(VE_RETURN_UNINIT_THIS);
+        }
+    }
+}
+
+/*=========================================================================
+ * FUNCTION:      Vfy_popReturn
+ * TYPE:          private operation
+ * OVERVIEW:      Check that a return is valid for this method.
+ *
+ * INTERFACE:
+ *   parameters:  returnType: the type to be returned.
+ *   returns:     Nothing.
+ *=======================================================================*/
+
+void Vfy_popReturn(VERIFIERTYPE returnType) {
+
+    VERIFIERTYPE ty[2];
+    unsigned char *sig = returnSig;
+
+    returnType = Vfy_pop(returnType);
+
+    if (sig[0] == 'V') {
+        Vfy_throw(VE_EXPECT_NO_RETVAL);
+    }
+    change_Arg_to_StackType(&sig, ty);
+    if (!Vfy_isAssignable(returnType, ty[0])) {
+        Vfy_throw(VE_RETVAL_BAD_TYPE);
+    }
+
+   /*
+    * Is this needed here as well as in Vfy_popReturnVoid()?
+    */
+
+    if (methodBeingVerified->nameTypeKey.nt.nameKey == initNameAndType.nt.nameKey) {
+        fatalError(KVM_MSG_VFY_UNEXPECTED_RETURN_TYPE);
+     /*
+     //   if (vLocals[0] == ITEM_InitObject) {
+     //       Vfy_throw(VE_RETURN_UNINIT_THIS);
+     //   }
+     */
+    }
+}
+
+/*=========================================================================
+ * FUNCTION:      Vfy_pushClassKey
+ * TYPE:          private operation on type keys
+ * OVERVIEW:      Push the equivalent VERIFIERTYPES for CLASSKEY
+ *
+ * INTERFACE:
+ *   parameters:  fieldType: CLASSKEY
+ *   returns:     Nothing
+ *=======================================================================*/
+
+void Vfy_pushClassKey(CLASSKEY fieldType) {
+    switch (fieldType) {
+        case 'I':
+        case 'B':
+        case 'Z':
+        case 'C':
+        case 'S': {
+            Vfy_push(ITEM_Integer);
+            break;
+        }
+#if IMPLEMENTS_FLOAT
+        case 'F': {
+            Vfy_push(ITEM_Float);
+            break;
+        }
+        case 'D': {
+            Vfy_push(ITEM_Double);
+            Vfy_push(ITEM_Double_2);
+            break;
+        }
+#endif
+        case 'J': {
+            Vfy_push(ITEM_Long);
+            Vfy_push(ITEM_Long_2);
+            break;
+        }
+        default: {
+            Vfy_push(Vfy_toVerifierType(fieldType));
+            break;
+        }
+    }
+}
+
+/*=========================================================================
+ * FUNCTION:      Vfy_popClassKey
+ * TYPE:          private operation on type keys
+ * OVERVIEW:      Pop the equivalent VERIFIERTYPES for CLASSKEY
+ *
+ * INTERFACE:
+ *   parameters:  fieldType: CLASSKEY
+ *   returns:     Nothing
+ *=======================================================================*/
+
+void Vfy_popClassKey(CLASSKEY fieldType) {
+    switch (fieldType) {
+        case 'I':
+        case 'B':
+        case 'Z':
+        case 'C':
+        case 'S': {
+            Vfy_pop(ITEM_Integer);
+            break;
+        }
+#if IMPLEMENTS_FLOAT
+        case 'F': {
+            Vfy_pop(ITEM_Float);
+            break;
+        }
+        case 'D': {
+            Vfy_pop(ITEM_Double_2);
+            Vfy_pop(ITEM_Double);
+            break;
+        }
+#endif
+        case 'J': {
+            Vfy_pop(ITEM_Long_2);
+            Vfy_pop(ITEM_Long);
+            break;
+        }
+        default: {
+            Vfy_pop(Vfy_toVerifierType(fieldType));
+            break;
+        }
+    }
+}
+
+/*=========================================================================
+ * FUNCTION:      Vfy_setupCalleeContext
+ * TYPE:          private operation
+ * OVERVIEW:      Pop the arguments of the callee context
+ *
+ * INTERFACE:
+ *   parameters:  Class key for the methodTypeKey
+ *   returns:     Nothing.
+ *=======================================================================*/
+
+METHODTYPEKEY calleeContext;
+unsigned char *sigResult;
+
+void Vfy_setupCalleeContext(METHODTYPEKEY methodTypeKey) {
+    calleeContext = methodTypeKey;
+}
+
+/*=========================================================================
+ * FUNCTION:      Vfy_popInvokeArguments
+ * TYPE:          private operation on stack
+ * OVERVIEW:      Pop the arguments of the callee context
+ *
+ * INTERFACE:
+ *   parameters:  None
+ *   returns:     The number of words popped
+ *=======================================================================*/
+
+int Vfy_popInvokeArguments() {
+
+    unsigned char* sig = (unsigned char*)change_Key_to_Name(calleeContext, NULL);
+    unsigned char* sig_bak;
+    unsigned short nargs;
+    int nwords = 0;
+    CLASSKEY ty[2];
+    int j,k;
+    unsigned short i;
+
+    nargs = *sig++;
+
+    sig_bak = sig;
+
+    for (i = 0; i < nargs; i++) {
+        nwords += change_Arg_to_StackType(&sig, ty);
+    }
+    sig = sig_bak;
+
+   /*
+    * Are there the required number of words on the stack?
+    */
+    if (vSP < nwords) {
+        Vfy_throw(VE_ARGS_NOT_ENOUGH);
+    }
+    vSP -= nwords;
+
+    k = 0;
+    for (i = 0; i < nargs; i++) {
+        int n = change_Arg_to_StackType(&sig, ty);
+        for (j = 0; j < n; j++) {
+            VERIFIERTYPE arg = vStack[vSP + k];
+            if (!vIsAssignable(arg, ty[j], NULL)) {
+                Vfy_throw(VE_ARGS_BAD_TYPE);
+            }
+            k++;
+        }
+    }
+
+   sigResult = sig;
+
+   return nwords;
+}
+
+/*=========================================================================
+ * FUNCTION:      Vfy_pushInvokeResult
+ * TYPE:          private operation on stack
+ * OVERVIEW:      Push the callee's result
+ *
+ * INTERFACE:
+ *   parameters:  None
+ *   returns:     Nothing
+ *=======================================================================*/
+
+void Vfy_pushInvokeResult() {
+
+   /*
+    * Push the result type.
+    */
+    if (*sigResult != 'V') {
+        CLASSKEY ty[2];
+        int i;
+        int n = change_Arg_to_StackType(&sigResult, ty);
+        for (i = 0 ; i < n; i++) {
+            Vfy_push(ty[i]);
+        }
+    }
+}
+
+bool_t Vfy_MethodNameStartsWithLeftAngleBracket(METHODNAMEKEY methodNameKey) {
+    char *methodName = change_Key_to_Name(methodNameKey, NULL);
+    return methodName[0] == '<';
+}
+
+bool_t Vfy_MethodNameIsInit(METHODNAMEKEY methodNameKey) {
+    return methodNameKey == initNameAndType.nt.nameKey;
+}
+
+void Vfy_ReplaceTypeWithType(VERIFIERTYPE fromType, VERIFIERTYPE toType) {
+    int i;
+    for (i = 0; i < vSP; i++) {
+        if (vStack[i] == fromType) {
+            vStack[i] = toType;
+        }
+    }
+    for (i = 0; i < Mth_frameSize(methodBeingVerified); i++) {
+        if (vLocals[i] == fromType) {
+            vLocals[i] = toType;
+        }
+    }
+
+}
+
+/* ------------------------------------------------------------------------ *\
+ *                          Method Accessor Methods                         *
+\* ------------------------------------------------------------------------ */
+
+/*=========================================================================
+ * FUNCTION:      Mth_getStackMapEntryIP
+ * TYPE:          private operation
+ * OVERVIEW:      Get the ip address of an entry in the stack map table
+ *
+ * INTERFACE:
+ *   parameters:  vMethod: the method, stackMapIndex: the index
+ *   returns:     The ip address of the indexed entry. Or 0x7FFFFFFF if
+ *                the index is off the end of the table.
+ *=======================================================================*/
+
+int Mth_getStackMapEntryIP(METHOD vMethod, int stackMapIndex) {
+    METHOD thisMethod = (METHOD)vMethod;
+    POINTERLIST stackMaps = thisMethod->u.java.stackMaps.verifierMap;
+    if (stackMaps && stackMapIndex < stackMaps->length) {
+        return stackMaps->data[stackMapIndex + stackMaps->length].cell;
+    } else {
+        return 0x7FFFFFFF;
+    }
+}
+
+/*=========================================================================
+ * FUNCTION:      Mth_checkStackMapOffset
+ * TYPE:          private operation
+ * OVERVIEW:      Validates the stackmap offset to ensure that it does
+ *                not exceed code size. 
+ *
+ * INTERFACE:
+ *   parameters:  vMethod: the method, stackMapIndex: the index
+ *   returns:     true if ok, false otherwise. 
+ *=======================================================================*/
+
+bool_t Mth_checkStackMapOffset(METHOD vMethod, int stackMapIndex) {
+    METHOD thisMethod = (METHOD)vMethod;
+    POINTERLIST stackMaps = thisMethod->u.java.stackMaps.verifierMap;
+
+    if (stackMaps && stackMapIndex != stackMaps->length) {
+        return FALSE; 
+    } 
+    return TRUE;
+}
+
+/*=========================================================================
+ * FUNCTION:      Mth_getExceptionTableLength
+ * TYPE:          private operation
+ * OVERVIEW:      Get the number of entries in the exception table
+ *
+ * INTERFACE:
+ *   parameters:  vMethod: the method
+ *   returns:     The number of entries
+ *=======================================================================*/
+
+int Mth_getExceptionTableLength(METHOD vMethod) {
+    HANDLERTABLE handlers = vMethod->u.java.handlers;
+    if (handlers != 0) {
+        return handlers->length;
+    } else {
+        return 0;
+    }
+}
+
+/* ------------------------------------------------------------------------ *\
+ *                                 Printing                                 *
+\* ------------------------------------------------------------------------ */
+
+#if INCLUDEDEBUGCODE
+
+/*=========================================================================
+ * FUNCTION:      Vfy_setErrorIp
+ * TYPE:          private operation
+ * OVERVIEW:      Set the ip address for error printing
+ *
+ * INTERFACE:
+ *   parameters:  ip: the IP address
+ *   returns:     Nothing
+ *=======================================================================*/
+
+/*
+ * Set to ip for error messages
+ */
+void Vfy_setErrorIp(int ip) {
+    vErrorIp = ip;
+#if EXCESSIVE_GARBAGE_COLLECTION
+    garbageCollect(0);
+#endif
+}
+
+/*=========================================================================
+ * FUNCTION:      getByteCodeName()
+ * TYPE:          public debugging operation
+ * OVERVIEW:      Given a bytecode value, get the mnemonic name of
+ *                the bytecode.
+ * INTERFACE:
+ *   parameters:  bytecode as an integer
+ *   returns:     constant string containing the name of the bytecode
+ *=======================================================================*/
+
+#if INCLUDEDEBUGCODE
+static const char*
+getByteCodeName(ByteCode token) {
+    if (token >= 0 && token <= LASTBYTECODE)
+         return byteCodeNames[token];
+    else return "<INVALID>";
+}
+#else
+#  define getByteCodeName(token) ""
+#endif
+
+/*=========================================================================
+ * FUNCTION:      Vfy_printVerifyStartMessage
+ * TYPE:          private operation
+ * OVERVIEW:      Print trace info
+ *
+ * INTERFACE:
+ *   parameters:  vMethod: the method
+ *   returns:     Nothing
+ *=======================================================================*/
+
+static void Vfy_printVerifyStartMessage(METHOD vMethod) {
+    if (traceverifier) {
+        START_TEMPORARY_ROOTS
+            DECLARE_TEMPORARY_ROOT(char*, className,
+                                   getClassName(&(vMethod->ofClass->clazz)));
+            unsigned short nameKey = vMethod->nameTypeKey.nt.nameKey;
+            unsigned short typeKey = vMethod->nameTypeKey.nt.typeKey;
+            DECLARE_TEMPORARY_ROOT(char*, signature,
+                                   change_Key_to_MethodSignature(typeKey));
+            fprintf(stdout, "Verifying method %s.%s%s\n",
+                    className, change_Key_to_Name(nameKey, NULL), signature);
+        END_TEMPORARY_ROOTS
+    }
+}
+
+/*=========================================================================
+ * FUNCTION:      Vfy_printVerifyLoopMessage
+ * TYPE:          private operation
+ * OVERVIEW:      Print trace info
+ *
+ * INTERFACE:
+ *   parameters:  vMethod: the method,ip: the IP address
+ *   returns:     Nothing
+ *=======================================================================*/
+
+void Vfy_printVerifyLoopMessage(METHOD vMethod, IPINDEX ip) {
+    if (traceverifier) {
+        unsigned char *code = Mth_getBytecodes(vMethod);
+        ByteCode token = code[ip];
+        fprintf(stdout, "Display derived/recorded stackmap at %ld:\n", (long)ip);
+        printStackMap(vMethod, ip);
+        fprintf(stdout, "%ld %s\n", (long)ip, getByteCodeName(token));
+    }
+}
+
+/*=========================================================================
+ * FUNCTION:      Vfy_printVerifyEndMessage
+ * TYPE:          private operation
+ * OVERVIEW:      Print trace info
+ *
+ * INTERFACE:
+ *   parameters:  vMethod: the method
+ *   returns:     Nothing
+ *=======================================================================*/
+
+static void Vfy_printVerifyEndMessage(METHOD vMethod, int result) {
+    static const char* verifierStatusInfo[] =
+        KVM_MSG_VERIFIER_STATUS_INFO_INITIALIZER; /* See messages.h */
+    if (result != 0) {
+        const int  count = sizeof(verifierStatusInfo)/sizeof(verifierStatusInfo[0]);
+        const char *info = (result > 0 && result < count)
+                                 ? verifierStatusInfo[result]
+                                 : "Unknown problem";
+        fprintf(stderr, "Error verifying method ");
+        printMethodName(vMethod, stderr);
+        fprintf(stderr, "Approximate bytecode offset %ld: %s\n", (long)vErrorIp, info);
+    }
+}
+
+/*=========================================================================
+ * FUNCTION:      Vfy_trace1
+ * TYPE:          private operation
+ * OVERVIEW:      Print trace info
+ *
+ * INTERFACE:
+ *   parameters:  msg: a printf format string, p1: a parameter
+ *   returns:     Nothing
+ *=======================================================================*/
+
+void Vfy_trace1(char *msg, long p1) {
+    if (traceverifier) {
+        fprintf(stdout, msg, p1);
+    }
+}
+
+#endif /* INCLUDEDEBUGCODE */
+
+ /* ------------------------------------------------------------------------ *\
+  *                               Entry / Exit                               *
+ \* ------------------------------------------------------------------------ */
+
+ static jmp_buf vJumpBuffer;
+
+ /*
+  * Main verity routine
+  */
+
+/*=========================================================================
+ * FUNCTION:      Vfy_verifyMethod
+ * TYPE:          private operation
+ * OVERVIEW:      Verify a method
+ *
+ * INTERFACE:
+ *   parameters:  vMethod: the method
+ *   returns:     Nothing
+ *=======================================================================*/
+
+ static int Vfy_verifyMethod(METHOD vMethod) {
+
+    void Vfy_verifyMethodOrAbort(const METHOD vMethod);
+    static bool_t Vfy_checkNewInstructions(METHOD vMethod);
+    int res;
+
+#if INCLUDEDEBUGCODE
+    Vfy_printVerifyStartMessage(vMethod);
+#endif
+
+    START_TEMPORARY_ROOTS
+
+        vMaxStack = vMethod->u.java.maxStack;
+        vFrameSize = vMethod->frameSize;
+        IS_TEMPORARY_ROOT(vStack,  (VERIFIERTYPE*) callocObject(ByteSizeToCellSize(vMaxStack  * sizeof(VERIFIERTYPE)), GCT_NOPOINTERS));
+        IS_TEMPORARY_ROOT(vLocals, (VERIFIERTYPE*) callocObject(ByteSizeToCellSize(vFrameSize * sizeof(VERIFIERTYPE)), GCT_NOPOINTERS));
+
+       /*
+        * This bitmap keeps track of all the NEW instructions that we have
+        * already seen.
+        */
+        IS_TEMPORARY_ROOT(NEWInstructions, NULL);
+
+        vSP = 0;                   /* initial stack is empty. */
+
+       /*
+        * All errors from Vfy_verifyMethodOrAbort are longjmped here. If no error
+        * is thrown then res will be zero from the call to setjmp
+        */
+        res = setjmp(vJumpBuffer);
+        if (res == 0) {
+           /*
+            * Setup the verification context and call the core function.
+            */
+            methodBeingVerified    = vMethod;
+            bytecodesBeingVerified = Mth_getBytecodes(vMethod);
+
+            Vfy_verifyMethodOrAbort(vMethod);
+            if (!Vfy_checkNewInstructions(vMethod)) {
+                Vfy_throw(VE_BAD_NEW_OFFSET);
+            }
+        }
+
+    END_TEMPORARY_ROOTS
+
+#if INCLUDEDEBUGCODE
+    Vfy_printVerifyEndMessage(vMethod, res);
+#endif
+
+    return res;
+}
+
+/*=========================================================================
+ * FUNCTION:      Vfy_throw
+ * TYPE:          private operation
+ * OVERVIEW:      Throw a verification exception
+ *
+ * INTERFACE:
+ *   parameters:  code: the VE_xxxx code
+ *   returns:     Does a longjmp back to Vfy_verifyMethod
+ *=======================================================================*/
+
+void Vfy_throw(int code) {
+     longjmp(vJumpBuffer, code);
+ }
+
+/*=========================================================================
+ * FUNCTION:      Vfy_checkNewInstructions
+ * TYPE:          private operation
+ * OVERVIEW:      ITEM_new were all used
+ *
+ * INTERFACE:
+ *   parameters:  thisMethod: the method
+ *   returns:     FALSE if there is an error
+ *=======================================================================*/
+
+static bool_t Vfy_checkNewInstructions(METHOD thisMethod) {
+
+   /* We need to double check that all of the ITEM_new's that
+    * we stack in the stack map were legitimate.
+    */
+    const int codeLength = thisMethod->u.java.codeLength;
+    int i, j;
+    POINTERLIST stackMaps = thisMethod->u.java.stackMaps.verifierMap;
+    if (stackMaps != NULL) {
+        for (i = stackMaps->length; --i >= 0;) {
+            unsigned short *stackMap =
+                (unsigned short*)stackMaps->data[i].cellp;
+            for (j = 0; j < 2; j++) {
+                /* Do this loop twice: locals and stack */
+                unsigned short count = *stackMap++;
+                while (count-- > 0) {
+                    unsigned short typeKey = *stackMap++;
+                    if (typeKey & ITEM_NewObject_Flag) {
+                        int index = DECODE_NEWOBJECT(typeKey);
+                        if (index >= codeLength
+                               || NEWInstructions == NULL
+                               || !IS_NTH_BIT(NEWInstructions, index)) {
+                            return FALSE;
+                        }
+                    }
+                }
+            }
+        }
+    }
+    return TRUE;
+}
+
diff -ruN ./temp/j2me_cldc/kvm/VmExtra/src/main.c ./final_my_j2me/kvm/VmExtra/src/main.c
--- ./temp/j2me_cldc/kvm/VmExtra/src/main.c	2003-02-06 13:56:00.000000000 +1300
+++ ./final_my_j2me/kvm/VmExtra/src/main.c	2007-04-15 13:57:09.000000000 +1200
@@ -68,6 +68,11 @@
 #define BUILD_VERSION "generic"
 #endif
 
+/*
+I am changing this so that we can start the JVM without any arguments from the command-promp at all
+Author: Avinash Malik.
+*/
+/*
 int main (int argc, char* argv[]) {
     int result;
 
@@ -104,7 +109,7 @@
         } else if ((strcmp(argv[1], "-port") == 0) && (argc > 2)) {
             debuggerPort = (short)atoi(argv[2]);
             argv+=2; argc -=2;
-#endif /* ENABLE_JAVA_DEBUGGER */
+#endif 
 
         } else if ((strcmp(argv[1], "-heapsize") == 0) && (argc > 2)) {
             char *endArg;
@@ -116,14 +121,7 @@
                 default:              printHelpText(); exit(1);
             }
 
-            /* In principle, KVM can run with just a few kilobytes */
-            /* of heap space.  We use 16 kilobytes as the minimum  */
-            /* as that value is useful for some test cases.        */
-            /* The maximum heap size allowed by the KVM garbage    */
-            /* collector is 64 megabytes.  In practice, the        */
-            /* collector is optimized only for small heaps, and    */
-            /* is likely to have noticeable GC pauses with heaps   */
-            /* larger than a few megabytes */
+           
             if (heapSize < 16 * 1024) { 
                 fprintf(stderr, KVM_MSG_USES_16K_MINIMUM_MEMORY "\n");
                 heapSize = 16 * 1024;
@@ -133,7 +131,7 @@
                 heapSize = 64 * 1024 * 1024;
             }
 
-            /* Make sure the heap size is divisible by four */
+            
             heapSize -= heapSize%CELL;
            
             argv+=2; argc -=2;
@@ -160,7 +158,7 @@
             FOR_EACH_TRACE_FLAG(TURN_ON_OPTION)
             argv++; argc--;
 
-#endif /* INCLUDEDEBUGCODE */
+#endif 
 
 #if USE_JAM
         } else if (strcmp(argv[1], "-jam") == 0) {
@@ -174,30 +172,30 @@
                     KVM_MSG_CANT_COMBINE_DEBUGGER_OPTION_WITH_REPEAT_OPTION);
                 exit(1);
             }
-#endif /* ENABLE_JAVA_DEBUGGER */
+#endif
             JamRepeat = TRUE;
             argv++; argc--;
         } else if (JamEnabled && (strcmp(argv[1], "-appsdir") == 0)
                   && argc > 2) {
             jamInstalledAppsDir = argv[2];
             argv+=2; argc-=2;
-#endif /* USE_JAM */
+#endif 
 
         } else {
             break;
         }
     }
 
-    /* Skip program name */
+    
     argc--;
     argv++;
 
     if (UserClassPath == NULL && !JamEnabled) { 
         UserClassPath = getenv("classpath");
         if (UserClassPath == NULL) { 
-            /* Just in case environment variable reading is case sensitive */
+            
             UserClassPath = getenv("CLASSPATH");
-            /* Use "." as the default classpath */
+            
             if (UserClassPath == NULL) { 
                 UserClassPath = ".";
             }
@@ -220,23 +218,22 @@
         } while(JamRepeat);
         JamFinalize();
     } else
-#endif /* USE_JAM */
+#endif 
 
     {
  
-        /* Call the portable KVM startup routine */
+       
         result = StartJVM(argc, argv);
 
 #if ENABLEPROFILING
-        /* By default, the VM prints out profiling information */
-        /* upon exiting if profiling is turned on. */
+        
         printProfileInfo();
-#endif /* ENABLEPROFILING */
+#endif 
 
-        /* If no classfile was provided, print help text */
+        
         if (result == -1) printHelpText();
     }
 
     return result;
-}
+}*/
 
diff -ruN ./temp/j2me_cldc/kvm/VmUnix/build/Makefile ./final_my_j2me/kvm/VmUnix/build/Makefile
--- ./temp/j2me_cldc/kvm/VmUnix/build/Makefile	2007-05-16 09:36:45.000000000 +1200
+++ ./final_my_j2me/kvm/VmUnix/build/Makefile	2007-05-15 16:26:58.000000000 +1200
@@ -37,7 +37,8 @@
             verifier.c log.c jar.c inflate.c  stackmap.c profiling.c  \
      	      pool.c runtime_md.c StartJVM.c                            \
             nativeFunctionTableUnix.c events.c resource.c             \
-            verifierUtil.c
+            verifierUtil.c j2me.c
+
 
 ifeq ($(DEBUG), true)
    SRCFILES += debugger.c debuggerSocketIO.c debuggerOutputStream.c debuggerInputStream.c
@@ -85,14 +86,16 @@
 endif
 
 ifeq ($(PLATFORM), linux)
-LIBS =    -lm -lnsl
+LIBS =    -lm #-lj2me_syslib #-lnsl
 CPPFLAGS = -DUNIX -DLINUX -D$(ARCH) \
 	   -I$(TOP)/kvm/VmCommon/h -I$(TOP)/kvm/VmUnix/h \
-	   -I$(TOP)/kvm/VmExtra/h -I$(TOP)/jam/h
+	   -I$(TOP)/kvm/VmExtra/h -I$(TOP)/jam/h	   
+	   #-I /opt/altera/nios2_6.1/components/altera_nios2/HAL/inc #this is the bare-bone
+	   #-DSYSTEM_BUS_WIDTH=32 #this is for bare-bone
 endif
 
 ifeq ($(GCC), true)
-   CC = nios2-linux-uclibc-gcc
+   CC = nios2-elf-gcc #nios2-linux-uclibc-gcc #arm is the other one but it does compile even with arm
    CFLAGS =  -Wall $(CPPFLAGS) $(ROMFLAGS) $(OTHER_FLAGS)
    DEBUG_FLAG = -g 
    OPTIMIZE_FLAG = -O2
@@ -115,7 +118,7 @@
 
 kvm$(j)$(g): obj$j$g/ fp_obj$j$g/ $(CLEANUPXPM) $(OBJFILES) $(FP_OBJFILES)
 	@echo "Linking ... $@"
-	@$(CC) $(OBJFILES) $(FP_OBJFILES) -o $@ $(LIBS) -elf2flt="-s 100000"
+	@$(CC) -T'/home/amal029/download/d2/j2me_syslib/Debug/system_description/generated.x' -msys-crt0='/home/amal029/download/d2/j2me_syslib/Debug/crt0.o' -msys-lib=j2me_syslib -L '/home/amal029/download/d2/j2me_syslib/Debug' -DALT_DEBUG -O0 -g -Wall -mhw-mul -mno-hw-mulx -mno-hw-div $(OBJFILES) $(FP_OBJFILES) -o $@ $(LIBS) #-L. #-elf2flt="-s 100000" #changed the name of the file to be made
 
 clean: 
 	rm -rf core kvm* .noincludexpm* obj* ./SunWS_cache fp_obj*
diff -ruN ./temp/j2me_cldc/kvm/VmUnix/h/machine_md.h ./final_my_j2me/kvm/VmUnix/h/machine_md.h
--- ./temp/j2me_cldc/kvm/VmUnix/h/machine_md.h	2003-02-06 13:56:00.000000000 +1300
+++ ./final_my_j2me/kvm/VmUnix/h/machine_md.h	2007-03-06 11:38:00.000000000 +1300
@@ -33,7 +33,7 @@
 
 #ifdef LINUX
 #include <sys/time.h>
-#include <fpu_control.h>
+//#include <fpu_control.h>
 #endif
 
 /*=========================================================================
diff -ruN ./temp/j2me_cldc/kvm/VmUnix/h/machine_md.h~ ./final_my_j2me/kvm/VmUnix/h/machine_md.h~
--- ./temp/j2me_cldc/kvm/VmUnix/h/machine_md.h~	1970-01-01 12:00:00.000000000 +1200
+++ ./final_my_j2me/kvm/VmUnix/h/machine_md.h~	2003-02-06 13:56:00.000000000 +1300
@@ -0,0 +1,141 @@
+/*
+ * Copyright © 2003 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ *
+ */
+
+/*=========================================================================
+ * KVM
+ *=========================================================================
+ * SYSTEM:    KVM
+ * FILE:      machine_md.h (for UNIX/Solaris/Linux)
+ * OVERVIEW:  This file is included in every compilation.  It contains
+ *            definitions that are specific to the Solaris/Linux ports 
+ *            of KVM.
+ * AUTHOR:    Frank Yellin
+ *            Andreas Heilwagen, Kinsley Wong (Linux port)
+ * NOTE:      This file overrides many of the default compilation 
+ *            flags and macros defined in VmCommon/h/main.h.
+ *=======================================================================*/
+
+/*=========================================================================
+ * Include files
+ *=======================================================================*/
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <ctype.h>
+#include <time.h>
+#include <math.h>
+#include <setjmp.h>
+
+#ifdef LINUX
+#include <sys/time.h>
+#include <fpu_control.h>
+#endif
+
+/*=========================================================================
+ * Platform-specific datatype definitions
+ *=======================================================================*/
+
+typedef long long           long64;    /* 64-bit signed integer type */
+typedef unsigned long long  ulong64;   /* 64-bit unsigned integer type */
+typedef long long           jlong;     /* Added for KNI */
+
+#ifndef Calendar_md
+unsigned long * Calendar_md(void);
+#endif
+
+/*=========================================================================
+ * Compilation flags and macros that override values defined in main.h
+ *=======================================================================*/
+
+/* By default we are assume that if we are not using a i386 machine the 
+ * target platform is big-endian.
+ * Solaris requires 8-byte alignment of longs and doubles */
+
+#if !defined(i386) && !defined(__arm__)
+#define BIG_ENDIAN 1
+#define NEED_LONG_ALIGNMENT 1
+#define NEED_DOUBLE_ALIGNMENT 1
+#else
+#undef BIG_ENDIAN
+#undef LITTLE_ENDIAN
+#undef NEED_LONG_ALIGNMENT 
+#define LITTLE_ENDIAN 1
+#define NEED_LONG_ALIGNMENT 0 
+#endif
+
+#if defined(i386)
+/* This definition is used for compiling in */
+/* the x86-specific strictfp operations */
+#define PROCESSOR_ARCHITECTURE_X86 1
+#endif
+
+/* Make the VM run a little faster (can afford the extra space) */
+#define ENABLEFASTBYTECODES 1
+
+/* Override the sleep function defined in main.h */
+#define SLEEP_FOR(delta)                                     \
+    {                                                        \
+           struct timeval timeout;                           \
+           timeout.tv_sec = delta / 1000;                    \
+           timeout.tv_usec = (delta % 1000) * 1000;          \
+           select(0, NULL, NULL, NULL, &timeout);            \
+        }
+
+/*=========================================================================
+ * Platform-specific function prototypes
+ *=======================================================================*/
+
+#define InitializeVM()
+#define FinalizeVM()
+
+#define freeHeap(heap) free(heap)
+#define RandomNumber_md() rand()
+
+void InitializeWindowSystem();
+void FinalizeWindowSystem(void);
+
+/*=========================================================================
+ * The following are used in several different places, and its worthwhile
+ * to define them just once
+ *=======================================================================*/
+
+void* allocateVirtualMemory_md(long size);
+void  freeVirtualMemory_md(void *address, long size);
+
+enum { PVM_NoAccess, PVM_ReadOnly, PVM_ReadWrite };
+void  protectVirtualMemory_md(void *address, long size, int protection);
+
+/*=========================================================================
+ * FUNCTION:      The stub of GetAndStoreNextKVMEvent
+ * TYPE:          event handler
+ * OVERVIEW:      Wait for an external event to occur, and store
+ *                the event to the KVM event queue.
+ *                On a real device, the implementation of this
+ *                function should try to conserve battery if 
+ *                the routine is called with the 'forever'
+ *                flag turned on, or with a 'waitUntil' parameter
+ *                larger than zero.
+ * INTERFACE
+ *   parameters:  forever: a boolean flag that tells whether the
+ *                KVM has anything to do or not.  When the KVM calls
+ *                this routine with the forever flag turned on, the
+ *                VM has no threads to run and this function can call
+ *                machine-specific battery conservation/hibernation
+ *                facilities.  If the forever flag is off, the function
+ *                should try to return immediately, or at least after
+ *                'waitUntil' milliseconds, since there are other threads
+ *                that need to continue running.
+ *                waitUntil: the amount of milliseconds this routine
+ *                should wait in case the 'forever' flag is off.
+ *   returns:     nothing directly, but the event should be stored
+ *                in the event queue of the KVM (see events.c and
+ *                the porting guide for details).
+ *=======================================================================*/
+
+#define GetAndStoreNextKVMEvent(x,y)
+#define _NOT_IMPLEMENTED_GetAndStoreNextKVMEvent
diff -ruN ./temp/j2me_cldc/kvm/VmUnix/src/j2me.c ./final_my_j2me/kvm/VmUnix/src/j2me.c
--- ./temp/j2me_cldc/kvm/VmUnix/src/j2me.c	1970-01-01 12:00:00.000000000 +1200
+++ ./final_my_j2me/kvm/VmUnix/src/j2me.c	2007-05-15 18:14:27.000000000 +1200
@@ -0,0 +1,19 @@
+#include <main.h>
+#include <stdio.h>
+#include <global.h>
+
+#if USE_JAM
+#include <jam.h>
+#endif
+
+int main (void){
+    JamEnabled = FALSE;
+    JamRepeat = FALSE;
+    RequestedHeapSize = DEFAULTHEAPSIZE;    
+    char* className = "Asproto.Asproto";
+    char *argv[] = {className};
+    if(StartJVM(1,argv) == 1){
+        return 1;
+    }    
+    return 0;
+}
diff -ruN ./temp/j2me_cldc/kvm/VmUnix/src/runtime_md.c ./final_my_j2me/kvm/VmUnix/src/runtime_md.c
--- ./temp/j2me_cldc/kvm/VmUnix/src/runtime_md.c	2006-11-06 15:17:37.000000000 +1300
+++ ./final_my_j2me/kvm/VmUnix/src/runtime_md.c	2007-03-06 11:40:03.000000000 +1300
@@ -25,7 +25,7 @@
 #include <stdlib.h>
 #include <signal.h>
 #include <fcntl.h>
-#include <sys/mman.h>
+//#include <sys/mman.h>
 
 /*=========================================================================
  * Definitions and variables
@@ -90,6 +90,8 @@
 /* Virtual memory allocation and protection operations. */
 /* Used for testing the correctness of the garbage collector */
 
+/*
+
 void *
 allocateVirtualMemory_md(long size) {
     int devZero = open("/dev/zero", O_RDONLY);
@@ -115,6 +117,7 @@
     }
     mprotect(address, size, flag);
 }
+*/
 
 /*=========================================================================
  * FUNCTION:      signal_handler (showStack)
@@ -168,8 +171,8 @@
 void InitializeFloatingPoint() {
 #if defined(LINUX) && PROCESSOR_ARCHITECTURE_X86
     /* Set the precision FPU to double precision */
-//    fpu_control_t cw = (_FPU_DEFAULT & ~_FPU_EXTENDED) | _FPU_DOUBLE;
-//    _FPU_SETCW(cw);
+    //fpu_control_t cw = (_FPU_DEFAULT & ~_FPU_EXTENDED) | _FPU_DOUBLE;
+    //_FPU_SETCW(cw);
 #endif
 }
 
