MacOS 編譯 openjdk8 並導入 Clion 調試


環境准備

  • 安裝Xcode11.0,當然也可以是其他版本,盡量超過11.0可以在appstore下載,也可以開發者網址下載:https://developer.apple.com/download/more/

  • 安裝xcode-select

    xcode-select install
    
  • 安裝mercurial,類似於git可以下載openjdk源碼

    brew install mercurial
    
  • 安裝freetype,它是一個用C語言實現的一個字體光柵化庫。它可以用來將字符柵格化並映射成位圖以及提供其他字體相關業務的支持。

    brew install freetype
    

下載openjdk

  • 下載代碼方法一:可以直接在官網下載

     hg clone http://hg.openjdk.java.net/jdk8u/jdk8u60 jdk8u
     cd jdk8u
     sh ./get_source.sh
    
  • 方法二:可以在github上面下載

    git clone https://github.com/dwtfukgv/openjdk-jdk8u jdk8u
    
  • 代碼的目錄結構如下

    目錄 內容
    . 通用配置和生成makefile編譯文件,configureMakeFile
    hotspot 用於構建 OpenJDK 虛擬機的源代碼和make文件,也就是JVM源碼,目錄結構后面會介紹。
    langtools JDK提供的開發工具,比如javacjavap等工具,目錄結構后面會介紹。
    jdk JDK的源碼和用於構建 OpenJDK 運行時庫和雜項的make文件,目錄結構后面會介紹。
    jaxp JAXP的全稱是Java API for XML Processing,是Java定義的一組操作XML文檔的API,注意JAXP只是定義了API,並沒有提供具體的實現,Java為了保證JAXP能夠即裝即用,默認帶了Apache Xerces 解析器,代碼位於jaxp/src/com/sun/org/apache下。目錄結構后面會介紹。
    jaxws JAX-WS全稱是JavaTM API forXML-Based Web Services, 是一組基於SOAP協議實現的Web Service的API,與之相對的是JAX-RS,全稱是JavaTM API for RESTful Webservices,是一組基於RESTful風格的Http服務實現Web Service的API。JAF全稱是JavaBeans Activation Framework, JAF的目的在於統一處理不同數據格式的方法(不管數據格式為簡單文本還是由圖片、聲音、視頻甚至其它"活動"內容共同組成的復合文檔),使得Java對象與編碼數據流之間的映射變得非常容易,可以參考JavaMail中JAF的應用。JAX-WS相關代碼位於jaxws/src/share/jaxws_classes,目錄結構后面會介紹。
    nashorn JDK8內嵌的Nashorn JavaScript 引擎,擴展了JavaJVM上運行動態JavaScript腳本的能力。
    corba CORBA 全稱是Common Object Request Broker Architecture,CORBA 1.1 由對象管理組織在 1991 年發布,他定義了接口定義語言(IDL)和應用編程接口(API),從而通過實現對象請求代理(ORB)來激活客戶/服務器的交互。CORBA 2.0 於 1994 年的 12 月發布,他定義了如何跨越不同的 ORB 提供者而進行通訊。在功能上基本等同於Web Service。它實現了分布式系統下跨平台,跨語言的數據的傳輸和遠程方法的本地調用。
  • 對環境變量進行設置

    # 設定語言選項,必須設置
    export LANG=C
    # Mac平台,C編譯器不再是GCC,而是clang
    export CC=clang
    export CXX=clang++
    export CXXFLAGS=-stdlib=libc++
    # 是否使用clang,如果使用的是GCC編譯,該選項應該設置為false
    export USE_CLANG=true
    # 跳過clang的一些嚴格的語法檢查,不然會將N多的警告作為Error
    export COMPILER_WARNINGS_FATAL=false
    # 鏈接時使用的參數
    export LFLAGS='-Xlinker -lstdc++'
    # 使用64位數據模型
    export LP64=1
    # 告訴編譯平台是64位,不然會按照32位來編譯
    export ARCH_DATA_MODEL=64
    # 允許自動下載依賴
    export ALLOW_DOWNLOADS=true
    # 並行編譯的線程數,編譯時長,為了不影響其他工作,可以選擇2
    export HOTSPOT_BUILD_JOBS=4
    export PARALLEL_COMPILE_JOBS=4 #ALT_PARALLEL_COMPILE_JOBS=2
    # 是否跳過與先前版本的比較
    export SKIP_COMPARE_IMAGES=true
    # 是否使用預編譯頭文件,加快編譯速度
    export USE_PRECOMPILED_HEADER=true
    # 是否使用增量編譯
    export INCREMENTAL_BUILD=true
    # 編譯內容
    export BUILD_LANGTOOL=true
    export BUILD_JAXP=true
    export BUILD_JAXWS=true
    export BUILD_CORBA=true
    export BUILD_HOTSPOT=true
    export BUILD_JDK=true
    # 編譯版本
    export SKIP_DEBUG_BUILD=true
    export SKIP_FASTDEBUG_BULID=false
    export DEBUG_NAME=debug
    # 避開javaws和瀏覽器Java插件之類部分的build
    export BUILD_DEPLOY=false
    export BUILD_INSTALL=false
    
    # 最后需要干掉這兩個環境變量(如果你配置過),不然會發生詭異的事件
    unset JAVA_HOME
    unset CLASSPATH
    
  • 將環境變量寫到一個單獨的腳本里,假設是temp.sh,然后使其生效,就在該shell運行編譯代碼,注意不要使用新的shell窗口

    # 使腳本生效
    source ./temp.sh
    

