For faster navigation, this Iframe is preloading the Wikiwand page for GCJ.

GCJ

GNU Compiler for Java
开发者The GNU Project
首次发布1998年9月6日,​25年前​(1998-09-06[1]
最终版本
  • 6.5 (2018年10月26日;稳定版本)[2]
编辑维基数据链接
操作系统Unix-like
类型Compiler
许可协议GNU GPL
网站gcc.gnu.org

GNU Java编译器(英语:GNU Compiler for JavaGCJ)是一个自由的Java编译器。它是GCC(GNU Compiler Collection)的一部分,已有十多年的历史。但自2017年起,GNU宣布不再对其进行维护,也不会在GNU的后继版本中包括它。[3][4]

GCJ可将Java 源代码编译为Java虚拟机字节码或适用于不同架构的机器码。它还可以将包含字节码的类文件和整个jar文件编译为机器代码。[5][6]

历史

[编辑]

GCJ的运行时库来源于GNU Classpath项目,但libgcj库之间有一些区别。GCJ4.3使用了Eclipse Java编译器作为编译前端。[7]

在2007年,GNU做了许多工作来在GNU Classpath中实现两个重要的Java图形库:AWT库和Swing库。首先尝试实现的为AWT库,当AWT库实现后,便可以开始考虑实现Swing库。这时至少有一种自由的方式来实现Swing。[8]但是GCJ从未支持到Java1.2以及更高的版本。现在来看该项目已被完全放弃。

直至2015年,GCJ未进行任何的开发,并且该项目被标记为维护模式。在这段时间,自由的Java实现主要在OpenJDK项目中进行。[9] GCJ在2016年9月30日被从GCC工具链中移除。[10][11] 该通知随GCC7.1版本的发布而发布。[12] 而GCC6中仍包括GCJ。

性能

[编辑]

使用GCJ将Java源码编译为机器代码后,其启动时间一般比使用JVM运行等效字节码的启动时间更快。[13]

Compiled Native Interface

[编辑]

Compiled Native Interface (CNI), 原名"Cygnus Native Interface", 是一个GCJ软件框架。与JNI(Java Native Interface)类似,它允许Java程序访问和使用本机共享库(在各个平台和不同的硬件类型中有所不同)和使用C++编写的共享库。

两种方式的比较

[编辑]

CNI的作者对于CNI和JNI的评价如下:[14]

CNI依赖于类似于C++的Java类。例如这是一个Java类:[15]

public class Int
{
   public int i;
   public Int(int i) { this.i = i; }
   public static Int zero = new Int(0);
}

于是就可以这样使用:

#include <gcj/cni.h>
#include <Int>

Int *mult(Int *p, int k)
{
  if (k == 0)
    return Int::zero;  // 静态成员访问
  return new Int(p->i * k);
}

另见

[编辑]
  • Excelsior JET (另一个Java实现)
  • IcedTea
  • Kaffe
  • SableVM
  • JamVM
  • Apache Harmony
  • Jikes
  • GraalVM - GraalVM的本地映像功能使用了预编译技术,这使得它可以生成类文件可执行的二进制文件。
  • 自由的Java实现
  • Kotlin - Kotlin/Native是一种将Kotlin语言编译为本地可执行二进制文件而无需JVM的技术。它包括一个基于LLVM的后端和本地Kotlin库实现两个部分。

备注

[编辑]
  1. ^ 这句话的意思是,CNI的理念是在编译层面使Java和C++做到尽量兼容,而这需要Java和C++的编译器的某些标准一致。GNU计划刚好既实现了Java编译器,又实现了C++编译器,因此很容易在编译器层面对其进行调整,使其更易用,性能更高。

参考资料

[编辑]
  1. ^ Anthony Green, Cygnus Solutions. GCJ announcement. [2020-08-07]. (原始内容存档于2017-07-11). 
  2. ^ GCC Releases - GNU Project. 
  3. ^ Archived copy. [2010-04-22]. (原始内容存档于2007-05-09). 
  4. ^ Campbell, Bill. Introduction to Compiler Construction in a Java World. CRC Press Taylor & Francis Group. 2013 [2014-02-06]. ISBN 978-1-4398-6088-5. (原始内容存档于2020-08-12). 
  5. ^ 存档副本. [2020-08-07]. (原始内容存档于2020-09-04). 
  6. ^ 存档副本. [2020-08-07]. (原始内容存档于2016-08-20). 
  7. ^ gcj to use Eclipse compiler as a front end. 2007-01-08 [2007-05-20]. (原始内容存档于2007-05-09). 
  8. ^ GCC Frequently Asked Questions - GNU Project - Free Software Foundation (FSF). gcc.gnu.org. [2020-08-01]. (原始内容存档于2020-06-12). 
  9. ^ GCC Looks To Turn Off Java, Replace With Go Or ADA. [2020-08-07]. (原始内容存档于2020-07-25). 
  10. ^ Andrew Haley. [gcc] Revision 240661. 2016-09-30 [2020-08-07]. (原始内容存档于2019-06-16). 
  11. ^ Tromey, Tom. The Deletion of gcj. The Cliffs of Inanity. 2016-10-02 [2016-10-03]. (原始内容存档于2020-07-25). 
  12. ^ GCC 7 Release Series: Changes, New Features, and Fixes. [2017-05-09]. (原始内容存档于2020-09-02). 
  13. ^ GCJ: The GNU Static Java Compiler (PDF). [2009-08-02]. (原始内容 (PDF)存档于2011-06-07). 
  14. ^ The GCJ FAQ - GNU Project - Free Software Foundation (FSF). [2020-08-07]. (原始内容存档于2016-10-20). 
  15. ^ 这个例子来源于 https://gcc.gnu.org/onlinedocs/gcj/Objects-and-Classes.html#Objects-and-Classes页面存档备份,存于互联网档案馆

外部链接

[编辑]
{{bottomLinkPreText}} {{bottomLinkText}}
GCJ
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?