openjdk1.8中的Makefile

openJdk1.8中的makefile,记录下java的执行文件编译过程及jvm编译过程。

目录说明

openjdk源码中有很多目录,根据功能做了模块化划分,每个目录实现其相应的功能。
每个目录下的结构都差不多,分为src(源码)、make(makefile)、test(或没有)、其他特殊目录。

  • openjdk
    • common 一些公共文件,比如下载源码的shell脚本、生成make的autoconf等文件
    • corba 分布式通讯接口
    • hotspot 虚拟机实现
    • jaxp xml处理代码
    • jaxws ws实现api
    • jdk jdk源码
    • langtools java语言工具实现,比如javac、javap等
    • make make文件
    • nashorn java中js的运行时实现
    • test 测试文件

Jdk目录

目录

  • jdk
    • src 源码目录
      • bsd bsd实现
      • linux linux实现
      • macosx macos实现
      • share 公用代码,linux平台代码会在这里
      • solaris solaris实现
      • windows window实现
    • make makefile
    • test 单元测试文件

langtools目录

该目录主要实现了jdk提供的基于jvm的工具,比如:java, javac, javah, javap等。

目录

  • langtools
  • src 源码目录
    • share java源代码
      • bin 模板
      • classes java源码文件
        • com 存放了java提供的一些基础类实现,打包成tools.jar
        • javax
        • jdk
      • sample 样例源码
  • make makefile目录
  • test 测试用例目录

Makefile目标生成

可执行文件编译Makefile

文件名为:/openjdk/jdk/make/CompileLaunchers.gmk
java中提供的bin目录下的java、javac、javap等都不是完全通过c/c++编写实现的,是通过c/c++入口,启动虚拟机加载class文件实现的相关功能。
通过c/c++的main函数入口,创建jvm虚拟机后,通过执行相关功能的java代码实现其功能,所以java相关的功能如编译、运行、查看jvm信息等功能都是通过启动一个jvm虚拟机或者通过jvmti等实现的。

