View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Sp01 Final Exam Review: Virtual Machines

See Final Exam Review - Sp2001

Comments? Answers? Criticisms?

a. Give three reasons why it may make sense to use a virtual machine instead of native code in an application or device.

1. System Independence - A Java application will run the same in any Java VM, regardless of the hardware and software underlying the system.

2. Security - Because the VM has no contact with the operating system, there is little possibility of a Java program damaging other files or applications.

3. Code safety - Since run-time error-checking is possible with the use of VM, the VM can catch exceptions such as array-out-of-bounds or the infamous "Segmentation fault (core dump)" error that C likes to give us. :-)

4. User-interactive - User-interactive programming languages are more easily implemented using VM, where users can change the source code while the program is being executed.

b. Identify two features of the Java HotSpot and Squeak virtual machines that are common between them, and two other features that are different.

Java Hotspot? Never heard of that thing before.

c. What takes up the majority of code (and probably execution time) in a primitive written for a virtual machine?

Interface with the underlying OS and error-checking. (?)

chok
VM has no contact with the operating system? Code safety misses an important one. HotSpot is a JIT. On (c), did Olin talk to y'all about boxing and unboxing objects? Mark Guzdial

For code safety you can have the concept of a "sandbox" where the VM can play but can't touch resources outside of it's permitted area (perhaps it's not allowed to touch files outside of a certain directory, or it's not permitted to open network connections).

While Olin only mentioned boxes briefly (that I can recall/find in my notes), I'll hazard a guess anyways:

Memory in squeak comes in 32 bit hunks, but not all data fits nicely into those blocks, so your primitive will have to do some aligning and massaging to get the data to fit nicely.
Let's take floating points as an example for boxing-unboxing. Floats in Squeak have a platform-independent format (endian of the processor doesn't matter) and some object header information. Floats in a given OS are some format to make it easier for FP operations. Converting from object->native format is called "unboxing", and putting the result back into an object is called "boxing." The reality is that the biggest time sink in many primitives is boxing and unboxing. For example, one of my students is working with OpenGL in Squeak. OpenGL is zoomer-fast, but he's finding that the overall result is slower than using Squeak's built-in 3D renderer! Why? Because of the time cost associated with getting the OpenGL bits into the Squeak object Display (e.g., dealing with color differences, dealing with format differences, etc.) and vice-versa: Boxing-unboxing problems. Mark Guzdial
There is at least one more reason to use VM's, one that was used on the earliest slow computers and is still important today; I mentioned it in class–anyone remember? Also, how do VM's catch errors? It's not like there is a single "segmentation fault" error. Why do most interpreted systems not segment fault (or GPF)? -Lex Spoon
VM's give us garabage collection so instead of spending effort on deallocating memory, you can concentrate on adding more features, researching user interaction, etc. right?
hamed
b. Java and Squeak's VMs are stack based. The garbage collection for both use generational scavenging and mark-sweep.
Differences: Java is a typed language, exceptions are handled in Squeak by Squeak while Java's are handled by the VM, threads are handled by Java in the VM while Squeaks are handeld by Squeak and primitives.


Lex, I think you're looking for Exception handling? Java - handled by VM, faster. Squeak - handled by Squeak (whatever that means from the lecture slides), slower

chok :-)


and the advantage of having slower exception handling means you can debug it interactively there in the system because its handled in squeak, not in the VM. i guess its a religious debate though (whether it is an "advantage" or not), as seen in newsgroup? hehehe
not to mention squeaks exceptions allow you to proceed through next frame of execution!



Link to this Page