开发者

How does the JVM and CLR know when to kick in

Just wondering if someone would be kind enough to explain to me how the JVM, CLR and other "Virtual Machines" know when to "kick in"?

By this I me开发者_C百科an, you double click on your executable and your machine begins executing the code but at some point - obviously - the code needs to inform the machine that this code requires some other process to function and needs to pass in the op codes. So how does this take place?


Every executable first runs unmanaged code, which passes the control e.g. to CLR (calls _CorExeMain from mscoree.dll). Then the CLR (the unmanaged thing) reads/compiles/executes the code (and do other stuff) inside your assembly.


In .net programs there is a kind of bootloader in the executable which starts the CLR. This bootloader is written in native machine code so it can be executed directly. It is followed by the managed code and additional application resources which are then taken by the CLR to execute the .net program.

Have a look at the JVM and it might be more clear. You have several .class files which are beeing passed to java.exe. These .class files contains java bytecode and cannot be executed directly by double clicking on it. Also a .jar file is just a zip file with .class and other files in it. The file extension .jar is mapped to java.exe and when you double click it java.exe is executed with the .jar file as parameter - same process as you double click on a .doc word file and Word starts.


This is somewhat operating system dependent. In linux, you can't run a Java program by just saying the name of the java program, you usually do java . I haven't run any CLR binaries, but I assume that it is the same. In Windows (and for things like Jar files) windows has a handler that says something like "when the user opens a file that ends with .jar, run java" and similar for .net binaries.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