編譯openjdk

  • 編譯命令,當前所在的位置就是所下的openjdk的項目位置,並且要和上一個shell的同一窗口,否則需要重新執行使腳本生效

    bash ./configure --with-debug-level=slowdebug --with-freetype-include=/usr/local/Cellar/freetype/2.10.4/include/freetype2 --with-freetype-lib=/usr/local/Cellar/freetype/2.10.4/lib/ --with-boot-jdk=/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home --enable-debug-symbols
    
  • 上面代碼只需要修改一下--with-freetype-include--with-freetype-lib--with-boot-jdk的位置即可,前兩個就是上面所安裝的freetype的安裝位置,默認應該是我這個位置。

    • --with-boot-jdk是本地jdk的位置,可能版本不太一樣,其他的應該是一樣的
    • --with-debug-level調試信息的級別,可選值有releasefastdebugslowdebug
  • 其他參數的意思在上面的配置文件里有部分解釋,也可以通過sh ./configure --help查看字段意義,也可能看官網的解釋:http://hg.openjdk.java.net/jdk8u/jdk8u/raw-file/tip/README-builds.html#configure

  • 出現下面圖就成功了。

    ====================================================
    A new configuration has been successfully created in
    /Users/dwtfukgv/ClionProjects/jdk8u/build/macosx-x86_64-normal-server-slowdebug
    using configure arguments '--with-debug-level=slowdebug --with-freetype-include=/usr/local/Cellar/freetype/2.10.4/include/freetype2 --with-freetype-lib=/usr/local/Cellar/freetype/2.10.4/lib/ --with-boot-jdk=/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home --enable-debug-symbols --with-xcode-path=/Applications/Xcode.app OBJCOPY=gobjcopy'.
    
    Configuration summary:
    * Debug level:    slowdebug
    * JDK variant:    normal
    * JVM variants:   server
    * OpenJDK target: OS: macosx, CPU architecture: x86, address length: 64
    
    Tools summary:
    * Boot JDK:       java version "1.8.0_261" Java(TM) SE Runtime Environment (build 1.8.0_261-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.261-b12, mixed mode)  (at /Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home)
    * C Compiler:     Apple clang version (clang-1100.0.33.8) version 11.0.0 (clang-1100.0.33.8) (at /usr/bin/clang)
    * C++ Compiler:   Apple clang version (clang-1100.0.33.8) version 11.0.0 (clang-1100.0.33.8) (at /usr/bin/clang++)
    
    Build performance summary:
    * Cores to use:   5
    * Memory limit:   16384 MB
    * ccache status:  not installed (consider installing)
    
    Build performance tip: ccache gives a tremendous speedup for C++ recompilations.
    You do not have ccache installed. Try installing it.
    
  • 進行make操作

    make all
    
  • 成功后會輸出下面的信息

    ----- Build times -------
    Start 2021-05-02 22:10:30
    End   2021-05-02 22:11:52
    00:00:00 corba
    00:00:00 demos
    00:00:48 docs
    00:00:12 hotspot
    00:00:18 images
    00:00:00 jaxp
    00:00:00 jaxws
    00:00:02 jdk
    00:00:00 langtools
    00:00:00 nashorn
    00:01:22 TOTAL
    -------------------------
    Finished building OpenJDK for target 'all'
    
  • 最后測試一下java是否已經編譯成功

    ./build/macosx-x86_64-normal-server-slowdebug/jdk/bin/java -version
    
  • 輸出以下信息就是成功

    openjdk version "1.8.0-internal-debug"
    OpenJDK Runtime Environment (build 1.8.0-internal-debug-dtfukgv_2021_05_02_21_14-b00)
    OpenJDK 64-Bit Server VM (build 25.60-b23-debug, mixed mode)
    

