\section{Pros and Cons of Java}
\label{sec:experiences}

A working prototype of the system (without graphics support) was written
in a weekend, with the time divided roughly equally between the
translation script and the vector methods.  Java's standard collection
of predefined classes proved very helpful in this rapid-prototyping
phase, as did its built-in garbage collection.  Object-oriented features
were not heavily used---in essence, we treated Java as a secure,
portable dialect of C with garbage collection, polymorphism, and a good
collection of pre-existing libraries.

However, two aspects of Java proved troublesome during development.
First, Java lacks templates, parametric polymorphism, a built-in
preprocessor, or any other way to generate type-specialized versions of
the same basic method.  Thus, each \vcode\ vector operation has to be
implemented as a separate method, although many of them perform
essentially the same loop, changing only the operator or type. We used
the \texttt{m4} preprocessor to generate multiple specialized methods
from a single macro body.  An alternative would be to add parametric
polymorphism to Java using a system such as Pizza~\cite{pizza-java97}.

Second, Java compilers and virtual machines are still in their infancy.
The Sun JDK compiler does not perform standard optimizations such as
common subexpression elimination or loop-invariant code motion (for
example, the reference to \texttt{a.length} in the loop in Figure 3 will
be evaluated on each loop iteration).  Currently, these optimizations
must be performed by the programmer.  Additionally, there is a lack of
performance data available for use in making informed design and
optimization decisions.  We performed a series of micro-benchmarks to
establish the comparative cost of various Java
operations~\cite{jch-javapage}.  These benchmarks show that creating
objects is a dominant cost for small problem sizes and becomes
relatively more expensive in just-in-time compilers.  We were therefore
careful in our design to avoid creating unnecessary objects (for
example, we never create objects in an inner loop).

