简体   繁体   English

JVM 和 CLR 如何知道何时启动

[英]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"?只是想知道是否有人愿意向我解释 JVM、CLR 和其他“虚拟机”如何知道何时“启动”?

By this I mean, 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.我的意思是,你双击你的可执行文件,你的机器开始执行代码,但在某些时候——显然——代码需要通知机器该代码需要对 function 进行一些其他处理,并且需要传递操作码。 So how does this take place?那么这是如何发生的呢?

Every executable first runs unmanaged code, which passes the control eg to CLR (calls _CorExeMain from mscoree.dll).每个可执行文件首先运行非托管代码,将控制权传递给 CLR(从 mscoree.dll 调用 _CorExeMain)。 Then the CLR (the unmanaged thing) reads/compiles/executes the code (and do other stuff) inside your assembly.然后 CLR(非托管事物)读取/编译/执行程序集中的代码(并执行其他操作)。

In .net programs there is a kind of bootloader in the executable which starts the CLR.在 .net 程序中,在启动 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.紧随其后的是托管代码和其他应用程序资源,然后 CLR 将使用这些资源来执行 .net 程序。

Have a look at the JVM and it might be more clear.看看 JVM 可能会更清楚。 You have several.class files which are beeing passed to java.exe.您有几个.class 文件正在传递给 java.exe。 These.class files contains java bytecode and cannot be executed directly by double clicking on it.这些.class文件包含java字节码,不能直接双击执行。 Also a.jar file is just a zip file with.class and other files in it.此外,a.jar 文件只是一个 zip 文件,其中包含 .class 和其他文件。 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. 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.在ZE206A54E97690CCE50CCE872D70EE896Z中,您不能通过仅说出Z93F725A07423FE1C8888888888B48B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4BBENION无法运行ZD52387880E1EA22817A72D3759219819Z I haven't run any CLR binaries, but I assume that it is the same.我没有运行任何 CLR 二进制文件,但我认为它是相同的。 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. 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.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM