Java的JVM和.NET的CLR的内部工作方式之间有什么区别?

时间:2020-03-05 18:52:16  来源:igfitidea点击:

Java的JVM和.NET的CLR的内部工作方式之间有什么区别?

也许起点是,它们在各自的环境中(Java> JVM>机器代码)(C> CLR> IL)基本上是同一件事。

更新:几个人提到了我要讲的要点:

  • 垃圾收集
  • 装箱/拆箱
  • JIT调试
  • 泛型/模板
  • 请随时提出其他区分这两个主题的好话题。

@George Mauer,这听起来很有趣:

Already posted this once but here is a series of interviews with c# chief language designer Anders Hejlsberg.

解决方案

回答

从这里。我不能说得更好(好吧,除了火焰战争,这是一个没有火焰的地方:-))。

Hello,
  
  Responding to your question seems
  fraught with peril by starting a flame
  war, so I'll proceed cautiously.
  
  There are a number of fundamental
  technical similarities between the
  Java Runtime and the Common Language
  Runtime, including garbage collected
  memory, an intermediate language
  (Microsoft IL versus Java ByteCode),
  core system libraries, and support for
  fairly high level languages, code
  security, and deployment.
  
  However, each of these 'similar' areas
  also have a number of sizable and
  small differences, and it's beyond the
  scope of a simple Forum post to
  describe most of them.
  
  I would suggest asking a more
  targetted question about any of the
  various runtime features and component
  areas (e.g. memory management,
  compilation, system libraries,
  security, etc.) and then we can
  provide a more targetted response
  (e.g. a blog, a technical article, or
  some books).

回答

这应该是一个很好的线程。

CLR和JVM之间的最大区别之一是CLR与泛型的本机集成。

取而代之的是Java删除了泛型类型,并且JVM只能通过对看起来像伪泛型的对象进行自动装箱来处理这些对象。

回答

已经发布过一次,但是这里是对首席语言设计师Anders Hejlsberg的一系列采访。尽管大多数人都在谈论Cand Java之间的差异,但他也深入探讨了虚拟机之间的差异。

回答

正如Vinko所说,完整的细节超出了论坛帖子的范围。差异/相似性可以归结为:

它们都是运行时环境"沙箱",其中包括"即时"编译器,可将中间语言(MSIL或者ByteCode)中的程序指令转换为本地机器代码,并提供自动内存管理(垃圾收集)。位于各个运行时环境之上的是一组类库,这些类库为开发人员提供了更高级别的抽象,以简化开发任务。

实际上,这些运行时环境的实际实现方式内部是Microsoft和Sun专有的。例如,垃圾收集系统使用的算法虽然在技术功能上可能相似,但在实现上却有所不同。

回答

Miguel de Icaza在这里提到:

Seasoned industry programmers will notice that the above is
  very much like Java and the Java VM.   They are right, the above
  is just like Java. 
  
  The CIL has one feature not found in Java though: it is
  byte code representation that is powerful enough to be used as a
  target for many languages: from C++, C, Fortran and Eiffel to Lisp
  and Haskell including things like Java, C#, JavaScript and Visual
  Basic in the mix.
  
  I wish I had the time to go in more detail, but for the sake
  of this argument, the above will suffice.

不过,注释会涉及一些细节,例如尾部调用优化。自2002年以来,尽管CLR和JVM现在都有针对它的多种语言,但情况发生了很大变化。但是尽管如此,还是值得一读。

回答

一个本质的区别是,JVM可跨平台移植,并且可在Linux,Macintosh和许多手机和嵌入式设备上运行。

CLR在Microsoft支持的平台上运行,其Mono项目在更多方面提供了对CLR旧版本的部分支持。

在内部,这意味着JVM的性能将根据平台本身提供的功能而在那些不同的平台上有所不同。

回答

据我所知,.Net CLR仍具有运行时内置的更加灵活和强大的代码访问安全性,允许更精细的权限和执行策略。

回答

垃圾收集方面也有差异。
JVM使用复制收集器以及标记和清除。 .NET用户Copying Collector和Mark紧凑(很难实现)。

Flyswat提到的类型擦除也很重要。 JVM不了解泛型,所有东西都是对象和相关的性能。装箱和拆箱的罚款。同样,反射不会为我们提供一般信息。 CLR本机支持泛型。