JVM 和 CLR 如何知道何时启动
只是想知道是否有人愿意向我解释 JVM、CLR 和其他“虚拟机”如何知道何时“启动”?
我的意思是,您双击可执行文件,您的机器开始执行代码,但在某些时候(显然),代码需要通知机器该代码需要其他进程才能运行,并且需要传递操作码。那么这是如何发生的呢?
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 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. So how does this take place?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
每个可执行文件首先运行非托管代码,它将控制权传递给 CLR(从 mscoree.dll 调用 _CorExeMain)。然后 CLR(非托管事物)读取/编译/执行程序集中的代码(并执行其他操作)。
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.
在 .net 程序中,可执行文件中存在一种启动 CLR 的引导加载程序。该引导加载程序是用本机机器代码编写的,因此可以直接执行。接下来是托管代码和其他应用程序资源,然后 CLR 会使用这些资源来执行 .net 程序。
看一下JVM,可能会更清楚。您有几个 .class 文件正在传递给 java.exe。这些.class文件包含java字节码,不能通过双击直接执行。另外,.jar 文件只是一个包含 .class 和其他文件的 zip 文件。文件扩展名 .jar 映射到 java.exe,当您双击它时,java.exe 将以 .jar 文件作为参数执行 - 与双击 .doc Word 文件并启动 Word 的过程相同。
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.
这在某种程度上依赖于操作系统。在linux中,你不能仅仅通过说出java程序的名称来运行Java程序,你通常会执行 java 。我没有运行任何 CLR 二进制文件,但我认为它是相同的。在 Windows 中(对于 Jar 文件之类的东西),Windows 有一个处理程序,它会说“当用户打开以 .jar 结尾的文件时,运行 java”,对于 .net 二进制文件也类似。
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.