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

Spring 2004 Final Exam Review: Virtual Machines

a. Give three reasons that one might use a virtual machine (and compiling to native code) instead of a compiler to compile directly to machine code.

b. Give a good reason why you might add a primitive to a VM.

c. How are the Java and Squeak VM's similar. How are they different?

d. What is one algorithm that is used for garbage collection?

e. Is it a good idea to use a VM when doing 3D graphics? When doing applications that you want to be secure?

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

Justin Barber

a) Makes programs portable, memory is handled by vm (provided garbage collection), better security (not executing on bare machine). Good for O-O Programing too because objects are initiailized.

b) ?

c) Similiar in that both are stack based. Different in that Java supports native data types. Java associates threads with stacks, not method contexts. Same gc alogrithms.

d) Combination of generation scavenging and mark-sweep

e) No, . Yes, because VM specifies a format for the class it ensures it must be followed before execution.

f) manipulating the stack or method context.

I don't understand what he meant in a in the above...
a) To put the cost of portability on the language maintainer, not the programmer using the language. Memory can be handled by the VM (garbage collection). The VM can audit the code so it will run in a sandbox to help safeguard against malicious code.

b) Primitives are fast.

c) They both provide memory management and run time exception handling. Java allows access to primitive types (as primitive types) whereas everything in Squeak is an object (some objects end up as primitive types though).

d) Generation scavaging.

e) Yes. 3D programming is highly math intensive, but also highly repetetive and also highly optimizable. VMs can easily win with code blocks that tend to do the same thing with just slightly different numbers.
Yes. The VM can audit the code as it runs to avoid malicious usage.

f) I need to verify the above answer... I have no clue.
Andrew Sayman

per the squeakVM slide "Performance of certain operations such as Intensive 3-D graphics" this is under weakness of VM. So no you wouldn't want to use it for 3D.
Also, per the slide: "Security Not running on the bare machine, can be safer" which is under strength of VM. So yes. -Tin Nguyen

I guess I simply disagree with that slide then. This question said nothing about Squeak's VM when asking questions here. I guess it also doesn't really specify what they mean. I will accept that a more correct answer is no, but this question seems poorly worded to me.
Andrew Sayman

Actually, the question seemed pretty clear. It asked "Is it a good idea to use a VM when doing 3D graphics?" And under the slide entitled "Weaknesses of VMs" it lists as one of the weaknesses:
Of course, you can disagree with that slide, and you seem to have a valid argument, but unless you want to come back to Tech during the summer after your final has been graded, and convince the TAs of your point, I'd recommend you stick with your plan to go with the safer road.

Seth Horrigan

actually, i might accept andrew's answer as correct. we're not so intent on having you all memorize slides, as we are in having you learn and be able to apply concepts. generally, 3d graphics are slower in vms because of the boxing/unboxing noted below, however, if you have a good argument and we think it makes sense that's what we're really looking for. andrew's answer would certainly get more points than a simple "no". -ellie

F. Although the slides do not explicitly say so, if you look at the code for a primitive, about 90% of it is getting the data from Squeak into local variables so that the data can be handled in the machine code. For example, the addition primitive, found on Page 196 of the blue book, has five lines of code to access the two arguments and to check them, and one line of code to do the actual addition.

Seth Horrigan

F. According to the lecture slide note, most of the code is checking return values and converting to and from intergers: "Notice that most of the code is dealing with testing for return values and converting things to and from integers" (Slide 46).

Tejesh Patel (TJ)

part f: yes, seth and tj, slow downs in vm's tend to be centered around "boxing and unboxing", dealing with the conversion between a higher level world of objects and a lower level world of primitives (machine code) -ellie

A comment about 3D graphics.
3D graphics are heavily hardware dependent. Programmers make use of graphics API's that pretty much speak directly to the hardware. eg. openGL and Direct X. The VM by nature has an added layer (the virtual bytecode)... which itself is layered upon the system's OS. There are just too many software layers to trickle through to get to the hardware. It will be slower, and is not suited for intensive 3d graphics.

Does this explanation take into account JIT? Things like OpenGL have lots of calls where you set up a long list of stuff, and then you can have the hardware render it in one big bang. The time to set these things up isn't very different between a VM and system code, and the big bang could easily be in a JIT part of the VM. You might lose if you wanted to do a lot of transforms and such, but these things are being moved to the hardware more and more these days too. If you make a list in OpenGL with the common transforms being a part of it then that will also go very quickly.

Also, I know nothing about DirectX, and it also isn't pertinent to this discussion. DirectX is completely non-interoperable and non-platform-independent. Using it in a VM would cause you to lose most of the benefits of a VM, so I would consider it cut out for reasons completely unrelated to the viability of VMs managing 3d code.
Andrew Sayman

Links to this Page