導入Clion

  • 點擊ClionFile | open...找到jdk8u下面的compile_commands.json打開Open as Project,等待Clion建立索引。

    image

  • 建立創建自定義Build Target,點擊Clion | Preference... | Build, Execution, Deployment | Custom Build Targets

    image

  • 點擊+或者Add target,起個名字,修改BuildClean,添加External Tools

    image

  • BuildClean的參數如下,Working directory是項目的根路徑

    image

    image

  • 最終顯示畫面應該是這樣

    image

  • 創建Run/Debug configuration,點擊Run | Edit Configurations...,點擊+添加一個Custom Build Application如下圖

    image

  • 創建Executable,我們可以選擇我們編譯出來的java,路徑應該是./jdk8u/build/macosx-x86_64-normal-server-slowdebug/jdk/bin/java,然后測試一下,給個參數是-version輸出java的版本號,如下圖

    image

  • 然后點擊運行RunClion會重新編譯,最后會顯示java的版本號,如下圖

    image

  • 如果不想每次都重新編譯Build可以刪除Before launch中的Build操作,Before launch還是在剛才的Run | Edit Configurations...中,可以選擇-將其刪除,如下圖

    image

  • 然后運行Debug可能出現以下錯誤SIGSEGV (signal SIGSEGV),因為MacOS上面使用lldb,所以需要添加一個配置文件,文件名是.lldbinit,注意該文件是在用戶目錄下,也就是目錄,不要在項目根目錄創建。

    image

    # ~/.lldbinit 文件內容
    break set -n main -C "process handle --pass true --stop false SIGSEGV" -C "process handle --pass true --stop false SIGBUS"
    
  • 再次運行Debug就不會出現剛才這個問題了

    !image

  • (可選)如果修改了項目代碼,需要重要進行編譯,重新生成Compilation Database,如果覺得麻煩可以使用File Watchers進行自動更新,如果需要可以查看文檔:https://www.jetbrains.com/help/clion/managing-makefile-projects.html#filewatcher-plugin

