From cf8898af037039998c43b3e0394e44a9ec876600 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=99=93=E5=BE=97=E5=92=AF?= Date: Tue, 21 Jul 2020 16:01:27 +0800 Subject: [PATCH] =?UTF-8?q?add=20maple=5Fbuild/doc/build=5FOpenJDK8=5Fzh.m?= =?UTF-8?q?d=20=E6=8A=9B=E7=A0=96=E5=BC=95=E7=8E=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- maple_build/doc/build_OpenJDK8_zh.md | 176 ++++++++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 maple_build/doc/build_OpenJDK8_zh.md diff --git a/maple_build/doc/build_OpenJDK8_zh.md b/maple_build/doc/build_OpenJDK8_zh.md new file mode 100644 index 0000000..f5e84d9 --- /dev/null +++ b/maple_build/doc/build_OpenJDK8_zh.md @@ -0,0 +1,176 @@ +``` +# Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. +# +# Licensed under the Mulan Permissive Software License v2 +# You can use this software according to the terms and conditions of the MulanPSL - 2.0. +# You may obtain a copy of MulanPSL - 2.0 at: +# +# https://opensource.org/licenses/MulanPSL-2.0 +# +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR +# FIT FOR A PARTICULAR PURPOSE. +# See the MulanPSL - 2.0 for more details. +# +``` + +# Download OpenJDK-8, customize and build required OpenJDK-8 components +# 下载 OpenJDK-8 , 定制和构建需要的 OpenJDK-8 组件 + +The following OpenJDK-8 components are needed for building libcore.so and running user's Java program. + +需要以下的 OpenJDK-8 组件来构建 libcore.so 以及运行用户的 Java 程序. + +Java Core libraries: + +Java 核心库: +``` + rt.jar (customized) + charsets.jar + jce.jar + jsse.jar +``` +Shared libraries(Can use these three shared libraries from the openjdk-8-jdk-headless package also): + +共享库(也可以使用openjdk-8-jdk-headless里面的三个共享库): +``` + libjava.so + libjvm.so + libverify.so +``` +Please note that one of the components rt.jar is a customized version for Maple Engine. In order +to generate the customized version of rt.jar file, modification to Object.java file of OpenJDK-8 +and building OpenJDK-8 from source are required. + +请注意其中一个组件 rt.jar 是方舟引擎定制版. 要生成方舟引擎定制版的 rt.jar 文件, 首先需要修改 OpenJDK-8 +的 Object.java ,然后从源代码构建 OpenJDK-8 + +The followings are instructions of how to build OpenJDK-8 components on OpenJDK-8 build machine, +how to modify Object.java file or customize rt.jar, and where to copy required components built +to the destinated libcore.so build directorie. + +以下是构建 OpenJDK-8 组件的指南,包括如何修改 Object.java 或者 定制 rt.jar ,以及如何将已经构建好的组 +件复制到指定的 libcore.so 构建目录 +## 1. Download OpenJDK- 8 Source +## 1. 下载 OpenJDK- 8源代码 + +Create OpenJDK-8 build environment and download OpenJDK-8 source +In order to build OpenJDK-8 from source, OpenJDK 7 JRE or JDK is required. To install OpenJDK 7 +on Ubuntu 16.04 Linux, use the following command: + +搭建 OpenJDK-8 构建环境以及下载 OpenJDK-8 的源代码 +要从源代码构建OpenJDK-8,首先需要OpenJDK 7 JRE 或者 JDK。要在Ubuntu 16.04上 安装OpenJDK 7,需要使用以下命令: +``` +$ sudo add-apt-repository ppa:openjdk-r/ppa +More info: https://launchpad.net/~openjdk-r/+archive/ubuntu/ppa +Press [ENTER] to continue or ctrl-c to cancel adding it + Press ENTER. +gpg: keyring '/tmp/tmpccfu5qmx/secring.gpg' created +gpg: keyring '/tmp/tmpccfu5qmx/pubring.gpg' created +gpg: requesting key 86F44E2A from hkp server keyserver.ubuntu.com +gpg: /tmp/tmpccfu5qmx/trustdb.gpg: trustdb created +gpg: key 86F44E2A: public key "Launchpad OpenJDK builds (all archs)" imported +gpg: Total number processed: 1 +gpg: imported: 1 (RSA: 1) +OK +``` +``` +$ sudo apt-get update +$ sudo apt-get install openjdk-7-jdk +``` +Note: Install all dependent software development packages required if they have not been already +installed (such as hg). + +注意:安装依赖(例如hg) + +Download OpenJDK-8 source: + +下载OpenJDK-8源代码: +``` +$ hg clone http://hg.openjdk.java.net/jdk8/jdk8 ~/my_opejdk8 +$ cd ~/my_opejdk8 +$ bash ./get_source.sh +``` +## 2. Customize Object Class +## 2. 定制 Object 类 +Add two extra fields in Object class by modifying Object.java file: + +修改Object.java文件,在Object类添加两个额外字段: + +Add the following fields in Object class of Object.java file as the first two fields of the class +by editing the ~/my_opejdk8/jdk/src/share/classes/java/lang/Object.java file by inserting the +following 2 lines right after the line `public class Object {`: + +编辑 ~/my_opejdk8/jdk/src/share/classes/java/lang/Object.java 文件,在`public class Object {`行之后插入 +以下两行: +``` +public class Object { + long reserved_1; int reserved_2; // Add two extra fields here + private static native void registerNatives(); +``` + +## 3. Build OpenJDK- 8 +## 3. 构建 OpenJDK-8 + +Build OpenJDK-8 using the following commands: + +使用以下命令构建OpenJDK-8 +``` +$ cd ~/my_opejdk8 +$ bash ./configure +``` + +Note: you may need to following the hints of the outputs of above commend to install missing +dependent packages required for building OpenJDK-8. + +注意:您可能需要遵循上述输出的提示以安装 构建 OpenJDK-8 所需的缺失的依赖包。 + +``` +$ export DISABLE_HOTSPOT_OS_VERSION_CHECK=ok; make all +``` + +## 4. Copy required OpenJDK components to Maple build directory +## 4. 复制需要的OpenJDK组件到方舟构建目录 +Copy following built files from OpenJDK-8 build (under ~/my_opejdk8/build directory) to +directory maple_engine/maple_build/jar/: + +从OpenJDK-8构建目录(在 ~/my_opejdk8/build 目录下)复制以下构建好的文件到 maple_engine/maple_build/jar/目录: +``` + rt.jar + jce.jar + jsse.jar + charsets.jar +``` + +Copy following built files from OpenJDK-8 build to directory maple/engine/maple_runtime/lib/x86_64/: + +从OpenJDK-8构建目录复制以下 构建好的文件 到 maple/engine/maple_runtime/lib/x86_64/ 目录: +``` + libjava.so + libjvm.so + libverify.so +``` + +## 4. Build libcore.so and run HelloWorld +## 4. 构建libcore.so并运行HelloWorld + +Build Maple compiler&engine and libcore.so: + +构建方舟编译器、方舟引擎以及 libcore.so +``` +$ cd maple_engine +$ source ./envsetup.sh +$ ./maple_build/tools/build-maple.sh +$ ./maple_build/tools/build-libcore.sh +``` + +Build and run HelloWorld.java: + +构建并运行HelloWorld.java: +``` +$ cd maple_build/examples/HelloWorld +$ $MAPLE_BUILD_TOOLS/java2asm.sh HelloWorld.java +$ $MAPLE_BUILD_TOOLS/asm2so.sh HelloWorld.s +$ $MAPLE_BUILD_TOOLS/run-app.sh -classpath ./HelloWorld.so HelloWorld + +``` -- Gitee