在makefile文件中可以查看到该部分定义。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
ifndef BUILD_HEADLESS_ONLY
$(eval $(call SetupLauncher,appletviewer, \
-DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "sun.applet.Main"$(COMMA) }',, \
$(XLIBS)))
endif

$(eval $(call SetupLauncher,extcheck, \
-DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "com.sun.tools.extcheck.Main"$(COMMA) }'))

$(eval $(call SetupLauncher,idlj, \
-DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "com.sun.tools.corba.se.idl.toJavaPortable.Compile"$(COMMA) }'))

$(eval $(call SetupLauncher,jar, \
-DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "sun.tools.jar.Main"$(COMMA) }'))

$(eval $(call SetupLauncher,jarsigner, \
-DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "sun.security.tools.jarsigner.Main"$(COMMA) }'))

$(eval $(call SetupLauncher,javac, \
-DEXPAND_CLASSPATH_WILDCARDS \
-DNEVER_ACT_AS_SERVER_CLASS_MACHINE \
-DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "com.sun.tools.javac.Main"$(COMMA) }'))

ifeq ($(ENABLE_SJAVAC), yes)
$(eval $(call SetupLauncher,sjavac, \
-DEXPAND_CLASSPATH_WILDCARDS \
-DNEVER_ACT_AS_SERVER_CLASS_MACHINE \
-DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "com.sun.tools.sjavac.Main"$(COMMA) }'))
endif

$(eval $(call SetupLauncher,javadoc, \
-DEXPAND_CLASSPATH_WILDCARDS \
-DNEVER_ACT_AS_SERVER_CLASS_MACHINE \
-DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "com.sun.tools.javadoc.Main"$(COMMA) }'))

$(eval $(call SetupLauncher,javah, \
-DEXPAND_CLASSPATH_WILDCARDS \
-DNEVER_ACT_AS_SERVER_CLASS_MACHINE \
-DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "com.sun.tools.javah.Main"$(COMMA) }'))

$(eval $(call SetupLauncher,javap, \
-DEXPAND_CLASSPATH_WILDCARDS \
-DNEVER_ACT_AS_SERVER_CLASS_MACHINE \
-DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "com.sun.tools.javap.Main"$(COMMA) }'))

$(eval $(call SetupLauncher,jdeps, \
-DEXPAND_CLASSPATH_WILDCARDS \
-DNEVER_ACT_AS_SERVER_CLASS_MACHINE \
-DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "com.sun.tools.jdeps.Main"$(COMMA) }'))

BUILD_LAUNCHER_jconsole_CFLAGS_windows := -DJAVAW
BUILD_LAUNCHER_jconsole_LDFLAGS_windows := user32.lib

$(eval $(call SetupLauncher,jconsole, \
-DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "-J-Djconsole.showOutputViewer"$(COMMA) "sun.tools.jconsole.JConsole"$(COMMA) }' \
-DAPP_CLASSPATH='{ "/lib/jconsole.jar"$(COMMA) "/lib/tools.jar"$(COMMA) "/classes" }'))

$(eval $(call SetupLauncher,jdb, \
-DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "com.sun.tools.example.debug.tty.TTY"$(COMMA) }' \
-DAPP_CLASSPATH='{ "/lib/tools.jar"$(COMMA) "/lib/sa-jdi.jar"$(COMMA) "/classes" }'))

$(eval $(call SetupLauncher,jhat, \
-DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "com.sun.tools.hat.Main"$(COMMA) }'))

具体各个具体功能实现可以由makefile中找到相关的类文件查看实现。
这些类在目录langtools目录中。

在linux上编译openjdk的时候,所有java提供的工具程序(bin目录下的可执行程序)入口都是jdk/src/bin/share/bin/main.c。但是具体的功能代码实现其实是在langtools下通过java代码实现的,到底是怎么是怎么实现的呢。
1、在jdk/src/share/bin/defines.h中通过宏开关实现了jvm虚拟机执行参数的定义,如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#如果定义了JAVA_ARGS宏,则会把jvm的参数从宏定义中获取
# 此处参照/openjdk/jdk/make/CompileLaunchers.gmk文件在声明javac的地方,定义了该宏内容
# -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "com.sun.tools.javac.Main"$(COMMA) }')),所以生成的elf文件javac中
# 会得到该值为{ "-J-ms8m"$(COMMA) "com.sun.tools.javac.Main"$(COMMA) }
#ifdef JAVA_ARGS
static const char* const_progname = "java";
static const char* const_jargs[] = JAVA_ARGS;
/*
* ApplicationHome is prepended to each of these entries; the resulting
* strings are concatenated (separated by PATH_SEPARATOR) and used as the
* value of -cp option to the launcher.
*/
#ifndef APP_CLASSPATH
#define APP_CLASSPATH { "/lib/tools.jar", "/classes" }
#endif /* APP_CLASSPATH */
static const char* const_appclasspath[] = APP_CLASSPATH;
#else /* !JAVA_ARGS */
#ifdef PROGNAME
static const char* const_progname = PROGNAME;
#else
static char* const_progname = NULL;
#endif
static const char** const_jargs = NULL;
static const char** const_appclasspath = NULL;
#endif /* JAVA_ARGS */

#ifdef LAUNCHER_NAME
static const char* const_launcher = LAUNCHER_NAME;
#else /* LAUNCHER_NAME */
static char* const_launcher = NULL;
#endif /* LAUNCHER_NAME */

#ifdef EXPAND_CLASSPATH_WILDCARDS
static const jboolean const_cpwildcard = JNI_TRUE;
#else
static const jboolean const_cpwildcard = JNI_FALSE;
#endif /* EXPAND_CLASSPATH_WILDCARDS */

#if defined(NEVER_ACT_AS_SERVER_CLASS_MACHINE)
static const jint const_ergo_class = NEVER_SERVER_CLASS;
#elif defined(ALWAYS_ACT_AS_SERVER_CLASS_MACHINE)
static const jint const_ergo_class = ALWAYS_SERVER_CLASS;
#else
static const jint const_ergo_class = DEFAULT_POLICY;
#endif /* NEVER_ACT_AS_SERVER_CLASS_MACHINE */

最终生成的elf程序常量区段会有程序名称及入口的class类名称。

当使用javac编译java文件时,入口参数1为java文件路径,然后启动一个java虚拟机vm,把com.sun.tools.javac.Main aaa.java传递给
java虚拟机vm执行,传递给虚拟机参数如下:

1
2
3
4
5
6
7
8
9
JavaVM args:
version 0x00010002, ignoreUnrecognized is JNI_FALSE, nOptions is 7
option[0] = '-Dsun.java.launcher.diag=true'
option[1] = '-Dapplication.home=/opt/source/jdk8u-dev/build/linux-x86_64-normal-server-slowdebug/jdk'
option[2] = '-Djava.class.path=/opt/source/jdk8u-dev/build/linux-x86_64-normal-server-slowdebug/jdk/lib/tools.jar:/opt/source/jdk8u-dev/build/linux-x86_64-normal-server-slowdebug/jdk/classes'
option[3] = '-Xms8m'
option[4] = '-Dsun.java.command=com.sun.tools.javac.Main aaa.java'
option[5] = '-Dsun.java.launcher=SUN_STANDARD'
option[6] = '-Dsun.java.launcher.pid=5997'

jar包生成

jdk编译后会生成很多jar包,除了jvm虚拟机提供的一些平台功能外,其他语言层面的功能都是由java开发的jar包对外提供的,所以现在有很多语言都基于jvm做了实现。
openjdk提供了由运行时rt.jar, 工具tools.jar,编码charset.jar等其他功能jar。
下面详细介绍几个重要的jar包是怎么生成的。

tools.jar包

tools.jar包在jdk的lib目录下,主要提供jdk/bin目录下java工具的虚拟机里面的实现代码,由java开发。
生成tools.jar包的makefile文件是:文件名为:/openjdk/jdk/make/CreateJars.gmk,内容如下:

源码路径:langtools目录

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#声明tools包含的目录范围
TOOLS_JAR_INCLUDES := \
com/sun/codemodel \
com/sun/istack/internal/tools \
com/sun/jarsigner \
com/sun/javadoc \
com/sun/jdi \
com/sun/source \
com/sun/tools/attach \
com/sun/tools/classfile \
com/sun/tools/corba \
com/sun/tools/doclets \
com/sun/tools/doclint \
com/sun/tools/example/debug/expr \
com/sun/tools/example/debug/tty \
com/sun/tools/extcheck \
com/sun/tools/hat \
com/sun/tools/internal/jxc \
com/sun/tools/internal/jxc/ap \
com/sun/tools/internal/ws \
com/sun/tools/internal/ws/wscompile/plugin/at_generated \
com/sun/tools/internal/xjc \
com/sun/tools/javac \
com/sun/tools/javadoc \
com/sun/tools/javah \
com/sun/tools/javap \
com/sun/tools/jdeps \
com/sun/tools/jdi \
com/sun/tools/script/shell \
com/sun/xml/internal/dtdparser \
com/sun/xml/internal/rngom \
com/sun/xml/internal/xsom \
org/relaxng/datatype \
sun/applet \
sun/jvmstat \
sun/rmi/rmic \
sun/security/tools/jarsigner \
sun/tools/asm \
sun/tools/attach \
sun/tools/jar \
sun/tools/java \
sun/tools/javac \
sun/tools/jcmd \
sun/tools/jinfo \
sun/tools/jmap \
sun/tools/jps \
sun/tools/jstack \
sun/tools/jstat \
sun/tools/jstatd \
sun/tools/native2ascii \
sun/tools/serialver \
sun/tools/tree \
sun/tools/util

# tools.jar排除sjavac工具
# The sjavac tools is not ready for public consumption.
TOOLS_JAR_EXCLUDES = com/sun/tools/sjavac

#调用打包生成tools.jar文件
$(eval $(call SetupArchive,BUILD_TOOLS_JAR, , \
SRCS := $(JDK_OUTPUTDIR)/classes, \
SUFFIXES := .class .prp .gif .properties .xml .css .xsd .js .html .txt .java \
Tool aliasmap options, \
INCLUDES := $(TOOLS_JAR_INCLUDES), \
EXCLUDES := $(TOOLS_JAR_EXCLUDES), \
EXTRA_FILES := META-INF/services/com.sun.jdi.connect.Connector \
META-INF/services/com.sun.jdi.connect.spi.TransportService \
META-INF/services/com.sun.tools.attach.spi.AttachProvider \
META-INF/services/com.sun.tools.internal.ws.wscompile.Plugin \
META-INF/services/com.sun.tools.internal.xjc.Plugin, \
JAR := $(IMAGES_OUTPUTDIR)/lib/tools.jar, \
SKIP_METAINF := true, \
CHECK_COMPRESS_JAR := true))

rt.jar包

rt.jar包在jdk的lib目录下,主要提供java语言层面的运行时库,由java开发。
rt.jar包含的文件范围由:/openjdk/jdk/make/profile-rtjar-includes.txt定义,内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#
# Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation. Oracle designates this
# particular file as subject to the "Classpath" exception as provided
# by Oracle in the LICENSE file that accompanied this code.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#

# Included or excluded types must take one of two forms
# - *.class to indicate all classes; or else
# - a full single type name e.g.
# com/sun/security/auth/callback/DialogCallbackHandler$$1.class
# You can not use arbitrary wildcards like DialogCallbackHandler*.class.
#
# Notes:
# - Nested types must use $$ in place of $ as $ is the make meta-character
# - If a package is not listed in any profile's inclusion list then it will
# not appear in any profile. But if a package is also missing from the
# full JRE's inclusion list then it will still be part of the full JRE.
# This is because the full JRE's inclusion lists are only used to define
# the exclusion lists for profiles; they are not used to define the full
# JRE contents - that is still done with the pre-profile legacy mechanism
# (all packagesthat can be found, less those not intended for rt.jar).
# This was done to minimize the impact of profiles on the regular
# non-profile build.
#
PROFILE_1_RTJAR_INCLUDE_PACKAGES := \
com/sun/demo/jvmti/hprof \
com/sun/java/util/jar/pack \
com/sun/net/ssl \
com/sun/nio/file \
com/sun/security/cert/internal/x509 \
java/io \
java/lang \
java/math \
java/net \
java/nio \
java/security \
java/text \
java/time \
java/util \
javax/net \
javax/script \
javax/security \
jdk \
sun/invoke \
sun/launcher \
sun/misc \
sun/net/ \
sun/nio \
sun/reflect \
sun/security \
sun/text \
sun/usagetracker \
sun/util

PROFILE_1_RTJAR_INCLUDE_TYPES :=

PROFILE_1_RTJAR_EXCLUDE_TYPES :=

PROFILE_1_INCLUDE_METAINF_SERVICES :=


PROFILE_2_RTJAR_INCLUDE_PACKAGES := \
com/sun/java_cup/internal/runtime \
com/sun/net/httpserver \
com/sun/org/apache \
com/sun/rmi/rmid \
com/sun/xml/internal/stream \
java/rmi \
java/sql \
javax/rmi/ssl \
javax/sql \
javax/transaction \
javax/xml \
org/w3c \
org/xml/sax \
sun/net/httpserver \
sun/rmi \
sun/util/xml

PROFILE_2_RTJAR_INCLUDE_TYPES :=

PROFILE_2_RTJAR_EXCLUDE_TYPES :=

PROFILE_2_INCLUDE_METAINF_SERVICES := \
META-INF/services/sun.util.spi.XmlPropertiesProvider


PROFILE_3_RTJAR_INCLUDE_PACKAGES := \
com/sun/jmx \
com/sun/jndi \
com/sun/management \
com/sun/naming/internal \
com/sun/nio/sctp \
com/sun/org/apache/xml/internal/security \
com/sun/rowset \
com/sun/security/auth \
com/sun/security/jgss \
com/sun/security/ntlm \
com/sun/security/sasl \
com/sun/tracing \
java/lang/instrument \
java/lang/management \
java/security/acl \
java/util/prefs \
javax/annotation/processing \
javax/lang/model \
javax/management \
javax/naming \
javax/security/auth/kerberos \
javax/security/sasl \
javax/smartcardio \
javax/sql/rowset \
javax/tools \
javax/xml/crypto \
org/ietf/jgss \
org/jcp/xml \
sun/instrument \
sun/management \
sun/net/dns \
sun/net/www/protocol/http/ntlm \
sun/net/www/protocol/http/spnego \
sun/nio/ch/sctp \
sun/security/acl \
sun/security/jgss \
sun/security/krb5 \
sun/security/provider/certpath/ldap \
sun/security/smartcardio \
sun/tracing

PROFILE_3_RTJAR_INCLUDE_TYPES :=

PROFILE_3_RTJAR_EXCLUDE_TYPES := \
com/sun/security/auth/callback/DialogCallbackHandler$$1.class \
com/sun/security/auth/callback/DialogCallbackHandler$$2.class \
com/sun/security/auth/callback/DialogCallbackHandler$$Action.class \
com/sun/security/auth/callback/DialogCallbackHandler$$ConfirmationInfo.class \
com/sun/security/auth/callback/DialogCallbackHandler.class \
javax/management/remote/rmi/_RMIConnectionImpl_Tie.class \
javax/management/remote/rmi/_RMIConnection_Stub.class \
javax/management/remote/rmi/_RMIServerImpl_Tie.class \
javax/management/remote/rmi/_RMIServer_Stub.class

FULL_JRE_RTJAR_INCLUDE_PACKAGES := \
com/oracle \
com/sun/accessibility/internal/resources \
com/sun/activation/registries \
com/sun/awt \
com/sun/beans \
com/sun/corba \
com/sun/image/codec/jpeg \
com/sun/imageio \
com/sun/istack \
com/sun/java/browser \
com/sun/java/swing \
com/sun/jmx/remote/protocol/iiop \
com/sun/jndi/cosnaming \
com/sun/jndi/toolkit/corba \
com/sun/jndi/url/corbaname \
com/sun/jndi/url/iiop \
com/sun/jndi/url/iiopname \
com/sun/media/sound \
com/sun/org/glassfish \
com/sun/org/omg \
com/sun/swing \
com/sun/xml/internal/bind \
com/sun/xml/internal/fastinfoset \
com/sun/xml/internal/messaging \
com/sun/xml/internal/org \
com/sun/xml/internal/stream/buffer \
com/sun/xml/internal/txw2 \
com/sun/xml/internal/ws \
java/applet \
java/awt \
java/beans \
javax/accessibility \
javax/activation \
javax/activity \
javax/imageio \
javax/jws \
javax/print \
javax/rmi/CORBA \
javax/sound \
javax/swing \
javax/xml/bind \
javax/xml/soap \
javax/xml/ws \
org/omg \
sun/applet \
sun/audio \
sun/awt \
sun/corba \
sun/dc \
sun/font \
sun/java2d \
sun/net/ftp \
sun/net/smtp \
sun/net/www/content/audio \
sun/net/www/content/image \
sun/net/www/content/text \
sun/net/www/protocol/ftp \
sun/net/www/protocol/mailto \
sun/net/www/protocol/netdoc \
sun/print \
sun/security/tools/policytool \
sun/swing \
sun/tools/jar

FULL_JRE_RTJAR_INCLUDE_TYPES := \
com/sun/security/auth/callback/DialogCallbackHandler$$1.class \
com/sun/security/auth/callback/DialogCallbackHandler$$2.class \
com/sun/security/auth/callback/DialogCallbackHandler$$Action.class \
com/sun/security/auth/callback/DialogCallbackHandler$$ConfirmationInfo.class \
com/sun/security/auth/callback/DialogCallbackHandler.class \
javax/annotation/*.class \
javax/management/remote/rmi/_RMIConnectionImpl_Tie.class \
javax/management/remote/rmi/_RMIConnection_Stub.class \
javax/management/remote/rmi/_RMIServerImpl_Tie.class \
javax/management/remote/rmi/_RMIServer_Stub.class \
javax/rmi/*.class

FULL_JRE_RTJAR_EXCLUDE_TYPES :=

FULL_JRE_INCLUDE_METAINF_SERVICES := \
META-INF/services/com.sun.tools.internal.ws.wscompile.Plugin \
META-INF/services/com.sun.tools.internal.xjc.Plugin \
META-INF/services/javax.print.PrintServiceLookup \
META-INF/services/javax.print.StreamPrintServiceFactory \
META-INF/services/javax.sound.midi.spi.MidiDeviceProvider \
META-INF/services/javax.sound.midi.spi.MidiFileReader \
META-INF/services/javax.sound.midi.spi.MidiFileWriter \
META-INF/services/javax.sound.midi.spi.SoundbankReader \
META-INF/services/javax.sound.sampled.spi.AudioFileReader \
META-INF/services/javax.sound.sampled.spi.AudioFileWriter \
META-INF/services/javax.sound.sampled.spi.FormatConversionProvider \
META-INF/services/javax.sound.sampled.spi.MixerProvider \
META-INF/services/sun.java2d.cmm.PCMM \
META-INF/services/sun.java2d.pipe.RenderingEngine

生成tools.jar包的makefile文件是:文件名为:/openjdk/jdk/make/CreateJars.gmk,内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#声明rt排除的范围
# Full JRE exclude list for rt.jar and resources.jar
# This value should exclude types destined for jars other than rt.jar and resources.jar.
# When building a Profile this value augments the profile specific exclusions
RT_JAR_EXCLUDES += \
com/sun/codemodel \
com/sun/crypto/provider \
com/sun/istack/internal/tools \
com/sun/jarsigner \
com/sun/java/accessibility \
com/sun/javadoc \
com/sun/jdi \
com/sun/net/ssl/internal/ssl \
com/sun/source \
com/sun/tools \
com/sun/xml/internal/dtdparser \
com/sun/xml/internal/rngom \
com/sun/xml/internal/xsom \
javax/crypto \
javax/swing/AbstractButtonBeanInfo.class \
javax/swing/beaninfo \
javax/swing/BoxBeanInfo.class \
javax/swing/JAppletBeanInfo.class \
javax/swing/JButtonBeanInfo.class \
javax/swing/JCheckBoxBeanInfo.class \
javax/swing/JCheckBoxMenuItemBeanInfo.class \
javax/swing/JColorChooserBeanInfo.class \
javax/swing/JComboBoxBeanInfo.class \
javax/swing/JComponentBeanInfo.class \
javax/swing/JDesktopPaneBeanInfo.class \
javax/swing/JDialogBeanInfo.class \
javax/swing/JEditorPaneBeanInfo.class \
javax/swing/JFileChooserBeanInfo.class \
javax/swing/JFormattedTextFieldBeanInfo.class \
javax/swing/JFrameBeanInfo.class \
javax/swing/JInternalFrameBeanInfo.class \
javax/swing/JLabelBeanInfo.class \
javax/swing/JLayeredPaneBeanInfo.class \
javax/swing/JListBeanInfo.class \
javax/swing/JMenuBarBeanInfo.class \
javax/swing/JMenuBeanInfo.class \
javax/swing/JMenuItemBeanInfo.class \
javax/swing/JOptionPaneBeanInfo.class \
javax/swing/JPanelBeanInfo.class \
javax/swing/JPasswordFieldBeanInfo.class \
javax/swing/JPopupMenuBeanInfo.class \
javax/swing/JProgressBarBeanInfo.class \
javax/swing/JRadioButtonBeanInfo.class \
javax/swing/JRadioButtonMenuItemBeanInfo.class \
javax/swing/JScrollBarBeanInfo.class \
javax/swing/JScrollPaneBeanInfo.class \
javax/swing/JSeparatorBeanInfo.class \
javax/swing/JSliderBeanInfo.class \
javax/swing/JSpinnerBeanInfo.class \
javax/swing/JSplitPaneBeanInfo.class \
javax/swing/JTabbedPaneBeanInfo.class \
javax/swing/JTableBeanInfo.class \
javax/swing/JTextAreaBeanInfo.class \
javax/swing/JTextFieldBeanInfo.class \
javax/swing/JTextPaneBeanInfo.class \
javax/swing/JToggleButtonBeanInfo.class \
javax/swing/JToolBarBeanInfo.class \
javax/swing/JTreeBeanInfo.class \
javax/swing/JWindowBeanInfo.class \
javax/swing/SwingBeanInfoBase.class \
javax/swing/text/JTextComponentBeanInfo.class \
META-INF/services/com.sun.jdi.connect.Connector \
META-INF/services/com.sun.jdi.connect.spi.TransportService \
META-INF/services/com.sun.tools.attach.spi.AttachProvider \
META-INF/services/com.sun.tools.xjc.Plugin \
META-INF/services/sun.net.spi.nameservice.NameServiceDescriptor \
org/relaxng/datatype \
sun/awt/HKSCS.class \
sun/awt/motif/X11GB2312.class \
sun/awt/motif/X11GB2312\$$$$Decoder.class \
sun/awt/motif/X11GB2312\$$$$Encoder.class \
sun/awt/motif/X11GBK.class \
sun/awt/motif/X11GBK\$$$$Encoder.class \
sun/awt/motif/X11KSC5601.class \
sun/awt/motif/X11KSC5601\$$$$Decoder.class \
sun/awt/motif/X11KSC5601\$$$$Encoder.class \
sun/jvmstat \
sun/net/spi/nameservice/dns \
sun/nio/cs/ext \
sun/rmi/rmic \
sun/security/ec \
sun/security/internal \
sun/security/mscapi \
sun/security/pkcs11 \
sun/security/provider/Sun.class \
sun/security/rsa/SunRsaSign.class \
sun/security/ssl \
sun/security/tools/jarsigner \
sun/swing/BeanInfoUtils.class \
sun/text/resources/cldr \
sun/tools/asm \
sun/tools/attach \
sun/tools/java \
sun/tools/javac \
sun/tools/jcmd \
sun/tools/jconsole \
sun/tools/jinfo \
sun/tools/jmap \
sun/tools/jps \
sun/tools/jstack \
sun/tools/jstat \
sun/tools/jstatd \
sun/tools/native2ascii \
sun/tools/serialver \
sun/tools/tree \
sun/tools/util \
sun/util/cldr/CLDRLocaleDataMetaInfo.class \
sun/util/resources/cldr \
$(LOCALEDATA_INCLUDES) \
com/oracle/jrockit/jfr \
oracle/jrockit/jfr \
jdk/jfr

# 在jdk编译输出classes目录下查询所有定义依赖的文件
# Find all files in the classes dir to use as dependencies. This could be more fine granular.
ALL_FILES_IN_CLASSES := $(call not-containing, _the., $(filter-out %javac_state, \
$(call CacheFind, $(JDK_OUTPUTDIR)/classes)))

RT_JAR_MANIFEST_FILE := $(IMAGES_OUTPUTDIR)/lib$(PROFILE)/_the.rt.jar_manifest
RESOURCE_JAR_MANIFEST_FILE := $(IMAGES_OUTPUTDIR)/lib$(PROFILE)/_the.resources.jar_manifest

$(RT_JAR_MANIFEST_FILE): $(MAINMANIFEST) $(BEANMANIFEST)
$(MKDIR) -p $(@D)
$(RM) $@ $@.tmp
$(SED) -e "s#@@RELEASE@@#$(RELEASE)#" \
-e "s#@@COMPANY_NAME@@#$(COMPANY_NAME)#" \
$(MAINMANIFEST) >> $@.tmp
$(ECHO) >> $@.tmp
$(CAT) $(BEANMANIFEST) >> $@.tmp
$(MV) $@.tmp $@


# This defines a target-specific variables to make the shell logic easier to see.
# We need to find the Version.class file for the profile currently being built
$(IMAGES_OUTPUTDIR)/lib$(PROFILE)/rt.jar: \
CLASS_FILE = $(if $(PROFILE), $(strip $(foreach class, $(PROFILE_VERSION_CLASS_TARGETS), $(if $(findstring $(PROFILE), $(class)), $(class)))), NO_SUCH_FILE)
# This is the real target
$(IMAGES_OUTPUTDIR)/lib$(PROFILE)/rt.jar: $(IMAGES_OUTPUTDIR)/lib$(PROFILE)/_the.rt.jar.contents $(RT_JAR_MANIFEST_FILE) $(PROFILE_VERSION_CLASS_TARGETS) $(BEANLESS_CLASSES_TARGETS)
$(ECHO) Creating rt.jar $(PROFILE) Compressed=$(COMPRESS_JARS)
$(MKDIR) -p $(@D)
$(RM) $@ $@.tmp
$(CD) $(JDK_OUTPUTDIR)/classes && \
$(JAR) $(RT_JAR_CREATE_OPTIONS) $@.tmp $(RT_JAR_MANIFEST_FILE) \
@$(IMAGES_OUTPUTDIR)/lib$(PROFILE)/_the.rt.jar.contents && \
if [ -f $(CLASS_FILE) ]; then \
$(ECHO) Updating rt.jar $(PROFILE) && \
$(CD) $(patsubst %$(VERSION_CLASS_PATH), %, $(CLASS_FILE)) && \
$(JAR) $(RT_JAR_UPDATE_OPTIONS) $@.tmp $(VERSION_CLASS_PATH); \
$(CD) $(BEANLESS_CLASSES) && \
$(JAR) $(RT_JAR_UPDATE_OPTIONS) $@.tmp $(CLASSES_TO_DEBEAN); \
fi
$(MV) $@.tmp $@

jconsole.jar

jconsole.jar包在jdk的lib目录下,是一个Java监视和管理控制台的客户端程序,由javax swing开发。
jsoncole可以附加本地java进程,通过api查询方式或者使用jms协议查询java虚拟机一些观测数据。
jconsole.jar主要组成由jdk/src/share/classes/sun/tools/jconsole、
jdk/src/share/classes/com/sun/tools/jconsole目录下文件组成。

jdk本身提供了2中方式,一种是bin目录下的jconsole程序,另外一种就是lib下的jconsole.jar包。
bin下的jsoncole直接运行,启动打开jconsole的main入口, lib下的jsoncole.jar需要使用java -jar jsoncole.jar运行。

1
2
3
4
5
6
7
$(eval $(call SetupArchive,BUILD_JCONSOLE_JAR, , \
SRCS := $(JDK_OUTPUTDIR)/classes, \
SUFFIXES := .class .gif .png .properties, \
INCLUDES := sun/tools/jconsole com/sun/tools/jconsole, \
JARMAIN := sun.tools.jconsole.JConsole, \
JAR := $(IMAGES_OUTPUTDIR)/lib/jconsole.jar, \
SKIP_METAINF := true))

dt.jar

dt.jar包在jdk的lib目录下,提供运行时图形界面运行时环境,在使用java swing、awt开发的时候必须依赖该库。
dt.jar主要组成由

1
2
3
4
jdk/src/share/classes/javax/swing/
jdk/src/share/classes/sun/swing/
jdk/make/data/swingbeaninfo/javax/swing/SwingBeanInfoBase.java
jdk/make/data/swingbeaninfo/sun/swing/BeanInfoUtils.java

文件组成。

排除jdk/src/share/classes/javax/plaf目录下文件。

1
2
3
4
5
6
7
8
$(eval $(call SetupArchive,BUILD_SWINGBEANS_JAR, , \
SRCS := $(JDK_OUTPUTDIR)/classes, \
SUFFIXES := BeanInfo.class .gif, \
INCLUDES := javax/swing sun/swing, \
EXCLUDES := javax/swing/plaf, \
EXTRA_FILES := javax/swing/SwingBeanInfoBase.class sun/swing/BeanInfoUtils.class, \
JAR := $(IMAGES_OUTPUTDIR)/lib/dt.jar, \
SKIP_METAINF := true))
文章目录
  1. 1. 目录说明
    1. 1.1. Jdk目录
      1. 1.1.1. 目录
    2. 1.2. langtools目录
      1. 1.2.1. 目录
  2. 2. Makefile目标生成
    1. 2.1. 可执行文件编译Makefile
    2. 2.2. jar包生成
      1. 2.2.1. tools.jar包
      2. 2.2.2. rt.jar包
      3. 2.2.3. jconsole.jar
      4. 2.2.4. dt.jar