It’s 1997, and you can't walk through a dev shop without hearing someone mention "Applets" or "The Sandbox." But as a systems guy, I’m less interested in the spinning Duke animation on a webpage and more interested in what's happening under the hood. I've been digging into the Java Virtual Machine (JVM) specification, and it is a fascinating piece of engineering.
The JVM is a stack-based machine. Unlike your physical x86 or SPARC CPU which uses registers for most operations, the JVM performs its work on an operand stack. When you add two numbers in Java, the bytecode looks something like iload_1, iload_2, iadd. This makes the bytecode extremely compact-most instructions are just a single byte-and it makes the task of writing an interpreter for a new hardware platform relatively straightforward.
This is the secret to "Write Once, Run Anywhere" (WORA). Sun Microsystems didn't just give us a language; they gave us a standardized execution environment. The .class file you compile on your Windows 95 machine is bit-for-bit identical to the one running on a Solaris server or a PowerPC Mac.
However, the "interpreter" part is where the critics have a point. Java is slow. Running a virtual stack machine in software is inherently more expensive than executing native machine code. But the "Just-In-Time" (JIT) compilers starting to appear in JDK 1.1 are a game-changer. By identifying "hot" methods and compiling them to native code on the fly, we're seeing performance that starts to rival C++ for long-running processes.
Looking forward, the JVM is going to be about much more than just the Java language. Its design is robust enough that I could see other languages-maybe even Smalltalk or a Lisp-being targeted at bytecode. The garbage collection, the security manager, and the class loading mechanism provide a solid foundation for enterprise software. We're moving away from the era of manual memory management, and the JVM is leading the charge.
// How the JVM sees a simple addition
// public int add(int a, int b) { return a + b; }
0: iload_1 // Push local variable 1 onto stack
1: iload_2 // Push local variable 2 onto stack
2: iadd // Pop two, add them, push result
3: ireturn // Return the top of the stack
The JVM is the future of the server-room.
Aunimeda designs and builds scalable software architectures - from system design to implementation and ongoing engineering.
Contact us to discuss architecture for your project. See also: Custom Software Development, Web Development