遇到的問題

  • 問題1: 出現Xcode 4 is required to build JDK 8, the version found was 11.0.

    configure: error: Xcode 4 is required to build JDK 8, the version found was 11.0. Use --with-xcode-path to specify the location of Xcode 4 or make Xcode 4 active by using xcode-select.
    configure exiting with result code 1
    

    解決方式:是找到common/autoconf/generated-configure.sh文件,注釋以下幾行:

    XCODE_VERSION=`$XCODEBUILD -version | grep '^Xcode ' | sed 's/Xcode //'`
        XC_VERSION_PARTS=( ${XCODE_VERSION//./ } )
        if test ! "${XC_VERSION_PARTS[0]}" = "4"; then
          as_fn_error $? "Xcode 4 is required to build JDK 8, the version found was $XCODE_VERSION. Use --with-xcode-path to specify the location of Xcode 4 or make Xcode 4 active by using xcode-select." "$LINENO" 5
        fi
    
  • 問題2: 出現 Unable to find required framework headers, provide a valid path to Xcode 4

    configure: error: Unable to find required framework headers, provide a valid path to Xcode 4 using --with-xcode-path
    configure exiting with result code 1
    

    解決方式:configure時參數添加--with-xcode-path

    --with-xcode-path=/Applications/Xcode.app
    
  • 問題3: 出現Agreeing to the Xcode/iOS license requires admin privileges

    Agreeing to the Xcode/iOS license requires admin privileges, please run “sudo xcodebuild -license” and then retry this command.
    (none, will use system headers and frameworks)
    configure: error: Unable to find required framework headers, provide a valid path to Xcode 4 using --with-xcode-path
    configure exiting with result code 1
    

    解決方式: 執行以下命令

    sudo xcodebuild -license
    # 閱讀文檔后輸入 agree 
    
  • 問題4: 出現GCC compiler is required. Try setting --with-tools-dir.

    configure: The C compiler (located as /usr/bin/clang) does not seem to be the required GCC compiler.
    configure: The result from running with --version was: "Apple clang version 11.0.0 (clang-1100.0.33.8)"
    configure: error: GCC compiler is required. Try setting --with-tools-dir.
    configure exiting with result code 1
    

    解決方式: 是找到common/autoconf/generated-configure.sh文件,注釋下面的代碼,注意可能里面有多處,同意gcc的版本大於3.81,否則會有問題

    as_fn_error $? "GCC compiler is required. Try setting --with-tools-dir." "$LINENO" 5
    
  • 問題5: 出現Unable to find objcopy, cannot enable debug-symbols

    checking if we should generate debug symbols... configure: error: Unable to find objcopy, cannot enable debug-symbols
    configure exiting with result code 1
    

    解決方式: 需要安裝binutils,並且需要在configure時添加參數OBJCOPY

    # 安裝 binutils
    brew install binutils
    
    # configure 添加參數
    OBJCOPY=gobjcopy
    
  • 問題6: 出現iostream' file not found

    warning: include path for stdlibc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]
    warning: include path for stdlibc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]
    warning: include path for stdlibc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]
    warning: include path for stdlibc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]
    Compiling /Users/dwtfukgv/ClionProjects/jdk8u/hotspot/src/share/vm/adlc/dict2.cpp
    In file included from /Users/dwtfukgv/ClionProjects/jdk8u/hotspot/src/share/vm/adlc/arena.c
    pp:25:
    /Users/dwtfukgv/ClionProjects/jdk8u/hotspot/src/share/vm/adlc/adlc.hpp:35:10: fatal error: 'iostream' file not found
    #include <iostream>
    export LANG=C
             ^~~~~~~~~~
    In file included from /Users/dwtfukgv/ClionProjects/jdk8u/hotspot/src/share/vm/adlc/archDesc.cpp:27:
    /Users/dwtfukgv/ClionProjects/jdk8u/hotspot/src/share/vm/adlc/adlc.hpp:35:10: fatal error: 'iostream' file not found
    #include <iostream>
             ^~~~~~~~~~
    In file included from /Users/dwtfukgv/ClionProjects/jdk8u/hotspot/src/share/vm/adlc/dfa.cpp:26:
    /Users/dwtfukgv/ClionProjects/jdk8u/hotspot/src/share/vm/adlc/adlc.hpp:35:10: fatal error: 'iostream' file not found
    #include <iostream>
             ^~~~~~~~~~
    In file included from /Users/dwtfukgv/ClionProjects/jdk8u/hotspot/src/share/vm/adlc/adlparse.cpp:27:
    /Users/dwtfukgv/ClionProjects/jdk8u/hotspot/src/share/vm/adlc/adlc.hpp:35:10: fatal error: 'iostream' file not found
    #include <iostream>
             ^~~~~~~~~~
    warning: include path for stdlibc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]
    In file included from /Users/dwtfukgv/ClionProjects/jdk8u/hotspot/src/share/vm/adlc/dict2.cpp:27:
    /Users/dwtfukgv/ClionProjects/jdk8u/hotspot/src/share/vm/adlc/adlc.hpp:35:10: fatal error: 'iostream' file not found
    #include <iostream>
             ^~~~~~~~~~
    1 warning and 1 error generated.
    

    解決方式: 下載下面這個依賴並安裝

    git clone https://github.com/dwtfukgv/xcode-missing-libstdc-
    cd xcode-missing-libstdc-
    sh ./install.sh
    
  • 問題7: 出現ordered comparison between pointer and zero ('address' (aka 'unsigned char *') and 'int')

    Compiling /Users/dwtfukgv/ClionProjects/jdk8u/hotspot/src/share/vm/opto/live.cpp
    /Users/dwtfukgv/ClionProjects/jdk8u/hotspot/src/share/vm/opto/lcm.cpp:52:35: error: ordered comparison between pointer and zero ('address' (aka 'unsigned char *') and 'int')
      if (Universe::narrow_oop_base() > 0) { // Implies UseCompressedOops.
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~
    

    解決方式:if改成下面的代碼

    if(Universe::narrow_oop_base() != NULL) {
    
  • 問題8: 出現ordered comparison between pointer and zero ('const TypeInt *' and 'int')

    /Users/dwtfukgv/ClionProjects/jdk8u/hotspot/src/share/vm/opto/loopPredicate.cpp:781:73: error: ordered comparison between pointer and zero ('const TypeInt *' and 'int')
          assert(rng->Opcode() == Op_LoadRange || _igvn.type(rng)->is_int() >= 0, "must be");
                                                  ~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~
    

    解決方式:assert改成下面的代碼

     assert(rng->Opcode() == Op_LoadRange || _igvn.type(rng)->is_int() != NULL, "must be");
    
  • 問題9: 出現ordered comparison between pointer and zero ('char *' and 'int')

    Compiling /Users/dwtfukgv/ClionProjects/jdk8u/hotspot/src/share/vm/runtime/vmStructs.cpp
    /Users/dwtfukgv/ClionProjects/jdk8u/hotspot/src/share/vm/runtime/virtualspace.cpp:345:14: error: ordered comparison between pointer and zero ('char *' and 'int')
      if (base() > 0) {
          ~~~~~~ ^ ~
    Compiling /Users/dwtfukgv/ClionProjects/jdk8u/hotspot/src/share/vm/classfile/vmSymbols.cpp
    1 error generated.
    

    解決方式:if改成下面的代碼

    if (base() != NULL) {
    
  • 問題10: 出現

    Compiling /Users/dwtfukgv/ClionProjects/jdk8u/hotspot/src/share/vm/utilities/vmError.cpp
    1 error generated.
    gmake[6]: *** [/Users/dwtfukgv/ClionProjects/jdk8u/hotspot/make/bsd/makefiles/rules.make:151: virtualspace.o] Error 1
    gmake[6]: *** Waiting for unfinished jobs....
    4 warnings generated.
    gmake[5]: *** [/Users/dwtfukgv/ClionProjects/jdk8u/hotspot/make/bsd/makefiles/top.make:129: the_vm] Error 2
    gmake[4]: *** [/Users/dwtfukgv/ClionProjects/jdk8u/hotspot/make/bsd/Makefile:290: debug] Error 2
    gmake[3]: *** [Makefile:231: generic_build2] Error 2
    gmake[2]: *** [Makefile:177: debug] Error 2
    gmake[1]: *** [HotspotWrapper.gmk:45: /Users/dwtfukgv/ClionProjects/jdk8u/build/macosx-x86_64-normal-server-slowdebug/hotspot/_hotspot.timestamp] Error 2
    gmake: *** [/Users/dwtfukgv/ClionProjects/jdk8u//make/Main.gmk:109: hotspot-only] Error 2
    

    解決方式:hotspot/make/linux/makefiles/adjust-mflags.sh文件中的內容進行替換,原因是make的版本太高,有些參數有點混用。

    s/ -j\([^       ]\)/ -j -\1/
    # 替換為
    s/ -j\([^       l]\)/ -j -\1/
    
  • 問題11:

    Undefined symbols for architecture x86_64:
      "_attachCurrentThread", referenced from:
          +[ThreadUtilities getJNIEnv] in ThreadUtilities.o
          +[ThreadUtilities getJNIEnvUncached] in ThreadUtilities.o
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    gmake[2]: *** [lib/PlatformLibraries.gmk:56: /Users/dwtfukgv/ClionProjects/jdk8u/build/macosx-x86_64-normal-server-slowdebug/jdk/lib/libosxapp.dylib] Error 1
    gmake[2]: *** Waiting for unfinished jobs....
    gmake[1]: *** [BuildJdk.gmk:70: libs-only] Error 2
    make: *** [jdk-only] Error 2
    

    解決方式:./jdk/src/macosx/native/sun/osxapp/ThreadUtilities.m文件中的內容進行修改

    inline void attachCurrentThread(void** env) {
    // 替換為
    static inline void attachCurrentThread(void** env) {
    
  • 問題12: 出現error occurred during error reporting , id 0x4

    openjdk version "1.8.0-internal-debug"
    OpenJDK Runtime Environment (build 1.8.0-internal-debug-dtfukgv_2021_05_02_21_14-b00)
    OpenJDK 64-Bit Server VM (build 25.60-b23-debug, mixed mode)
    #
    # A fatal error has been detected by the Java Runtime Environment:
    #
    #  SIGILL (0x4) at pc=0x0000000110c3ae38, pid=84856, tid=0x0000000000002803
    #
    # JRE version: OpenJDK Runtime Environment (8.0) (build 1.8.0-internal-debug-zhoujunen_2019_11_19_10_28-b00)
    # Java VM: OpenJDK 64-Bit Server VM (25.71-b00-debug mixed mode bsd-amd64 compressed oops)
    # Problematic frame:
    # V  [libjvm.dylib+0xa3ae38]  PerfData::~PerfData()+0x8
    #
    # Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
    #
    # An error report file with more information is saved as:
    # /Users/zhoujunwen/Documents/workspace/jdk8u/hs_err_pid84856.log
    #
    # If you would like to submit a bug report, please visit:
    #   http://bugreport.java.com/bugreport/crash.jsp
    #
    
    [error occurred during error reporting , id 0x4]
    
    [1]    84856 abort      build/macosx-x86_64-normal-server-slowdebug/jdk/bin/java -version
    

    解決方式:hotspot/src/share/vm/runtime/perfData.cpp的內容進行修改,注釋掉delete p;這一行,然后重新make all即可。

    void PerfDataManager::destroy() {
    
      if (_all == NULL)
        // destroy already called, or initialization never happened
        return;
    
      for (int index = 0; index < _all->length(); index++) {
        PerfData* p = _all->at(index);
        //delete p;
      }
    
      delete(_all);
      delete(_sampled);
      delete(_constants);
    
      _all = NULL;
      _sampled = NULL;
      _constants = NULL;
    }
    
  • 問題13: 如果編譯完成在導入Clion時發現沒有compile_commands.json文件

    解決方式: 需要借助一些工具像bear或者compiledb,下面只介紹一種compiledb的方式,推薦使用

    # 安裝 compiledb,如果沒有 pip 自行安裝
    pip install compiledb
    # 構建並使用compiledb工具生成Compilation Database
    compiledb make all COMPILER_WARNINGS_FATAL=false
    # 或者打印詳細日志 compiledb make all LOG=debug COMPILER_WARNINGS_FATAL=false
    
  • 問題14: 出現大量的編譯警告,如果不想看到可以進行處理,可以通過注釋./hotspot/make/bsd/makefiles/gcc.make中的以下代碼

    ifneq ($(COMPILER_WARNINGS_FATAL),false)
      WARNINGS_ARE_ERRORS = -Werror
    endif
    
  • 問題15: 出現**clang: error: unknown argument: '-fpch-deps'**,可以通過注釋./hotspot/make/bsd/makefiles/gcc.make的以下代碼來解決

    ifeq ($(USE_CLANG),)
      ifneq ($(CC_VER_MAJOR), 2)
        DEPFLAGS += -fpch-deps
      endif
    endif
    

主要目錄結構說明

  • jaxp目錄結構:

    • jaxp\src\org\w3c\domJAXP支持解析XMLDOM模型代碼。
    • jaxp\src\org\xml\saxJAXP支持解析XMLSAX模型代碼。
    • jaxp\src\javax\xml\streamJAXP支持解析XMLSTAX模型代碼,除了stream目錄。
  • jaxws目錄結構:

    • jaxws\src\share\jaf_classesJAF的相關代碼。
    • jaxws\src\share\jaxws_classes\comJDK內部實現使用的類。
    • jaxws\src\share\jaxws_classes\javax是對外暴露的API。
    • jaxws\src\share\jaxws_classes\comJDK內部依賴的包。
  • langtools目錄結構:

    • src/share/classes/com/sum/javadoc:生成API文檔的接口定義,即The Doclet API。
    • src/share/classes/com/sum/source: 解析源碼的接口定義。
    • src/share/classes/com/sum/tools/docletsdoclintjavadoc文檔生成工具源碼。
    • src/share/classes/com/sum/tools/classfile:共用的讀取解決classfile的工具源碼。
    • src/share/classes/com/sum/tools/javacjavac Java代碼編譯工具源碼。
    • src/share/classes/com/sum/tools/sjavacsjavac Java代碼多線程和增量編譯工具源碼,8中為初版。
    • src/share/classes/com/sum/tools/javahjavah JNI調用中用於生成native接口的頭文件的工具源碼。
    • src/share/classes/com/sum/tools/javapjavap查看源代碼編譯后字節碼的工具源碼。
    • src/share/classes/com/sum/tools/jdepsjdeps查看Java包或者類依賴的工具源碼。
    • src/share/classes/javax/lang/model:用於語言建模、語言處理任務和API等。
    • src/share/classes/javax/annotation/process:注解的處理框架 。
  • jdk目錄結構:

    ​ 其中aixbsdlinuxmacosxsolariswindows是各平台的特定實現,其中aixbsdlinuxsolaris都是類Unix系統,基本共用solaris的實現。share目錄下是平台無關的實現。

    • bin目錄是JVM的啟動入口。
    • classes目錄是JDK源碼。
    • native目錄是JDK源碼中native接口的實現源碼。
    • back目錄是JDWP(Java Debug Wire Protocol ) Java調試通信協議的實現。
    • transport目錄是建立JDWP握手連接相關的實現。
    • instrument目錄是javaagent工具即JVMTIAgent的實現。
  • hotspot目錄結構:

    hotspot是JVM即JRE Java運行時環境的實現,具體如下:

    ├─agent Serviceability Agent實現,提供HSDB JVM調試工具
    ├─make 編譯構建相關代碼
    ├─src HotSpot VM的源代碼
    │ ├─cpu 不同CPU架構下CPU相關代碼(匯編器、模板解釋器、ad文件、部分runtime函數在這里實現)
    │ ├─os 不同OS下系統調用相關代碼
    │ ├─os_cpu 跟OS和CPU架構相關的系統調用相關的代碼,如用戶棧操作
    │ └─share 平台無關的共用代碼
    │ ├─tools 工具
    │ │ ├─hsdis 反匯編插件,用於查看JIT即時編譯器產生的匯編代碼
    │ │ ├─IdealGraphVisualizer 將server編譯器的中間代碼可視化的工具
    │ │ ├─LogCompilation 將-XX:+LogCompilation輸出的日志(hotspot.log)整理成更容易閱讀的格式的工具
    │ │ └─ProjectCreator 生成Visual Studio的project文件的工具
    │ └─vm HotSpot VM的核心代碼
    │ ├─adlc 平台描述文件(上面的cpu或os_cpu里的*.ad文件)的編譯器
    │ ├─asm 匯編器接口
    │ ├─c1 client編譯器(又稱“C1”)
    │ ├─ci 動態編譯器
    │ ├─classfile 類文件的處理(包括類加載和系統符號表等)
    │ ├─code 動態生成的代碼的管理
    │ ├─compiler 從VM調用動態編譯器的接口
    │ ├─gc_implementation GC的實現
    │ │ ├─concurrentMarkSweep Concurrent Mark Sweep GC的實現
    │ │ ├─g1 Garbage-First GC的實現(不使用老的分代式GC框架)
    │ │ ├─parallelScavenge ParallelScavenge GC的實現(server VM默認,不使用老的分代式GC框架)
    │ │ ├─parNew ParNew GC的實現
    │ │ └─shared GC的共通實現
    │ ├─gc_interface GC的接口
    │ ├─interpreter 解釋器,包括“模板解釋器”(官方版在用)和“C++解釋器”(官方版不在用)
    │ ├─libadt 一些抽象數據結構
    │ ├─memory 內存管理相關(老的分代式GC框架也在這里)
    │ ├─oops HotSpot VM的對象系統的實現
    │ ├─opto server編譯器(又稱“C2”或“Opto”)
    │ ├─prims HotSpot VM的對外接口,包括部分標准庫的native部分和JVMTI實現
    │ ├─runtime 運行時支持庫(包括線程管理、編譯器調度、鎖、反射等)
    │ ├─services 主要是用來支持JMX之類的管理功能的接口
    │ ├─shark 基於LLVM的JIT編譯器(官方版里沒有使用)
    │ └─utilities 一些基本的工具類
    └─test 單元測試

參考


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM