我刚刚注意到,在CentOS 6,Ubuntu 18.10上的OpenJDK 8和Windows 11上的Oracle JDK 11上的旧JRockit JDK 6中,bin
中的二进制文件大小大致相同。
$ ls -la /usr/lib/jvm/java-8-openjdk-amd64/bin/
insgesamt 472
drwxr-xr-x 2 root root 4096 Jan 31 08:03 .
drwxr-xr-x 7 root root 144 Jan 31 08:03 ..
-rwxr-xr-x 1 root root 14504 Jan 14 22:02 appletviewer
-rwxr-xr-x 1 root root 14504 Jan 14 22:02 extcheck
-rwxr-xr-x 1 root root 14504 Jan 14 22:02 idlj
-rwxr-xr-x 1 root root 14504 Jan 14 22:02 jar
-rwxr-xr-x 1 root root 14504 Jan 14 22:02 jarsigner
lrwxrwxrwx 1 root root 15 Jan 14 22:02 java -> ../jre/bin/java
-rwxr-xr-x 1 root root 14504 Jan 14 22:02 javac
-rwxr-xr-x 1 root root 14504 Jan 14 22:02 javadoc
-rwxr-xr-x 1 root root 14504 Jan 14 22:02 javah
-rwxr-xr-x 1 root root 14504 Jan 14 22:02 javap
-rwxr-xr-x 1 root root 2806 Jan 14 22:02 java-rmi.cgi
-rwxr-xr-x 1 root root 14504 Jan 14 22:02 jcmd
-rwxr-xr-x 1 root root 14528 Jan 14 22:02 jconsole
-rwxr-xr-x 1 root root 14520 Jan 14 22:02 jdb
-rwxr-xr-x 1 root root 14504 Jan 14 22:02 jdeps
-rwxr-xr-x 1 root root 14504 Jan 14 22:02 jhat
-rwxr-xr-x 1 root root 14552 Jan 14 22:02 jinfo
lrwxrwxrwx 1 root root 14 Jan 14 22:02 jjs -> ../jre/bin/jjs
-rwxr-xr-x 1 root root 14552 Jan 14 22:02 jmap
-rwxr-xr-x 1 root root 14504 Jan 14 22:02 jps
-rwxr-xr-x 1 root root 14504 Jan 14 22:02 jrunscript
-rwxr-xr-x 1 root root 14520 Jan 14 22:02 jsadebugd
-rwxr-xr-x 1 root root 14552 Jan 14 22:02 jstack
-rwxr-xr-x 1 root root 14504 Jan 14 22:02 jstat
-rwxr-xr-x 1 root root 14504 Jan 14 22:02 jstatd
lrwxrwxrwx 1 root root 18 Jan 14 22:02 keytool -> ../jre/bin/keytool
-rwxr-xr-x 1 root root 14504 Jan 14 22:02 native2ascii
lrwxrwxrwx 1 root root 15 Jan 14 22:02 orbd -> ../jre/bin/orbd
lrwxrwxrwx 1 root root 18 Jan 14 22:02 pack200 -> ../jre/bin/pack200
lrwxrwxrwx 1 root root 21 Jan 14 22:02 policytool -> ../jre/bin/policytool
-rwxr-xr-x 1 root root 14504 Jan 14 22:02 rmic
lrwxrwxrwx 1 root root 15 Jan 14 22:02 rmid -> ../jre/bin/rmid
lrwxrwxrwx 1 root root 22 Jan 14 22:02 rmiregistry -> ../jre/bin/rmiregistry
-rwxr-xr-x 1 root root 14504 Jan 14 22:02 schemagen
-rwxr-xr-x 1 root root 14504 Jan 14 22:02 serialver
lrwxrwxrwx 1 root root 21 Jan 14 22:02 servertool -> ../jre/bin/servertool
lrwxrwxrwx 1 root root 20 Jan 14 22:02 tnameserv -> ../jre/bin/tnameserv
lrwxrwxrwx 1 root root 20 Jan 14 22:02 unpack200 -> ../jre/bin/unpack200
-rwxr-xr-x 1 root root 14504 Jan 14 22:02 wsgen
-rwxr-xr-x 1 root root 14504 Jan 14 22:02 wsimport
-rwxr-xr-x 1 root root 14504 Jan 14 22:02 xjc
这很奇怪,因为它们在完成的任务(例如wsimport和xjc)中没有什么共同之处。进行十六进制转储显示,二进制文件相差仅几字节,而相对较大。
答案 0 :(得分:1)
所有这些可执行文件都包含很少的代码,并将它们的大部分工作委托给同一组共享库:
$ ldd java
linux-vdso.so.1 => (0x00007ffd7faee000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f2128acd000)
libjli.so => /usr/java/jdk1.8.0_144/bin/./../lib/amd64/jli/libjli.so (0x00007f21288b7000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f21286b3000)
libc.so.6 => /lib64/libc.so.6 (0x00007f21282e6000)
/lib64/ld-linux-x86-64.so.2 (0x00007f2128ce9000)
$ ldd javac
linux-vdso.so.1 => (0x00007fff8c1e9000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f23c6f3c000)
libjli.so => /usr/java/jdk1.8.0_144/bin/./../lib/amd64/jli/libjli.so (0x00007f23c6d26000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f23c6b22000)
libc.so.6 => /lib64/libc.so.6 (0x00007f23c6755000)
/lib64/ld-linux-x86-64.so.2 (0x00007f23c7158000)
$ ldd jar
linux-vdso.so.1 => (0x00007ffda8ff5000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f4029428000)
libjli.so => /usr/java/jdk1.8.0_144/bin/./../lib/amd64/jli/libjli.so (0x00007f4029212000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f402900e000)
libc.so.6 => /lib64/libc.so.6 (0x00007f4028c41000)
/lib64/ld-linux-x86-64.so.2 (0x00007f4029644000)
大小上的微小差异来自它们自己的符号,它们之间的符号仍然大部分相同:
$ nm java
0000000000600af4 A __bss_start
000000000040055c t call_gmon_start
0000000000600af8 b completed.6075
00000000006008a0 d const_launcher
00000000006008a8 d const_progname
0000000000600880 d __CTOR_END__
0000000000600878 d __CTOR_LIST__
0000000000600af0 D __data_start
0000000000600af0 W data_start
0000000000400760 t __do_global_ctors_aux
0000000000400580 t __do_global_dtors_aux
00000000004007b0 R __dso_handle
0000000000600890 D __DTOR_END__
0000000000600b00 b dtor_idx.6077
0000000000600888 d __DTOR_LIST__
00000000006008b0 d _DYNAMIC
0000000000600af4 A _edata
0000000000600b08 A _end
0000000000400798 T _fini
00000000004005f0 t frame_dummy
0000000000400870 r __FRAME_END__
0000000000600ac8 d _GLOBAL_OFFSET_TABLE_
w __gmon_start__
00000000004004e8 T _init
0000000000600874 d __init_array_end
0000000000600874 d __init_array_start
00000000004007a8 R _IO_stdin_used
0000000000600898 d __JCR_END__
0000000000600898 d __JCR_LIST__
U JLI_Launch@@SUNWprivate_1.1
w _Jv_RegisterClasses
00000000004006c0 T __libc_csu_fini
00000000004006d0 T __libc_csu_init
U __libc_start_main@@GLIBC_2.2.5
0000000000400620 T main
0000000000400530 T _start
0000000000000000 A SUNWprivate_1.1
$ nm javac
0000000000600b70 A __bss_start
000000000040055c t call_gmon_start
0000000000600b70 b completed.6075
0000000000600b60 d const_appclasspath
0000000000600b50 d const_jargs
00000000006008e8 d const_launcher
00000000006008f0 d const_progname
00000000006008c8 d __CTOR_END__
00000000006008c0 d __CTOR_LIST__
0000000000600b40 D __data_start
0000000000600b40 W data_start
0000000000400770 t __do_global_ctors_aux
0000000000400580 t __do_global_dtors_aux
00000000004007c0 R __dso_handle
00000000006008d8 D __DTOR_END__
0000000000600b78 b dtor_idx.6077
00000000006008d0 d __DTOR_LIST__
00000000006008f8 d _DYNAMIC
0000000000600b70 A _edata
0000000000600b80 A _end
00000000004007a8 T _fini
00000000004005f0 t frame_dummy
00000000004008b8 r __FRAME_END__
0000000000600b10 d _GLOBAL_OFFSET_TABLE_
w __gmon_start__
00000000004004e8 T _init
00000000006008bc d __init_array_end
00000000006008bc d __init_array_start
00000000004007b8 R _IO_stdin_used
00000000006008e0 d __JCR_END__
00000000006008e0 d __JCR_LIST__
U JLI_Launch@@SUNWprivate_1.1
w _Jv_RegisterClasses
00000000004006d0 T __libc_csu_fini
00000000004006e0 T __libc_csu_init
U __libc_start_main@@GLIBC_2.2.5
0000000000400620 T main
0000000000400530 T _start
0000000000000000 A SUNWprivate_1.1