| 1) It is better for object-oriented because objects are very complex and VM handles initialization. It supports message sending and not function calling. 2) VM's allow for portability, binary compatibility between platforms. 3) VM's allow memory handling so that programmers don't have to explicitly allocate and deallocate memory. VM also provides garbage collection. ~Sabina Karkin |
| Good answers Sabina, anymore anyone? Barbara Ericson |
| Using a virtual machine and compiling to native code are two different things. You're using a compiler to compile to machine code in either case. (3:) There is nothing saying that VM's have to do garbage collection. (1:) This answer isn't really on-target either... timmy |
| When using a virtual machine you can either do just-in-time compiliation or do an interpreter. If the platform that you want to run on has a just-in-time compilier you can use it since they are usually faster but that doesn't mean you have to use it on all platforms. One reason for using a VM is that it can do garbage collection and in Squeak and Java's VMs do provide garbage collection. Barbara Ericson |
| There are more reasons for using a VM. Anybody else want to add some? Barbara Ericson |
| Security and faster startup are also reasons for using a VM. ~Sabina Karkin |
| faster startup? timmy |
| as a side-effect of them being more memory efficient (and of course this isn't necessarily so). A more important advantage of this is that it makes VM's suitable for low-power, low-memory consumer devices. Michael Mitchell |
| Good answer Michael Barbara Ericson |
| You might add a primitive (code inside the VM interpreter) in VM for handling arithmetic manipulations, storage management, for control, and for input-output. ~Sabina Karkin |
| Good answers Sabina, anymore anyone? Barbara Ericson |
| Another reason to add primitives might be for increased speed. Jason Williams |
| Yes, Jason, speed is a major reason for adding a primitive. Barbara Ericson |
| Similarities: They are both stack-based. They both execute bytecodes. They both have garbage collection. Differences: Java VM bytecodes are typed and have more operands. Java VM makes threads more significant (stacks are associated with threads, not with method contexts). With Java, threads/processes are all in the VM, whereas with Squeak, they are done with Squeak and primitives. Java handles exceptions within VM (faster but more complex), whereas Squeak handles exceptions within Squeak (flexible-able to continue, easier to port, but slower). It's harder to port to different platforms with Java VM. Java VM guarantees a level of security. ~Sabina Karkin |
| Nice answers Sabina Barbara Ericson |
| One algorithm is reference-counting where you keep a count of all references to an object. When it's zero, you remove the object. Downside is problems with cycles and it can defer with things on stack because every store to object memory requires incrementing/decrementing. ~Sabina Karkin |
| Good answers Sabina. There are more algorithms. Anyone else care to try it? Barbara Ericson |
| mark-and-sweep, generational, and uhh maybe copy-and-(sweep?). Maybe you'll ask us to explain them on the test? timmy |
| Yes, explaining would be good. Barbara Ericson |
| It is not a good idea to use a VM when doing 3D graphics because it is not able to handle 3D. It is a good idea to use a VM when doing applications that you want to be secure because VM generates a good level of security. ~Sabina Karkin |
| Why isn't the VM able to handle 3D graphics? Barbara Ericson |
| VM's in theory can handle 3D graphics; there are speed issues, however, that make it more viable to do 3D graphics in a lower-level language like C or C++. Jason Williams |
| VMs generally don't optimize for a particular hardware feature. Same goes for many libraries. timmy |
| Right, timmy, virtual machines don't take advantage of hardware features since they are supposed to be easy to port to other machines. Barbara Ericson |
| Defining the Plugin code takes up most of the code. (I'm not really sure about this question.) ~Sabina Karkin |
| No, I am looking for what takes the most code and execution time in the code for the primitive. Barbara Ericson |
| depends on the primitive...handling types and transferring data is probably one of the bigger annoyances timmy |
| What is it that we have to do with types in going from OO to primitives? Barbara Ericson |
| convert them. The way a language or implementation holds non-primitive data is implementation dependant so there is no standard way. Sometimes the conversion is referred to boxing and unboxing. timmy |
| Right, timmy, in fast primitives much of the code and execution time goes into boxing and unboxing (converting from the object type to the primtive type. For example, Strings in Java are not arrays of characters as they are in C so a conversion has to be made. Barbara Ericson |