4 ms·
The update that describes why 4KB of RAM was necessary was interesting to me. In 1998 I wrote a Java Virtual Machine in assembly language for a PIC-like microco
by k1w1 12y ago
The update that describes why 4KB of RAM was necessary was interesting to me. In 1998 I wrote a Java Virtual Machine in assembly language for a PIC-like microcontroller that only had 4k of ROM (actually it was 4k instructions, but they were 12-bit words giving 6kB). I managed to get all of the important features of the language to fit, including exception handling and an interactive debugger. However by the end, each time I wanted to add a new instruction to my code I had to find something else to optimize first so it would still fit in 4k.
By the end I convinced myself that 4k was the minimum possible code size for implementing a JVM.
The JVM was used in the Parallax Javelin Stamp - a Java version of the BASIC Stamp (http://en.wikipedia.org/wiki/BASIC_Stamp http://en.wikipedia.org/wiki/BASIC_Stamp).
As an aside, the SX microcontroller only had 256 bytes (yes bytes!) of RAM internally so I used an external 32kB SRAM for the Java heap and stack. The 256 bytes of internal RAM held the internal state of the interpreter and memory manager.
- seanmcdirmid 12y agoAround the same time, I wrote a JVM for the PalmPilot [1]. I think it had to fit into 128K of ram with an additional 256K of memory for data (like the class libraries). I was able to fit the entire JDK 1.0.2 runtime into it by transforming the byte code. But 4K...wow! [1] http://lampwww.epfl.ch/~mcdirmid/papers/ghost.pdf http://lampwww.epfl.ch/~mcdirmid/papers/ghost.pdf
- radio4fan 12y agoYep, 4k is pretty wow indeed. My first computer was a Sinclair ZX81, which only had 1K or RAM, but there was 8K of ROM, and the BASIC interpreter was pretty, um basic.
- analog31 12y agoThe hardware was interesting too. It bit-banged the video display circuit, leaving only the re-trace interval for general purpose computation, including running BASIC programs. Yet the result was an extremely simple and inexpensive design. Every early microcomputer had to come up with a solution to the video display problem. As I understand it, the Apple II had a bus architecture that interleaved the clock timing of the video circuit and the CPU, sharing a single bus. The Commodore computers had custom video graphics chips. And so forth.
- sitkack 12y agoThat is amazing. I used a Dallas Semiconductor 8051 with a JVM on it. Can't believe you fit a JVM into 4k of ROM.
- k1w1 12y agoSince the product itself is now discontinued (though it did sell for 10 years), I have posted the source code for posterity: https://github.com/k1w1/javelin-stamp/blob/master/asm/javelin.src https://github.com/k1w1/javelin-stamp/blob/master/asm/javeli... Reading back over the assembly code gives me fond memories - but I am glad I don't spend my nights debugging my code with an oscilloscope and flashing LEDs anymore. It is a bit more productive coding in Ruby! The JVM had some limitations to fit into 4k: no floating point, 16-bit integers and no dynamic linking. There was a PC program that took the Java class files, statically linked them and translated the bytecode to a more compressed form for download to the chip.
- sitkack 12y agoThis is great, reading through it now. What do you think about Dalvik's register based VM ? Have you looked http://www.jopdesign.com/ http://www.jopdesign.com/ ? Are you doing anything hardware related these days ?
- k1w1 12y agoAt the time I wrote this code there was a lot of talk about Java specific processors. Ultimately that was a mistake because Moore's law meant the x86 architecture (and JIT technology) got faster more quickly that anyone could get chips to market. These days I am about as far from embedded systems as you can get. I write Ruby on Rails code for aha.io. There is a lot of satisfaction in seeing the perfect waveform on your oscilloscope when the assembly code finally works - but these days I think there is much more satisfaction in being able to crank out a complex algorithm with some elegant Ruby and have it being used by customers before going home for dinner.
- sitkack 12y agoI don't yet understand how you did memory allocation. Could you give me a pointer?