+The remaining constant pool types can be completely resolved in the
+first pass and need no further processing. These types, including the
+actions taken in the first pass, are as follows:
+
+\begin{itemize}
+
+ \item \texttt{CONSTANT\_Integer}
+
+ \begin{itemize}
+
+ \item create a new \texttt{constant\_integer} structure (see
+ figure~\ref{constantintegerstructure})
+
+ \item read a 4 byte \texttt{signed integer} value via
+ \texttt{suck\_s4} from the binary representation
+
+ \item store the value into the \texttt{value} field of the
+ \texttt{constant\_integer} structure
+
+ \item store the type \texttt{CONSTANT\_Integer} into \texttt{cptags}
+ and the pointer to the \texttt{constant\_integer} structure into
+ \texttt{cpinfos} at the appropriate index
+
+ \item increase the constant pool index by one
+
+ \end{itemize}
+
+\begin{figure}[h]
+\begin{verbatim}
+ typedef struct { /* Integer */
+ s4 value;
+ } constant_integer;
+\end{verbatim}
+\caption{\texttt{constant\_integer} structure}
+\label{constantintegerstructure}
+\end{figure}
+
+ \item \texttt{CONSTANT\_Float}
+
+ \begin{itemize}
+
+ \item create a new \texttt{constant\_float} structure (see
+ figure~\ref{constantfloatstructure})
+
+ \item read a 4 byte \texttt{float} value via \texttt{suck\_float}
+ from the binary representation
+
+ \item store the value into the \texttt{value} field of the
+ \texttt{constant\_float} structure
+
+ \item store the type \texttt{CONSTANT\_Float} into \texttt{cptags}
+ and the pointer to the \texttt{constant\_float} structure into
+ \texttt{cpinfos} at the appropriate index
+
+ \item increase the constant pool index by one
+
+ \end{itemize}
+
+\begin{figure}[h]
+\begin{verbatim}
+ typedef struct { /* Float */
+ float value;
+ } constant_float;
+\end{verbatim}
+\caption{\texttt{constant\_float} structure}
+\label{constantfloatstructure}
+\end{figure}
+
+ \item \texttt{CONSTANT\_Long}
+
+ \begin{itemize}
+
+ \item create a new \texttt{constant\_long} structure (see
+ figure~\ref{constantlongstructure})
+
+ \item read a 8 byte \texttt{signed long} value via \texttt{suck\_s8}
+ from the binary representation
+
+ \item store the value into the \texttt{value} field of the
+ \texttt{constant\_long} structure
+
+ \item store the type \texttt{CONSTANT\_Long} into \texttt{cptags}
+ and the pointer to the \texttt{constant\_long} structure into
+ \texttt{cpinfos} at the appropriate index
+
+ \item increase the constant pool index by two
+
+ \end{itemize}
+
+\begin{figure}[h]
+\begin{verbatim}
+ typedef struct { /* Long */
+ s8 value;
+ } constant_long;
+\end{verbatim}
+\caption{\texttt{constant\_long} structure}
+\label{constantlongstructure}
+\end{figure}
+
+ \item \texttt{CONSTANT\_Double}
+
+ \begin{itemize}
+
+ \item create a new \texttt{constant\_double} structure (see
+ figure~\ref{constantdoublestructure})
+
+ \item read a 8 byte \texttt{double} value via \texttt{suck\_double}
+ from the binary representation
+
+ \item store the value into the \texttt{value} field of the
+ \texttt{constant\_double} structure
+
+ \item store the type \texttt{CONSTANT\_Double} into \texttt{cptags}
+ and the pointer to the \texttt{constant\_double} structure into
+ \texttt{cpinfos} at the appropriate index
+
+ \item increase the constant pool index by two
+
+ \end{itemize}
+
+\begin{figure}[h]
+\begin{verbatim}
+ typedef struct { /* Double */
+ double value;
+ } constant_double;
+\end{verbatim}
+\caption{\texttt{constant\_double} structure}
+\label{constantdoublestructure}
+\end{figure}
+
+ \item \texttt{CONSTANT\_Utf8}
+
+ \begin{itemize}
+
+ \item read the length of the UTF8 string via \texttt{suck\_u2}
+
+ \item store the type \texttt{CONSTANT\_Utf8} into \texttt{cptags} at
+ the appropriate index
+
+ \item create a new UTF8 string in the runtime environment of the
+ Java Virtual Machine via \texttt{utf\_new\_intern}
+
+ \item store the pointer of the newly created UTF8 string into
+ \texttt{cpinfos} at the appropriate index
+
+ \item skip \texttt{length} bytes in the binary representation of the
+ class or interface via \texttt{skip\_nbytes}
+
+ \item increase the constant pool index by one
+
+ \end{itemize}
+
+\end{itemize}
+
+In the second pass, the references are resolved and the runtime
+structures are created. In further detail this includes for
+
+\begin{itemize}
+
+ \item \texttt{CONSTANT\_Class}
+
+ \begin{itemize}
+
+ \item resolve the UTF8 name string from the class' constant pool
+
+ \item store the type \texttt{CONSTANT\_Class} in \texttt{cptags} at
+ the appropriate index
+
+ \item create a class in the class hashtable with the UTF8 name
+
+ \item store the pointer to the new class in \texttt{cpinfos} at the
+ appropriate index
+
+ \end{itemize}
+
+ \item \texttt{CONSTANT\_String}
+
+ \begin{itemize}
+
+ \item resolve the UTF8 string of the referenced string from the
+ class' constant pool
+
+ \item store type \texttt{CONSTANT\_String} in \texttt{cptags} and
+ store the UTF8 string pointer into \texttt{cpinfos} at the
+ appropriate index
+
+ \end{itemize}
+
+ \item \texttt{CONSTANT\_NameAndType}
+
+ \begin{itemize}
+
+ \item create a new \texttt{constant\_nameandtype} structure (see
+ figure~\ref{constantnameandtype})
+
+ \item resolve the UTF8 name and description string of the field or
+ method and store them into the \texttt{constant\_nameandtype}
+ structure
+
+ \item store type \texttt{CONSTANT\_NameAndType} into
+ \texttt{cptags} and store a pointer to the
+ \texttt{constant\_nameandtype} structure into \texttt{cpinfos}
+
+ \end{itemize}
+
+\begin{figure}[h]
+\begin{verbatim}
+ typedef struct { /* NameAndType (Field or Method) */
+ utf *name; /* field/method name */
+ utf *descriptor; /* field/method type descriptor string */
+ } constant_nameandtype;
+\end{verbatim}
+\caption{\texttt{constant\_nameandtype} structure}
+\label{constantnameandtype}
+\end{figure}
+
+ \item \texttt{CONSTANT\_Fieldref} \\
+ \texttt{CONSTANT\_Methodref} \\
+ \texttt{CONSTANT\_InterfaceMethodref}
+
+ \begin{itemize}
+
+ \item create a new \texttt{constant\_FMIref} structure (see
+ figure~\ref{constantFMIref})
+
+ \item resolve the referenced \texttt{constant\_nameandtype}
+ structure which contains the name and descriptor resolved in a
+ previous step and store the name and descriptor into the
+ \texttt{constant\_FMIref} structure
+
+ \item resolve the pointer of the referenced class which was created
+ in a previous step and store the pointer of the class into the
+ \texttt{constant\_FMIref} structure
+
+ \item store the type of the current constant pool entry in
+ \texttt{cptags} and store the pointer to \texttt{constant\_FMIref}
+ in \texttt{cpinfos} at the appropriate index
+
+ \end{itemize}
+
+\begin{figure}[h]
+\begin{verbatim}
+ typedef struct { /* Fieldref, Methodref and InterfaceMethodref */
+ classinfo *class; /* class containing this field/method/interface */
+ utf *name; /* field/method/interface name */
+ utf *descriptor; /* field/method/interface type descriptor string */
+ } constant_FMIref;
+\end{verbatim}
+\caption{\texttt{constant\_FMIref} structure}
+\label{constantFMIref}
+\end{figure}
+
+\end{itemize}
+
+Any UTF8 strings, \texttt{constant\_nameandtype} structures or
+referenced classes are resolved with the
+
+\begin{verbatim}
+ voidptr class_getconstant(classinfo *c, u4 pos, u4 ctype);
+\end{verbatim}
+
+function. This functions checks for type equality and then returns the
+requested \texttt{cpinfos} slot of the specified class.
+
+
+\subsection{Interface loading}
+
+Interface loading is very simple and straightforward. After reading
+the number of interfaces, for every interface referenced, a
+\texttt{u2} constant pool index is read from the currently loading
+class or interface. This index is used to resolve the interface class
+via the \texttt{class\_getconstant} function from the class' constant
+pool. This means, interface \textit{loading} is more interface
+\textit{resolving} than loading. The resolved interfaces are stored
+in an \texttt{classinfo *} array allocated by the class loader. The
+memory pointer of the array is assigned to the \texttt{interfaces}
+field of the \texttt{clasinfo} structure.
+
+
+\subsection{Field loading}
+
+The number of fields of the class or interface is read as \texttt{u2}
+value. For each field the function
+
+\begin{verbatim}
+ static bool field_load(classbuffer *cb, classinfo *c, fieldinfo *f);
+\end{verbatim}
+
+is called. The \texttt{fieldinfo *} argument is a pointer to a
+\texttt{fieldinfo} structure (see figure~\ref{fieldinfostructure})
+allocated by the class loader. The fields' \texttt{name} and
+\texttt{descriptor} are resolved from the class constant pool via
+\texttt{class\_getconstant}. If the verifier option is turned on, the
+fields' \texttt{flags}, \texttt{name} and \texttt{descriptor} are
+checked for validity and can result in a
+\texttt{java.lang.ClassFormatError}.
+
+\begin{figure}[h]
+\begin{verbatim}
+ struct fieldinfo { /* field of a class */
+ s4 flags; /* ACC flags */
+ s4 type; /* basic data type */
+ utf *name; /* name of field */
+ utf *descriptor; /* JavaVM descriptor string of field */
+
+ s4 offset; /* offset from start of object (instance variables) */
+
+ imm_union value; /* storage for static values (class variables) */
+
+ classinfo *class; /* needed by typechecker. Could be optimized */
+ /* away by using constant_FMIref instead of */
+ /* fieldinfo throughout the compiler. */
+ ...
+ };
+\end{verbatim}
+\caption{\texttt{fieldinfo} structure}
+\label{fieldinfostructure}
+\end{figure}
+
+Each field can have some attributes. The number of attributes is read
+as \texttt{u2} value from the binary representation. If the field has
+the \texttt{ACC\_FINAL} bit set in the flags, the
+\texttt{ConstantValue} attribute is available. This is the only
+attribute processed by \texttt{field\_load} and can occur only once,
+otherwise a \texttt{java.lang.ClassFormatError} is thrown. The
+\texttt{ConstantValue} entry in the constant pool contains the value
+for the \texttt{final} field. Depending on the fields' type, the
+proper constant pool entry is resolved and assigned.
+
+
+\subsection{Method loading}
+\label{sectionmethodloading}
+
+As for the fields, the number of the class or interface methods is read from
+the binary representation as \texttt{u2} value. For each method the function
+
+\begin{verbatim}
+ static bool method_load(classbuffer *cb, classinfo *c, methodinfo *m);
+\end{verbatim}
+
+is called. The beginning of the method loading code is nearly the same
+as the field loading code. The \texttt{methodinfo *} argument is a
+pointer to a \texttt{methodinfo} structure allocated by the class
+loader. The method's \texttt{name} and \texttt{descriptor} are
+resolved from the class constant pool via
+\texttt{class\_getconstant}. With the verifier turned on, some method
+checks are carried out. These include \texttt{flags}, \texttt{name}
+and \texttt{descriptor} checks and argument count check.
+
+\begin{figure}[h]
+\begin{verbatim}
+ struct methodinfo { /* method structure */
+ java_objectheader header; /* we need this in jit's monitorenter */
+ s4 flags; /* ACC flags */
+ utf *name; /* name of method */
+ utf *descriptor; /* JavaVM descriptor string of method */
+ ...
+ bool isleafmethod; /* does method call subroutines */
+
+ classinfo *class; /* class, the method belongs to */
+ s4 vftblindex; /* index of method in virtual function */
+ /* table (if it is a virtual method) */
+ s4 maxstack; /* maximum stack depth of method */
+ s4 maxlocals; /* maximum number of local variables */
+ s4 jcodelength; /* length of JavaVM code */
+ u1 *jcode; /* pointer to JavaVM code */
+ ...
+ s4 exceptiontablelength;/* exceptiontable length */
+ exceptiontable *exceptiontable; /* the exceptiontable */
+
+ u2 thrownexceptionscount;/* number of exceptions attribute */
+ classinfo **thrownexceptions; /* checked exceptions a method may throw */
+
+ u2 linenumbercount; /* number of linenumber attributes */
+ lineinfo *linenumbers; /* array of lineinfo items */
+ ...
+ u1 *stubroutine; /* stub for compiling or calling natives */
+ ...
+ };
+\end{verbatim}
+\caption{\texttt{methodinfo} structure}
+\label{methodinfostructure}
+\end{figure}
+
+The method loading function has to distinguish between a
+\texttt{native} and a ''normal'' JAVA method. Depending on the
+\texttt{ACC\_NATIVE} flags, a different stub is created.
+
+For a JAVA method, a \textit{compiler stub} is created. The purpose of
+this stub is to call the CACAO jit compiler with a pointer to the byte
+code of the JAVA method as argument to compile the method into machine
+code. During code generation a pointer to this compiler stub routine
+is used as a temporary method call, if the method is not compiled
+yet. After the target method is compiled, the new entry point of the
+method is patched into the generated code and the compiler stub is
+needless, thus it is freed.
+
+If the method is a \texttt{native} method, the loader tries to find
+the native function. If the function was found, a \textit{native stub}
+is generated. This stub is responsible to manipulate the method's
+arguments to be suitable for the \texttt{native} method called. This
+includes inserting the \textit{JNI environment} pointer as first
+argument and, if the \texttt{native} method has the
+\texttt{ACC\_STATIC} flag set, inserting a pointer to the methods
+class as second argument. If the \texttt{native} method is
+\texttt{static}, the native stub also checks if the method's class is
+already initialized. If the method's class is not initialized as the
+native stub is generated, a \texttt{asm\_check\_clinit} calling code
+is emitted.
+
+Each method can have some attributes. The method loading function
+processes two of them: \texttt{Code} and \texttt{Exceptions}.
+
+The \texttt{Code} attribute is a \textit{variable-length} attribute
+which contains the Java Virtual Machine instructions---the byte
+code---of the JAVA method. If the method is either \texttt{native} or
+\texttt{abstract}, it must not have a \texttt{Code} attribute,
+otherwise it must have exactly one \texttt{Code}
+attribute. Additionally to the byte code, the \texttt{Code} attribute
+contains the exception table and attributes to \texttt{Code} attribute
+itself. One exception table entry contains the \texttt{start\_pc},
+\texttt{end\_pc} and
+\texttt{handler\_pc} of the \texttt{try-catch} block, each read as
+\texttt{u2} value, plus a reference to the class of the
+\texttt{catch\_type}. Currently there are two attributes of the
+\texttt{Code} attribute defined in the JVM specification:
+\texttt{LineNumberTable} and \texttt{LocalVariableTable}. CACAO only
+processes the \texttt{LineNumberTable} attribute. A
+\texttt{LineNumberTable} entry consist of the \texttt{start\_pc} and
+the \texttt{line\_number}, which are stored in a \texttt{lineinfo}
+structure (see figure~\ref{lineinfostructure}).
+
+\begin{figure}[h]
+\begin{verbatim}
+ struct lineinfo {
+ u2 start_pc;
+ u2 line_number;
+ };
+\end{verbatim}
+\caption{\texttt{lineinfo} structure}
+\label{lineinfostructure}
+\end{figure}
+
+The linenumber count and the memory pointer of the \texttt{lineinfo}
+structure array are assigned to the \texttt{classinfo} fields
+\texttt{linenumbercount} and \texttt{linenumbers} respectively.
+
+The \texttt{Exceptions} attribute is a \textit{variable-length}
+attribute and contains the checked exceptions the JAVA method may
+throw. The \texttt{Exceptions} attribute consist of the count of
+exceptions, which is stored in the \texttt{classinfo} field
+\texttt{thrownexceptionscount}, and the adequate amount of \texttt{u2}
+constant pool index values. The exception classes are resolved from
+the constant pool and stored in an allocated \texttt{classinfo *}
+array, whose memory pointer is assigned to the
+\texttt{thrownexceptions} field of the \texttt{classinfo} structure.
+
+Any attributes which are not processed by the CACAO class loading
+system, are skipped via
+
+\begin{verbatim}
+ static bool skipattributebody(classbuffer *cb);
+\end{verbatim}
+
+which skips one attribute or
+
+\begin{verbatim}
+ static bool skipattributes(classbuffer *cb, u4 num);
+\end{verbatim}