Arthas源码学习之填坑2 --- 编译openjdk8

游戏        2019-10-14   来源:城堡秘密

参考

http://cr.openjdk.java.net/~ihse/demo-new-build-readme/common/doc/building.html

编译配置:

Vmware/CentOS: 7.4.1708

Memory: 2.8G 

CPU: 2

Free Disk: 10G

CentOS 6.x 太老,难以安装clang, 一个c编译器。说比gcc好。

  1. 获得代码

    OpenJDK用Mercurial汞(化学代码hg)来管理代码。

    yum install mercurial

    hg clone http://hg.openjdk.java.net/jdk8/jdk8

    这会下几百k的脚本,然后在就可以执行:

    bash get_source.sh 下载几百M代码。

  2. 安装所需的依赖包

    yum groupinstall "Development Tools"

    FreeType,CUPS...

  3. bash configure

  4. make

成功后生成build目录,不过途中里边有几个error和一对warning

Generating Nimbus source files

[Error] encoded value was less than 0: encode

...

是个bug:

https://bugs.openjdk.java.net/browse/JDK-8016451

5.验证

# ./java -version

openjdk version "1.8.0-internal"

OpenJDK Runtime Environment (build 1.8.0-internal-root_2019_02_09_20_11-b00)

OpenJDK 64-Bit Server VM (build 25.0-b70, mixed mode)

# pwd

/opt/software/jdk8/build/linux-x86_64-normal-server-release/jdk/bin

代码的入口在main.c of jdk/src/share/bin

主线程src/share/vm/runtime/thread.cpp

会在启动时读取-agentlib或-Xrun参数

// Find a command line agent library and return its entry point for

//         -agentlib:  -agentpath:   -Xrun

// num_symbol_entries must be passed-in since only the caller knows the number of symbols in the array.

static OnLoadEntry_t lookup_on_load(AgentLibrary* agent, const char *on_load_symbols[], size_t num_symbol_entries) {

so. Instrument不过是预先埋了几个点,而且很有意思的是,

在具体的instrument动态库(jdk/src/share/instrument)里

代码的主人居然是Wily!

#include    "sun_instrument_InstrumentationImpl.h"


/*

 * Copyright 2003 Wily Technology, Inc.

 */

2019年1月时JDK收费元年,Amazon也出了自己的OpenJDK Corretto --- 意大利coffee